//Release 1.1: Added more information to Buffer Format, reflected in decommap.txt.
#define MAJOR_REL 1
//#define MINOR_REL 1 //Original
#define MINOR_REL 2 //Added LSB/MSB, bpw, DataType, and Extract mask


#define PC_CLOCK 0
#define IRIG_CLOCK 1

typedef struct archive_buffer_t {
int nCurBuff; //Which buffer we are currently WRITING TO
HANDLE hPingPong[2];
LPSTR lpPingPong[2];
UINT uPingPongBytes[2];
} ARCHBUFF, far *LPARCHBUFF;

static ARCHBUFF sArchBuff;

typedef struct archive_file_header_t {
WORD nMajorRel; //The major release number, eg the 1 in v 1.0
WORD nMinorRel; //The minor release number, eg the 0 in v 1.0
WORD nClockType; //PC or IRIG CURRENTLY NOT USED
BOOL bLSB; //Version 1.2, changed from nReserved.
DWORD dwTicks; //Number of millisecs in length of the recording.
DWORD dwStartTicks; //Starting tick count
DWORD dwBytes; //Number of bytes that follow with DB information
DWORD dwParams; //Total number of params in archive
DWORD dwReserved[10]; //Reserved for future use
} ARCH_FILE_HEADER, far *LPARCH_FILE_HEADER;

static ARCH_FILE_HEADER sFileHeader;


#define MAX_PARAM_LEN 31
typedef struct buffer_format_t {
char szParamName[MAX_PARAM_LEN + 1];
DWORD lOffset; //Offset IN BYTES to the start of this param
DWORD lOccurances; //Number of occurances of the param
WORD nSize; //Size of the param in BYTES.
BOOL bArchive; //TRUE if we have data for this param

//Changes for v1.2. Took away 2 DWORDS from dwReserved added
//Added nBPW, nDataType, and nExtractMask
//a WORD to keep alignment...
WORD nBPW; //BPW for this param
WORD nDataType; //Data type for this param
WORD nExtractMask; //Extract mask for this param
WORD nReserved; //Keep number of reserved words balanced!
DWORD dwReserved[8]; //Reserved for future use
} BUFFER_FORMAT, far *LPBUFFER_FORMAT;




#define DATA_HEADER_ID 0xBeefBabeL
#define DATA_TRAILER_ID 0xBabeBeefL

typedef struct archive_data_header_t {
DWORD lHeaderID; //Unique ID for the top
WORD nHeaderSize; //Size of this structure, including lHeaderID.
DWORD lPacketNum; //Number of the packet
DWORD lLen; //Len of data following
WORD nSource; //The source of the data
WORD nType; //The type of data...eg embedded
DWORD dwTicks; //The value of the PC clock in ticks. Starts at 0
RawIRIG_s sIRIG; //The time in IRIG format
WORD nFlags; //Misc. flags
DWORD lTrailerID; //Unique ID for the end
} ARCH_DATA_HEADER, far *LPARCH_DATA_HEADER;

static ARCH_DATA_HEADER sDataHeader;


typedef struct {
unsigned short hdays;
unsigned short tdays;
unsigned short udays;
unsigned short thours;
unsigned short uhours;
unsigned short tmin;
unsigned short umin;
unsigned short tsec;
unsigned short usec;
unsigned short hmsec;
unsigned short tmsec;
unsigned short umsec;
unsigned short husec;
unsigned short tusec;
unsigned short uusec;
unsigned short status;
} RawIRIG_s;
// note: all higher level abstractions of IRIG supported elsewhere! (RCH)