source: fact/FADctrl/FADBoard.h@ 12970

Last change on this file since 12970 was 12891, checked in by ogrimm, 13 years ago
Added code for automized measurement of dynamic range, not yet tested
File size: 2.4 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;
24const int MAX_WAIT_FOR_CONDITION = 10;
25
26class 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 void DynamicRange();
99
100 unsigned short Port;
101 char *Name;
102 bool CommOK;
103 bool Active;
104 bool Continue;
105 pthread_t Thread;
106 pthread_cond_t CondVar;
107
108 // Amplitude calibration
109 int Count;
110
111 private:
112 enum StateType {standbye, baseline, gain, secondary, cleanup, wait};
113 struct BoardStatus InitialStatus;
114 StateType State;
115};
116
117#endif
Note: See TracBrowser for help on using the repository browser.