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

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