From 4a4efda69fd0e435b01e7e273b5c0fdb9bbf763b Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Mon, 11 Feb 2013 10:45:41 +0000 Subject: [PATCH] added calibrate pedestal for gotthard git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@456 951219d9-93cf-4727-9268-0efd64621fa3 --- .../commonFiles/sls_detector_funcs.h | 3 +- .../gotthardDetectorServer/firmware_funcs.c | 7 ++- .../gotthardDetectorServer/firmware_funcs.h | 5 +++ .../gotthardDetectorServer/server_funcs.c | 42 ++++++++++++++++++ .../gotthardDetectorServer/server_funcs.h | 3 ++ .../multiSlsDetector/multiSlsDetector.cpp | 26 ++++++++++- .../multiSlsDetector/multiSlsDetector.h | 26 +++++++++-- .../slsDetector/slsDetector.cpp | 43 ++++++++++++++++++- slsDetectorSoftware/slsDetector/slsDetector.h | 19 +++++--- .../slsDetector/slsDetectorCommand.cpp | 29 +++++++++++-- .../slsDetector/slsDetectorUtils.h | 5 +++ 11 files changed, 190 insertions(+), 18 deletions(-) diff --git a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h index 73bf29d2a..e03669351 100644 --- a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h @@ -130,8 +130,9 @@ enum { F_ENABLE_FILE_WRITE, /**< sets the receiver file write */ - F_SET_FRAME_INDEX /**< sets the receiver frame index */ + F_SET_FRAME_INDEX, /**< sets the receiver frame index */ + F_CALIBRATE_PEDESTAL /**< starts acquistion, calibrates pedestal and write back to fpga */ /* Always append functions hereafter!!! */ }; diff --git a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c index b79af8c8e..2a0d428dc 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c +++ b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c @@ -2286,6 +2286,11 @@ int resetCounterBlock(int startACQ){ } - +int calibratePedestal(int frames){ + + printf("In Calibrate Pedestal\n"); + + return 0; +} diff --git a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.h b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.h index 2873cd1fb..1ef8de85c 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.h +++ b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.h @@ -142,6 +142,11 @@ int setSynchronization(int s); int loadImage(int index, short int ImageVals[]); int readCounterBlock(int startACQ, short int CounterVals[]); int resetCounterBlock(int startACQ); + +int calibratePedestal(int frames); + + + /* u_int32_t setNBits(u_int32_t); diff --git a/slsDetectorSoftware/gotthardDetectorServer/server_funcs.c b/slsDetectorSoftware/gotthardDetectorServer/server_funcs.c index 2aab106fe..9a40d5c40 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/server_funcs.c +++ b/slsDetectorSoftware/gotthardDetectorServer/server_funcs.c @@ -184,6 +184,7 @@ int function_table() { flist[F_RESET_COUNTER_BLOCK]=&reset_counter_block; flist[F_START_RECEIVER]=&start_receiver; flist[F_STOP_RECEIVER]=&stop_receiver; + flist[F_CALIBRATE_PEDESTAL]=&calibrate_pedestal; return OK; } @@ -2963,3 +2964,44 @@ int stop_receiver(int file_des) { + + +int calibrate_pedestal(int file_des){ + + int ret=OK; + int retval=-1; + int n; + int frames; + + sprintf(mess,"Could not calibrate pedestal\n"); + + n = receiveDataOnly(file_des,&frames,sizeof(frames)); + if (n < 0) { + sprintf(mess,"Error reading from socket\n"); + ret=FAIL; + } + + if (ret==OK) { + if (differentClients==1 && lockStatus==1) { + ret=FAIL; + sprintf(mess,"Detector locked by %s\n",lastClientIP); + } else + ret=calibratePedestal(frames); + } + + if(ret==OK){ + if (differentClients) + ret=FORCE_UPDATE; + } + + /* send answer */ + /* send OK/failed */ + n = sendDataOnly(file_des,&ret,sizeof(ret)); + if (ret==FAIL) + n += sendDataOnly(file_des,mess,sizeof(mess)); + else + n += sendDataOnly(file_des,&retval,sizeof(retval)); + + /*return ok/fail*/ + return ret; +} diff --git a/slsDetectorSoftware/gotthardDetectorServer/server_funcs.h b/slsDetectorSoftware/gotthardDetectorServer/server_funcs.h index a71664b9d..cd43ec862 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/server_funcs.h +++ b/slsDetectorSoftware/gotthardDetectorServer/server_funcs.h @@ -90,4 +90,7 @@ int reset_counter_block(int); int start_receiver(int); int stop_receiver(int); + +int calibrate_pedestal(int); + #endif diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index d2c6d5b5b..4e6a2e6ca 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -1575,8 +1575,12 @@ int multiSlsDetector::setROI(int nroi, int *xmin, int *xmax, int *ymin, int *yma }; -*/ +int multiSlsDetector::getROI(int nroi, int *xmin, int *xmax, int *ymin, int *ymax){ + + +}; +*/ double* multiSlsDetector::decodeData(int *datain, double *fdata) { double *dataout; @@ -3921,3 +3925,23 @@ int64_t multiSlsDetector::clearAllErrorMask(){ return getErrorMask(); } + + + + +int multiSlsDetector::calibratePedestal(int frames){ + int ret=-100, ret1; + + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + ret1=detectors[idet]->calibratePedestal(frames); + if (ret==-100) + ret=ret1; + else if (ret!=ret1) + ret=-1; + } + } + + return ret; +} + diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 21b64f1d8..295e547a8 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -622,12 +622,25 @@ class multiSlsDetector : public slsDetectorUtils { /** set roi - - not yet implemented + \param nroi number of rois + \param xmin x minimum of roi + \param xmax x maximum of roi + \param ymin y minimum of roi + \param ymax y maximum of roi + \returns number of rois added */ - int setROI(int nroi=-1, int *xmin=NULL, int *xmax=NULL, int *ymin=NULL, int *ymax=NULL); + //int setROI(int nroi=-1, int *xmin=NULL, int *xmax=NULL, int *ymin=NULL, int *ymax=NULL); - + /** + get roi + \param nroi number of rois + \param xmin x minimum of roi + \param xmax x maximum of roi + \param ymin y minimum of roi + \param ymax y maximum of roi + \returns number of rois + */ + //int getROI(int &xmin, int &xmax, int &ymin, int &ymax); //Corrections @@ -1146,6 +1159,11 @@ class multiSlsDetector : public slsDetectorUtils { */ int64_t clearAllErrorMask(); + /** Starts acquisition, calibrates pedestal and writes to fpga + /returns number of frames + */ + int calibratePedestal(int frames = 0); + protected: diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 4457c187e..a4b9ef7ae 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -3911,11 +3911,19 @@ int slsDetector::setDynamicRange(int n){ return thisDetector->dynamicRange; }; -/* +/* int slsDetector::setROI(int nroi, int *xmin, int *xmax, int *ymin, int *ymax){ + return thisDetector->nROI; +}; + + +int slsDetector::getROI(int nroi, int *xmin, int *xmax, int *ymin, int *ymax){ + + + return thisDetector->nROI; }; */ @@ -6146,4 +6154,37 @@ int slsDetector::setFrameIndex(int index){ } +int slsDetector::calibratePedestal(int frames){ + int ret=FAIL; + int retval=-1; + int fnum=F_CALIBRATE_PEDESTAL; + char mess[100]; + +#ifdef VERBOSE + std::cout<<"Calibrating Pedestal " <onlineFlag==ONLINE_FLAG) { + if (controlSocket) { + if (controlSocket->Connect()>=0) { + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&frames,sizeof(frames)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + controlSocket->Disconnect(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + } + + return retval; +} + + diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 0677e1b38..266d66bb4 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -1038,16 +1038,18 @@ class slsDetector : public slsDetectorUtils, public energyConversion { int getDataBytes(){return thisDetector->dataBytes;}; - - /** set roi - - not yet implemented + \param nroi number of rois + \param xmin x minimum of roi + \param xmax x maximum of roi + \param ymin y minimum of roi + \param ymax y maximum of roi + \returns number of rois added */ - int setROI(int nroi=-1, int *xmin=NULL, int *xmax=NULL, int *ymin=NULL, int *ymax=NULL); - + //int setROI(int nroi=-1, int *xmin=NULL, int *xmax=NULL, int *ymin=NULL, int *ymax=NULL); + /** set/get readout flags @@ -1523,6 +1525,11 @@ class slsDetector : public slsDetectorUtils, public energyConversion { int fillModuleMask(int *mM); + /** Starts acquisition, calibrates pedestal and writes to fpga + /returns number of frames + */ + int calibratePedestal(int frames = 0); + protected: diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 40a54891d..27f7f5cc1 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -383,6 +383,9 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDetectorSize; i++; + //descrToFuncMap[i].m_pFuncName="roi"; // + //descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDetectorSize; + //i++; /* flags */ @@ -461,6 +464,13 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings; i++; + + descrToFuncMap[i].m_pFuncName="pedestal"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings; + i++; + + + /* pots */ descrToFuncMap[i].m_pFuncName="vthreshold"; // @@ -2543,7 +2553,9 @@ string slsDetectorCommand::cmdDetectorSize(int narg, char *args[], int action) { if (action==PUT_ACTION) { if (cmd=="maxmod") return string("cannot put!"); + // else if (cmd=="roi"){ + // } else if (sscanf(args[1],"%d",&val)) ; else @@ -2594,11 +2606,9 @@ string slsDetectorCommand::cmdSettings(int narg, char *args[], int action) { return helpSettings(narg,args,action); int val=-1;//ret, char ans[1000]; + + // portType index; - - - - // if (sscanf(args[1],"%d",&val)) // ; // else @@ -2672,6 +2682,15 @@ string slsDetectorCommand::cmdSettings(int narg, char *args[], int action) { myDet->saveSettingsFile(sval, -1); return string("done"); + } else if (cmd=="pedestal") { + if (action==GET_ACTION) + return string("cannot get"); + if (sscanf(args[1],"%d",&val)){ + sprintf(ans,"%d",myDet->calibratePedestal(val)); + return string(ans); + }else + return string("cannot parse frame number")+cmd; + } return string("unknown settings command ")+cmd; @@ -2686,6 +2705,8 @@ 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 << "pedestal i \n starts acquisition for i frames, calculates pedestal and writes back to fpga."<< std::endl; + } if (action==GET_ACTION || action==HELP_ACTION) { os << "settings \n gets the settings of the detector"<< std::endl; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index 242da2afa..30a26a0b4 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -650,6 +650,11 @@ virtual int exitReceiver()=0; virtual int enableWriteToFile(int enable=-1)=0; +/** Starts acquisition, calibrates pedestal and writes to fpga + /returns number of frames +*/ +virtual int calibratePedestal(int frames = 0)=0; + protected: