mrfioc2  2.3.0
Classes | Public Member Functions | Protected Member Functions | List of all members
TimeStampSource Class Referenceabstract

#include <mrmtimesrc.h>

Inheritance diagram for TimeStampSource:
Inheritance graph
[legend]

Classes

struct  Impl
 

Public Member Functions

 TimeStampSource (double period)
 
virtual ~TimeStampSource ()
 
void resyncSecond ()
 Call to re-initialize timestamp counter from system time. More...
 
void tickSecond ()
 Call just after the start of each second. More...
 
bool validSeconds () const
 Whether tickSecond() has been called for the past 5 seconds. More...
 
double deltaSeconds () const
 last difference between More...
 
void softSecondsSrc (bool enable)
 enable sending of event 125 by software timer. Simulation of external HW clock More...
 
bool isSoftSeconds () const
 
std::string nextSecond () const
 

Protected Member Functions

virtual void setEvtCode (epicsUInt32 evtCode)=0
 
virtual void postSoftSecondsSrc ()
 

Detailed Description

Definition at line 16 of file mrmtimesrc.h.

Constructor & Destructor Documentation

◆ TimeStampSource()

TimeStampSource::TimeStampSource ( double  period)
explicit

Definition at line 143 of file mrmtimesrc.cpp.

144  :impl(new Impl(this, period))
145 {
146  resyncSecond();
147 }
void resyncSecond()
Call to re-initialize timestamp counter from system time.
Definition: mrmtimesrc.cpp:154

◆ ~TimeStampSource()

TimeStampSource::~TimeStampSource ( )
virtual

Definition at line 149 of file mrmtimesrc.cpp.

150 {
151  delete impl;
152 }

Member Function Documentation

◆ deltaSeconds()

double TimeStampSource::deltaSeconds ( ) const

last difference between

Definition at line 224 of file mrmtimesrc.cpp.

225 {
226  Guard G(impl->mutex);
227  return impl->lastError;
228 }
epicsGuard< epicsMutex > Guard
Definition: mrmtimesrc.cpp:28

◆ isSoftSeconds()

bool TimeStampSource::isSoftSeconds ( ) const

Definition at line 263 of file mrmtimesrc.cpp.

264 {
265 #ifdef HAVE_CNS
266  Guard G(impl->mutex);
267  return !!impl->softsrc.get();
268 #else
269  return false;
270 #endif
271 }
epicsGuard< epicsMutex > Guard
Definition: mrmtimesrc.cpp:28

◆ nextSecond()

std::string TimeStampSource::nextSecond ( ) const

Definition at line 273 of file mrmtimesrc.cpp.

274 {
275  epicsTimeStamp raw;
276  {
277  Guard G(impl->mutex);
278  raw.secPastEpoch = impl->next - POSIX_TIME_AT_EPICS_EPOCH;
279  raw.nsec = 0;
280  }
281  epicsTime time(raw);
282 
283  std::vector<char> buf(40);
284 
285  buf.resize(time.strftime(&buf[0], buf.size(), "%a, %d %b %Y %H:%M:%S"));
286  // buf.size() doesn't include trailing nil
287 
288  return std::string(&buf[0], buf.size());
289 }
epicsGuard< epicsMutex > Guard
Definition: mrmtimesrc.cpp:28

◆ postSoftSecondsSrc()

virtual void TimeStampSource::postSoftSecondsSrc ( )
inlineprotectedvirtual

Reimplemented in evgMrm.

Definition at line 45 of file mrmtimesrc.h.

45 {tickSecond();}
void tickSecond()
Call just after the start of each second.
Definition: mrmtimesrc.cpp:160

◆ resyncSecond()

void TimeStampSource::resyncSecond ( )

Call to re-initialize timestamp counter from system time.

Definition at line 154 of file mrmtimesrc.cpp.

155 {
156  Guard G(impl->mutex);
157  impl->resync = true;
158 }
epicsGuard< epicsMutex > Guard
Definition: mrmtimesrc.cpp:28

◆ setEvtCode()

virtual void TimeStampSource::setEvtCode ( epicsUInt32  evtCode)
protectedpure virtual

Implemented in EVRMRM, and evgMrm.

◆ softSecondsSrc()

void TimeStampSource::softSecondsSrc ( bool  enable)

enable sending of event 125 by software timer. Simulation of external HW clock

