versadac  1
versadac - Scalable Recorder Firmware
uhh_filewalker.h
1 /*****************************************************************************
2 FILE : U H H _ F I L E W A L K E R . H
3 VERSION : $Id: uhh_filewalker.h 4938 2006-10-10 14:20:18Z martinto $
4 AUTHOR : Dave Storey
5 SYSTEM : Gnu C++
6 DESCRIPTION : UHH file-walker class. This is used to walk a single UHH file.
7 *****************************************************************************/
8 
9 #if !defined __UHH_FILEWALKER_H
10 #define __UHH_FILEWALKER_H
11 
12 #include "uhh_heap.h"
13 #include "uhh_grouphist.h"
14 #include "uhh_dataitem.h"
15 #include "uhh_messageitem.h"
16 #include "ENUM_UhhMsg_Err.h"
17 #include "ENUM_Uhh_ScaleType.h"
18 #include "ENUM_ScaleType.h"
19 
20 #include <stdio.h>
21 
22 
23 // Walk codes - these report what happened when the file walker was asked to
24 // walk through the file using next/prevDataRecord(...).
25 
26 enum ENUM_UhhWalkCode {
27  ENUM_UhhWalkCode_Progressed,
28  ENUM_UhhWalkCode_HitTime,
29  ENUM_UhhWalkCode_HitSample,
30  ENUM_UhhWalkCode_HitMessage
31 };
32 
33 
34 
35 class UhhFileWalker : public UhhHeap
36 {
37 public:
38  UhhFileWalker();
39  ~UhhFileWalker();
40  void close();
41  ENUM_UhhMsg_Err getBasicInfo();
42  bool isOpen();
43  ENUM_UhhMsg_Err nextDataRecord(ENUM_UhhWalkCode *z_peCode,
44  double z_dTixMax);
45  ENUM_UhhMsg_Err open(UhhSlice *z_pSlice);
46  ENUM_UhhMsg_Err prepareWalking(UhhDataItem *z_pWalkData,UhhMessageItem *z_pMsgWalkItem,
47  bool z_bAcquireSamp, bool z_bAcquireMsgs);
48  ENUM_UhhMsg_Err prevDataRecord(ENUM_UhhWalkCode *z_peCode,
49  double z_dTixMin,
50  bool z_bStopAtSample);
51  ENUM_UhhMsg_Err prevMsgRecord(ENUM_UhhWalkCode *z_peCode,
52  double z_dEarliestTix);
53  void setMessageFilter(sint32 z_nCategories);
54  void setMessageAcquisition(bool z_bAcquire);
55  ENUM_UhhMsg_Err setTix(double z_dTix);
56  ENUM_UhhMsg_Err setTixEarliest();
57  ENUM_UhhMsg_Err setTixLatest();
58 
59  static ENUM_ScaleType uhhToResScaleType( ENUM_Uhh_ScaleType z_nUhhType );
60 
61 private:
62 
63  // PRIVATE STRUCTURES
64 
65 
66  // Block structure used to build the 'scaffolding'.
67  // A 'block' corresponds to a section of the file between two ref records.
68 
69  struct Block {
70  Block *pEarlier;
71  Block *pLater;
72  double dTix;
73  sint32 nSeek;
74  };
75 
76 
77  // Data value union used for encoding values
78 
79  union ValU
80  {
81  double d; // Value, if represented as a double
82  float f; // Value, if represented as a float
83  uint8 au[8]; // Access to individual bytes
84  };
85 
86 
87  // Info required for walking on a per-value basis
88 
89  struct WalkVal
90  {
91  ValU Val;
92  uint8 uComp;
93  bool bStatus;
94  };
95 
96 
97  // Info required for walking on a per-point basis
98 
99  struct WalkPoint
100  {
101  bool bBoolData;
102  uint8 uBoolData;
103  WalkVal aVals[2]; // never need more than 2 (min-max)
104  };
105 
106 
107 
108  // PRIVATE MEMBERS
109 
110  bool m_bBigEndian;
111 
112  FILE *m_pF; // The file pointer
113  UhhSlice *m_pSlice; // The slice corresponding to the file
114  UhhSegHdr *m_pSegHdr; // Current segment header
115  UhhHistHdr *m_pHistHdr; // Current history header
116 
117  // Scaffolding
118  Block *m_pBlkEarliest;
119  Block *m_pBlkLatest;
120 
121  // Main cache - holds file contents between 2 reference data records
122  Block *m_pCacheBlock;
123  sint32 m_nCacheSize;
124  uint8 *m_puCache;
125  uint8 *m_puCacheEnd;
126 
127  // Basic cache - used before main cache established
128  // Reuses some main cache stuff, plus:
129  sint32 m_nBcacheSize; // Basic cache size
130  sint32 m_nBcacheOffset; // Current offset into file
131  sint32 m_nBcachePrefSeekOffset; // Preferred offset for seek
132 
133  // Current framed record in cache
134  uint8 *m_puRecStart; // Start of record
135  uint8 *m_puRecData; // Start of data bytes
136  uint8 *m_puRecChecksum; // Checksum
137  uint8 *m_puRecEnd; // End of record (ie start of next)
138  sint32 m_nRecId; // Record Id, ie type of record
139  double m_dRecTix; // Time of record, where relevant
140  uint8 *m_puRead; // Used to read data
141 
142  // Walking data
143  bool m_bInLeader;
144  bool m_bInTrailer;
145  double m_dTixWalkInterval;
146  double m_dTixWalkSample;
147  UhhDataItem *m_pWalkItem; // NB normally externally owned
148  UhhMessageItem *m_pMsgWalkItem;
149  uint16 m_uWalkPoints; // Size of array below
150  WalkPoint *m_pWalkPoints; // Allocated array
151  uint8 *m_puWalk; // Cache pointer for current walk position
152 
153  // UHH file walker pass count used for processor sharing
154  uint16 m_uWalkerPass; // Count of uhh file walker passes
155 
156 
157 
158 
159  // The following two entities apply when ONLY navigating for messages
160  sint32 m_lPrevMsgOffset; // offset in the file to the previous message
161  double m_dMsgCurrentPtime; // current time at which to start msg retrieval
162 
163  sint32 m_nMsgFilter; // bitmask representing categories of
164  // interest when retrieving ONLY messages
165  // Modes
166  bool m_bAcquireSamp;
167  bool m_bAcquireMsgs;
168  bool m_bVerifyChecksum;
169 
170  // Internal mode to enable/disable acquisition of messages, counts etc
171  bool m_bAcquire;
172 
173 
174  // PRIVATE METHODS
175 
176  // Basic cache file reading (method names prefixed with 'b')
177  ENUM_UhhMsg_Err bFindEndOrRef(sint32 *z_pnSeek);
178  ENUM_UhhMsg_Err bFindMsg(sint32 *z_pnSeek);
179  ENUM_UhhMsg_Err bInit(sint32 z_nMaxSize, sint32 z_nPrefSeekOffset);
180  ENUM_UhhMsg_Err bRead(sint32 *z_pnByte);
181  ENUM_UhhMsg_Err bReadFlexDouble(double *z_pdValue);
182  ENUM_UhhMsg_Err bReadFlexInt(sint32 *z_pnValue);
183  ENUM_UhhMsg_Err bReadMetabyte(sint32 *z_pnValue);
184  ENUM_UhhMsg_Err bReadSint32(sint32 *z_pnValue);
185  ENUM_UhhMsg_Err bReadUint8(uint8 *z_puValue);
186  ENUM_UhhMsg_Err bSeek(sint32 z_nPosition);
187 
188  // Cached block file reading (method names prefixed with 'c')
189  ENUM_UhhMsg_Err cFindNextRecord(sint32 z_nIdMin, sint32 z_nIdMax);
190  ENUM_UhhMsg_Err cFrameNextRecord();
191  ENUM_UhhMsg_Err cFramePrevRecord();
192  ENUM_UhhMsg_Err cLoad(Block *z_pBlock);
193  ENUM_UhhMsg_Err cLoadOffset(sint32 z_nOffset);
194  ENUM_UhhMsg_Err cNextDataRecord(enum ENUM_UhhWalkCode *z_peCode,
195  double z_dTixMax);
196  ENUM_UhhMsg_Err cPrevDataRecord(enum ENUM_UhhWalkCode *z_peCode,
197  double z_dTixMax,
198  bool z_bStopAtSample);
199  ENUM_UhhMsg_Err cPrevMsgRecord(enum ENUM_UhhWalkCode *z_peCode,
200  double z_dTixMin);
201  ENUM_UhhMsg_Err cReadDouble(double *z_pdValue,
202  sint32 z_nBytes = sizeof(double));
203  ENUM_UhhMsg_Err cReadFlexDouble(double *z_dValue);
204  ENUM_UhhMsg_Err cReadFlexInt(sint32 *z_pValue);
205  ENUM_UhhMsg_Err cReadFloat(float *z_pfValue,
206  sint32 z_nBytes = sizeof(float));
207  ENUM_UhhMsg_Err cReadHistoryHeader();
208  ENUM_UhhMsg_Err cReadInterval(double *z_pdTix);
209  ENUM_UhhMsg_Err cReadRefData();
210  ENUM_UhhMsg_Err cReadSample();
211  ENUM_UhhMsg_Err cReadSegmentHeader();
212  ENUM_UhhMsg_Err cReadSint32(sint32 *z_pnValue);
213  ENUM_UhhMsg_Err cReadString(uc_char **z_pszValue);
214  ENUM_UhhMsg_Err cReadTix(double *z_pdValue);
215  ENUM_UhhMsg_Err cReadUint16(uint16 *z_puValue);
216  ENUM_UhhMsg_Err cReadUint8(uint8 *z_puValue);
217  void cSkipBytes(sint32 z_BytesToSkip);
218  ENUM_UhhMsg_Err cVerifyRefData();
219 
220  ENUM_UhhMsg_Err checkLastBlock();
221  ENUM_UhhMsg_Err createScaffold();
222 
223  void inLeader();
224  void inTrailer();
225 
226 };
227 
228 
229 
230 #endif
Definition: uhh_seghdr.h:116
Definition: uhh_dataitem.h:53
Definition: uhh_messageitem.h:17
Definition: uhh_histhdr.h:14
Definition: uhh_filewalker.h:35
Definition: uhh_heap.h:31
Definition: uhh_grouphist.h:52