#ifndef FADBoard_H_SEEN #define FADBoard_H_SEEN #include #include #include #include #include #include #include #include #include #include #include #include #include #include "FAD.h" #include "FADFormat.h" const unsigned int READ_BUFFER_SIZE = 1000000; const unsigned int STATUS_SIZE = 200; const int MAX_WAIT_FOR_CONDITION = 10; class FADBoard: public DimThread { class FAD *m; int Socket; pthread_mutex_t Mutex; DimService *DIM_Name, *DIM_Status, *DIM_ID, *DIM_Frequency, *DIM_Lock, *DIM_TriggerNum; DimService *DIM_Rate, *DIM_Temp, *DIM_ROI, *DIM_DAC, *DIM_ACalData, *DIM_BoardTime; void ReadLoop(); static void LaunchThread(class FADBoard *); static void ThreadCleanup(class FADBoard *); void threadHandler(); void SetStatus(const char *, ...); public: FADBoard(std::string, unsigned short, class FAD *, unsigned int); ~FADBoard(); struct BoardStatus { uint16_t BoardID; uint64_t DNA; uint16_t FirmwareRevision; uint32_t BoardTime; uint32_t EventCounter; char Message[STATUS_SIZE]; struct timeval Update; float Rate; uint32_t TriggerNum; uint32_t Runnumber; uint16_t TriggerType; uint16_t TriggerCRC; uint16_t TriggerCell[NChips]; float Frequency; short Lock[NChips]; int8_t PhaseShift; bool denable; bool dwrite; bool DCM_lock; bool DCM_ready; bool spi_clk; bool RefClk_low; uint16_t ROI[NChips][NChannels]; uint16_t DAC[NDAC]; float Temp[NTemp]; } Status; short Data[NChips][NChannels][NBins]; long int Sum[NChips][NChannels][NBins]; struct CalibData { uint64_t DNA; short Baseline[NChips][NChannels][NBins]; double Gain[NChips][NChannels][NBins]; double Secondary[NChips][NChannels][NBins]; float Temp; float Frequency; time_t Time; } ACalib; float ACalData[3][NChips][NChannels][NBins]; // for DIM service void Send(const void *, size_t); void Send(unsigned short); struct BoardStatus GetStatus(); void AmplitudeCalibration(); void Lock(); void Unlock(); void DynamicRange(); unsigned short Port; char *Name; bool CommOK; bool Active; bool Continue; pthread_t Thread; pthread_cond_t CondVar; // Amplitude calibration int Count; private: enum StateType {standbye, baseline, gain, secondary, cleanup, wait}; struct BoardStatus InitialStatus; StateType State; }; #endif