/****************************************************************************/
/* 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: ctdTest.cc,v 1.5 2000/02/22 22:39:48 jrieffel Exp $
  *-----------------------------------------------------------------------*/
#include <stdlib.h>
#include <conio.h>
#include <process.h>
#include <signal.h>

#include "Syslog.h"
#include "CTDIF.h"
#include "System.h"

int main( int argc, char **argv )
{
     float cond, temp, depth, tfreq, cfreq;
     long cond_time_s, cond_time_ns, temp_time_s, temp_time_ns;
     float v1,v2,v3,v4,v5,v6;
     CTDIF *ctd;
     pid_t _ctdServer;
     
     try { 
       if ((_ctdServer = System::spawn("ctdServer","")) == -1)
	 {
	   Syslog::write("System::spawn(ctdServer) failed\n");
	 }
     }
     catch ( ... )
       {
	 Syslog::write("ctdTest -- caught exception on spawning of ctd Server\n");
       }
     
     try {
       ctd = new CTDIF("ctd");
     }
     catch (...) 
       {
	 Syslog::write("CTDTest -- Caught exception on creation of CTDIF.\n");
	 exit( -1 );
       }
     
     
     printf("Press any key to exit\n");
     
     while( !kbhit() ) 
       {
	 if (ctd->get_CTD_data(&cond, &temp, &depth, &tfreq, &cfreq, 
			       &cond_time_s, &cond_time_ns, &temp_time_s, 
			       &temp_time_ns,
			       &v1,
			       &v2,
			       &v3,
			       &v4,
			       &v5,
			       &v6
			       ) == OK) {

	 printf("cond = %lf, temp = %lf, tfreq = %lf, cfreq = %lf, "
		"cts = %ld, ctns = %ld, tts = %ld, ttns = %ld\n  ", 
		cond, temp, tfreq, cfreq, cond_time_s, cond_time_ns, 
		temp_time_s, temp_time_ns);

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

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

     delete ctd;
     
  return 0;
}
