/* ----------------------------------------------------------------------- */ 
/* DeviceMessages.h                                                        */ 
/*                                                                         */ 
/* ----------------------------------------------------------------------- */ 
/*                                                                         */ 
/* (c) Copyright 1998, 1999, 2000, 2001  EdgeTech Inc                      */ 
/*                                                                         */ 
/* This file contains proprietary information, and trade secrets of        */ 
/* EdgeTech, and may not be disclosed or reproduced without the prior      */ 
/* written consent of EdgeTech.                                            */ 
/*                                                                         */ 
/* EdgeTech is not responsible for the consequences of the use or misuse   */ 
/* of this software, even if they result from defects in it.               */ 
/*                                                                         */ 
/* Messages for controlling attached devices                               */ 
/* ----------------------------------------------------------------------- */ 

#ifndef __DEVICE_MESSAGES_H__
#define __DEVICE_MESSAGES_H__


/* ----------------------------------------------------------------------- */ 
/* includes                                                                */ 
/* ----------------------------------------------------------------------- */ 

#include "SonarMessages.h"
#include "Subsystem.h"
#include "Timestamp.h"
#include "PublicMessageOffsets.h"


/* ----------------------------------------------------------------------- */ 
/* A list of device messages                                               */ 
/* ----------------------------------------------------------------------- */ 

typedef enum
{
  /* Note: Use SONAR_MESSAGE_DATA_NETWORK, SONAR_MESSAGE_DATA_DISK to      */ 
  /* enable / disable data output on a device.                             */ 

  /* --------------------------------------------------------------------- */ 
  /* A Serial Port allows the reading and writing of data to a port.       */ 
  /* --------------------------------------------------------------------- */ 

  /* Read or write bytes of (raw) data to the port (DEVDataType)           */ 
  DEV_SERIAL_DATA = MESSAGE_OFFSET_DEV,

  /* Receives baud rate, etc - eg (DEVSerialParametersType)                */ 
  DEV_SERIAL_PARAMETERS,

  /* -------------------------------------------------------------------- */ 
  /* NMEA Data                                                            */ 
  /* -------------------------------------------------------------------- */ 

  /* Validated RS232 Data from a NMEA Source.                             */ 
  /* Format is the same as serial port data DEV_SERIAL_DATA (DEVDataType) */ 
  /* Each message is a single NMEA string excluding the <CR>/<LF>         */ 
  DEV_SERIAL_NMEA_DATA,

  /* --------------------------------------------------------------------- */ 
  /* Generic device control - reserved for future expansion.               */ 
  /* --------------------------------------------------------------------- */ 

  /* Read or write bytes of data to the port (DEVDeviceDataType)           */ 
  DEV_DEVICE_DATA = MESSAGE_OFFSET_DEV_GENERIC,

  /* Receives device parameters.  Size is specific to device subsystem.    */ 
  DEV_DEVICE_PARAMETERS,

  /* Send a special command to the device (SonarMessageLongType)           */ 
  DEV_DEVICE_COMMAND,

  /* --------------------------------------------------------------------- */ 
  /* Special device messages                                               */ 
  /* --------------------------------------------------------------------- */ 
  /* A Pitch Roll Sensor Can Profile:                                      */ 
  /*   3 axis accelerometers,                                              */ 
  /*   3 axis rate gyros,                                                  */ 
  /*   Pitch, Roll                                                         */ 
  /*   Heave                                                               */ 
  /*   Heading                                                             */ 
  /* It is a serial device.                                                */ 
  /* --------------------------------------------------------------------- */ 

  /* Sends data of type (DEVDataType + PitchRollDataType)                  */ 
  DEV_PITCHROLL_DATA = MESSAGE_OFFSET_DEV_PITCHROLL,

  /* Calibrate Sensor.                                                     */ 
  /* Currently only the Crossbow DMU6 Pitch Roll uses to Calibrate its     */ 
  /*   Rate Gyros                                                          */ 
  DEV_PITCHROLL_CALIBRATE,

  /* Receives baud rate, etc. - e.g. (DeviceDMU6ParametersType)            */ 
  /* This is a special message which is retained for backward compatibility*/ 
  /* Not recommended for new systems.                                      */ 
  DEV_PITCHROLL_DMU6_PARAMETERS,

  /* --------------------------------------------------------------------- */ 
  /* Low rate analog IO messages                                           */ 
  /* --------------------------------------------------------------------- */ 
  /* This is misc analog sampled data.  Not generally used.                */ 
  /* --------------------------------------------------------------------- */ 

  /* Sends data of type (AnalogIOItemType) on a get                        */ 
  DEV_ANALOGIO_DATA = MESSAGE_OFFSET_DEV_ANALOGIO,

  /* Set parameters for analog IO data (DeviceAnalogIOParametersType)      */ 
  DEV_ANALOGIO_PARAMETERS,

  /* --------------------------------------------------------------------- */ 
  /* A Pressure sensor reads pressure and optionally temp / salinity.      */ 
  /* --------------------------------------------------------------------- */ 

  /* Sends data of type (DEVDataType + DEVPressureType)                    */ 
  DEV_PRESSURE_DATA = MESSAGE_OFFSET_DEV_PRESSURE,

  /* --------------------------------------------------------------------- */ 
  /* Altitude sensor                                                       */ 
  /* --------------------------------------------------------------------- */ 

  /* Altitude readings.  The message header is followed by                 */ 
  /* (DEVDataType + DEVAltitudeType)                                       */ 
  DEV_ALTITUDE_DATA = MESSAGE_OFFSET_DEV_ALTITUDE,

  /* --------------------------------------------------------------------- */ 
  /* Add more device messages here                                         */ 
  /* --------------------------------------------------------------------- */ 

} DeviceMessagesType;


