/* ---------------------------------------------------------------------- */ 
/* JSFDefs.h                                                              */ 
/* ---------------------------------------------------------------------- */ 
/*                                                                        */ 
/* (c) Copyright 2006, 2007  EdgeTech,                                    */ 
/*                                                                        */ 
/* 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.              */ 
/*                                                                        */ 
/* ---------------------------------------------------------------------- */ 
/* EdgeTech JSF Data format description.  This is the format that data is */ 
/* normally stored in or transmitted over the ethernet.  A sonar data     */ 
/* message contains a standard 16-byte header, followed by this header and*/ 
/* finally followed by the acoustic data.                                 */ 
/* ---------------------------------------------------------------------- */ 

#pragma once


/* ---------------------------------------------------------------------- */ 
/* Each record of data has a 240 byte header, the content of which is     */ 
/* defined below.  There are some redundant fields such as some of the    */ 
/* time stamp fields, which are maintained for backward compatibility.    */  
/* The non-acoustic fields such as pitch / roll and GPS coordinates, if   */ 
/* filled in, are approximate and not normally interpolated to the nearest*/ 
/* ping time.  Thus, multiple pings may have the same GPS fix.  It is     */ 
/* highly recommended that the specific messages that contain the         */ 
/* non-acoustic data be used for this information.  See the               */ 
/* DeviceMessages.h file for details.                                     */ 
/* ---------------------------------------------------------------------- */ 

