My Project
drvemTSBuffer.h
1 /*************************************************************************\
2 * Copyright (c) 2020 Michael Davidsaver
3 * mrfioc2 is distributed subject to a Software License Agreement found
4 * in file LICENSE that is included with this distribution.
5 \*************************************************************************/
6 #ifndef DRVEMTSBUFFER_H
7 #define DRVEMTSBUFFER_H
8 
9 #include <vector>
10 #include <utility> // std::pair
11 
12 #include <dbScan.h>
13 
14 #include "mrf/object.h"
15 
16 class EVRMRM;
17 
18 struct EVRMRMTSBuffer : public mrf::ObjectInst<EVRMRMTSBuffer>
19 {
20  typedef mrf::ObjectInst<EVRMRMTSBuffer> base_t;
21 
22  explicit EVRMRMTSBuffer(const std::string& n, EVRMRM* evr);
23  virtual ~EVRMRMTSBuffer();
24 
25  virtual void lock() const OVERRIDE FINAL;
26  virtual void unlock() const OVERRIDE FINAL;
27 
28  epicsUInt32 dropCount() const { return dropped; }
29 
30  epicsUInt16 timeEvent() const { return timeEvt; }
31  void flushTimeSet(epicsUInt16 v);
32 
33  epicsUInt16 flushEvent() const { return flushEvt; }
34  void flushEventSet(epicsUInt16 v);
35 
36  void flushNow();
37  void doFlush();
38 
39  epicsUInt32 getTimesRelFirst(epicsInt32 *arr, epicsUInt32 count) const;
40  epicsUInt32 getTimesRelFlush(epicsInt32 *arr, epicsUInt32 count) const;
41  epicsUInt32 getTimesRelPrevFlush(epicsInt32 *arr, epicsUInt32 count) const;
42 
43  IOSCANPVT flushed() const { return scan; }
44 
45  EVRMRM* const evr;
46 
47  epicsUInt32 dropped;
48 
49  IOSCANPVT scan;
50 
51  epicsUInt8 timeEvt;
52  epicsUInt8 flushEvt;
53 
54  struct ebuf_t {
55  size_t pos;
56  std::vector<epicsTimeStamp> buf;
57  epicsTimeStamp flushtime, prevflushtime;
58  bool ok, prevok;
59  bool drop;
60  ebuf_t() :pos(0u), ok(false), prevok(false), drop(false) {
61  flushtime.secPastEpoch = 0u;
62  flushtime.nsec = 0u;
63  prevflushtime = flushtime;
64  }
65  private:
66  ebuf_t(const ebuf_t&);
67  } ebufs[2];
68  // active buffer being filled. Other is for readout.
69  // must lock both evr and this mutex to change.
70  unsigned char active; // either 0 or 1
71 };
72 
73 #endif // DRVEMTSBUFFER_H
Modular Register Map Event Receivers.
Definition: drvem.h:97
User implementation hook.
Definition: object.h:460