/* ----------------------------------------------------------------------- */ 
/* Special subsystem IDs for message headers.                              */ 
/* ----------------------------------------------------------------------- */ 

typedef enum
{
  /* Raw serial device messages                                            */ 
  /* This subsystem is used to control raw data IO.                        */ 
  DEVICE_SUBSYSTEM_SERIAL_RAW = SUBSYSTEM_OFFSET_DEVICE,

  /* Parsed Serial device messages.                                        */ 
  /* This subsystem is used to control parsed data io.                     */ 
  /* Note: The main difference between the RAW and PARSED subsystems is    */ 
  /*   that the SONAR_MESSAGE_DATA_ENABLE must be associated with the      */ 
  /*   correct subsystem number to select either / or both raw and         */ 
  /*   processed receipt of data.  Baud rate settings, etc should be sent  */ 
  /*   via the raw subsystem.  Specific parser device commands, if any,    */ 
  /*   should be sent to the parsed subsystem.                             */ 
  DEVICE_SUBSYSTEM_SERIAL_PARSED,

  /* Analog IO (low rate IO) messages                                      */ 
  DEVICE_SUBSYSTEM_ANALOGIO,

} DeviceSubsystemType;


/* ----------------------------------------------------------------------- */ 
/* Understanding device data                                               */ 
/* ----------------------------------------------------------------------- */ 
/* Device data such as serial data ALWAYS consists of TWO parts:           */ 
/* 1) Overall Common Header of type DEVDataType                            */ 
/* 2) Device Specific Data (eg pitch roll readings or raw serial data)     */ 
/*                                                                         */ 
/* In addition: Device messages, as do all messages also contain a standard*/ 
/* message header.  Here are a few examples:                               */ 
/*                                                                         */ 
/* Pitch Roll: (SonarMessageHeaderType)(DEVDataType)(DEVPitchRollDataType) */ 
/* Serial Data:(SonarMessageHeaderType)(DEVDataType)(Raw Serial Data)      */ 
/* Pressure:   (SonarMessageHeaderType)(DEVDataType)(DEVPressureType)      */ 
/* ----------------------------------------------------------------------- */ 

/* ----------------------------------------------------------------------- */ 
/* The common device header for device data being received.                */ 
/* ----------------------------------------------------------------------- */ 

