/****************************************************************************/
/* Copyright (c) 2003 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : fastcatTest.cc                                                */
/* Author   :                                                               */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 12/17/2003                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
#include <stdlib.h>
#include <conio.h>
#include <process.h>
#include <signal.h>

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

int main( int argc, char **argv )
{
  float cond, temp, depth, salinity, velocity, cfreq, pvolts;
  long tcounts, pcounts;
     TimeIF::TimeSpec condSampleTime, tempSampleTime;
     FastCatIF *fastcat;
     pid_t _server;
     
     try { 
       SerialParameters serialParams(&argc, argv);
       char argString[100];
       sprintf(argString, "-serial %s", serialParams.string());
       if ((_server = System::spawn("fastcatServer", argString)) == -1) {
	 Syslog::write("System::spawn(fastcatServer) failed\n");
       }
     }
     catch ( ... )
       {
	 Syslog::write("fastcatTest -- caught exception on spawning of "
		       "fastcatServer\n");
       }
     
     try {
       fastcat = new FastCatIF("fastcat", "FastCat");
     }
     catch (Exception e) 
     {
	 Syslog::write("fastcatTest -- Caught exception on creation of FastCatIF:%s\n",
		       e.msg);
	 exit( -1 );
     }
     
     
     printf("Press any key to exit\n");
     
     while (True) {

       if (fastcat->ready())
       {
         if(fastcat->get_CTD_data(&cond, &temp, &depth,
			      &condSampleTime, &tempSampleTime,
			      &salinity,
			      &velocity,
                              &tcounts, &cfreq, &pcounts, &pvolts
			      ) == DeviceIF::Ok)
         {
	   printf("cond = %lf, temp = %lf, pressure(dB) = %lf cts = %ld, ctns = %ld, tts = %ld, ttns = %ld\n  ", 
		  cond, temp, depth, 
		  condSampleTime.seconds, condSampleTime.nanoSeconds,
		  tempSampleTime.seconds, tempSampleTime.nanoSeconds);

	   printf("\nsalinity: %lf, velocity: %lf\n", salinity, velocity);
           printf("\ntcounts: %d, cfreq(hz): %f\n", tcounts, cfreq);
           printf("\npcounts: %d, pvolts: %f\n", pcounts, pvolts);

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

     delete fastcat;
     kill(0, SIGTERM);

     return 0;
}
