XCube Stream Reader SDK
|
00001 //============================================================================ 00002 // Name : CX3cFile.h 00003 // Author : John Roberts, enhanced by Michael Johnson 00004 // Version : 00005 // Copyright : (C) Copyright 2010 XCube Research and Development 00006 // All rights reserved. 00007 // 00008 // Description : X3C File definitions and methods 00009 // 00010 // HISTORY : 00011 // 08/11/10 - Initial version.... 00012 // 10/20/10 - MGJ: added additional read/write/get/set methods 00013 // 02/29/12 - JER: flip data file suffix to "lf1" 00014 //============================================================================ 00015 00016 #ifndef CX3CFILE_H_ 00017 #define CX3CFILE_H_ 00018 00019 #include <time.h> 00020 #include <fcntl.h> 00021 #include <sys/time.h> 00022 #include "xcTypes.h" 00023 00024 //Logger FILE TYPE SUFFIX, as in "myDataFile.x3c" 00025 //Note there is not '.' file type separator defined here. 00026 //History: For the first year and a half (2010, 2011) the Logger used the ".x3c" 00027 // File Suffix for DATA files. This was change to .lf1 Feb 28, 2012. 00028 #define SUFFIX_LF1 00029 #ifdef SUFFIX_LF1 00030 #define LOGDATA_FILE_SUFFIX_STR "lf1" 00031 #else 00032 #define LOGDATA_FILE_SUFFIX_STR "x3c" 00033 #endif 00034 00035 #define X3C_MAGIC 0x58334321 00036 #define X3C_VERSION_MINOR 0x0001 00037 #define X3C_VERSION_MAJOR 0x0000 00038 00039 /* 00040 * This is a timeval as stored in the X3C file. 00041 * It has to use the same types everywhere, independent of the actual 00042 * `struct timeval'. `struct timeval' has 32-bit tv_sec values on some 00043 * platforms and 64-bit tv_sec values on other platforms, and writing 00044 * out native `struct timeval' values would mean files could only be 00045 * read on systems with the same tv_sec size as the system on which 00046 * the file was written. 00047 */ 00048 struct x3c_timeval { 00049 UINT32 tv_sec; //Seconds since 00:00:00 GMT, 1 January 1970 00050 union{ 00051 UINT32 tv_usec; // Additional microseconds since tv_sec 00052 UINT32 tv_nsec; // Additional nanoseconds since tv_sec 00053 }; 00054 }; 00055 00056 // GLOBAL FILE HEADER 00057 typedef struct _X3C_HEADER_ { 00058 UINT32 magic; /* magic number */ 00059 UINT16 version_major; /* major version number */ 00060 UINT16 version_minor; /* minor version number */ 00061 UINT16 task_type; /* defines data source */ 00062 UINT16 task_enum; 00063 struct x3c_timeval ts; /* File Creation time */ 00064 INT32 thiszone; /* GMT to local correction */ 00065 UINT32 opt[2]; /* optional data */ 00066 }X3C_HEADER; 00067 00068 // PACKET HEADER 00069 typedef struct _X3C_PACKET_HEADER_ { 00070 struct x3c_timeval ts; 00071 UINT32 len; /* packet data length */ 00072 } X3C_PACKET_HEADER; 00073 00074 00075 class CX3cFile { 00076 public: 00077 CX3cFile(); 00078 virtual ~CX3cFile(); 00079 00080 // Init Data Buffer 00081 int createDataBuffer(int len); 00082 int getDataBufferSize() { return(mDataBufferSize); }; 00083 00084 // TBD 00085 X3C_HEADER * getX3cHeaderPtr() { return(&mX3cHeader); }; 00086 X3C_PACKET_HEADER * getPacketHeaderPtr() { return(&mPacketHeader); }; 00087 int setX3cHeader(X3C_HEADER * pX3cHeader); 00088 int setPacketHeader(X3C_PACKET_HEADER * pPacketHeader); 00089 00090 int getX3cHeaderLen() { return(sizeof(X3C_HEADER)); }; 00091 int getPacketHeaderLen() { return(sizeof(X3C_PACKET_HEADER)); }; 00092 int getPacketLen() { return((int)(sizeof(X3C_PACKET_HEADER) + mPacketDataLen)); }; 00093 00094 // Get/Set Packet Data 00095 char * getPacketDataPtr() { return(mPacketData); }; 00096 int getPacketDataLen() { return(mPacketDataLen); }; 00097 int setPacketData(char * buffer, UINT32 len); 00098 void setPacketDataLen(UINT32 len) { mPacketDataLen = len; }; 00099 00100 00101 // Get/Set X3C_Header 00102 UINT32 getX3cMagicNumber() { return(mX3cHeader.magic); }; 00103 UINT16 getX3cVersionMajor() { return(mX3cHeader.version_major); }; 00104 UINT16 getX3cVersionMinor() { return(mX3cHeader.version_minor); }; 00105 UINT16 getX3cTaskType() { return(mX3cHeader.task_type); }; 00106 UINT16 getX3cTaskEnum() { return(mX3cHeader.task_enum); }; 00107 INT32 getX3cTimeZone() { return(mX3cHeader.thiszone); }; 00108 INT32 getX3cOpt1() { return(mX3cHeader.opt[0]); }; 00109 INT32 getX3cOpt2() { return(mX3cHeader.opt[1]); }; 00110 INT32 getX3cTimeSec() { return(mX3cHeader.ts.tv_sec); }; 00111 INT32 getX3cTimeUSec() { return(mX3cHeader.ts.tv_usec); }; 00112 INT32 getX3cTimeNSec() { return(mX3cHeader.ts.tv_nsec); }; 00113 void getX3cTime(timeval * tv) { // sec and usec 00114 tv->tv_sec = mX3cHeader.ts.tv_sec; 00115 tv->tv_usec = mX3cHeader.ts.tv_usec; 00116 return; 00117 }; 00118 void getX3cTime(timespec * ts) { // sec and nsec 00119 ts->tv_sec = mX3cHeader.ts.tv_sec; 00120 ts->tv_nsec = mX3cHeader.ts.tv_nsec; 00121 return; 00122 }; 00123 00124 // Get/Set X3C_PACKET_HEADER 00125 UINT32 getPacketDataLength() { return(mPacketHeader.len); }; 00126 INT32 getPacketTimeSec() { return(mPacketHeader.ts.tv_sec); }; 00127 INT32 getPacketTimeUSec() { return(mPacketHeader.ts.tv_usec); }; 00128 INT32 getPacketTimeNSec() { return(mPacketHeader.ts.tv_nsec); }; 00129 void getPacketTime(timeval * tv) { // sec and usec 00130 tv->tv_sec = mPacketHeader.ts.tv_sec; 00131 tv->tv_usec = mPacketHeader.ts.tv_usec; 00132 return; 00133 }; 00134 void getPacketTime(timespec * ts) { // sec and nsec 00135 ts->tv_sec = mPacketHeader.ts.tv_sec; 00136 ts->tv_nsec = mPacketHeader.ts.tv_nsec; 00137 return; 00138 }; 00139 00140 void getX3cTimeStamp(struct x3c_timeval * xts); 00141 00142 // Utility methods 00143 void printX3cHeader(); 00144 void printPacketHeader(); 00145 void printPacketData(); 00146 00147 // Legacy call, should be removed in the future 00148 int wrX3CHeader(INT32 *fd, UINT32 taskType, UINT32 taskEnum, INT32 thisZone); 00149 // this is not legacy but can be refactored - jtrier 00150 int wrX3CHeader(INT32 *fd, UINT32 taskType, UINT32 taskEnum, INT32 thisZone, 00151 struct timeval tv, UINT32 opt1, UINT32 opt2); 00152 00153 private: 00154 char * mPacketData; // allocated with the createDataBuffer 00155 UINT32 mPacketDataLen; 00156 UINT32 mDataBufferSize; 00157 00158 X3C_HEADER mX3cHeader; 00159 X3C_PACKET_HEADER mPacketHeader; 00160 00161 }; 00162 00163 #endif /* CX3CFILE_H_ */