source: fact/FADctrl/FADBoard.h@ 10719

Last change on this file since 10719 was 10642, checked in by ogrimm, 13 years ago
FADctrl publishes amplitude calibration information as DIM service
File size: 2.3 KB
Line 
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
22const unsigned int READ_BUFFER_SIZE = 1000000;
23const unsigned int STATUS_SIZE = 200;
24
25class FADBoard: public DimThread {
26
27 class FAD *m;
28 int Socket;
29 pthread_mutex_t Mutex;
30 DimService *DIM_Name, *DIM_Status, *DIM_ID, *DIM_Frequency, *DIM_TriggerNum;
31 DimService *DIM_Rate, *DIM_Temp, *DIM_ROI, *DIM_DAC, *DIM_ACalData;
32
33 void ReadLoop();
34 static void LaunchThread(class FADBoard *);
35 void threadHandler();
36 void SetStatus(const char *, ...);
37
38 public:
39 FADBoard(std::string, unsigned short, class FAD *, unsigned int);
40 ~FADBoard();
41
42 struct BoardStatus {
43 uint16_t BoardID;
44 uint64_t DNA;
45 uint16_t FirmwareRevision;
46 uint32_t BoardTime;
47 uint32_t EventCounter;
48
49 char Message[STATUS_SIZE];
50 struct timeval Update;
51 float Rate;
52
53 uint32_t TriggerNum;
54 uint32_t Runnumber;
55 uint16_t TriggerType;
56 uint16_t TriggerCRC;
57 uint16_t TriggerCell[NChips];
58
59 float Frequency;
60 bool Lock[NChips];
61 int8_t PhaseShift;
62
63 bool denable;
64 bool dwrite;
65 bool DCM_lock;
66 bool DCM_ready;
67 bool spi_clk;
68
69 uint16_t ROI[NChips][NChannels];
70 uint16_t DAC[NDAC];
71 float Temp[NTemp];
72 } Status;
73
74 short Data[NChips][NChannels][NBins];
75 long int Sum[NChips][NChannels][NBins];
76
77 struct CalibData {
78 uint64_t DNA;
79 short Baseline[NChips][NChannels][NBins];
80 double Gain[NChips][NChannels][NBins];
81 double Secondary[NChips][NChannels][NBins];
82 float Temp;
83 float Frequency;
84 time_t Time;
85 } ACalib;
86
87 float ACalData[3][NChips][NChannels][NBins]; // for DIM service
88
89 void Send(const void *, size_t);
90 void Send(unsigned short);
91 struct BoardStatus GetStatus();
92 void AmplitudeCalibration();
93 void Lock();
94 void Unlock();
95
96 unsigned short Port;
97 char *Name;
98 bool CommOK;
99 bool Active;
100 bool Continue;
101 pthread_t Thread;
102 pthread_cond_t CondVar;
103
104 // Amplitude calibration
105 int Count;
106
107 private:
108 enum StateType {standbye, baseline, gain, secondary, cleanup, wait};
109 struct BoardStatus InitialStatus;
110 StateType State;
111};
112
113#endif
Note: See TracBrowser for help on using the repository browser.