source: fact/FADctrl/FADBoard.h@ 10927

Last change on this file since 10927 was 10813, checked in by ogrimm, 14 years ago
Corrected dcm_ready and dcm_lock bit evaluation
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;
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 static void ThreadCleanup(class FADBoard *);
36 void threadHandler();
37 void SetStatus(const char *, ...);
38
39 public:
40 FADBoard(std::string, unsigned short, class FAD *, unsigned int);
41 ~FADBoard();
42
43 struct BoardStatus {
44 uint16_t BoardID;
45 uint64_t DNA;
46 uint16_t FirmwareRevision;
47 uint32_t BoardTime;
48 uint32_t EventCounter;
49
50 char Message[STATUS_SIZE];
51 struct timeval Update;
52 float Rate;
53
54 uint32_t TriggerNum;
55 uint32_t Runnumber;
56 uint16_t TriggerType;
57 uint16_t TriggerCRC;
58 uint16_t TriggerCell[NChips];
59
60 float Frequency;
61 bool Lock[NChips];
62 int8_t PhaseShift;
63
64 bool denable;
65 bool dwrite;
66 bool DCM_lock;
67 bool DCM_ready;
68 bool spi_clk;
69 bool RefClk_low;
70
71 uint16_t ROI[NChips][NChannels];
72 uint16_t DAC[NDAC];
73 float Temp[NTemp];
74 } Status;
75
76 short Data[NChips][NChannels][NBins];
77 long int Sum[NChips][NChannels][NBins];
78
79 struct CalibData {
80 uint64_t DNA;
81 short Baseline[NChips][NChannels][NBins];
82 double Gain[NChips][NChannels][NBins];
83 double Secondary[NChips][NChannels][NBins];
84 float Temp;
85 float Frequency;
86 time_t Time;
87 } ACalib;
88
89 float ACalData[3][NChips][NChannels][NBins]; // for DIM service
90
91 void Send(const void *, size_t);
92 void Send(unsigned short);
93 struct BoardStatus GetStatus();
94 void AmplitudeCalibration();
95 void Lock();
96 void Unlock();
97
98 unsigned short Port;
99 char *Name;
100 bool CommOK;
101 bool Active;
102 bool Continue;
103 pthread_t Thread;
104 pthread_cond_t CondVar;
105
106 // Amplitude calibration
107 int Count;
108
109 private:
110 enum StateType {standbye, baseline, gain, secondary, cleanup, wait};
111 struct BoardStatus InitialStatus;
112 StateType State;
113};
114
115#endif
Note: See TracBrowser for help on using the repository browser.