source: trunk/FACT++/src/HeadersFTM.h@ 19154

Last change on this file since 19154 was 19022, checked in by tbretz, 6 years ago
Suppress some compiler warnings with clang.
File size: 26.8 KB
Line 
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
14namespace 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 kFtmStates = 0x0ff,
27 kFtmLocked = 0x100,
28
29 };
30
31 // idle: not locked: 0x2711
32 // running: not locked: 0x2713
33
34 namespace State
35 {
36 enum StateMachine
37 {
38 kDisconnected = 1,
39 kConnected,
40 kIdle,
41 kValid,
42 kTriggerOn,
43 kConfiguring1,
44 kConfiguring2,
45 kConfigured1,
46 kConfigured2,
47
48 kConfigError1 = 0x101,
49 kConfigError2 = 0x102,
50 //kConfigError3 = 0x103,
51 };
52 }
53
54 /// Command codes for FTM communication
55 enum Commands
56 {
57 // First word
58 kCmdRead = 0x0001, ///< Request data
59 kCmdWrite = 0x0002, ///< Send data
60 kCmdStartRun = 0x0004, ///< Enable the trigger output
61 kCmdStopRun = 0x0008, ///< Disable the trigger output
62 kCmdPing = 0x0010, ///< Ping all FTUs (get FTU list)
63 kCmdCrateReset = 0x0020, ///< Reboot (no power cycle) all FTUs and FADs of one crate
64 kCmdDisableReports = 0x0040, ///< Disable transmission of rate-reports (dynamic data)
65 kCmdConfigFTU = 0x0080, ///< Configure single FTU board
66 kCmdToggleLed = 0xc000,
67
68 // second word for read and write
69 kCmdStaticData = 0x0001, ///< Specifies that static (configuration) data is read/written
70 kCmdDynamicData = 0x0002, ///< Specifies that dynamic data is read/written
71 kCmdRegister = 0x0004, ///< Specifies that a register is read/written
72
73 // second word for StartRun
74 kStartRun = 0x0001, ///< ...until kCmdStopRun
75 kTakeNevents = 0x0002, ///< ...fixed number of events
76
77 // second word for kCmdCrateReset
78 kResetCrate0 = 0x0001,
79 kResetCrate1 = 0x0002,
80 kResetCrate2 = 0x0004,
81 kResetCrate3 = 0x0008,
82 };
83
84
85 /// Types sent in the header of the following data
86 enum Types
87 {
88 kHeader = 0, ///< Local extension to identify a header in fCounter
89 kStaticData = 1, ///< Static (configuration) data
90 kDynamicData = 2, ///< Dynamic data (rates)
91 kFtuList = 3, ///< FTU list (answer of ping)
92 kErrorList = 4, ///< Error list (error when FTU communication failed)
93 kRegister = 5, ///< A requested register value
94 };
95
96 // --------------------------------------------------------------------
97
98 enum Delimiter
99 {
100 kDelimiterStart = 0xfb01, ///< Start delimiter send before each header
101 kDelimiterEnd = 0x04fe ///< End delimiter send after each data block
102 };
103
104#pragma clang diagnostic push
105#pragma clang diagnostic ignored "-Waddress-of-packed-member"
106
107 struct Header
108 {
109 uint16_t fDelimiter; ///< Start delimiter
110 uint16_t fType; ///< Type of the data to be received after the header
111 uint16_t fDataSize; ///< Size in words to be received after the header (incl end delim.)
112 uint16_t fState; ///< State of the FTM central state machine
113 uint64_t fBoardId; ///< FPGA device DNA (unique chip id)
114 uint16_t fFirmwareId; ///< Version number
115 uint32_t fTriggerCounter; ///< FTM internal counter of all trigger decision independant of trigger-line enable/disable (reset: start/stop run)
116 uint64_t fTimeStamp; ///< Internal counter (micro-seconds, reset: start/stop run)
117
118 Header() { init(*this); }
119
120 std::vector<uint16_t> HtoN() const
121 {
122 Header h(*this);
123
124 Reverse(&h.fBoardId);
125 Reverse(&h.fTriggerCounter);
126 Reverse(&h.fTimeStamp);
127
128 return htoncpy(h);
129 }
130 void operator=(const std::vector<uint16_t> &vec)
131 {
132 ntohcpy(vec, *this);
133
134 Reverse(&fBoardId);
135 Reverse(&fTriggerCounter);
136 Reverse(&fTimeStamp);
137 }
138
139 void clear() { reset(*this); }
140 void print(std::ostream &out) const;
141
142 } __attribute__((__packed__));
143
144 struct DimPassport
145 {
146 uint64_t fBoardId;
147 uint16_t fFirmwareId;
148
149 DimPassport(const Header &h) :
150 fBoardId(h.fBoardId),
151 fFirmwareId(h.fFirmwareId)
152 {
153 }
154 } __attribute__((__packed__));
155
156 /*
157 struct DimTriggerCounter
158 {
159 uint64_t fTimeStamp;
160 uint32_t fTriggerCounter;
161
162 DimTriggerCounter(const Header &h) :
163 fTimeStamp(h.fTimeStamp),
164 fTriggerCounter(h.fTriggerCounter)
165 {
166 }
167 } __attribute__((__packed__));
168 */
169
170 struct StaticDataBoard
171 {
172 uint16_t fEnable[4]; /// enable of 4x9 pixels coded as 4x9bits
173 uint16_t fDAC[5]; /// 0-3 (A-D) Threshold of patches, 4 (H) Threshold for N out of 4 (12 bit each)
174 uint16_t fPrescaling; /// Internal readout time of FTUs for trigger counter
175
176 StaticDataBoard() { init(*this); }
177
178 void print(std::ostream &out) const;
179
180 } __attribute__((__packed__));
181
182 struct StaticData
183 {
184 enum Limits
185 {
186 kMaxMultiplicity = 40, ///< Minimum required trigger multiplicity
187 kMaxWindow = 0xf, ///< (4ns * x + 8ns) At least N (multiplicity) rising edges (trigger signal) within this window
188 kMaxDeadTime = 0xffff, ///< (4ns * x + 8ns)
189 kMaxDelayTimeMarker = 0x3ff, ///< (4ns * x + 8ns)
190 kMaxDelayTrigger = 0x3ff, ///< (4ns * x + 8ns)
191 kMaxTriggerInterval = 0x3ff, ///<
192 kMaxIntensity = 0x7f,
193 kMaxSequence = 0x1f,
194 kMaxDAC = 0xfff,
195 kMaxAddr = 0xfff,
196 kMaxPatchIdx = 159,
197 kMaxPixelIdx = 1439,
198 kMaskSettings = 0xf,
199 kMaskLEDs = 0xf,
200 };
201
202 enum GeneralSettings
203 {
204 kTrigger = 0x80, ///< Physics trigger decision (PhysicTrigger)
205 kPedestal = 0x40, ///< Pedestal trigger (artifical)
206 kLPint = 0x20, ///< Enable artificial trigger after light pulse (LP2)
207 kLPext = 0x10, ///< Enable trigger decision after light pulse (CalibrationTrigger, LP1)
208 kExt2 = 0x08, ///< External trigger signal 2
209 kExt1 = 0x04, ///< External trigger signal 1
210 kVeto = 0x02, ///< Veto trigger decision / artifical triggers
211 kClockConditioner = 0x01, ///< Select clock conditioner frequency (1) / time marker (0) as output
212 };
213
214 enum LightPulserEnable
215 {
216 kGroup1 = 0x40,
217 kGroup2 = 0x80,
218 };
219
220 uint16_t fGeneralSettings; /// Enable for different trigger types / select for TIM/ClockConditioner output (only 8 bit used)
221 uint16_t fStatusLEDs; /// only 8 bit used
222 uint16_t fTriggerInterval; /// [ms] Interval between two artificial triggers (no matter which type) minimum 1ms, 10 bit
223 uint16_t fTriggerSequence; /// Ratio between trigger types send as artificial trigger (in this order) 3x5bit
224 uint8_t fIntensityLPext; /// Intensity of LEDs (0-127)
225 uint8_t fEnableLPext; /// Enable for LED group 1/2 (LightPulserEnable)
226 uint8_t fIntensityLPint; /// Intensity of LEDs (0-127)
227 uint8_t fEnableLPint; /// Enable for LED group 1/2 (LightPulserEnable)
228 uint32_t fDummy0;
229 uint16_t fMultiplicityPhysics; /// Required trigger multiplicity for physcis triggers (0-40)
230 uint16_t fMultiplicityCalib; /// Required trigger multiplicity calibration (LPext) triggers (0-40)
231 uint16_t fDelayTrigger; /// (4ns * x + 8ns) FTM internal programmable delay between trigger decision and output
232 uint16_t fDelayTimeMarker; /// (4ns * x + 8ns) FTM internal programmable delay between trigger descision and time marker output
233 uint16_t fDeadTime; /// (4ns * x + 8ns) FTM internal programmable dead time after trigger decision
234 uint32_t fClockConditioner[8]; /// R0, R1, R8, R9, R11, R13, R14, R15
235 uint16_t fWindowPhysics; /// (4ns * x + 8ns) At least N (multiplicity) rising edges (trigger signal) within this window
236 uint16_t fWindowCalib; /// (4ns * x + 8ns) At least N (multiplicity) rising edges (trigger signal) within this window
237 uint16_t fDummy1;
238
239 StaticDataBoard fBoard[4][10]; // 4 crates * 10 boards (Crate0/FTU0 == readout time of FTUs)
240
241 uint16_t fActiveFTU[4]; // 4 crates * 10 bits (FTU enable)
242
243 StaticData() { init(*this); }
244 StaticData(const std::vector<uint16_t> &vec)
245 {
246 ntohcpy(vec, *this);
247
248 for (int i=0; i<8; i++)
249 Reverse(fClockConditioner+i);
250 }
251
252 std::vector<uint16_t> HtoN() const
253 {
254 StaticData d(*this);
255 for (int i=0; i<8; i++)
256 Reverse(d.fClockConditioner+i);
257
258 return htoncpy(d);
259 }
260
261 bool operator==(StaticData d) const
262 {
263 for (int i=0; i<4; i++)
264 for (int j=0; j<10; j++)
265 memcpy(d.fBoard[i][j].fDAC, fBoard[i][j].fDAC, sizeof(uint16_t)*5);
266 return memcmp(this, &d, sizeof(StaticData))==0;
267 }
268
269 bool valid() const { static StaticData empty; return memcmp(this, &empty, sizeof(FTM::StaticData))!=0; }
270
271 void clear() { reset(*this); }
272 void print(std::ostream &out) const;
273
274 StaticDataBoard &operator[](int i) { return fBoard[i/10][i%10]; }
275 const StaticDataBoard &operator[](int i) const { return fBoard[i/10][i%10]; }
276
277 void EnableFTU(int i) { fActiveFTU[i/10] |= (1<<(i%10)); }
278 void DisableFTU(int i) { fActiveFTU[i/10] &= ~(1<<(i%10)); }
279
280 void EnableAllFTU() { for (int i=0; i<4; i++) fActiveFTU[i] = 0x3ff; }
281 void DisableAllFTU() { for (int i=0; i<4; i++) fActiveFTU[i] = 0; }
282
283 void EnableLPint(LightPulserEnable group, bool enable)
284 {
285 if (enable)
286 fEnableLPint |= group;
287 else
288 fEnableLPint &= ~group;
289 }
290
291 void EnableLPext(LightPulserEnable group, bool enable)
292 {
293 if (enable)
294 fEnableLPext |= group;
295 else
296 fEnableLPext &= ~group;
297 }
298
299 void ToggleFTU(int i) { fActiveFTU[i/10] ^= (1<<(i%10)); }
300
301 void Enable(GeneralSettings type, bool enable)
302 {
303 if (enable)
304 fGeneralSettings |= uint16_t(type);
305 else
306 fGeneralSettings &= ~uint16_t(type);
307 }
308
309 bool IsEnabled(GeneralSettings type) const { return fGeneralSettings&uint16_t(type); }
310
311 uint16_t *EnablePixel(int idx, bool enable)
312 {
313 const int pixel = idx%9;
314 const int patch = (idx/9)%4;
315 const int board = (idx/9)/4;
316
317 uint16_t &pix = fBoard[board/10][board%10].fEnable[patch];
318
319 if (enable)
320 pix |= (1<<pixel);
321 else
322 pix &= ~(1<<pixel);
323
324 return &pix;
325 }
326
327 void EnablePatch(int idx, bool enable)
328 {
329 const int patch = idx%4;
330 const int board = idx/4;
331
332 fBoard[board/10][board%10].fEnable[patch] = enable ? 0x1ff : 0;
333 }
334
335 void EnableAllPixel()
336 {
337 for (int c=0; c<4; c++)
338 for (int b=0; b<10; b++)
339 for (int p=0; p<4; p++)
340 fBoard[c][b].fEnable[p] = 0x1ff;
341 }
342
343 bool Enabled(uint16_t idx) const
344 {
345 const int pixel = idx%9;
346 const int patch = (idx/9)%4;
347 const int board = (idx/9)/4;
348
349 return (fBoard[board/10][board%10].fEnable[patch]>>pixel)&1;
350 }
351
352 uint8_t GetSequencePed() const { return (fTriggerSequence>>10)&0x1f; }
353 uint8_t GetSequenceLPint() const { return (fTriggerSequence>> 5)&0x1f; }
354 uint8_t GetSequenceLPext() const { return (fTriggerSequence) &0x1f; }
355
356 void SetSequence(uint8_t ped, uint8_t lpint, uint8_t lpext)
357 {
358 fTriggerSequence = ((ped&0x1f)<<10)|((lpint&0x1f)<<5)|(lpext&0x1f);
359
360 Enable(kPedestal, ped >0);
361 Enable(kLPext, lpext>0);
362 Enable(kLPint, lpint>0);
363 }
364
365 void SetClockRegister(const uint64_t reg[])
366 {
367 for (int i=0; i<8; i++)
368 fClockConditioner[i] = reg[i];
369 }
370
371 void SetPrescaling(uint16_t val)
372 {
373 for (int c=0; c<4; c++)
374 for (int b=0; b<10; b++)
375 fBoard[c][b].fPrescaling = val;
376 }
377
378 } __attribute__((__packed__));
379
380 // DimStructures must be a multiple of two... I don't know why
381 struct DimStaticData
382 {
383 uint64_t fTimeStamp;
384 //8
385 uint16_t fGeneralSettings; // only 8 bit used
386 uint16_t fStatusLEDs; // only 8 bit used
387 uint64_t fActiveFTU; // 40 bits in row
388 //20
389 uint16_t fTriggerInterval; // only 10 bit used
390 //22
391 uint16_t fTriggerSeqLPint; // only 5bits used
392 uint16_t fTriggerSeqLPext; // only 5bits used
393 uint16_t fTriggerSeqPed; // only 5bits used
394 // 28
395 uint8_t fEnableLPint; /// Enable for LED group 1/2 (LightPulserEnable)
396 uint8_t fEnableLPext; /// Enable for LED group 1/2 (LightPulserEnable)
397 uint8_t fIntensityLPint; /// Intensity of LEDs (0-127)
398 uint8_t fIntensityLPext; /// Intensity of LEDs (0-127)
399 //32
400 uint16_t fMultiplicityPhysics; // 0-40
401 uint16_t fMultiplicityCalib; // 0-40
402 //36
403 uint16_t fWindowPhysics;
404 uint16_t fWindowCalib;
405 //40
406 uint16_t fDelayTrigger;
407 uint16_t fDelayTimeMarker;
408 uint32_t fDeadTime;
409 //48
410 uint32_t fClockConditioner[8];
411 //64
412 uint16_t fEnable[90]; // 160*9bit = 180byte
413 uint16_t fThreshold[160];
414 uint16_t fMultiplicity[40]; // N out of 4
415 uint16_t fPrescaling[40];
416 // 640+64 = 704
417
418 bool HasTrigger() const { return fGeneralSettings & StaticData::kTrigger; }
419 bool HasPedestal() const { return fGeneralSettings & StaticData::kPedestal; }
420 bool HasLPext() const { return fGeneralSettings & StaticData::kLPext; }
421 bool HasLPint() const { return fGeneralSettings & StaticData::kLPint; }
422 bool HasExt2() const { return fGeneralSettings & StaticData::kExt2; }
423 bool HasExt1() const { return fGeneralSettings & StaticData::kExt1; }
424 bool HasVeto() const { return fGeneralSettings & StaticData::kVeto; }
425 bool HasClockConditioner() const { return fGeneralSettings & StaticData::kClockConditioner; }
426
427 bool HasLPextG1() const { return fEnableLPext&StaticData::kGroup1; }
428 bool HasLPextG2() const { return fEnableLPext&StaticData::kGroup2; }
429 bool HasLPintG1() const { return fEnableLPint&StaticData::kGroup1; }
430 bool HasLPintG2() const { return fEnableLPint&StaticData::kGroup2; }
431
432 bool IsActive(int i) const { return fActiveFTU&(uint64_t(1)<<i); }
433 bool IsEnabled(int i) const { return fEnable[i/16]&(1<<(i%16)); }
434
435 DimStaticData() { memset(this, 0, sizeof(DimStaticData)); }
436
437 DimStaticData(const Header &h, const StaticData &d) :
438 fTimeStamp(h.fTimeStamp),
439 fGeneralSettings(d.fGeneralSettings),
440 fStatusLEDs(d.fStatusLEDs),
441 fActiveFTU( uint64_t(d.fActiveFTU[0]) |
442 (uint64_t(d.fActiveFTU[1])<<10) |
443 (uint64_t(d.fActiveFTU[2])<<20) |
444 (uint64_t(d.fActiveFTU[3])<<30)),
445 fTriggerInterval(d.fTriggerInterval),
446 fTriggerSeqLPint((d.fTriggerSequence>>5)&0x1f),
447 fTriggerSeqLPext((d.fTriggerSequence)&0x1f),
448 fTriggerSeqPed((d.fTriggerSequence>>10)&0x1f),
449 fEnableLPint(d.fEnableLPint),
450 fEnableLPext(d.fEnableLPext),
451 fIntensityLPint(d.fIntensityLPint),
452 fIntensityLPext(d.fIntensityLPext),
453 fMultiplicityPhysics(d.fMultiplicityPhysics),
454 fMultiplicityCalib(d.fMultiplicityCalib),
455 fWindowPhysics(d.fWindowPhysics*4+8),
456 fWindowCalib(d.fWindowCalib*4+8),
457 fDelayTrigger(d.fDelayTrigger*4+8),
458 fDelayTimeMarker(d.fDelayTimeMarker*4+8),
459 fDeadTime(uint32_t(d.fDeadTime)*4+8)
460 {
461 memcpy(fClockConditioner, d.fClockConditioner, sizeof(uint32_t)*8);
462
463 uint16_t src[160];
464 for (int i=0; i<40; i++)
465 {
466 for (int j=0; j<4; j++)
467 {
468 src[i*4+j] = d[i].fEnable[j];
469 fThreshold[i*4+j] = d[i].fDAC[j];
470 }
471
472 fMultiplicity[i] = d[i].fDAC[4];
473 fPrescaling[i] = d[i].fPrescaling+1;
474 }
475 bitcpy(fEnable, 90, src, 160, 9);
476 }
477
478 } __attribute__((__packed__));
479
480
481 struct DynamicDataBoard
482 {
483 uint32_t fRatePatch[4]; // Patch 0,1,2,3
484 uint32_t fRateTotal; // Sum
485
486 uint16_t fOverflow; // Patches: bits 0-3, total 4
487 uint16_t fCrcError;
488
489 void print(std::ostream &out) const;
490
491 void reverse()
492 {
493 for (int i=0; i<4; i++)
494 Reverse(fRatePatch+i);
495
496 Reverse(&fRateTotal);
497 }
498
499 uint32_t &operator[](int i) { return fRatePatch[i]; }
500
501 } __attribute__((__packed__));
502
503
504 struct DynamicData
505 {
506 uint64_t fOnTimeCounter;
507 uint16_t fTempSensor[4]; // U45, U46, U48, U49
508
509 DynamicDataBoard fBoard[4][10]; // 4 crates * 10 boards
510
511 DynamicData() { init(*this); }
512
513 std::vector<uint16_t> HtoN() const
514 {
515 DynamicData d(*this);
516
517 Reverse(&d.fOnTimeCounter);
518
519 for (int c=0; c<4; c++)
520 for (int b=0; b<10; b++)
521 d.fBoard[c][b].reverse();
522
523 return htoncpy(d);
524 }
525
526 void operator=(const std::vector<uint16_t> &vec)
527 {
528 ntohcpy(vec, *this);
529
530 Reverse(&fOnTimeCounter);
531
532 for (int c=0; c<4; c++)
533 for (int b=0; b<10; b++)
534 fBoard[c][b].reverse();
535 }
536
537 void clear() { reset(*this); }
538 void print(std::ostream &out) const;
539
540 DynamicDataBoard &operator[](int i) { return fBoard[i/10][i%10]; }
541 const DynamicDataBoard &operator[](int i) const { return fBoard[i/10][i%10]; }
542
543 } __attribute__((__packed__));
544
545
546 struct DimDynamicData
547 {
548 uint64_t fTimeStamp;
549
550 uint64_t fOnTimeCounter;
551 float fTempSensor[4];
552
553 uint32_t fRatePatch[160];
554
555 uint32_t fRateBoard[40];
556 uint16_t fRateOverflow[40];
557
558 uint16_t fPrescaling[40];
559
560 uint16_t fCrcError[40];
561
562 uint16_t fState;
563
564 DimDynamicData(const Header &h, const DynamicData &d, const StaticData &s) :
565 fTimeStamp(h.fTimeStamp),
566 fOnTimeCounter(d.fOnTimeCounter),
567 fState(h.fState)
568 {
569 for (int i=0; i<4; i++)
570 fTempSensor[i] = d.fTempSensor[i];
571
572 for (int i=0; i<40; i++)
573 {
574 fRateBoard[i] = d[i].fRateTotal;
575 fRateOverflow[i] = d[i].fOverflow;
576 fCrcError[i] = d[i].fCrcError;
577 for (int j=0; j<4; j++)
578 fRatePatch[i*4+j] = d[i].fRatePatch[j];
579
580 fPrescaling[i] = s[i].fPrescaling+1;
581 }
582 }
583
584 } __attribute__((__packed__));
585
586 struct DimTriggerRates
587 {
588 uint64_t fTimeStamp;
589 uint64_t fOnTimeCounter;
590 uint32_t fTriggerCounter;
591 float fTriggerRate;
592 float fBoardRate[40];
593 float fPatchRate[160];
594
595 float fElapsedTime;
596 float fOnTime;
597
598 DimTriggerRates() { memset(this, 0, sizeof(DimTriggerRates)); }
599
600 DimTriggerRates(const Header &h, const DynamicData &d, const StaticData &s, float rate, float et, float ot) :
601 fTimeStamp(h.fTimeStamp), fOnTimeCounter(d.fOnTimeCounter),
602 fTriggerCounter(h.fTriggerCounter), fTriggerRate(rate),
603 fElapsedTime(et), fOnTime(ot)
604 {
605 for (int i=0; i<40; i++)
606 {
607 if ((d[i].fOverflow>>4)&1)
608 fBoardRate[i] = float(UINT32_MAX+1)*2/(s[i].fPrescaling+1);
609 else
610 fBoardRate[i] = float(d[i].fRateTotal)*2/(s[i].fPrescaling+1);
611
612 // FIXME: Include fCrcError in calculation
613 //fRateOverflow[i] = d[i].fOverflow;
614 for (int j=0; j<4; j++)
615 if ((d[i].fOverflow>>j)&1)
616 fPatchRate[i*4+j] = float(UINT32_MAX+1)*2/(s[i].fPrescaling+1);
617 else
618 fPatchRate[i*4+j] = float(d[i].fRatePatch[j])*2/(s[i].fPrescaling+1);
619 }
620 }
621
622 } __attribute__((__packed__));
623
624
625 struct FtuResponse
626 {
627 uint16_t fPingAddr; // Number of Pings and addr (pings= see error)
628 uint64_t fDNA;
629 uint16_t fErrorCounter; //
630
631 void reverse() { Reverse(&fDNA); }
632
633 void print(std::ostream &out) const;
634
635 } __attribute__((__packed__));
636
637#pragma clang diagnostic pop
638
639 struct FtuList
640 {
641 uint16_t fNumBoards; /// Total number of boards responded
642 uint16_t fNumBoardsCrate[4]; /// Num of board responded in crate 0-3
643 uint16_t fActiveFTU[4]; /// List of active FTU boards in crate 0-3
644
645 FtuResponse fFTU[4][10];
646
647 FtuList() { init(*this); }
648
649 std::vector<uint16_t> HtoN() const
650 {
651 FtuList d(*this);
652
653 for (int c=0; c<4; c++)
654 for (int b=0; b<10; b++)
655 d.fFTU[c][b].reverse();
656
657 return htoncpy(d);
658 }
659
660 void operator=(const std::vector<uint16_t> &vec)
661 {
662 ntohcpy(vec, *this);
663
664 for (int c=0; c<4; c++)
665 for (int b=0; b<10; b++)
666 fFTU[c][b].reverse();
667 }
668
669 void clear() { reset(*this); }
670 void print(std::ostream &out) const;
671
672 FtuResponse &operator[](int i) { return fFTU[i/10][i%10]; }
673 const FtuResponse &operator[](int i) const { return fFTU[i/10][i%10]; }
674
675 } __attribute__((__packed__));
676
677 struct DimFtuList
678 {
679 uint64_t fTimeStamp;
680 uint64_t fActiveFTU;
681
682 uint16_t fNumBoards; /// Number of boards answered in total
683 uint8_t fNumBoardsCrate[4]; /// Number of boards answered per crate
684
685 uint64_t fDNA[40]; /// DNA of FTU board
686 uint8_t fAddr[40]; /// Address of FTU board
687 uint8_t fPing[40]; /// Number of pings until response (same as in Error)
688
689 DimFtuList(const Header &h, const FtuList &d) :
690 fTimeStamp(h.fTimeStamp),
691 fActiveFTU( uint64_t(d.fActiveFTU[0]) |
692 (uint64_t(d.fActiveFTU[1])<<10) |
693 (uint64_t(d.fActiveFTU[2])<<20) |
694 (uint64_t(d.fActiveFTU[3])<<30)),
695 fNumBoards(d.fNumBoards)
696 {
697 for (int i=0; i<4; i++)
698 fNumBoardsCrate[i] = d.fNumBoardsCrate[i];
699
700 for (int i=0; i<40; i++)
701 {
702 fDNA[i] = d[i].fDNA;
703 fAddr[i] = d[i].fPingAddr&0x3f;
704 fPing[i] = (d[i].fPingAddr>>8)&0x3;
705 }
706 }
707
708 bool IsActive(int i) const { return fActiveFTU&(uint64_t(1)<<i); }
709
710 } __attribute__((__packed__));
711
712
713 struct Error
714 {
715 uint16_t fNumCalls; // 0=error, >1 needed repetition but successfull
716
717 uint16_t fDelimiter;
718 uint16_t fDestAddress;
719 uint16_t fSrcAddress;
720 uint16_t fFirmwareId;
721 uint16_t fCommand;
722 uint16_t fData[21];
723 uint16_t fCrcErrorCounter;
724 uint16_t fCrcCheckSum;
725
726 Error() { init(*this); }
727
728 std::vector<uint16_t> HtoN() const
729 {
730 return htoncpy(*this);
731 }
732
733 void operator=(const std::vector<uint16_t> &vec) { ntohcpy(vec, *this); }
734
735 void clear() { reset(*this); }
736
737 uint16_t &operator[](int idx) { return fData[idx]; }
738 const uint16_t &operator[](int idx) const { return fData[idx]; }
739
740 void print(std::ostream &out) const;
741
742 } __attribute__((__packed__));
743
744 struct DimError
745 {
746 uint64_t fTimeStamp;
747 Error fError;
748
749 DimError(const Header &h, const Error &e) :
750 fTimeStamp(h.fTimeStamp),
751 fError(e)
752 {
753 fError.fDestAddress = (e.fDestAddress&0x3)*10 + ((e.fDestAddress>>2)&0xf);
754 fError.fSrcAddress = (e.fSrcAddress &0x3)*10 + ((e.fSrcAddress >>2)&0xf);
755 }
756
757 } __attribute__((__packed__));
758
759 /*
760 struct Command
761 {
762 uint16_t fStartDelimiter;
763 uint16_t fCommand;
764 uint16_t fParam[3];
765
766 Command() { init(*this); }
767
768 void HtoN() { hton(*this); }
769 void NtoH() { ntoh(*this); }
770
771 void operator=(const std::vector<uint16_t> &vec) { ntohcpy(vec, *this); }
772
773 void clear() { reset(*this); }
774
775
776 } __attribute__((__packed__));
777 */
778
779 // --------------------------------------------------------------------
780
781 inline std::ostream &operator<<(std::ostream &out, const FtuResponse &h)
782 {
783 h.print(out);
784 return out;
785 }
786
787 inline std::ostream &operator<<(std::ostream &out, const Header &h)
788 {
789 h.print(out);
790 return out;
791 }
792
793
794 inline std::ostream &operator<<(std::ostream &out, const FtuList &h)
795 {
796 h.print(out);
797 return out;
798 }
799
800 inline std::ostream &operator<<(std::ostream &out, const DynamicDataBoard &h)
801 {
802 h.print(out);
803 return out;
804 }
805
806 inline std::ostream &operator<<(std::ostream &out, const DynamicData &h)
807 {
808 h.print(out);
809 return out;
810 }
811
812 inline std::ostream &operator<<(std::ostream &out, const StaticDataBoard &h)
813 {
814 h.print(out);
815 return out;
816 }
817
818 inline std::ostream &operator<<(std::ostream &out, const StaticData &h)
819 {
820 h.print(out);
821 return out;
822 }
823
824 inline std::ostream &operator<<(std::ostream &out, const Error &h)
825 {
826 h.print(out);
827 return out;
828 }
829};
830
831#endif
Note: See TracBrowser for help on using the repository browser.