typedef struct
{
  /*  0 - 7 : Timestamp                                                    */ 
  TimestampType timestamp;    

  /* Reserved for future expansion.                                        */ 
  unsigned char reserved[4];

  /* Begins at byte 12, This is serial port or other data.                 */ 
  /* data[];                                                               */ 

} DEVDataType;


/* ----------------------------------------------------------------------- */ 
/* Parameters for a serial port                                            */ 
/* Note that .ini files are provided to set these parameters and messages  */ 
/* are not normally needed to configure the ports.                         */  
/* ----------------------------------------------------------------------- */ 

typedef struct
{
  /* Parity 0: even, 1: odd, 2: none, 3: mark, 4: space                    */ 
  unsigned char parity;

  /* Stop bits                                                             */ 
  unsigned char stopBits;

  /* Non-zero to enable output to a topside via the network interface on   */ 
  /* the data socket.                                                      */ 
  unsigned char enableNetworkOutput;

  /* Non-zero to enable output to a topside based RS232 port.              */ 
  unsigned char enableTopsideSerialIO;

  /* Approximate Interval for polling port in bottle for input data in ms  */ 
  unsigned short wetPortCheckInterval;

  /* Approximate Interval for polling port in topside for input data in ms */ 
  unsigned short dryPortCheckInterval;

  /* Baud rate                                                             */ 
  unsigned long baud;

  /* Reserved information for extended parsing of serial port data.  May   */ 
  /* be used to specify special parsing / EOL processing in the future     */ 
  /* releases.  Set to 0 for compatibility.                                */ 
  unsigned char extendedParsingInfo;

  /* Data bits.                                                            */ 
  unsigned char dataBits;

  /* Reserverd for future use (Round to 64 bytes).                         */ 
  unsigned char reserved[50];

} DEVSerialParametersType;


/* ----------------------------------------------------------------------- */ 
/* Each analog IO data set is timestamped.  Up to 8 value are reported.    */ 
/* ----------------------------------------------------------------------- */ 

typedef struct
{
  /* Decimation factor for reporting of analog IO data.                    */ 
  long int decimation;

} DeviceAnalogIOParametersType;


/* ----------------------------------------------------------------------- */ 
/* Each analog IO data set is timestamped.  Up to 8 value are reported.    */ 
/* These values are ADC4 and ADC6 for each of 4 mux inputs on the ADC64.   */ 
/* ----------------------------------------------------------------------- */ 

typedef struct
{
  /* Data for this sample                                                  */ 
  short int data[8];

  /* Reserved for future use                                               */ 
  unsigned char reserved[8];

} AnalogIOItemType;


/* ----------------------------------------------------------------------- */ 
/* The data structure for Crossbow DMU6 Parameters.                        */ 
/* Note that these can be set in the .ini file so no messages are required */ 
/* ----------------------------------------------------------------------- */ 

typedef struct
{
  /* Calibration constant (0 - 255).  It takes approx that many seconds    */ 
  /* to calibrate the device                                               */ 
  int calFactor;

  /* Time constant (0 - 255).  Weigh the rate gyros with respect to the    */ 
  /* accelerometers for computing pitch and roll.                          */ 
  int timeConstant;

  /* Decimation factor.  Use a positive number to decimate with            */ 
  /* continuous sampling (1 => full rate of about 80 hz).  Use a negative  */ 
  /* number for polled operation at that number of milliseconds per sample */ 
  /* (-100 => 10 times per second)                                         */ 
  int decimation;

} DeviceDMU6ParametersType;


/* ----------------------------------------------------------------------- */ 
/* The data structure for Pitch roll data.                                 */ 
/* ----------------------------------------------------------------------- */ 

