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 #include "Lf1PacketHeader.h" 00025 00026 //Logger FILE TYPE SUFFIX, as in "myDataFile.x3c" 00027 //Note there is not '.' file type separator defined here. 00028 //History: For the first year and a half (2010, 2011) the Logger used the ".x3c" 00029 // File Suffix for DATA files. This was change to .lf1 Feb 28, 2012. 00030 #define SUFFIX_LF1 00031 #ifdef SUFFIX_LF1 00032 #define LOGDATA_FILE_SUFFIX_STR "lf1" 00033 #else 00034 #define LOGDATA_FILE_SUFFIX_STR "x3c" 00035 #endif 00036 00037 #define X3C_MAGIC 0x58334321 00038 #define X3C_VERSION_MINOR 0x0001 00039 #define X3C_VERSION_MAJOR 0x0000 00040 00041 //struct x3c_timeval is now defined in Lf1PacketHeader.h 00042 00043 // GLOBAL FILE HEADER 00044 typedef struct _X3C_HEADER_ { 00045 UINT32 magic; /* magic number */ 00046 UINT16 version_major; /* major version number */ 00047 UINT16 version_minor; /* minor version number */ 00048 UINT16 task_type; /* defines data source */ 00049 UINT16 task_enum; 00050 struct x3c_timeval ts; /* File Creation time */ 00051 INT32 thiszone; /* GMT to local correction */ 00052 UINT32 opt[2]; /* optional data */ 00053 }X3C_HEADER; 00054 00056 00057 00058 class CX3cFile { 00059 public: 00060 CX3cFile(); 00061 virtual ~CX3cFile(); 00062 00063 // Initialize Data Buffer 00064 int createDataBuffer(int len); 00065 unsigned getDataBufferSize() { return(mDataBufferSize); }; 00066 00067 // TBD 00068 X3C_HEADER * getX3cHeaderPtr() { return(&mX3cHeader); }; 00069 X3C_PACKET_HEADER * getPacketHeaderPtr() { return(&mPacketHeader); }; 00070 int setX3cHeader(X3C_HEADER * pX3cHeader); 00071 int setPacketHeader(X3C_PACKET_HEADER * pPacketHeader); 00072 00073 int getX3cHeaderLen() { return(sizeof(X3C_HEADER)); }; 00074 int getPacketHeaderLen() { return(sizeof(X3C_PACKET_HEADER)); }; 00075 int getPacketLen() { return((int)(sizeof(X3C_PACKET_HEADER) + mPacketDataLen)); }; 00076 00077 // Get/Set Packet Data 00078 char * getPacketDataPtr() { return(mPacketData); }; 00079 unsigned getPacketDataLen() { return(mPacketDataLen); }; 00080 int setPacketData(char * buffer, UINT32 len); 00081 void setPacketDataLen(UINT32 len) { mPacketDataLen = len; }; 00082 00083 00084 // Get/Set X3C_Header 00085 unsigned getX3cMagicNumber() { return(mX3cHeader.magic); }; 00086 UINT16 getX3cVersionMajor() { return(mX3cHeader.version_major); }; 00087 UINT16 getX3cVersionMinor() { return(mX3cHeader.version_minor); }; 00088 UINT16 getX3cTaskType() { return(mX3cHeader.task_type); }; 00089 UINT16 getX3cTaskEnum() { return(mX3cHeader.task_enum); }; 00090 INT32 getX3cTimeZone() { return(mX3cHeader.thiszone); }; 00091 unsigned getX3cOpt1() { return(mX3cHeader.opt[0]); }; 00092 unsigned getX3cOpt2() { return(mX3cHeader.opt[1]); }; 00093 unsigned getX3cTimeSec() { return(mX3cHeader.ts.tv_sec); }; 00094 unsigned getX3cTimeUSec() { return(mX3cHeader.ts.tv_usec); }; 00095 unsigned getX3cTimeNSec() { return(mX3cHeader.ts.tv_nsec); }; 00096 void getX3cTime(timeval * tv) { // sec and usec 00097 tv->tv_sec = mX3cHeader.ts.tv_sec; 00098 tv->tv_usec = mX3cHeader.ts.tv_usec; 00099 return; 00100 }; 00101 void getX3cTime(timespec * ts) { // sec and nsec 00102 ts->tv_sec = mX3cHeader.ts.tv_sec; 00103 ts->tv_nsec = mX3cHeader.ts.tv_nsec; 00104 return; 00105 }; 00106 00107 // Get/Set X3C_PACKET_HEADER 00108 UINT32 getPacketDataLength() { return(mPacketHeader.len); }; 00109 unsigned getPacketTimeSec() { return(mPacketHeader.ts.tv_sec); }; 00110 unsigned getPacketTimeUSec() { return(mPacketHeader.ts.tv_usec); }; 00111 unsigned getPacketTimeNSec() { return(mPacketHeader.ts.tv_nsec); }; 00112 void getPacketTime(timeval * tv) { // sec and usec 00113 tv->tv_sec = mPacketHeader.ts.tv_sec; 00114 tv->tv_usec = mPacketHeader.ts.tv_usec; 00115 return; 00116 }; 00117 void getPacketTime(timespec * ts) { // sec and nsec 00118 ts->tv_sec = mPacketHeader.ts.tv_sec; 00119 ts->tv_nsec = mPacketHeader.ts.tv_nsec; 00120 return; 00121 }; 00122 00123 void getX3cTimeStamp(struct x3c_timeval * xts); 00124 00125 // Utility methods 00126 void printX3cHeader(); 00127 void printPacketHeader(); 00128 void printPacketData(); 00129 00130 // Legacy call, should be removed in the future 00131 int wrX3CHeader(INT32 *fd, UINT32 taskType, UINT32 taskEnum, INT32 thisZone); 00132 // this is not legacy but can be refactored - jtrier 00133 int wrX3CHeader(INT32 *fd, UINT32 taskType, UINT32 taskEnum, INT32 thisZone, 00134 struct timeval tv, UINT32 opt1, UINT32 opt2); 00135 00136 private: 00137 char * mPacketData; // allocated with the createDataBuffer 00138 UINT32 mPacketDataLen; 00139 UINT32 mDataBufferSize; 00140 00141 X3C_HEADER mX3cHeader; 00142 X3C_PACKET_HEADER mPacketHeader; 00143 00144 }; 00145 00146 #endif /* CX3CFILE_H_ */