diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h index 770a5a405..5050478ed 100644 --- a/slsDetectorSoftware/commonFiles/error_defs.h +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -49,6 +49,7 @@ using namespace std; #define RECEIVER_FRAME_NUM_NOT_SET 0x0000000000000400ULL #define RECEIVER_DYNAMIC_RANGE 0x0000000000000800ULL #define RECEIVER_TEN_GIGA 0x0000000000001000ULL +#define ALLTIMBITS_NOT_SET 0x0000000000002000ULL // 0x00000000FFFFFFFFULL /** @short class returning all error messages for error mask */ @@ -146,6 +147,9 @@ public: if(slsErrorMask&RECEIVER_TEN_GIGA) retval.append("Could not enable/disable 10GbE in the receiver.\n"); + if(slsErrorMask&ALLTIMBITS_NOT_SET) + retval.append("Could not set all trimbits to value.\n"); + return retval; diff --git a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h index c45b7d04b..87bb241aa 100644 --- a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h @@ -89,7 +89,8 @@ enum { F_RESET_COUNTER_BLOCK, /**< resets the counter block memory for gotthard */ F_CALIBRATE_PEDESTAL, /**< starts acquistion, calibrates pedestal and write back to fpga */ - F_ENABLE_TEN_GIGA /**< enable 10Gbe */ + F_ENABLE_TEN_GIGA, /**< enable 10Gbe */ + F_SET_ALL_TRIMBITS /** < set all trimbits to this value */ /* Always append functions hereafter!!! */ diff --git a/slsDetectorSoftware/eigerDetectorServer/EigerHighLevelFunctions.c b/slsDetectorSoftware/eigerDetectorServer/EigerHighLevelFunctions.c index 1e44e5170..eb556796b 100644 --- a/slsDetectorSoftware/eigerDetectorServer/EigerHighLevelFunctions.c +++ b/slsDetectorSoftware/eigerDetectorServer/EigerHighLevelFunctions.c @@ -13,8 +13,8 @@ #include "slsDetectorServer_defs.h" //include port number struct sockaddr_in eiger_socket_addr; -int eiger_max_message_length = 1024; -char eiger_message[1024]; +int eiger_max_message_length = 270000;//263681 +char eiger_message[270000];//263681 int eiger_message_length = 0; int eiger_ret_val=0; @@ -55,6 +55,8 @@ int EigerGetExternalGating(){return eiger_extgating;} int EigerGetExternalGatingPolarity(){return eiger_extgatingpolarity;} int EigerInit(){ + saved_trimbits[0] = -1; + static int passed = 0; if(!passed){ @@ -145,7 +147,7 @@ int EigerSetTrimbits(const int *data){ int ichip; // convert the trimbits from int32 to chars and add border pixels. - for(iy=0;iy<256;y++) { + for(iy=0;iy<256;iy++) { for (ichip=0; ichip<4; ichip++) { for(ix=0;ix<256;ix++) { tt[ip++]=(char)(data[ich++]&(0x3f)); @@ -170,12 +172,13 @@ int EigerSetAllTrimbits(unsigned int value){ int ip=0, ich=0; int iy, ix; int ichip; + int sl=0; // convert the trimbits from int32 to chars and add border pixels. - for(iy=0;iy<256;y++) { + for(iy=0;iy<256;iy++) { for (ichip=0; ichip<4; ichip++) { for(ix=0;ix<256;ix++) { - tt[ip++]=value&0x3f; + tt[ip++]=(char)(value&0x3f); } if (ichip<3) { tt[ip++]=0; @@ -183,30 +186,27 @@ int EigerSetAllTrimbits(unsigned int value){ } } } - eiger_message_length = sprintf(eiger_message,"settrimbits %s", tt); - memcpy(saved_trimbits,data,256*256*4*sizeof(int)); + + char s2[270000]; + strcpy(s2,"settrimbits "); + //for() + sl=strlen(s2); + strncpy(s2+sl,tt, 263680); + s2[263680+sl]='\0'; + + eiger_message_length = strlen(s2); + //eiger_message_length = sprintf(eiger_message,"settrimbits %s", tt); + for (iy=0;iy<263680;++iy) + printf("%d:%c\t\t",iy,tt[iy]); + printf("tfggt:%s , length :%d\n",tt, strlen(tt)); + printf("Command sent:%s , length :%d\n",s2, eiger_message_length); + for(iy=0;iy<256*256*4;++iy) + saved_trimbits[iy] = value; return EigerSendCMD(); } - -/* int EigerGetTrimbits(const int *data){ */ -/* eiger_ret_val=0; */ -/* char tt[263681]; */ -/* tt[263680]='\0'; */ -/* int ip=0, ich=0; */ -/* int iy, ix; */ -/* int ichip; */ - -/* eiger_message_length = sprintf(eiger_message,"settrimbits %s", tt); */ -/* memcpy(data,saved_trimbits,256*256*4*sizeof(int)); */ -/* return EigerSendCMD(); */ -/* } */ - - - - int EigerGetTrimbits(const int *data){ eiger_ret_val=0; char tt[263681]; @@ -222,9 +222,6 @@ int EigerSetAllTrimbits(unsigned int value){ - - - int EigerGetDAC(const char* iname){ eiger_ret_val=1; eiger_message_length = sprintf(eiger_message,"getdacvalue %s",iname); diff --git a/slsDetectorSoftware/eigerDetectorServer/FebControl.cxx b/slsDetectorSoftware/eigerDetectorServer/FebControl.cxx index 6ac58cdd8..9f1ac72d0 100644 --- a/slsDetectorSoftware/eigerDetectorServer/FebControl.cxx +++ b/slsDetectorSoftware/eigerDetectorServer/FebControl.cxx @@ -698,62 +698,62 @@ float FebControl::GetDAC(string s){ */ bool FebControl::SetTrimbits(unsigned int module_num, unsigned char *trimbits){ - - unsigned int module_index=0; - if(!GetModuleIndex(module_num,module_index)){ - cout<<"Warning could not set trimbits, bad module number."<>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(!(WriteRegister(0xfff,DAQ_REG_STATIC_BITS,disable_chip_mask|DAQ_STATIC_BIT_PROGRAM|DAQ_STATIC_BIT_M8)&&SetCommandRegister(DAQ_SET_STATIC_BIT)&&StartDAQOnlyNWaitForFinish())){ + cout<<"Could not select chips"<GetTopLeftAddress(),0,0,1024,trimbits_to_load_r)||!WriteMemory(modules[0]->GetTopRightAddress(),0,0,1024,trimbits_to_load_l)||!StartDAQOnlyNWaitForFinish()) return 0; - } //end row_set loop (groups of 16 rows) - } // end l_r loop + for(int row_set=0;row_set<16;row_set++){ //16 rows at a time + if(row_set==0){ + if(!SetCommandRegister(DAQ_RESET_COMPLETELY|DAQ_SEND_A_TOKEN_IN|DAQ_LOAD_16ROWS_OF_TRIMBITS)){ + cout<<"Warning: Could not SetCommandRegister for loading trim bits."<>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 - return SetStaticBits(); //send the static bits + if(!WriteMemory(modules[0]->GetTopLeftAddress(),0,0,1024,trimbits_to_load_r)||!WriteMemory(modules[0]->GetTopRightAddress(),0,0,1024,trimbits_to_load_l)||!StartDAQOnlyNWaitForFinish()) 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 } diff --git a/slsDetectorSoftware/eigerDetectorServer/FebServer.cxx b/slsDetectorSoftware/eigerDetectorServer/FebServer.cxx index 9217a07b8..ad9e94ed8 100755 --- a/slsDetectorSoftware/eigerDetectorServer/FebServer.cxx +++ b/slsDetectorSoftware/eigerDetectorServer/FebServer.cxx @@ -259,7 +259,12 @@ int main(int argc, char* argv[]){ break; case evSetTrimBits : - feb_controler->SetTrimbits(0,(unsigned char*)data); + tmp_str[0] = GetNextString(data); + /*char tt[263681];*/ + for(int i=0;i<10;i++) + cout <SetTrimbits(0,(unsigned char*)(tmp_str[0].c_str())); return_message.append("\tExecuted: SetTrimBits "); AddNumber(return_message,n[0]); return_message.append("\n"); ret_val = 0; break; diff --git a/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServer b/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServer index 01b998f5d..2937d1af0 100755 Binary files a/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServer and b/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServer differ diff --git a/slsDetectorSoftware/eigerDetectorServer/bin/feb_debug b/slsDetectorSoftware/eigerDetectorServer/bin/feb_debug index 679aad0f5..5c402a301 100755 Binary files a/slsDetectorSoftware/eigerDetectorServer/bin/feb_debug and b/slsDetectorSoftware/eigerDetectorServer/bin/feb_debug differ diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c index fb404469a..9ee7e5205 100644 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c @@ -141,6 +141,7 @@ int64_t getDetectorId(enum idMode arg){ int getDetectorNumber(){ + int res=0; char hostname[100]; if (gethostname(hostname, sizeof hostname) == 0) @@ -159,8 +160,13 @@ int getDetectorNumber(){ pclose(sysFile); sscanf(output,"%x",&res); return res; +*/ + /* + int res=0; + char hostname[100] = "beb000"; + sscanf(hostname,"%x",&res); + return res; */ - } @@ -291,8 +297,9 @@ int setModule(sls_detector_module myMod){ // thisSettings = (enum detectorSettings)myMod.reg; // thisSettings = 0; - setSettings( (enum detectorSettings)myMod.reg); // put the settings in the module register?!?!? -/** set trimbits*/ + setSettings( (enum detectorSettings)myMod.reg,-1); // put the settings in the module register?!?!? + EigerSetTrimbits(myMod.chanregs); + if (detectorModules) copyModule(detectorModules,&myMod); return 0; @@ -598,6 +605,7 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod){ } + int getTotalNumberOfChannels(){return getNumberOfChannelsPerModule();};//NCHIP*NCHAN*nModBoard;} int getTotalNumberOfChips(){return 4;};//NCHIP*nModBoard;} int getTotalNumberOfModules(){return 1;}//nModBoard;} @@ -675,6 +683,21 @@ enum synchronizationMode setSynchronization(enum synchronizationMode arg){ return NO_SYNCHRONIZATION; } +void setAllTrimbits(int val){ + int ichan; + EigerSetAllTrimbits(val); +#ifdef VERBOSE + printf("Copying register %x value %d\n",destMod->reg,val); +#endif + if (detectorModules){ + for (ichan=0; ichan<(detectorModules->nchan); ichan++) { + *((detectorModules->chanregs)+ichan)=val; + } + } +} +int getAllTrimbits(){ + return *((detectorModules->chanregs)); +} #endif diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 6c8275b64..812c0a2f1 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -3721,6 +3721,36 @@ int multiSlsDetector::saveSettingsFile(string fname, int imod) { +int multiSlsDetector::setAllTrimbits(int val, int imod){ + + int ret=-100, ret1,id, im; + + if (decodeNMod(imod, id, im)>=0) { + if (detectors[id]) { + ret1=detectors[id]->setAllTrimbits(val,im); + if(detectors[id]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors; idet++) { + if (detectors[idet]) { + ret1=detectors[idet]->setAllTrimbits(val,imod); + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&val,sizeof(val)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(ALLTIMBITS_NOT_SET)); + } else { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + } + controlSocket->Disconnect(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + +#ifdef VERBOSE + std::cout<< "All trimbits were set to "<< retval << std::endl; +#endif + return retval; +} + + int slsDetector::loadCalibrationFile(string fname, int imod) { diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index e1aecef1d..6ffb42c04 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -510,6 +510,13 @@ class slsDetector : public slsDetectorUtils, public energyConversion { */ int saveSettingsFile(string fname, int imod=-1); + /** sets all the trimbits to a particular value + \param val trimbit value + \param imod module number, -1 means all modules + \returns OK or FAIL + */ + int setAllTrimbits(int val, int imod=-1); + /** loads the modules calibration data reading from a file \param fname file name . If not specified, extension is automatically generated! diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 54423ee72..cee4a387c 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -497,6 +497,9 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings; i++; + descrToFuncMap[i].m_pFuncName="trimval"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings; + i++; descrToFuncMap[i].m_pFuncName="pedestal"; // descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings; @@ -2912,6 +2915,15 @@ string slsDetectorCommand::cmdSettings(int narg, char *args[], int action) { myDet->saveSettingsFile(sval, -1); return string("done"); + } else if (cmd=="trimval") { + if (action==PUT_ACTION){ + if (sscanf(args[1],"%d",&val)) + myDet->setAllTrimbits(val); + else + return string("invalid trimbit value ")+cmd; + } + sprintf(ans,"%d",myDet->setAllTrimbits(-1)); + return ans; } else if (cmd=="pedestal") { if (action==GET_ACTION) return string("cannot get"); @@ -2935,6 +2947,7 @@ string slsDetectorCommand::helpSettings(int narg, char *args[], int action) { os << "threshold eV\n sets the detector threshold in eV"<< std::endl; os << "trimbits fname\n loads the trimfile fname to the detector. If no extension is specified, the serial number of each module will be attached."<< std::endl; os << "trim:mode fname\n trims the detector according to mode (can be noise, beam, improve, fix) and saves the resulting trimbits to file fname."<< std::endl; + os << "trimval i \n sets all the trimbits to i" << std::endl; os << "pedestal i \n starts acquisition for i frames, calculates pedestal and writes back to fpga."<< std::endl; } @@ -2942,6 +2955,7 @@ string slsDetectorCommand::helpSettings(int narg, char *args[], int action) { os << "settings \n gets the settings of the detector"<< std::endl; os << "threshold V\n gets the detector threshold"<< std::endl; os << "trimbits [fname]\n returns the trimfile loaded on the detector. If fname is specified the trimbits are saved to file. If no extension is specified, the serial number of each module will be attached."<< std::endl; + os << "trimval \n returns the value all trimbits are set to. If they are different, returns -1." << std::endl; } return os.str(); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index 431c0bfc0..c2d50008f 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -490,6 +490,14 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { */ virtual int saveSettingsFile(string fname, int imod=-1)=0; + /** sets all the trimbits to a particular value + \param val trimbit value + \param imod module number, -1 means all modules + \returns OK or FAIL + */ + virtual int setAllTrimbits(int val, int imod=-1)=0; + + /** diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h index 824580375..e21e69ded 100644 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h @@ -128,6 +128,8 @@ enum synchronizationMode setSynchronization(enum synchronizationMode arg); #ifdef EIGERD void setExternalGating(int enable[]); +void setAllTrimbits(int val); +int getAllTrimbits(); #endif diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c index 9d216c800..560ad9037 100755 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c @@ -157,7 +157,7 @@ int function_table() { flist[F_STOP_RECEIVER]=&stop_receiver; flist[F_CALIBRATE_PEDESTAL]=&calibrate_pedestal; flist[F_ENABLE_TEN_GIGA]=&enable_ten_giga; - + flist[F_SET_ALL_TRIMBITS]=&set_all_trimbits; #ifdef VERBOSE @@ -3420,3 +3420,60 @@ int enable_ten_giga(int file_des) { /*return ok/fail*/ return ret; } + + + +int set_all_trimbits(int file_des){ + + + int retval; + int arg; + int n; + int ret=OK,ret1=OK; + + sprintf(mess,"can't set sll trimbits\n"); + + n = receiveData(file_des,&arg,sizeof(arg),INT32); + if (n < 0) { + sprintf(mess,"Error reading from socket\n"); + ret=FAIL; + } + +#ifdef VERBOSE + printf("setting all trimbits to %d\n",arg); +#endif +#ifdef SLS_DETECTOR_FUNCTION_LIST + if (differentClients==1 && lockStatus==1 && arg!=GET_READOUT_FLAGS) { + ret=FAIL; + sprintf(mess,"Detector locked by %s\n",lastClientIP); + } else { + if(arg < -1){ + ret = FAIL; + strcpy(mess,"Cant set trimbits to this value\n"); + }else { + if(arg >= 0) + setAllTrimbits(arg); + retval = getAllTrimbits(); + } + } +#endif + if (ret==OK) { + if (arg!=-1 && arg!=retval) { + ret=FAIL; + sprintf(mess,"Could not set all trimbits: should be %d but is %d\n", arg, retval); + }else if (differentClients) + ret=FORCE_UPDATE; + } + + + //ret could be swapped during sendData + ret1 = ret; + n = sendData(file_des,&ret1,sizeof(ret),INT32); + if (ret==FAIL) { + n = sendData(file_des,mess,sizeof(mess),OTHER); + } else { + n = sendData(file_des,&retval,sizeof(retval),INT32); + } + return ret; + +} diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h index 42814787c..7f1e44ab8 100755 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h @@ -81,5 +81,6 @@ int start_receiver(int); int stop_receiver(int); int calibrate_pedestal(int); int enable_ten_giga(int); +int set_all_trimbits(int); #endif