typedef struct
{
  /* Acceleration in x : Multiply by (20 * 1.5) / (32768) to get Gs        */ 
  short int ax;

  /* Acceleration in y : Multiply by (20 * 1.5) / (32768) to get Gs        */ 
  short int ay;

  /* Acceleration in x : Multiply by (20 * 1.5) / (32768) to get Gs        */ 
  short int az;

  /* Rate Gyro in x : Multiply by (500 * 1.5) / (32768) to get Degrees/Sec */ 
  short int rx;

  /* Rate Gyro in y : Multiply by (500 * 1.5) / (32768) to get Degrees/Sec */ 
  short int ry;

  /* Rate Gyro in y : Multiply by (500 * 1.5) / (32768) to get Degrees/Sec */ 
  short int rz;

  /* Pitch : Multiply by (180.0 / 32768.0) to get Degrees                  */ 
  short int pitch;

  /* Roll  : Multiply by (180.0 / 32768.0) to get Degrees                  */ 
  short int roll; 

  /* Temperature int units of 1/10 of a degree C.                          */ 
  /* Degrees C = (temperature / 10.0).                                     */ 
  /* There is difference between the original and new DMU6 (with DSP).     */ 
  /* Internally, the raw DMU6 is converted to C via the following formula  */ 
  /* Old DMU6 : Degrees C = (temperature * 4 / 4096 - 1.375) / 0.0225      */ 
  /* New DMU6 : Degrees C = (temperature * 5 / 4096 - 1.375) / 0.0225      */ 
  short int temperature;
  
  /* Device specific info.  This is device specific info provided for      */ 
  /* Diagnostic purposes.                                                  */ 
  /* For the Crossbow DMU, this is the internal counter which ticks at     */ 
  /* about 6.25 us                                                         */ 
  unsigned short devInfo;

  /* Estimated Heave in millimeters.                                       */ 
  short heave;

  /* Heading in units of 0.01 Degrees (0..360)                             */ 
  unsigned short heading;

  /* Data valid flags:                                                     */ 
  /* Bit  0: ax                                                            */ 
  /* Bit  1: ay                                                            */ 
  /* Bit  2: az                                                            */ 
  /* Bit  3: rx                                                            */ 
  /* Bit  4: ry                                                            */ 
  /* Bit  5: rz                                                            */ 
  /* Bit  6: pitch                                                         */ 
  /* Bit  7: roll                                                          */ 
  /* Bit  8: heave                                                         */ 
  /* Bit  9: heading                                                       */ 
  /* Bit 10: temperature                                                   */ 
  /* Bit 11: devInfo                                                       */ 
  long int flags;

  /* Reserved for future expansion.                                        */ 
  long int reserved;

} PitchRollDataType;


/* ----------------------------------------------------------------------- */ 
/* The data structure for Pressure sensor readings.                        */ 
/* ----------------------------------------------------------------------- */ 

typedef struct
{
  /* Pressure in PSI * 1000                                                */ 
  long int pressure;

  /* Temperature in Degrees C * 1000.                                      */ 
  long int temperature;

  /* Salinity in Parts Per Million.                                        */ 
  long int saltPPM;

  /* Data valid flags:                                                     */ 
  /* Bit 0: pressure                                                       */ 
  /* Bit 1: temp                                                           */ 
  /* Bit 2: saltPPM                                                        */ 
  long int flags;

  /* Reserved for future information.                                      */ 
  long int reserved[12];

} DEVPressureType;

/* ----------------------------------------------------------------------- */ 
/* The data structure for Altitude sensor readings.                        */ 
/* ----------------------------------------------------------------------- */ 

typedef struct
{
  /* Indicates which values are present.                                   */ 
  /* Bit 0 : Altitude present                                              */ 
  /* Bit 1 : Forward Velocity present.                                     */ 
  /* Bit 2 : Across Track Velocity present.                                */ 
  /* Rest  : Reserved, presently 0.                                        */ 
  long flags;

  /* Altitude in mm (or -1 if no valid reading - bottom detect failed)     */ 
  long altitude;

  /* Forward velocity in mm per second.                                    */ 
  long forwardVelocity;

  /* Cross track velocity in mm per second.                                */ 
  long crossTrackVelocity;

  /* Reserved for future expansion.                                        */ 
  long reserved[4];

} DEVAltitudeType;

#endif  /* __DEVICE_MESSAGES_H__ */ 


/* ----------------------------------------------------------------------- */ 
/*                       end DeviceMessages.h                              */ 
/* ----------------------------------------------------------------------- */ 
