got rid of extra servers for eiger, converted to c and it works

This commit is contained in:
Maliakal Dhanya
2014-08-29 16:41:19 +02:00
parent 10ca7c10e8
commit c5a4f357bf
31 changed files with 662 additions and 720 deletions

View File

@@ -9,186 +9,176 @@
#define FEBCONTROL_H
#include <netinet/in.h>
#include <string>
#include <vector>
#include <stdlib.h>
//#include <string>
//#include <vector>
#include "FebInterface.h"
class Module{
private:
unsigned int module_number;
bool top_address_valid;
unsigned int top_left_address;
unsigned int top_right_address;
bool bottom_address_valid;
unsigned int bottom_left_address;
unsigned int bottom_right_address;
unsigned int idelay_top[4]; //ll,lr,rl,ll
unsigned int idelay_bottom[4]; //ll,lr,rl,ll
float high_voltage;
int* top_dac;
int* bottom_dac;
public:
Module(unsigned int number, unsigned int address_top); //for half module()
Module(unsigned int number, unsigned int address_top, unsigned int address_bottom);
~Module();
static const unsigned int ndacs;
static const std::string dac_names[16];
unsigned int GetModuleNumber() {return module_number;}
bool TopAddressIsValid() {return top_address_valid;}
unsigned int GetTopBaseAddress() {return (top_left_address&0xff);}
unsigned int GetTopLeftAddress() {return top_left_address;}
unsigned int GetTopRightAddress() {return top_right_address;}
unsigned int GetBottomBaseAddress() {return (bottom_left_address&0xff);}
bool BottomAddressIsValid() {return bottom_address_valid;}
unsigned int GetBottomLeftAddress() {return bottom_left_address;}
unsigned int GetBottomRightAddress() {return bottom_right_address;}
unsigned int SetTopIDelay(unsigned int chip,unsigned int value) { return TopAddressIsValid() &&chip<4 ? (idelay_top[chip]=value) : 0;} //chip 0=ll,1=lr,0=rl,1=rr
unsigned int GetTopIDelay(unsigned int chip) { return chip<4 ? idelay_top[chip] : 0;} //chip 0=ll,1=lr,0=rl,1=rr
unsigned int SetBottomIDelay(unsigned int chip,unsigned int value) { return BottomAddressIsValid() &&chip<4 ? (idelay_bottom[chip]=value) : 0;} //chip 0=ll,1=lr,0=rl,1=rr
unsigned int GetBottomIDelay(unsigned int chip) { return chip<4 ? idelay_bottom[chip] : 0;} //chip 0=ll,1=lr,0=rl,1=rr
float SetHighVoltage(float value) { return TopAddressIsValid() ? (high_voltage=value) : -1;}
float GetHighVoltage() { return high_voltage;}
int SetTopDACValue(unsigned int i, int value) { return (i<ndacs && TopAddressIsValid()) ? (top_dac[i]=value) : -1;}
int GetTopDACValue(unsigned int i) { return (i<ndacs) ? top_dac[i]:-1;}
int SetBottomDACValue(unsigned int i, int value) { return (i<ndacs && BottomAddressIsValid()) ? (bottom_dac[i]=value) : -1;}
int GetBottomDACValue(unsigned int i) { return (i<ndacs) ? bottom_dac[i]:-1;}
struct Module{
unsigned int module_number;
int top_address_valid;
unsigned int top_left_address;
unsigned int top_right_address;
int bottom_address_valid;
unsigned int bottom_left_address;
unsigned int bottom_right_address;
unsigned int idelay_top[4]; //ll,lr,rl,ll
unsigned int idelay_bottom[4]; //ll,lr,rl,ll
float high_voltage;
int* top_dac;
int* bottom_dac;
};
void Module_Module(struct Module* mod,unsigned int number, unsigned int address_top);
void Module_Module1(struct Module* mod,unsigned int number, unsigned int address_top, unsigned int address_bottom);
unsigned int Module_GetModuleNumber(struct Module* mod);
int Module_TopAddressIsValid(struct Module* mod);
unsigned int Module_GetTopBaseAddress(struct Module* mod);
unsigned int Module_GetTopLeftAddress(struct Module* mod) ;
unsigned int Module_GetTopRightAddress(struct Module* mod);
unsigned int Module_GetBottomBaseAddress(struct Module* mod);
int Module_BottomAddressIsValid(struct Module* mod);
unsigned int Module_GetBottomLeftAddress(struct Module* mod);
unsigned int Module_GetBottomRightAddress(struct Module* mod);
unsigned int Module_SetTopIDelay(struct Module* mod,unsigned int chip,unsigned int value);
unsigned int Module_GetTopIDelay(struct Module* mod,unsigned int chip) ;
unsigned int Module_SetBottomIDelay(struct Module* mod,unsigned int chip,unsigned int value);
unsigned int Module_GetBottomIDelay(struct Module* mod,unsigned int chip);
float Module_SetHighVoltage(struct Module* mod,float value);
float Module_GetHighVoltage(struct Module* mod);
int Module_SetTopDACValue(struct Module* mod,unsigned int i, int value);
int Module_GetTopDACValue(struct Module* mod,unsigned int i);
int Module_SetBottomDACValue(struct Module* mod,unsigned int i, int value);
int Module_GetBottomDACValue(struct Module* mod,unsigned int i);
class FebControl:private FebInterface{
private:
std::vector<Module*> modules;
void ClearModules();
unsigned int staticBits; //program=1,m4=2,m8=4,test=8,rotest=16,cs_bar_left=32,cs_bar_right=64
unsigned int acquireNReadoutMode; //safe or parallel, half or full speed
unsigned int triggerMode; //internal timer, external start, external window, signal polarity (external trigger and enable)
unsigned int externalEnableMode; //external enabling engaged and it's polarity
unsigned int subFrameMode;
unsigned int photon_energy_eV;
unsigned int nimages;
float exposure_time_in_sec;
float exposure_period_in_sec;
unsigned int trimbit_size;
unsigned int* last_downloaded_trimbits;
void PrintModuleList();
bool GetModuleIndex(unsigned int module_number, unsigned int& module_index);
bool CheckModuleAddresses(Module* m);
bool AddModule(unsigned int module_number, unsigned int top_address);
bool AddModule(unsigned int module_number, unsigned int top_address, unsigned int bottom_address, bool half_module=0);
bool GetDACNumber(std::string s, unsigned int& n);
bool SendDACValue(unsigned int dst_num, unsigned int ch, unsigned int& value);
bool VoltageToDAC(float value, unsigned int& digital, unsigned int nsteps, float vmin, float vmax);
float DACToVoltage(unsigned int digital,unsigned int nsteps,float vmin,float vmax);
bool SendHighVoltage(unsigned int module_index, float& value);
bool SendIDelays(unsigned int dst_num, bool chip_lr, unsigned int channels, unsigned int ndelay_units);
bool SetStaticBits();
bool SetStaticBits(unsigned int the_static_bits);
bool SendBitModeToBebServer();
unsigned int ConvertTimeToRegister(float time_in_sec);
unsigned int AddressToAll();
bool SetCommandRegister(unsigned int cmd);
bool GetDAQStatusRegister(unsigned int dst_address, unsigned int &ret_status);
bool StartDAQOnlyNWaitForFinish(int sleep_time_us=5000);
bool ResetChipCompletely();
struct sockaddr_in serv_addr;
bool SetupSendToSocket(const char* ip_address_hostname, unsigned short int port);
int WriteNRead(char* message, int length, int max_length);
void Feb_Control_ClearModules();
public:
FebControl();
virtual ~FebControl();
void Feb_Control_PrintModuleList();
int Feb_Control_GetModuleIndex(unsigned int module_number, unsigned int* module_index);
int Feb_Control_CheckModuleAddresses(struct Module* m);
int Feb_Control_AddModule(unsigned int module_number, unsigned int top_address);
/*int Feb_Control_AddModule(unsigned int module_number, unsigned int top_address, unsigned int bottom_address, int half_module=0);*/
int Feb_Control_AddModule1(unsigned int module_number, unsigned int top_address, unsigned int bottom_address, int half_module);
bool Init();
bool ReadSetUpFileToAddModules(std::string file_name);
bool ReadSetUpFile(unsigned int module_num, std::string file_name);
bool CheckSetup();
int Feb_Control_GetDACNumber(char* s, unsigned int* n);
int Feb_Control_SendDACValue(unsigned int dst_num, unsigned int ch, unsigned int* value);
int Feb_Control_VoltageToDAC(float value, unsigned int* digital, unsigned int nsteps, float vmin, float vmax);
float Feb_Control_DACToVoltage(unsigned int digital,unsigned int nsteps,float vmin,float vmax);
unsigned int GetNModules();
unsigned int GetNHalfModules();
int Feb_Control_SendHighVoltage(unsigned int module_index, float* value);
bool SetHighVoltage(float value);
bool SetHighVoltage(unsigned int module_num,float value);
int Feb_Control_SendIDelays(unsigned int dst_num, int chip_lr, unsigned int channels, unsigned int ndelay_units);
bool SetPhotonEnergy(unsigned int full_energy_eV);
unsigned int GetPhotonEnergy(){return photon_energy_eV;}
int Feb_Control_SetStaticBits();
int Feb_Control_SetStaticBits1(unsigned int the_static_bits);
bool SetIDelays(unsigned int module_num, unsigned int ndelay_units);
bool SetIDelays(unsigned int module_num, unsigned int chip_pos, unsigned int ndelay_units);
int Feb_Control_SendBitModeToBebServer();
unsigned int Feb_Control_ConvertTimeToRegister(float time_in_sec);
unsigned int Feb_Control_AddressToAll();
int Feb_Control_SetCommandRegister(unsigned int cmd);
int Feb_Control_GetDAQStatusRegister(unsigned int dst_address, unsigned int* ret_status);
/*int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us=5000);*/
int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us);
int Feb_Control_ResetChipCompletely();
struct sockaddr_in Feb_Control_serv_addr;
/*
int Feb_Control_SetupSendToSocket(const char* ip_address_hostname, unsigned short int port);
int Feb_Control_WriteNRead(char* message, int length, int max_length);
*/
void Feb_Control_FebControl();
int Feb_Control_Init();
int Feb_Control_ReadSetUpFileToAddModules(char* file_name);
int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name);
int Feb_Control_CheckSetup();
unsigned int Feb_Control_GetNModules();
unsigned int Feb_Control_GetNHalfModules();
int Feb_Control_SetHighVoltage(float value);
int Feb_Control_SetHighVoltage1(unsigned int module_num,float value);
int Feb_Control_SetPhotonEnergy(unsigned int full_energy_eV);
unsigned int Feb_Control_GetPhotonEnergy();
int Feb_Control_SetIDelays(unsigned int module_num, unsigned int ndelay_units);
int Feb_Control_SetIDelays1(unsigned int module_num, unsigned int chip_pos, unsigned int ndelay_units);
bool DecodeDACString(std::string dac_str, unsigned int& module_index, bool& top, bool& bottom, unsigned int& dac_ch);
bool SetDAC(std::string s, int value, bool is_a_voltage_mv=0);
bool GetDAC(std::string s, int& ret_value, bool voltage_mv=0);
bool GetDACName(unsigned int dac_num, std::string &s);
int Feb_Control_DecodeDACString(char* dac_str, unsigned int* module_index, int* top, int* bottom, unsigned int* dac_ch);
/*int Feb_Control_SetDAC(string s, int value, int is_a_voltage_mv=0);*/
int Feb_Control_SetDAC(char* s, int value, int is_a_voltage_mv);
/* int Feb_Control_GetDAC(string s, int* ret_value, int voltage_mv=0);*/
int Feb_Control_GetDAC(char* s, int* ret_value, int voltage_mv);
int Feb_Control_GetDACName(unsigned int dac_num,char* s);
bool SetTrimbits(unsigned int module_num, unsigned int* trimbits);
unsigned int* GetTrimbits();
int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int* trimbits);
unsigned int* Feb_Control_GetTrimbits();
/**Added by Dhanya */
bool LoadTrimbitFile();
bool SaveTrimbitFile();
bool SaveAllTrimbitsTo(int value);
int Feb_Control_LoadTrimbitFile();
int Feb_Control_SaveTrimbitFile();
int Feb_Control_SaveAllTrimbitsTo(int value);
bool Reset();
bool StartAcquisition();
bool StopAcquisition();
bool AcquisitionInProgress();
bool WaitForFinishedFlag(int sleep_time_us=5000);
int Feb_Control_Reset();
int Feb_Control_StartAcquisition();
int Feb_Control_StopAcquisition();
int Feb_Control_AcquisitionInProgress();
/*int Feb_Control_WaitForFinishedFlag(int sleep_time_us=5000);*/
int Feb_Control_WaitForFinishedFlag(int sleep_time_us);
//functions for setting up exposure
void PrintAcquisitionSetup();
bool SetNExposures(unsigned int n_images);
unsigned int GetNExposures();
bool SetExposureTime(float the_exposure_time_in_sec);
float GetExposureTime();
bool SetExposurePeriod(float the_exposure_period_in_sec);
float GetExposurePeriod();
bool SetDynamicRange(unsigned int four_eight_sixteen_or_thirtytwo);
unsigned int GetDynamicRange();
bool SetReadoutSpeed(unsigned int readout_speed=0); //0->full,1->half,2->quarter or 3->super_slow
bool SetReadoutMode(unsigned int readout_mode=0); //0->parallel,1->non-parallel,2-> safe_mode
bool SetTriggerMode(unsigned int trigger_mode=0, bool polarity=1);
bool SetExternalEnableMode(bool use_external_enable=0, bool polarity=1);
void Feb_Control_PrintAcquisitionSetup();
int Feb_Control_SetNExposures(unsigned int n_images);
unsigned int Feb_Control_GetNExposures();
int Feb_Control_SetExposureTime(double the_exposure_time_in_sec);
double Feb_Control_GetExposureTime();
int Feb_Control_SetExposurePeriod(double the_exposure_period_in_sec);
double Feb_Control_GetExposurePeriod();
int Feb_Control_SetDynamicRange(unsigned int four_eight_sixteen_or_thirtytwo);
unsigned int Feb_Control_GetDynamicRange();
/*int Feb_Control_SetReadoutSpeed(unsigned int readout_speed=0); //0->full,1->half,2->quarter or 3->super_slow*/
int Feb_Control_SetReadoutSpeed(unsigned int readout_speed); //0->full,1->half,2->quarter or 3->super_slow
/* int Feb_Control_SetReadoutMode(unsigned int readout_mode=0); //0->parallel,1->non-parallel,2-> safe_mode*/
int Feb_Control_SetReadoutMode(unsigned int readout_mode); //0->parallel,1->non-parallel,2-> safe_mode
/* int Feb_Control_SetTriggerMode(unsigned int trigger_mode=0, int polarity=1);*/
int Feb_Control_SetTriggerMode(unsigned int trigger_mode, int polarity);
/*int Feb_Control_SetExternalEnableMode(int use_external_enable=0, int polarity=1);*/
int Feb_Control_SetExternalEnableMode(int use_external_enable, int polarity);
//functions for testing
bool SetTestModeVariable(bool on=1);
bool GetTestModeVariable();
/*int Feb_Control_SetTestModeVariable(int on=1);*/
int Feb_Control_SetTestModeVariable(int on);
int Feb_Control_GetTestModeVariable();
};
#endif