/****************************************************************************/
/* Copyright (c) 2001 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : Ips4.h                                                        */
/* Author   :                                                               */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 04/04/2001                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
#ifndef _IPS_H
#define _IPS_H

#include "SerialDeviceDriver.h"
#include "Ips4Output.h"
#include "Ips4Log.h"
#include "Attributes.h"

extern "C"
{
#include "IceDraft.h"
}

/*
CLASS
Ips4

DESCRIPTION
Ips4 Device Driver Interface

AUTHOR
Rich Henthorn

*/

class Ips4 : public SerialDeviceDriver {
  
  friend class Ips4Log;

public:

  Ips4(SerialDevice *serialDevice, Boolean verbose);

  virtual ~Ips4();

  DeviceIF::Status stop();

  DeviceIF::Status start();

  /////////////////////////////////////////////////////////////////////////
  // calculate_IceDraft() - compute the icedraft using the following inputs
  //
  //	pAtm    - estimated value of the atmospheric pressure (in bars)
  //    nPoints - number of elements in CTD array
  //	cond    - pointer to conductivity array (C(S,T,0)/C(35,T,0))
  //	temp    - pointer to temperature array (degress Celsius)
  //	pres    - pointer to pressure array (absolute pressure in bars)
  //
  // output:
  //      iceDraft- address of double to place calculated ice draft
  //
  int calculate_IceDraft(double pAtm, int nPoints,
			 double cond[/*nPoints*/], 
			 double temp[/*nPoints*/], 
			 double pres[/*nPoints*/],
			 double *iceDraft);

protected:

  Ips4Log *_log;

  Ips4Output *_output;

  icedraft_t *_iceDraft;

  char *_ipsRecord;

  Boolean _verbose;

  int _numberErrors;

  ////////////////////////////////////////////////////////////////////
  // initialization routine
  virtual DeviceIF::Status initialize();

  ////////////////////////////////////////////////////////////////////
  // Read a fixed-length record
  virtual DeviceIF::Status readRecord(unsigned char *record,
				      int maxRecordBytes,
				      const char *recordTerminator,
				      unsigned readTimeout,
				      int *nBytesRead);
  
  ////////////////////////////////////////////////////////////////////
  // Process a record
  virtual DeviceIF::Status  processRecord(unsigned char *record, int nRecordBytes);

  ////////////////////////////////////////////////////////////////////
  // Write to shared memory in a standardized way
  void writeOutput(char *message = "writeOutput()");
};

#endif
