/****************************************************************************/
/* Copyright (c) 2000 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : Parosci.h                                                     */
/* Author   :                                                               */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 02/07/2000                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
/*
CLASS 
PSA916

DESCRIPTION
Paroscientific depth sensor driver

AUTHOR
John Rieffel

*/

#ifndef _PAROSCI_H
#define _PAROSCI_H

#include <unistd.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/uio.h>
#include <fcntl.h>
#include <errno.h>
#include <iostream.h>
#include <math.h>
#include <signal.h>
#include <time.h>

#include "MissionClock.h"
#include "ParosciOutput.h"
#include "ParosciLog.h"
#include "Attributes.h"
#include "SharedData.h"
#include "StreamSerialDriver.h"
#include "Task.h"
#include "SerialDevice.h"
#include "time.h"
#include "WorkSiteIF.h"
#include "EdgetechFSDWIF.h"

#define BAUD 38400 
#define PARITY "NONE"
#define STOP_BITS 1
#define DATA_BITS 8
#define READ_TIMEOUT 5000

#define PARO_TIMEOUT 5000
#define INT_TIME 24 
#define  UNITS_VAL 3

#define MAX_PRESSURE 1000
#define MIN_PRESSURE -1
#define DEFAULT_BARO_CORRECTION_BAR (1.11)

#define REPLY_LEN 32

class Parosci : public Task{

  friend class ParosciLog;

public:
     
     Parosci(SerialDevice *interface, int baro_corr_flag);
     virtual ~Parosci();
     void run();
 
protected:

     ParosciLog *_log;

     Attributes _attributes;
     long  _pr, _tempInt;
     double pressure, depth, start_depth;
     double pres_period, temp_period;

     int serialNo;
     timespec readtime;
     int _baro_corr_flag;
     double init_pres, init_temp;
     double site_latitude;

     static const char *coeffNameList[];
     int coeffNameListLen;
//     double pc[sizeof(iniseq)/sizeof(char*)];
// I wish this didn't need to be hard coded
     double pc[16];

     char reply[REPLY_LEN];
     
     ParosciOutput *_output;
     MissionClock *clock;
     SerialDevice *_device;
     EdgetechFSDWIF * _edgetechIF;

     timer_t timer_id;
 
     DeviceIF::Status initialize();
     DeviceIF::Status readRecord(unsigned char *record, 
				 int maxRecordBytes, 
				 const char *recordTerminator,
				 unsigned readTimeout,
				 int *nBytesRead)
     { return DeviceIF::Ok; }

     DeviceIF::Status processRecord();

     static const double kPsiToBar;
     inline double psiToBar( double psi )
       { return kPsiToBar * psi; };

     static const double kBarToPsi;
     inline double barToPsi( double bar )
       { return kBarToPsi * bar; };

     void periodicParosciCallback( void );

     double comp_temp(double);
     double comp_press_bar(double, double);
     double corrected_depth(double);

     int getParosci(void);
     void startupPressurePeriod();

     //Send Pressure Data to the edgetech System=
     void insertPressureRecordEdgetech();

     // Write a command string to the Parosci in two parts.
     // First, write a '*', to stop the stream from the device.
     // Then write the command string. The command string should
     // NOT have a leading '*'
     //
     void writeCommand(const char *cmd);
};


#endif

