source: fact/FADctrl/FADBoard.h@ 10782

Last change on this file since 10782 was 10757, checked in by ogrimm, 14 years ago
Added thread cancellation handler to ensure mutex gets unlocked
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 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
70 uint16_t ROI[NChips][NChannels];
71 uint16_t DAC[NDAC];
72 float Temp[NTemp];
73 } Status;
74
75 short Data[NChips][NChannels][NBins];
76 long int Sum[NChips][NChannels][NBins];
77
78 struct CalibData {
79 uint64_t DNA;
80 short Baseline[NChips][NChannels][NBins];
81 double Gain[NChips][NChannels][NBins];
82 double Secondary[NChips][NChannels][NBins];
83 float Temp;
84 float Frequency;
85 time_t Time;
86 } ACalib;
87
88 float ACalData[3][NChips][NChannels][NBins]; // for DIM service
89
90 void Send(const void *, size_t);
91 void Send(unsigned short);
92 struct BoardStatus GetStatus();
93 void AmplitudeCalibration();
94 void Lock();
95 void Unlock();
96
97 unsigned short Port;
98 char *Name;
99 bool CommOK;
100 bool Active;
101 bool Continue;
102 pthread_t Thread;
103 pthread_cond_t CondVar;
104
105 // Amplitude calibration
106 int Count;
107
108 private:
109 enum StateType {standbye, baseline, gain, secondary, cleanup, wait};
110 struct BoardStatus InitialStatus;
111 StateType State;
112};
113
114#endif
Note: See TracBrowser for help on using the repository browser.