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