versadac  1
versadac - Scalable Recorder Firmware
am_historydata.h
1 /*****************************************************************************
2 FILE : am_historydata.h
3 VERSION : $Id: am_historydata.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 recorded PV data.
7 *****************************************************************************/
8 
9 #if !defined(__AM_HISTORYDATA_H)
10 #define __AM_HISTORYDATA_H
11 
12 #if !defined(__LINKLIST_H)
13 #include "linklist.h"
14 #endif
15 
16 #if !defined(__AM_HISTORYXORPV_H)
17 #include "am_historyxorpv.h"
18 #endif
19 
20 #if !defined(__AM_HISTORYRECORD_H)
21 #include "am_historyrecord.h"
22 #endif
23 
24 #if !defined(__AM_HISTORYHDR_H)
25 #include "am_historyhdr.h"
26 #endif
27 
28 class AM_HistoryPVConfig;
29 
31 {
32  public :
33 
34 /*------------------------------------------------------------------------------
35 FUNCTION : AM_HistoryData constructor
36 DESCRIPTION :
37 ARGUMENTS : headerPtrPtr - address of pointer to header object., note that
38  pointer itself may not be set up at construction time
39 RETURN : N/A
40 NOTES :
41 ------------------------------------------------------------------------------*/
43 
44 /*------------------------------------------------------------------------------
45 FUNCTION : AM_HistoryData destructor
46 DESCRIPTION :
47 ARGUMENTS : N/A
48 RETURN : N/A
49 NOTES : Calls clear() which then calls the destructItem() function
50  for each item in the record.
51 ------------------------------------------------------------------------------*/
52  virtual ~AM_HistoryData();
53 
54  // virtual services inherited from class AM_HistoryRecord
55  virtual sint32 read( AM_HistoryStream & stream );
56  virtual uint16 recordID();
57 
58  // non-virtual services
59 
60 /*------------------------------------------------------------------------------
61 FUNCTION : AM_HistoryData::create
62 DESCRIPTION : creates array for PV data.
63 ARGUMENTS :
64 RETURN : None.
65 NOTES :
66 ------------------------------------------------------------------------------*/
67  void create();
68 
69 /*------------------------------------------------------------------------------
70 FUNCTION : AM_HistoryData::init
71 DESCRIPTION : Resets PV values and status for start of file read.
72 ARGUMENTS : None.
73 RETURN : None.
74 NOTES :
75 ------------------------------------------------------------------------------*/
76  void init();
77 
78 /*------------------------------------------------------------------------------
79 FUNCTION : readIntervalIncrease
80 DESCRIPTION : service to read in an interval increase record
81  from current position in archive file.
82 ARGUMENTS : stream : pointer to open archive file stream.
83 RETURN : TRUE if data read in successfully, otherwise FALSE.
84 NOTES :
85 ------------------------------------------------------------------------------*/
86  sint32 readIntervalIncrease( AM_HistoryStream & stream );
87 
88 /*------------------------------------------------------------------------------
89 FUNCTION : readIntervalDecrease
90 DESCRIPTION : service to read in an interval increase record
91  from current position in archive file.
92 ARGUMENTS : stream : pointer to open archive file stream.
93 RETURN : TRUE if data read in successfully, otherwise FALSE.
94 NOTES :
95 ------------------------------------------------------------------------------*/
96  sint32 readIntervalDecrease( AM_HistoryStream & stream );
97 
98 /*------------------------------------------------------------------------------
99 FUNCTION : readReferenceRecord
100 DESCRIPTION : service to read in a Reference data record
101  from current position in archive file.
102 ARGUMENTS : stream : pointer to open archive file stream.
103 RETURN : TRUE if data read in successfully, otherwise FALSE.
104 NOTES :
105 ------------------------------------------------------------------------------*/
106  sint32 readReferenceRecord( AM_HistoryStream & stream );
107 
108 /*------------------------------------------------------------------------------
109 FUNCTION : AM_HistoryData::setPvParameters
110 DESCRIPTION : transfer parameters from configs to pv objects
111 ARGUMENTS : None.
112 RETURN : None.
113 NOTES :
114 ------------------------------------------------------------------------------*/
115  void setPvParameters();
116 
117 /*---------------------------------------------------------------------------
118 FUNCTION : getTimestamp
119 DESCRIPTION : Returns the time of the samples in UTC.
120 ARGUMENTS : Object for converting ticks to seconds.
121  Optional return argument for number of milliseconds
122 RETURN : UTC time + milliseconds over
123 NOTES :
124 ------------------------------------------------------------------------------*/
125  time_t getTimestamp( AM_HistoryHeader & ticksConverter,
126  uint16 * pRetMillisecs );
127 
128 /*---------------------------------------------------------------------------
129 FUNCTION : AM_HistoryData::getTicksSinceStart
130 DESCRIPTION : Returns offset in ticks of last sample from start time.
131 ARGUMENTS : None.
132 RETURN : Sample time stamp, in ticks since start of log.
133 NOTES :
134 ---------------------------------------------------------------------------*/
135  double getTicksSinceStart();
136 
137 /*---------------------------------------------------------------------------
138 FUNCTION : AM_HistoryData::getSamples
139 DESCRIPTION : Returns the values from the latest sample
140 ARGUMENTS : Exit parameter for number of samples
141 RETURN : COntiguous array of sample data
142 NOTES :
143 ---------------------------------------------------------------------------*/
144  AM_HistoryXORPV * getSamples( uint16 * pNumOfSamples );
145 
146  private :
147 
148  LinkedList<AM_HistoryPVConfig> *m_pPointConfigs;
149  AM_HistoryXORPV * m_pSamples;
150  uint16 m_NoOfPoints;
151 
152  // this is the timestamp of the current sample
153  double m_TicksSinceStart; // ticks since start of log
154  // interval between this sample and the last one. Used to detect change in sample interval.
155  // It is set to m_OngoingSampleIntervalTicks
156  // when new sample is being read and then used to determine new timestamp rel to current one
157  double m_DeltaTicks;
158  // The current sample interval, used to intialise m_ticksToNextSample when a
159  // sample is read
160  double m_OngoingSampleIntervalTicks;
161  // number of ticks to next sample, used to determine new timestamp when a sample
162  // is read
163  double m_TicksToNextSample;
164  bool m_bFirstReferenceRecordSeen;
165 
166 }; // class AM_HistoryData
167 
168 
169 // ***************************************
170 // inline services for class AM_HistoryData
171 // ***************************************
172 
173 /*---------------------------------------------------------------------------
174 FUNCTION : getTimestamp
175 DESCRIPTION : Returns the time of the samples in UTC.
176 ARGUMENTS : Object for converting ticks to seconds.
177  Optional return argument for number of milliseconds
178 RETURN : UTC time + milliseconds over
179 NOTES :
180 ------------------------------------------------------------------------------*/
181 inline time_t AM_HistoryData::getTimestamp( AM_HistoryHeader & ticksConverter,
182  uint16 * pRetMillisecs )
183 {
184  return ticksConverter.ticksToUtc(ticksConverter.getStartTimeTicks()+
185  m_TicksSinceStart, pRetMillisecs);
186 }
187 
188 /*---------------------------------------------------------------------------
189 FUNCTION : AM_HistoryData::getTicksSinceStart
190 DESCRIPTION : Returns offset in ticks of last sample from start time.
191 ARGUMENTS : None.
192 RETURN : Sample time stamp, in ticks since start of log.
193 NOTES :
194 ---------------------------------------------------------------------------*/
195 inline double AM_HistoryData::getTicksSinceStart()
196 {
197  return m_TicksSinceStart;
198 }
199 
200 /*---------------------------------------------------------------------------
201 FUNCTION : AM_HistoryData::getSamples
202 DESCRIPTION : Returns the values from the latest sample
203 ARGUMENTS : Exit parameter for number of samples
204 RETURN : COntiguous array of sample data
205 NOTES :
206 ---------------------------------------------------------------------------*/
207 inline AM_HistoryXORPV * AM_HistoryData::getSamples( uint16 * pNumOfSamples = NULL )
208 {
209  if (pNumOfSamples != NULL)
210  *pNumOfSamples = m_NoOfPoints;
211 
212  return m_pSamples;
213 }
214 
215 #endif // end of __AM_HISTORYDATA_H conditional include
216 
Definition: am_historyxorpv.h:16
Definition: am_historystream.h:23
Definition: am_historypvconf.h:24
Definition: am_historydata.h:30
Definition: am_historyrecord.h:29
Definition: am_historyhdr.h:28