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

Last change on this file since 11711 was 11708, checked in by tbretz, 14 years ago
Added light-pulser settings to the DimStaticData structure.
File size: 24.7 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 kTakingData ,//= ConnectionFTM::kTakingData,
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 struct DimTriggerCounter
150 {
151 uint64_t fTimeStamp;
152 uint32_t fTriggerCounter;
153
154 DimTriggerCounter(const Header &h) :
155 fTimeStamp(h.fTimeStamp),
156 fTriggerCounter(h.fTriggerCounter)
157 {
158 }
159 } __attribute__((__packed__));
160
161
162 struct StaticDataBoard
163 {
164 uint16_t fEnable[4]; /// enable of 4x9 pixels coded as 4x9bits
165 uint16_t fDAC[5]; /// 0-3 (A-D) Threshold of patches, 4 (H) Threshold for N out of 4 (12 bit each)
166 uint16_t fPrescaling; /// Internal readout time of FTUs for trigger counter
167
168 StaticDataBoard() { init(*this); }
169
170 void print(std::ostream &out) const;
171
172 } __attribute__((__packed__));
173
174 struct StaticData
175 {
176 enum Limits
177 {
178 kMaxMultiplicity = 40, ///< Minimum required trigger multiplicity
179 kMaxWindow = 0xf, ///< (4ns * x + 8ns) At least N (multiplicity) rising edges (trigger signal) within this window
180 kMaxDeadTime = 0xffff, ///< (4ns * x + 8ns)
181 kMaxDelayTimeMarker = 0x3ff, ///< (4ns * x + 8ns)
182 kMaxDelayTrigger = 0x3ff, ///< (4ns * x + 8ns)
183 kMaxTriggerInterval = 0x3ff, ///<
184 kMaxIntensity = 0x7f,
185 kMaxSequence = 0x1f,
186 kMaxDAC = 0xfff,
187 kMaxAddr = 0xfff,
188 kMaxPatchIdx = 159,
189 kMaxPixelIdx = 1439,
190 kMaskSettings = 0xf,
191 kMaskLEDs = 0xf,
192 };
193
194 enum GeneralSettings
195 {
196 kTrigger = 0x80, ///< Physics trigger decision (PhysicTrigger)
197 kPedestal = 0x40, ///< Pedestal trigger (artifical)
198 kLPint = 0x20, ///< Enable artificial trigger after light pulse (LP2)
199 kLPext = 0x10, ///< Enable trigger decision after light pulse (CalibrationTrigger, LP1)
200 kExt2 = 0x08, ///< External trigger signal 2
201 kExt1 = 0x04, ///< External trigger signal 1
202 kVeto = 0x02, ///< Veto trigger decision / artifical triggers
203 kClockConditioner = 0x01, ///< Select clock conditioner frequency (1) / time marker (0) as output
204 };
205
206 enum LightPulserEnable
207 {
208 kGroup1 = 0x4,
209 kGroup2 = 0x8,
210 };
211
212 uint16_t fGeneralSettings; /// Enable for different trigger types / select for TIM/ClockConditioner output (only 8 bit used)
213 uint16_t fStatusLEDs; /// only 8 bit used
214 uint16_t fTriggerInterval; /// [ms] Interval between two artificial triggers (no matter which type) minimum 1ms, 10 bit
215 uint16_t fTriggerSequence; /// Ratio between trigger types send as artificial trigger (in this order) 3x5bit
216 uint8_t fEnableLPext; /// Enable for LED group 1/2 (LightPulserEnable)
217 uint8_t fIntensityLPext; /// Intensity of LEDs (0-127)
218 uint8_t fEnableLPint; /// Enable for LED group 1/2 (LightPulserEnable)
219 uint8_t fIntensityLPint; /// Intensity of LEDs (0-127)
220 uint32_t fDummy0;
221 uint16_t fMultiplicityPhysics; /// Required trigger multiplicity for physcis triggers (0-40)
222 uint16_t fMultiplicityCalib; /// Required trigger multiplicity calibration (LPext) triggers (0-40)
223 uint16_t fDelayTrigger; /// (4ns * x + 8ns) FTM internal programmable delay between trigger decision and output
224 uint16_t fDelayTimeMarker; /// (4ns * x + 8ns) FTM internal programmable delay between trigger descision and time marker output
225 uint16_t fDeadTime; /// (4ns * x + 8ns) FTM internal programmable dead time after trigger decision
226 uint32_t fClockConditioner[8]; /// R0, R1, R8, R9, R11, R13, R14, R15
227 uint16_t fWindowPhysics; /// (4ns * x + 8ns) At least N (multiplicity) rising edges (trigger signal) within this window
228 uint16_t fWindowCalib; /// (4ns * x + 8ns) At least N (multiplicity) rising edges (trigger signal) within this window
229 uint16_t fDummy1;
230
231 StaticDataBoard fBoard[4][10]; // 4 crates * 10 boards (Crate0/FTU0 == readout time of FTUs)
232
233 uint16_t fActiveFTU[4]; // 4 crates * 10 bits (FTU enable)
234
235 StaticData() { init(*this); }
236 StaticData(const std::vector<uint16_t> &vec)
237 {
238 ntohcpy(vec, *this);
239
240 for (int i=0; i<8; i++)
241 Reverse(fClockConditioner+i);
242 }
243
244 std::vector<uint16_t> HtoN() const
245 {
246 StaticData d(*this);
247 for (int i=0; i<8; i++)
248 Reverse(d.fClockConditioner+i);
249
250 return htoncpy(d);
251 }
252
253 bool operator==(const StaticData &d) const
254 {
255 return memcmp(this, &d, sizeof(StaticData))==0;
256 }
257
258 void clear() { reset(*this); }
259 void print(std::ostream &out) const;
260
261 StaticDataBoard &operator[](int i) { return fBoard[i/10][i%10]; }
262 const StaticDataBoard &operator[](int i) const { return fBoard[i/10][i%10]; }
263
264 void EnableFTU(int i) { fActiveFTU[i/10] |= (1<<(i%10)); }
265 void DisableFTU(int i) { fActiveFTU[i/10] &= ~(1<<(i%10)); }
266
267 void EnableAllFTU() { for (int i=0; i<4; i++) fActiveFTU[i] = 0x3ff; }
268 void DisableAllFTU() { for (int i=0; i<4; i++) fActiveFTU[i] = 0; }
269
270 void EnableLPint(LightPulserEnable group, bool enable)
271 {
272 if (enable)
273 fEnableLPint |= group;
274 else
275 fEnableLPint &= ~group;
276 }
277
278 void EnableLPext(LightPulserEnable group, bool enable)
279 {
280 if (enable)
281 fEnableLPext |= group;
282 else
283 fEnableLPext &= ~group;
284 }
285
286 void ToggleFTU(int i) { fActiveFTU[i/10] ^= (1<<(i%10)); }
287
288 void Enable(GeneralSettings type, bool enable)
289 {
290 if (enable)
291 fGeneralSettings |= uint16_t(type);
292 else
293 fGeneralSettings &= ~uint16_t(type);
294 }
295
296 bool IsEnabled(GeneralSettings type) const { return fGeneralSettings&uint16_t(type); }
297
298 uint16_t *EnablePixel(int idx, bool enable)
299 {
300 const int pixel = idx%9;
301 const int patch = (idx/9)%4;
302 const int board = (idx/9)/4;
303
304 uint16_t &pix = fBoard[board/10][board%10].fEnable[patch];
305
306 if (enable)
307 pix |= (1<<pixel);
308 else
309 pix &= ~(1<<pixel);
310
311 return &pix;
312 }
313
314 void EnableAllPixel()
315 {
316 for (int c=0; c<4; c++)
317 for (int b=0; b<10; b++)
318 for (int p=0; p<4; p++)
319 fBoard[c][b].fEnable[p] = 0x1ff;
320 }
321
322 bool Enabled(uint16_t idx) const
323 {
324 const int pixel = idx%9;
325 const int patch = (idx/9)%4;
326 const int board = (idx/9)/4;
327
328 return (fBoard[board/10][board%10].fEnable[patch]>>pixel)&1;
329 }
330
331 uint8_t GetSequencePed() const { return (fTriggerSequence>>10)&0x1f; }
332 uint8_t GetSequenceLPint() const { return (fTriggerSequence>> 5)&0x1f; }
333 uint8_t GetSequenceLPext() const { return (fTriggerSequence) &0x1f; }
334
335 void SetSequence(uint8_t ped, uint8_t lpint, uint8_t lpext)
336 {
337 fTriggerSequence = ((ped&0x1f)<<10)|((lpint&0x1f)<<5)|(lpext&0x1f);
338
339 Enable(kPedestal, ped >0);
340 Enable(kLPext, lpext>0);
341 Enable(kLPint, lpint>0);
342 }
343
344 void SetClockRegister(const uint64_t reg[])
345 {
346 for (int i=0; i<8; i++)
347 fClockConditioner[i] = reg[i];
348 }
349
350 void SetPrescaling(uint16_t val)
351 {
352 for (int c=0; c<4; c++)
353 for (int b=0; b<10; b++)
354 fBoard[c][b].fPrescaling = val;
355 }
356
357 } __attribute__((__packed__));
358
359 // DimStructures must be a multiple of two... I don't know why
360 struct DimStaticData
361 {
362 uint64_t fTimeStamp;
363 //8
364 uint16_t fGeneralSettings; // only 8 bit used
365 uint16_t fStatusLEDs; // only 8 bit used
366 uint64_t fActiveFTU; // 40 bits in row
367 //20
368 uint16_t fTriggerInterval; // only 10 bit used
369 //22
370 uint16_t fTriggerSeqLPint; // only 5bits used
371 uint16_t fTriggerSeqLPext; // only 5bits used
372 uint16_t fTriggerSeqPed; // only 5bits used
373 // 28
374 uint8_t fEnableLPint; /// Enable for LED group 1/2 (LightPulserEnable)
375 uint8_t fEnableLPext; /// Enable for LED group 1/2 (LightPulserEnable)
376 uint8_t fIntensityLPint; /// Intensity of LEDs (0-127)
377 uint8_t fIntensityLPext; /// Intensity of LEDs (0-127)
378 //32
379 uint16_t fMultiplicityPhysics; // 0-40
380 uint16_t fMultiplicityCalib; // 0-40
381 //36
382 uint16_t fWindowPhysics;
383 uint16_t fWindowCalib;
384 //40
385 uint16_t fDelayTrigger;
386 uint16_t fDelayTimeMarker;
387 uint32_t fDeadTime;
388 //48
389 uint32_t fClockConditioner[8];
390 //64
391 uint16_t fEnable[90]; // 160*9bit = 180byte
392 uint16_t fThreshold[160];
393 uint16_t fMultiplicity[40]; // N out of 4
394 uint16_t fPrescaling[40];
395 // 640+64 = 704
396
397 bool HasTrigger() const { return fGeneralSettings & StaticData::kTrigger; }
398 bool HasPedestal() const { return fGeneralSettings & StaticData::kPedestal; }
399 bool HasLPext() const { return fGeneralSettings & StaticData::kLPext; }
400 bool HasLPint() const { return fGeneralSettings & StaticData::kLPint; }
401 bool HasExt2() const { return fGeneralSettings & StaticData::kExt2; }
402 bool HasExt1() const { return fGeneralSettings & StaticData::kExt1; }
403 bool HasVeto() const { return fGeneralSettings & StaticData::kVeto; }
404 bool HasClockConditioner() const { return fGeneralSettings & StaticData::kClockConditioner; }
405
406 bool HasLPextG1() const { return fEnableLPext&StaticData::kGroup1; }
407 bool HasLPextG2() const { return fEnableLPext&StaticData::kGroup2; }
408 bool HasLPintG1() const { return fEnableLPint&StaticData::kGroup1; }
409 bool HasLPintG2() const { return fEnableLPint&StaticData::kGroup2; }
410
411 bool IsActive(int i) const { return fActiveFTU&(uint64_t(1)<<i); }
412 bool IsEnabled(int i) const { return fEnable[i/16]&(1<<(i%16)); }
413
414 DimStaticData() { memset(this, 0, sizeof(DimStaticData)); }
415
416 DimStaticData(const Header &h, const StaticData &d) :
417 fTimeStamp(h.fTimeStamp),
418 fGeneralSettings(d.fGeneralSettings),
419 fStatusLEDs(d.fStatusLEDs),
420 fActiveFTU( uint64_t(d.fActiveFTU[0]) |
421 (uint64_t(d.fActiveFTU[1])<<10) |
422 (uint64_t(d.fActiveFTU[2])<<20) |
423 (uint64_t(d.fActiveFTU[3])<<30)),
424 fTriggerInterval(d.fTriggerInterval),
425 fTriggerSeqLPint((d.fTriggerSequence>>5)&0x1f),
426 fTriggerSeqLPext((d.fTriggerSequence)&0x1f),
427 fTriggerSeqPed((d.fTriggerSequence>>10)&0x1f),
428 fEnableLPint(d.fEnableLPint),
429 fEnableLPext(d.fEnableLPext),
430 fIntensityLPint(d.fIntensityLPext),
431 fIntensityLPext(d.fIntensityLPext),
432 fMultiplicityPhysics(d.fMultiplicityPhysics),
433 fMultiplicityCalib(d.fMultiplicityCalib),
434 fWindowPhysics(d.fWindowPhysics*4+8),
435 fWindowCalib(d.fWindowCalib*4+8),
436 fDelayTrigger(d.fDelayTrigger*4+8),
437 fDelayTimeMarker(d.fDelayTimeMarker*4+8),
438 fDeadTime(uint32_t(d.fDeadTime)*4+8)
439 {
440 memcpy(fClockConditioner, d.fClockConditioner, sizeof(uint32_t)*8);
441
442 uint16_t src[160];
443 for (int i=0; i<40; i++)
444 {
445 for (int j=0; j<4; j++)
446 {
447 src[i*4+j] = d[i].fEnable[j];
448 fThreshold[i*4+j] = d[i].fDAC[j];
449 }
450
451 fMultiplicity[i] = d[i].fDAC[4];
452 fPrescaling[i] = d[i].fPrescaling+1;
453 }
454 bitcpy(fEnable, 90, src, 160, 9);
455 }
456
457 } __attribute__((__packed__));
458
459
460 struct DynamicDataBoard
461 {
462 uint32_t fRatePatch[4]; // Patch 0,1,2,3
463 uint32_t fRateTotal; // Sum
464
465 uint16_t fOverflow; // Patches: bits 0-3, total 4
466 uint16_t fCrcError;
467
468 void print(std::ostream &out) const;
469
470 void reverse()
471 {
472 for (int i=0; i<4; i++)
473 Reverse(fRatePatch+i);
474
475 Reverse(&fRateTotal);
476 }
477
478 uint32_t &operator[](int i) { return fRatePatch[i]; }
479
480 } __attribute__((__packed__));
481
482
483 struct DynamicData
484 {
485 uint64_t fOnTimeCounter;
486 uint16_t fTempSensor[4]; // U45, U46, U48, U49
487
488 DynamicDataBoard fBoard[4][10]; // 4 crates * 10 boards
489
490 DynamicData() { init(*this); }
491
492 std::vector<uint16_t> HtoN() const
493 {
494 DynamicData d(*this);
495
496 Reverse(&d.fOnTimeCounter);
497
498 for (int c=0; c<4; c++)
499 for (int b=0; b<10; b++)
500 d.fBoard[c][b].reverse();
501
502 return htoncpy(d);
503 }
504
505 void operator=(const std::vector<uint16_t> &vec)
506 {
507 ntohcpy(vec, *this);
508
509 Reverse(&fOnTimeCounter);
510
511 for (int c=0; c<4; c++)
512 for (int b=0; b<10; b++)
513 fBoard[c][b].reverse();
514 }
515
516 void clear() { reset(*this); }
517 void print(std::ostream &out) const;
518
519 DynamicDataBoard &operator[](int i) { return fBoard[i/10][i%10]; }
520 const DynamicDataBoard &operator[](int i) const { return fBoard[i/10][i%10]; }
521
522 } __attribute__((__packed__));
523
524
525 struct DimDynamicData
526 {
527 uint64_t fTimeStamp;
528
529 uint64_t fOnTimeCounter;
530 float fTempSensor[4];
531
532 uint32_t fRatePatch[160];
533
534 uint32_t fRateBoard[40];
535 uint16_t fRateOverflow[40];
536
537 uint16_t fCrcError[40];
538
539 uint16_t fState;
540
541 DimDynamicData(const Header &h, const DynamicData &d) :
542 fTimeStamp(h.fTimeStamp),
543 fOnTimeCounter(d.fOnTimeCounter),
544 fState(h.fState)
545 {
546 for (int i=0; i<4; i++)
547 fTempSensor[i] = d.fTempSensor[i];
548
549 for (int i=0; i<40; i++)
550 {
551 fRateBoard[i] = d[i].fRateTotal;
552 fRateOverflow[i] = d[i].fOverflow;
553 fCrcError[i] = d[i].fCrcError;
554 for (int j=0; j<4; j++)
555 fRatePatch[i*4+j] = d[i].fRatePatch[j];
556 }
557 }
558
559 } __attribute__((__packed__));
560
561
562 struct FtuResponse
563 {
564 uint16_t fPingAddr; // Number of Pings and addr (pings= see error)
565 uint64_t fDNA;
566 uint16_t fErrorCounter; //
567
568 void reverse() { Reverse(&fDNA); }
569
570 void print(std::ostream &out) const;
571
572 } __attribute__((__packed__));
573
574 struct FtuList
575 {
576 uint16_t fNumBoards; /// Total number of boards responded
577 uint16_t fNumBoardsCrate[4]; /// Num of board responded in crate 0-3
578 uint16_t fActiveFTU[4]; /// List of active FTU boards in crate 0-3
579
580 FtuResponse fFTU[4][10];
581
582 FtuList() { init(*this); }
583
584 std::vector<uint16_t> HtoN() const
585 {
586 FtuList d(*this);
587
588 for (int c=0; c<4; c++)
589 for (int b=0; b<10; b++)
590 d.fFTU[c][b].reverse();
591
592 return htoncpy(d);
593 }
594
595 void operator=(const std::vector<uint16_t> &vec)
596 {
597 ntohcpy(vec, *this);
598
599 for (int c=0; c<4; c++)
600 for (int b=0; b<10; b++)
601 fFTU[c][b].reverse();
602 }
603
604 void clear() { reset(*this); }
605 void print(std::ostream &out) const;
606
607 FtuResponse &operator[](int i) { return fFTU[i/10][i%10]; }
608 const FtuResponse &operator[](int i) const { return fFTU[i/10][i%10]; }
609
610 } __attribute__((__packed__));
611
612 struct DimFtuList
613 {
614 uint64_t fTimeStamp;
615 uint64_t fActiveFTU;
616
617 uint16_t fNumBoards; /// Number of boards answered in total
618 uint8_t fNumBoardsCrate[4]; /// Number of boards answered per crate
619
620 uint64_t fDNA[40]; /// DNA of FTU board
621 uint8_t fAddr[40]; /// Address of FTU board
622 uint8_t fPing[40]; /// Number of pings until response (same as in Error)
623
624 DimFtuList(const Header &h, const FtuList &d) :
625 fTimeStamp(h.fTimeStamp),
626 fActiveFTU( uint64_t(d.fActiveFTU[0]) |
627 (uint64_t(d.fActiveFTU[1])<<10) |
628 (uint64_t(d.fActiveFTU[2])<<20) |
629 (uint64_t(d.fActiveFTU[3])<<30)),
630 fNumBoards(d.fNumBoards)
631 {
632 for (int i=0; i<4; i++)
633 fNumBoardsCrate[i] = d.fNumBoardsCrate[i];
634
635 for (int i=0; i<40; i++)
636 {
637 fDNA[i] = d[i].fDNA;
638 fAddr[i] = d[i].fPingAddr&0x3f;
639 fPing[i] = (d[i].fPingAddr>>8)&0x3;
640 }
641 }
642
643 bool IsActive(int i) const { return fActiveFTU&(uint64_t(1)<<i); }
644
645 } __attribute__((__packed__));
646
647
648 struct Error
649 {
650 uint16_t fNumCalls; // 0=error, >1 needed repetition but successfull
651
652 uint16_t fDelimiter;
653 uint16_t fDestAddress;
654 uint16_t fSrcAddress;
655 uint16_t fFirmwareId;
656 uint16_t fCommand;
657 uint16_t fData[21];
658 uint16_t fCrcErrorCounter;
659 uint16_t fCrcCheckSum;
660
661 Error() { init(*this); }
662
663 std::vector<uint16_t> HtoN() const
664 {
665 return htoncpy(*this);
666 }
667
668 void operator=(const std::vector<uint16_t> &vec) { ntohcpy(vec, *this); }
669
670 void clear() { reset(*this); }
671
672 uint16_t &operator[](int idx) { return fData[idx]; }
673 const uint16_t &operator[](int idx) const { return fData[idx]; }
674
675 void print(std::ostream &out) const;
676
677 } __attribute__((__packed__));
678
679 struct DimError
680 {
681 uint64_t fTimeStamp;
682 Error fError;
683
684 DimError(const Header &h, const Error &e) :
685 fTimeStamp(h.fTimeStamp),
686 fError(e)
687 {
688 fError.fDestAddress = (e.fDestAddress&0x3)*10 + ((e.fDestAddress>>2)&0xf);
689 fError.fSrcAddress = (e.fSrcAddress &0x3)*10 + ((e.fSrcAddress >>2)&0xf);
690 }
691
692 } __attribute__((__packed__));
693
694 /*
695 struct Command
696 {
697 uint16_t fStartDelimiter;
698 uint16_t fCommand;
699 uint16_t fParam[3];
700
701 Command() { init(*this); }
702
703 void HtoN() { hton(*this); }
704 void NtoH() { ntoh(*this); }
705
706 void operator=(const std::vector<uint16_t> &vec) { ntohcpy(vec, *this); }
707
708 void clear() { reset(*this); }
709
710
711 } __attribute__((__packed__));
712 */
713
714 // --------------------------------------------------------------------
715
716 inline std::ostream &operator<<(std::ostream &out, const FtuResponse &h)
717 {
718 h.print(out);
719 return out;
720 }
721
722 inline std::ostream &operator<<(std::ostream &out, const Header &h)
723 {
724 h.print(out);
725 return out;
726 }
727
728
729 inline std::ostream &operator<<(std::ostream &out, const FtuList &h)
730 {
731 h.print(out);
732 return out;
733 }
734
735 inline std::ostream &operator<<(std::ostream &out, const DynamicDataBoard &h)
736 {
737 h.print(out);
738 return out;
739 }
740
741 inline std::ostream &operator<<(std::ostream &out, const DynamicData &h)
742 {
743 h.print(out);
744 return out;
745 }
746
747 inline std::ostream &operator<<(std::ostream &out, const StaticDataBoard &h)
748 {
749 h.print(out);
750 return out;
751 }
752
753 inline std::ostream &operator<<(std::ostream &out, const StaticData &h)
754 {
755 h.print(out);
756 return out;
757 }
758
759 inline std::ostream &operator<<(std::ostream &out, const Error &h)
760 {
761 h.print(out);
762 return out;
763 }
764};
765
766#endif
Note: See TracBrowser for help on using the repository browser.