typedef struct 
{
  /*   0 -   3 : Time in seconds since 1/1/1970 (standard time() value)   */ 
  /* Use with (millisecondsToday mod 1000) to get a full time stamp       */ 
  long int           timeSince1970; 

  /*   4 -   7 : Starting depth (window offset) in samples.               */ 
  unsigned long int  startDepth;    

  /*   8 -  11 : Ping number (increments with ping)                       */ 
  unsigned long int  pingNum;        

  /*  12 -  27 : Reserved - do not use                                    */ 
  short int          reserved0[8];

  /*  28 -  29 : ID Code (always 1 = seismic data)                        */ 
  short int          traceIDCode;   

  /*  30 -  31 : Validity flags bitmap                                    */ 
  /* Bit  0    : Lat Lon or XY valid                                      */ 
  /* Bit  1    : Course valid                                             */ 
  /* Bit  2    : Speed valid                                              */ 
  /* Bit  3    : Heading valid                                            */ 
  /* Bit  4    : Pressure valid                                           */ 
  /* Bit  5    : Pitch roll valid                                         */ 
  /* Bit  6    : Altitude valid                                           */ 
  /* Bit  7    : Reserved                                                 */ 
  /* Bit  8    : Water temperature valid                                  */ 
  /* Bit  9    : Depth valid                                              */ 
  /* Bit 10    : Annotaiton valid                                         */ 
  /* Bit 11    : Cable counter valid                                      */ 
  unsigned short int  validityFlags;

  /*  33 -  34 : Reserved - do not use                                    */ 
  unsigned short int  reserved1;

  /*  34 -  35 : DataFormatType                                           */ 
  /*   0 = 1 short  per sample  - envelope data                           */ 
  /* the total number of bytes of data to follow is  2 * samples.         */ 
  /*   1 = 2 shorts per sample  - stored as real(1), imag(1),             */ 
  /* the total number of bytes of data to follow is  4 * samples.         */ 
  /*   2 = 1 short  per sample  - before matched filter (raw)             */ 
  /* the total number of bytes of data to follow is  2 * samples.         */ 
  /*   3 = 1 short  per sample  - real part analytic signal               */ 
  /* the total number of bytes of data to follow is  2 * samples.         */ 
  /*   4 = 1 short  per sample  - pixel data / ceros data                 */ 
  /* the total number of bytes of data to follow is  2 * samples.         */ 
  /*   5 = 1 byte   per sample  - pixel data                              */ 
  /* the total number of bytes of data to follow is  1 * samples.         */ 
  /*   6 = 1 long   per sample  - raw data                                */ 
  /* the total number of bytes of data to follow is  4 * samples.         */ 
  /*   7 = 2 floats per sample  - stored as real(1), imag(1),             */ 
  /* the total number of bytes of data to follow is  8 * samples.         */ 
  /*   8 = 1 float  per sample  - envelope data                           */ 
  /* the total number of bytes of data to follow is  4 * samples.         */ 
  /* -----                                                                */ 
  /* NOTE: Values greater than 255 indicate that the data to follow is    */ 
  /* compressed and must be decompressed prior to use via the             */ 
  /* decompressiondll or other means.                                     */ 
  short int          dataFormat;    

  /*  36 -  37 : Aft distance from antennae to tow point in cm            */ 
  short int          NMEAantennaeR; 

  /*  38 -  39 : Starboard distance from antennae to tow point in cm      */ 
  short int          NMEAantennaeO; 
  
  /*  40 -  79 : Reserved for future use                                  */ 
  short int          reserved2[20];          

  /* -------------------------------------------------------------------- */ 
  /* Navigation data :                                                    */ 
  /* If the coorUnits are seconds(2), the x values represent longitude    */ 
  /* and the y values represent latitude.  A positive value designates    */ 
  /* the number of seconds east of Greenwich Meridian or north of the     */ 
  /* equator.                                                             */ 
  /* -------------------------------------------------------------------- */ 

  /*  80 -  83 : Longitude in 10000 * (Minutes of Arc) or X in mm         */ 
  long int           groupCoordX;    

  /*  84 -  87 : Latitude in 10000 * (Minutes of Arc) or Y in mm          */ 
  long int           groupCoordY;    

  /*  88 -  89 : Units of coordinates - 1->length mm(x/y), 2->10000 *     */ 
  /* (Minutes of Arc), 3->length in dm.                                   */ 
  short int          coordUnits;    

  /*  90 - 113 : Annotation string                                        */ 
  char               annotation[24];

  /* 114 - 115 : Samples in this packet                                   */ 
  /* Note: Use the message header byte count in conjunction with the      */ 
  /*       dataformat field to determine if the actual number of samples  */ 
  /*       can exceed 65535.  if the true number of samples exceeds 65535,*/ 
  /*       then this is the 16-lsbs of the number of samples.             */ 
  unsigned short int samples;       

  /* 116 - 119 : Sample interval in ns of stored data                     */ 
  unsigned long int  sampleInterval;

  /* 120 - 121 : Gain factor of ADC                                       */ 
  unsigned short int ADCGain;       

  /* 122 - 123 : user pulse power setting (0 - 100) percent               */ 
  short int          pulsePower;    

  /* 124 - 125 : Reserved                                                 */ 
  short int          reserved3;    

  /* 126 - 127 : Starting frequency in DHz (10 Hz)                        */ 
  unsigned short int startFreq;     

  /* 128 - 129 : Ending frequency in DHz (10 Hz)                          */ 
  unsigned short int endFreq;       

  /* 130 - 131 : Sweep length in ms                                       */ 
  unsigned short int sweepLength;   

  /* 132 - 135 : Pressure in milliPSI - (1/1000 PSI)                      */ 
  long               pressure;

  /* 136 - 139 : Depth estimate in mm                                     */ 
  long               depth;

  /* 140 - 141 : Sample rate in Hz mod 65536                              */ 
  /* Note:  For Raw data it is 1/2 the sampling rate mod 65536.           */ 
  unsigned short int sampleRate;

  /* 142 - 143 : Unique pulse identifier                                  */ 
  unsigned short int pulseID;    

  /* 144 - 147 : Altitude in mm                                           */ 
  long               altitude;

  /* 148 - 155 : Reserved                                                 */ 
  long               reserved4[2];

  /* 156 - 157 : Year data recorded (CPU time)                            */ 
  short int          year;          

  /* 158 - 159 : day                                                      */ 
  short int          day;           

  /* 160 - 161 : hour                                                     */ 
  short int          hour;          

  /* 162 - 163 : minute                                                   */ 
  short int          minute;        

  /* 164 - 165 : second                                                   */ 
  short int          second;        

  /* 166 - 167 : Always 3                                                 */ 
  short int          timeBasis;     

  /* 168 - 169 : weighting factor for block floating point expansion      */ 
  /* -- defined as 2 -N volts for lsb                                     */ 
  /* IMPORTANT: All data MUST be scaled by pow(2, -weightingFactor)       */ 
  /*            DO NOT IGNORE THIS VALUE.                                 */ 
  short int          weightingFactor;

  /* 170 - 171 : Number of pulses in the water                            */ 
  short int          numPulses;    

  /* -------------------------------------------------------------------- */ 
  /* From pitch/roll/temp/heading sensor(s)                               */ 
  /* -------------------------------------------------------------------- */ 

  /* 172 - 173 : Compass heading  0.00 to 360.00 degrees in 1/100 degree  */ 
  unsigned short int heading;       

  /* 174 - 175 : Pitch ((degrees / 180.0) * 32768.0)  maximum resolution  */ 
  short int          pitch;         

  /* 176 - 177 : Roll  ((degrees / 180.0) * 32768.0)  maximum resolution  */ 
  short int          roll;          

  /* 178 - 179 : Temperature (10 * degrees C) of towfish electronics.     */ 
  short int          temperature;   

  /* -------------------------------------------------------------------- */ 
  /* User defined area from 180-239                                       */ 
  /* -------------------------------------------------------------------- */ 

  /* 180 - 181 : Reserved                                                 */ 
  short int          reserved5;    

  /* 182 - 183 : TriggerSource (0 = internal, 1 = external)               */ 
  short int          trigSource;    

  /* 184 - 185 : Mark Number (0 = no mark)                                */ 
  unsigned short int markNumber;    

  /* Note that the NMEA time fields are the time of the GPS fix and come  */ 
  /* from the same sentence which reported the fix.                       */ 

  /* 186 - 187 : Hour                                                     */ 
  short int          NMEAHour;

  /* 188 - 189 : Minutes                                                  */ 
  short int          NMEAMinutes;

  /* 190 - 191 : Seconds                                                  */ 
  short int          NMEASeconds;

  /* 192 - 193 : Course                                                   */ 
  short int          NMEACourse;

  /* 194 - 195 : Speed in tenths of a knot                                */ 
  short int          NMEASpeed;

  /* 196 - 197 : Day                                                      */ 
  /* Note:  Will be 0 if NMEA sentence does not have this field           */ 
  short int          NMEADay;

  /* 198 - 199 : Year                                                     */ 
  /* Note:  Will be 0 if NMEA sentence does not have this field           */ 
  short int          NMEAYear;

  /* 200 - 203 : Millieconds today                                        */ 
  /* Use with seconds since 1970 to get time to the ms                    */ 
  unsigned long int  millisecondsToday;

  /* 204 - 205 : Maximum absolute value of ADC samples for this packet    */ 
  unsigned short int ADCMax;        

  /* 206 - 209 : Reserved                                                 */ 
  short int          reserved6[2];      

  /* 210 - 215 : Sonar Software version number                            */ 
  char               softwareVersion[6]; 

  /* 216 - 219 : Initial spherical correction factor in samples.          */ 
  /* A value of -1 indicates that the spherical spreading is disabled.    */ 
  long int           sphericalCorrection;
  
  /* 220 - 221 : Packet number - Each ping starts with packet 1           */ 
  unsigned short int packetNum;     

  /* 222 - 223 : A/D decimation * 100 before FFT                          */ 
  short int          ADCDecimation; 

  /* 224 - 225 : Decimation factor after FFT                              */ 
  short int          decimation;    

  /* 226 - 227 : Water Temperature in 1/10 degree C                       */ 
  short int          waterTemperature;

  /* 228 - 231 : Distance to the fish in meters                           */ 
  float              layback;

  /* 232 - 235 : Reserved                                                 */ 
  long int           reserved7;

  /* 236 - 237 : cable out in decimeters                                  */ 
  unsigned short     cableOut;

  /* 238 - 239 : towfish depth in decimeters                              */ 
  unsigned short     towfishDepth;

  /* -------------------------------------------------------------------- */ 
  /* Data area begins here                                                */ 
  /* -------------------------------------------------------------------- */ 
  /* Data begins at byte 240, has this.samples data points in it          */ 
  /* Normally : short int data[] (see dataFormat field);                  */ 
  /* -------------------------------------------------------------------- */ 

} JSFDataType;

/* ---------------------------------------------------------------------- */ 
/*                       end JSFDefs.h                                    */ 
/* ---------------------------------------------------------------------- */ 

