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