1 | #ifndef FACT_HeadersFTM
|
---|
2 | #define FACT_HeadersFTM
|
---|
3 |
|
---|
4 | #include <ostream>
|
---|
5 |
|
---|
6 | // For debugging
|
---|
7 | #include <iostream>
|
---|
8 |
|
---|
9 | #include "ByteOrder.h"
|
---|
10 |
|
---|
11 | // ====================================================================
|
---|
12 |
|
---|
13 |
|
---|
14 | namespace FTM
|
---|
15 | {
|
---|
16 | enum States
|
---|
17 | {
|
---|
18 | kFtmUndefined = 0,
|
---|
19 |
|
---|
20 | // FTM internal states
|
---|
21 | kFtmIdle = 1, ///< Trigger output disabled, configuration possible
|
---|
22 | kFtmConfig = 2, ///< FTM and FTUs are being reconfigured
|
---|
23 | kFtmRunning = 3, ///< Trigger output enabled, configuration ignored
|
---|
24 | kFtmCalib = 4,
|
---|
25 | };
|
---|
26 |
|
---|
27 | enum StateMachine
|
---|
28 | {
|
---|
29 | kDisconnected = 1, //ConnectionFTM::kDisconnected,
|
---|
30 | kConnected ,//= ConnectionFTM::kConnected,
|
---|
31 | kIdle ,//= ConnectionFTM::kIdle,
|
---|
32 | kTakingData ,//= ConnectionFTM::kTakingData,
|
---|
33 | kConfiguring1,
|
---|
34 | kConfiguring2,
|
---|
35 | kConfigured,
|
---|
36 |
|
---|
37 | kConfigError1 = 0x101,
|
---|
38 | kConfigError2 = 0x102,
|
---|
39 |
|
---|
40 | kCmdTest
|
---|
41 | };
|
---|
42 |
|
---|
43 | /// Command codes for FTM communication
|
---|
44 | enum Commands
|
---|
45 | {
|
---|
46 | // First word
|
---|
47 | kCmdRead = 0x0001, ///< Request data
|
---|
48 | kCmdWrite = 0x0002, ///< Send data
|
---|
49 | kCmdStartRun = 0x0004, ///< Enable the trigger output
|
---|
50 | kCmdStopRun = 0x0008, ///< Disable the trigger output
|
---|
51 | kCmdPing = 0x0010, ///< Ping all FTUs (get FTU list)
|
---|
52 | kCmdCrateReset = 0x0020, ///< Reboot (no power cycle) all FTUs and FADs of one crate
|
---|
53 | kCmdDisableReports = 0x0040, ///< Disable transmission of rate-reports (dynamic data)
|
---|
54 | kCmdToggleLed = 0xc000,
|
---|
55 |
|
---|
56 | // second word for read and write
|
---|
57 | kCmdStaticData = 0x0001, ///< Specifies that static (configuration) data is read/written
|
---|
58 | kCmdDynamicData = 0x0002, ///< Specifies that dynamic data is read/written
|
---|
59 | kCmdRegister = 0x0004, ///< Specifies that a register is read/written
|
---|
60 |
|
---|
61 | // second word for StartRun
|
---|
62 | kStartRun = 0x0001, ///< ...until kCmdStopRun
|
---|
63 | kTakeNevents = 0x0002, ///< ...fixed number of events
|
---|
64 |
|
---|
65 | // second word for kCmdCrateReset
|
---|
66 | kResetCrate0 = 0x0001,
|
---|
67 | kResetCrate1 = 0x0002,
|
---|
68 | kResetCrate2 = 0x0004,
|
---|
69 | kResetCrate3 = 0x0008,
|
---|
70 | };
|
---|
71 |
|
---|
72 |
|
---|
73 | /// Types sent in the header of the following data
|
---|
74 | enum Types
|
---|
75 | {
|
---|
76 | kHeader = 0, ///< Local extension to identify a header in fCounter
|
---|
77 | kStaticData = 1, ///< Static (configuration) data
|
---|
78 | kDynamicData = 2, ///< Dynamic data (rates)
|
---|
79 | kFtuList = 3, ///< FTU list (answer of ping)
|
---|
80 | kErrorList = 4, ///< Error list (error when FTU communication failed)
|
---|
81 | kRegister = 5, ///< A requested register value
|
---|
82 | };
|
---|
83 |
|
---|
84 | // --------------------------------------------------------------------
|
---|
85 |
|
---|
86 | enum Delimiter
|
---|
87 | {
|
---|
88 | kDelimiterStart = 0xfb01, ///< Start delimiter send before each header
|
---|
89 | kDelimiterEnd = 0x04fe ///< End delimiter send after each data block
|
---|
90 | };
|
---|
91 |
|
---|
92 | struct Header
|
---|
93 | {
|
---|
94 | uint16_t fDelimiter; ///< Start delimiter
|
---|
95 | uint16_t fType; ///< Type of the data to be received after the header
|
---|
96 | uint16_t fDataSize; ///< Size in words to be received after the header (incl end delim.)
|
---|
97 | uint16_t fState; ///< State of the FTM central state machine
|
---|
98 | uint64_t fBoardId; ///< FPGA device DNA (unique chip id)
|
---|
99 | uint16_t fFirmwareId; ///< Version number
|
---|
100 | uint32_t fTriggerCounter; ///< FTM internal counter of all trigger decision independant of trigger-line enable/disable (reset: start/stop run)
|
---|
101 | uint64_t fTimeStamp; ///< Internal counter (micro-seconds, reset: start/stop run)
|
---|
102 |
|
---|
103 | Header() { init(*this); }
|
---|
104 |
|
---|
105 | std::vector<uint16_t> HtoN() const
|
---|
106 | {
|
---|
107 | Header h(*this);
|
---|
108 |
|
---|
109 | Reverse(&h.fBoardId);
|
---|
110 | Reverse(&h.fTriggerCounter);
|
---|
111 | Reverse(&h.fTimeStamp);
|
---|
112 |
|
---|
113 | return htoncpy(h);
|
---|
114 | }
|
---|
115 | void operator=(const std::vector<uint16_t> &vec)
|
---|
116 | {
|
---|
117 | ntohcpy(vec, *this);
|
---|
118 |
|
---|
119 | Reverse(&fBoardId);
|
---|
120 | Reverse(&fTriggerCounter);
|
---|
121 | Reverse(&fTimeStamp);
|
---|
122 | }
|
---|
123 |
|
---|
124 | void clear() { reset(*this); }
|
---|
125 | void print(std::ostream &out) const;
|
---|
126 |
|
---|
127 | } __attribute__((__packed__));
|
---|
128 |
|
---|
129 | struct DimPassport
|
---|
130 | {
|
---|
131 | uint64_t fBoardId;
|
---|
132 | uint16_t fFirmwareId;
|
---|
133 |
|
---|
134 | DimPassport(const Header &h) :
|
---|
135 | fBoardId(h.fBoardId),
|
---|
136 | fFirmwareId(h.fFirmwareId)
|
---|
137 | {
|
---|
138 | }
|
---|
139 | } __attribute__((__packed__));
|
---|
140 |
|
---|
141 | struct DimTriggerCounter
|
---|
142 | {
|
---|
143 | uint64_t fTimeStamp;
|
---|
144 | uint32_t fTriggerCounter;
|
---|
145 |
|
---|
146 | DimTriggerCounter(const Header &h) :
|
---|
147 | fTimeStamp(h.fTimeStamp),
|
---|
148 | fTriggerCounter(h.fTriggerCounter)
|
---|
149 | {
|
---|
150 | }
|
---|
151 | } __attribute__((__packed__));
|
---|
152 |
|
---|
153 |
|
---|
154 | struct StaticDataBoard
|
---|
155 | {
|
---|
156 | uint16_t fEnable[4]; /// enable of 4x9 pixels coded as 4x9bits
|
---|
157 | uint16_t fDAC[5]; /// 0-3 (A-D) Threshold of patches, 4 (H) Threshold for N out of 4 (12 bit each)
|
---|
158 | uint16_t fPrescaling; /// Internal readout time of FTUs for trigger counter
|
---|
159 |
|
---|
160 | StaticDataBoard() { init(*this); }
|
---|
161 |
|
---|
162 | void print(std::ostream &out) const;
|
---|
163 |
|
---|
164 | } __attribute__((__packed__));
|
---|
165 |
|
---|
166 | struct StaticData
|
---|
167 | {
|
---|
168 | enum Limits
|
---|
169 | {
|
---|
170 | kMaxMultiplicity = 40, ///< Minimum required trigger multiplicity
|
---|
171 | kMaxWindow = 0xf, ///< (4ns * x + 8ns) At least N (multiplicity) rising edges (trigger signal) within this window
|
---|
172 | kMaxDeadTime = 0xffff, ///< (4ns * x + 8ns)
|
---|
173 | kMaxDelayTimeMarker = 0x3ff, ///< (4ns * x + 8ns)
|
---|
174 | kMaxDelayTrigger = 0x3ff, ///< (4ns * x + 8ns)
|
---|
175 | kMaxTriggerInterval = 0x3ff, ///<
|
---|
176 | kMaxSequence = 0x1f,
|
---|
177 | kMaxDAC = 0xfff,
|
---|
178 | kMaxAddr = 0xfff,
|
---|
179 | kMaxPatchIdx = 159,
|
---|
180 | kMaxPixelIdx = 1439,
|
---|
181 | kMaskSettings = 0xf,
|
---|
182 | kMaskLEDs = 0xf,
|
---|
183 | };
|
---|
184 |
|
---|
185 | enum GeneralSettings
|
---|
186 | {
|
---|
187 | kTrigger = 0x80, ///< Physics trigger decision (PhysicTrigger)
|
---|
188 | kPedestal = 0x40, ///< Pedestal trigger (artifical)
|
---|
189 | kLPint = 0x20, ///< Enable artificial trigger after light pulse (LP2)
|
---|
190 | kLPext = 0x10, ///< Enable trigger decision after light pulse (CalibrationTrigger, LP1)
|
---|
191 | kExt2 = 0x08, ///< External trigger signal 2
|
---|
192 | kExt1 = 0x04, ///< External trigger signal 1
|
---|
193 | kVeto = 0x02, ///< Veto trigger decision / artifical triggers
|
---|
194 | kClockConditioner = 0x01, ///< Select clock conditioner frequency (1) / time marker (0) as output
|
---|
195 | };
|
---|
196 |
|
---|
197 | uint16_t fGeneralSettings; // Enable for different trigger types / select for TIM/ClockConditioner output (only 8 bit used)
|
---|
198 | uint16_t fStatusLEDs; // only 8 bit used
|
---|
199 | uint16_t fTriggerInterval; // [ms] Interval between two artificial triggers (no matter which type) minimum 1ms, 10 bit
|
---|
200 | uint16_t fTriggerSequence; // Ratio between trigger types send as artificial trigger (in this order) 3x5bit
|
---|
201 | uint64_t fDummy0;
|
---|
202 | uint16_t fMultiplicityPhysics; /// Required trigger multiplicity for physcis triggers (0-40)
|
---|
203 | uint16_t fMultiplicityCalib; /// Required trigger multiplicity calibration (LPext) triggers (0-40)
|
---|
204 | uint16_t fDelayTrigger; /// (4ns * x + 8ns) FTM internal programmable delay between trigger decision and output
|
---|
205 | uint16_t fDelayTimeMarker; /// (4ns * x + 8ns) FTM internal programmable delay between trigger descision and time marker output
|
---|
206 | uint16_t fDeadTime; /// (4ns * x + 8ns) FTM internal programmable dead time after trigger decision
|
---|
207 | uint32_t fClockConditioner[8]; /// R0, R1, R8, R9, R11, R13, R14, R15
|
---|
208 | uint16_t fWindowPhysics; /// (4ns * x + 8ns) At least N (multiplicity) rising edges (trigger signal) within this window
|
---|
209 | uint16_t fWindowCalib; /// (4ns * x + 8ns) At least N (multiplicity) rising edges (trigger signal) within this window
|
---|
210 | uint16_t fDummy1;
|
---|
211 |
|
---|
212 | StaticDataBoard fBoard[4][10]; // 4 crates * 10 boards (Crate0/FTU0 == readout time of FTUs)
|
---|
213 |
|
---|
214 | uint16_t fActiveFTU[4]; // 4 crates * 10 bits (FTU enable)
|
---|
215 |
|
---|
216 | StaticData() { init(*this); }
|
---|
217 | StaticData(const std::vector<uint16_t> &vec)
|
---|
218 | {
|
---|
219 | ntohcpy(vec, *this);
|
---|
220 |
|
---|
221 | for (int i=0; i<8; i++)
|
---|
222 | Reverse(fClockConditioner+i);
|
---|
223 | }
|
---|
224 |
|
---|
225 | std::vector<uint16_t> HtoN() const
|
---|
226 | {
|
---|
227 | StaticData d(*this);
|
---|
228 | for (int i=0; i<8; i++)
|
---|
229 | Reverse(d.fClockConditioner+i);
|
---|
230 |
|
---|
231 | return htoncpy(d);
|
---|
232 | }
|
---|
233 |
|
---|
234 | bool operator==(const StaticData &d) const
|
---|
235 | {
|
---|
236 | return memcmp(this, &d, sizeof(StaticData))==0;
|
---|
237 | }
|
---|
238 |
|
---|
239 | void clear() { reset(*this); }
|
---|
240 | void print(std::ostream &out) const;
|
---|
241 |
|
---|
242 | StaticDataBoard &operator[](int i) { return fBoard[i/10][i%10]; }
|
---|
243 | const StaticDataBoard &operator[](int i) const { return fBoard[i/10][i%10]; }
|
---|
244 |
|
---|
245 | void EnableFTU(int i) { fActiveFTU[i/10] |= (1<<(i%10)); }
|
---|
246 | void DisableFTU(int i) { fActiveFTU[i/10] &= ~(1<<(i%10)); }
|
---|
247 |
|
---|
248 | void EnableAllFTU() { for (int i=0; i<4; i++) fActiveFTU[i] = 0x3ff; }
|
---|
249 | void DisableAllFTU() { for (int i=0; i<4; i++) fActiveFTU[i] = 0; }
|
---|
250 |
|
---|
251 | void ToggleFTU(int i) { fActiveFTU[i/10] ^= (1<<(i%10)); }
|
---|
252 |
|
---|
253 | void Enable(GeneralSettings type, bool enable)
|
---|
254 | {
|
---|
255 | if (enable)
|
---|
256 | fGeneralSettings |= uint16_t(type);
|
---|
257 | else
|
---|
258 | fGeneralSettings &= ~uint16_t(type); }
|
---|
259 |
|
---|
260 | bool IsEnabled(GeneralSettings type) const { return fGeneralSettings&uint16_t(type); }
|
---|
261 |
|
---|
262 | void EnablePixel(int idx, bool enable)
|
---|
263 | {
|
---|
264 | const int pixel = idx%9;
|
---|
265 | const int patch = (idx/9)%4;
|
---|
266 | const int board = (idx/9)/4;
|
---|
267 |
|
---|
268 | uint16_t &pix = fBoard[board/10][board%10].fEnable[patch];
|
---|
269 |
|
---|
270 | if (enable)
|
---|
271 | pix |= (1<<pixel);
|
---|
272 | else
|
---|
273 | pix &= ~(1<<pixel);
|
---|
274 | }
|
---|
275 |
|
---|
276 | bool Enabled(uint16_t idx) const
|
---|
277 | {
|
---|
278 | const int pixel = idx%9;
|
---|
279 | const int patch = (idx/9)%4;
|
---|
280 | const int board = (idx/9)/4;
|
---|
281 |
|
---|
282 | return (fBoard[board/10][board%10].fEnable[patch]>>pixel)&1;
|
---|
283 | }
|
---|
284 |
|
---|
285 | uint8_t GetSequencePed() const { return (fTriggerSequence>>10)&0x1f; }
|
---|
286 | uint8_t GetSequenceLPint() const { return (fTriggerSequence>> 5)&0x1f; }
|
---|
287 | uint8_t GetSequenceLPext() const { return (fTriggerSequence) &0x1f; }
|
---|
288 |
|
---|
289 | } __attribute__((__packed__));
|
---|
290 |
|
---|
291 | // DimStructures must be a multiple of two... I don't know why
|
---|
292 | struct DimStaticData
|
---|
293 | {
|
---|
294 | uint64_t fTimeStamp;
|
---|
295 | //8
|
---|
296 | uint16_t fGeneralSettings; // only 8 bit used
|
---|
297 | uint16_t fStatusLEDs; // only 8 bit used
|
---|
298 | uint64_t fActiveFTU; // 40 bits in row
|
---|
299 | //20
|
---|
300 | uint16_t fTriggerInterval; // only 10 bit used
|
---|
301 | //22
|
---|
302 | uint16_t fTriggerSeqLPint; // only 5bits used
|
---|
303 | uint16_t fTriggerSeqLPext; // only 5bits used
|
---|
304 | uint16_t fTriggerSeqPed; // only 5bits used
|
---|
305 | //28
|
---|
306 | uint16_t fMultiplicityPhysics; // 0-40
|
---|
307 | uint16_t fMultiplicityCalib; // 0-40
|
---|
308 | //32
|
---|
309 | uint16_t fWindowPhysics;
|
---|
310 | uint16_t fWindowCalib;
|
---|
311 | //36
|
---|
312 | uint16_t fDelayTrigger;
|
---|
313 | uint16_t fDelayTimeMarker;
|
---|
314 | uint32_t fDeadTime;
|
---|
315 | //44
|
---|
316 | uint32_t fClockConditioner[8];
|
---|
317 | //60
|
---|
318 | uint16_t fEnable[90]; // 160*9bit = 180byte
|
---|
319 | uint16_t fThreshold[160];
|
---|
320 | uint16_t fMultiplicity[40]; // N out of 4
|
---|
321 | uint16_t fPrescaling[40];
|
---|
322 | // 640+60 = 700
|
---|
323 |
|
---|
324 | bool HasTrigger() const { return fGeneralSettings & StaticData::kTrigger; }
|
---|
325 | bool HasPedestal() const { return fGeneralSettings & StaticData::kPedestal; }
|
---|
326 | bool HasLPext() const { return fGeneralSettings & StaticData::kLPext; }
|
---|
327 | bool HasLPint() const { return fGeneralSettings & StaticData::kLPint; }
|
---|
328 | bool HasExt2() const { return fGeneralSettings & StaticData::kExt2; }
|
---|
329 | bool HasExt1() const { return fGeneralSettings & StaticData::kExt1; }
|
---|
330 | bool HasVeto() const { return fGeneralSettings & StaticData::kVeto; }
|
---|
331 | bool HasClockConditioner() const { return fGeneralSettings & StaticData::kClockConditioner; }
|
---|
332 |
|
---|
333 | bool IsActive(int i) const { return fActiveFTU&(uint64_t(1)<<i); }
|
---|
334 | bool IsEnabled(int i) const { return fEnable[i/16]&(1<<(i%16)); }
|
---|
335 |
|
---|
336 | DimStaticData() { memset(this, 0, sizeof(DimStaticData)); }
|
---|
337 |
|
---|
338 | DimStaticData(const Header &h, const StaticData &d) :
|
---|
339 | fTimeStamp(h.fTimeStamp),
|
---|
340 | fGeneralSettings(d.fGeneralSettings),
|
---|
341 | fStatusLEDs(d.fStatusLEDs),
|
---|
342 | fActiveFTU( uint64_t(d.fActiveFTU[0]) |
|
---|
343 | (uint64_t(d.fActiveFTU[1])<<10) |
|
---|
344 | (uint64_t(d.fActiveFTU[2])<<20) |
|
---|
345 | (uint64_t(d.fActiveFTU[3])<<30)),
|
---|
346 | fTriggerInterval(d.fTriggerInterval),
|
---|
347 | fTriggerSeqLPint((d.fTriggerSequence>>5)&0x1f),
|
---|
348 | fTriggerSeqLPext((d.fTriggerSequence)&0x1f),
|
---|
349 | fTriggerSeqPed((d.fTriggerSequence>>10)&0x1f),
|
---|
350 | fMultiplicityPhysics(d.fMultiplicityPhysics),
|
---|
351 | fMultiplicityCalib(d.fMultiplicityCalib),
|
---|
352 | fWindowPhysics(d.fWindowPhysics*4+8),
|
---|
353 | fWindowCalib(d.fWindowCalib*4+8),
|
---|
354 | fDelayTrigger(d.fDelayTrigger*4+8),
|
---|
355 | fDelayTimeMarker(d.fDelayTimeMarker*4+8),
|
---|
356 | fDeadTime(uint32_t(d.fDeadTime)*4+8)
|
---|
357 | {
|
---|
358 | memcpy(fClockConditioner, d.fClockConditioner, sizeof(uint32_t)*8);
|
---|
359 |
|
---|
360 | uint16_t src[160];
|
---|
361 | for (int i=0; i<40; i++)
|
---|
362 | {
|
---|
363 | for (int j=0; j<4; j++)
|
---|
364 | {
|
---|
365 | src[i*4+j] = d[i].fEnable[j];
|
---|
366 | fThreshold[i*4+j] = d[i].fDAC[j];
|
---|
367 | }
|
---|
368 |
|
---|
369 | fMultiplicity[i] = d[i].fDAC[4];
|
---|
370 | fPrescaling[i] = d[i].fPrescaling+1;
|
---|
371 | }
|
---|
372 | bitcpy(fEnable, 90, src, 160, 9);
|
---|
373 | }
|
---|
374 |
|
---|
375 | } __attribute__((__packed__));
|
---|
376 |
|
---|
377 |
|
---|
378 | struct DynamicDataBoard
|
---|
379 | {
|
---|
380 | uint32_t fRatePatch[4]; // Patch 0,1,2,3
|
---|
381 | uint32_t fRateTotal; // Sum
|
---|
382 |
|
---|
383 | uint16_t fOverflow; // Patches: bits 0-3, total 4
|
---|
384 | uint16_t fCrcError;
|
---|
385 |
|
---|
386 | void print(std::ostream &out) const;
|
---|
387 |
|
---|
388 | void reverse()
|
---|
389 | {
|
---|
390 | for (int i=0; i<4; i++)
|
---|
391 | Reverse(fRatePatch+i);
|
---|
392 |
|
---|
393 | Reverse(&fRateTotal);
|
---|
394 | }
|
---|
395 |
|
---|
396 | uint32_t &operator[](int i) { return fRatePatch[i]; }
|
---|
397 |
|
---|
398 | } __attribute__((__packed__));
|
---|
399 |
|
---|
400 |
|
---|
401 | struct DynamicData
|
---|
402 | {
|
---|
403 | uint64_t fOnTimeCounter;
|
---|
404 | uint16_t fTempSensor[4]; // U45, U46, U48, U49
|
---|
405 |
|
---|
406 | DynamicDataBoard fBoard[4][10]; // 4 crates * 10 boards
|
---|
407 |
|
---|
408 | DynamicData() { init(*this); }
|
---|
409 |
|
---|
410 | std::vector<uint16_t> HtoN() const
|
---|
411 | {
|
---|
412 | DynamicData d(*this);
|
---|
413 |
|
---|
414 | Reverse(&d.fOnTimeCounter);
|
---|
415 |
|
---|
416 | for (int c=0; c<4; c++)
|
---|
417 | for (int b=0; b<10; b++)
|
---|
418 | d.fBoard[c][b].reverse();
|
---|
419 |
|
---|
420 | return htoncpy(d);
|
---|
421 | }
|
---|
422 |
|
---|
423 | void operator=(const std::vector<uint16_t> &vec)
|
---|
424 | {
|
---|
425 | ntohcpy(vec, *this);
|
---|
426 |
|
---|
427 | Reverse(&fOnTimeCounter);
|
---|
428 |
|
---|
429 | for (int c=0; c<4; c++)
|
---|
430 | for (int b=0; b<10; b++)
|
---|
431 | fBoard[c][b].reverse();
|
---|
432 | }
|
---|
433 |
|
---|
434 | void clear() { reset(*this); }
|
---|
435 | void print(std::ostream &out) const;
|
---|
436 |
|
---|
437 | DynamicDataBoard &operator[](int i) { return fBoard[i/10][i%10]; }
|
---|
438 | const DynamicDataBoard &operator[](int i) const { return fBoard[i/10][i%10]; }
|
---|
439 |
|
---|
440 | } __attribute__((__packed__));
|
---|
441 |
|
---|
442 |
|
---|
443 | struct DimDynamicData
|
---|
444 | {
|
---|
445 | uint64_t fTimeStamp;
|
---|
446 |
|
---|
447 | uint64_t fOnTimeCounter;
|
---|
448 | float fTempSensor[4];
|
---|
449 |
|
---|
450 | uint32_t fRatePatch[160];
|
---|
451 |
|
---|
452 | uint32_t fRateBoard[40];
|
---|
453 | uint16_t fRateOverflow[40];
|
---|
454 |
|
---|
455 | uint16_t fCrcError[40];
|
---|
456 |
|
---|
457 | DimDynamicData(const Header &h, const DynamicData &d) :
|
---|
458 | fTimeStamp(h.fTimeStamp),
|
---|
459 | fOnTimeCounter(d.fOnTimeCounter)
|
---|
460 | {
|
---|
461 | for (int i=0; i<4; i++)
|
---|
462 | fTempSensor[i] = d.fTempSensor[i];
|
---|
463 |
|
---|
464 | for (int i=0; i<40; i++)
|
---|
465 | {
|
---|
466 | fRateBoard[i] = d[i].fRateTotal;
|
---|
467 | fRateOverflow[i] = d[i].fOverflow;
|
---|
468 | fCrcError[i] = d[i].fCrcError;
|
---|
469 | for (int j=0; j<4; j++)
|
---|
470 | fRatePatch[i*4+j] = d[i].fRatePatch[j];
|
---|
471 | }
|
---|
472 | }
|
---|
473 |
|
---|
474 | } __attribute__((__packed__));
|
---|
475 |
|
---|
476 |
|
---|
477 | struct FtuResponse
|
---|
478 | {
|
---|
479 | uint16_t fPingAddr; // Number of Pings and addr (pings= see error)
|
---|
480 | uint64_t fDNA;
|
---|
481 | uint16_t fErrorCounter; //
|
---|
482 |
|
---|
483 | void reverse() { Reverse(&fDNA); }
|
---|
484 |
|
---|
485 | void print(std::ostream &out) const;
|
---|
486 |
|
---|
487 | } __attribute__((__packed__));
|
---|
488 |
|
---|
489 | struct FtuList
|
---|
490 | {
|
---|
491 | uint16_t fNumBoards; /// Total number of boards responded
|
---|
492 | uint16_t fNumBoardsCrate[4]; /// Num of board responded in crate 0-3
|
---|
493 | uint16_t fActiveFTU[4]; /// List of active FTU boards in crate 0-3
|
---|
494 |
|
---|
495 | FtuResponse fFTU[4][10];
|
---|
496 |
|
---|
497 | FtuList() { init(*this); }
|
---|
498 |
|
---|
499 | std::vector<uint16_t> HtoN() const
|
---|
500 | {
|
---|
501 | FtuList d(*this);
|
---|
502 |
|
---|
503 | for (int c=0; c<4; c++)
|
---|
504 | for (int b=0; b<10; b++)
|
---|
505 | d.fFTU[c][b].reverse();
|
---|
506 |
|
---|
507 | return htoncpy(d);
|
---|
508 | }
|
---|
509 |
|
---|
510 | void operator=(const std::vector<uint16_t> &vec)
|
---|
511 | {
|
---|
512 | ntohcpy(vec, *this);
|
---|
513 |
|
---|
514 | for (int c=0; c<4; c++)
|
---|
515 | for (int b=0; b<10; b++)
|
---|
516 | fFTU[c][b].reverse();
|
---|
517 | }
|
---|
518 |
|
---|
519 | void clear() { reset(*this); }
|
---|
520 | void print(std::ostream &out) const;
|
---|
521 |
|
---|
522 | FtuResponse &operator[](int i) { return fFTU[i/10][i%10]; }
|
---|
523 | const FtuResponse &operator[](int i) const { return fFTU[i/10][i%10]; }
|
---|
524 |
|
---|
525 | } __attribute__((__packed__));
|
---|
526 |
|
---|
527 | struct DimFtuList
|
---|
528 | {
|
---|
529 | uint64_t fTimeStamp;
|
---|
530 | uint64_t fActiveFTU;
|
---|
531 |
|
---|
532 | uint16_t fNumBoards; /// Number of boards answered in total
|
---|
533 | uint8_t fNumBoardsCrate[4]; /// Number of boards answered per crate
|
---|
534 |
|
---|
535 | uint64_t fDNA[40]; /// DNA of FTU board
|
---|
536 | uint8_t fAddr[40]; /// Address of FTU board
|
---|
537 | uint8_t fPing[40]; /// Number of pings until response (same as in Error)
|
---|
538 |
|
---|
539 | DimFtuList(const Header &h, const FtuList &d) :
|
---|
540 | fTimeStamp(h.fTimeStamp),
|
---|
541 | fActiveFTU( uint64_t(d.fActiveFTU[0]) |
|
---|
542 | (uint64_t(d.fActiveFTU[1])<<10) |
|
---|
543 | (uint64_t(d.fActiveFTU[2])<<20) |
|
---|
544 | (uint64_t(d.fActiveFTU[3])<<30)),
|
---|
545 | fNumBoards(d.fNumBoards)
|
---|
546 | {
|
---|
547 | for (int i=0; i<4; i++)
|
---|
548 | fNumBoardsCrate[i] = d.fNumBoardsCrate[i];
|
---|
549 |
|
---|
550 | for (int i=0; i<40; i++)
|
---|
551 | {
|
---|
552 | fDNA[i] = d[i].fDNA;
|
---|
553 | fAddr[i] = d[i].fPingAddr&0x3f;
|
---|
554 | fPing[i] = (d[i].fPingAddr>>8)&0x3;
|
---|
555 | }
|
---|
556 | }
|
---|
557 |
|
---|
558 | bool IsActive(int i) const { return fActiveFTU&(uint64_t(1)<<i); }
|
---|
559 |
|
---|
560 | } __attribute__((__packed__));
|
---|
561 |
|
---|
562 |
|
---|
563 | struct Error
|
---|
564 | {
|
---|
565 | uint16_t fNumCalls; // 0=error, >1 needed repetition but successfull
|
---|
566 |
|
---|
567 | uint16_t fDelimiter;
|
---|
568 | uint16_t fDestAddress;
|
---|
569 | uint16_t fSrcAddress;
|
---|
570 | uint16_t fFirmwareId;
|
---|
571 | uint16_t fCommand;
|
---|
572 | uint16_t fData[21];
|
---|
573 | uint16_t fCrcErrorCounter;
|
---|
574 | uint16_t fCrcCheckSum;
|
---|
575 |
|
---|
576 | Error() { init(*this); }
|
---|
577 |
|
---|
578 | std::vector<uint16_t> HtoN() const
|
---|
579 | {
|
---|
580 | return htoncpy(*this);
|
---|
581 | }
|
---|
582 |
|
---|
583 | void operator=(const std::vector<uint16_t> &vec) { ntohcpy(vec, *this); }
|
---|
584 |
|
---|
585 | void clear() { reset(*this); }
|
---|
586 |
|
---|
587 | uint16_t &operator[](int idx) { return fData[idx]; }
|
---|
588 | const uint16_t &operator[](int idx) const { return fData[idx]; }
|
---|
589 |
|
---|
590 | void print(std::ostream &out) const;
|
---|
591 |
|
---|
592 | } __attribute__((__packed__));
|
---|
593 |
|
---|
594 | struct DimError
|
---|
595 | {
|
---|
596 | uint64_t fTimeStamp;
|
---|
597 | Error fError;
|
---|
598 |
|
---|
599 | DimError(const Header &h, const Error &e) :
|
---|
600 | fTimeStamp(h.fTimeStamp),
|
---|
601 | fError(e)
|
---|
602 | {
|
---|
603 | fError.fDestAddress = (e.fDestAddress&0x3)*10 + ((e.fDestAddress>>2)&0xf);
|
---|
604 | fError.fSrcAddress = (e.fSrcAddress &0x3)*10 + ((e.fSrcAddress >>2)&0xf);
|
---|
605 | }
|
---|
606 |
|
---|
607 | } __attribute__((__packed__));
|
---|
608 |
|
---|
609 | /*
|
---|
610 | struct Command
|
---|
611 | {
|
---|
612 | uint16_t fStartDelimiter;
|
---|
613 | uint16_t fCommand;
|
---|
614 | uint16_t fParam[3];
|
---|
615 |
|
---|
616 | Command() { init(*this); }
|
---|
617 |
|
---|
618 | void HtoN() { hton(*this); }
|
---|
619 | void NtoH() { ntoh(*this); }
|
---|
620 |
|
---|
621 | void operator=(const std::vector<uint16_t> &vec) { ntohcpy(vec, *this); }
|
---|
622 |
|
---|
623 | void clear() { reset(*this); }
|
---|
624 |
|
---|
625 |
|
---|
626 | } __attribute__((__packed__));
|
---|
627 | */
|
---|
628 |
|
---|
629 | // --------------------------------------------------------------------
|
---|
630 |
|
---|
631 | inline std::ostream &operator<<(std::ostream &out, const FtuResponse &h)
|
---|
632 | {
|
---|
633 | h.print(out);
|
---|
634 | return out;
|
---|
635 | }
|
---|
636 |
|
---|
637 | inline std::ostream &operator<<(std::ostream &out, const Header &h)
|
---|
638 | {
|
---|
639 | h.print(out);
|
---|
640 | return out;
|
---|
641 | }
|
---|
642 |
|
---|
643 |
|
---|
644 | inline std::ostream &operator<<(std::ostream &out, const FtuList &h)
|
---|
645 | {
|
---|
646 | h.print(out);
|
---|
647 | return out;
|
---|
648 | }
|
---|
649 |
|
---|
650 | inline std::ostream &operator<<(std::ostream &out, const DynamicDataBoard &h)
|
---|
651 | {
|
---|
652 | h.print(out);
|
---|
653 | return out;
|
---|
654 | }
|
---|
655 |
|
---|
656 | inline std::ostream &operator<<(std::ostream &out, const DynamicData &h)
|
---|
657 | {
|
---|
658 | h.print(out);
|
---|
659 | return out;
|
---|
660 | }
|
---|
661 |
|
---|
662 | inline std::ostream &operator<<(std::ostream &out, const StaticDataBoard &h)
|
---|
663 | {
|
---|
664 | h.print(out);
|
---|
665 | return out;
|
---|
666 | }
|
---|
667 |
|
---|
668 | inline std::ostream &operator<<(std::ostream &out, const StaticData &h)
|
---|
669 | {
|
---|
670 | h.print(out);
|
---|
671 | return out;
|
---|
672 | }
|
---|
673 |
|
---|
674 | inline std::ostream &operator<<(std::ostream &out, const Error &h)
|
---|
675 | {
|
---|
676 | h.print(out);
|
---|
677 | return out;
|
---|
678 | }
|
---|
679 | };
|
---|
680 |
|
---|
681 | #endif
|
---|