/****************************************************************************/
/* Copyright (c) 2000 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : ctdTest.cc                                                    */
/* Author   :                                                               */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 02/07/2000                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
/*-----------------------------------------------------------------------*
  PROGRAM: ctdServer

  DESCRIPTION: Binary wrapper for ctd Server

  AUTHOR: Aaron Marsh

  $Id: seabirdTest.cc,v 1.4 2001/07/30 22:18:56 henthorn Exp $
  *-----------------------------------------------------------------------*/
#include <stdlib.h>
#include <conio.h>
#include <process.h>
#include <signal.h>

#include "Syslog.h"
#include "CtdIF.h"
#include "System.h"
#include "SerialParameters.h"

int main( int argc, char **argv )
{
     float cond, temp, depth, tfreq, cfreq;
     TimeIF::TimeSpec condSampleTime, tempSampleTime;
     float v1,v2,v3,v4,v5,v6;
     CtdIF *ctd;
     pid_t _ctdServer;
     
     try { 
       SerialParameters serialParams(&argc, argv);
       char argString[100];
       sprintf(argString, "-n ctdDriver -serial %s", serialParams.string());
       if ((_ctdServer = System::spawn("seabirdServer", argString)) == -1) {
	 Syslog::write("System::spawn(seabirdServer) failed\n");
       }
     }
     catch ( ... )
       {
	 Syslog::write("seabirdTest -- caught exception on spawning of "
		       "seabirdServer\n");
       }
     
     try {
       ctd = new CtdIF("ctd", "ctdDriver");
     }
     catch (Exception e) 
       {
	 Syslog::write("seabirdTest -- Caught exception on creation of CtdIF:%s\n",
		       e.msg);
	 exit( -1 );
       }
     
     
     printf("Press any key to exit\n");
     
     while (True) {

       if (ctd->get_CTD_data(&cond, &temp, &depth, &tfreq, &cfreq, 
			     &condSampleTime, &tempSampleTime,
			     &v1,
			     &v2,
			     &v3,
			     &v4,
			     &v5,
			     &v6
			     ) == DeviceIF::Ok) {

	 printf("cond = %lf, temp = %lf, tfreq = %lf, cfreq = %lf, "
		"cts = %ld, ctns = %ld, tts = %ld, ttns = %ld\n  ", 
		cond, temp, tfreq, cfreq, 
		condSampleTime.seconds, condSampleTime.nanoSeconds,
		tempSampleTime.seconds, tempSampleTime.nanoSeconds);

	 printf("\nvoltages: %lf, %lf, \t%lf, %lf, \t%lf, %lf\n",v1,v2,v3,v4,v5,v6);

	 }
	 else 
	   printf("ctd->get_CTD_data() returned error\n");
	 
	 sleep(1);
       }

     delete ctd;
     kill(0, SIGTERM);

  return 0;
}
