diff --git a/slsDetectorSoftware/Makefile b/slsDetectorSoftware/Makefile index eb3708d50..36eda6c4c 100644 --- a/slsDetectorSoftware/Makefile +++ b/slsDetectorSoftware/Makefile @@ -69,14 +69,14 @@ gotthardVirtualServer: $(SRC_MYTHEN_SVC) %.o : %.cpp %.h Makefile - $(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -lpthread -lrt $(LIBZMQ) #$(FLAGS) + $(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -lpthread -lrt $(LIBZMQ) #$(FLAGS) package: $(OBJS) $(DESTDIR)/libSlsDetector.so $(DESTDIR)/libSlsDetector.a $(DESTDIR)/libSlsDetector.so: $(OBJS) - $(CXX) -shared -Wl,-soname,libSlsDetector.so -o libSlsDetector.so $(OBJS) -lc $(INCLUDES) $(DFLAGS) $(FLAGS) $(EPICSFLAGS) -L/usr/lib64 -lpthread -lrt $(LIBZMQ) + $(CXX) -shared -Wl,-soname,libSlsDetector.so -o libSlsDetector.so $(OBJS) -lc $(INCLUDES) $(DFLAGS) $(FLAGS) $(EPICSFLAGS) -L/usr/lib64 -lpthread -lrt $(LIBZMQ) $(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR)) mv libSlsDetector.so $(DESTDIR) diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h index 05e2656b5..ac4f5b930 100644 --- a/slsDetectorSoftware/commonFiles/error_defs.h +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -19,11 +19,12 @@ using namespace std; /** Error flags */ /*Assumption: Only upto 63 detectors */ -#define CRITICAL_ERROR_MASK 0xFFFFFFFF #define MULTI_DETECTORS_NOT_ADDED 0x8000000000000000ULL +#define CRITICAL_ERROR_MASK 0xFFFFFFF +// 0xFFFFFFF000000000ULL #define CANNOT_CONNECT_TO_DETECTOR 0x4000000000000000ULL #define CANNOT_CONNECT_TO_RECEIVER 0x2000000000000000ULL #define COULDNOT_SET_CONTROL_PORT 0x1000000000000000ULL @@ -40,10 +41,9 @@ using namespace std; #define COULD_NOT_CONFIGURE_MAC 0x0002000000000000ULL #define COULDNOT_START_RECEIVER 0x0001000000000000ULL // default error like starting threads #define COULDNOT_STOP_RECEIVER 0x0000800000000000ULL +// 0xFFFFFFF000000000ULL -// 0xFFFFFFFF00000000ULL - - +// 0x0000000FFFFFFFFFULL #define COULDNOT_SET_NETWORK_PARAMETER 0x0000000000000001ULL #define COULDNOT_SET_ROI 0x0000000000000002ULL #define RECEIVER_READ_FREQUENCY 0x0000000000000004ULL @@ -74,9 +74,10 @@ using namespace std; #define RECEIVER_READ_TIMER 0x0000000008000000ULL #define RECEIVER_ACQ_TIME_NOT_SET 0x0000000010000000ULL #define RECEIVER_FLIPPED_DATA_NOT_SET 0x0000000020000000ULL -#define RECEIVER_FILE_FORMAT 0x0000000040000000ULL +#define THRESHOLD_NOT_SET 0x0000000040000000ULL +#define RECEIVER_FILE_FORMAT 0x0000000080000000ULL +// 0x0000000FFFFFFFFFULL -// 0x00000000FFFFFFFFULL /** @short class returning all error messages for error mask */ class errorDefs { @@ -235,10 +236,13 @@ public: if(slsErrorMask&RECEIVER_FLIPPED_DATA_NOT_SET) retval.append("Could not set receiver flipped data/bottom\n"); + if(slsErrorMask&THRESHOLD_NOT_SET) + retval.append("Could not set threshold\n"); if(slsErrorMask&RECEIVER_FILE_FORMAT) retval.append("Could not set receiver file format\n"); + //------------------------------------------------------ length of message diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h index 8e3a82689..df7e34c53 100755 --- a/slsDetectorSoftware/commonFiles/sls_detector_defs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_defs.h @@ -126,7 +126,7 @@ class slsDetectorDefs: public virtual slsReceiverDefs{ typedef struct { int module; /**< is the module number */ int serialnumber; /**< is the module serial number */ - int nchan; /**< is the number of channels per chip */ + int nchan; /**< is the number of channels on the module*/ int nchip; /**< is the number of chips on the module */ int ndac; /**< is the number of dacs on the module */ int nadc; /**< is the number of adcs on the module */ diff --git a/slsDetectorSoftware/eigerDetectorServer/Beb.cxx b/slsDetectorSoftware/eigerDetectorServer/Beb.cxx deleted file mode 100644 index 80746bbe6..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/Beb.cxx +++ /dev/null @@ -1,470 +0,0 @@ - -/** - * @author Ian Johnson - * @version 1.0 - */ - - -//return reversed 1 means good, 0 means failed - - - -#include -#include -#include -#include -#include -#include -#include - - -#include "xfs_types.h" -#include "xparameters.h" - -#include "Beb.h" - -using namespace std; - -BebInfo::BebInfo(unsigned int beb_num){beb_number=beb_num;serial_address=0;src_mac_1GbE="";src_mac_10GbE="";src_ip_1GbE="";src_ip_10GbE=""; src_port_1GbE=src_port_10GbE=0;} -bool BebInfo::SetHeaderInfo(bool ten_gig, string src_mac, string src_ip, unsigned int src_port){ - if(ten_gig){ src_mac_10GbE = src_mac; src_ip_10GbE = src_ip; src_port_10GbE = src_port;} - else { src_mac_1GbE = src_mac; src_ip_1GbE = src_ip; src_port_1GbE = src_port;} - return 1; -} - -bool BebInfo::SetSerialAddress(unsigned int a){ - //address pre shifted - if(a>0xff) return 0; - serial_address = 0x04000000 | ((a&0xff)<<16); - return 1; -} - -void BebInfo::Print(){ - cout<<"\t"<Print(); - cout<InitNewMemory(XPAR_PLB_LL_NEW_MEMORY, arg1)) - printf("New Memory FAIL\n"); - else - printf("New Memory OK\n"); - -} - -Beb::~Beb(){ - delete ll; - delete [] send_data_raw; - delete [] recv_data_raw; -} - -void Beb::ClearBebInfos(){ - for(unsigned int i=0;iSetSerialAddress(0xff)) beb_infos.push_back(b0); //all bebs for reset and possibly get request data? - - if(!ReadSetUpFromFile("/home/root/executables/setup_beb.txt")) return 0; -/* - //loop through file to fill vector. - BebInfo* b = new BebInfo(26); - b->SetSerialAddress(0); //0xc4000000 - b->SetHeaderInfo(0,"00:50:c2:46:d9:34","129.129.205.78",42000 + 26); // 1 GbE, ip address can be acquire from the network "arp" - b->SetHeaderInfo(1,"00:50:c2:46:d9:35","10.0.26.1",52000 + 26); //10 GbE, everything calculable/setable - beb_infos.push_back(b); -*/ - - return CheckSourceStuffBebInfo(); -} - - - -bool Beb::SetBebSrcHeaderInfos(unsigned int beb_number, bool ten_gig, string src_mac, string src_ip,unsigned int src_port){ - //so that the values can be reset externally for now.... - - unsigned int i = GetBebInfoIndex(beb_number); - if(!i) return 0; //i must be greater than 0, zero is the global send - beb_infos[i]->SetHeaderInfo(ten_gig,src_mac,src_ip,src_port); - - cout<<"Printing Beb info number ("<Print(); - cout<>cmd_st; - if(!strcmp("add_beb",cmd_st)){ - if(!(iss>>value_i[0]>>value_i[1]>>str_mac1>>str_ip1>>str_mac10>>str_ip10)){ - cout<<"Error adding beb from "<SetSerialAddress(value_i[1]); - b->SetHeaderInfo(0,str_mac1,str_ip1,42000+value_i[0]); - b->SetHeaderInfo(1,str_mac10,str_ip10,52000+value_i[0]); - beb_infos.push_back(b); - } - } - - infile.close(); - - return 1; -} - - - -bool Beb::CheckSourceStuffBebInfo(){ - for(unsigned int i=1;iGetBebNumber(),0,"00:00:00:00:00:00","10.0.0.1",20000)||!SetHeaderData(beb_infos[i]->GetBebNumber(),1,"00:00:00:00:00:00","10.0.0.1",20000)){ - cout<<"Error in BebInfo for module number "<GetBebNumber()<<"."<Print(); - return 0; - } - } - return 1; -} - -unsigned int Beb::GetBebInfoIndex(unsigned int beb_numb){ - if(!beb_numb) return 0; - - for(unsigned int i=1;iGetBebNumber()) return i; - return 0; -} - - - -bool Beb::WriteTo(unsigned int index){ - if(index>=beb_infos.size()){ - cout<<"WriteTo index error."<GetSerialAddress(); - if(ll->Write(4,send_data_raw)!=4) return 0; - - send_data_raw[0] = 0xc0000000; - if((send_ndata+1)*4!=ll->Write((send_ndata+1)*4,send_data_raw)) return 0; - - return 1; -} - - -void Beb::SwapDataFun(bool little_endian, unsigned int n, unsigned int *d){ - if(little_endian) for(unsigned int i=0;i>8) | ((d[i]&0xff000000)>>24)); //little_endian - else for(unsigned int i=0;i>16)); -} - - -bool Beb::SetByteOrder(){ - send_data_raw[0] = 0x8fff0000; - if(ll->Write(4,send_data_raw)!=4) return 0; - - while((ll->Read(recv_buffer_size*4,recv_data_raw)/4)>0) cout<<"\t) Cleanning buffer ..."<GetSrcMAC(ten_gig),beb_infos[i]->GetSrcIP(ten_gig),beb_infos[i]->GetSrcPort(ten_gig),dst_mac,dst_ip,dst_port); -} - -bool Beb::SetHeaderData(string src_mac, string src_ip, unsigned int src_port, string dst_mac, string dst_ip, unsigned int dst_port){ - /* example header*/ - //static unsigned int* word_ptr = new unsigned int [16]; - static udp_header_type udp_header = { - {0x00, 0x50, 0xc5, 0xb2, 0xcb, 0x46}, // DST MAC - {0x00, 0x50, 0xc2, 0x46, 0xd9, 0x02}, // SRC MAC - {0x08, 0x00}, - {0x45}, - {0x00}, - {0x00, 0x00}, - {0x00, 0x00}, - {0x40}, - {0x00}, - {0xff}, - {0x11}, - {0x00, 0x00}, - {129, 205, 205, 128}, // Src IP - {129, 205, 205, 122}, // Dst IP - {0x0f, 0xa1}, - {0x13, 0x89}, - {0x00, 0x00}, //{0x00, 0x11}, - {0x00, 0x00} - }; - - if(!SetMAC(src_mac,&(udp_header.src_mac[0]))) return 0; - if(!SetIP(src_ip,&(udp_header.src_ip[0]))) return 0; - if(!SetPortNumber(src_port,&(udp_header.src_port[0]))) return 0; - - if(!SetMAC(dst_mac,&(udp_header.dst_mac[0]))) return 0; - if(!SetIP(dst_ip,&(udp_header.dst_ip[0]))) return 0; - if(!SetPortNumber(dst_port,&(udp_header.dst_port[0]))) return 0; - - - AdjustIPChecksum(&udp_header); - - unsigned int* base_ptr = (unsigned int *) &udp_header; - unsigned int num_words = ( sizeof(udp_header_type) + 3 ) / 4; - // for(unsigned int i=0; i "<3))||(i==3&&(ip.length()<1||ip.length()>3))){ - cout<<"Error: in ip address -> "<> 8) & 0xff ; - dst_ptr[1] = port_number & 0xff; - return 1; -} - - -void Beb::AdjustIPChecksum(udp_header_type *ip){ - unsigned char *cptr = (unsigned char *) ip->ver_headerlen; - - ip->ip_header_checksum[0] = 0; - ip->ip_header_checksum[1] = 0; - ip->total_length[0] = 0; - ip->total_length[1] = 28; // IP + UDP Header Length - - // calc ip checksum - unsigned int ip_checksum = 0; - for(unsigned int i=0; i<10; i++){ - ip_checksum += ( (cptr[2*i] << 8) + (cptr[2*i + 1]) ); - if (ip_checksum & 0x00010000) ip_checksum = (ip_checksum + 1) & 0x0000ffff; - } - - ip->ip_header_checksum[0] = (ip_checksum >> 8) & 0xff ; - ip->ip_header_checksum[1] = ip_checksum & 0xff ; -} - - - -bool Beb::SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, bool ten_gig, unsigned int dst_number, unsigned int npackets, unsigned int packet_size, bool stop_read_when_fifo_empty){ - - unsigned int i = GetBebInfoIndex(beb_number); //zero is the global send - - send_ndata = 3; - if(left_right == 1) send_data[0] = 0x00040000; - else if(left_right == 2) send_data[0] = 0x00080000; - else if(left_right == 3) send_data[0] = 0x000c0000; - else return 0; - - //packet_size/=2; - if(dst_number>0x3f) return 0; - if(packet_size>0x3ff) return 0; - if(npackets==0||npackets>0x100) return 0; - npackets--; - - - send_data[1] = 0x62000000 | (!stop_read_when_fifo_empty) << 27 | (ten_gig==1) << 24 | packet_size << 14 | dst_number << 8 | npackets; - send_data[2] = 0; - - SwapDataFun(0,2,&(send_data[1])); - - if(!WriteTo(i)) return 0; - - return 1; -} - - -bool Beb::SetUpTransferParameters(short the_bit_mode){ - if(the_bit_mode!=4&&the_bit_mode!=8&&the_bit_mode!=16&&the_bit_mode!=32) return 0; - bit_mode = the_bit_mode; - - //nimages = the_number_of_images; - // on_dst = 0; - - return 1; -} - -bool Beb::RequestNImages(unsigned int beb_number, unsigned int left_right, bool ten_gig, unsigned int dst_number, unsigned int nimages, bool test_just_send_out_packets_no_wait){ - if(dst_number>64) return 0; - - unsigned int header_size = 4; //4*64 bits - unsigned int packet_size = ten_gig ? 0x200 : 0x80; // 4k or 1k packets - unsigned int npackets = ten_gig ? bit_mode*4 : bit_mode*16; - bool in_two_requests = (!ten_gig&&bit_mode==32); - if(in_two_requests) npackets/=2; - - //cout<<"here: "< -#include -#include -#include -#include // std::remove_if - -#include -#include -#include -#include -#include - -#include "Beb.h" -#include "slsDetectorServer_defs.h" //include port number - -using namespace std; - -enum cmd_string {evNotFound, - evRequestImages,evTestRequest, - evSetBitMode, - evSetupTableEntry,evSetDstParameters, - evTest,evTestSend, - evExitServer}; - -map enum_map; - -void init(){ - - enum_map["requestimages"] = evRequestImages; // - enum_map["testrequest"] = evTestRequest; // - - enum_map["setbitmode"] = evSetBitMode; // (resets on_dst and dst_requested) - - enum_map["setuptableentry"] = evSetupTableEntry; - enum_map["setdstparameters"] = evSetDstParameters; // (resets on_dst and dst_requested) - - enum_map["test"] = evTest; - enum_map["testsend"] = evTestSend; - enum_map["exitserver"] = evExitServer; - -} - -int server_list_s; -int server_conn_s; -int AccpetConnectionAndWaitForData(char* buffer, int maxlength); -bool WriteNClose(const char* buffer, int length); -bool SetupListenSocket(unsigned short int port); - - -string LowerCase(string str); -string GetNextString(string str,bool start_from_beginning=0); -void AddNumber(string& str, int n, int location=-1);//-1 means append - -int main(int argc, char* argv[]){ - cout<1) - bebs = new Beb(atoi(argv[1])); - else - bebs = new Beb(-1); - - // unsigned short int port_number = atoi(argv[1]); - - unsigned short int port_number = BEB_PORT; - if(!SetupListenSocket(port_number)) return 1; - - - int length=1000; - char data[1000]; - - int stop = 0; - time_t rawtime; - struct tm *timeinfo; - - bool send_to_ten_gig = 0; - int ndsts_in_use=32; - unsigned int nimages_per_request=1; - - int on_dst=0; - bool dst_requested[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - - while(!stop){ - - cout< "<0){ - return_start_pos = return_message.length(); - - switch(enum_map.find(LowerCase(cmd))->second){ - - case evRequestImages : - tmp_str[0] = GetNextString(data); - n[0] = atoi(tmp_str[0].data()); //dst number - if(tmp_str[0].length()<1||n[0]<0||n[0]>=ndsts_in_use){ - return_message.append("\tError executing: RequestImages (note dst_number must be less than ndsts_in_use that is set with SetDstParameters\n"); - ret_val = 1; - }else{ - dst_requested[n[0]] = 1; - ret_val=0; - tmp_str[1] = " ( "; - while(dst_requested[on_dst]){ - //waits on data - if((ret_val = (!bebs->RequestNImages(0,1,send_to_ten_gig,on_dst,nimages_per_request)||!bebs->RequestNImages(0,2,send_to_ten_gig,0x20|on_dst,nimages_per_request)))) break; - AddNumber(tmp_str[1],on_dst);tmp_str[1].append(" "); - dst_requested[on_dst++]=0; - on_dst%=ndsts_in_use; - } - if(ret_val) return_message.append("\tError executing: RequestImages "); - else{ return_message.append("\tExecuted: RequestImages "); AddNumber(return_message,n[0]);} - return_message.append(tmp_str[1]); - return_message.append(" )\n"); - } - break; - - case evTestRequest : - tmp_str[0] = GetNextString(data); - n[0] = atoi(tmp_str[0].data()); //dst number - if(tmp_str[0].length()<1||n[0]<0||n[0]>=ndsts_in_use){ - return_message.append("\tError executing: TestRequest (note dst_number must be less than 2xndsts_in_use that is set with SetDstParameters\n"); - ret_val = 1; - }else{ - ret_val = (!bebs->RequestNImages(0,1,send_to_ten_gig,n[0],nimages_per_request,1)||!bebs->RequestNImages(0,2,send_to_ten_gig,0x20|n[0],nimages_per_request,1)); - if(ret_val) return_message.append("\tError executing: TestRequest \n"); - else{ return_message.append("\tExecuted: TestRequest "); AddNumber(return_message,n[0]); return_message.append("\n");} - } - break; - - case evSetBitMode : - on_dst = 0; - for(n[0]=0;n[0]<32;n[0]++) dst_requested[n[0]] = 0; //clear dst requested - n[0] = atoi(GetNextString(data).data()); - if((ret_val = !bebs->SetUpTransferParameters(n[0]))) return_message.append("\tError executing: SetBitMode \n"); - else{ return_message.append("\tExecuted: SetBitMode ");AddNumber(return_message,n[0]);return_message.append("\n");} - break; - - case evSetDstParameters : //move below // - on_dst = 0; - for(n[0]=0;n[0]<32;n[0]++) dst_requested[n[0]] = 0; //clear dst requested - n[0] = atoi(GetNextString(data).data()); //<1GbE(0) or 10GbE(1)> - n[1] = atoi(GetNextString(data).data()); // - n[2] = atoi(GetNextString(data).data()); // 0)> - - if((n[0]!=0&&n[0]!=1)||(n[1]<1||n[1]>32)||n[2]<1){ - return_message.append("\tError executing: SetDstParameters <1GbE(0) or 10GbE(1)> \n"); - ret_val=1; - } - else{ - send_to_ten_gig = n[0]; - ndsts_in_use=n[1]; - nimages_per_request=n[2]; - return_message.append("\tExecuted: SetDstParameters "); - AddNumber(return_message,n[0]);return_message.append(" "); - AddNumber(return_message,n[1]);return_message.append(" "); - AddNumber(return_message,n[2]);return_message.append(" "); - ret_val=0; - } - break; - - case evSetupTableEntry : - n[0] = atoi(GetNextString(data).data()); //beb_number; - n[1] = atoi(GetNextString(data).data()); //<1GbE(0) or 10GbE(1)> - n[2] = atoi(GetNextString(data).data()); //header_number - tmp_str[0] = GetNextString(data); //src_mac - tmp_str[1] = GetNextString(data); //src_ip - n[3] = atoi(GetNextString(data).data()); //src_port - tmp_str[2] = GetNextString(data); //dst_mac - tmp_str[3] = GetNextString(data); //dst_ip - n[4] = atoi((tmp_str[4]=GetNextString(data)).data()); //dst_port - - if(n[0]<1||(n[1]!=0&&n[1]!=1)||(n[2]<0||n[2]>63)||tmp_str[0].length()<1||tmp_str[1].length()<1||n[3]<0||tmp_str[2].length()<1||tmp_str[3].length()<1||n[4]<0||tmp_str[4].length()<1){ - return_message.append("\tError executing: SetupTableEntry <1GbE(0) or 10GbE(1)> \n"); - ret_val = 1; - }else{ - for(int i=0;i<32;i++)/** modified for Aldo*/ - ret_val = !bebs->SetBebSrcHeaderInfos(n[0],n[1],tmp_str[0],tmp_str[1],n[3])||!bebs->SetUpUDPHeader(n[0],n[1],n[2]+i,tmp_str[2],tmp_str[3],n[4]); - - if(ret_val) return_message.append("\tError Executing: SetupTableEntry "); - else return_message.append("\tExecuted: SetupTableEntry "); - AddNumber(return_message,n[0]);return_message.append(" "); - AddNumber(return_message,n[1]);return_message.append(" "); - AddNumber(return_message,n[2]);return_message.append(" "); - return_message.append(tmp_str[0]);return_message.append(" "); - return_message.append(tmp_str[1]);return_message.append(" "); - AddNumber(return_message,n[3]);return_message.append(" "); - return_message.append(tmp_str[2]);return_message.append(" "); - return_message.append(tmp_str[3]);return_message.append(" "); - AddNumber(return_message,n[4]); - } - break; - - case evTest : - n[0] = atoi(GetNextString(data).data()); - if(n[0]<1){ - return_message.append("\tError executing: Test \n"); - ret_val = 1; - }else{ - ret_val = !bebs->Test(n[0]); - if(ret_val) return_message.append("\tError Executing: Test "); - else return_message.append("\tExecuted: Test "); - AddNumber(return_message,n[0]); - } - break; - - - case evTestSend : - n[0] = atoi(GetNextString(data).data()); //beb_number; - n[1] = atoi(GetNextString(data).data()); //giga bit, ten giga bit - n[2] = atoi((tmp_str[0]=GetNextString(data)).data()); //header_number - - if(n[0]<1||(n[1]!=0&&n[1]!=1)||(n[2]<0||n[2]>63)||tmp_str[0].length()<1){ - return_message.append("\tError executing: TestSend <1GbE(0) or 10GbE(1)> \n"); - ret_val = 1; - }else{ - ret_val = !bebs->SendMultiReadRequest(n[0],1,n[1],n[2],1,0); - - if(ret_val) return_message.append("\tError Executing: TestSend "); - else return_message.append("\tExecuted: TestSend "); - AddNumber(return_message,n[0]);return_message.append(" "); - AddNumber(return_message,n[1]);return_message.append(" "); - AddNumber(return_message,n[2]);return_message.append(" "); - } - break; - - case evExitServer : - return_message.append("\tExiting Server ....\n"); - stop = 1; - ret_val = -200; - break; - - default : - return_message.append("\tWarning command \""); - return_message.append(cmd); - return_message.append("\" not found.\n"); - return_message.append("\t\tValid commands: "); - map::iterator it = enum_map.begin(); - while(it!=enum_map.end()){ - return_message.append((it++)->first); - return_message.append(" "); - } - - ret_val=-100; - break; - } - - return_message.append("\n"); - AddNumber(return_message,ret_val,return_start_pos); - if(ret_val!=0) break; - - cmd = GetNextString(data); - } - return_message.append("\n\n\n"); - - AddNumber(return_message,ret_val,0); - cout<0) return sub; - } - - return ""; -} - - - -void AddNumber(string& str, int n, int location){ - static char retval_st[100]; - sprintf(retval_st,"%d",n); - - if(location<0) str.append(retval_st); - else str.insert(location,retval_st); -} - - -bool SetupListenSocket(unsigned short int port){ - server_list_s=0; - server_conn_s=0; - - if((server_list_s = socket(AF_INET, SOCK_STREAM, 0))<0) return 0; - - struct sockaddr_in servaddr; /* socket address structure */ - memset(&servaddr, 0, sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = htonl(INADDR_ANY); - servaddr.sin_port = htons(port); - - if(bind(server_list_s,(struct sockaddr *) &servaddr,sizeof(servaddr))<0) return 0; - - if(listen(server_list_s,32) < 0){ // 1024 /* Backlog for listen() */ - return 0; - } - - return 1; -} - - -int AccpetConnectionAndWaitForData(char* buffer, int maxlength){ - if(server_list_s==0||maxlength<=0) return 0; - - if((server_conn_s = accept(server_list_s,NULL,NULL))< 0) return 0; - - int nread = read(server_conn_s,buffer,maxlength-1); - - if(nread<0) return 0; - - buffer[nread]='\0'; - return nread; -} - -bool WriteNClose(const char* buffer, int length){ - if(server_conn_s==0||length<=0) return 0; - - int nsent = write(server_conn_s,buffer,length); - if(close(server_conn_s)<0) return 0; - - server_conn_s=0; - return (nsent==length); -} - - - - diff --git a/slsDetectorSoftware/eigerDetectorServer/Commands.txt b/slsDetectorSoftware/eigerDetectorServer/Commands.txt deleted file mode 100644 index e03e20865..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/Commands.txt +++ /dev/null @@ -1,28 +0,0 @@ - -Internal setup: - setdac - trimbits - rate correction tau - high voltage - - -Setup: - photon energy - dynamic range (4,8,16,32) - number of images - exposure time - exposure period - readout speed(full speed, 1/2 speed, 1/4 or super slow) - readout mode (parallel, non-parallel or super safe) - trigger mode (internal,external start of series, external start of acquisitions, external window) - trigger polarity (pos/neg) - external gating (on, pos/neg) - - -Acquisition: - start acquisition - stop acquisition - acquisition in progress - wait until daq is finished - status (needs to be implemented) - diff --git a/slsDetectorSoftware/eigerDetectorServer/Eiger.cxx b/slsDetectorSoftware/eigerDetectorServer/Eiger.cxx deleted file mode 100644 index 43ac6c5fc..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/Eiger.cxx +++ /dev/null @@ -1,1027 +0,0 @@ - -/** - * @author Ian Johnson - * @version 1.0 - */ - - -#include -#include -#include - -#include -#include -#include -#include - - -#include "EigerRegisterDefs.h" -#include "Eiger.h" - -using namespace std; - -//GetDAQStatusRegister(512,current_mode_bits_from_fpga)){ - -const unsigned int Module::ndacs = 16; -const string Module::dac_names[16] = {"SvP","Vtr","Vrf","Vrs","SvN","Vtgstv","Vcmp_ll","Vcmp_lr","cal","Vcmp_rl","rxb_rb","rxb_lb","Vcmp_rr","Vcp","Vcn","Vis"}; - - -Module::Module(unsigned int number, unsigned int address_top){ - module_number = number; - top_address_valid = 1; - top_left_address = 0x100 | (0xff & address_top); - top_right_address = 0x200 | (0xff & address_top); - bottom_address_valid = 0; - bottom_left_address = 0; - bottom_right_address = 0; - - high_voltage = -1; - top_dac = new float [ndacs]; - bottom_dac = new float [ndacs]; - for(unsigned int i=0;iGetModuleNumber()); - ReadSetUpFile(modules[i]->GetModuleNumber(),st); - } - - return CheckSetup(); -} - - -bool Eiger::ReadSetUpFileToAddModules(string file_name){ - static ifstream infile; - static string line; - static char cmd_st[2000]; - static int value_i[3]; - - infile.open(file_name.c_str(),ios::in); - if(!infile.is_open()) return 0; - - cout<>cmd_st; - if(!strcmp("add_module",cmd_st)){ - if(!(iss>>value_i[0]>>value_i[1]>>value_i[2])){ - cout<<"Error adding module from "<>value_i[0]>>value_i[1])){ - cout<<"Error adding half module from "<TopAddressIsValid()){ - feb_list[nfebs++] = modules[i]->GetTopRightAddress(); - feb_list[nfebs++] = modules[i]->GetTopLeftAddress(); - } - if(modules[i]->BottomAddressIsValid()){ - feb_list[nfebs++] = modules[i]->GetBottomRightAddress(); - feb_list[nfebs++] = modules[i]->GetBottomLeftAddress(); - } - } - - SendCompleteFebList(nfebs,feb_list); - delete [] feb_list; - - cout<GetModuleNumber()<<" "; - if(modules[i]->TopAddressIsValid()) cout<GetTopBaseAddress()<<" (top) "<BottomAddressIsValid()) cout<GetBottomBaseAddress()<<" (bottom)"<GetModuleNumber()==module_number){ - module_index=i; - return 1; - } - } - - return 0; -} - -bool Eiger::CheckModuleAddresses(unsigned int top_address, unsigned int bottom_address){ - bool found_t = 0; - bool found_b = 0; - for(unsigned int i=0;iGetTopBaseAddress() || top_address==modules[i]->GetBottomBaseAddress())) found_t=1; - if(bottom_address!=0 && (bottom_address==modules[i]->GetTopBaseAddress() || bottom_address==modules[i]->GetBottomBaseAddress())) found_b=1; - } - - if(top_address==bottom_address) cout<<"\tWarning: top and bottom address are the same "<>cmd_st; - - if(cmd_st[0]=='#'||!strcmp("add_module",cmd_st)||!strcmp("add_half_module",cmd_st)){ ;// cout<<"do nothing "<>value_i[0])) cout<<"Error reading iodelay from "<>value_f; - SetHighVoltage(module_num,value_f); - }else if(!strcmp("photon_energy",cmd_st)){ - iss>>value_f; - SetPhotonEnergy(value_f); - }else if(!strcmp("dynamic_range",cmd_st)){ - iss>>value_i[0]; - SetDynamicRange(value_i[0]); - }else if(!strcmp("readout_speed",cmd_st)){ - iss>>value_i[0]; - SetReadoutSpeed(value_i[0]); - }else if(!strcmp("readout_mode",cmd_st)){ - iss>>value_i[0]; - SetReadoutMode(value_i[0]); - }else{ - iss>>value_f; - if(module_num>0) sprintf(cmd_st,"mod%d::%s",module_num,cmd_st); - if(!SetDAC(cmd_st,value_f)) cout<<"error in string: "<GetTopIDelay(j)<0){ - cout<<"Warning: module "<GetModuleNumber()<<"'s idelay top number "<GetBottomIDelay(j)<0){ - cout<<"Warning: module "<GetModuleNumber()<<"'s idelay bottom number "<GetHighVoltage()<0){ - cout<<"Warning: module "<GetModuleNumber()<<"'s high voltage not set."<GetTopDACVoltage(j)<0){ - cout<<"Warning: module "<GetModuleNumber()<<"'s top \""<GetBottomDACVoltage(j)<0){ - cout<<"Warning: module "<GetModuleNumber()<<"'s bottom \""<TopAddressIsValid()) n_half_modules++; - if(modules[i]->BottomAddressIsValid()) n_half_modules++; - } - - return n_half_modules; -} - -bool Eiger::SetPhotonEnergy(unsigned int full_energy_eV){ - photon_energy_eV = full_energy_eV; - cout<<"Setting photon energy to: "<3){ - cout<<"Error SetIDelay chip_pos "<TopAddressIsValid()){ - if(SendIDelays(modules[module_index]->GetTopLeftAddress(),chip_pos%2==0,0xffffffff,ndelay_units)){ - if(module_index!=0) modules[module_index]->SetTopIDelay(chip_pos,ndelay_units); - else for(unsigned int i=0;iSetTopIDelay(chip_pos,ndelay_units); - }else{ - cout<<"Error could not set idelay module number "<BottomAddressIsValid()){ - if(SendIDelays(modules[module_index]->GetBottomLeftAddress(),chip_pos%2==0,0xffffffff,ndelay_units)){ - if(module_index!=0) modules[module_index]->SetBottomIDelay(chip_pos,ndelay_units); - else for(unsigned int i=0;iSetBottomIDelay(chip_pos,ndelay_units); - }else{ - cout<<"Error could not set idelay module number "<TopAddressIsValid()){ - if(SendIDelays(modules[module_index]->GetTopRightAddress(),chip_pos%2==0,0xffffffff,ndelay_units)){ - if(module_index!=0) modules[module_index]->SetTopIDelay(chip_pos,ndelay_units); - else for(unsigned int i=0;iSetTopIDelay(chip_pos,ndelay_units); - }else{ - cout<<"Error could not set idelay module number "<BottomAddressIsValid()){ - if(SendIDelays(modules[module_index]->GetBottomRightAddress(),chip_pos%2==0,0xffffffff,ndelay_units)){ - if(module_index!=0) modules[module_index]->SetBottomIDelay(chip_pos,ndelay_units); - else for(unsigned int i=0;iSetBottomIDelay(chip_pos,ndelay_units); - }else{ - cout<<"Error could not set idelay module number "<0x3ff) ndelay_units=0x3ff; - // this is global - unsigned int delay_data_valid_nclks = 15 - ((ndelay_units&0x3c0)>>6); //data valid delay upto 15 clks - ndelay_units &= 0x3f; //up to 64 delay units - // ndelay_unit |= 0x40; //and one bit for a full clock delay for the enabled pixels is zero for now - - unsigned int set_left_delay_channels = chip_lr ? channels:0; - unsigned int set_right_delay_channels = chip_lr ? 0:channels; - - cout<<"\tSetting delays of "; - if(set_left_delay_channels!=0) cout<<"left chips of dst_num "<vmax) return 0; - digital = int(((value-vmin)/(vmax-vmin))*(nsteps-1) + 0.5); - return 1; -} - -float Eiger::DACToVoltage(unsigned int digital,unsigned int nsteps,float vmin,float vmax){ - return vmin+(vmax-vmin)*digital/(nsteps-1); -} - - -bool Eiger::SetHighVoltage(unsigned int module_num,float value){ - unsigned int module_index=0; - if(!GetModuleIndex(module_num,module_index)||!modules[module_index]->TopAddressIsValid()){ - cout<<"Error could not set high voltage module number "<GetTopRightAddress(),value)) return 0; - - if(module_index!=0) modules[module_index]->SetHighVoltage(value); - else for(unsigned int i=0;iSetHighVoltage(value); - - cout<<"\tHigh voltage of dst "<GetTopRightAddress()<<" set to "<GetHighVoltage()<<"."<TopAddressIsValid()){ - float v = value; - if(!SendDACValue(modules[module_index]->GetTopRightAddress(),dac_ch,v)) return 0; - if(module_index!=0) modules[module_index]->SetTopDACVoltage(dac_ch,v); - else for(unsigned int i=0;iSetTopDACVoltage(dac_ch,v); - - } - if(bottom&&modules[module_index]->BottomAddressIsValid()){ - float v = value; - if(!SendDACValue(modules[module_index]->GetBottomRightAddress(),dac_ch,v)) return 0; - if(module_index!=0) modules[module_index]->SetBottomDACVoltage(dac_ch,v); - else for(unsigned int i=0;iSetBottomDACVoltage(dac_ch,v); - } - - return 1; -} - -bool Eiger::GetDAC(std::string s, float& ret_value){ - cout<<"Function Eiger::GetDAC need to be finished....."<=Module::ndacs){ - cout<<"Warning: Eiger::GetDACName index out of range, "<15){ - cout<<"Warning invalid ch for SetDAC."<>3)<<((7-i)*4);//upper - trimbits_to_load_r[offset+chip_sc] |= ( 0x7 & trimbits[263679 - (row_set*16480+super_column_start_position_r+i)])<<((7-i)*4);//low - trimbits_to_load_r[offset+chip_sc+32] |= ((0x38 & trimbits[263679 - (row_set*16480+super_column_start_position_r+i)])>>3)<<((7-i)*4);//upper - } - } - } - - if(!WriteMemory(0,0,0,1024,trimbits_to_load_r)||!WriteMemory(1,0,0,1024,trimbits_to_load_l)||!StartDAQOnlyNWaitForFinish()) return 0; - } - } - - memcpy(last_downloaded_trimbits,trimbits,trimbit_size*sizeof(unsigned char)); - - return SetStaticBits(); //send the static bits -} - - -unsigned char* Eiger::GetTrimbits(){ - return last_downloaded_trimbits; -} - - - - -bool Eiger::SetCommandRegister(unsigned int cmd){ - // if(fifo_enabled){ - // return WriteRegister(-1,DAQ_REG_CHIP_CMDS,cmd | DAQ_FIFO_ENABLE); - // } - return WriteRegister(0xfff,DAQ_REG_CHIP_CMDS,cmd); -} - - -bool Eiger::GetDAQStatusRegister(int socket_num, unsigned int &ret_status){ - - if(!ReadRegister(socket_num,DAQ_REG_STATUS,ret_status)){ - cout<<"Error: reading status register."<> 16; - return 1; -} - - -bool Eiger::StartDAQOnlyNWaitForFinish(int sleep_time_us){ - if(!WriteRegister(0xfff,DAQ_REG_CTRL,0)||!WriteRegister(0xfff,DAQ_REG_CTRL,DAQ_CTRL_START)){ - cout<<"Warning: could not start."<full,1->half,2->quarter or 3->super_slow - acquireNReadoutMode &= (~DAQ_CHIP_CONTROLLER_SUPER_SLOW_SPEED); - if(readout_speed==1){ - acquireNReadoutMode |= DAQ_CHIP_CONTROLLER_HALF_SPEED; - cout<<"Everything at half speed, ie. reading with 50 MHz main clk (half speed) ...."<parallel,1->non-parallel,2-> safe_mode - acquireNReadoutMode &= (~DAQ_NEXPOSURERS_PARALLEL_MODE); - if(readout_mode==1){ - acquireNReadoutMode |= DAQ_NEXPOSURERS_NORMAL_NONPARALLEL_MODE; - cout<<"Readout mode set to normal non-parallel readout mode ... "< internal exposure time and period, - //"01"-> external acquistion start and internal exposure time and period, - //"10"-> external start trigger and internal exposure time, - //"11"-> external triggered start and stop of exposures - triggerMode = (~DAQ_NEXPOSURERS_EXTERNAL_IMAGE_START_AND_STOP); - - if(trigger_mode == 1){ - triggerMode = DAQ_NEXPOSURERS_EXTERNAL_ACQUISITION_START; - cout<<"Trigger mode: external start of acquisition sequence, internal exposure length and period."<(pow(2,29)-1)*pow(10,7)){ - float max_time = 10e-9*(pow(2,28)-1)*pow(10,7); - cout<<"Warning: time exceeds ("<pow(2,29)-1){ power_of_ten++; n_clk_cycles = round(n_clk_cycles/10.0);} - decoded_time = int(n_clk_cycles)<<3 | int(power_of_ten); - } - - return decoded_time; -} - - -bool Eiger::ResetDataStream(){ - //for(int i=0;i<10;i++) cout<<"Warning need to think about reseting data stream ...."< -#include - -#include "Feb.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; - float* top_dac; - float* 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;} - - float SetTopDACVoltage(unsigned int i, float value) { return (i 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 char* last_downloaded_trimbits; - - void PrintModuleList(); - bool GetModuleIndex(unsigned int module_number, unsigned int& module_index); - bool CheckModuleAddresses(unsigned int top_address, unsigned int bottom_address); - 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, float& 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); - - unsigned int ConvertTimeToRegister(float time_in_sec); - - bool SetCommandRegister(unsigned int cmd); - bool GetDAQStatusRegister(int socket_num, unsigned int &ret_status); - bool StartDAQOnlyNWaitForFinish(int sleep_time_us=5000); - bool ResetDataStream(); - - bool ResetChipCompletely(); - - public: - Eiger(); - virtual ~Eiger(); - - bool Init(); - bool ReadSetUpFileToAddModules(std::string file_name); - bool ReadSetUpFile(unsigned int module_num, std::string file_name); - bool CheckSetup(); - - unsigned int GetNModules(); - unsigned int GetNHalfModules(); - - //bool SetHighVoltage(float value); - bool SetHighVoltage(unsigned int module_num,float value); - - bool SetPhotonEnergy(unsigned int full_energy_eV); - unsigned int GetPhotonEnergy(){return photon_energy_eV;} - - bool SetIDelays(unsigned int module_num, unsigned int ndelay_units); - bool SetIDelays(unsigned int module_num, unsigned int chip_pos, unsigned int ndelay_units); - - bool SetDAC(std::string s, float value); - bool GetDAC(std::string s, float& ret_value); - bool GetDACName(unsigned int dac_num, std::string &s); - - bool SetTrimbits(unsigned char* trimbits); - unsigned char* GetTrimbits(); - - - - bool Reset(); - bool StartAcquisition(); - bool StopAcquisition(); - bool AcquisitionInProgress(); - bool WaitForFinishedFlag(int sleep_time_us=5000); - - //functions for setting up exposure - void PrintAcquisitionSetup(); - bool SetNImages(unsigned int n_images); - unsigned int GetNImages(); - 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); - - - //functions for testing - bool SetTestModeVariable(bool on=1); - bool GetTestModeVariable(); - - bool FebTest(){return Feb::Test();} - -}; - - -#endif diff --git a/slsDetectorSoftware/eigerDetectorServer/EigerBackEndFunctions.c b/slsDetectorSoftware/eigerDetectorServer/EigerBackEndFunctions.c deleted file mode 100644 index 1378160f5..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/EigerBackEndFunctions.c +++ /dev/null @@ -1,200 +0,0 @@ - -/** - * @author Ian Johnson - * @version 1.0 - */ - - -#include -#include -#include -#include - - - -#include "slsDetectorServer_defs.h" //include port number - -struct sockaddr_in eiger_back_socket_addr; -int eiger_back_max_message_length = 1024; -char eiger_back_message[1024]; -int eiger_back_message_length = 0; -int eiger_back_ret_val=0; - - -int bit_mode=0; -int ten_giga=0; - -int EigerBackInit(){ - static int passed = 0; - - if(!passed){ - struct hostent *dst_host; - if((dst_host = gethostbyname("localhost")) == NULL){ //or look into getaddrinfo(3) - fprintf(stderr,"ERROR, no such host\n"); - return 0; - }else{ - //struct sockaddr_in eiger_back_socket_addr; - int port = BEB_PORT; - bzero((char *) &eiger_back_socket_addr, sizeof(eiger_back_socket_addr)); - eiger_back_socket_addr.sin_family = AF_INET; - bcopy((char *)dst_host->h_addr,(char *)&eiger_back_socket_addr.sin_addr.s_addr,dst_host->h_length); - eiger_back_socket_addr.sin_port = htons(port); - passed = 1; - } - } - - return passed; -} - - -int EigerBackSendCMD(){ - if(!EigerBackInit()||eiger_back_message_length<=0) return 0; - - int sockfd = socket(AF_INET,SOCK_STREAM,0); - if(sockfd<0){ - fprintf(stderr,"ERROR opening socket\n"); - return 0; - } - - if(connect(sockfd,(struct sockaddr *) &eiger_back_socket_addr,sizeof(eiger_back_socket_addr))<0){ - fprintf(stderr,"ERROR connecting\n"); - return 0; - } - - int n = write(sockfd,eiger_back_message,eiger_back_message_length); - int ret_length = read(sockfd,eiger_back_message,eiger_back_max_message_length); - - close(sockfd); - - if(n<0||ret_length<0) return 0; - - - //fprintf(stdout,"%s\n",eiger_back_message); - if(eiger_back_ret_val>0){ - int i=0; - eiger_back_message[1]='\0'; - if(atoi(eiger_back_message)!=0) return 0; - - for(i=2;i <1GbE(0) or 10GbE(1)> -int EigerSetupTableEntryLeft(int ipad, long long int macad, long long int detectormacadd, int detipad, int udpport){ - char src_mac[50], src_ip[50],dst_mac[50], dst_ip[50]; - - int src_port = 0xE185; - int dst_port = udpport; - sprintf(src_ip,"%d.%d.%d.%d",(detipad>>24)&0xff,(detipad>>16)&0xff,(detipad>>8)&0xff,(detipad)&0xff); - sprintf(dst_ip,"%d.%d.%d.%d",(ipad>>24)&0xff,(ipad>>16)&0xff,(ipad>>8)&0xff,(ipad)&0xff); - sprintf(src_mac,"%02x:%02x:%02x:%02x:%02x:%02x",(unsigned int)((detectormacadd>>40)&0xFF), - (unsigned int)((detectormacadd>>32)&0xFF), - (unsigned int)((detectormacadd>>24)&0xFF), - (unsigned int)((detectormacadd>>16)&0xFF), - (unsigned int)((detectormacadd>>8)&0xFF), - (unsigned int)((detectormacadd>>0)&0xFF)); - sprintf(dst_mac,"%02x:%02x:%02x:%02x:%02x:%02x",(unsigned int)((macad>>40)&0xFF), - (unsigned int)((macad>>32)&0xFF), - (unsigned int)((macad>>24)&0xFF), - (unsigned int)((macad>>16)&0xFF), - (unsigned int)((macad>>8)&0xFF), - (unsigned int)((macad>>0)&0xFF)); - - printf("Seting up Table Entry Left:\n"); - printf("src_port:%d\n",src_port); - printf("dst_port:%d\n",dst_port); - printf("src_ip:%s\n",src_ip); - printf("dst_ip:%s\n",dst_ip); - printf("src_mac:%s\n",src_mac); - printf("dst_mac:%s\n\n",dst_mac); - - - - eiger_back_ret_val=0; - eiger_back_message_length = sprintf(eiger_back_message,"setuptableentry %d %d %d %s %s %d %s %s %d",34,ten_giga,0,src_mac,src_ip,src_port,dst_mac,dst_ip,dst_port); - return EigerBackSendCMD(); -} - - -int EigerSetupTableEntryRight(int ipad, long long int macad, long long int detectormacadd, int detipad, int udpport){ - char src_mac[50], src_ip[50],dst_mac[50], dst_ip[50]; - - int src_port = 0xE185; - int dst_port = udpport+1; - sprintf(src_ip,"%d.%d.%d.%d",(detipad>>24)&0xff,(detipad>>16)&0xff,(detipad>>8)&0xff,(detipad)&0xff); - sprintf(dst_ip,"%d.%d.%d.%d",(ipad>>24)&0xff,(ipad>>16)&0xff,(ipad>>8)&0xff,(ipad)&0xff); - sprintf(src_mac,"%02x:%02x:%02x:%02x:%02x:%02x",(unsigned int)((detectormacadd>>40)&0xFF), - (unsigned int)((detectormacadd>>32)&0xFF), - (unsigned int)((detectormacadd>>24)&0xFF), - (unsigned int)((detectormacadd>>16)&0xFF), - (unsigned int)((detectormacadd>>8)&0xFF), - (unsigned int)((detectormacadd>>0)&0xFF)); - sprintf(dst_mac,"%02x:%02x:%02x:%02x:%02x:%02x",(unsigned int)((macad>>40)&0xFF), - (unsigned int)((macad>>32)&0xFF), - (unsigned int)((macad>>24)&0xFF), - (unsigned int)((macad>>16)&0xFF), - (unsigned int)((macad>>8)&0xFF), - (unsigned int)((macad>>0)&0xFF)); - - printf("Seting up Table Entry Right:\n"); - printf("src_port:%d\n",src_port); - printf("dst_port:%d\n",dst_port); - printf("src_ip:%s\n",src_ip); - printf("dst_ip:%s\n",dst_ip); - printf("src_mac:%s\n",src_mac); - printf("dst_mac:%s\n\n",dst_mac); - - eiger_back_ret_val=0; - eiger_back_message_length = sprintf(eiger_back_message,"setuptableentry %d %d %d %s %s %d %s %s %d",34,ten_giga,32,src_mac,src_ip,src_port,dst_mac,dst_ip,dst_port); - return EigerBackSendCMD(); -} - - - - -int RequestImages(){ - printf("Going to request images\n"); - eiger_back_ret_val=0; - eiger_back_message_length = sprintf(eiger_back_message,"requestimages %d",0); // dst_number - return EigerBackSendCMD(); -} - -int SetDestinationParameters(int i){ - eiger_back_ret_val=0; - eiger_back_message_length = sprintf(eiger_back_message,"setdstparameters %d %d %d",ten_giga,1,i);// number of dsts - return EigerBackSendCMD(); -} - - -void SetTenGigbaBitEthernet(int val){ - ten_giga = val; -} - - -int GetTenGigbaBitEthernet(){ - return ten_giga; -} diff --git a/slsDetectorSoftware/eigerDetectorServer/EigerHighLevelFunctions.c b/slsDetectorSoftware/eigerDetectorServer/EigerHighLevelFunctions.c deleted file mode 100644 index 445a9a2cb..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/EigerHighLevelFunctions.c +++ /dev/null @@ -1,363 +0,0 @@ - -/** - * @author Ian Johnson - * @version 1.0 - */ - -#include -#include -#include -#include - -#include "slsDetectorServer_defs.h" //include port number - - - -int eiger_nexposures = 1; -float eiger_exposuretime = 0; -float eiger_exposureperiod = 0; -int eiger_ncycles = 1; -int eiger_ngates = 0; -int eiger_getphotonenergy = 0; -int eiger_dynamicrange = 0; -int eiger_readoutspeed = 0; -int eiger_readoutmode = 0; -int eiger_highvoltage = 0; -int eiger_iodelay = 0; -int eiger_triggermode = 0; -int eiger_extgating = 0; -int eiger_extgatingpolarity = 0; - -const unsigned int ndacs = 16; -const char* dac_names[16] = {"SvP","Vtr","Vrf","Vrs","SvN","Vtgstv","Vcmp_ll","Vcmp_lr","cal","Vcmp_rl","rxb_rb","rxb_lb","Vcmp_rr","Vcp","Vcn","Vis"}; - -int saved_trimbits[256*256*4]; - - -int EigerGetNumberOfExposures(){return eiger_nexposures;} -float EigerGetExposureTime(){return eiger_exposuretime;} -float EigerGetExposurePeriod(){return eiger_exposureperiod;} -int EigerGetNumberOfCycles(){return eiger_ncycles;} -/*int EigerGetNumberOfGates(){return eiger_ngates;}*/ -unsigned int EigerGetDynamicRange(){return eiger_dynamicrange;} -int EigerGetPhotonEnergy(){return eiger_getphotonenergy;} -int EigerGetReadoutSpeed(){return eiger_readoutspeed;} -int EigerGetReadoutMode(){return eiger_readoutmode;} -int EigerGetHighVoltage(){return eiger_highvoltage;} -int EigerGetIODelay(){return eiger_iodelay;} -int EigerGetTriggerMode(){return eiger_triggermode;} -int EigerGetExternalGating(){return eiger_extgating;} -int EigerGetExternalGatingPolarity(){return eiger_extgatingpolarity;} - -int EigerInit(){ - saved_trimbits[0] = -1; - - -} - - -int EigerSendCMD(){ - if(!EigerInit()||eiger_message_length<=0) return 0; - - int sockfd = socket(AF_INET,SOCK_STREAM,0); - if(sockfd<0){ - fprintf(stderr,"ERROR opening socket\n"); - return 0; - } - - if(connect(sockfd,(struct sockaddr *) &eiger_socket_addr,sizeof(eiger_socket_addr))<0){ - fprintf(stderr,"ERROR connecting\n"); - return 0; - } - - int n = write(sockfd,eiger_message,eiger_message_length); - - int ret_length = read(sockfd,eiger_message,eiger_max_message_length); - - close(sockfd); - - if(n<0||ret_length<0) return 0; - - - //fprintf(stdout,"%s\n",eiger_message); - if(eiger_ret_val>0){ - int i=0; - eiger_message[1]='\0'; - if(atoi(eiger_message)!=0) return 0; - - for(i=2;i0&&ireadout ->expose -> ..., with store is always closed -#define DAQ_NEXPOSURERS_PARALLEL_MODE 0x00600000 //parallel acquire/read mode - -//DAQ_NEXPOSURERS_READOUT_COMPLETE_IMAGES is old now hard-wired in the firmware that every image comes with a header -//#define DAQ_NEXPOSURERS_READOUT_COMPLETE_IMAGES 0x00800000 //DAQ_IGNORE_INITIAL_CRAP and DAQ_CLKOUT_LAST_4_BITS_AND_RETURN_TO_START - -#define DAQ_NEXPOSURERS_EXTERNAL_ENABLING 0x01000000 -#define DAQ_NEXPOSURERS_EXTERNAL_ENABLING_POLARITY 0x02000000 -#define DAQ_NEXPOSURERS_EXTERNAL_TRIGGER_POLARITY 0x04000000 - -#define DAQ_NEXPOSURERS_INTERNAL_ACQUISITION 0x00000000 //internally controlled -#define DAQ_NEXPOSURERS_EXTERNAL_ACQUISITION_START 0x08000000 //external acquisition start -#define DAQ_NEXPOSURERS_EXTERNAL_IMAGE_START 0x10000000 //external image start -#define DAQ_NEXPOSURERS_EXTERNAL_IMAGE_START_AND_STOP 0x18000000 //externally controlly, external image start and stop - -#define DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING 0x20000000 -#define DAQ_NEXPOSURERS_ACTIVATE_RATE_CORRECTION 0x40000000 - -//#define DAQ_MASTER_HALF_MODULE 0x80000000 currently not used - - -//chips static bits -#define DAQ_STATIC_BIT_PROGRAM 0x00000001 -#define DAQ_STATIC_BIT_M4 0x00000002 //these are the status bits, not bit mode -#define DAQ_STATIC_BIT_M8 0x00000004 //these are the status bits, not bit mode -#define DAQ_STATIC_BIT_M12 0x00000000 //these are the status bits, not bit mode, ie. "00" is 12 bit mode -#define DAQ_STATIC_BIT_CHIP_TEST 0x00000008 -#define DAQ_STATIC_BIT_ROTEST 0x00000010 -#define DAQ_CS_BAR_LEFT 0x00000020 -#define DAQ_CS_BAR_RIGHT 0x00000040 - - -//status flags -#define DAQ_STATUS_DAQ_RUNNING 0x01 -#define DAQ_DATA_COLLISION_ERROR 0x02 - -#define DAQ_STATUS_CURRENT_M4 0x04 -#define DAQ_STATUS_CURRENT_M8 0x08 -#define DAQ_STATUS_CURRENT_M12 0x00 //in 12 bit mode both are cleared -#define DAQ_STATUS_CURRENT_TESTMODE 0x10 -#define DAQ_STATUS_TOKEN_OUT 0x20 -#define DAQ_STATUS_SERIAL_OUT 0x40 -#define DAQ_STATUS_PIXELS_ARE_ENABLED 0x80 -#define DAQ_STATUS_DAQ_RUN_TOGGLE 0x200 - -//data delay registers -#define CHIP_DATA_OUT_DELAY_REG_CTRL 1 -#define CHIP_DATA_OUT_DELAY_REG2 2 -#define CHIP_DATA_OUT_DELAY_REG3 3 -#define CHIP_DATA_OUT_DELAY_REG4 4 -#define CHIP_DATA_OUT_DELAY_SET 0x20000000 - - -//module configuration -#define TOP_BIT_MASK 0x00f -#define MASTER_BIT_MASK 0x200 diff --git a/slsDetectorSoftware/eigerDetectorServer/EigerTest.cxx b/slsDetectorSoftware/eigerDetectorServer/EigerTest.cxx deleted file mode 100644 index 4e95bd560..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/EigerTest.cxx +++ /dev/null @@ -1,38 +0,0 @@ - -/** - * @author Ian Johnson - * @version 1.0 - */ - - -#include -#include - -#include - -#include "Eiger.h" - - -using namespace std; - -int main(int argc, char* argv[]){ - - cout<<"\n\n\n\n\n\n\n\n\n\n"<1) ? atoi(argv[1]):5; - - //Feb *f = new Feb(); - // f->Test(); - //delete f; - //return 0; - - Eiger* e = new Eiger(); - e->SetNImages(n); - e->SetDynamicRange(32); - e->SetExposureTime(0.02); - e->SetExposurePeriod(0.050); - e->StartAcquisition(); - - delete e; - - return 0; -} diff --git a/slsDetectorSoftware/eigerDetectorServer/Feb.cxx b/slsDetectorSoftware/eigerDetectorServer/Feb.cxx deleted file mode 100644 index 8bb6bbebc..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/Feb.cxx +++ /dev/null @@ -1,326 +0,0 @@ - -/** - * @author Ian Johnson - * @version 1.0 - */ - - -//return reversed 1 means good, 0 means failed - - -#include -#include -//#include -//#include -//#include -//#include - -#include "xparameters.h" - -#include "Feb.h" - -using namespace std; - -Feb::Feb(){ - - nfebs = 0; - feb_numb = 0; - - send_ndata = 0; - send_buffer_size = 1026; - send_data_raw = new unsigned int [send_buffer_size+1]; - send_data = &send_data_raw[1]; - - recv_ndata = 0; - recv_buffer_size = 1026; - recv_data_raw = new unsigned int [recv_buffer_size+1]; - recv_data = &recv_data_raw[1]; - - ll = new LocalLinkInterface(XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_RIGHT_BASEADDR); - -} - -Feb::~Feb(){ - delete ll; - if(feb_numb) delete [] feb_numb; - delete [] send_data_raw; - delete [] recv_data_raw; -} - -void Feb::SendCompleteFebList(unsigned int n,unsigned int* list){ - if(feb_numb) delete [] feb_numb; - nfebs = n; - feb_numb = new unsigned int [n]; - for(unsigned int i=0;i0xfff) return 0; - - send_data_raw[0] = 0x90000000 | (ch<<16); //we - if(ll->Write(4,send_data_raw)!=4) return 0; - - send_data_raw[0] = 0xc0000000; //data - return ((send_ndata+1)*4==ll->Write((send_ndata+1)*4,send_data_raw)); -} - -bool Feb::ReadFrom(unsigned int ch, unsigned int ntrys){ - if(ch>=0xfff) return 0; - - recv_data_raw[0] = 0xa0000000 | (ch<<16); //read data - ll->Write(4,recv_data_raw); - usleep(20); - - recv_ndata=-1; - for(unsigned int t=0;tRead(recv_buffer_size*4,recv_data_raw)/4)>0){ - recv_ndata--; - break; - } - cout<<"\t Read try number: "<=0); -} - -void Feb::PrintData(){ - cout<<"Sent data: "<1&&recv_ndata>1){ - cout<<"\t\t Tail sent: "<Write(4,send_data_raw)!=4) return 0; - - cout<<"Feb::CheckingCommunication ...."<Read(recv_buffer_size*4,recv_data_raw)/4)>0) cout<<"\t) Cleanning buffer ..."<=nfebs){ - cout<<"Error invalid sub number "<send_buffer_size-2) return 0; - - send_ndata = nreads+2; - send_data[0] = 0x20000000 | nreads << 14; //cmd -> read "00" , nreads - - for(unsigned int i=0;isend_buffer_size-2) return 0; - - //cout<<"Write register : "< write nwrites and how many - send_data[2*nwrites+1] = 0; //tail - - for(unsigned int i=0;isend_buffer_size-2) return 0; - - send_ndata = nwrites+2; - send_data[0] = 0xc0000000 | mem_num << 24 | nwrites << 14 | start_address; //cmd -> write to memory, nwrites, mem number, start address - send_data[nwrites+1] = 0; //tail - for(unsigned int i=0;i -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - - - -#include "FebRegisterDefs.h" -#include "FebControl.h" - -using namespace std; - -//GetDAQStatusRegister(512,current_mode_bits_from_fpga)){ - -const unsigned int Module::ndacs = 16; -const string Module::dac_names[16] = {"SvP","Vtr","Vrf","Vrs","SvN","Vtgstv","Vcmp_ll","Vcmp_lr","cal","Vcmp_rl","rxb_rb","rxb_lb","Vcmp_rr","Vcp","Vcn","Vis"}; - - -Module::Module(unsigned int number, unsigned int address_top){ - module_number = number; - top_address_valid = 1; - top_left_address = 0x100 | (0xff & address_top); - top_right_address = 0x200 | (0xff & address_top); - bottom_address_valid = 0; - bottom_left_address = 0; - bottom_right_address = 0; - - high_voltage = -1; - top_dac = new int [ndacs]; - bottom_dac = new int [ndacs]; - for(unsigned int i=0;iGetModuleNumber()); - ReadSetUpFile(modules[i]->GetModuleNumber(),st); - } - - - return CheckSetup(); -} - - -bool FebControl::ReadSetUpFileToAddModules(string file_name){ - static ifstream infile; - static string line; - static char cmd_st[2000]; - static int value_i[3]; - - infile.open(file_name.c_str(),ios::in); - if(!infile.is_open()) return 0; - - cout<>cmd_st; - if(!strcmp("add_module",cmd_st)){ - if(!(iss>>value_i[0]>>value_i[1]>>value_i[2])){ - cout<<"Error adding module from "<>value_i[0]>>value_i[1])){ - cout<<"Error adding half module from "<TopAddressIsValid()){ - feb_list[nfebs++] = modules[i]->GetTopRightAddress(); - feb_list[nfebs++] = modules[i]->GetTopLeftAddress(); - } - if(modules[i]->BottomAddressIsValid()){ - feb_list[nfebs++] = modules[i]->GetBottomRightAddress(); - feb_list[nfebs++] = modules[i]->GetBottomLeftAddress(); - } - } - - FebInterface::SendCompleteList(nfebs,feb_list); - delete [] feb_list; - - cout<GetModuleNumber()<<" "; - if(modules[i]->TopAddressIsValid()) cout<GetTopBaseAddress()<<" (top) "<BottomAddressIsValid()) cout<GetBottomBaseAddress()<<" (bottom)"<GetModuleNumber()==module_number){ - module_index=i; - return 1; - } - } - - return 0; -} - -bool FebControl::CheckModuleAddresses(Module* m){ - bool found_t = 0; - bool found_b = 0; - for(unsigned int i=0;iTopAddressIsValid() && modules[i]->GetTopBaseAddress() && m->GetTopBaseAddress()==modules[i]->GetTopBaseAddress()) || - (m->TopAddressIsValid() && modules[i]->GetBottomBaseAddress() && m->GetTopBaseAddress()==modules[i]->GetBottomBaseAddress())) found_t=1; - if((m->BottomAddressIsValid() && modules[i]->GetTopBaseAddress() && m->GetBottomBaseAddress()==modules[i]->GetTopBaseAddress()) || - (m->BottomAddressIsValid() && modules[i]->GetBottomBaseAddress() && m->GetBottomBaseAddress()==modules[i]->GetBottomBaseAddress())) found_b=1; - } - - if(found_t) cout<<"\tWarning: top address "<< m->GetTopBaseAddress()<<" already used."<GetBottomBaseAddress()<<" already used."<TopAddressIsValid()&&m->BottomAddressIsValid()&&m->GetTopBaseAddress()==m->GetBottomBaseAddress(); - if(top_bottom_same) cout<<"\tWarning: top and bottom address are the same "<GetTopBaseAddress()<<"."<TopAddressIsValid()&&m->BottomAddressIsValid()){ - cout<<"\tAdding full module number "<GetModuleNumber()<<" with top and bottom base addresses: "<GetTopBaseAddress()<<" "<GetBottomBaseAddress()<TopAddressIsValid()){ - cout<<"\tAdding half module number "<GetModuleNumber()<<" with top base address: "<GetTopBaseAddress()<BottomAddressIsValid()){ - cout<<"\tAdding half module number "<GetModuleNumber()<<" with bottom base address: "<GetBottomBaseAddress()<>cmd_st; - - if(cmd_st[0]=='#'||!strcmp("add_module",cmd_st)||!strcmp("add_half_module",cmd_st)){ ;// cout<<"do nothing "<>value_i[0])) cout<<"Error reading iodelay from "<>value_f; - SetHighVoltage(module_num,value_f); - }else if(!strcmp("photon_energy",cmd_st)){ - iss>>value_f; - SetPhotonEnergy(value_f); - }else if(!strcmp("dynamic_range",cmd_st)){ - iss>>value_i[0]; - SetDynamicRange(value_i[0]); - }else if(!strcmp("readout_speed",cmd_st)){ - iss>>value_i[0]; - SetReadoutSpeed(value_i[0]); - }else if(!strcmp("readout_mode",cmd_st)){ - iss>>value_i[0]; - SetReadoutMode(value_i[0]); - }else{ - iss>>value_f; - if(module_num>0) sprintf(cmd_st,"mod%d::%s",module_num,cmd_st); - if(!SetDAC(cmd_st,value_f,1)) cout<<"error in string: "<GetTopIDelay(j)<0){ - cout<<"Warning: module "<GetModuleNumber()<<"'s idelay top number "<GetBottomIDelay(j)<0){ - cout<<"Warning: module "<GetModuleNumber()<<"'s idelay bottom number "<GetHighVoltage()<0){ - cout<<"Warning: module "<GetModuleNumber()<<"'s high voltage not set."<GetTopDACValue(j)<0){ - cout<<"Warning: module "<GetModuleNumber()<<"'s top \""<GetBottomDACValue(j)<0){ - cout<<"Warning: module "<GetModuleNumber()<<"'s bottom \""<TopAddressIsValid()) n_half_modules++; - if(modules[i]->BottomAddressIsValid()) n_half_modules++; - } - - return n_half_modules; -} - -bool FebControl::SetPhotonEnergy(unsigned int full_energy_eV){ - photon_energy_eV = full_energy_eV; - cout<<"Setting photon energy to: "<3){ - cout<<"Error SetIDelay chip_pos "<TopAddressIsValid()){ - if(SendIDelays(modules[module_index]->GetTopLeftAddress(),chip_pos%2==0,0xffffffff,ndelay_units)){ - if(module_index!=0) modules[module_index]->SetTopIDelay(chip_pos,ndelay_units); - else{ - for(unsigned int i=0;iSetTopIDelay(chip_pos,ndelay_units); - for(unsigned int i=0;iSetBottomIDelay(chip_pos,ndelay_units); - } - }else{ - cout<<"Error could not set idelay module number "<BottomAddressIsValid()){ - if(SendIDelays(modules[module_index]->GetBottomLeftAddress(),chip_pos%2==0,0xffffffff,ndelay_units)){ - if(module_index!=0) modules[module_index]->SetBottomIDelay(chip_pos,ndelay_units); - else{ - for(unsigned int i=0;iSetTopIDelay(chip_pos,ndelay_units); - for(unsigned int i=0;iSetBottomIDelay(chip_pos,ndelay_units); - } - }else{ - cout<<"Error could not set idelay module number "<TopAddressIsValid()){ - if(SendIDelays(modules[module_index]->GetTopRightAddress(),chip_pos%2==0,0xffffffff,ndelay_units)){ - if(module_index!=0) modules[module_index]->SetTopIDelay(chip_pos,ndelay_units); - else for(unsigned int i=0;iSetTopIDelay(chip_pos,ndelay_units); - }else{ - cout<<"Error could not set idelay module number "<BottomAddressIsValid()){ - if(SendIDelays(modules[module_index]->GetBottomRightAddress(),chip_pos%2==0,0xffffffff,ndelay_units)){ - if(module_index!=0) modules[module_index]->SetBottomIDelay(chip_pos,ndelay_units); - else for(unsigned int i=0;iSetBottomIDelay(chip_pos,ndelay_units); - }else{ - cout<<"Error could not set idelay module number "<0x3ff) ndelay_units=0x3ff; - // this is global - unsigned int delay_data_valid_nclks = 15 - ((ndelay_units&0x3c0)>>6); //data valid delay upto 15 clks - ndelay_units &= 0x3f; - - unsigned int set_left_delay_channels = chip_lr ? channels:0; - unsigned int set_right_delay_channels = chip_lr ? 0:channels; - - cout<<"\tSetting delays of "; - if(set_left_delay_channels!=0) cout<<"left chips of dst_num "<vmax) return 0; - digital = int(((value-vmin)/(vmax-vmin))*(nsteps-1) + 0.5); - return 1; -} - -float FebControl::DACToVoltage(unsigned int digital,unsigned int nsteps,float vmin,float vmax){ - return vmin+(vmax-vmin)*digital/(nsteps-1); -} - - -bool FebControl::SetHighVoltage(float value){ - return SetHighVoltage(0,value); -} - -bool FebControl::SetHighVoltage(unsigned int module_num,float value){ - unsigned int module_index=0; - if(!GetModuleIndex(module_num,module_index)||!modules[module_index]->TopAddressIsValid()){ - cout<<"Error could not set high voltage module number "<GetTopRightAddress(),value)) return 0; - - if(module_index!=0) modules[module_index]->SetHighVoltage(value); - else for(unsigned int i=0;iSetHighVoltage(value); - - cout<<"\tHigh voltage of dst "<GetTopRightAddress()<<" set to "<GetHighVoltage()<<"."<4095){ - cout<<"Waring: SetDac bad value, "<TopAddressIsValid()){ - if(!SendDACValue(modules[module_index]->GetTopRightAddress(),dac_ch,v)) return 0; - if(module_index!=0) modules[module_index]->SetTopDACValue(dac_ch,v); - else for(unsigned int i=0;iSetTopDACValue(dac_ch,v); - } - - if(bottom&&modules[module_index]->BottomAddressIsValid()){ - if(!SendDACValue(modules[module_index]->GetBottomRightAddress(),dac_ch,v)) return 0; - if(module_index!=0) modules[module_index]->SetBottomDACValue(dac_ch,v); - else for(unsigned int i=0;iSetBottomDACValue(dac_ch,v); - } - - return 1; -} - -bool FebControl::GetDAC(std::string s, int& ret_value, bool voltage_mv){ - - unsigned int module_index, dac_ch; - bool top, bottom; - if(!DecodeDACString(s,module_index,top,bottom,dac_ch)) return 0; - - ret_value = top ? modules[module_index]->GetTopDACValue(dac_ch) : modules[module_index]->GetBottomDACValue(dac_ch); - - if(voltage_mv) ret_value = DACToVoltage(ret_value,4096,0,2048); - - return 1; -} - - -bool FebControl::GetDACName(unsigned int dac_num, std::string &s){ - if(dac_num>=Module::ndacs){ - cout<<"Warning: FebControl::GetDACName index out of range, "<15){ - cout<<"Warning invalid ch for SetDAC."<>3)<<((7-i)*4);//upper - trimbits_to_load_r[offset+chip_sc] |= ( 0x7 & trimbits[row_set*16480+super_column_start_position_r+i])<<((7-i)*4);//low - trimbits_to_load_r[offset+chip_sc+32] |= ((0x38 & trimbits[row_set*16480+super_column_start_position_r+i])>>3)<<((7-i)*4);//upper -/* - trimbits_to_load_l[offset+chip_sc] |= ( 0x7 & trimbits[263679 - (row_set*16480+super_column_start_position_l+i)])<<((7-i)*4);//low - trimbits_to_load_l[offset+chip_sc+32] |= ((0x38 & trimbits[263679 - (row_set*16480+super_column_start_position_l+i)])>>3)<<((7-i)*4);//upper - trimbits_to_load_r[offset+chip_sc] |= ( 0x7 & trimbits[263679 - (row_set*16480+super_column_start_position_r+i)])<<((7-i)*4);//low - trimbits_to_load_r[offset+chip_sc+32] |= ((0x38 & trimbits[263679 - (row_set*16480+super_column_start_position_r+i)])>>3)<<((7-i)*4);//upper - */ - - } // end column loop i - } //end supercolumn loop sc - } //end row loop - -/* - if(!WriteMemory(modules[0]->GetTopLeftAddress(),0,0,1024,trimbits_to_load_r)||!WriteMemory(modules[0]->GetTopRightAddress(),0,0,1024,trimbits_to_load_l)||!StartDAQOnlyNWaitForFinish()){ - cout <<" some errror!"<< endl; - return 0; - } -*/ - if(!WriteMemory(modules[0]->GetTopLeftAddress(),0,0,1023,trimbits_to_load_r)||!WriteMemory(modules[0]->GetTopRightAddress(),0,0,1023,trimbits_to_load_l)||!StartDAQOnlyNWaitForFinish()){ - cout <<" some errror!"<< endl; - return 0; - } - - } //end row_set loop (groups of 16 rows) - } // end l_r loop - memcpy(last_downloaded_trimbits,trimbits,trimbit_size*sizeof(unsigned char)); - return SetStaticBits(); //send the static bits -} - - -unsigned int* FebControl::GetTrimbits(){ - return last_downloaded_trimbits; -} - - - - -unsigned int FebControl::AddressToAll(){ - if(modules.size()==0) return 0; - return modules[0]->GetTopLeftAddress()|modules[0]->GetTopRightAddress(); -} - -bool FebControl::SetCommandRegister(unsigned int cmd){ - return WriteRegister(AddressToAll(),DAQ_REG_CHIP_CMDS,cmd); -} - - -bool FebControl::GetDAQStatusRegister(unsigned int dst_address, unsigned int &ret_status){ - - if(!ReadRegister(dst_address,DAQ_REG_STATUS,ret_status)){ - cout<<"Error: reading status register."<> 16; - return 1; -} - - -bool FebControl::StartDAQOnlyNWaitForFinish(int sleep_time_us){ - if(!WriteRegister(AddressToAll(),DAQ_REG_CTRL,0)||!WriteRegister(AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_START)){ - cout<<"Warning: could not start."<GetTopRightAddress(),status_reg_r))) - return 0; - if(status_reg_r&DAQ_STATUS_DAQ_RUNNING) return 1; - - /* - if(!(GetDAQStatusRegister(modules[i]->GetTopLeftAddress(),status_reg_r)&&GetDAQStatusRegister(modules[i]->GetTopRightAddress(),status_reg_l))){ - for(int i=0;i<2;i++) cout<<"Waring trouble reading status register. Returning zero to avoid inifite loops, this could cause trouble!"<full,1->half,2->quarter or 3->super_slow - acquireNReadoutMode &= (~DAQ_CHIP_CONTROLLER_SUPER_SLOW_SPEED); - if(readout_speed==1){ - acquireNReadoutMode |= DAQ_CHIP_CONTROLLER_HALF_SPEED; - cout<<"Everything at half speed, ie. reading with 50 MHz main clk (half speed) ...."<parallel,1->non-parallel,2-> safe_mode - acquireNReadoutMode &= (~DAQ_NEXPOSURERS_PARALLEL_MODE); - if(readout_mode==1){ - acquireNReadoutMode |= DAQ_NEXPOSURERS_NORMAL_NONPARALLEL_MODE; - cout<<"Readout mode set to normal non-parallel readout mode ... "< internal exposure time and period, - //"01"-> external acquistion start and internal exposure time and period, - //"10"-> external start trigger and internal exposure time, - //"11"-> external triggered start and stop of exposures - triggerMode = (~DAQ_NEXPOSURERS_EXTERNAL_IMAGE_START_AND_STOP); - - if(trigger_mode == 1){ - triggerMode = DAQ_NEXPOSURERS_EXTERNAL_ACQUISITION_START; - cout<<"Trigger mode: external start of acquisition sequence, internal exposure length and period."<(pow(2,29)-1)*pow(10,7)){ - float max_time = 10e-9*(pow(2,28)-1)*pow(10,7); - cout<<"Warning: time exceeds ("<pow(2,29)-1){ power_of_ten++; n_clk_cycles = round(n_clk_cycles/10.0);} - decoded_time = int(n_clk_cycles)<<3 | int(power_of_ten); - } - - return decoded_time; -} - -bool FebControl::ResetChipCompletely(){ - if(!SetCommandRegister(DAQ_RESET_COMPLETELY) || !StartDAQOnlyNWaitForFinish()){ - cout<<"Warning: could not ResetChipCompletely()."<h_addr,(char *)&serv_addr.sin_addr.s_addr,server->h_length); - serv_addr.sin_port = htons(port); - - return 1; -} - -int FebControl::WriteNRead(char* message, int length, int max_length){ - - int sockfd = socket(AF_INET, SOCK_STREAM, 0); - if(sockfd <0){ - fprintf(stderr,"ERROR opening socket\n"); - return 0; - } - - if(connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0){ - fprintf(stderr,"ERROR connecting\n"); - return 0; - } - - int n = write(sockfd,message,length); - if(n<0) printf("ERROR writing to socket"); - - length = read(sockfd,message,max_length); - if(length<0) printf("ERROR reading to socket"); - - close(sockfd); - - return length; -} - - -bool FebControl::StartAcquisition(){ - - static unsigned int reg_nums[20]; - static unsigned int reg_vals[20]; - - PrintAcquisitionSetup(); - - // if(!Reset()||!ResetDataStream()){ - if(!Reset()){ - cout<<"Trouble reseting daq or data stream..."< -#include -//#include -//#include -//#include -//#include - -#include "xparameters.h" - -#include "FebInterface.h" - -using namespace std; - -FebInterface::FebInterface(){ - - nfebs = 0; - feb_numb = 0; - - send_ndata = 0; - send_buffer_size = 1026; - send_data_raw = new unsigned int [send_buffer_size+1]; - send_data = &send_data_raw[1]; - - recv_ndata = 0; - recv_buffer_size = 1026; - recv_data_raw = new unsigned int [recv_buffer_size+1]; - recv_data = &recv_data_raw[1]; - - ll = new LocalLinkInterface(XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_RIGHT_BASEADDR); - -} - -FebInterface::~FebInterface(){ - delete ll; - if(feb_numb) delete [] feb_numb; - delete [] send_data_raw; - delete [] recv_data_raw; -} - -void FebInterface::SendCompleteList(unsigned int n,unsigned int* list){ - if(feb_numb) delete [] feb_numb; - nfebs = n; - feb_numb = new unsigned int [n]; - for(unsigned int i=0;i0xfff) return 0; - - send_data_raw[0] = 0x8fff0000; - if(ll->Write(4,send_data_raw)!=4) return 0; - - send_data_raw[0] = 0x90000000 | (ch<<16); - if(ll->Write(4,send_data_raw)!=4) return 0; - - send_data_raw[0] = 0xc0000000; - return ((send_ndata+1)*4==ll->Write((send_ndata+1)*4,send_data_raw)); -} - -bool FebInterface::ReadFrom(unsigned int ch, unsigned int ntrys){ - if(ch>=0xfff) return 0; - - recv_data_raw[0] = 0xa0000000 | (ch<<16); - ll->Write(4,recv_data_raw); - usleep(20); - - recv_ndata=-1; - for(unsigned int t=0;tRead(recv_buffer_size*4,recv_data_raw)/4)>0){ - recv_ndata--; - break; - } - usleep(1000); - } - - return (recv_ndata>=0); -} - - - -bool FebInterface::SetByteOrder(){ - - send_data_raw[0] = 0x8fff0000; - if(ll->Write(4,send_data_raw)!=4) return 0; - - send_ndata = 2; - send_data[0] = 0; - send_data[1] = 0; - - unsigned int dst = 0xff; - for(unsigned int i=0;isend_buffer_size-2) return 0; - - send_ndata = nreads+2; - send_data[0] = 0x20000000 | nreads << 14; - - for(unsigned int i=0;isend_buffer_size-2) return 0; - - //cout<<"Write register : "<send_buffer_size-2) {cout<<"error herer: nwrites:"< write to memory, nwrites, mem number, start address - send_data[nwrites+1] = 0; - for(unsigned int i=0;i -#include -#include -#include -#include // std::remove_if - -#include -#include -#include -#include -#include - -#include "FebControl.h" -#include "slsDetectorServer_defs.h" //include port number - -using namespace std; - -enum cmd_string {evNotFound, - evReinitialize,evReset, - - evSetInputDelays, - evSetDACValue,evGetDACValue,evSetDACVoltage,evGetDACVoltage,evSetHighVoltage,//evGetHighVoltage, - - evSetTrimBits, - evSetAllTrimBits, - evGetTrimBits, - //evLoadTrimBitFile, - - evSetBitMode, - evSetPhotonEnergy, - // evSetPhotonEnergyCalibrationParameters,evActivateRateCorrection,evDeactivateRateCorrection,evSetRateCorrectionTau, - - evSetReadoutSpeed,evSetReadoutMode, - - //temp solution - // evNotFound1,evNotFound2,evNotFound3, - - evSetNumberOfExposures,evSetExposureTime,evSetExposurePeriod, - // evSetTriggerPolarityToPositive,evSetTriggerPolarityToNegative, - evSetTriggerMode, - evSetExternalGating, - evStartAcquisition,evStopAcquisition,evIsDaqStillRunning, - evWaitUntilDaqFinished, - evExitServer -}; - -map enum_map; - -void init(){ - - enum_map["reinitialize"] = evReinitialize; - enum_map["reset"] = evReset; - enum_map["setinputdelays"] = evSetInputDelays; - enum_map["setdacvalue"] = evSetDACValue; - enum_map["getdacvalue"] = evGetDACValue; - enum_map["setdacvoltage"] = evSetDACVoltage; - enum_map["getdacvoltage"] = evGetDACVoltage; - enum_map["sethighvoltage"] = evSetHighVoltage; - enum_map["settrimbits"] = evSetTrimBits; - enum_map["setalltrimbits"] = evSetAllTrimBits; - enum_map["gettrimbits"] = evGetTrimBits; - // enum_map["loadtrimbitfile"] = evLoadTrimBitFile; - enum_map["setbitmode"] = evSetBitMode; - enum_map["setphotonenergy"] = evSetPhotonEnergy; - // enum_map["setphotonenergycalibrationparameters"] = evSetPhotonEnergyCalibrationParameters; - // enum_map["activateratecorrection"] = evActivateRateCorrection; - // enum_map["deactivateratecorrection"] = evDeactivateRateCorrection; - // enum_map["setratecorrectiontau"] = evSetRateCorrectionTau; - enum_map["setreadoutspeed"] = evSetReadoutSpeed; - enum_map["setreadoutmode"] = evSetReadoutMode; - enum_map["setnumberofexposures"] = evSetNumberOfExposures; - enum_map["setexposuretime"] = evSetExposureTime; - enum_map["setexposureperiod"] = evSetExposurePeriod; - // enum_map["settriggerpolaritytopositive"] = evSetTriggerPolarityToPositive; - // enum_map["settriggerpolaritytonegative"] = evSetTriggerPolarityToNegative; - enum_map["settriggermode"] = evSetTriggerMode; - enum_map["setexternalgating"] = evSetExternalGating; - enum_map["startacquisition"] = evStartAcquisition; - enum_map["stopacquisition"] = evStopAcquisition; - enum_map["isdaqstillrunning"] = evIsDaqStillRunning; - enum_map["waituntildaqfinished"] = evWaitUntilDaqFinished; - enum_map["exitserver"] = evExitServer; -} - -int server_list_s; -int server_conn_s; -int AccpetConnectionAndWaitForData(char* buffer, int maxlength); -bool WriteNClose(const char* buffer, int length); -bool SetupListenSocket(unsigned short int port); - - -string LowerCase(string str); -string GetNextString(string str,bool start_from_beginning=0); -void AddNumber(string& str, int n, int location=-1, bool space_after=0);//-1 means append -void AddNumber(string& str, float v, int location=-1, bool space_after=0);//-1 means append - -int main(int argc, char* argv[]){ - cout< "<0){ - int ret_parameter = 0; - return_start_pos = return_message.length(); - - switch(enum_map.find(LowerCase(cmd))->second){ - - case evReinitialize : - if(feb_controler->Init()){ - return_message.append("\tExecuted: Reinitialize\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: Reinitialize\n"); - ret_val = 1; - } - break; - - case evReset : - if(feb_controler->Reset()){ - return_message.append("\tExecuted: Reset\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: Reset\n"); - ret_val = 1; - } - break; - - - - case evSetInputDelays : - tmp_str[0] = GetNextString(data); - n[0] = atoi(tmp_str[0].data()); - - if(tmp_str[0].length()>0&&feb_controler->SetIDelays(0,n[0])){ - return_message.append("\tExecuted: SetInputDelays "); AddNumber(return_message,n[0]); return_message.append("\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: SetInputDelays \n"); - ret_val = 1; - } - break; - - - - case evSetDACValue : - tmp_str[0] = GetNextString(data); - tmp_str[1] = GetNextString(data); - n[0] = atoi(tmp_str[1].data()); - - if(tmp_str[0].length()>0&&tmp_str[1].length()>0&&feb_controler->SetDAC(tmp_str[0],n[0])){ - return_message.append("\tExecuted: SetDACValue "); return_message.append(tmp_str[0]+" "); AddNumber(return_message,n[0]); return_message.append("\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: SetDACValue \n"); - ret_val = 1; - } - break; - - case evGetDACValue : - tmp_str[0] = GetNextString(data); - - if(tmp_str[0].length()>0&&feb_controler->GetDAC(tmp_str[0],ret_parameter)){ - return_message.append("\tExecuted: GetDACValue "); return_message.append(tmp_str[0]+" -> ");AddNumber(return_message,ret_parameter); return_message.append("\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: GetDACValue \n"); - ret_val = 1; - } - break; - - case evSetDACVoltage : - tmp_str[0] = GetNextString(data); - tmp_str[1] = GetNextString(data); - n[0] = atoi(tmp_str[1].data()); - - if(tmp_str[0].length()>0&&tmp_str[1].length()>0&&feb_controler->SetDAC(tmp_str[0],n[0],1)){ - return_message.append("\tExecuted: SetDACVoltage "); return_message.append(tmp_str[0]+" "); AddNumber(return_message,n[0]); return_message.append("\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: SetDACVoltage \n"); - ret_val = 1; - } - break; - - case evGetDACVoltage : - tmp_str[0] = GetNextString(data); - - if(tmp_str[0].length()>0&&feb_controler->GetDAC(tmp_str[0],ret_parameter,1)){ - return_message.append("\tExecuted: GetDACVoltage "); return_message.append(tmp_str[0]+" -> ");AddNumber(return_message,ret_parameter); return_message.append(" mV\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: GetDACVoltage \n"); - ret_val = 1; - } - break; - - case evSetHighVoltage : - tmp_str[0] = GetNextString(data); - v[0] = atof(tmp_str[0].data()); - - if(tmp_str[0].length()>0&&feb_controler->SetHighVoltage(v[0])){ - return_message.append("\tExecuted: SetHighVoltage "); AddNumber(return_message,v[0]); return_message.append("\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: SetHighVoltage \n"); - ret_val = 1; - } - break; - - case evSetTrimBits : - tmp_str[0] = GetNextString(data); - if(feb_controler->LoadTrimbitFile()){ - /* if(1){*/ - /*tmp_str[0] = GetNextString(data); - feb_controler->SetTrimbits(0,(unsigned char*)(tmp_str[0].c_str()));*/ - return_message.append("\tExecuted: SetTrimBits\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: SetTrimBits \n"); - ret_val = 1; - } - break; - - case evSetAllTrimBits : - tmp_str[0] = GetNextString(data); - n[0] = atoi(tmp_str[0].data()); - if(feb_controler->SaveAllTrimbitsTo(n[0])){ - /*feb_controler->SetTrimbits(0,(unsigned char*)(tmp_str[0].c_str()));*/ - /*if(1){*/ - return_message.append("\tExecuted: SetAllTrimBits\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: SetAllTrimBits \n"); - ret_val = 1; - } - break; - - - case evGetTrimBits : - if(feb_controler->SaveTrimbitFile()){ - /*if(1){*/ - /*tmp_str[0] = GetNextString(data); - feb_controler->GetTrimbits();*/ - return_message.append("\tExecuted: GetTrimBits\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: GetTrimBits \n"); - ret_val = 1; - } - break; - - - // case evLoadTrimBitFile : - - case evSetBitMode : - tmp_str[0] = GetNextString(data); - n[0] = atoi(tmp_str[0].data()); - - if(tmp_str[0].length()>0&&feb_controler->SetDynamicRange(n[0])){ - return_message.append("\tExecuted: SetBitMode "); AddNumber(return_message,n[0]); return_message.append("\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: SetBitMode \n"); - ret_val = 1; - } - break; - - case evSetPhotonEnergy : - tmp_str[0] = GetNextString(data); - n[0] = atoi(tmp_str[0].data()); - if(tmp_str[0].length()>0&&feb_controler->SetPhotonEnergy(n[0])){ - return_message.append("\tExecuted: SetPhotonEnergy "); AddNumber(return_message,n[0]); return_message.append("\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: SetPhotonEnergy \n"); - ret_val = 1; - } - break; - - // case evSetPhotonEnergyCalibrationParameters : - // case evActivateRateCorrection : - // case evDeactivateRateCorrection : - // case evSetRateCorrectionTau : - - - case evSetReadoutSpeed : - tmp_str[0] = GetNextString(data); - n[0] = atoi(tmp_str[0].data()); - if(tmp_str[0].length()>0&&feb_controler->SetReadoutSpeed(n[0])){ - return_message.append("\tExecuted: SetReadoutSpeed "); AddNumber(return_message,n[0]); return_message.append("\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: SetReadoutSpeed \n"); - ret_val = 1; - } - break; - - case evSetReadoutMode : - tmp_str[0] = GetNextString(data); - n[0] = atoi(tmp_str[0].data()); - if(tmp_str[0].length()>0&&feb_controler->SetReadoutMode(n[0])){ - return_message.append("\tExecuted: SetReadoutMode "); AddNumber(return_message,n[0]); return_message.append("\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: SetReadoutMode parallel,1->non-parallel,2-> safe_mode>\n"); - ret_val = 1; - } - break; - - case evSetNumberOfExposures : - tmp_str[0] = GetNextString(data); - n[0] = atoi(tmp_str[0].data()); - if(tmp_str[0].length()>0&&feb_controler->SetNExposures(n[0])){ - return_message.append("\tExecuted: SetNumberOfExposures "); AddNumber(return_message,n[0]); return_message.append("\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: SetNumberOfExposures \n"); - ret_val = 1; - } - break; - - case evSetExposureTime : - tmp_str[0] = GetNextString(data); - v[0] = atof(tmp_str[0].data()); - if(tmp_str[0].length()>0&&feb_controler->SetExposureTime(v[0])){ - return_message.append("\tExecuted: SetExposureTime "); AddNumber(return_message,v[0]); return_message.append("\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: SetExposureTime \n"); - ret_val = 1; - } - break; - - case evSetExposurePeriod : - tmp_str[0] = GetNextString(data); - v[0] = atof(tmp_str[0].data()); - if(tmp_str[0].length()>0&&feb_controler->SetExposurePeriod(v[0])){ - return_message.append("\tExecuted: SetExposurePeriod "); AddNumber(return_message,v[0]); return_message.append("\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: SetExposurePeriod \n"); - ret_val = 1; - } - break; - // case evSetTriggerPolarityToPositive : - // case evSetTriggerPolarityToNegative : - case evSetTriggerMode : - tmp_str[0] = GetNextString(data); - n[0] = atoi(tmp_str[0].data()); - if(tmp_str[0].length()>0&&feb_controler->SetTriggerMode(n[0])){ - return_message.append("\tExecuted: SetTriggerMode "); AddNumber(return_message,n[0]); return_message.append("\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: SetTriggerMode \n"); - ret_val = 1; - } - break; - - case evSetExternalGating : - tmp_str[0] = GetNextString(data); - tmp_str[1] = GetNextString(data); - n[0] = atoi(tmp_str[0].data()); - n[1] = atoi(tmp_str[1].data()); - if(tmp_str[0].length()<1 || tmp_str[1].length()<1 || (n[0]!=0&&n[0]!=1) || (n[1]!=0&&n[1]!=1)){ - return_message.append("\tError executing: setexternalgating \n"); - ret_val = 1; - } - feb_controler->SetExternalEnableMode(n[0],n[1]); - ret_val = 0; - break; - - case evStartAcquisition : - if(feb_controler->StartAcquisition()){ - return_message.append("\tExecuted: StartAcquisition\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: StartAcquisition\n"); - ret_val = 1; - } - break; - - case evStopAcquisition : - if(feb_controler->StopAcquisition()){ - return_message.append("\tExecuted: StopAcquisition\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: StopAcquisition\n"); - ret_val = 1; - } - break; - - - case evIsDaqStillRunning : - return_message.append("\tExecuted: evIsDaqStillRunning\n"); - ret_parameter = feb_controler->AcquisitionInProgress(); - ret_val = 0; - break; - - - case evWaitUntilDaqFinished : - if(feb_controler->WaitForFinishedFlag()){ - return_message.append("\tExecuted: WaitUntilDaqFinished\n"); - ret_val = 0; - }else{ - return_message.append("\tError executing: WaitUntilDaqFinished\n"); - ret_val = 1; - } - break; - - - case evExitServer : - return_message.append("\tExiting Server ....\n"); - stop = 1; - ret_val = -200; - break; - - - default : - return_message.append("\tWarning command \""); - return_message.append(cmd); - return_message.append("\" not found.\n"); - return_message.append("\t\tValid commands: "); - map::iterator it = enum_map.begin(); - while(it!=enum_map.end()){ - return_message.append((it++)->first); - return_message.append(" "); - } - - ret_val=-100; - break; - } - - // return_message.append("\n"); - //AddNumber(return_message,ret_parameter,return_start_pos); - AddNumber(return_message,ret_val,return_start_pos,1); - AddNumber(return_message,ret_parameter,0,1); - if(ret_val!=0) break; - - cmd = GetNextString(data); - } - /*return_message.append("\n\n\n");*/ - - AddNumber(return_message,ret_val,0,1); - cout<0) return sub; - } - - return ""; -} - - -void AddNumber(string& str, int n, int location, bool space_after){ - static char retval_st[100]; - if(space_after) sprintf(retval_st,"%d ",n); - else sprintf(retval_st,"%d",n); - - if(location<0) str.append(retval_st); - else str.insert(location,retval_st); -} - -void AddNumber(string& str, float v, int location, bool space_after){ - static char retval_st[100]; - if(space_after) sprintf(retval_st,"%f ",v); - else sprintf(retval_st,"%f",v); - - if(location<0) str.append(retval_st); - else str.insert(location,retval_st); -} - - -bool SetupListenSocket(unsigned short int port){ - server_list_s=0; - server_conn_s=0; - - if((server_list_s = socket(AF_INET, SOCK_STREAM, 0))<0) return 0; - - struct sockaddr_in servaddr; /* socket address structure */ - memset(&servaddr, 0, sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = htonl(INADDR_ANY); - servaddr.sin_port = htons(port); - - if(bind(server_list_s,(struct sockaddr *) &servaddr,sizeof(servaddr))<0) return 0; - - if(listen(server_list_s,32) < 0){ // 1024 /* Backlog for listen() */ - return 0; - } - - return 1; -} - - -int AccpetConnectionAndWaitForData(char* buffer, int maxlength){ - if(server_list_s==0||maxlength<=0) return 0; - - if((server_conn_s = accept(server_list_s,NULL,NULL))< 0) return 0; - - int nread = read(server_conn_s,buffer,maxlength-1); - - if(nread<0) return 0; - - buffer[nread]='\0'; - return nread; -} - -bool WriteNClose(const char* buffer, int length){ - if(server_conn_s==0||length<=0) return 0; - - int nsent = write(server_conn_s,buffer,length); - if(close(server_conn_s)<0) return 0; - - server_conn_s=0; - return (nsent==length); -} - - - diff --git a/slsDetectorSoftware/eigerDetectorServer/HardwareIO.cxx b/slsDetectorSoftware/eigerDetectorServer/HardwareIO.cxx deleted file mode 100644 index 3c6cff40b..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/HardwareIO.cxx +++ /dev/null @@ -1,87 +0,0 @@ - -//Class initially from Gerd and was called mmap_test.c -//return reversed 1 means good, 0 means failed - - -//#include -//#include -//#include -//#include -//#include - -#include "HardwareIO.h" - -xfs_u8 HardwareIO::xfs_in8(xfs_u32 InAddress) -{ - /* read the contents of the I/O location and then synchronize the I/O - * such that the I/O operation completes before proceeding on - */ - - xfs_u8 IoContents; - __asm__ volatile ("eieio; lbz %0,0(%1)":"=r" (IoContents):"b" - (InAddress)); - return IoContents; -} - -/*****************************************************************************/ - -xfs_u16 HardwareIO::xfs_in16(xfs_u32 InAddress) -{ - /* read the contents of the I/O location and then synchronize the I/O - * such that the I/O operation completes before proceeding on - */ - - xfs_u16 IoContents; - __asm__ volatile ("eieio; lhz %0,0(%1)":"=r" (IoContents):"b" - (InAddress)); - return IoContents; -} - -/*****************************************************************************/ - -xfs_u32 HardwareIO::xfs_in32(xfs_u32 InAddress) -{ - /* read the contents of the I/O location and then synchronize the I/O - * such that the I/O operation completes before proceeding on - */ - - xfs_u32 IoContents; - __asm__ volatile ("eieio; lwz %0,0(%1)":"=r" (IoContents):"b" - (InAddress)); - return IoContents; -} - -/*****************************************************************************/ - -void HardwareIO::xfs_out8(xfs_u32 OutAddress, xfs_u8 Value) -{ - /* write the contents of the I/O location and then synchronize the I/O - * such that the I/O operation completes before proceeding on - */ - - __asm__ volatile ("stb %0,0(%1); eieio"::"r" (Value), "b"(OutAddress)); -} - -/*****************************************************************************/ -void HardwareIO::xfs_out16(xfs_u32 OutAddress, xfs_u16 Value) -{ - /* write the contents of the I/O location and then synchronize the I/O - * such that the I/O operation completes before proceeding on - */ - - __asm__ volatile ("sth %0,0(%1); eieio"::"r" (Value), "b"(OutAddress)); -} - -/*****************************************************************************/ - -void HardwareIO::xfs_out32(xfs_u32 OutAddress, xfs_u32 Value) -{ - /* write the contents of the I/O location and then synchronize the I/O - * such that the I/O operation completes before proceeding on - */ - - __asm__ volatile ("stw %0,0(%1); eieio"::"r" (Value), "b"(OutAddress)); -} - - - diff --git a/slsDetectorSoftware/eigerDetectorServer/LocalLinkInterface.cxx b/slsDetectorSoftware/eigerDetectorServer/LocalLinkInterface.cxx deleted file mode 100644 index a8b3311ac..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/LocalLinkInterface.cxx +++ /dev/null @@ -1,277 +0,0 @@ - -//Class initially from Gerd and was called mmap_test.c -//return reversed 1 means good, 0 means failed - - -#include -#include -//#include - - -#include "HardwareMMappingDefs.h" - -#include "LocalLinkInterface.h" - - - -LocalLinkInterface::LocalLinkInterface(unsigned int ll_fifo_badr){ - // printf("\n v 1 \n"); - printf("Initialize PLB LL FIFOs\n"); - ll_fifo_base=0; - ll_fifo_ctrl_reg=0; - if(Init(ll_fifo_badr)){ - Reset(); - printf("\tFIFO Status : 0x%08x\n",StatusVector()); - }else printf("\tError LocalLink Mappping : 0x%08x\n",ll_fifo_badr); - - printf("\n\n"); -} - -LocalLinkInterface::~LocalLinkInterface(){}; - -LocalLinkInterface::LocalLinkInterface(){ - printf("Initialize new memory\n"); - } - -int LocalLinkInterface::InitNewMemory (unsigned int addr, int ifg){ - unsigned int CSP0BASE; - int fd; - - /*fd = open("/dev/mem", O_RDWR | O_SYNC, 0); - if (fd == -1) { - printf("\nCan't find /dev/mem!\n"); - return 0; - } - printf("/dev/mem opened\n"); - - - CSP0BASE = (u_int32_t)mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd, addr); - if (CSP0BASE == (u_int32_t)MAP_FAILED) { - printf("\nCan't map memmory area!!\n"); - return 0; - } - printf("CSP0 mapped\n"); - - - volatile u_int8_t *ptr1; - - ptr1=(u_int8_t*)(CSP0BASE); - - printf("pointer val=%x\n",(void*)ptr1); - - printf("ifg_control=%02x\n",*ptr1); - - *ptr1=ifg; - - printf("ifg_control new=%02x\n",*ptr1); - - close(fd); -*/ - return 1; -} - - - -bool LocalLinkInterface::Init(unsigned int ll_fifo_badr){ - int fd; - void *plb_ll_fifo_ptr; - - if ((fd=open("/dev/mem", O_RDWR)) < 0){ - fprintf(stderr, "Could not open /dev/mem\n"); - return 0; - } - - plb_ll_fifo_ptr = mmap(0, getpagesize(), PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, ll_fifo_badr); - close(fd); - - if (plb_ll_fifo_ptr == MAP_FAILED){ - perror ("mmap"); - return 0; - } - - ll_fifo_base = (xfs_u32) plb_ll_fifo_ptr; - ll_fifo_ctrl_reg = 0; - - return 1; -} - - - -bool LocalLinkInterface::Reset(){ - return Reset(PLB_LL_FIFO_CTRL_RESET_STD); -} - -bool LocalLinkInterface::Reset(unsigned int rst_mask){ - ll_fifo_ctrl_reg |= rst_mask; - printf("\tCTRL Register bits: 0x%08x\n",ll_fifo_ctrl_reg); - - xfs_out32(ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll_fifo_ctrl_reg); - xfs_out32(ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll_fifo_ctrl_reg); - xfs_out32(ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll_fifo_ctrl_reg); - xfs_out32(ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll_fifo_ctrl_reg); - - ll_fifo_ctrl_reg &= (~rst_mask); - - xfs_out32(ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll_fifo_ctrl_reg); - // printf("FIFO CTRL Address: 0x%08x\n FIFO CTRL Register: 0x%08x\n",PLB_LL_FIFO_REG_CTRL,plb_ll_fifo[PLB_LL_FIFO_REG_CTRL]); - return 1; -} - - - -unsigned int LocalLinkInterface::StatusVector(){ - return xfs_in32(ll_fifo_base+4*PLB_LL_FIFO_REG_STATUS); -} - -int LocalLinkInterface::Write(unsigned int buffer_len, void *buffer){ - // note: buffer must be word (4 byte) aligned - // frame_len in byte - int vacancy=0; - int i; - int words_send = 0; - int last_word; - unsigned int *word_ptr; - unsigned int fifo_ctrl; - xfs_u32 status; - - if (buffer_len < 1) return -1; - - last_word = (buffer_len-1)/4; - word_ptr = (unsigned int *)buffer; - - while (words_send <= last_word) - { - while (!vacancy)//wait for Fifo to be empty again - { - status = xfs_in32(ll_fifo_base+4*PLB_LL_FIFO_REG_STATUS); - if((status & PLB_LL_FIFO_STATUS_ALMOSTFULL) == 0) vacancy = 1; - } - - //Just to know: #define PLB_LL_FIFO_ALMOST_FULL_THRESHOLD_WORDS 100 - for (i=0; ((i>>> SOF\n\r"); - buffer_ptr = 0; - sof = 1; - } - - fifo_val = xfs_in32(ll_fifo_base+4*PLB_LL_FIFO_REG_FIFO); //read from fifo - - if ((buffer_ptr > 0) || sof) - { - if ( (buffer_len >> 2) > buffer_ptr) - { - word_ptr[buffer_ptr++] = fifo_val; //write to buffer - } - else - { - buffer_ptr = 0; - return -2; // buffer overflow - } - - if (status & PLB_LL_FIFO_STATUS_LL_EOF) - { - len = (buffer_ptr << 2) -3 + ( (status & PLB_LL_FIFO_STATUS_LL_REM)>>PLB_LL_FIFO_STATUS_LL_REM_SHIFT ); -// printf(">>>>status=0x%08x EOF len = %d \n\r\n\r",status, len); - buffer_ptr = 0; - return len; - } - - } - } - } - while(!(status & PLB_LL_FIFO_STATUS_EMPTY)); - - return 0; -} - -bool LocalLinkInterface::ctrl_reg_write_mask(unsigned int mask, unsigned int val){ - // printf("Fifo CTRL Reg(1): 0x%08x\n",plb_ll_fifo_ctrl_reg); - ll_fifo_ctrl_reg &= (~mask); - //printf("Fifo CTRL Reg(2): 0x%08x\n",plb_ll_fifo_ctrl_reg); - ll_fifo_ctrl_reg |= ( mask & val); -// printf("Fifo CTRL Reg: 0x%08x\n",plb_ll_fifo_ctrl_reg); - xfs_out32(ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll_fifo_ctrl_reg); -// printf("Fifo STAT Reg: 0x%08x\n", plb_ll_fifo[PLB_LL_FIFO_REG_STATUS]); - return 1; -} - - -int LocalLinkInterface::Test(unsigned int buffer_len, void *buffer){ - - int len; - unsigned int rec_buff_len = 4096; - unsigned int rec_buffer[4097]; - - - Write(buffer_len,buffer); - usleep(10000); - - do{ - len = Read(rec_buff_len,rec_buffer); - printf("receive length: %i\n",len); - - if (len > 0){ - rec_buffer[len]=0; - printf((char*) rec_buffer); - printf("\n"); - } - } while(len > 0); - - printf("\n\n\n\n"); - return 1; -} - -void LocalLinkInterface::llfifo_print_frame(unsigned char* fbuff, int len){ - printf("\n\r----Frame of len : %d Byte\n\r",len); - for(int i=0;i - -#include "xparameters.h" - -#include "LocalLinkInterface.h" - -int main(){ - - char s[2000]; - sprintf(s,"papamama"); - - LocalLinkInterface* l0 = new LocalLinkInterface(XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_LEFT_BASEADDR); - l0->Test(8,s); - LocalLinkInterface* l1 = new LocalLinkInterface(XPAR_PLB_LL_FIFO_AURORA_RX4_TX1_LEFT_BASEADDR); - l1->Test(8,s); - LocalLinkInterface* l2 = new LocalLinkInterface(XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_RIGHT_BASEADDR); - l2->Test(8,s); - LocalLinkInterface* l3 = new LocalLinkInterface(XPAR_PLB_LL_FIFO_AURORA_RX4_TX1_RIGHT_BASEADDR); - l3->Test(8,s); - - delete l0; - delete l1; - delete l2; - delete l3; - - return 1; -} diff --git a/slsDetectorSoftware/eigerDetectorServer/Makefile b/slsDetectorSoftware/eigerDetectorServer/Makefile index 3a9cc6c59..ccf582d27 100755 --- a/slsDetectorSoftware/eigerDetectorServer/Makefile +++ b/slsDetectorSoftware/eigerDetectorServer/Makefile @@ -1,5 +1,4 @@ CC = powerpc-4xx-softfloat-gcc -CCX = powerpc-4xx-softfloat-g++ BLACKFIN_CC = bfin-uclinux-gcc CFLAGS += -Wall -DDACS_INT -DEIGERD -DSLS_DETECTOR_FUNCTION_LIST -DDACS_INT -DSTOP_SERVER #-DVERBOSEI #-DVERBOSE #-DVIRTUAL -DPCCOMPILE -DMARTIN LDLIBS += -lm -lstdc++ @@ -10,13 +9,10 @@ INSTMODE = 0777 SRC_CLNT = communication_funcs.c slsDetectorServer.c slsDetectorServer_funcs.c slsDetectorFunctionList.c FebControl.c Beb.c HardwareIO.c LocalLinkInterface.c Feb.c FebInterface.c -#SRC_CLNT2 = FebServer.cxx FebControl.cxx FebInterface.cxx LocalLinkInterface.cxx HardwareIO.cxx -#SRC_CLNT3 = BebServer.cxx Beb.cxx LocalLinkInterface.cxx HardwareIO.cxx - OBJS = $(SRC_CLNT:.c=.o) -all: clean $(PROGS) hv9m_blackfin_server #feb_debug beb_debug +all: clean $(PROGS) #hv9m_blackfin_server boot: $(OBJS) @@ -27,14 +23,7 @@ $(PROGS): $(CC) -o $@ $(SRC_CLNT) $(CFLAGS) $(LDLIBS) mv $(PROGS) $(DESTDIR) -feb_debug:$(SRC_CLNT2) - $(CCX) -o feb_debug $(SRC_CLNT2) -I. - mv feb_debug $(DESTDIR) - -beb_debug:$(SRC_CLNT3) - $(CCX) -o beb_debug $(SRC_CLNT3) -I. - mv beb_debug $(DESTDIR) - + hv9m_blackfin_server:9mhvserial_bf.c $(BLACKFIN_CC) -o hv9m_blackfin_server 9mhvserial_bf.c -Wall #-DVERBOSE mv hv9m_blackfin_server $(DESTDIR) diff --git a/slsDetectorSoftware/eigerDetectorServer/Test.cxx b/slsDetectorSoftware/eigerDetectorServer/Test.cxx deleted file mode 100644 index 8e07d609b..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/Test.cxx +++ /dev/null @@ -1,38 +0,0 @@ - -/** - * @author Ian Johnson - * @version 1.0 - */ - - -#include -#include - -#include "xparameters.h" - -#include "Feb.h" - - -using namespace std; - -int main(){ - - cout<<"\n\n\n\n\n\n\n\n\n\n"<ReadRegister(0,0,v); - feb->ReadRegister(0,0xffffffff,v); - cout<ReadRegister(1,0,v); - feb->ReadRegister(1,0xffffffff,v); - - delete feb; - - return 1; -} diff --git a/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.16.5 b/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.3.0.16.0 similarity index 75% rename from slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.16.5 rename to slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.3.0.16.0 index 9fdf4f404..9d70f306e 100755 Binary files a/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.16.5 and b/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.3.0.16.0 differ diff --git a/slsDetectorSoftware/eigerDetectorServer/bin/hv9m_blackfin_server b/slsDetectorSoftware/eigerDetectorServer/bin/hv9m_blackfin_server deleted file mode 100755 index a23826d2f..000000000 Binary files a/slsDetectorSoftware/eigerDetectorServer/bin/hv9m_blackfin_server and /dev/null differ diff --git a/slsDetectorSoftware/eigerDetectorServer/build.sh b/slsDetectorSoftware/eigerDetectorServer/build.sh deleted file mode 100755 index 876ac32f5..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/build.sh +++ /dev/null @@ -1,19 +0,0 @@ - -echo -e "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" - -. /opt/eldk-5.1/powerpc-4xx-softfloat/environment-setup-ppc440-linux - -#powerpc-4xx-softfloat-g++ -Wall -o test Test.cxx HardwareIO.cxx LocalLinkInterface.cxx Feb.cxx -I . -#powerpc-4xx-softfloat-g++ -Wall -o hardware_interface_test HardwareInterfaceTest.cxx HardwareInterface.cxx HardwareMMapping.cxx -I . - - -#powerpc-4xx-softfloat-g++ -Wall -o eiger_test EigerTest.cxx Eiger.cxx HardwareIO.cxx LocalLinkInterface.cxx Feb.cxx -I . - -powerpc-4xx-softfloat-g++ -Wall -o feb_debug FebServer.cxx FebControl.cxx FebInterface.cxx LocalLinkInterface.cxx HardwareIO.cxx -I . - -powerpc-4xx-softfloat-g++ -Wall -o beb_debug BebServer.cxx Beb.cxx LocalLinkInterface.cxx HardwareIO.cxx -I . - - -cp eiger_test rootfs_executables/. - - diff --git a/slsDetectorSoftware/eigerDetectorServer/doxy_eiger.config b/slsDetectorSoftware/eigerDetectorServer/doxy_eiger.config deleted file mode 100644 index 9f9de954a..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/doxy_eiger.config +++ /dev/null @@ -1,94 +0,0 @@ -# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in -# documentation are documented, even if no documentation was available. -# Private class members and static file members will be hidden unless -# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES - -EXTRACT_ALL = YES - -# If the EXTRACT_PRIVATE tag is set to YES all private members of a class -# will be included in the documentation. - -EXTRACT_PRIVATE = NO - - - -# If the EXTRACT_STATIC tag is set to YES all static members of a file -# will be included in the documentation. - -EXTRACT_STATIC = YES - -# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) -# defined locally in source files will be included in the documentation. -# If set to NO only classes defined in header files are included. - -EXTRACT_LOCAL_CLASSES = YES - -# This flag is only useful for Objective-C code. When set to YES local -# methods, which are defined in the implementation section but not in -# the interface are included in the documentation. -# If set to NO (the default) only methods in the interface are included. - -EXTRACT_LOCAL_METHODS = YES - -# If this flag is set to YES, the members of anonymous namespaces will be -# extracted and appear in the documentation as a namespace called -# 'anonymous_namespace{file}', where file will be replaced with the base -# name of the file that contains the anonymous namespace. By default -# anonymous namespace are hidden. - -EXTRACT_ANON_NSPACES = NO - -# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all -# undocumented members of documented classes, files or namespaces. -# If set to NO (the default) these members will be included in the -# various overviews, but no documentation section is generated. -# This option has no effect if EXTRACT_ALL is enabled. - -HIDE_UNDOC_MEMBERS = NO - -# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all -# undocumented classes that are normally visible in the class hierarchy. -# If set to NO (the default) these classes will be included in the various -# overviews. This option has no effect if EXTRACT_ALL is enabled. - -HIDE_UNDOC_CLASSES = NO - -# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all -# friend (class|struct|union) declarations. -# If set to NO (the default) these declarations will be included in the -# documentation. - -HIDE_FRIEND_COMPOUNDS = NO - -INTERNAL_DOCS = NO - -SHOW_INCLUDE_FILES = NO - -SHOW_FILES = NO - -SHOW_NAMESPACES = NO - -COMPACT_LATEX = YES - -PAPER_TYPE = a4 - -PDF_HYPERLINKS = YES - -USE_PDFLATEX = YES - -LATEX_HIDE_INDICES = YES - -PREDEFINED = __cplusplus - -HAVE_DOT = YES -CALL_GRAPH = YES -CALLER_GRAPH = YES - - -INPUT = Beb.h Eiger.h FebControl.h FebInterface.h gitInfoEiger.h HardwareIO.h LocalLinkInterface.h sls_detector_funcs.h slsDetectorServer_defs.h sls_receiver_defs.h xfs_types.h communication_funcs.h EigerRegisterDefs.h Feb.h FebRegisterDefs.h gitInfoEigerTmp.h HardwareMMappingDefs.h sls_detector_defs.h slsDetectorFunctionList.h slsDetectorServer_funcs.h sls_receiver_funcs.h xparameters.h Beb.cxx BebServer.cxx Eiger.cxx EigerTest.cxx FebControl.cxx Feb.cxx FebInterface.cxx FebServer.cxx HardwareIO.cxx LocalLinkInterface.cxx LocalLinkTest.cxx Test.cxx - - - - -OUTPUT_DIRECTORY = docs - diff --git a/slsDetectorSoftware/eigerDetectorServer/renameServer.sh b/slsDetectorSoftware/eigerDetectorServer/renameServer.sh index 9aca06728..54d5d2622 100644 --- a/slsDetectorSoftware/eigerDetectorServer/renameServer.sh +++ b/slsDetectorSoftware/eigerDetectorServer/renameServer.sh @@ -1,3 +1,4 @@ mv bin/eigerDetectorServer bin/$2 +cp bin/$2 /tftpboot git rm -f bin/$1 git add bin/$2 diff --git a/slsDetectorSoftware/eigerDetectorServer/setup.txt b/slsDetectorSoftware/eigerDetectorServer/setup.txt deleted file mode 100644 index 64c3600e1..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/setup.txt +++ /dev/null @@ -1,53 +0,0 @@ - - -#detector setup - #add_module module_number base_address_top (for half module) - #add_module module_number base_address_top base_address_bottom (for full module) -add_half_module 17 0 -#add_half_module 17 1 for bottom -#add_module 18 10 12 -#add_module 2 13 15 -#add_module 1 120 22 - - -#default setting -photon_energy 8000 -dynamic_range 16 -readout_speed 1 #(0-full,1-half,2-quarter and 3-superslow) -readout_mode 0 #(0-parallel,1-non_parallel,2-safe_mode) - - -#default dacs -SvP 0 -Vtr 1280 -Vrf 1550 -Vrs 700 -SvN 2000 -Vtgstv 1278 -Vcmp_ll 750 -Vcmp_lr 750 -cal 2000 -Vcmp_rl 750 -rxb_rb 600 -rxb_lb 600 -Vcmp_rr 750 -Vcp 100 -Vcn 1000 -Vis 775 - -#default high_voltage -high_voltage 152 - -#default iodelays -iodelay 675 - -#newgoodiodelay 643 -#halfspeed_add_about 32 -#goodiodelay 1467 -#goodiodelay 1550 - - - - - - diff --git a/slsDetectorSoftware/eigerDetectorServer/setup_beb.txt b/slsDetectorSoftware/eigerDetectorServer/setup_beb.txt deleted file mode 100644 index 148cc17e9..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/setup_beb.txt +++ /dev/null @@ -1,12 +0,0 @@ - - -#detector setup -#add_beb base_address mac_1GBE ip_1GBE mac_10GBE ip_10GBE - -add_beb 26 0 00:50:c2:46:d9:34 129.129.205.78 00:50:c2:46:d9:35 10.0.26.1 - - - - - - diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c index b675703c6..9b8b48ca3 100644 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c @@ -28,8 +28,6 @@ int *detectorChips=NULL; int *detectorChans=NULL; dacs_t *detectorDacs=NULL; dacs_t *detectorAdcs=NULL; -int* detectorGain = NULL; -int* detectorOffset = NULL; int eiger_highvoltage = 0; int eiger_iodelay = 0; @@ -101,16 +99,12 @@ int initDetector(){ detectorChans=malloc(n*NCHIP*NCHAN*sizeof(int)); detectorDacs=malloc(n*NDAC*sizeof(dacs_t)); detectorAdcs=malloc(n*NADC*sizeof(dacs_t)); - detectorGain=malloc(n*NGAIN*sizeof(int)); - detectorOffset=malloc(n*NOFFSET*sizeof(int)); #ifdef VERBOSE printf("modules from 0x%x to 0x%x\n",detectorModules, detectorModules+n); printf("chips from 0x%x to 0x%x\n",detectorChips, detectorChips+n*NCHIP); printf("chans from 0x%x to 0x%x\n",detectorChans, detectorChans+n*NCHIP*NCHAN); printf("dacs from 0x%x to 0x%x\n",detectorDacs, detectorDacs+n*NDAC); printf("adcs from 0x%x to 0x%x\n",detectorAdcs, detectorAdcs+n*NADC); - printf("gains from 0x%x to 0x%x\n",detectorGain, detectorGain+n*NGAIN); - printf("offsets from 0x%x to 0x%x\n",detectorOffset, detectorOffset+n*NOFFSET); #endif for (imod=0; imoddacs=detectorDacs+imod*NDAC; @@ -125,19 +119,9 @@ int initDetector(){ (detectorModules+imod)->gain=0; (detectorModules+imod)->offset=0; (detectorModules+imod)->reg=0; - /* initialize registers, dacs, retrieve sn, adc values etc */ } - for(i=0;i=0){ - detectorGain[i] = gain[i]; - printf("gain[%d]:%d\n",i,detectorGain[i]); - }else cprintf(RED,"gain not changed\n"); - } - for(i=0;i=0){ - detectorOffset[i] = offset[i]; - printf("offset[%d]:%d\n",i,detectorOffset[i]); - }else cprintf(RED,"offset not changed\n"); - } - - if(setIODelay(*delay, -1)!= (*delay)){ - cprintf(RED,"could not set iodelay %d\n",*delay); + if(setIODelay(delay, -1)!= delay){ + cprintf(RED,"could not set iodelay %d\n",delay); return FAIL; } @@ -682,21 +651,14 @@ int setModule(sls_detector_module myMod, int* gain, int* offset,int* delay){ } -int getModule(sls_detector_module *myMod, int* gain, int* offset){ +int getModule(sls_detector_module *myMod){ int i; int retval[2]; - //printf("get gainval[0]:%d\n",detectorGain[0]); //dacs for(i=0;i= 0) { - - enum detDacIndex ind[NGAIN]={VCMP_LL,VCMP_LR,VCMP_RL, VCMP_RR}; - const char* vcmp[4]={"vcmp_ll","vcmp_lr","vcmp_rl","vcmp_rr"}; - int valid=0; - - //calculate thrvalues for dacs - for(i=0;i=0 && thrvalue[i]<2001)valid++; - }//ngains - - if( valid == NGAIN){ - eiger_photonenergy = ev; - for(i=0;i= 0) + eiger_photonenergy = ev; return getThresholdEnergy(imod); } diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h b/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h index 9ddfea71b..2919ed968 100644 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h @@ -25,8 +25,8 @@ #define NCHIP 4 #define NDAC 16 #define NADC 0 -#define NGAIN 4 -#define NOFFSET 4 +#define NGAIN 0 +#define NOFFSET 0 #define NMAXMODX 1 #define NMAXMODY 1 diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index db64114f2..99bc5d025 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -1144,41 +1144,54 @@ int multiSlsDetector::getThresholdEnergy(int pos) { int multiSlsDetector::setThresholdEnergy(int e_eV, int pos, detectorSettings isettings) { - int i, posmin, posmax; - int ret1=-100, ret; + int posmin, posmax; + int ret=-100; + if (pos<0) { + posmin=0; + posmax=thisMultiDetector->numberOfDetectors; + } else { + posmin=pos; + posmax=pos+1; + } - if (pos<0) { - posmin=0; - posmax=thisMultiDetector->numberOfDetectors; - } else { - posmin=pos; - posmax=pos+1; - } - - for (i=posmin; isetThresholdEnergy(e_eV,-1,isettings); - if(detectors[i]->getErrorMask()) - setErrorMask(getErrorMask()|(1<(ret1+200)) - ret1=FAIL; - -#ifdef VERBOSE - cout << "return value " << ret1 << endl; -#endif - } - - } - thisMultiDetector->currentThresholdEV=ret1; - return ret1; + if(!threadpool){ + cout << "Error in creating threadpool. Exiting" << endl; + return -1; + }else{ + //return storage values + int* iret[posmax-posmin]; + for(int idet=posmin; idet(&slsDetector::setThresholdEnergy, + detectors[idet],e_eV,-1,isettings,iret[idet])); + threadpool->add_task(task); + } + } + threadpool->startExecuting(); + threadpool->wait_for_tasks_to_complete(); + for(int idet=posmin; idet(*iret[idet]+200)) + ret=-1; + delete iret[idet]; + }else ret=-1; + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<currentThresholdEV=ret; + return ret; } + + + slsDetectorDefs::detectorSettings multiSlsDetector::getSettings(int pos) { int i, posmin, posmax; diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 079c5e3a6..9dd102edc 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -655,8 +655,8 @@ int slsDetector::initializeDetectorSize(detectorType type) { thisDetector->nChip[Y]=1; thisDetector->nDacs=16; thisDetector->nAdcs=0; - thisDetector->nGain=4; - thisDetector->nOffset=4; + thisDetector->nGain=0; + thisDetector->nOffset=0; thisDetector->nModMax[X]=1; thisDetector->nModMax[Y]=1; thisDetector->dynamicRange=16; @@ -2825,12 +2825,8 @@ slsDetectorDefs::sls_detector_chip slsDetector::getChip(int ichip, int imod){ int slsDetector::setModule(int reg, int imod){ sls_detector_module myModule; - int* g=0; - int* o=0; - int* iod=0; - int64_t tau=-1; -#ifdef VERBOSE + #ifdef VERBOSE std::cout << "slsDetector set module " << std::endl; #endif int charegs[thisDetector->nChans*thisDetector->nChips]; @@ -2897,14 +2893,14 @@ int slsDetector::setModule(int reg, int imod){ ads[i]=-1; myModule.adcs=ads; } - ret=setModule(myModule,g,o,iod,tau); + ret=setModule(myModule,-1,-1,-1,0,0); } return ret; }; -int slsDetector::setModule(sls_detector_module module, int* gainval, int* offsetval, int* iodelay, int64_t tau){ +int slsDetector::setModule(sls_detector_module module, int iodelay, int tau, int e_eV, int* gainval, int* offsetval){ int fnum=F_SET_MODULE; int retval; @@ -2923,16 +2919,18 @@ int slsDetector::setModule(sls_detector_module module, int* gainval, int* offset controlSocket->SendDataOnly(&fnum,sizeof(fnum)); sendModule(&module); - //extra gain and offset - eiger - if((thisDetector->nGain) && (gainval)) + //not included in module + if(gainval && (thisDetector->nGain)) controlSocket->SendDataOnly(gainval,sizeof(int)*thisDetector->nGain); - if((thisDetector->nOffset) && (offsetval)) + if(offsetval && (thisDetector->nOffset)) controlSocket->SendDataOnly(offsetval,sizeof(int)*thisDetector->nOffset); - if(thisDetector->myDetectorType == EIGER){ - controlSocket->SendDataOnly(iodelay,sizeof(int)); + if(thisDetector->myDetectorType == EIGER) { + controlSocket->SendDataOnly(&iodelay,sizeof(iodelay)); controlSocket->SendDataOnly(&tau,sizeof(tau)); + controlSocket->SendDataOnly(&e_eV,sizeof(e_eV)); } + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); if (ret!=FAIL) controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); @@ -3129,13 +3127,14 @@ slsDetectorDefs::sls_detector_module *slsDetector::getModule(int imod){ offset[i+imod*thisDetector->nOffset]=offsetval[i]; } - if(gainval) delete[]gainval; - if(offsetval) delete[]offsetval; - } else { deleteModule(myMod); myMod=NULL; } + + if(gainval) delete[]gainval; + if(offsetval) delete[]offsetval; + return myMod; } @@ -3200,41 +3199,201 @@ int slsDetector::getThresholdEnergy(int imod){ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isettings){ - int fnum= F_SET_THRESHOLD_ENERGY; - int retval; - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; + //currently only for eiger + if (thisDetector->myDetectorType == EIGER) { + setThresholdEnergyAndSettings(e_eV,isettings); + return thisDetector->currentThresholdEV; + } + + int fnum= F_SET_THRESHOLD_ENERGY; + int retval; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; #ifdef VERBOSE - std::cout<< "Setting threshold energy "<< std::endl; + std::cout<< "Setting threshold energy "<< std::endl; #endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&e_eV,sizeof(e_eV)); - controlSocket->SendDataOnly(&imod,sizeof(imod)); - controlSocket->SendDataOnly(&isettings,sizeof(isettings)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - std::cout<< "Detector returned error: "<< std::endl; - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< mess << std::endl; - } else { + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&e_eV,sizeof(e_eV)); + controlSocket->SendDataOnly(&imod,sizeof(imod)); + controlSocket->SendDataOnly(&isettings,sizeof(isettings)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + std::cout<< "Detector returned error: "<< std::endl; + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< mess << std::endl; + } else { #ifdef VERBOSE - std::cout<< "Detector returned OK "<< std::endl; + std::cout<< "Detector returned OK "<< std::endl; #endif - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - thisDetector->currentThresholdEV=retval; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } else { - thisDetector->currentThresholdEV=e_eV; - } - return thisDetector->currentThresholdEV; + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + thisDetector->currentThresholdEV=retval; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } else { + thisDetector->currentThresholdEV=e_eV; + } + return thisDetector->currentThresholdEV; }; + + +int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isettings) { + + //if settings provided, use that, else use the shared memory variable + detectorSettings is = ((isettings != GET_SETTINGS) ? isettings: thisDetector->currentSettings); + string ssettings; + switch (is) { + case STANDARD: + ssettings="/standard"; + thisDetector->currentSettings=STANDARD; + break; + case HIGHGAIN: + ssettings="/highgain"; + thisDetector->currentSettings=HIGHGAIN; + break; + case LOWGAIN: + ssettings="/lowgain"; + thisDetector->currentSettings=LOWGAIN; + break; + case VERYHIGHGAIN: + ssettings="/veryhighgain"; + thisDetector->currentSettings=VERYHIGHGAIN; + break; + case VERYLOWGAIN: + ssettings="/verylowgain"; + thisDetector->currentSettings=VERYLOWGAIN; + break; + default: + printf("Error: Unknown settings %s for this detector!\n", getDetectorSettings(is).c_str()); + setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); + return FAIL; + } + + //verify e_eV exists in trimEneregies[] + if (!thisDetector->nTrimEn || + (e_eV < thisDetector->trimEnergies[0]) || + (e_eV > thisDetector->trimEnergies[thisDetector->nTrimEn-1]) ) { + printf("Error: This energy %d not defined for this module!\n", e_eV); + setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); + return FAIL; + } + + //find if interpolation required + bool interpolate = true; + for (int i = 0; i < thisDetector->nTrimEn; ++i) { + if (thisDetector->trimEnergies[i] == e_eV) { + interpolate = false; + break; + } + } + + //fill detector module structure + sls_detector_module *myMod = NULL; + int iodelay = -1; //not included in the module + int tau = -1; //not included in the module + + //normal + if(!interpolate) { + //find their directory names + ostringstream ostfn; + ostfn << thisDetector->settingsDir << ssettings << "/" << e_eV << "eV" << "/noise.sn" << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER) << setbase(10); + string settingsfname = ostfn.str(); +#ifdef VERBOSE + printf("Settings File is %s\n", settingsfname1.c_str()); +#endif + //read the files + myMod=createModule(); + if (NULL == readSettingsFile(settingsfname,thisDetector->myDetectorType, iodelay, tau, myMod)) { + if(myMod)deleteModule(myMod); + return FAIL; + } + } + + + //interpolate + else { + //find the trim values + int trim1 = -1, trim2 = -1; + for (int i = 0; i < thisDetector->nTrimEn; ++i) { + if (e_eV < thisDetector->trimEnergies[i]) { + trim2 = thisDetector->trimEnergies[i]; + trim1 = thisDetector->trimEnergies[i-1]; + break; + } + } + //find their directory names + ostringstream ostfn; + ostfn << thisDetector->settingsDir << ssettings << "/" << trim1 << "eV" << "/noise.sn" << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER) << setbase(10); + string settingsfname1 = ostfn.str(); + ostfn.str(""); ostfn.clear(); + ostfn << thisDetector->settingsDir << ssettings << "/" << trim2 << "eV" << "/noise.sn" << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER) << setbase(10); + string settingsfname2 = ostfn.str(); + //read the files +#ifdef VERBOSE + printf("Settings Files are %s and %s\n",settingsfname1.c_str(), settingsfname2.c_str()); +#endif + sls_detector_module *myMod1=createModule(); + sls_detector_module *myMod2=createModule(); + int iodelay1 = -1; //not included in the module + int tau1 = -1; //not included in the module + int iodelay2 = -1; //not included in the module + int tau2 = -1; //not included in the module + if (NULL == readSettingsFile(settingsfname1,thisDetector->myDetectorType, iodelay1, tau1, myMod1)) { + setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN)); + deleteModule(myMod1); + deleteModule(myMod2); + return FAIL; + } + if (NULL == readSettingsFile(settingsfname2,thisDetector->myDetectorType, iodelay2, tau2, myMod2)) { + setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN)); + deleteModule(myMod1); + deleteModule(myMod2); + return FAIL; + } + if (iodelay1 != iodelay2) { + printf("iodelays do not match between files\n"); + setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); + deleteModule(myMod1); + deleteModule(myMod2); + return FAIL; + } + iodelay = iodelay1; + + //interpolate module + myMod = interpolateTrim(thisDetector->myDetectorType, myMod1, myMod2, e_eV, trim1, trim2); + if (myMod == NULL) { + printf("Could not interpolate, different dac values in files\n"); + setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); + } + //interpolate tau + tau = linearInterpolation(e_eV, trim1, trim2, tau1, tau2); + printf("new tau:%d\n",tau); + + deleteModule(myMod1); + deleteModule(myMod2); + } + + + myMod->module=0; + myMod->reg=thisDetector->currentSettings; + setModule(*myMod, iodelay, tau, e_eV, 0, 0); + deleteModule(myMod); + if (getSettings(-1) != is){ + std::cout << "Could not set settings in detector" << endl; + setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); + return FAIL; + } + + return OK; +} + + + /* select detector settings */ @@ -3281,20 +3440,36 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise #ifdef VERBOSE std::cout<< "slsDetector setSettings "<< std::endl; #endif + + //only set client shared memory variable for Eiger, settings threshold loads the module data (trimbits, dacs etc.) + if (thisDetector->myDetectorType == EIGER) { + switch(isettings) { + case STANDARD: + case HIGHGAIN: + case LOWGAIN: + case VERYHIGHGAIN: + case VERYLOWGAIN: + thisDetector->currentSettings = isettings; + break; + default: + printf("Unknown settings %s for this detector!\n", getDetectorSettings(isettings).c_str()); + } + return thisDetector->currentSettings; + } + sls_detector_module *myMod=createModule(); int modmi=imod, modma=imod+1, im=imod; string settingsfname, calfname; string ssettings; + //not included in module structure + int iodelay = -1; + int tau = -1; int* gainval=0, *offsetval=0; - int* iodelay=0; if(thisDetector->nGain) gainval=new int[thisDetector->nGain]; if(thisDetector->nOffset) offsetval=new int[thisDetector->nOffset]; - if(thisDetector->myDetectorType == EIGER) - iodelay = new int; - int64_t tau=-1; int ret=0; @@ -3452,7 +3627,7 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise #ifdef VERBOSE cout << "the settings file name is "<myDetectorType, myMod,iodelay)) { + if (NULL == readSettingsFile(settingsfname,thisDetector->myDetectorType, iodelay, tau, myMod)) { //if it didnt open, try default settings file ostringstream ostfn_default; switch(thisDetector->myDetectorType){ @@ -3472,7 +3647,7 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise #ifdef VERBOSE cout << settingsfname << endl; #endif - if (!readSettingsFile(settingsfname,thisDetector->myDetectorType, myMod,iodelay)) { + if (NULL == readSettingsFile(settingsfname,thisDetector->myDetectorType, iodelay, tau, myMod)) { //if default doesnt work, return error std::cout << "Could not open settings file" << endl; setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN)); @@ -3483,41 +3658,43 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise //calibration file**** - calfname=oscfn.str(); + if(thisDetector->myDetectorType != EIGER) { + calfname=oscfn.str(); #ifdef VERBOSE - cout << "Specific file:"<< calfname << endl; -#endif - //extra gain and offset - if(thisDetector->nGain) - ret = readCalibrationFile(calfname,gainval, offsetval, tau, thisDetector->myDetectorType ); - //normal gain and offset inside sls_detector_module - else - ret = readCalibrationFile(calfname,myMod->gain, myMod->offset); - - //if it didnt open, try default - if(ret != OK){ - ostringstream oscfn_default; - oscfn_default << thisDetector->calDir << ssettings << ssettings << ".cal"; - calfname=oscfn_default.str(); -#ifdef VERBOSE - cout << "Default file:" << calfname << endl; + cout << "Specific file:"<< calfname << endl; #endif //extra gain and offset if(thisDetector->nGain) - ret = readCalibrationFile(calfname,gainval, offsetval, tau, thisDetector->myDetectorType ); + ret = readCalibrationFile(calfname,gainval, offsetval); //normal gain and offset inside sls_detector_module else ret = readCalibrationFile(calfname,myMod->gain, myMod->offset); - } - //if default doesnt work, return error - if(ret != OK){ - std::cout << "Could not open calibration file" << calfname << endl; - setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN)); - return thisDetector->currentSettings; + + //if it didnt open, try default + if(ret != OK){ + ostringstream oscfn_default; + oscfn_default << thisDetector->calDir << ssettings << ssettings << ".cal"; + calfname=oscfn_default.str(); +#ifdef VERBOSE + cout << "Default file:" << calfname << endl; +#endif + //extra gain and offset + if(thisDetector->nGain) + ret = readCalibrationFile(calfname,gainval, offsetval); + //normal gain and offset inside sls_detector_module + else + ret = readCalibrationFile(calfname,myMod->gain, myMod->offset); + } + //if default doesnt work, return error + if(ret != OK){ + std::cout << "Could not open calibration file" << calfname << endl; + setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN)); + return thisDetector->currentSettings; + } } //if everything worked, set module**** - setModule(*myMod,gainval,offsetval,iodelay, tau); + setModule(*myMod,iodelay,tau,-1,gainval,offsetval); } } @@ -6507,9 +6684,9 @@ int slsDetector::writeConfigurationFile(ofstream &outfile, int id){ -int slsDetector::writeSettingsFile(string fname, int imod, int* iodelay){ +int slsDetector::writeSettingsFile(string fname, int imod, int& iodelay, int& tau){ - return writeSettingsFile(fname,thisDetector->myDetectorType, detectorModules[imod], iodelay); + return writeSettingsFile(fname,thisDetector->myDetectorType, detectorModules[imod], iodelay, tau); }; @@ -6774,22 +6951,9 @@ int slsDetector::loadSettingsFile(string fname, int imod) { sls_detector_module *myMod=NULL; - //tau set to -2 to not affect in any way (-1 for set settings) - int64_t tau =-2; - int* gainval=0; int* offsetval=0; - int *iodelay=0; - if(thisDetector->nGain){ - gainval=new int[thisDetector->nGain]; - for(int i=0;inGain;i++) - gainval[i] = -1; - } - if(thisDetector->nOffset){ - offsetval=new int[thisDetector->nOffset]; - for(int i=0;inOffset;i++) - offsetval[i] = -1; - } - if(thisDetector->myDetectorType == EIGER) - iodelay = new int;*iodelay=0; + int iodelay = -1; + int tau = -1; + string fn=fname; fn=fname; int mmin=0, mmax=setNumberOfModules(); @@ -6809,17 +6973,15 @@ int slsDetector::loadSettingsFile(string fname, int imod) { ostfn << ".sn" << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER, im); fn=ostfn.str(); } - myMod=readSettingsFile(fn, thisDetector->myDetectorType,myMod,iodelay); + myMod=readSettingsFile(fn, thisDetector->myDetectorType,iodelay, tau, myMod); if (myMod) { myMod->module=im; //settings is saved in myMod.reg for all except mythen if(thisDetector->myDetectorType!=MYTHEN) myMod->reg=thisDetector->currentSettings; - setModule(*myMod,gainval,offsetval,iodelay,tau); + setModule(*myMod,iodelay,tau,-1,0,0); deleteModule(myMod); - if(gainval) delete[] gainval; - if(offsetval) delete[] offsetval; } else return FAIL; } @@ -6831,7 +6993,8 @@ int slsDetector::saveSettingsFile(string fname, int imod) { sls_detector_module *myMod=NULL; int ret=FAIL; - int *iod = 0; + int iodelay = -1; + int tau = -1; int mmin=0, mmax=setNumberOfModules(); if (imod>=0) { @@ -6847,10 +7010,10 @@ int slsDetector::saveSettingsFile(string fname, int imod) { if ((myMod=getModule(im))) { if(thisDetector->myDetectorType == EIGER){ - iod = new int; - *iod = (int)setDAC((dacs_t)-1,IO_DELAY,0,-1); + iodelay = (int)setDAC((dacs_t)-1,IO_DELAY,0,-1); + tau = (int64_t)getRateCorrectionTau(); } - ret=writeSettingsFile(ostfn.str(), thisDetector->myDetectorType, *myMod,iod); + ret=writeSettingsFile(ostfn.str(), thisDetector->myDetectorType, *myMod, iodelay, tau); deleteModule(myMod); } } @@ -6898,12 +7061,15 @@ int slsDetector::setAllTrimbits(int val, int imod){ int slsDetector::loadCalibrationFile(string fname, int imod) { + if(thisDetector->myDetectorType == EIGER) { + std::cout << "Not required for this detector!" << std::endl; + return FAIL; + } + sls_detector_module *myMod=NULL; string fn=fname; - int64_t tau = -1; int* gainval=0; int* offsetval=0; - int* iodelay=0; if(thisDetector->nGain){ gainval=new int[thisDetector->nGain]; for(int i=0;inGain;i++) @@ -6935,18 +7101,16 @@ int slsDetector::loadCalibrationFile(string fname, int imod) { } fn=ostfn.str(); if((myMod=getModule(im))){ - iodelay = new int; - *iodelay = (int)setDAC(-1,IO_DELAY,0); //extra gain and offset if(thisDetector->nGain){ - if(readCalibrationFile(fn,gainval, offsetval,tau, thisDetector->myDetectorType)==FAIL) + if(readCalibrationFile(fn,gainval, offsetval)==FAIL) return FAIL; } //normal gain and offset inside sls_detector_module else{ if(readCalibrationFile(fn,myMod->gain, myMod->offset)==FAIL) return FAIL; } - setModule(*myMod,gainval,offsetval,iodelay,tau); + setModule(*myMod,-1,-1,-1,gainval,offsetval); deleteModule(myMod); if(gainval) delete[]gainval; @@ -6978,7 +7142,7 @@ int slsDetector::saveCalibrationFile(string fname, int imod) { if ((myMod=getModule(im))) { //extra gain and offset if(thisDetector->nGain) - ret=writeCalibrationFile(ostfn.str(),gain, offset,(int64_t)thisDetector->tDead, thisDetector->myDetectorType); + ret=writeCalibrationFile(ostfn.str(),gain, offset); //normal gain and offset inside sls_detector_module else ret=writeCalibrationFile(ostfn.str(),myMod->gain, myMod->offset); diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 6221a661a..bd02b3b31 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -507,11 +507,12 @@ class slsDetector : public slsDetectorUtils, public energyConversion { \param fname name of the file to be written \param imod module number \param iodelay io delay (detector specific) + \param tau tau (detector specific) \returns OK or FAIL if the file could not be written \sa ::sls_detector_module sharedSlsDetector mythenDetector::writeSettingsFile(string, int) */ using energyConversion::writeSettingsFile; - int writeSettingsFile(string fname, int imod, int* iodelay=0); + int writeSettingsFile(string fname, int imod, int& iodelay, int& tau); /** @@ -948,14 +949,15 @@ class slsDetector : public slsDetectorUtils, public energyConversion { /** configure chip \param module module to be set - must contain correct module number and also channel and chip registers - \param gainval pointer to extra gain values - \param offsetval pointer to extra offset values \param iodelay iodelay (detector specific) \param tau tau (detector specific) + \param e_eV threashold in eV (detector specific) + \param gainval pointer to extra gain values + \param offsetval pointer to extra offset values \returns current register value \sa ::sls_detector_module */ - int setModule(sls_detector_module module, int* gainval, int* offsetval,int* iodelay, int64_t tau); + int setModule(sls_detector_module module, int iodelay, int tau, int e_eV, int* gainval=0, int* offsetval=0); //virtual int setModule(sls_detector_module module); /** @@ -989,6 +991,14 @@ class slsDetector : public slsDetectorUtils, public energyConversion { \returns current threshold value for imod in ev (-1 failed) */ int setThresholdEnergy(int e_eV, int imod=-1, detectorSettings isettings=GET_SETTINGS); + + /** + set threshold energy + \param e_eV threshold in eV + \param isettings ev. change settings + \returns OK if successful, else FAIL + */ + int setThresholdEnergyAndSettings(int e_eV, detectorSettings isettings); /** get detector settings diff --git a/slsDetectorSoftware/slsDetector/slsDetectorBase.h b/slsDetectorSoftware/slsDetector/slsDetectorBase.h index 26529c367..b7c2bcfae 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorBase.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorBase.h @@ -433,10 +433,6 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef int setThresholdEnergy(int e_eV){return setThresholdEnergy(e_eV,-1);}; - // int getBeamEnergy(){return 2*getThresholdEnergy();}; - //int setBeamEnergy(int e){return 2*setThresholdEnergy(e/2);}; - - /** Prints receiver configuration \returns OK or FAIL diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index b0de290dc..d09f1fb8f 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -184,7 +184,7 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { i++; descrToFuncMap[i].m_pFuncName="trimen"; - descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdUnderDevelopment; + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdTrimEn; i++; @@ -3297,15 +3297,28 @@ string slsDetectorCommand::cmdSettings(int narg, char *args[], int action) { myDet->setOnline(ONLINE_FLAG); if (cmd=="settings") { - if (action==PUT_ACTION) - myDet->setSettings(myDet->getDetectorSettings(string(args[1]))); + detectorSettings sett = GET_SETTINGS; + if (action==PUT_ACTION) { + sett = myDet->setSettings(myDet->getDetectorSettings(string(args[1]))); + if (myDet->getDetectorsType() == EIGER) { + return myDet->getDetectorSettings(sett); + } + } return myDet->getDetectorSettings(myDet->getSettings()); } else if (cmd=="threshold") { if (action==PUT_ACTION) { - if (sscanf(args[1],"%d",&val)) - myDet->setThresholdEnergy(val); - else - return string("invalid threshold value ")+cmd; + detectorType type = myDet->getDetectorsType(); + if (!sscanf(args[1],"%d",&val)) { + return string("invalid threshold value"); + } + if (type != EIGER || (type == EIGER && narg<=2)) { + myDet->setThresholdEnergy(val); + } else { + detectorSettings sett= myDet->getDetectorSettings(string(args[2])); + if(sett == -1) + return string("invalid settings value"); + myDet->setThresholdEnergy(val, -1, sett); + } } sprintf(ans,"%d",myDet->getThresholdEnergy()); return string(ans); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUsers.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUsers.cpp index 4bf4e9c90..7da1668c6 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUsers.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUsers.cpp @@ -147,14 +147,6 @@ int slsDetectorUsers::setThresholdEnergy(int e_eV){ return myDetector->setThresholdEnergy(e_eV); } -int slsDetectorUsers::getBeamEnergy(){ - return 2*myDetector->getThresholdEnergy(); -} - -int slsDetectorUsers::setBeamEnergy(int e_eV){ - return 2*myDetector->setThresholdEnergy(e_eV/2); -} - double slsDetectorUsers::setExposureTime(double t, bool inseconds){ int64_t tms = (int64_t)(t * (1E+9)); if (t < 0) tms = -1; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUsers.h b/slsDetectorSoftware/slsDetector/slsDetectorUsers.h index 214661384..7c7ed1a18 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUsers.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUsers.h @@ -302,19 +302,6 @@ class slsDetectorUsers */ int setThresholdEnergy(int e_eV); - /** - @short get beam energy -- only for dectris! - \returns current beam energy - */ - int getBeamEnergy(); - - - /** - @short set beam energy -- only for dectris! - \param e_eV beam in eV - \returns current beam energyin ev (-1 failed) - */ - int setBeamEnergy(int e_eV); /** @short set/get exposure time value diff --git a/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.cpp b/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.cpp index aa54cb2ed..d55e4cc8f 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.cpp @@ -69,85 +69,58 @@ int energyConversion::writeCalibrationFile(string fname, double gain, double off }; -int energyConversion::readCalibrationFile(string fname, int *gain, int *offset, int64_t &tau, detectorType myDetectorType){ - - +int energyConversion::readCalibrationFile(string fname, int *gain, int *offset){ string str; ifstream infile; double o,g; int ig=0; - switch (myDetectorType) { - case EIGER: - - - #ifdef VERBOSE - std::cout<< "Opening file "<< fname << std::endl; + std::cout<< "Opening file "<< fname << std::endl; #endif - infile.open(fname.c_str(), ios_base::in); - if (infile.is_open()) { - //get gain and offset - for (ig=0; ig<4; ig++) { - //while ( (getline(infile,str)) > -1) { - getline(infile,str); + infile.open(fname.c_str(), ios_base::in); + if (infile.is_open()) { + //get gain and offset + for (ig=0; ig<4; ig++) { + //while ( (getline(infile,str)) > -1) { + getline(infile,str); #ifdef VERBOSE - std::cout<< str << std::endl; + std::cout<< str << std::endl; #endif - istringstream ssstr(str); - ssstr >> o >> g; - offset[ig]=(int)(o*1000); - gain[ig]=(int)(g*1000); - // ig++; - if (ig>=4) - break; - } - //get tau - if (myDetectorType == EIGER) { - if(getline(infile,str)){ - istringstream ssstr(str); - ssstr >> tau; -#ifdef VERBOSE - std::cout<< "tau:" << tau << std::endl; -#endif - } - } - infile.close(); - cout << "Calibration file loaded: " << fname << endl; - } else { - cout << "Could not open calibration file: "<< fname << std::endl; - gain[0]=0; - offset[0]=0; -#ifndef MYROOT - return FAIL; -#endif - return -1; + istringstream ssstr(str); + ssstr >> o >> g; + offset[ig]=(int)(o*1000); + gain[ig]=(int)(g*1000); + // ig++; + if (ig>=4) + break; } + infile.close(); + cout << "Calibration file loaded: " << fname << endl; + } else { + cout << "Could not open calibration file: "<< fname << std::endl; + gain[0]=0; + offset[0]=0; #ifndef MYROOT - return OK; -#endif - return 0; - break; - default: - std::cout<< "Writing Calibration Files for this detector not defined\n" << std::endl; return FAIL; +#endif + return -1; } +#ifndef MYROOT + return OK; +#endif + return 0; }; -int energyConversion::writeCalibrationFile(string fname, int *gain, int *offset, int64_t tau, detectorType myDetectorType){ +int energyConversion::writeCalibrationFile(string fname, int *gain, int *offset){ //std::cout<< "Function not yet implemented " << std::endl; ofstream outfile; - switch (myDetectorType) { - case EIGER: - outfile.open (fname.c_str()); - // >> i/o operations here << if (outfile.is_open()) { for (int ig=0; ig<4; ig++) outfile << ((double)offset[ig]/1000) << " " << ((double)gain[ig]/1000) << std::endl; - outfile << tau << std::endl; } else { std::cout<< "Could not open calibration file "<< fname << " for writing" << std::endl; #ifndef MYROOT @@ -161,21 +134,53 @@ int energyConversion::writeCalibrationFile(string fname, int *gain, int *offset, return OK; #endif return 0; - break; - default: - std::cout<< "Writing Calibration Files for this detector not defined\n" << std::endl; - return FAIL; - } - }; + +slsDetectorDefs::sls_detector_module* energyConversion::interpolateTrim(detectorType myDetectorType, sls_detector_module* a, sls_detector_module* b, const int energy, const int e1, const int e2){ + // only implemented for eiger currently (in terms of which dacs) + if(myDetectorType != EIGER) { + printf("Interpolation of Trim values not implemented for this detector!\n"); + return NULL; + } + + sls_detector_module* myMod = createModule(myDetectorType); + enum eiger_DacIndex{SVP,VTR,VRF,VRS,SVN,VTGSTV,VCMP_LL,VCMP_LR,CAL,VCMP_RL,RXB_RB,RXB_LB,VCMP_RR,VCP,VCN,VIS}; + + //Copy other dacs + int num_dacs_to_copy = 10; + int dacs_to_copy[] = {SVP,VTR,VRS,SVN,VTGSTV,CAL,RXB_RB,RXB_LB,VCN,VIS}; + for (int i = 0; i < num_dacs_to_copy; ++i) { + if(a->dacs[dacs_to_copy[i]] != b->dacs[dacs_to_copy[i]]) { + deleteModule(myMod); + return NULL; + } + myMod->dacs[dacs_to_copy[i]] = a->dacs[dacs_to_copy[i]]; + } + + //Interpolate vrf, vcmp, vcp + int num_dacs_to_interpolate = 6; + int dacs_to_interpolate[] = {VRF,VCMP_LL,VCMP_LR,VCMP_RL,VCMP_RR,VCP}; + for (int i = 0; i < num_dacs_to_interpolate; ++i) { + myMod->dacs[dacs_to_interpolate[i]] = linearInterpolation(energy, e1, e2, + a->dacs[dacs_to_interpolate[i]], b->dacs[dacs_to_interpolate[i]]); + } + + //Interpolate all trimbits + for (int i = 0; inchan; i++) + myMod->chanregs[i] = linearInterpolation(energy, e1, e2, a->chanregs[i], b->chanregs[i]); + return myMod; +} + + + #ifndef MYROOT /* I/O */ -slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string fname, detectorType myDetectorType, sls_detector_module *myMod, int* iodelay){ +slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string fname, detectorType myDetectorType, int& iodelay, int& tau, sls_detector_module* myMod){ @@ -353,7 +358,7 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string infile.close(); strcpy(settingsFile,fname.c_str()); - cout << "Settings file loaded: " << settingsFile << endl; + printf("Settings file loaded: %s\n",settingsFile); return myMod; } @@ -365,12 +370,14 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string infile.open(myfname.c_str(),ifstream::binary); if (infile.is_open()) { infile.read((char*) myMod->dacs,sizeof(dacs_t)*(myMod->ndac)); - infile.read((char*) iodelay,sizeof(*iodelay)); + infile.read((char*)&iodelay,sizeof(iodelay)); + infile.read((char*)&tau,sizeof(tau)); infile.read((char*) myMod->chanregs,sizeof(int)*(myMod->nchan)); #ifdef VERBOSE for(int i=0;indac;i++) std::cout << "dac " << i << ":" << myMod->dacs[i] << std::endl; - std::cout << "iodelay:" << *iodelay << std::endl; + std::cout << "iodelay:" << iodelay << std::endl; + std::cout << "tau:" << tau << std::endl; #endif if(infile.eof()){ cout< + V linearInterpolation(const E x, const E x1, const E x2, const V y1, const V y2){ + double k = static_cast(y2-y1)/(x2-x1); + double m = y1-k*x1; + int y = round( k*x+m ); + return static_cast(y); + } + /** + * interpolates dacs and trimbits between 2 trim files + \param myDetectorType detector type (needed for which dacs that neeeds to be interpolated & which kept same) + \param a first module structure + \param b second module structure + \param energy energy to trim at + \param e1 reference trim value + \param e2 reference trim value + \returns the pointer to the module structure with interpolated values or NULL if error + */ + sls_detector_module* interpolateTrim(detectorType myDetectorType, sls_detector_module* a, sls_detector_module* b, const int energy, const int e1, const int e2); @@ -83,12 +100,13 @@ class energyConversion reads a trim/settings file \param fname name of the file to be read \param myDetectorType detector type (needed for number of channels, chips, dacs etc.) - \param myMod pointer to the module structure which has to be set.
If it is NULL a new module structure will be created \param iodelay io delay (detector specific) + \param tau tau (detector specific) + \param myMod pointer to the module structure which has to be set.
If it is NULL a new module structure will be created \returns the pointer to myMod or NULL if reading the file failed */ - sls_detector_module* readSettingsFile(string fname, detectorType myDetectorType, sls_detector_module* myMod=NULL, int* iodelay=0); + sls_detector_module* readSettingsFile(string fname, detectorType myDetectorType, int& iodelay, int& tau, sls_detector_module* myMod=NULL); /** writes a trim/settings file @@ -96,11 +114,12 @@ class energyConversion \param myDetectorType detector type (needed for number of channels, chips, dacs etc.) \param mod module structure which has to be written to file \param iodelay io delay (detector specific) + \param tau tau (detector specific) \returns OK or FAIL if the file could not be written \sa ::sls_detector_module mythenDetector::writeSettingsFile(string, sls_detector_module) */ - int writeSettingsFile(string fname, detectorType myDetectorType, sls_detector_module mod, int* iodelay=0); + int writeSettingsFile(string fname, detectorType myDetectorType, sls_detector_module mod, int& iodelay, int& tau); /** allocates the momery for a detector module structure \param myDetectorType detector type (needed for number of channels, chips, dacs etc.) @@ -114,6 +133,7 @@ class energyConversion */ virtual void deleteModule(sls_detector_module *myMod)=0; + protected: /** pointer to settings file name */ char *settingsFile; diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h index baa0ab382..ca7eb6d4a 100644 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h @@ -72,14 +72,12 @@ int getChip(sls_detector_chip *myChip); #ifdef EIGERD -int setModule(sls_detector_module myMod, int* gain, int* offset,int* delay); -int getModule(sls_detector_module *myMod, int* gain, int* offset); +int setModule(sls_detector_module myMod, int delay); #else int setModule(sls_detector_module myMod); -int getModule(sls_detector_module *myMod); #endif - +int getModule(sls_detector_module *myMod); enum detectorSettings setSettings(enum detectorSettings sett, int imod); enum detectorSettings getSettings(); diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c index b41c65a73..39fc96d9b 100755 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c @@ -1867,10 +1867,9 @@ int set_module(int file_des) { #ifdef SLS_DETECTOR_FUNCTION_LIST sls_detector_module myModule; #ifdef EIGERD - int *myGain = (int*)malloc(getNumberOfGainsPerModule()*sizeof(int)); - int *myOffset = (int*)malloc(getNumberOfOffsetsPerModule()*sizeof(int)); - int *myIODelay = (int*)malloc(sizeof(int)); - int64_t myTau=-1; + int myIODelay = -1; + int myTau = -1; + int myEV = -1; #endif int *myChip=(int*)malloc(getNumberOfChipsPerModule()*sizeof(int)); int *myChan=(int*)malloc(getNumberOfChannelsPerModule()*sizeof(int)); @@ -1902,16 +1901,6 @@ int set_module(int file_des) { sprintf(mess,"could not allocate chans\n"); ret=FAIL; } -#ifdef EIGERD - if (!myGain){ - sprintf(mess,"could not allocate gains\n"); - ret=FAIL; - } - if (!myOffset){ - sprintf(mess,"could not allocate offsets\n"); - ret=FAIL; - } -#endif myModule.nchip=getNumberOfChipsPerModule(); myModule.nchan=getNumberOfChannelsPerModule(); myModule.ndac=getNumberOfDACsPerModule(); @@ -1923,10 +1912,9 @@ int set_module(int file_des) { #endif ret=receiveModule(file_des, &myModule); #ifdef EIGERD - n = receiveData(file_des,myGain,sizeof(int)*getNumberOfGainsPerModule(),INT32); - n = receiveData(file_des,myOffset,sizeof(int)*getNumberOfOffsetsPerModule(),INT32); - n = receiveData(file_des,myIODelay,sizeof(int),INT32); - n = receiveData(file_des,&myTau,sizeof(myTau),INT64); + n = receiveData(file_des,&myIODelay,sizeof(myIODelay),INT32); + n = receiveData(file_des,&myTau,sizeof(myTau),INT32); + n = receiveData(file_des,&myEV,sizeof(myEV),INT32); #endif if (ret>=0) ret=OK; @@ -1937,16 +1925,12 @@ int set_module(int file_des) { #ifdef VERBOSE printf("module number is %d,register is %d, nchan %d, nchip %d, ndac %d, nadc %d, gain %f, offset %f\n",myModule.module, myModule.reg, myModule.nchan, myModule.nchip, myModule.ndac, myModule.nadc, myModule.gain,myModule.offset); #ifdef EIGERD - int i; - for(i=0;i= 0) setThresholdEnergy(myEV,-1); + //set dacs, trimbits and iodelay + ret=setModule(myModule, myIODelay); + //rate correction - if(myTau > -2){ //ignore -2: from load settings) - - //set default tau value (-1 or a normal value) - setDefaultSettingsTau_in_nsec(myTau); - - //switch off rate correction: no value read from load calib/load settings) - if(myTau == -1){ - if(getRateCorrectionEnable()){ - ret = FAIL; - setRateCorrection(0); - strcat(mess,"Cannot set Rate correction. No default tau provided. Deactivating Rate Correction\n"); - cprintf(RED,"%s",mess); - } - } - - - //normal tau value (only if enabled) - else if (getRateCorrectionEnable()){ - int64_t retvalTau = setRateCorrection(myTau); //myTau will not be -1 here - if(myTau != retvalTau){ - cprintf(RED,"%s",mess); - ret=FAIL; - } + //switch off rate correction: no value read from load calib/load settings) + if(myTau == -1){ + if(getRateCorrectionEnable()){ + ret = FAIL; + setRateCorrection(0); + strcat(mess,"Cannot set Rate correction. No default tau provided. Deactivating Rate Correction\n"); + cprintf(RED,"%s",mess); } } + + //normal tau value (only if enabled) + else if (getRateCorrectionEnable()){ + int64_t retvalTau = setRateCorrection(myTau); + if(myTau != retvalTau){ + cprintf(RED,"%s",mess); + ret=FAIL; + } + } + retval = getSettings(); #else @@ -2027,10 +2009,6 @@ int set_module(int file_des) { free(myChan); free(myDac); free(myAdc); -#ifdef EIGERD - free(myGain); - free(myOffset); -#endif #endif return ret; } @@ -2048,10 +2026,6 @@ int get_module(int file_des) { sls_detector_module myModule; #ifdef SLS_DETECTOR_FUNCTION_LIST -#ifdef EIGERD - int *myGain = (int*)malloc(getNumberOfGainsPerModule()*sizeof(int)); - int *myOffset = (int*)malloc(getNumberOfOffsetsPerModule()*sizeof(int)); -#endif int *myChip=(int*)malloc(getNumberOfChipsPerModule()*sizeof(int)); int *myChan=(int*)malloc(getNumberOfChannelsPerModule()*sizeof(int)); int *myDac=(int*)malloc(getNumberOfDACsPerModule()*sizeof(int)); @@ -2082,16 +2056,6 @@ int get_module(int file_des) { sprintf(mess,"could not allocate chans\n"); ret=FAIL; } -#ifdef EIGERD - if (!myGain){ - sprintf(mess,"could not allocate gains\n"); - ret=FAIL; - } - if (!myOffset){ - sprintf(mess,"could not allocate offsets\n"); - ret=FAIL; - } -#endif myModule.ndac=getNumberOfDACsPerModule(); myModule.nchip=getNumberOfChipsPerModule(); myModule.nchan=getNumberOfChannelsPerModule(); @@ -2114,18 +2078,7 @@ int get_module(int file_des) { if (imod>=0) { ret=OK; myModule.module=imod; -#ifdef EIGERD - getModule(&myModule, myGain, myOffset); -#ifdef VERBOSE - for(i=0;i=0. Switching off Rate Correction\n"); + cprintf(RED,"%s",mess); } - cprintf(RED,"%s",mess); } //set rate @@ -4020,7 +3967,7 @@ int set_rate_correct(int file_des) { } //32 bit mode else{ - int64_t retval = setRateCorrection(tau_ns); //tau_ns will not be -1 here + int64_t retval = setRateCorrection(tau_ns); if(tau_ns != retval){ cprintf(RED,"%s",mess); ret=FAIL; diff --git a/slsDetectorSoftware/threadFiles/Task.h b/slsDetectorSoftware/threadFiles/Task.h index 785298d46..95472eb4b 100644 --- a/slsDetectorSoftware/threadFiles/Task.h +++ b/slsDetectorSoftware/threadFiles/Task.h @@ -106,29 +106,31 @@ private: class Task: public virtual slsDetectorDefs{ public: /* Return: int, Param: int */ - Task(func1_t * t): m1(t),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){}; + Task(func1_t * t): m1(t),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(0){}; /* Return: int, Param: string,int */ - Task(func2_t * t): m1(0),m2(t),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){}; + Task(func2_t * t): m1(0),m2(t),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(0){}; /* Return: string, Param: string */ - Task(func1_t * t): m1(0),m2(0),m3(t),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){}; + Task(func1_t * t): m1(0),m2(0),m3(t),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(0){}; /* Return: char*, Param: char* */ - Task(func1_t * t): m1(0),m2(0),m3(0),m4(t),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){}; + Task(func1_t * t): m1(0),m2(0),m3(0),m4(t),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(0){}; /* Return: detectorSettings, Param: int */ - Task(func1_t * t): m1(0),m2(0),m3(0),m4(0),m5(t),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){}; + Task(func1_t * t): m1(0),m2(0),m3(0),m4(0),m5(t),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(0){}; /* Return: detectorSettings, Param: detectorSettings,int */ - Task(func2_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(t),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){}; + Task(func2_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(t),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(0){}; /* Return: int, Param: int,int */ - Task(func2_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(t),m8(0),m9(0),m10(0),m11(0),m12(0){}; - /* Return: int, Param: int,int */ - Task(func3_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(t),m9(0),m10(0),m11(0),m12(0){}; + Task(func2_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(t),m8(0),m9(0),m10(0),m11(0),m12(0),m13(0){}; + /* Return: int, Param: int,int,int */ + Task(func3_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(t),m9(0),m10(0),m11(0),m12(0),m13(0){}; /* Return: int, Param: trimMode,int,int,int */ - Task(func4_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(t),m10(0),m11(0),m12(0){}; + Task(func4_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(t),m10(0),m11(0),m12(0),m13(0){}; /* Return: int, Param: none */ - Task(func0_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(t),m11(0),m12(0){}; - /* Return: char*, Param: networkParameter,string,string */ - Task(func2_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(t),m12(0){}; + Task(func0_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(t),m11(0),m12(0),m13(0){}; + /* Return: char*, Param: networkParameter,string */ + Task(func2_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(t),m12(0),m13(0){}; /* Return: void, Param: none */ - Task(func00_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(t){}; + Task(func00_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(t),m13(0){}; + /* Return: int, Param: int,int,detectorSettings */ + Task(func3_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(t){}; @@ -147,6 +149,7 @@ public: else if(m10) (*m10)(); else if(m11) (*m11)(); else if(m12) (*m12)(); + else if(m13) (*m13)(); } private: @@ -164,16 +167,18 @@ private: func2_t * m6; /* Return: int, Param: int,int */ func2_t * m7; - /* Return: int, Param: int,int */ + /* Return: int, Param: int,int,int */ func3_t * m8; /* Return: int, Param: trimMode,int,int,int */ func4_t * m9; /* Return: int, Param: int */ func0_t * m10; - /* Return: char*, Param: networkParameter,string,string */ + /* Return: char*, Param: networkParameter,string */ func2_t * m11; /* Return: void, Param: none */ func00_t * m12; + /* Return: int, Param: int,int,detectorSettings */ + func3_t * m13; };