forked from sPHENIX-Collaboration/rcdaq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaq_device_rtclock.cc
131 lines (95 loc) · 2.51 KB
/
daq_device_rtclock.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <iostream>
#include <string.h>
#include <daq_device_rtclock.h>
using namespace std;
daq_device_rtclock::daq_device_rtclock(const int eventtype
, const int subeventid
, const int n_what)
{
m_eventType = eventtype;
m_subeventid = subeventid;
}
daq_device_rtclock::~daq_device_rtclock()
{
}
// the put_data function
int daq_device_rtclock::put_data(const int etype, int * adr, const int length )
{
if (etype != m_eventType ) // not our id
{
return 0;
}
struct timespec clk;
if ( daq_getEventFormat() ) // we are writing PRDF
{
formatPacketHdr(adr);
packetdata_ptr sevt = (packetdata_ptr) adr;
// update id's etc
sevt->sub_id = m_subeventid;
sevt->sub_type = 4;
sevt->sub_decoding = 30000+9;
int *d = (int *) &sevt->data;
int s = clock_gettime(CLOCK_MONOTONIC_RAW, &clk);
if (s) // error, set everything to 0
{
for ( int i = 0; i < 6; i++) *d++ = 0;
}
else
{
*d++ = clk.tv_sec;
memcpy(d, &clk.tv_nsec, sizeof(clk.tv_nsec));
d+=2;
*d++ = previous_clk.tv_sec;
memcpy(d, &previous_clk.tv_nsec, sizeof(previous_clk.tv_nsec));
d+=2;
}
previous_clk = clk;
sevt->sub_length += 6;
return sevt->sub_length;
}
else
{
sevt = (subevtdata_ptr) adr;
// set the initial subevent length
sevt->sub_length = SEVTHEADERLENGTH;
// update id's etc
sevt->sub_id = m_subeventid;
sevt->sub_type=4;
sevt->sub_decoding = IDRTCLK;
sevt->reserved[0] = 0;
sevt->reserved[1] = 0;
int *d = (int *) &sevt->data;
int s = clock_gettime(CLOCK_MONOTONIC_RAW, &clk);
if (s) // error, set everything to 0
{
for ( int i = 0; i < 6; i++) *d++ = 0;
}
else
{
*d++ = clk.tv_sec;
memcpy(d, &clk.tv_nsec, sizeof(clk.tv_nsec));
d+=2;
*d++ = previous_clk.tv_sec;
memcpy(d, &previous_clk.tv_nsec, sizeof(previous_clk.tv_nsec));
d+=2;
}
previous_clk = clk;
sevt->sub_padding = 0;
sevt->sub_length += 6;
return sevt->sub_length;
}
}
void daq_device_rtclock::identify(std::ostream& os) const
{
os << "Real-time clock Device Event Type: " << m_eventType << " Subevent id: " << m_subeventid << endl;
}
int daq_device_rtclock::max_length(const int etype) const
{
if (etype != m_eventType) return 0;
return (6 + SEVTHEADERLENGTH);
}
int daq_device_rtclock::init()
{
clock_gettime(CLOCK_MONOTONIC_RAW, &previous_clk);
return 0;
}