versadac  1
versadac - Scalable Recorder Firmware
am_historypv.h
1 /*****************************************************************************
2 FILE : am_historypv.h
3 VERSION : $Id: am_historypv.h 4938 2006-10-10 14:20:18Z martinto $
4 AUTHOR : Sandra Herring
5 SYSTEM : GNU C++ for Power PC
6 DESCRIPTION : Header file for a recorded PV.
7 *****************************************************************************/
8 
9 #if !defined(__AM_HISTORYPV_H)
10 #define __AM_HISTORYPV_H
11 
12 #if !defined(__AM_PVDATA_H)
13 #include "am_pvdata.h"
14 #endif
15 
16 class AM_HistoryStream;
17 class AM_HistoryPVConfig;
18 class AM_Timezone;
19 class AM_TimeFormatter;
20 class AM_Archiver;
21 
22 // object used to hold details in AM_HistoryPV, one for max or normal chan and one for min
24 {
25  public:
26  AM_PointStatus m_Status;
27  double m_Value;
28  float m_ValueBeforeOffsetFloat;
29  double m_ValueBeforeOffsetDouble;
30 
31  // working variables used in processing of sample record
32  struct
33  {
34  uint16 pvBytes : 8;
35  uint16 newBoolData : 1;
36  uint16 newStatus : 1;
37  } m_ReceiveData;
38 }; // class AM_HistoryPVDetail
39 
40 class AM_CsvStream;
41 
43 {
44  public :
45 
46 /*------------------------------------------------------------------------------
47 FUNCTION : AM_HistoryPV constructor
48 DESCRIPTION :
49 ARGUMENTS :
50 RETURN : N/A
51 NOTES :
52 ------------------------------------------------------------------------------*/
53  AM_HistoryPV();
54 
55  // pure virtual services
56 
57 /*------------------------------------------------------------------------------
58 FUNCTION : AM_HistoryPV::readValue
59 DESCRIPTION : pure virtual service to read this object's compressed PV from
60  the current position in the Archive stream and
61  update the current value.
62 ARGUMENTS : stream : pointer to open archive file stream.
63 RETURN : TRUE if data read in successfully, otherwise FALSE.
64 NOTES :
65 ------------------------------------------------------------------------------*/
66  virtual sint32 readValue( AM_HistoryStream & stream ) = 0;
67 
68  // non-pure virtual services
69 
70 /*------------------------------------------------------------------------------
71 FUNCTION : AM_HistoryPV::extractDataStoredFlags
72 DESCRIPTION : virtual service to parse the "data stored" flags assigned to
73  this sample in the received data record.
74 ARGUMENTS : dataStored : data stored flags for this PV.
75  index index of pv this data applies to
76  Call first with 0, then return indicates whether it
77  needs to be called again with 1
78 RETURN : TRUE if it must be called with another value for the second pv
79 NOTES : base class copies flags into object.
80 ------------------------------------------------------------------------------*/
81  virtual bool extractDataStoredFlags( uint8 dataStored, int index );
82 
83  // non-virtual services
84 
85 /*------------------------------------------------------------------------------
86 FUNCTION : AM_HistoryPV::extractBoolData
87 DESCRIPTION : service to parse the boolean data
88  assigned to this sample in the received data record.
89 ARGUMENTS : boolData : boolean data for this PV.
90 RETURN : None.
91 NOTES :
92 ------------------------------------------------------------------------------*/
93  void extractBoolData( uint8 boolData );
94 
95 /*------------------------------------------------------------------------------
96 FUNCTION : AM_HistoryPV::extractXorBoolData
97 DESCRIPTION : service to parse the boolean data
98  assigned to this sample in the received data record. where the data
99  is to be xor'd with current value
100 ARGUMENTS : boolData : boolean data for this PV.
101 RETURN : None.
102 NOTES :
103 ------------------------------------------------------------------------------*/
104  void extractXorBoolData( uint8 boolData );
105 
106 /*------------------------------------------------------------------------------
107 FUNCTION : AM_HistoryPV::init
108 DESCRIPTION : Resets PV value and status for start of file read.
109 ARGUMENTS : None.
110 RETURN : None.
111 NOTES :
112 ------------------------------------------------------------------------------*/
113  void init();
114 
115 /*------------------------------------------------------------------------------
116 FUNCTION : AM_HistoryPV::newBoolData
117 DESCRIPTION : service to return whether boolean data has been flagged
118  as arriving in this sample.
119 ARGUMENTS : None.
120 RETURN : TRUE if boolean data expected for this PV, FALSE if not.
121 NOTES :
122 ------------------------------------------------------------------------------*/
123  bool newBoolData();
124 
125 /*------------------------------------------------------------------------------
126 FUNCTION : AM_HistoryPV::readAlarms
127 DESCRIPTION : service to read the alarm bytes for this PV
128  from the current position in the Archive stream.
129 ARGUMENTS : stream : pointer to open archive file stream.
130 RETURN : TRUE if data read in successfully, otherwise FALSE.
131 NOTES :
132 ------------------------------------------------------------------------------*/
133  bool readAlarms( AM_HistoryStream & stream );
134 
135 /*------------------------------------------------------------------------------
136 FUNCTION : AM_HistoryPV::readReferenceValue
137 DESCRIPTION : service to read this object's initial pv value from uhh file
138  reference data record
139 ARGUMENTS : stream : pointer to open archive file stream.
140 RETURN : TRUE if data read in successfully, otherwise FALSE.
141 NOTES :
142 ------------------------------------------------------------------------------*/
143  sint32 readReferenceValue( AM_HistoryStream & stream );
144 
145 /*------------------------------------------------------------------------------
146 FUNCTION : AM_HistoryPV::readStatus
147 DESCRIPTION : service to read the status byte(s) for this PV
148  from the current position in the Archive stream.
149 ARGUMENTS : stream : pointer to open archive file stream.
150  bunconditionalStatus if set then status bytes are always expected
151  (used in reference record in uhh files)
152 RETURN : TRUE if data read in successfully, otherwise FALSE.
153 NOTES :
154 ------------------------------------------------------------------------------*/
155  sint32 readStatus( AM_HistoryStream & stream, bool bUnconditionalStatus );
156 
157 /*------------------------------------------------------------------------------
158 FUNCTION : AM_HistoryPV::readXorStatus
159 DESCRIPTION : service to read the status byte for this PV
160  from the current position in the Archive stream, using xor to
161  modify existing value
162 ARGUMENTS : stream : pointer to open archive file stream.
163 RETURN : TRUE if data read in successfully, otherwise FALSE.
164 NOTES :
165 ------------------------------------------------------------------------------*/
166  sint32 readXorStatus( AM_HistoryStream & stream );
167 
168 /*------------------------------------------------------------------------------
169 FUNCTION : AM_HistoryPV::FetNumPvs
170 DESCRIPTION : Returns up no of pvs.
171 ARGUMENTS :
172 RETURN : 1 for normal, 2 for min/max
173 NOTES :
174 ------------------------------------------------------------------------------*/
175  uint8 GetNumPvs();
176 
177 /*------------------------------------------------------------------------------
178 FUNCTION : AM_HistoryPV::SetNumPvs
179 DESCRIPTION : Sets up no of pvs. 1 for normal, 2 for min/max
180 ARGUMENTS : no of ps
181 RETURN : None.
182 NOTES :
183 ------------------------------------------------------------------------------*/
184  void SetNumPvs( uint8 nNumPvs );
185 
186 /*------------------------------------------------------------------------------
187 FUNCTION : AM_HistoryPV::GetValue
188 DESCRIPTION : Returns value of the pv(s) at time of the sample.
189 ARGUMENTS : pv index, 0 or 1
190 RETURN : PV value
191 NOTES :
192 ------------------------------------------------------------------------------*/
193  double GetValue( uint8 index );
194 
195 /*------------------------------------------------------------------------------
196 FUNCTION : AM_HistoryPV::SetOffset
197 DESCRIPTION :
198 ARGUMENTS : Offset to apply to value after uncompression.
199 RETURN : None.
200 NOTES :
201 ------------------------------------------------------------------------------*/
202  void SetOffset( double offset );
203 
204 /*------------------------------------------------------------------------------
205 FUNCTION : AM_HistoryPV::SetNumBytes
206 DESCRIPTION : service to set number of bytes in data record
207 ARGUMENTS : bytes number of bytes
208 RETURN :
209 NOTES :
210 ------------------------------------------------------------------------------*/
211  void SetNumBytes( uint16 bytes );
212 
213 /*------------------------------------------------------------------------------
214 FUNCTION : AM_HistoryPV::SetPvDouble
215 DESCRIPTION : service to set whether pv is a double or a float
216 ARGUMENTS : bPvDouble whether double or not (ie single)
217 RETURN :
218 NOTES :
219 ------------------------------------------------------------------------------*/
220  void SetPvDouble( bool bPvDouble );
221 
222 /*------------------------------------------------------------------------------
223 FUNCTION : AM_HistoryPV::linkConfig
224 DESCRIPTION : service to attach the specified configuration to this data point
225 ARGUMENTS : configuration object
226 RETURN : None.
227 NOTES :
228 ------------------------------------------------------------------------------*/
229  void linkConfig( AM_HistoryPVConfig *_pConfig );
230 
231 /*---------------------------------------------------------------------------
232 FUNCTION : formatForSpreadsheet
233 DESCRIPTION : Provides formatted point value at given timestamp
234 ARGUMENTS : index which of the min & max readings to format
235  pBuf where to put the string
236  csvStream output options and time zone
237  timeFormatter formatter for date/time format PV
238 RETURN :
239 NOTES :
240 ---------------------------------------------------------------------------*/
241  char * formatForSpreadsheet( uint8 index,
242  char * pBuf,
243  AM_CsvStream & csvStream,
244  AM_TimeFormatter & timeFormatter );
245 
246  // attributes
247  protected :
248  AM_HistoryPVConfig *m_pConfig;
249  double m_Offset; // Offset applied to value after uncompression
250  uint16 m_uhhBytes; // num of bytes for uhh files only
251  bool m_bPvDouble; // for uhh files indicates that value is double (else float)
252 
253  // details for max(or normal) and min channel
254  uint8 m_nNumPvs; // 1 for normal, 2 for max/min
255  AM_HistoryPVDetail m_Detail[2];
256 
257  struct
258  {
259  bool on;
260  bool ackd;
261  } m_Alarm[4];
262 
263 }; // class AM_HistoryPV
264 
265 
266 // ********************************************
267 // inline services for History PV Sample class
268 // ********************************************
269 
270 /*------------------------------------------------------------------------------
271 FUNCTION : AM_HistoryPV::linkConfig
272 DESCRIPTION : service to attach the specified configuration to this data point
273 ARGUMENTS : configuration object
274 RETURN : None.
275 NOTES :
276 ------------------------------------------------------------------------------*/
277 inline void AM_HistoryPV::linkConfig( AM_HistoryPVConfig * pConfig )
278 {
279  m_pConfig = pConfig;
280 }
281 
282 /*------------------------------------------------------------------------------
283 FUNCTION : AM_HistoryPV::newBoolData
284 DESCRIPTION : service to return whether boolean data has been flagged
285  as arriving in this sample.
286 ARGUMENTS : None.
287 RETURN : TRUE if boolean data expected for this PV, FALSE if not.
288 NOTES :
289 ------------------------------------------------------------------------------*/
290 inline bool AM_HistoryPV::newBoolData()
291 {
292  // this is always the first chan as second pv does not have separate bool data
293  return m_Detail[0].m_ReceiveData.newBoolData;
294 }
295 
296 
297 /*------------------------------------------------------------------------------
298 FUNCTION : AM_HistoryPV::SetOffset
299 DESCRIPTION :
300 ARGUMENTS : Offset to apply to value after uncompression.
301 RETURN : None.
302 NOTES :
303 ------------------------------------------------------------------------------*/
304 inline void AM_HistoryPV::SetOffset( double offset )
305 {
306  m_Offset = offset;
307 }
308 
309 /*------------------------------------------------------------------------------
310 FUNCTION : AM_HistoryPV::SetNumBytes
311 DESCRIPTION : service to set number of bytes in data record
312 ARGUMENTS : bytes number of bytes
313 RETURN :
314 NOTES :
315 ------------------------------------------------------------------------------*/
316 inline void AM_HistoryPV::SetNumBytes( uint16 bytes )
317 {
318  m_uhhBytes = bytes;
319 }
320 
321 /*------------------------------------------------------------------------------
322 FUNCTION : AM_HistoryPV::SetPvDouble
323 DESCRIPTION : service to set whether pv is a double or a float
324 ARGUMENTS : bPvDouble whether double or not (ie single)
325 RETURN :
326 NOTES :
327 ------------------------------------------------------------------------------*/
328 inline void AM_HistoryPV::SetPvDouble( bool bPvDouble )
329 {
330  m_bPvDouble = bPvDouble;
331 }
332 
333 /*------------------------------------------------------------------------------
334 FUNCTION : AM_HistoryPV::GetNumPvs
335 DESCRIPTION : Returns no of pvs.
336 ARGUMENTS :
337 RETURN : 1 for normal, 2 for min/max
338 NOTES :
339 ------------------------------------------------------------------------------*/
340 inline uint8 AM_HistoryPV::GetNumPvs()
341 {
342  return m_nNumPvs;
343 }
344 
345 /*------------------------------------------------------------------------------
346 FUNCTION : AM_HistoryPV::SetNumPvs
347 DESCRIPTION : Sets up no of pvs. 1 for normal, 2 for min/max
348 ARGUMENTS : no of ps
349 RETURN : None.
350 NOTES :
351 ------------------------------------------------------------------------------*/
352 inline void AM_HistoryPV::SetNumPvs( uint8 nNumPvs )
353 {
354  m_nNumPvs = nNumPvs;
355 }
356 
357 /*------------------------------------------------------------------------------
358 FUNCTION : AM_HistoryPV::GetValue
359 DESCRIPTION : Returns value of the pv(s) at time of the sample.
360 ARGUMENTS : pv index, 0 or 1
361 RETURN : PV value
362 NOTES :
363 ------------------------------------------------------------------------------*/
364 inline double AM_HistoryPV::GetValue( uint8 index )
365 {
366  return m_Detail[index].m_Value;
367 }
368 
369 #endif // end of __AM_HISTORYPV_H conditional include
370 
Definition: am_historystream.h:23
Definition: am_historypvconf.h:24
Definition: am_historypv.h:42
Definition: am_archiver.h:90
Definition: am_historypv.h:23
Definition: am_pvdata.h:21
Definition: am_csvstream.h:62
Definition: am_timezone.h:75
Definition: am_timeformatter.h:21