added trimval function, but sending trimbits from char to int bug

This commit is contained in:
Maliakal Dhanya 2014-07-21 16:39:36 +02:00
parent e15d6077df
commit 7e46a407c6
17 changed files with 276 additions and 84 deletions

View File

@ -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;

View File

@ -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!!! */

View File

@ -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);

View File

@ -698,15 +698,15 @@ float FebControl::GetDAC(string s){
*/
bool FebControl::SetTrimbits(unsigned int module_num, unsigned char *trimbits){
printf("aaa\n");
unsigned int module_index=0;
if(!GetModuleIndex(module_num,module_index)){
cout<<"Warning could not set trimbits, bad module number."<<endl;
return 0;
}
printf("bbb\n");
if(!Reset()) cout<<"Warning could not reset DAQ."<<endl;
printf("ccc\n");
for(int l_r=0;l_r<2;l_r++){ // l_r loop
unsigned int disable_chip_mask = l_r ? DAQ_CS_BAR_LEFT : DAQ_CS_BAR_RIGHT;

View File

@ -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 <<i<<":"<<tmp_str[0][i]<<"\t\t";
printf("Cjhgkfdjg :%s\n",tmp_str[0].c_str());
feb_controler->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;

View File

@ -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

View File

@ -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<<id));
}
}
else if (imod<0) {
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) {
ret1=detectors[idet]->setAllTrimbits(val,imod);
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
if (ret==-100)
ret=ret1;
else if (ret!=ret1)
ret=-1;
}
}
}
return ret;
}
int multiSlsDetector::loadCalibrationFile(string fname, int imod) {
int id, im, ret;

View File

@ -474,6 +474,14 @@ class multiSlsDetector : public slsDetectorUtils {
int saveSettingsFile(string fname, int nmod=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
*/
int setAllTrimbits(int val, int imod=-1);
/** loads the modules calibration data reading from a file - file name extension is automatically generated! */
int loadCalibrationFile(string fname, int nmod=0);

View File

@ -5719,6 +5719,41 @@ int slsDetector::saveSettingsFile(string fname, int imod) {
int slsDetector::setAllTrimbits(int val, int imod){
int fnum=F_SET_ALL_TRIMBITS;
int retval;
char mess[100];
int ret=OK;
#ifdef VERBOSE
std::cout<< "Setting all trimbits to "<< val << std::endl;
#endif
if (thisDetector->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) {

View File

@ -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!

View File

@ -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();

View File

@ -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;
/**

View File

@ -128,6 +128,8 @@ enum synchronizationMode setSynchronization(enum synchronizationMode arg);
#ifdef EIGERD
void setExternalGating(int enable[]);
void setAllTrimbits(int val);
int getAllTrimbits();
#endif

View File

@ -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;
}

View File

@ -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