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

  DESCRIPTION: Device interface for Ixsea Octans

  AUTHOR: Hans Thomas

  $Id: Octans.h,v 1.2 2001/06/05 05:09:49 hthomas Exp $
 *-----------------------------------------------------------------------*/

#ifndef _OCTANS_H
#define _OCTANS_H

#include "StreamDriverTask.h"
#include "SerialDevice.h"
#include "OctansOutput.h"
#include "OctansLog.h"

#include "AHRSOutput.h"

#define OctansTaskName "octans"

#define GYROCOMPAS1_PKT_LENGTH (63)
#define VICTOR_PKT_LENGTH (40)


class Octans : public SerialDeviceDriver {

  friend class OctansLog;

public:
  enum OctansProtocol{
    gyrocompass1,
    victor,
    imbat,
    ptvf
  };

  Octans( SerialDevice *device, enum OctansProtocol protocol=gyrocompass1);
  
  virtual ~Octans();
  
  Boolean setHexDump( Boolean );

  void octansDebugMode( Boolean newMode );
  void status(char *str);
  void currentData(char *str);

protected:

  OctansLog *_log;

  SerialDevice *_device;

  OctansOutput _output;

private:
  OctansProtocol _protocol;
  virtual DeviceIF::Status initialize();
  virtual DeviceIF::Status readRecord(unsigned char *record, int maxBytes,
				      const char *recordTerminator,
				      unsigned readTimeout, int *nbytesRead);
  virtual DeviceIF::Status processRecord(unsigned char *record, int nbytes);
  void loadConfig( const char *configFile );

  Boolean _octansDebugMode;
  Boolean _dumpHex;

  struct octansState {
    float roll, pitch, yaw;
    float surge, sway, heave;
    float speedX, speedY, speedZ;
    float compLatitude;
    unsigned long status;
  };

  struct victorDataPacket {
    unsigned char Header;
    unsigned char numBytes;
    unsigned char userID;
    float roll, pitch, yaw;
    float rollRate, pitchRate, yawRate;
    float rollAxisAcc, pitchAxisAcc, yawAxisAcc;
    unsigned char checksum;
  };

  int checkChecksum( unsigned char *data, unsigned char csum);
  DeviceIF::Status readASCIIRecord(unsigned char *record,int maxBytes,
				   int readTimeout, int *nbytesRead);
  DeviceIF::Status readVictorRecord(unsigned char *record, int maxBytes,
				    int readTimeout, int *nbytesRead);
  DeviceIF::Status readImbatRecord(unsigned char *record, int maxBytes,
				    int readTimeout, int *nbytesRead);
  DeviceIF::Status processASCIIRecord(unsigned char *record, int nbytes);
  DeviceIF::Status processVictorRecord(unsigned char *record, int nbytes);
  DeviceIF::Status processImbatRecord(unsigned char *record, int nbytes);
};


#endif
