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

  DESCRIPTION: Binary wrapper for psa916 Server

  AUTHOR: Aaron Marsh

  $Id: parosciTest.cc,v 1.8 2001/08/31 14:24:55 hthomas Exp $
  *-----------------------------------------------------------------------*/

#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <signal.h>
#include <process.h>
#include <i86.h>
#include "DepthSensorIF.h"
#include "Syslog.h"
#include "System.h"
#include "SerialParameters.h"

int main( int argc, char **argv ) 
{
  DepthSensorIF *depthSensor;

  double depth, temp, pressure;

  pid_t _serverPid;
  pid_t workSiteServer;

  if ((workSiteServer = System::spawn("workSite",  "")) == -1) 
    throw Exception("System::spawn(workSite Server) failed");

  printf(" parosciTest: Started WorkSite Server.\n");

  try { 
    SerialParameters serialParams(&argc, argv);
    char argString[100];
    sprintf(argString, "-serial %s", serialParams.string());
    if ((_serverPid = System::spawn("parosciServer", argString)) == -1)
      {
	Syslog::write("System::spawn(parosciServer) failed\n");
      }
  }
  catch ( ... )
    {
      Syslog::write("parosciTest -- "
		    "caught exception on spawning of Parosci Server\n");
    }


  try 
  {
       depthSensor = new DepthSensorIF( "Parosci", 1000 );
  }
  catch (...)
  {
       Syslog::write("parosciTest -- Caught exception on IF creation\n");
       exit( -1 );
  }

  printf("Press any key to exit\n");

  while (True) {

       TimeIF::TimeSpec sampleTime;

       if (depthSensor->depth( &depth, &sampleTime ) != OK)
	 fprintf(stderr, "Error reading depth\n");

       if (depthSensor->temp( &temp, &sampleTime ) != OK)
	 fprintf(stderr, "Error reading temp\n");

       if (depthSensor->pressure( &pressure, &sampleTime ) != OK)
	 fprintf(stderr, "Error reading pressure\n");

       printf("Depth: % 12lf, temp: % 12lf, pressure: % 12lf\n",
	      depth, temp, pressure );

       delay(200);
       
  }

  delete depthSensor;
  kill(0, SIGTERM);
  return 0;
}