Definition at line 231 of file mrmtimesrc.cpp.

232 {
233 #ifdef HAVE_CNS
234  mrf::auto_ptr<epicsThread> cleanup;
235  {
236  Guard G(impl->mutex);
237  if(enable && !impl->softsrc.get()) {
238  // start it
239  impl->stopsrc = false;
240  impl->softsrc.reset(new epicsThread(impl->softsrcRun,
241  "SoftTimeSrc",
242  epicsThreadGetStackSize(epicsThreadStackSmall),
243  epicsThreadPriorityHigh));
244  impl->softsrc->start();
245 
246  resyncSecond();
247 
248  } else if(!enable && impl->softsrc.get()) {
249  impl->stopsrc = true;
250  cleanup = PTRMOVE(impl->softsrc);
251  }
252  }
253  if(cleanup.get()) {
254  impl->wakeup.signal();
255  cleanup->exitWait();
256  }
257 #else
258  if(enable)
259  throw std::runtime_error("Soft timestamp source not supported");
260 #endif
261 }
void resyncSecond()
Call to re-initialize timestamp counter from system time.
Definition: mrmtimesrc.cpp:154
epicsGuard< epicsMutex > Guard
Definition: mrmtimesrc.cpp:28

◆ tickSecond()

void TimeStampSource::tickSecond ( )

Call just after the start of each second.

Definition at line 160 of file mrmtimesrc.cpp.

161 {
162  epicsUInt32 tosend=0;
163  bool ok;
164 
165  epicsTimeStamp ts;
166  bool valid = epicsTimeOK == generalTimeGetExceptPriority(&ts, 0, ER_PROVIDER_PRIORITY);
167 
168  {
169  Guard G(impl->mutex);
170 
171  ok = impl->okCnt>=5;
172 
173  /* delay re-sync request until 1Hz is stable, valid system time is available */
174  if(ok && valid && impl->resync) {
175  impl->next = ts.secPastEpoch+POSIX_TIME_AT_EPICS_EPOCH+1;
176  impl->resync = false;
177  }
178 
179  if(ok) {
180  tosend = impl->next;
181  }
182 
183  impl->next++;
184  ok &= tosend!=0;
185 
186  if(ok && valid) {
187  impl->lastError = double(tosend) - (ts.secPastEpoch+POSIX_TIME_AT_EPICS_EPOCH);
188  } else {
189  impl->lastError = -1.0;
190  }
191 
192  if(!impl->timeout.get()) {
193  // lazy start of timestamp timeout thread
194  impl->timeout.reset(new epicsThread(impl->timeoutRun,
195  "TimeStampTimeout",
196  epicsThreadGetStackSize(epicsThreadStackSmall)));
197  impl->timeout->start();
198  }
199  }
200 
201  impl->wakeup.signal();
202 
203  if(!ok) return;
204 
205  for(unsigned i = 0; i < 32; tosend <<= 1, i++) {
206  try {
207  if( tosend & 0x80000000 )
209  else
211  }catch(std::exception& e){
212  errlogPrintf("Soft timestamp source can't send shift event: %s\n", e.what());
213  return;
214  }
215  }
216 }
virtual void setEvtCode(epicsUInt32 evtCode)=0
mrf::auto_ptr< epicsThread > timeout
Definition: mrmtimesrc.cpp:125
#define MRF_EVENT_TS_SHIFT_0
Definition: mrfCommon.h:113
#define MRF_EVENT_TS_SHIFT_1
Definition: mrfCommon.h:114
#define ER_PROVIDER_PRIORITY
Priority given to EVR&#39;s timestamp/event provider.
Definition: mrfCommon.h:131
epicsThreadRunableMethod< Impl, &Impl::runTimeout > timeoutRun
Definition: mrmtimesrc.cpp:124
epicsGuard< epicsMutex > Guard
Definition: mrmtimesrc.cpp:28

◆ validSeconds()

bool TimeStampSource::validSeconds ( ) const

Whether tickSecond() has been called for the past 5 seconds.

Definition at line 218 of file mrmtimesrc.cpp.

219 {
220  Guard G(impl->mutex);
221  return impl->okCnt>=5;
222 }
epicsGuard< epicsMutex > Guard
Definition: mrmtimesrc.cpp:28

The documentation for this class was generated from the following files: