versadac  1
versadac - Scalable Recorder Firmware
dre_file.h
1 /*****************************************************************************
2 FILE : dre_file.h
3 AUTHOR : Dave Storey
4 SYSTEM : GNU C++ for ARM
5 DESCRIPTION : Data Recording Engine file class declaration.
6  This object handles the recording activity for a single
7  UHH file, using messages forwarded by the DRE task object.
8 *****************************************************************************/
9 
10 #ifndef __DRE_FILE_H
11 #define __DRE_FILE_H
12 
13 #include <stdio.h>
14 
15 #include "dre_msg.h"
16 #include "dre_hmgr.h"
17 #include "dre_buff.h"
18 #include "dre.h"
19 
20 class DreFile
21 {
22 public:
23 
24  // PUBLIC METHODS
25 
26  DreFile(DreHistMgr *z_pHistMgr, uint8 z_uGroup, uint32 z_uBlockSize, uint8 z_uRecStatus);
27  ~DreFile();
28 
29  // Message handlers ('msg' prefix)
30  void msgAlmStat(DRE_MSG_ALARMS_T *z_pMsg);
31  void msgBatchHdr(DRE_BATCH_HDR_T *z_pMsg);
32  void msgBatchStart(DRE_MSG_BATCH_START_T *z_pMsg);
33  void msgBatchStop(DRE_MSG_BATCH_STOP_T *z_pMsg);
34  void msgHdrEnd();
35  void msgHistHdr(DRE_HIST_HDR_T *z_pMsg);
36  void msgLostData();
37  void msgMessage(DRE_MSG_MESSAGE_T *z_pMsg);
38  void msgRecStatus(DRE_MSG_RECSTATUS_T *z_pMsg);
39  void msgRefAlm(DRE_REF_ALM_T *z_pMsg);
40  void msgRefPv(DRE_REF_PV_T *z_pMsg);
41  void msgPointHdr(DRE_PT_HDR_T *z_pMsg);
42  void msgSample(DRE_MSG_SAMPLE_T *z_pMsg);
43  void msgSegHdr(DRE_SEG_HDR_T *z_pMsg);
44  static ENUM_Uhh_ScaleType resToUhhScaleType( ENUM_ScaleType z_nInternalType );
45 
46  void closeStream(FILE **z_pStream, char *z_pFuncName, char *z_pFileName);
47  void disableRecording();
48  void flush();
49  int flushBuffer(char *z_pFuncName, DreBuffer *z_pBuf);
50  void failSlice(char *z_pFuncName, char *z_pDesc);
51  uint8 getGroup(){return(m_uGroup);}
52  FILE *openForAppend(char *z_pFuncName);
53  void recMessageRef();
54  void recRefData();
55  void reopen(double z_dTime, bool z_bBatchStart = FALSE);
56  void setNotRecording();
57  bool startedNewFile() {return(m_uSize == m_uHeaderEnd);}
58  void updateTime(double z_dTime);
59  static bool forceRemove(char *z_szPathName);
60 
61  // Public in-line methods
62  inline DRE_SLICE_T *getSlice() {return m_pSlice;}
63  inline uint32 getSize() {return m_uSize;}
64 
65  // The following are for test use only. In 'test mode' there are minor
66  // changes to file contents, e.g. version numbers, to avoid trivial
67  // differences in regression tests.
68  static inline uint32 getTestMode()
69  {
70  return m_uTestMode;
71  }
72  static inline void setTestMode(uint32 z_uTestMode)
73  {
74  m_uTestMode = z_uTestMode;
75  }
76 
77  // Public linkage (for external use only)
78  DreFile *pNext;
79 
80 private:
81 
82  // Array of constants used by wrTicks for conversions
83 #define MAX_TICK_BYTES 8 // => 56 bits, more than a double can handle
84  static const double s_adPow128[MAX_TICK_BYTES];
85 
86  bool m_bBigEndian; // TRUE if CPU is big-endian
87  bool m_bRecordingActive; // TRUE if recording is in progress
88  DreHistMgr *m_pHistMgr;
89  uint8 m_uGroup;
90  uc_char m_acGroupName[DRE_UHH_GROUP_NAME_L + 1];
91 
92  bool m_bMinmax; // PV min and max values to be stored
93 
94  DRE_SLICE_T *m_pSlice; // The slice this file represents
95  FILE *m_pF; // The file pointer
96  uint32 m_uSize, m_uRefDataRecord, m_uBlockGuide;
97  uint8 m_uRecStatus, m_uOldRecStatus; // Current/old recording status
98  uint32 m_uMsgRecord; // bytes at which last real message recorded
99  uint32 m_uMsgRefRecord; // bytes at which last message reference recorded
100  uint32 m_uHeaderEnd; // Location of end of header records
101  DreBuffer *m_pHeaderBuf, *m_pOldHeaderBuf;
102  DreBuffer *m_pRecordingBuf;
103  DRE_MSG_BATCH_DATA_T m_BatchData;
104  bool m_bBatchActive; // if this is set implies batch running
105  bool m_bOutputBatchHdrs; // if this is set output batch headers
106  uc_char *m_szBatchFileName; // if set then used as part of the history filename
107 
108  uint32 m_uChecksum;
109  bool m_bLostData; // Used to prevent repeated 'lost data' records
110 
111  // Point data: everything we ever need to store on a per-point basis
112  // - a combination of fixed, walking and transient data.
113  struct POINT_T
114  {
115  // Fixed data
116  bool bAnalogue; // TRUE if analogue, ie continuously varying
117  double dOffset; // PV offset added before storing
118  bool bDouble; // PV represented using double vs float format
119  uint8 uBytes; // Number of PV bytes to be stored
120 
121  // Walking data
122  uint8 uBoolData; // Current 'bool data' (colour A/B etc)
123 
124  // Transient data
125  uint8 uBoolDataChg; // Changed bits in bool data
126  };
127 
128  // Value data: everything we ever need to store on a per-value basis
129  // - a combination of walking and transient data.
130  struct VALUE_T
131  {
132  // Walking data
133  union {double dPV; float fPV;}; // Current value
134  uint8 *pPV; // Generic pointer to current value
135  uint8 uStatus; // Current status
136 
137  // Transient data
138  union {double dNewPV; float fNewPV;}; // New value
139  uint8 *pNewPV; // Generic pointer to new value
140  uint8 uCompress; // Compression count
141  uint8 uStatusChg; // Changed bits in status
142  };
143 
144  uint16 m_uNumPts; // Number of points in group
145  uint16 m_uNumVals; // Number of values in group (>m_uNumPts if minmax)
146  uint16 m_uPoint; // Used to keep track of point headers
147  POINT_T *m_aPoint; // Array of point data
148  VALUE_T *m_aValue; // Array of value data
149  uint32 m_uNumAlms; // Total number of alarms in group
150  uint8 *m_auAlmStat; // Array of current alarm statuses
151 
152  // Times and interval (all are in RM ticks)
153  sint32 m_nTimeSegment; // Current time segment number
154  double m_dStartTime; // Time used for start record
155  double m_dNewStartTime; // The new start time
156  double m_dLeaderTime; // Elapsed part of interval at start
157  double m_dCurrentTime; // Time of last data received
158  double m_dSampleTime; // Time of last sample received
159  double m_dInterval; // The current interval
160  double m_dNewInterval; // The new current interval
161 
162  // Time zone raw offset in msec.
163  sint32 m_nTzRawOffset;
164 
165  // Samples per flush
166  uint16 m_uSamplesPerFlush;
167  uint16 m_uCountPerFlush;
168  uint16 m_uSamplesPerCheckFS;
169  uint16 m_uCountPerCheckFS;
170 
171  // Stuff for 'limited flush' strategy (see notes in .cpp)
172  uint8 m_uLtdUnflushed;
173 #define DRE_LTD_BUF_LEN 20
174  double m_adLtdTimesBuf[DRE_LTD_BUF_LEN];
175  double *m_pdLtdTimesEnd;
176  double *m_pdLtdTimesOldest;
177 
178  // Stuff for memory usage estimate
179  uint8 m_uTicksPerSec;
180  uint32 m_uUpdatePeriod;
181  uint32 m_uUpdatePeriodA;
182  uint32 m_uUpdatePeriodB;
183 
184  static uint32 m_uTestMode; // Non-zero for 'test mode'
185 
186 
187  // PRIVATE METHODS
188 
189  void close();
190  uint8 compress(POINT_T *z_pPoint, VALUE_T *z_pValue,
191  DRE_MSG_PV_ETC_T *z_pNew);
192 
193  uc_char * getBatchFileName(DRE_MSG_BATCH_DATA_T *z_pBatchData);
194 
195  void newFile();
196  void terminate(bool z_bNoRefRec = FALSE);
197 
198  // Record writing methods ('rec' prefix)
199  void recInterval(double z_dChange);
200 
201  void updateUsage();
202 
203  // Low-level put functions and selector
204  void putBatchHdr(DRE_MSG_BATCH_DATA_T *z_pMsg, bool z_uStart);
205  void putToRecBuf(uint32 z_uByte); // Put byte to data records buffer
206  void putToHdrBuf(uint32 z_uByte); // Put byte to header buffer
207  bool m_bPutToHdrBuf;
208 
209  // Low-level write methods ('wr' prefix)
210  void wrByte(uint32 z_uVal);
211  void wrChecksumAndFlush(uint8 z_uFlushingStrategy);
212  void wrFloat32(float z_fVal);
213  void wrFloat32(float z_fVal, uint8 z_uBytes);
214  void wrFloat64(double z_dVal);
215  void wrFloat64(double z_dVal, uint8 z_uBytes);
216  void wrRecordId(uint32 z_uVal);
217  void wrSint32(sint32 z_nVal);
218  void wrString(char *z_sz);
219  void wrString(uc_char *z_sz);
220  void wrTicks(double z_dTicks); // Converts double to 'UintF'
221  void wrUint16(uint32 z_uVal);
222  void wrUint32(uint32 z_uVal);
223  void wrUintF(uint32 z_uVal);
224 };
225 
226 #endif
Definition: dre_msg.h:256
Definition: dre_hist.h:19
Definition: dre_msg.h:297
Definition: dre_buff.h:16
Definition: dre_msg.h:51
Definition: dre_file.h:20
Definition: dre_msg.h:172
Definition: dre_msg.h:183
Definition: dre_msg.h:123
Definition: dre_msg.h:245
Definition: dre_msg.h:216
Definition: dre_msg.h:149
Definition: dre_msg.h:204
Definition: dre_hmgr.h:24
Definition: dre_msg.h:63
Definition: dre_msg.h:192
Definition: dre_msg.h:266
Definition: dre_msg.h:156