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

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