//============================================================================
// Summary  : Reson Type Definition list
// Filename : ResonTypeDefs.h
// Author   : reed@bluefinrobotics.com
// Project  : Data Broadcaster
// Revision : 0.0
// Created  : 2002.04.15
// Modified : 2002.04.15
//============================================================================
// From 6046 Specification (2001.05.31)


#ifndef _RESON6046DATATYPES_H
#define _RESON6046DATATYPES_H
//#include "TimeIF.h"

// --- A3.1 Data Types ---
typedef          char      I8;
typedef unsigned char      U8;
typedef unsigned char      BYTE;
typedef          short     I16;
typedef unsigned short     U16;
typedef          int       I32;
typedef unsigned int       U32;
typedef          float     F32;
typedef          double    F64;


// 64 bit integer
struct Integer64
{
    I32 raw[2]; // place for most and least significant parts of the number.
};
typedef Integer64          I64;

// 64 bit unsigned integer
struct UnsignedInteger64
{
    U32 raw[2]; // place for most and least significant halfs of the number.
};
typedef UnsignedInteger64  U64;

// 7K Time Structure
#pragma pack(1)
struct _7kTime
{
    U16 year;    // 0 - 65535
    U16 day;     // 1 - 366
    F32 seconds; // 0.000000 - 59.000000
    U8 hours;    // 0 - 32
    U8 minutes;  // 0 - 59
};
typedef struct   _7kTime   T7K;


// Define the size of the structures so they
// don't have to be calculated for each use.
// Sizes are in bytes.
const unsigned int sizeI8 = sizeof(I8);
const unsigned int sizeU8 = sizeof(U8);
const unsigned int sizeBYTE = sizeof(BYTE);
const unsigned int sizeI16 = sizeof(I16);
const unsigned int sizeU16 = sizeof(U16);
const unsigned int sizeI32 = sizeof(I32);
const unsigned int sizeU32 = sizeof(U32);
const unsigned int sizeF32 = sizeof(F32);
const unsigned int sizeF64 = sizeof(F64);
const unsigned int sizeI64 = sizeof(I64);
const unsigned int sizeU64 = sizeof(U64);
const unsigned int sizeT7K = sizeof(T7K);

//Record Type Header definitions
//Record Type #1003
struct _7kPosRTH {
  U32 datumIdentifier; //0 for WGS84, >0 is reserved
  F64 latitude; //latitude in radians
  F64 longitude; //longitude in radians
  F64 height; //meters
  // DFD 1.00
  U8  position_type_flag;
  U8  utm_zone;
  U8  quality;
  U8  position_method;
};
typedef struct _7kPosRTH T7kPosRTH;

//Record Type #1004
struct _7kAttitudeRTH {
  U8 bitfield; //0: Pitch in radians (f32)
               //1: Roll in radians (f32)
               //2: Heading in radians (f32)
               //3: Heave in meters (f32)
               //7-4: Reserved
  U8 reserved;
  U8 numberFields; //Number of Fields
  // DFD 1.00
  F32 freq;
};
typedef struct _7kAttitudeRTH T7kAttitudeRTH;
//Record data is F32

// Record Type #1006
struct _7kAltitudeRTH {
  F32 distance;
};
typedef struct _7kAltitudeRTH T7kAltitudeRTH;

// Record Type #1008
struct _7kDepthRTH {
  U8  descriptor;   // Use value of 0 = depth to sensor
  U8  correction;   // Use value of 0 = Raw depth
  U16 reserved;
  F32 depth;        // Greater depth value means deeper
};
typedef struct _7kDepthRTH T7kDepthRTH;

//Record Type #1010
struct _7kCTDRTH {
  // DFD 1.00
  F32 freq;
  U8 SVsrcFlag;
  U8 SVAlg;
  U8 CondFlag;
  U8 PressFlag;
  U8 PosFlag;
  U8 SampleValidity;
  U16 reserved;
  F64 Lat;
  F64 Lon;
  F32 SampleRate;
  U32 NumSamples;
  F32 Cond;
  F32 Temp;
  F32 Pressure;
  F32 SVel;
  F32 Res;
};
typedef struct _7kCTDRTH T7KCTDRTH;

/*********************************************************/
/*         Bluefin record type 3100 structs              */

// Data frame (header)
struct _BfDataFrame {
  U32  packetSize;
  U16  version;
  U16  offset;     // Offset in bytes from the start of packet to the start of data
  U32  dataType;   // 0=Nav data, 1=Env data
  U32  dataSize;   // Either sizeof nav record or size of env record
  T7K  timestamp;
  U32  checksum;
  U16  reserved;
};
typedef struct _BfDataFrame TBfDataFrame;


// Bluefin nav record (3100)
struct _BfNavRecord {
  TBfDataFrame header;

  U32  quality;
  F64  lat;          // radians
  F64  lng;          // radians
  F32  speed;        // m/sec
  F64  depth;        // m
  F64  altitude;     // m
  F32  roll;         // radians
  F32  pitch;        // radians
  F32  yaw;          // radians
  F32  northingRate; // m/sec
  F32  eastingRate;  // m/sec
  F32  depthRate;    // m/sec 
  F32  altitudeRate; // m/sec
  F32  rollRate;     // radians/sec
  F32  pitchRate;    // radians/sec
  F32  yawRate;      // radians/sec
  F64  positionTime; // seconds
  F64  altitudeTime; // seconds
};
typedef struct _BfNavRecord TBfNavRecord;

// Bluefin env record (3100)
struct _CtdData {
  F32  cond; // S/m
  F32  temp; // degrees C
  F32  pressure; //decibar
  F32  salinity; //PSU
//  TimeIF::TimeSpec condSampleTime;
//  TimeIF::TimeSpec tempSampleTime;
  F64 surfacePressure; //dBar
  I32 tcounts; //thermister A/D counts 
  F32 cfreq; //Conductivity Frequency in Hz 
  I32 pcounts; //strain gauge pressure sensor A/D Counts
  F32 presCompVoltage; //volts
//  TimeIF::TimeSpec analogSampleTime;
  U16 analogChannels[8];  
};

struct _bfEnvData {
  U32  quality;
  F32  soundVelocity; // m/sec
  struct _CtdData ctd; // we are stashing the balance of the ctd data in the padding
  // the original padding in the message was 88 bytes, so we have to subtract off what we just added;
  U8   padding[88-sizeof(struct _CtdData)];
};
typedef struct _bfEnvData TBfEnvData;

struct _BfEnvRecord {
  TBfDataFrame header;
  TBfEnvData   data;
};
typedef struct _BfEnvRecord TBfEnvRecord;

/*********************************************************/
#endif
