/* ---------------------------------------------------------------------- */ 
/* FileIndexMessages.h                                                    */ 
/*                                                                        */ 
/* Copyright (c) 2007  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.              */ 
/*                                                                        */ 
/* ---------------------------------------------------------------------- */ 
/* This file contains the file index message formats.                     */ 
/* The end of each file can have multiple indices, to improve display and */ 
/* seeking speed.                                                         */ 
/* ---------------------------------------------------------------------- */ 

#ifndef __FILEINDEXMESSAGES_H__
#define __FILEINDEXMESSAGES_H__


/* ---------------------------------------------------------------------- */ 
/* includes                                                               */ 
/* ---------------------------------------------------------------------- */ 

#include "PublicMessageOffsets.h"


/* ---------------------------------------------------------------------- */ 
/* Message Types                                                          */ 
/* ---------------------------------------------------------------------- */ 
/* The sonarMessage field indicates the type of data to follow.           */ 
/* ---------------------------------------------------------------------- */ 

typedef enum
{
  /* -------------------------------------------------------------------- */ 
  /* Target commands                                                      */ 
  /* -------------------------------------------------------------------- */ 

  /* File index messages.  If present should be the last message in a file*/ 
  /* The index consists of 3 parts, a FileIndexHeaderType, index data     */ 
  /* specific to each type of index, and a FileIndexSignature             */ 
  FILEINDEX_MESSAGE_INDEXTABLE = MESSAGE_OFFSET_FILEINDEX,           

} FileIndexMessageType;

/* ====================================================================== */ 
/* Notes on FILEINDEX_MESSAGE_INDEXTABLE                                  */ 
/* This message consists of the following:                                */ 
/*                                                                        */ 
/* * SonarMessageHeaderType      : Standard message header                */ 
/* * FileIndexMasterIndex        : Master index header                    */ 
/*   * FileIndexMasterIndexEntry[] : List of tables included here         */ 
/* * Specific table 1 header (eg FileIndexStandardTableHeader)            */ 
/*   * Specific entries for table 1 (eg FileIndexStandardEntry)           */ 
/* * Specific table 2 header (if present)                                 */ 
/* ...                                                                    */ 
/* ... End of all tables                                                  */ 
/* * FileIndexSignature                                                   */ 
/*                                                                        */ 
/* The index message is normally the last message in a file.  The         */ 
/* FileIndexSignature is used to verify that its a valid message and to   */ 
/* locate the start of the message                                        */ 
/* ====================================================================== */ 

/* ---------------------------------------------------------------------- */ 
/* Signature at the end of the message : needed to locate message start   */ 
/* ---------------------------------------------------------------------- */ 

/* Unique signature strings                                               */ 

#define FILE_INDEX_SIGNATURESTRING0 ("File Index Signature String 000 : THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.")
#define FILE_INDEX_SIGNATURESTRING1 ("FILE INDEX SIGNATURE STRING 001 : the quick brown fox jumps over the lazy dog.")

/* ---------------------------------------------------------------------- */ 

typedef struct
{
  /* Information string : E.g. program used to generate this file / index */ 
  char          generalInformationString[80];

  /* Signature string 0 : Must be set to FILE_INDEX_SIGNATURESTRING0      */ 
  char          signature0[80];

  /* Signature string 1 : Must be set to FILE_INDEX_SIGNATURESTRING1      */ 
  char          signature1[80];

  /* This is the size of the master message in bytes (excluding the       */ 
  /* sonar message header type field but including this signature) to be  */ 
  /* used to go to the start of the message                               */ 
  unsigned long messageSizeBytes;

} FileIndexSignature;


/* ---------------------------------------------------------------------- */ 
/* Types of index tables supported                                        */ 
/* ---------------------------------------------------------------------- */ 

typedef enum
{
  /* Standard index, containing FileIndexEntryType items                  */ 
  FILEINDEX_ENTRY_STANDARD_INDEX,

  /* User defined table                                                   */ 
  FILEINDEX_ENTRY_USERDEFINED_INDEX,

} FileIndexEntryEnumType;


/* ---------------------------------------------------------------------- */ 
/* The master table index.                                                */ 
/* ---------------------------------------------------------------------- */ 

typedef struct
{
  /* Standard signature : Must be set to FILE_INDEX_SIGNATURESTRING0     */ 
  char     signature0[80];

  /* Number of entries in master index table                             */ 
  long int numberOfIndexTables;

  /* Reserved fields                                                     */ 
  long     reserved0;

  long     reserved1[14];

  /* Data to follow of type FileIndexMasterIndexEntry                    */ 
  /* FileIndexMasterIndexEntry[numberOfIndexTables];                     */ 

} FileIndexMasterIndex;


/* ---------------------------------------------------------------------- */ 
/* Master entry table                                                     */ 
/* ---------------------------------------------------------------------- */ 

typedef struct
{
  /* Subsystem for this entry                                            */ 
  long int subsystem;

  /* Type of entries to follow (see FileIndexEntryEnumType               */ 
  long int entryType;

  /* Size of table in bytes                                              */ 
  long int tableSizeBytes;

} FileIndexMasterIndexEntry;


/* ---------------------------------------------------------------------- */ 
/* Standard table header (FILEINDEX_ENTRY_STANDARD_INDEX)                 */ 
/* ---------------------------------------------------------------------- */ 

typedef struct
{
  /* Number of entries in table                                          */ 
  long int numEntries;

  /* Size of each entry in bytes.                                        */ 
  long int entrySizeBytes;

  /* Option flags                                                        */ 
  /* Bit 0 : set to 1 for XY coordinates, 0 for lat/lon                  */ 
  long int flags;

  /* Reserved for future use                                             */ 
  long int reserved0;

  /* Reserved for future use                                             */ 
  long int reserved1[124];

  /* FileIndexStandardEntry entryData[numEntries] follows this header    */ 

} FileIndexStandardTable;


/* ---------------------------------------------------------------------- */ 
/* An entry for a standard index table                                    */ 
/* ---------------------------------------------------------------------- */ 

typedef struct
{
  /* Ping number                                                         */ 
  unsigned long pingNumber;

  /* Time since 1970 in seconds                                          */ 
  unsigned long secondsSince1970;

  /* Latitude in minutes or Y in meters                                  */ 
  double        lat_y;

  /* Longitude in minutes or X in meters                                 */ 
  double        lon_x;

  /* heading in degrees                                                   */ 
  float         heading;

  /* Slant Range in milliseconds                                         */ 
  unsigned long slantRangeMS;

  /* Seek point in file                                                  */ 
  unsigned long seekToByte;

  /* Seek point in file, bits higher than 31 for very large files        */ 
  unsigned long seekToByteUpper32Bits;

  /* Source file sequence number                                         */ 
  unsigned long sourceFileSequenceNumber;

  /* Motion info                                                         */ 
  /* 0 : Pitch in 0.3 degree units (use +- 127 to indicate at limit      */ 
  /* 1 : Roll in 0.3 degree units (use +- 127 to indicate at limit       */ 
  /* 2 : Altitude in 0.3 meter units (255 indicates at limit)            */ 
  /* 3 : Depth in 0.3 meter units (255 indicates at limit)               */ 
  char motionInfopr[2];
  unsigned char motionInfoad[2];

  /* Reserved for future expansion                                       */ 
  unsigned long reserved0[1];

} FileIndexStandardTableEntry;

/* ---------------------------------------------------------------------- */ 

#endif  /* Not __FILEINDEXMESSAGES_H__ */ 


/* ---------------------------------------------------------------------- */ 
/*                       end FileIndexMessages.h                          */ 
/* ---------------------------------------------------------------------- */ 

