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

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