1 | #ifndef FADBoard_H_SEEN
|
---|
2 | #define FADBoard_H_SEEN
|
---|
3 |
|
---|
4 | #include <ctype.h>
|
---|
5 | #include <time.h>
|
---|
6 | #include <math.h>
|
---|
7 | #include <errno.h>
|
---|
8 | #include <unistd.h>
|
---|
9 | #include <dirent.h>
|
---|
10 | #include <sys/time.h>
|
---|
11 |
|
---|
12 | #include <stdlib.h>
|
---|
13 | #include <string.h>
|
---|
14 | #include <iostream>
|
---|
15 | #include <algorithm>
|
---|
16 | #include <sys/socket.h>
|
---|
17 | #include <netdb.h>
|
---|
18 |
|
---|
19 | #include "FAD.h"
|
---|
20 | #include "FADFormat.h"
|
---|
21 |
|
---|
22 | const unsigned int READ_BUFFER_SIZE = 1000000;
|
---|
23 | const unsigned int STATUS_SIZE = 200;
|
---|
24 | const int MAX_WAIT_FOR_CONDITION = 10;
|
---|
25 |
|
---|
26 | class FADBoard: public DimThread {
|
---|
27 |
|
---|
28 | class FAD *m;
|
---|
29 | int Socket;
|
---|
30 | pthread_mutex_t Mutex;
|
---|
31 | DimService *DIM_Name, *DIM_Status, *DIM_ID, *DIM_Frequency, *DIM_Lock, *DIM_TriggerNum;
|
---|
32 | DimService *DIM_Rate, *DIM_Temp, *DIM_ROI, *DIM_DAC, *DIM_ACalData, *DIM_BoardTime;
|
---|
33 |
|
---|
34 | void ReadLoop();
|
---|
35 | static void LaunchThread(class FADBoard *);
|
---|
36 | static void ThreadCleanup(class FADBoard *);
|
---|
37 | void threadHandler();
|
---|
38 | void SetStatus(const char *, ...);
|
---|
39 |
|
---|
40 | public:
|
---|
41 | FADBoard(std::string, unsigned short, class FAD *, unsigned int);
|
---|
42 | ~FADBoard();
|
---|
43 |
|
---|
44 | struct BoardStatus {
|
---|
45 | uint16_t BoardID;
|
---|
46 | uint64_t DNA;
|
---|
47 | uint16_t FirmwareRevision;
|
---|
48 | uint32_t BoardTime;
|
---|
49 | uint32_t EventCounter;
|
---|
50 |
|
---|
51 | char Message[STATUS_SIZE];
|
---|
52 | struct timeval Update;
|
---|
53 | float Rate;
|
---|
54 |
|
---|
55 | uint32_t TriggerNum;
|
---|
56 | uint32_t Runnumber;
|
---|
57 | uint16_t TriggerType;
|
---|
58 | uint16_t TriggerCRC;
|
---|
59 | uint16_t TriggerCell[NChips];
|
---|
60 |
|
---|
61 | float Frequency;
|
---|
62 | short Lock[NChips];
|
---|
63 | int8_t PhaseShift;
|
---|
64 |
|
---|
65 | bool denable;
|
---|
66 | bool dwrite;
|
---|
67 | bool DCM_lock;
|
---|
68 | bool DCM_ready;
|
---|
69 | bool spi_clk;
|
---|
70 | bool RefClk_low;
|
---|
71 |
|
---|
72 | uint16_t ROI[NChips][NChannels];
|
---|
73 | uint16_t DAC[NDAC];
|
---|
74 | float Temp[NTemp];
|
---|
75 | } Status;
|
---|
76 |
|
---|
77 | short Data[NChips][NChannels][NBins];
|
---|
78 | long int Sum[NChips][NChannels][NBins];
|
---|
79 |
|
---|
80 | struct CalibData {
|
---|
81 | uint64_t DNA;
|
---|
82 | short Baseline[NChips][NChannels][NBins];
|
---|
83 | double Gain[NChips][NChannels][NBins];
|
---|
84 | double Secondary[NChips][NChannels][NBins];
|
---|
85 | float Temp;
|
---|
86 | float Frequency;
|
---|
87 | time_t Time;
|
---|
88 | } ACalib;
|
---|
89 |
|
---|
90 | float ACalData[3][NChips][NChannels][NBins]; // for DIM service
|
---|
91 |
|
---|
92 | void Send(const void *, size_t);
|
---|
93 | void Send(unsigned short);
|
---|
94 | struct BoardStatus GetStatus();
|
---|
95 | void AmplitudeCalibration();
|
---|
96 | void Lock();
|
---|
97 | void Unlock();
|
---|
98 |
|
---|
99 | unsigned short Port;
|
---|
100 | char *Name;
|
---|
101 | bool CommOK;
|
---|
102 | bool Active;
|
---|
103 | bool Continue;
|
---|
104 | pthread_t Thread;
|
---|
105 | pthread_cond_t CondVar;
|
---|
106 |
|
---|
107 | // Amplitude calibration
|
---|
108 | int Count;
|
---|
109 |
|
---|
110 | private:
|
---|
111 | enum StateType {standbye, baseline, gain, secondary, cleanup, wait, setdac, measure};
|
---|
112 | StateType State;
|
---|
113 |
|
---|
114 | struct BoardStatus InitialStatus;
|
---|
115 | uint16_t DAC_DR, DAC_low;
|
---|
116 | int16_t Delta_DAC;
|
---|
117 | unsigned int Count_DR;
|
---|
118 | static const short CLIP_LEVEL = 2000;
|
---|
119 | double Mean[NChips][NChannels], Mean_low[NChips][NChannels];
|
---|
120 | int DR_low[NChips][NChannels], DR_high[NChips][NChannels];
|
---|
121 |
|
---|
122 | unsigned int ModifiedCalibCount;
|
---|
123 | };
|
---|
124 |
|
---|
125 | #endif
|
---|