diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h index c010f26ba..fed6af415 100644 --- a/slsDetectorSoftware/commonFiles/error_defs.h +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -8,16 +8,14 @@ #ifndef ERROR_DEFS_H_ #define ERROR_DEFS_H_ +#include "ansi.h" +#include "sls_detector_defs.h" +#include #include #include -using namespace std; - - -#include "sls_detector_defs.h" -#include #include - +using namespace std; /** Error flags */ /*Assumption: Only upto 63 detectors */ @@ -26,52 +24,57 @@ using namespace std; #define MULTI_DETECTORS_NOT_ADDED 0x8000000000000000ULL -#define CANNOT_CONNECT_TO_DETECTOR 0x8000000000000000ULL -#define CANNOT_CONNECT_TO_RECEIVER 0x4000000000000000ULL -#define COULDNOT_SET_CONTROL_PORT 0x2000000000000000ULL -#define COULDNOT_SET_STOP_PORT 0x1000000000000000ULL -#define COULDNOT_SET_DATA_PORT 0x0800000000000000ULL -#define FILE_PATH_DOES_NOT_EXIST 0x0400000000000000ULL -#define COULDNOT_CREATE_UDP_SOCKET 0x0200000000000000ULL -#define COULDNOT_CREATE_FILE 0x0100000000000000ULL -#define COULDNOT_ENABLE_COMPRESSION 0x0080000000000000ULL -#define RECEIVER_DET_HOSTNAME_NOT_SET 0x0040000000000000ULL -#define RECEIVER_DET_HOSTTYPE_NOT_SET 0x0020000000000000ULL -#define DETECTOR_TEN_GIGA 0x0010000000000000ULL -#define DETECTOR_ACTIVATE 0x0008000000000000ULL +#define CANNOT_CONNECT_TO_DETECTOR 0x4000000000000000ULL +#define CANNOT_CONNECT_TO_RECEIVER 0x2000000000000000ULL +#define COULDNOT_SET_CONTROL_PORT 0x1000000000000000ULL +#define COULDNOT_SET_STOP_PORT 0x0800000000000000ULL +#define COULDNOT_SET_DATA_PORT 0x0400000000000000ULL +#define FILE_PATH_DOES_NOT_EXIST 0x0200000000000000ULL +#define COULDNOT_CREATE_UDP_SOCKET 0x0100000000000000ULL +#define COULDNOT_CREATE_FILE 0x0080000000000000ULL +#define COULDNOT_ENABLE_COMPRESSION 0x0040000000000000ULL +#define RECEIVER_DET_HOSTNAME_NOT_SET 0x0020000000000000ULL +#define RECEIVER_DET_HOSTTYPE_NOT_SET 0x0010000000000000ULL +#define DETECTOR_TEN_GIGA 0x0008000000000000ULL +#define DETECTOR_ACTIVATE 0x0004000000000000ULL +#define COULD_NOT_CONFIGURE_MAC 0x0002000000000000ULL +#define COULDNOT_START_RECEIVER 0x0001000000000000ULL // default error like starting threads +#define COULDNOT_STOP_RECEIVER 0x0000800000000000ULL // 0xFFFFFFFF00000000ULL -#define COULD_NOT_CONFIGURE_MAC 0x0000000000000001ULL -#define COULDNOT_SET_NETWORK_PARAMETER 0x0000000000000002ULL -#define COULDNOT_SET_ROI 0x0000000000000004ULL -#define RECEIVER_READ_FREQUENCY 0x0000000000000008ULL -#define SETTINGS_NOT_SET 0x0000000000000010ULL -#define SETTINGS_FILE_NOT_OPEN 0x0000000000000020ULL -#define COULDNOT_START_RECEIVER 0x0000000000000040ULL // default error like starting threads -#define COULDNOT_STOP_RECEIVER 0x0000000000000080ULL -#define DETECTOR_TIMER_VALUE_NOT_SET 0x0000000000000100ULL -#define RECEIVER_ACQ_PERIOD_NOT_SET 0x0000000000000200ULL -#define RECEIVER_FRAME_NUM_NOT_SET 0x0000000000000400ULL -#define RECEIVER_DYNAMIC_RANGE 0x0000000000000800ULL -#define RECEIVER_TEN_GIGA 0x0000000000001000ULL -#define ALLTIMBITS_NOT_SET 0x0000000000002000ULL -#define COULD_NOT_SET_SPEED_PARAMETERS 0x0000000000004000ULL -#define COULD_NOT_SET_READOUT_FLAGS 0x0000000000008000ULL -#define COULD_NOT_SET_FIFO_DEPTH 0x0000000000010000ULL -#define COULD_NOT_SET_COUNTER_BIT 0x0000000000020000ULL -#define COULD_NOT_PULSE_PIXEL 0x0000000000040000ULL -#define COULD_NOT_PULSE_PIXEL_NMOVE 0x0000000000080000ULL -#define COULD_NOT_PULSE_CHIP 0x0000000000100000ULL -#define COULD_NOT_SET_RATE_CORRECTION 0x0000000000200000ULL -#define DETECTOR_NETWORK_PARAMETER 0x0000000000400000ULL -#define RATE_CORRECTION_NOT_32or16BIT 0x0000000000800000ULL -#define RATE_CORRECTION_NO_TAU_PROVIDED 0x0000000001000000ULL -#define PROGRAMMING_ERROR 0x0000000002000000ULL -#define RECEIVER_ACTIVATE 0x0000000004000000ULL -#define DATA_STREAMING 0x0000000008000000ULL -#define RESET_ERROR 0x0000000010000000ULL -#define POWER_CHIP 0x0000000020000000ULL + +#define COULDNOT_SET_NETWORK_PARAMETER 0x0000000000000001ULL +#define COULDNOT_SET_ROI 0x0000000000000002ULL +#define RECEIVER_READ_FREQUENCY 0x0000000000000004ULL +#define SETTINGS_NOT_SET 0x0000000000000008ULL +#define SETTINGS_FILE_NOT_OPEN 0x0000000000000010ULL +#define DETECTOR_TIMER_VALUE_NOT_SET 0x0000000000000020ULL +#define RECEIVER_ACQ_PERIOD_NOT_SET 0x0000000000000040ULL +#define RECEIVER_FRAME_NUM_NOT_SET 0x0000000000000080ULL +#define RECEIVER_DYNAMIC_RANGE 0x0000000000000100ULL +#define RECEIVER_TEN_GIGA 0x0000000000000200ULL +#define ALLTIMBITS_NOT_SET 0x0000000000000400ULL +#define COULD_NOT_SET_SPEED_PARAMETERS 0x0000000000000800ULL +#define COULD_NOT_SET_READOUT_FLAGS 0x0000000000001000ULL +#define COULD_NOT_SET_FIFO_DEPTH 0x0000000000002000ULL +#define COULD_NOT_SET_COUNTER_BIT 0x0000000000004000ULL +#define COULD_NOT_PULSE_PIXEL 0x0000000000008000ULL +#define COULD_NOT_PULSE_PIXEL_NMOVE 0x0000000000010000ULL +#define COULD_NOT_PULSE_CHIP 0x0000000000020000ULL +#define COULD_NOT_SET_RATE_CORRECTION 0x0000000000040000ULL +#define DETECTOR_NETWORK_PARAMETER 0x0000000000080000ULL +#define RATE_CORRECTION_NOT_32or16BIT 0x0000000000100000ULL +#define RATE_CORRECTION_NO_TAU_PROVIDED 0x0000000000200000ULL +#define PROGRAMMING_ERROR 0x0000000000400000ULL +#define RECEIVER_ACTIVATE 0x0000000000800000ULL +#define DATA_STREAMING 0x0000000001000000ULL +#define RESET_ERROR 0x0000000002000000ULL +#define POWER_CHIP 0x0000000004000000ULL +#define RECEIVER_READ_TIMER 0x0000000008000000ULL +#define RECEIVER_ACQ_TIME_NOT_SET 0x0000000010000000ULL +#define RECEIVER_FLIPPED_DATA_NOT_SET 0x0000000020000000ULL + // 0x00000000FFFFFFFFULL /** @short class returning all error messages for error mask */ class errorDefs { @@ -225,6 +228,12 @@ public: if(slsErrorMask&POWER_CHIP) retval.append("Could not power on/off/get the chip\n"); + if(slsErrorMask&RECEIVER_READ_TIMER) + retval.append("Could not set receiver read timer\n"); + + if(slsErrorMask&RECEIVER_FLIPPED_DATA_NOT_SET) + retval.append("Could not set receiver flipped data/bottom\n"); + //------------------------------------------------------ length of message diff --git a/slsDetectorSoftware/eigerDetectorServer/Beb.c b/slsDetectorSoftware/eigerDetectorServer/Beb.c index a3025fea9..5299f1d37 100644 --- a/slsDetectorSoftware/eigerDetectorServer/Beb.c +++ b/slsDetectorSoftware/eigerDetectorServer/Beb.c @@ -149,7 +149,7 @@ void Beb_Beb(){ -void Beb_GetModuleCopnfiguration(int* master, int* top){ +void Beb_GetModuleConfiguration(int* master, int* top, int* normal){ *top = 0; *master = 0; //mapping new memory to read master top module configuration @@ -168,6 +168,8 @@ void Beb_GetModuleCopnfiguration(int* master, int* top){ *top = 1; if(ret&MASTER_BIT_MASK) *master = 1; + if(ret&NORMAL_MODULE_BIT_MASK) + *normal = 1; //close file pointer Beb_close(fd,csp0base); } diff --git a/slsDetectorSoftware/eigerDetectorServer/Beb.h b/slsDetectorSoftware/eigerDetectorServer/Beb.h index 9431701ea..8aeaac0a8 100644 --- a/slsDetectorSoftware/eigerDetectorServer/Beb.h +++ b/slsDetectorSoftware/eigerDetectorServer/Beb.h @@ -45,7 +45,7 @@ struct BebInfo{ unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb); - void Beb_GetModuleCopnfiguration(int* master, int* top); + void Beb_GetModuleConfiguration(int* master, int* top, int* normal); void Beb_EndofDataSend(int tengiga); int Beb_SetMasterViaSoftware(); diff --git a/slsDetectorSoftware/eigerDetectorServer/FebControl.c b/slsDetectorSoftware/eigerDetectorServer/FebControl.c index a5dd9ae83..1786f16a3 100644 --- a/slsDetectorSoftware/eigerDetectorServer/FebControl.c +++ b/slsDetectorSoftware/eigerDetectorServer/FebControl.c @@ -61,6 +61,7 @@ int Feb_Control_current_index; int Feb_Control_counter_bit = 1; int Feb_control_master = 0; +int Feb_control_normal = 0; unsigned int Feb_Control_rate_correction_table[1024]; double Feb_Control_rate_meas[16384]; @@ -181,11 +182,12 @@ void Feb_Control_FebControl(){ -int Feb_Control_Init(int master, int top, int module_num){ +int Feb_Control_Init(int master, int top, int normal, int module_num){ unsigned int i; Feb_Control_module_number = 0; Feb_Control_current_index = 0; Feb_control_master = master; + Feb_control_normal = normal; //global send Feb_Control_AddModule1(0,1,0xff,0,1); @@ -492,59 +494,94 @@ float Feb_Control_DACToVoltage(unsigned int digital,unsigned int nsteps,float vm } -int Feb_Control_SetHighVoltage(float value){ - return Feb_Control_SetHighVoltage1(Feb_Control_module_number,value); -} +//only master gets to call this function +int Feb_Control_SetHighVoltage(int value){ -int Feb_Control_SetHighVoltage1(unsigned int module_num,float value){ - unsigned int module_index=0; - unsigned int i; - - if(Feb_control_master){//if(Module_TopAddressIsValid(&modules[module_index])){ - if(!Feb_Control_GetModuleIndex(module_num,&module_index)){/*||!Module_TopAddressIsValid(&modules[module_index])){*/ - cprintf(RED,"Error could not set high voltage module number %d invalid.\n",module_num); - return 0; - } - }else + if(!Feb_control_normal){ + cprintf(RED,"\nError: Setting High Voltage not implemented for special modules\n"); return 0; + } - if(!Feb_Control_SendHighVoltage(Module_GetTopRightAddress(&modules[module_index]),&value)) return 0; - - if(module_index!=0) Module_SetHighVoltage(&modules[module_index],value); - else for(i=0;i2*l) { @@ -1221,15 +1222,15 @@ int64_t getFrames(){ int64_t setExposureTime(int64_t value){ if (value!=-1){ printf("\nSetting exptime to %lldns\n",(long long int)value); - value*=(1E-3*clockdivider); + value*=(1E-3*clockdivider_exptime); } - int64_t retval = set64BitReg(value,SET_EXPTIME_LSB_REG, SET_EXPTIME_MSB_REG)/(1E-3*clockdivider);//(1E-9*CLK_FREQ); + int64_t retval = set64BitReg(value,SET_EXPTIME_LSB_REG, SET_EXPTIME_MSB_REG)/(1E-3*clockdivider_exptime);//(1E-9*CLK_FREQ); printf("Getting exptime: %lldns\n",(long long int)retval); return retval; } int64_t getExposureTime(){ - return get64BitReg(GET_EXPTIME_LSB_REG, GET_EXPTIME_MSB_REG)/(1E-3*clockdivider);//(1E-9*CLK_FREQ); + return get64BitReg(GET_EXPTIME_LSB_REG, GET_EXPTIME_MSB_REG)/(1E-3*clockdivider_exptime);//(1E-9*CLK_FREQ); } int64_t setGates(int64_t value){ @@ -1248,31 +1249,31 @@ int64_t getGates(){ int64_t setPeriod(int64_t value){ if (value!=-1){ printf("\nSetting period to %lldns\n",(long long int)value); - value*=(1E-3*clockdivider); + value*=(1E-3*clockdivider_fc); } - int64_t retval = set64BitReg(value,SET_PERIOD_LSB_REG, SET_PERIOD_MSB_REG)/(1E-3*clockdivider);//(1E-9*CLK_FREQ); + int64_t retval = set64BitReg(value,SET_PERIOD_LSB_REG, SET_PERIOD_MSB_REG)/(1E-3*clockdivider_fc);//(1E-9*CLK_FREQ); printf("Getting period: %lldns\n",(long long int)retval); return retval; } int64_t getPeriod(){ - return get64BitReg(GET_PERIOD_LSB_REG, GET_PERIOD_MSB_REG)/(1E-3*clockdivider);//(1E-9*CLK_FREQ); + return get64BitReg(GET_PERIOD_LSB_REG, GET_PERIOD_MSB_REG)/(1E-3*clockdivider_fc);//(1E-9*CLK_FREQ); } int64_t setDelay(int64_t value){ if (value!=-1){ printf("\nSetting delay to %lldns\n",(long long int)value); - value*=(1E-3*clockdivider); + value*=(1E-3*clockdivider_fc); } - int64_t retval = set64BitReg(value,SET_DELAY_LSB_REG, SET_DELAY_MSB_REG)/(1E-3*clockdivider);//(1E-9*CLK_FREQ); + int64_t retval = set64BitReg(value,SET_DELAY_LSB_REG, SET_DELAY_MSB_REG)/(1E-3*clockdivider_fc);//(1E-9*CLK_FREQ); printf("Getting delay: %lldns\n",(long long int)retval); return retval; } int64_t getDelay(){ - return get64BitReg(GET_DELAY_LSB_REG, GET_DELAY_MSB_REG)/(1E-3*clockdivider);//(1E-9*CLK_FREQ); + return get64BitReg(GET_DELAY_LSB_REG, GET_DELAY_MSB_REG)/(1E-3*clockdivider_fc);//(1E-9*CLK_FREQ); } int64_t setTrains(int64_t value){ diff --git a/slsDetectorSoftware/jungfrauDetectorServer/gitInfo.txt b/slsDetectorSoftware/jungfrauDetectorServer/gitInfo.txt index 28267fca2..c64e4f71a 100644 --- a/slsDetectorSoftware/jungfrauDetectorServer/gitInfo.txt +++ b/slsDetectorSoftware/jungfrauDetectorServer/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsDetectorSoftware/jungfrauDetectorServer URL: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git/jungfrauDetectorServer Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git -Repsitory UUID: 69e9e77d6b5517bc932f2ff4d54386d886ef6c39 -Revision: 53 +Repsitory UUID: 230d6b36e9852214f4ba5ae7c92647f35000b24d +Revision: 56 Branch: developer Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 1296 -Last Changed Date: 2016-11-08 15:25:16 +0100 +Last Changed Rev: 1313 +Last Changed Date: 2016-11-30 10:36:34 +0100 diff --git a/slsDetectorSoftware/jungfrauDetectorServer/gitInfoJungfrau.h b/slsDetectorSoftware/jungfrauDetectorServer/gitInfoJungfrau.h index 686601243..633eb8933 100644 --- a/slsDetectorSoftware/jungfrauDetectorServer/gitInfoJungfrau.h +++ b/slsDetectorSoftware/jungfrauDetectorServer/gitInfoJungfrau.h @@ -1,11 +1,11 @@ //#define SVNPATH "" #define SVNURL "git@git.psi.ch:sls_detectors_software/sls_detector_software.git/jungfrauDetectorServer" //#define SVNREPPATH "" -#define SVNREPUUID "69e9e77d6b5517bc932f2ff4d54386d886ef6c39" -//#define SVNREV 0x1296 +#define SVNREPUUID "230d6b36e9852214f4ba5ae7c92647f35000b24d" +//#define SVNREV 0x1313 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "Dhanya_Maliakal" -#define SVNREV 0x1296 -#define SVNDATE 0x20161108 +#define SVNREV 0x1313 +#define SVNDATE 0x20161130 // diff --git a/slsDetectorSoftware/jungfrauDetectorServer/jungfrauDetectorServerv2.2.0 b/slsDetectorSoftware/jungfrauDetectorServer/jungfrauDetectorServerv2.2.1 similarity index 74% rename from slsDetectorSoftware/jungfrauDetectorServer/jungfrauDetectorServerv2.2.0 rename to slsDetectorSoftware/jungfrauDetectorServer/jungfrauDetectorServerv2.2.1 index cdbf31638..6014d803c 100755 Binary files a/slsDetectorSoftware/jungfrauDetectorServer/jungfrauDetectorServerv2.2.0 and b/slsDetectorSoftware/jungfrauDetectorServer/jungfrauDetectorServerv2.2.1 differ diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 104f30e58..bcc4cb06d 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -251,7 +251,7 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1) #ifdef VERBOSE cout << thisMultiDetector->detectorIds[i] << endl; #endif - detectors[i]=new slsDetector(thisMultiDetector->detectorIds[i], this); + detectors[i]=new slsDetector(i, thisMultiDetector->detectorIds[i], this); // setAngularConversionPointer(detectors[i]->getAngularConversionPointer(),detectors[i]->getNModsPointer(),detectors[i]->getNChans()*detectors[i]->getNChips(), i); @@ -268,7 +268,12 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1) getNMods(); getMaxMods(); - threadStarted = false; + dataSocketsStarted = false; + for(int i=0;idetectorIds[pos]=detectors[pos]->getDetectorId(); thisMultiDetector->numberOfDetectors++; @@ -682,7 +687,7 @@ int multiSlsDetector::addSlsDetector(const char *name, int pos) { #ifdef VERBOSE cout << "Detector " << id << " already exists" << endl; #endif - s=new slsDetector(id, this); + s=new slsDetector(pos, id, this); if (s->getHostname()==string(name)) break; delete s; @@ -723,7 +728,7 @@ int multiSlsDetector::addSlsDetector(const char *name, int pos) { #ifdef VERBOSE cout << "Creating detector " << id << " of type " << getDetectorType(t) << endl; #endif - s=new slsDetector(t, id, this); + s=new slsDetector(pos, t, id, this); if (online) { s->setTCPSocket(name); setOnline(ONLINE_FLAG); @@ -756,7 +761,7 @@ int multiSlsDetector::addSlsDetector(detectorType t, int pos) { #ifdef VERBOSE cout << "Creating detector " << id << " of type " << getDetectorType(t) << endl; #endif - slsDetector *s=new slsDetector(t, id, this); + slsDetector *s=new slsDetector(pos, t, id, this); s=NULL; #ifdef VERBOSE cout << "Adding it to the multi detector structure" << endl; @@ -1415,41 +1420,46 @@ int multiSlsDetector::startReadOut(){ int* multiSlsDetector::getDataFromDetector() { int nel=thisMultiDetector->dataBytes/sizeof(int); - int n; - int* retval=new int[nel]; + int n = 0; + int* retval= NULL; int *retdet, *p=retval; - int nodata=1, nodatadet=-1;; + int nodata=1, nodatadet=-1; + int nodatadetectortype = false; + detectorType types = getDetectorsType(); + if(types == EIGER || types == JUNGFRAU){ + nodatadetectortype = true; + } + + if(!nodatadetectortype) + retval=new int[nel]; // cout << "multi: " << thisMultiDetector->dataBytes << endl; for (int id=0; idnumberOfDetectors; id++) { if (detectors[id]) { retdet=detectors[id]->getDataFromDetector(p); - n=detectors[id]->getDataBytes(); if(detectors[id]->getErrorMask()) setErrorMask(getErrorMask()|(1<getDataBytes(); + if (retdet) { + nodata=0; #ifdef VERBOSE - cout << "Detector " << id << " returned " << n << " bytes " << endl; + cout << "Detector " << id << " returned " << n << " bytes " << endl; #endif - } else { - nodatadet=id; + } else { + nodatadet=id; #ifdef VERBOSE - cout << "Detector " << id << " does not have data left " << endl; + cout << "Detector " << id << " does not have data left " << endl; #endif - /*if((detectors[id]->getDetectorsType() != EIGER)||(detectors[id]->getDetectorsType() != JUNGFRAU)) - break;*/ + } + p+=n/sizeof(int); } - p+=n/sizeof(int); } } //eiger returns only null - detectorType types = getDetectorsType(); - if(types == EIGER || types == JUNGFRAU){ - delete [] retval; + if(nodatadetectortype){ return NULL; } @@ -2280,6 +2290,7 @@ double* multiSlsDetector::decodeData(int *datain, int &nn, double *fdata) { } } + return dataout; } @@ -3803,6 +3814,20 @@ int multiSlsDetector::getMaxNumberOfModules(dimension d) { } + +int multiSlsDetector::getFlippedData(dimension d){ + int ret=-100,ret1; + for (int idet=0; idetnumberOfDetectors; idet++) + if (detectors[idet]){ + ret1=detectors[idet]->getFlippedData(d); + if(ret==-100) + ret=ret1; + else if (ret!=ret1) + ret=-1; + } + return ret; +} + int multiSlsDetector::setNumberOfModules(int p, dimension d) { int ret=0;//, ret1; @@ -3842,6 +3867,24 @@ int multiSlsDetector::setNumberOfModules(int p, dimension d) { } + + +int multiSlsDetector::setFlippedData(dimension d, int value){ + int ret=-100,ret1; + for (int idet=0; idetnumberOfDetectors; idet++) + if (detectors[idet]){ + ret1=detectors[idet]->setFlippedData(d,value); + if(ret==-100) + ret=ret1; + else if (ret!=ret1) + ret=-1; + } + return ret; +} + + + + int multiSlsDetector::decodeNMod(int i, int &id, int &im) { #ifdef VERBOSE cout << " Module " << i << " belongs to detector " << id << endl;; @@ -4331,6 +4374,7 @@ int multiSlsDetector::readConfigurationFile(string const fname){ // char ext[100]; setAcquiringFlag(false); + clearAllErrorMask(); string ans; string str; @@ -5042,429 +5086,336 @@ int multiSlsDetector::resetFramesCaught() { } -int multiSlsDetector::createReceivingDataThreads(bool destroy){ - if(!destroy) cprintf(MAGENTA,"Going to create data threads\n"); - else cprintf(MAGENTA,"Going to destroy data threads\n"); +int multiSlsDetector::createReceivingDataSockets(const bool destroy){ - int numReadouts = thisMultiDetector->numberOfDetectors; - if(getDetectorsType() == EIGER) - numReadouts *= 2; + //number of sockets + int numSockets = thisMultiDetector->numberOfDetectors; + int numSocketsPerDetector = 1; + if(getDetectorsType() == EIGER){ + numSocketsPerDetector = 2; + } + numSockets *= numSocketsPerDetector; - - //reset masks - killAllReceivingDataThreads = false; - - //destroy if(destroy){ -#ifdef DEBUG - cout << "Destroying Receiving Data Thread(s)" << endl; -#endif - killAllReceivingDataThreads = true; - for(int i = 0; i < numReadouts; ++i){ - sem_post(&sem_singlewait[i]); - pthread_join(receivingDataThreads[i],NULL); - sem_destroy(&sem_singlewait[i]); - sem_destroy(&sem_singledone[i]); -#ifdef DEBUG - cout << "." << flush << endl; -#endif - } - killAllReceivingDataThreads = false; - threadStarted = false; + cprintf(MAGENTA,"Going to destroy data sockets\n"); + //close socket + for(int i=0;igetReceiver()); + cout<<"rx_hostname:"<h_addr)); + } + //add port + sprintf(dataSocketServerDetails[i],"%s:%d",dataSocketServerDetails[i],DEFAULT_ZMQ_PORTNO + + (i/numSocketsPerDetector)*numSocketsPerDetector + (i%numSocketsPerDetector));//using this instead of i in the offchance, detid doesnt start at 0 (shmget error) + + //create context + context[i] = zmq_ctx_new(); + //create socket + zmqsocket[i] = zmq_socket(context[i], ZMQ_PULL); + //connect socket + zmq_connect(zmqsocket[i], dataSocketServerDetails[i]); + //int hwmval = 10; + //zmq_setsockopt(zmqsocket[i],ZMQ_RCVHWM,&hwmval,sizeof(hwmval)); //set receive HIGH WATER MARK (8-9ms slower//should not drop last packets) + cout << "ZMQ Client[" << i << "] from " << dataSocketServerDetails[i] << endl; + } + + dataSocketsStarted = true; + cout << "Receiving Data Socket(s) created" << endl; + return OK; +} + + + + + + + + + +int multiSlsDetector::getData(const int isocket, const bool masking, int* image, const int size, int &acqIndex, int &frameIndex, int &subframeIndex, string &filename){ + + zmq_msg_t message; + + //scan header------------------------------------------------------------------- + zmq_msg_init (&message); + int len = zmq_msg_recv(&message, zmqsocket[isocket], 0); + if (len == -1) { + cprintf(BG_RED,"Could not read header for socket %d\n",isocket); + zmq_msg_close(&message); + cprintf(RED, "%d message null\n",isocket); + return FAIL; + } + + + // error if you print it + // cout << isocket << " header len:"<startReceivingDataThread(); - //while(true); - - return this_pointer; -} -void multiSlsDetector::startReceivingDataThread(){ +void multiSlsDetector::readFrameFromReceiver(){ - int ithread = currentThreadIndex; //set current thread value index - - char hostname[100] = "tcp://"; - char rx_hostname[100]; - strcpy(rx_hostname, detectors[ithread]->getReceiver()); - cout<<"rx_hostname:"<h_addr)); - } - strcat(hostname,":"); - //server details - //char hostname[100] = "tcp://127.0.0.1:"; - int portno = DEFAULT_ZMQ_PORTNO + ithread; - sprintf(hostname,"%s%d",hostname,portno); - - //socket details - zmq_msg_t message; - void *context; - void *zmqsocket; - context = zmq_ctx_new(); - zmqsocket = zmq_socket(context, ZMQ_PULL); - //int hwmval = 10; - //zmq_setsockopt(zmqsocket,ZMQ_RCVHWM,&hwmval,sizeof(hwmval)); //set receive HIGH WATER MARK (8-9ms slower//should not drop last packets) - cprintf(RED,"connect ret:%d\n",zmq_connect(zmqsocket, hostname)); - cout << "ZMQ Client of " << ithread << " at " << hostname << endl; - cprintf(BLUE,"%d Created socket\n",ithread); - - - //initializations - int numReadoutPerDetector = 1; + //determine number of half readouts and maxX and maxY + int maxX=0,maxY=0; + int numSockets = thisMultiDetector->numberOfDetectors; + int numSocketsPerSLSDetector = 1; bool jungfrau = false; - int expectedsize = 1024*256;/**shouldnt work for other bit modes or anythign*/ - if(getDetectorsType() == EIGER){ - numReadoutPerDetector = 2; - expectedsize = 1024*256; - }else if(getDetectorsType() == JUNGFRAU){ + switch(getDetectorsType()){ + case EIGER: + numSocketsPerSLSDetector = 2; + numSockets *= numSocketsPerSLSDetector; + maxX = thisMultiDetector->numberOfChannel[X]; + maxY = thisMultiDetector->numberOfChannel[Y]; + break; + case JUNGFRAU: jungfrau = true; - expectedsize = 8192*128; + break; + default: + break; } - int singleDatabytes = detectors[ithread/numReadoutPerDetector]->getDataBytes(); - int nel=(singleDatabytes/numReadoutPerDetector)/sizeof(int); - int* image = new int[nel]; - int len,idet = 0; - singleframe[ithread]=NULL; - threadStarted = true; //let calling function know thread started and obtained current + //gui variables + int currentAcquisitionIndex = -1; + int currentFrameIndex = -1; + int currentSubFrameIndex = -1; + string currentFileName = ""; - //infinite loop, exited only (if gui restarted/ enabledatastreaming called) - while(true){ - - - sem_wait(&sem_singlewait[ithread]); //wait for it to be copied - //check to exit thread - if(killAllReceivingDataThreads) - break; - - //scan header------------------------------------------------------------------- - zmq_msg_init (&message); - len = zmq_msg_recv(&message, zmqsocket, 0); - if (len == -1) { - cprintf(BG_RED,"Could not read header for socket %d\n",ithread); - zmq_msg_close(&message); - cprintf(RED, "%d message null\n",ithread); - continue; + //getting sls values + int slsdatabytes = 0, slsmaxchannels = 0, bytesperchannel = 0, slsmaxX = 0, slsmaxY=0, nx=0, ny=0; + if(detectors[0]){ + slsdatabytes = detectors[0]->getDataBytes(); + slsmaxchannels = detectors[0]->getMaxNumberOfChannels(); + bytesperchannel = slsdatabytes/slsmaxchannels; + slsmaxX = detectors[0]->getTotalNumberOfChannels(X); + slsmaxY = detectors[0]->getTotalNumberOfChannels(Y); + } + //getting multi values + nx = getTotalNumberOfChannels(slsDetectorDefs::X); + ny = getTotalNumberOfChannels(slsDetectorDefs::Y); + //calculating offsets (for eiger interleaving ports) + int offsetX[numSockets]; int offsetY[numSockets]; + int bottom[numSockets]; + if(maxX){ + for(int i=0; ioffsetY[i/numSocketsPerSLSDetector] + slsmaxY)) * maxX * bytesperchannel; + //the left half or right half + if(!(i%numSocketsPerSLSDetector)) + offsetX[i] = thisMultiDetector->offsetX[i/numSocketsPerSLSDetector]; + else + offsetX[i] = thisMultiDetector->offsetX[i/numSocketsPerSLSDetector] + (slsmaxX/numSocketsPerSLSDetector); + offsetX[i] *= bytesperchannel; + bottom[i] = detectors[i/numSocketsPerSLSDetector]->getFlippedData(X);/*only for eiger*/ } + } + + int expectedslssize = slsdatabytes/numSocketsPerSLSDetector; + int* image = new int[(expectedslssize/sizeof(int))](); + int nel=(thisMultiDetector->dataBytes)/sizeof(int); + if(nel <= 0){ + cprintf(RED,"Error: Multislsdetector databytes not valid : %d\n", thisMultiDetector->dataBytes); + return; + } + int* multiframe=new int[nel](); - // error if you print it - // cout << ithread << " header len:"<numberOfDetectors); //reset frame memory + //get each frame + for(int isocket=0; isocketnumberOfChannel[X]; -// maxY = thisMultiDetector->numberOfChannel[Y]; -// } -// int numReadouts = numReadoutPerDetector * thisMultiDetector->numberOfDetectors; - -// //initializing variables -// currentFileName=""; -// currentAcquisitionIndex = -1; -// currentFrameIndex = -1; -// currentSubFrameIndex = -1; - - -// //getting values -// int slsdatabytes = 0, slsmaxchannels = 0, bytesperchannel = 0, slsmaxX = 0, slsmaxY=0; -// if(detectors[0]){ -// slsdatabytes = detectors[0]->getDataBytes(); -// slsmaxchannels = detectors[0]->getMaxNumberOfChannels(); -// bytesperchannel = slsdatabytes/slsmaxchannels; -// slsmaxX = detectors[0]->getTotalNumberOfChannels(X); -// slsmaxY = detectors[0]->getTotalNumberOfChannels(Y); -// } -// int nel=(thisMultiDetector->dataBytes)/sizeof(int); -// if(nel <= 0){ -// cprintf(RED,"Error: Multislsdetector databytes not valid : %d\n", thisMultiDetector->dataBytes); -// return; -// } -// int* multiframe=new int[nel]; -// int idet,offsetY,offsetX; -// int halfreadoutoffset = (slsmaxX/numReadoutPerDetector); -// int nx =getTotalNumberOfChannels(slsDetectorDefs::X); -// int ny =getTotalNumberOfChannels(slsDetectorDefs::Y); - -// volatile uint64_t dataThreadMask = 0x0; -// for(int i = 0; i < numReadouts; ++i) -// dataThreadMask|=(1<numberOfDetectors); //reset frame memory - -// //post all of them to start -// for(int ireadout=0; ireadoutoffsetY[idet] + slsmaxY)) * maxX * bytesperchannel; -// //the left half or right half -// if(!(ireadout%numReadoutPerDetector)) -// offsetX = thisMultiDetector->offsetX[idet]; -// else -// offsetX = thisMultiDetector->offsetX[idet] + halfreadoutoffset; -// offsetX *= bytesperchannel; -// //cprintf(BLUE,"offsetx:%d offsety:%d maxx:%d slsmaxX:%d slsmaxY:%d bytesperchannel:%d\n", -// // offsetX,offsetY,maxX,slsmaxX,slsmaxY,bytesperchannel); -// // cprintf(BLUE,"copying bytes:%d\n", (slsmaxX/numReadoutPerDetector)*bytesperchannel); -// //itnerleaving with other detectors - -// //bottom -// if(((idet+1)%2) == 0){ -// for(int i=0;idataBytes)/sizeof(int); if(nel <= 0){ cout << "Multislsdetector databytes not valid :" << thisMultiDetector->dataBytes << endl; acquisitionIndex = -1; return NULL; } int n,complete=OK; int i,k,offsetX, offsetY, maxX, maxY; double dr; int* retval=new int[nel]; int *retdet = NULL, *p=retval; string fullFName=""; string ext=""; int index=-1,f_index=-1,p_index=-1,det_index=-1; double sv0=-1,sv1=-1; if(getDetectorsType() == EIGER){ maxX = thisMultiDetector->numberOfChannel[X]; maxY = thisMultiDetector->numberOfChannel[Y]; } for (int id=0; idnumberOfDetectors; id++) { if (detectors[id]) { n=detectors[id]->getDataBytes(); retdet=detectors[id]->readFrameFromReceiver(fName, acquisitionIndex, frameIndex, subFrameIndex); if(detectors[id]->getErrorMask()) setErrorMask(getErrorMask()|(1<getDataBytes(); if(getDetectorsType() == EIGER){ - //cout << "fname:"<getMaxNumberOfChannels()<<" n:"<getMaxNumberOfChannels(); - k=(int)(detectors[id]->getMaxNumberOfChannels(X)*dr); - //bit mode - //cout << "dr:"<offsetY[id] + detectors[id]->getMaxNumberOfChannels(Y))) * maxX)*dr);//bit mode - offsetX = (int)(thisMultiDetector->offsetX[id]*dr); - //cout << "offsetY"<numberOfDetectors; idet++) { + if (detectors[idet]) { + ret1=detectors[idet]->setReceiverReadTimer(time_in_ms); + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<= 0){ - - if(threadStarted != enable){ + if(dataSocketsStarted != enable){ //destroy data threads - if(threadStarted) - createReceivingDataThreads(true); + if(dataSocketsStarted) + createReceivingDataSockets(true); //create data threads if(enable > 0){ - if(createReceivingDataThreads() == FAIL){ - std::cout << "Could not create data threads in client. Aborting creating data threads in receiver" << std::endl; + if(createReceivingDataSockets() == FAIL){ + std::cout << "Could not create data threads in client. Aborting creating data sockets in receiver" << std::endl; //only for the first det as theres no general one setErrorMask(getErrorMask()|(1<<0)); detectors[0]->setErrorMask((detectors[0]->getErrorMask())|(DATA_STREAMING)); @@ -5709,7 +5679,7 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ } } - }else enable = threadStarted; + }else enable = dataSocketsStarted; int ret=-100, ret1; for (int idet=0; idetnumberOfDetectors; idet++) { @@ -5725,9 +5695,9 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ } /* if(enable == -1) - return threadStarted; + return dataSocketsStarted; */ - return (threadStarted & ret); + return (dataSocketsStarted & ret); } int multiSlsDetector::enableReceiverCompression(int i){ diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 0be2eb72a..6151349fc 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -340,6 +340,12 @@ class multiSlsDetector : public slsDetectorUtils { int getMaxNumberOfChannelsPerDetector(dimension d){return thisMultiDetector->maxNumberOfChannelsPerDetector[d];}; + /** returns the enable if data will be flipped across x or y axis + * \param d axis across which data is flipped + * returns 1 or 0 + */ + int getFlippedData(dimension d=X); + int setMaxNumberOfChannelsPerDetector(dimension d,int i){thisMultiDetector->maxNumberOfChannelsPerDetector[d]=i; return thisMultiDetector->maxNumberOfChannelsPerDetector[d];}; double getScanStep(int index, int istep){return thisMultiDetector->scanSteps[index][istep];}; @@ -979,6 +985,14 @@ class multiSlsDetector : public slsDetectorUtils { int configureMAC(); int setNumberOfModules(int i=-1, dimension d=X); + + /** sets the enable which determines if data will be flipped across x or y axis + * \param d axis across which data is flipped + * \param value 0 or 1 to reset/set or -1 to get value + * \return enable flipped data across x or y axis + */ + int setFlippedData(dimension d=X, int value=-1); + int getMaxNumberOfModules(dimension d=X); int setDynamicRange(int i=-1); @@ -1196,19 +1210,18 @@ class multiSlsDetector : public slsDetectorUtils { int resetFramesCaught(); /** - * Create Receiving Data Threads - * @param destroy is true to destroy all the threads + * Create Receiving Data Sockets + * @param destroy is true to destroy all the sockets * @return OK or FAIL */ - int createReceivingDataThreads(bool destroy = false); + int createReceivingDataSockets(const bool destroy = false); /** Reads frames from receiver through a constant socket */ - //void readFrameFromReceiver(); - int* readFrameFromReceiver(char*, int&, int&, int&); - /** Locks/Unlocks the connection to the receiver + void readFrameFromReceiver(); + /** Locks/Unlocks the connection to the receiver /param lock sets (1), usets (0), gets (-1) the lock /returns lock status of the receiver */ @@ -1276,6 +1289,14 @@ class multiSlsDetector : public slsDetectorUtils { */ int setReadReceiverFrequency(int getFromReceiver, int freq=-1); + /** Sets the read receiver timer + if data required from receiver randomly readRxrFrequency=0, + then the timer between each data stream is set with time_in_ms + @param time_in_ms timer between frames + /returns read receiver timer + */ + int setReceiverReadTimer(int time_in_ms=500); + /** Enable or disable streaming data from receiver to client * @param enable 0 to disable 1 to enable -1 to only get the value * @returns data streaming @@ -1384,35 +1405,17 @@ class multiSlsDetector : public slsDetectorUtils { private: - /** - * Static function - Starts Data Thread of this object - * @param this_pointer pointer to this object - */ - static void* staticstartReceivingDataThread(void *this_pointer); /** - * Thread that receives data packets from receiver + * Gets data from socket */ - void startReceivingDataThread(); + int getData(const int isocket, const bool masking, int* image, const int size, int &acqIndex, int &frameIndex, int &subframeIndex, string &filename); - /* synchronizing between zmq threads */ - sem_t sem_singledone[MAXDET]; - sem_t sem_singlewait[MAXDET]; - int* singleframe[MAXDET]; - - /* Parameters given to the gui picked up from zmq threads*/ - int currentAcquisitionIndex; - int currentFrameIndex; - int currentSubFrameIndex; - string currentFileName; - - pthread_t receivingDataThreads[MAXDET]; - /** Ensures if threads created successfully */ - bool threadStarted; - /** Current Thread Index*/ - int currentThreadIndex; - /** Set to self-terminate data receiving threads waiting for semaphores */ - bool killAllReceivingDataThreads; + /** Ensures if sockets created successfully */ + bool dataSocketsStarted; + void *context[MAXDET]; + void *zmqsocket[MAXDET]; + char dataSocketServerDetails[MAXDET][100]; protected: diff --git a/slsDetectorSoftware/slsDetector/gitInfoLib.h b/slsDetectorSoftware/slsDetector/gitInfoLib.h index c2fbbfdcc..a7e8cf690 100644 --- a/slsDetectorSoftware/slsDetector/gitInfoLib.h +++ b/slsDetectorSoftware/slsDetector/gitInfoLib.h @@ -1,11 +1,11 @@ //#define SVNPATH "" #define SVNURLLIB "git@git.psi.ch:sls_detectors_software/sls_detector_software.git" //#define SVNREPPATH "" -#define SVNREPUUIDLIB "a10faa8aa60e206c4a0a25ae366e9c1e6f024cbc" -//#define SVNREV 0x1297 +#define SVNREPUUIDLIB "230d6b36e9852214f4ba5ae7c92647f35000b24d" +//#define SVNREV 0x1313 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTHLIB "Dhanya_Maliakal" -#define SVNREVLIB 0x1297 -#define SVNDATELIB 0x20161108 +#define SVNREVLIB 0x1313 +#define SVNDATELIB 0x20161130 // diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 1bd6649bb..feee27ccc 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -156,9 +156,10 @@ int slsDetector::freeSharedMemory() { -slsDetector::slsDetector(int id,multiSlsDetector *p) :slsDetectorUtils(), +slsDetector::slsDetector(int pos, int id, multiSlsDetector *p) :slsDetectorUtils(), thisDetector(NULL), detId(id), + posId(pos), parentDet(p), shmId(-1), controlSocket(NULL), @@ -208,9 +209,10 @@ slsDetector::slsDetector(int id,multiSlsDetector *p) :slsDetectorUtils(), -slsDetector::slsDetector(detectorType type, int id,multiSlsDetector *p): slsDetectorUtils(), +slsDetector::slsDetector(int pos, detectorType type, int id, multiSlsDetector *p): slsDetectorUtils(), thisDetector(NULL), detId(id), + posId(pos), parentDet(p), shmId(-1), controlSocket(NULL), @@ -265,9 +267,10 @@ slsDetector::~slsDetector(){ delete thisReceiver; }; -slsDetector::slsDetector(char *name, int id, int cport,multiSlsDetector *p) : slsDetectorUtils(), +slsDetector::slsDetector(int pos, char *name, int id, int cport,multiSlsDetector *p) : slsDetectorUtils(), thisDetector(NULL), detId(id), + posId(pos), parentDet(p), shmId(-1), controlSocket(NULL), @@ -761,6 +764,8 @@ int slsDetector::initializeDetectorSize(detectorType type) { thisDetector->tenGigaEnable=0; thisDetector->acquiringFlag = false; + thisDetector->flippedData[0] = 0; + thisDetector->flippedData[1] = 0; for (int ia=0; iaactionScript[ia],"none"); @@ -1327,13 +1332,14 @@ int slsDetector::activate(int const enable){ #endif if(ret!=FAIL){ - if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE std::cout << "Activating/Deactivating Receiver: " << retval << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->sendInt(fnum,retval,retval); - disconnectData(); + disconnectData(); + } if(ret==FAIL) setErrorMask((getErrorMask())|(RECEIVER_ACTIVATE)); } @@ -1638,15 +1644,16 @@ int slsDetector::setDetectorType(detectorType const type){ //receiver - if((retType != GENERIC) && (setReceiverOnline()==ONLINE_FLAG)) { + if((retType != GENERIC) && (thisDetector->receiverOnlineFlag==ONLINE_FLAG)) { retval = FAIL; - if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE std::cout << "Sending detector type to Receiver " << (int)thisDetector->myDetectorType << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ retval=thisReceiver->sendInt(fnum2,arg,(int)thisDetector->myDetectorType); - disconnectData(); + disconnectData(); + } if(retval==FAIL){ cout << "ERROR: Could not send detector type to receiver" << endl; setErrorMask((getErrorMask())|(RECEIVER_DET_HOSTTYPE_NOT_SET)); @@ -1880,6 +1887,57 @@ int slsDetector::getMaxNumberOfModules(dimension d){ + + +int slsDetector::setFlippedData(dimension d, int value){ + int retval=-1; + int fnum=F_SET_FLIPPED_DATA_RECEIVER; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + int args[2]={X,-1}; + + + if(thisDetector->myDetectorType!= EIGER){ + std::cout << "Flipped Data is not implemented in this detector" << std::endl; + setErrorMask((getErrorMask())|(RECEIVER_FLIPPED_DATA_NOT_SET)); + return -1; + } + +#ifdef VERBOSE + std::cout << std::endl; + std::cout << "Setting/Getting flipped data across axis " << d <<" with value " << value << std::endl; +#endif + if(value > -1){ + thisDetector->flippedData[d] = value; + args[1] = value; + }else + args[1] = thisDetector->flippedData[d]; + + args[0] = d; + + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { + if (connectData() == OK){ + ret=thisReceiver->sendIntArray(fnum,retval,args); + + disconnectData(); + } + + if((args[1] != retval && args[1]>=0) || (ret==FAIL)){ + ret = FAIL; + setErrorMask((getErrorMask())|(RECEIVER_FLIPPED_DATA_NOT_SET)); + } + + if(ret==FORCE_UPDATE) + updateReceiver(); + } + + + return thisDetector->flippedData[d]; +} + + + + /* This function is used to set the polarity and meaning of the digital I/O signals (signal index) @@ -2051,10 +2109,11 @@ int64_t slsDetector::getId( idMode mode, int imod){ retval=SVNREVLIB; retval=(retval<<32) | SVNDATELIB; } else if (mode==RECEIVER_VERSION) { - if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) { - if (connectData() == OK) - ret=thisReceiver->getInt(fnum2,retval); - disconnectData(); + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { + if (connectData() == OK){ + ret=thisReceiver->getInt(fnum2,retval); + disconnectData(); + } if(ret==FORCE_UPDATE) ret=updateReceiver(); } @@ -3824,24 +3883,26 @@ int* slsDetector::readFrame(){ int* slsDetector::getDataFromDetector(int *retval){ - int nel=thisDetector->dataBytes/sizeof(int); - int n; - - int *r=retval; - - - // int* retval=new int[nel]; - - if (retval==NULL) { - retval=new int[nel]; - // cout << "*****"<dataBytes/sizeof(int); + int n; + int *r=retval; - //#ifdef VERBOSE + int nodatadetectortype = false; + detectorType types = getDetectorsType(); + if(types == EIGER || types == JUNGFRAU){ + nodatadetectortype = true; + } + + + if (!nodatadetectortype && retval==NULL) + retval=new int[nel]; + + +#ifdef VERBOSE std::cout<< "getting data "<< thisDetector->dataBytes << " " << nel<< std::endl; - //#endif +#endif controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); #ifdef VERBOSE cout << "ret=" << ret << endl; @@ -3859,11 +3920,12 @@ int* slsDetector::getDataFromDetector(int *retval){ std::cout<< "Detector successfully returned: " << mess << " " << n << std::endl; #endif } - if (r==NULL) { + if ((!nodatadetectortype) && (r==NULL)){ delete [] retval; } return NULL; - } else { + } else if (!nodatadetectortype){ + n=controlSocket->ReceiveDataOnly(retval,thisDetector->dataBytes); //#ifdef VERBOSE @@ -4152,55 +4214,56 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){ //send acquisiton period/frame number to receiver - if((index==FRAME_NUMBER)||(index==FRAME_PERIOD)||(index==CYCLES_NUMBER)){ + if((index==FRAME_NUMBER)||(index==FRAME_PERIOD)||(index==CYCLES_NUMBER)||(index==ACQUISITION_TIME)){ if(ret != FAIL){ int64_t args[2]; retval = -1; args[0] = index; args[1] = thisDetector->timerValue[index]; - if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ //set #frames, #cycles if((index==FRAME_NUMBER)||(index==CYCLES_NUMBER)){ #ifdef VERBOSE - std::cout << "Setting/Getting number of frames " << index <<" to/from receiver " << args[1] << std::endl; + std::cout << "Setting/Getting number of frames*cycles " << index <<" to/from receiver " << args[1] << std::endl; #endif if(thisDetector->timerValue[CYCLES_NUMBER]==0) args[1] = thisDetector->timerValue[FRAME_NUMBER]; else args[1] = thisDetector->timerValue[FRAME_NUMBER]*thisDetector->timerValue[CYCLES_NUMBER]; } - //set period + //set period/exptime else{ #ifdef VERBOSE - std::cout << "Setting/Getting acquisition period " << index << " to/from receiver " << args[1] << std::endl; + if(index==ACQUISITION_TIME) + std::cout << "Setting/Getting acquisition time " << index << " to/from receiver " << args[1] << std::endl; + else + std::cout << "Setting/Getting acquisition period " << index << " to/from receiver " << args[1] << std::endl; #endif - //if acquisition period is zero, then #frames/buffer depends on exposure time and not acq period - if(!args[1]) - args[1] = timerValue[ACQUISITION_TIME]; } char mess[MAX_STR_LENGTH]=""; - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->sendIntArray(fnum2,retval,args,mess); - disconnectData(); + disconnectData(); + } if((args[1] != retval)|| (ret==FAIL)){ ret = FAIL; - if(index==FRAME_PERIOD){ - //exptime sent if acq period = 0 - if(retval){ - if(strstr(mess,"receiver not idle")==NULL) - cout << "ERROR:Acquisition Period in receiver set incorrectly to " << retval << " instead of " << args[1] << endl; - setErrorMask((getErrorMask())|(RECEIVER_ACQ_PERIOD_NOT_SET)); - } + if(index==ACQUISITION_TIME){ + if(strstr(mess,"receiver not idle")==NULL) + cout << "ERROR:Acquisition Time in receiver set incorrectly to " << retval << " instead of " << args[1] << endl; + setErrorMask((getErrorMask())|(RECEIVER_ACQ_TIME_NOT_SET)); + }else if(index==FRAME_PERIOD){ + if(strstr(mess,"receiver not idle")==NULL) + cout << "ERROR:Acquisition Period in receiver set incorrectly to " << retval << " instead of " << args[1] << endl; + setErrorMask((getErrorMask())|(RECEIVER_ACQ_PERIOD_NOT_SET)); }else{ if(strstr(mess,"receiver not idle")==NULL) cout << "ERROR:Number of Frames (* Number of cycles) in receiver set incorrectly to " << retval << " instead of " << args[1] << endl; setErrorMask((getErrorMask())|(RECEIVER_FRAME_NUM_NOT_SET)); } } - if(ret==FORCE_UPDATE) updateReceiver(); } @@ -4722,13 +4785,14 @@ int slsDetector::setDynamicRange(int n){ if(ret != FAIL){ retval = thisDetector->dynamicRange; if((n==-1) && (ret!= FORCE_UPDATE)) n =-1; - if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE std::cout << "Sending/Getting dynamic range to/from receiver " << n << std::endl; #endif - if (connectData() == OK) - ret=thisReceiver->sendInt(fnum2,retval1,n); - disconnectData(); + if (connectData() == OK){ + ret=thisReceiver->sendInt(fnum2,retval1,n); + disconnectData(); + } if ((ret==FAIL) || (retval1 != retval)){ ret = FAIL; cout << "ERROR:Dynamic range in receiver set incorrectly to " << retval1 << " instead of " << retval << endl; @@ -4964,12 +5028,12 @@ int slsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod){ double* slsDetector::decodeData(int *datain, int &nn, double *fdata) { - double *dataout; - if (fdata) { - dataout=fdata; - // printf("not allocating fdata!\n"); - } - else { + + double *dataout; + if (fdata) { + dataout=fdata; + // printf("not allocating fdata!\n"); + } else { if (thisDetector->myDetectorType==JUNGFRAUCTB) { dataout=new double[thisDetector->dataBytes/2]; nn=thisDetector->dataBytes/2; @@ -4980,95 +5044,90 @@ double* slsDetector::decodeData(int *datain, int &nn, double *fdata) { // printf("allocating fdata!\n"); } - const int bytesize=8; + const int bytesize=8; - int ival=0; - char *ptr=(char*)datain; - char iptr; + int ival=0; + char *ptr=(char*)datain; + char iptr; - int nbits=thisDetector->dynamicRange; - int nch=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; - int ipos=0, ichan=0, ibyte; + int nbits=thisDetector->dynamicRange; + int nch=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; + int ipos=0, ichan=0, ibyte; + + if (thisDetector->timerValue[PROBES_NUMBER]==0) { + if (thisDetector->myDetectorType==JUNGFRAUCTB) { - if (thisDetector->timerValue[PROBES_NUMBER]==0) { - if (thisDetector->myDetectorType==JUNGFRAUCTB) { - // cout << "nch " << nch << endl; for (ichan=0; ichandataBytes/2; ichan++) { - // // dataout[ichan]=0; - // ival=0; - // // for (ibyte=0; ibyte<2; ibyte++) { - // ibyte=0; - // iptr=ptr[ichan*2+ibyte]; - // ival|=((iptr<<(ibyte*bytesize))&(0xff<<(ibyte*bytesize))); - // ibyte=1; - // iptr=ptr[ichan*2+ibyte]; - // ival|=((iptr<<(ibyte*bytesize))&(0x3f<<(ibyte*bytesize))); - // // } dataout[ichan]=*((u_int16_t*)ptr); ptr+=2; } - } else { - switch (nbits) { - case 1: - for (ibyte=0; ibytedataBytes; ibyte++) { - iptr=ptr[ibyte]&0x1; - for (ipos=0; ipos<8; ipos++) { - // dataout[ibyte*2+ichan]=((iptr&((0xf)<>ichan)&0xf; - ival=(iptr>>(ipos))&0x1; - dataout[ichan]=ival; - ichan++; + + } else { + switch (nbits) { + case 1: + for (ibyte=0; ibytedataBytes; ibyte++) { + iptr=ptr[ibyte]&0x1; + for (ipos=0; ipos<8; ipos++) { + // dataout[ibyte*2+ichan]=((iptr&((0xf)<>ichan)&0xf; + ival=(iptr>>(ipos))&0x1; + dataout[ichan]=ival; + ichan++; + } + } + break; + case 4: + for (ibyte=0; ibytedataBytes; ibyte++) { + iptr=ptr[ibyte]&0xff; + for (ipos=0; ipos<2; ipos++) { + // dataout[ibyte*2+ichan]=((iptr&((0xf)<>ichan)&0xf; + ival=(iptr>>(ipos*4))&0xf; + dataout[ichan]=ival; + ichan++; + } + } + break; + case 8: + for (ichan=0; ichandataBytes; ichan++) { + ival=ptr[ichan]&0xff; + dataout[ichan]=ival; + } + break; + case 16: + for (ichan=0; ichanmyDetectorType == MYTHEN){ + for (ichan=0; ichandataBytes; ibyte++) { - iptr=ptr[ibyte]&0xff; - for (ipos=0; ipos<2; ipos++) { - // dataout[ibyte*2+ichan]=((iptr&((0xf)<>ichan)&0xf; - ival=(iptr>>(ipos*4))&0xf; - dataout[ichan]=ival; - ichan++; - } - } - break; - case 8: - for (ichan=0; ichandataBytes; ichan++) { - ival=ptr[ichan]&0xff; - dataout[ichan]=ival; - } - break; - case 16: - for (ichan=0; ichanonlineFlag==ONLINE_FLAG) { if (connectControl() == OK){ controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&arg,sizeof(arg)); @@ -5337,7 +5396,7 @@ double slsDetector::getRateCorrectionTau(){ #ifdef VERBOSE std::cout<< "Setting Rate Correction to " << arg << endl; #endif - if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (connectControl() == OK){ controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); @@ -5712,9 +5771,12 @@ char* slsDetector::setReceiver(string receiverIP){ setTimer(FRAME_PERIOD,thisDetector->timerValue[FRAME_PERIOD]); setTimer(FRAME_NUMBER,thisDetector->timerValue[FRAME_NUMBER]); + setTimer(ACQUISITION_TIME,thisDetector->timerValue[ACQUISITION_TIME]); setDynamicRange(thisDetector->dynamicRange); - if(thisDetector->myDetectorType == EIGER) + if(thisDetector->myDetectorType == EIGER){ + setFlippedData(X,-1); activate(-1); + } //std::cout << "***********************************dataStreaming:" << parentDet->enableDataStreamingFromReceiver(-1) << endl << endl; //parentDet->enableDataStreamingFromReceiver(parentDet->enableDataStreamingFromReceiver(-1)); //set scan tag @@ -5843,7 +5905,7 @@ int slsDetector::setUDPConnection(){ int ret = FAIL; int fnum = F_SETUP_RECEIVER_UDP; - char args[3][MAX_STR_LENGTH]; + char args[3][MAX_STR_LENGTH]={"","",""}; char retval[MAX_STR_LENGTH]=""; //called before set up @@ -5881,13 +5943,14 @@ int slsDetector::setUDPConnection(){ #endif //set up receiver for UDP Connection and get receivermac address - if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE std::cout << "Setting up UDP Connection for Receiver " << args[0] << "\t" << args[1] << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->sendUDPDetails(fnum,retval,args); - disconnectData(); + disconnectData(); + } if(ret!=FAIL){ strcpy(thisDetector->receiverUDPMAC,retval); @@ -5918,7 +5981,7 @@ int slsDetector::configureMAC(){ int ret=FAIL; int fnum=F_CONFIGURE_MAC,fnum2=F_RECEIVER_SHORT_FRAME; char mess[MAX_STR_LENGTH]=""; - char arg[6][50]; + char arg[6][50]={"","","","","",""}; char cword[50]="", *pcword; string sword; int retval=-1; @@ -6046,16 +6109,15 @@ int slsDetector::configureMAC(){ pthread_mutex_unlock(&ms); //connect to receiver if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ - if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ #ifdef VERBOSE std::cout << "Sending adc val to receiver " << retval << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->sendInt(fnum2,retval,retval); - disconnectData(); + disconnectData(); + } if(ret==FAIL) setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); - } } } @@ -6655,7 +6717,7 @@ int slsDetector::programFPGA(string fname){ #ifdef VERBOSE std::cout<< "Sending programming binary to detector " << endl; #endif - if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (connectControl() == OK){ controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&filesize,sizeof(filesize)); @@ -6750,7 +6812,7 @@ int slsDetector::resetFPGA(){ #ifdef VERBOSE std::cout<< "Sending reset to FPGA " << endl; #endif - if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (connectControl() == OK){ controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -6786,7 +6848,7 @@ int slsDetector::powerChip(int ival){ #ifdef VERBOSE std::cout<< "Sending power on/off/get to the chip " << endl; #endif - if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (connectControl() == OK){ controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&ival,sizeof(ival)); @@ -7160,10 +7222,10 @@ string slsDetector::checkReceiverOnline() { thisDetector->receiverOnlineFlag=OFFLINE_FLAG; delete dataSocket; dataSocket=NULL; - retval = FAIL; #ifdef VERBOSE std::cout<< "receiver offline!" << std::endl; #endif + return string(thisDetector->receiver_hostname); } else { thisDetector->receiverOnlineFlag=ONLINE_FLAG; dataSocket->SetTimeOut(100); @@ -7171,9 +7233,9 @@ string slsDetector::checkReceiverOnline() { #ifdef VERBOSE std::cout<< "receiver online!" << std::endl; #endif + return string(""); } } - return retval; } @@ -7252,7 +7314,7 @@ int slsDetector::setReceiverTCPSocket(string const name, int const receiver_port string slsDetector::setFilePath(string s) { int fnum = F_SET_RECEIVER_FILE_PATH; int ret = FAIL; - char arg[MAX_STR_LENGTH]; + char arg[MAX_STR_LENGTH]=""; char retval[MAX_STR_LENGTH] = ""; struct stat st; @@ -7269,14 +7331,15 @@ string slsDetector::setFilePath(string s) { } } - else if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + else{ strcpy(arg,s.c_str()); #ifdef VERBOSE std::cout << "Sending file path to receiver " << arg << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->sendString(fnum,retval,arg); - disconnectData(); + disconnectData(); + } if(ret!=FAIL){ pthread_mutex_lock(&ms); fileIO::setFilePath(string(retval)); @@ -7302,41 +7365,40 @@ string slsDetector::setFilePath(string s) { string slsDetector::setFileName(string s) { int fnum=F_SET_RECEIVER_FILE_NAME; int ret = FAIL; - char arg[MAX_STR_LENGTH]; + char arg[MAX_STR_LENGTH]=""; char retval[MAX_STR_LENGTH]=""; if(!s.empty()){ pthread_mutex_lock(&ms); fileIO::setFileName(s); if(thisDetector->myDetectorType == EIGER) - parentDet->setDetectorIndex(detId); + parentDet->setDetectorIndex(posId); else if(parentDet->getNumberOfDetectors()>1) - parentDet->setDetectorIndex(detId); + parentDet->setDetectorIndex(posId); s=parentDet->createReceiverFilePrefix(); pthread_mutex_unlock(&ms); } if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ - if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ - strcpy(arg,s.c_str()); + strcpy(arg,s.c_str()); #ifdef VERBOSE - std::cout << "Sending file name to receiver " << arg << std::endl; + std::cout << "Sending file name to receiver " << arg << std::endl; #endif - if (connectData() == OK) - ret=thisReceiver->sendString(fnum,retval,arg); - disconnectData(); - if(ret!=FAIL){ -#ifdef VERBOSE - std::cout << "Complete file prefix from receiver: " << retval << std::endl; -#endif - pthread_mutex_lock(&ms); - fileIO::setFileName(parentDet->getNameFromReceiverFilePrefix(string(retval))); - pthread_mutex_unlock(&ms); - - } - if(ret==FORCE_UPDATE) - updateReceiver(); + if (connectData() == OK){ + ret=thisReceiver->sendString(fnum,retval,arg); + disconnectData(); } + if(ret!=FAIL){ +#ifdef VERBOSE + std::cout << "Complete file prefix from receiver: " << retval << std::endl; +#endif + pthread_mutex_lock(&ms); + fileIO::setFileName(parentDet->getNameFromReceiverFilePrefix(string(retval))); + pthread_mutex_unlock(&ms); + + } + if(ret==FORCE_UPDATE) + updateReceiver(); } pthread_mutex_lock(&ms); @@ -7365,13 +7427,14 @@ int slsDetector::setFileIndex(int i) { } } - else if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + else{ #ifdef VERBOSE std::cout << "Sending file index to receiver " << arg << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->sendInt(fnum,retval,arg); - disconnectData(); + disconnectData(); + } if(ret!=FAIL){ pthread_mutex_lock(&ms); fileIO::setFileIndex(retval); @@ -7392,18 +7455,18 @@ int slsDetector::startReceiver(){ int ret = FAIL; char mess[MAX_STR_LENGTH] = ""; - if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) { + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { #ifdef VERBOSE std::cout << "Starting Receiver " << std::endl; #endif - if (connectData() == OK) - ret=thisReceiver->executeFunction(fnum,mess); - disconnectData(); - if(ret==FORCE_UPDATE) { - ret=updateReceiver(); - // cout<< "FU"<executeFunction(fnum,mess); + disconnectData(); + } + if(ret==FORCE_UPDATE) + ret=updateReceiver(); + else if (ret == FAIL){ if(strstr(mess,"UDP")!=NULL) setErrorMask((getErrorMask())|(COULDNOT_CREATE_UDP_SOCKET)); else if(strstr(mess,"file")!=NULL) @@ -7430,13 +7493,14 @@ int slsDetector::stopReceiver(){ if(thisDetector->myDetectorType != EIGER && thisDetector->myDetectorType != JUNGFRAU) detectorSendToReceiver(false); - if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) { + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { #ifdef VERBOSE std::cout << "Stopping Receiver " << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->executeFunction(fnum,mess); - disconnectData(); + disconnectData(); + } if(ret==FORCE_UPDATE) ret=updateReceiver(); else if (ret == FAIL) @@ -7455,13 +7519,14 @@ slsDetectorDefs::runStatus slsDetector::startReceiverReadout(){ int retval=-1; runStatus s=ERROR; - if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) { + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { #ifdef VERBOSE std::cout << "Starting Receiver Readout" << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->getInt(fnum,retval); - disconnectData(); + disconnectData(); + } if(retval!=-1) s=(runStatus)retval; if(ret==FORCE_UPDATE) @@ -7512,13 +7577,14 @@ slsDetectorDefs::runStatus slsDetector::getReceiverStatus(){ int retval=-1; runStatus s=ERROR; - if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) { + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { #ifdef VERBOSE std::cout << "Getting Receiver Status" << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->getInt(fnum,retval); - disconnectData(); + disconnectData(); + } if(retval!=-1) s=(runStatus)retval; if(ret==FORCE_UPDATE) @@ -7536,13 +7602,14 @@ int slsDetector::getFramesCaughtByReceiver(){ int ret = FAIL; int retval=-1; - if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) { + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { #ifdef VERBOSE std::cout << "Getting Frames Caught by Receiver " << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->getInt(fnum,retval); - disconnectData(); + disconnectData(); + } if(ret==FORCE_UPDATE) ret=updateReceiver(); } @@ -7557,13 +7624,14 @@ int slsDetector::getReceiverCurrentFrameIndex(){ int ret = FAIL; int retval=-1; - if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) { + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { #ifdef VERBOSE std::cout << "Getting Current Frame Index of Receiver " << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->getInt(fnum,retval); - disconnectData(); + disconnectData(); + } if(ret==FORCE_UPDATE) ret=updateReceiver(); } @@ -7579,13 +7647,14 @@ int slsDetector::resetFramesCaught(){ int ret = FAIL; char mess[MAX_STR_LENGTH] = ""; - if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) { + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { #ifdef VERBOSE std::cout << "Reset Frames Caught by Receiver" << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->executeFunction(fnum,mess); - disconnectData(); + disconnectData(); + } if(ret==FORCE_UPDATE) ret=updateReceiver(); } @@ -7652,13 +7721,14 @@ int slsDetector::lockReceiver(int lock){ int arg=lock; - if(setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG){ + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE std::cout << "Locking or Unlocking Receiver " << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->sendInt(fnum,retval,arg); - disconnectData(); + disconnectData(); + } if(ret==FORCE_UPDATE) updateReceiver(); } @@ -7676,13 +7746,14 @@ string slsDetector::getReceiverLastClientIP(){ int ret = FAIL; char retval[INET_ADDRSTRLEN]=""; - if(setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG){ + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE std::cout << "Geting Last Client IP connected to Receiver " << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->getLastClientIP(fnum,retval); - disconnectData(); + disconnectData(); + } if(ret==FORCE_UPDATE) updateReceiver(); } @@ -7733,7 +7804,7 @@ int slsDetector::updateReceiver() { int ret=OK; char mess[MAX_STR_LENGTH]=""; - if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) { + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { if (connectData() == OK){ dataSocket->SendDataOnly(&fnum,sizeof(fnum)); dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); @@ -7760,7 +7831,7 @@ int slsDetector::exitReceiver(){ int retval; int fnum=F_EXIT_RECEIVER; - if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) { + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { if (dataSocket) { dataSocket->Connect(); dataSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -7796,13 +7867,14 @@ int slsDetector::enableWriteToFile(int enable){ } } - else if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + else if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE std::cout << "Sending enable file write to receiver " << arg << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->sendInt(fnum,retval,arg); - disconnectData(); + disconnectData(); + } if(ret!=FAIL){ pthread_mutex_lock(&ms); parentDet->enableWriteToFileMask(retval); @@ -7837,13 +7909,14 @@ int slsDetector::overwriteFile(int enable){ } } - else if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + else if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE std::cout << "Sending enable file write to receiver " << arg << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->sendInt(fnum,retval,arg); - disconnectData(); + disconnectData(); + } if(ret!=FAIL){ pthread_mutex_lock(&ms); parentDet->enableOverwriteMask(retval); @@ -7875,13 +7948,14 @@ int slsDetector::setFrameIndex(int index){ pthread_mutex_unlock(&ms); } - else if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + else if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE std::cout << "Sending frame index to receiver " << arg << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->sendInt(fnum,retval,arg); - disconnectData(); + disconnectData(); + } if(ret!=FAIL){ pthread_mutex_lock(&ms); fileIO::setFrameIndex(retval); @@ -7954,13 +8028,14 @@ int slsDetector::setReadReceiverFrequency(int getFromReceiver, int freq){ if(!getFromReceiver) return retval; - if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE std::cout << "Sending read frequency to receiver " << arg << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->sendInt(fnum,retval,arg); - disconnectData(); + disconnectData(); + } if(ret==FAIL) retval = -1; if(ret==FORCE_UPDATE) @@ -7976,6 +8051,33 @@ int slsDetector::setReadReceiverFrequency(int getFromReceiver, int freq){ +int slsDetector::setReceiverReadTimer(int time_in_ms){ + int fnum=F_READ_RECEIVER_TIMER; + int ret = FAIL; + int arg = time_in_ms; + int retval = -1; + + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ +#ifdef VERBOSE + std::cout << "Sending read timer to receiver " << arg << std::endl; +#endif + if (connectData() == OK){ + ret=thisReceiver->sendInt(fnum,retval,arg); + disconnectData(); + } + if(ret==FORCE_UPDATE) + updateReceiver(); + } + + if ((time_in_ms > 0) && (retval != time_in_ms)){ + cout << "could not set receiver read timer to " << time_in_ms <<" Returned:" << retval << endl; + setErrorMask((getErrorMask())|(RECEIVER_READ_TIMER)); + } + return retval; +} + + + int slsDetector::enableDataStreamingFromReceiver(int enable){ int fnum=F_STREAM_DATA_FROM_RECEIVER; int ret = FAIL; @@ -7983,13 +8085,14 @@ int slsDetector::enableDataStreamingFromReceiver(int enable){ int arg = enable; - if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE std::cout << "***************Sending Data Streaming in Receiver " << arg << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->sendInt(fnum,retval,arg); - disconnectData(); + disconnectData(); + } if(ret==FAIL) retval = -1; if(ret==FORCE_UPDATE) @@ -8011,13 +8114,14 @@ int slsDetector::enableReceiverCompression(int i){ int retval=-1; - if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE std::cout << "Getting/Enabling/Disabling Receiver Compression with argument " << i << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->sendInt(fnum,retval,i); - disconnectData(); + disconnectData(); + } if(ret==FAIL) setErrorMask((getErrorMask())|(COULDNOT_ENABLE_COMPRESSION)); } @@ -8032,13 +8136,14 @@ void slsDetector::setDetectorHostname(){ char retval[MAX_STR_LENGTH]=""; - if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE std::cout << "Sending detector hostname to Receiver " << thisDetector->hostname << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->sendString(fnum,retval,thisDetector->hostname); - disconnectData(); + disconnectData(); + } if((ret==FAIL) || (strcmp(retval,thisDetector->hostname))) setErrorMask((getErrorMask())|(RECEIVER_DET_HOSTNAME_NOT_SET)); } @@ -8080,13 +8185,14 @@ int slsDetector::enableTenGigabitEthernet(int i){ if(configureMAC() != FAIL){ ret = FAIL; retval=-1; - if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE std::cout << "Enabling / Disabling 10Gbe in receiver: " << i << std::endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->sendInt(fnum2,retval,i); - disconnectData(); + disconnectData(); + } if(ret==FAIL) setErrorMask((getErrorMask())|(RECEIVER_TEN_GIGA)); } @@ -8107,16 +8213,17 @@ int slsDetector::setReceiverFifoDepth(int i){ int retval=-1; - if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE if(i ==-1) std::cout<< "Getting Receiver Fifo Depth" << endl; else std::cout<< "Setting Receiver Fifo Depth to " << i << endl; #endif - if (connectData() == OK) + if (connectData() == OK){ ret=thisReceiver->sendInt(fnum,retval,i); - disconnectData(); + disconnectData(); + } if(ret==FAIL) setErrorMask((getErrorMask())|(COULD_NOT_SET_FIFO_DEPTH)); } @@ -8141,7 +8248,7 @@ int slsDetector::setCTBPattern(string fname) { char retval[MAX_STR_LENGTH]=""; -// if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ +// if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ // #ifdef VERBOSE // std::cout << "Sending detector hostname to Receiver " << thisDetector->hostname << std::endl; // #endif diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 84ef549c3..9d22e51a5 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -267,6 +267,8 @@ class slsDetector : public slsDetectorUtils, public energyConversion { /** flag for acquiring */ bool acquiringFlag; + /** flipped data across x or y axis */ + int flippedData[2]; } sharedSlsDetector; @@ -295,20 +297,22 @@ class slsDetector : public slsDetectorUtils, public energyConversion { /** (default) constructor \param type is needed to define the size of the detector shared memory 9defaults to GENERIC i.e. the largest shared memory needed by any slsDetector is allocated \param id is the detector index which is needed to define the shared memory id. Different physical detectors should have different IDs in order to work independently + \param pos is the index of object in the parent multislsdet array \param p is the parent multislsdet to access filename ,path etc */ - slsDetector(detectorType type=GENERIC, int id=0, multiSlsDetector *p=NULL); + slsDetector(int pos, detectorType type=GENERIC, int id=0, multiSlsDetector *p=NULL); /** constructor \param id is the detector index which is needed to define the shared memory id. Different physical detectors should have different IDs in order to work independently + \param pos is the index of object in the parent multislsdet array \param p is the parent multislsdet to access filename ,path etc */ - slsDetector(int id, multiSlsDetector *p=NULL); + slsDetector(int pos, int id, multiSlsDetector *p=NULL); - slsDetector(char *name, int id=0, int cport=DEFAULT_PORTNO, multiSlsDetector *p=NULL); + slsDetector(int pos, char *name, int id=0, int cport=DEFAULT_PORTNO, multiSlsDetector *p=NULL); //slsDetector(string const fname); // ~slsDetector(){while(dataQueue.size()>0){}}; /** destructor */ @@ -668,6 +672,12 @@ class slsDetector : public slsDetectorUtils, public energyConversion { int getMaxNumberOfChannels(dimension d);//{return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nModMax[d];}; + /** returns the enable if data will be flipped across x or y axis + * \param d axis across which data is flipped + * returns 1 or 0 + */ + int getFlippedData(dimension d=X){return thisDetector->flippedData[d];}; + /** Returns number of rois */ int getNRoi(){return thisDetector->nROI;}; @@ -733,6 +743,12 @@ class slsDetector : public slsDetectorUtils, public energyConversion { int setNumberOfModules(int n=GET_FLAG, dimension d=X); // if n=GET_FLAG returns the number of installed modules + /** sets the enable which determines if data will be flipped across x or y axis + * \param d axis across which data is flipped + * \param value 0 or 1 to reset/set or -1 to get value + * \return enable flipped data across x or y axis + */ + int setFlippedData(dimension d=X, int value=-1); /* @@ -1412,6 +1428,7 @@ class slsDetector : public slsDetectorUtils, public energyConversion { */ int getDetectorId(int i=-1) {return detId;}; + /** Receives a data frame from the detector socket \returns pointer to the data (or NULL if failed) @@ -1596,19 +1613,7 @@ class slsDetector : public slsDetectorUtils, public energyConversion { */ int resetFramesCaught(); - /** - * Create Receiving Data Threads - * @param destroy is true to destroy all the threads - * @return OK or FAIL - */ - int createReceivingDataThreads(bool destroy = false){return 0;}; - - /** Reads frames from receiver through a constant socket - */ - //void readFrameFromReceiver(){}; - - int* readFrameFromReceiver(char*, int&, int&, int&); /** Locks/Unlocks the connection to the receiver /param lock sets (1), usets (0), gets (-1) the lock /returns lock status of the receiver @@ -1717,6 +1722,14 @@ class slsDetector : public slsDetectorUtils, public energyConversion { */ int setReadReceiverFrequency(int getFromReceiver, int freq=-1); + /** Sets the read receiver timer + if data required from receiver randomly readRxrFrequency=0, + then the timer between each data stream is set with time_in_ms + @param time_in_ms timer between frames + /returns read receiver timer + */ + int setReceiverReadTimer(int time_in_ms=500); + /** Enable or disable streaming data from receiver to client * @param enable 0 to disable 1 to enable -1 to only get the value * @returns data streaming @@ -1838,6 +1851,11 @@ class slsDetector : public slsDetectorUtils, public energyConversion { */ int detId; + /** + position ID + */ + int posId; + /** * parent multi detector diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index cdcd99454..3019dc849 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -432,7 +432,13 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDetectorSize; i++; + descrToFuncMap[i].m_pFuncName="flippeddatax"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDetectorSize; + i++; + descrToFuncMap[i].m_pFuncName="flippeddatay"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDetectorSize; + i++; /* flags */ @@ -1251,12 +1257,13 @@ string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action) { myDet->setOnline(ONLINE_FLAG); + myDet->setReceiverOnline(ONLINE_FLAG); if(myDet->acquire() == FAIL) return string("acquire unsuccessful"); if(myDet->setReceiverOnline()==ONLINE_FLAG){ char answer[100]; - sprintf(answer,"\n%d",myDet->getFramesCaughtByReceiver()); + sprintf(answer,"\nAcquired %d",myDet->getFramesCaughtByReceiver()); return string(answer); } @@ -1295,6 +1302,7 @@ string slsDetectorCommand::cmdData(int narg, char *args[], int action) { b=myDet->setThreadedProcessing(-1); myDet->setThreadedProcessing(0); myDet->setOnline(ONLINE_FLAG); + myDet->setReceiverOnline(ONLINE_FLAG); myDet->readAll(); //processdata in receiver is useful only for gui purposes if(myDet->setReceiverOnline()==OFFLINE_FLAG) @@ -1329,6 +1337,7 @@ string slsDetectorCommand::cmdFrame(int narg, char *args[], int action) { b=myDet->setThreadedProcessing(-1); myDet->setThreadedProcessing(0); myDet->setOnline(ONLINE_FLAG); + myDet->setReceiverOnline(ONLINE_FLAG); myDet->readFrame(); //processdata in receiver is useful only for gui purposes if(myDet->setReceiverOnline()==OFFLINE_FLAG) @@ -1737,6 +1746,7 @@ string slsDetectorCommand::cmdExitServer(int narg, char *args[], int action){ return string("Error closing server\n"); } else if (cmd=="exitreceiver"){ + myDet->setReceiverOnline(ONLINE_FLAG); if(myDet->exitReceiver()!=OK) return string("Receiver shut down\n"); else @@ -1858,6 +1868,7 @@ string slsDetectorCommand::helpTrimEn(int narg, char *args[], int action) { string slsDetectorCommand::cmdOutDir(int narg, char *args[], int action){ + myDet->setReceiverOnline(ONLINE_FLAG); if (action==HELP_ACTION) return helpOutDir(narg, args, action); @@ -1882,6 +1893,7 @@ string slsDetectorCommand::helpOutDir(int narg, char *args[], int action){ string slsDetectorCommand::cmdFileName(int narg, char *args[], int action){ + myDet->setReceiverOnline(ONLINE_FLAG); if (action==HELP_ACTION) return helpFileName(narg, args, action); if (cmd=="fname") { @@ -1911,7 +1923,7 @@ string slsDetectorCommand::cmdEnablefwrite(int narg, char *args[], int action){ int i; char ans[100]; - + myDet->setReceiverOnline(ONLINE_FLAG); if (action==HELP_ACTION) { return helpEnablefwrite(narg, args, action); } @@ -1943,7 +1955,7 @@ string slsDetectorCommand::cmdOverwrite(int narg, char *args[], int action){ int i; char ans[100]; - + myDet->setReceiverOnline(ONLINE_FLAG); if (action==HELP_ACTION) { return helpOverwrite(narg, args, action); } @@ -1975,7 +1987,7 @@ string slsDetectorCommand::helpOverwrite(int narg, char *args[], int action){ string slsDetectorCommand::cmdFileIndex(int narg, char *args[], int action){ char ans[100]; int i; - + myDet->setReceiverOnline(ONLINE_FLAG); if (action==HELP_ACTION) { return helpFileName(narg, args, action); } @@ -2088,6 +2100,8 @@ string slsDetectorCommand::cmdRateCorr(int narg, char *args[], int action){ double fval; char answer[1000]; + myDet->setOnline(ONLINE_FLAG); + if (action==PUT_ACTION) { sscanf(args[1],"%lf",&fval); myDet->setRateCorrection(fval); @@ -2785,6 +2799,7 @@ string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int actio return helpNetworkParameter(narg,args,action); myDet->setOnline(ONLINE_FLAG); + myDet->setReceiverOnline(ONLINE_FLAG); if (cmd=="detectormac") { t=DETECTOR_MAC; @@ -2954,6 +2969,7 @@ string slsDetectorCommand::cmdLock(int narg, char *args[], int action) { else if(cmd=="r_lock"){ + myDet->setReceiverOnline(ONLINE_FLAG); if (action==PUT_ACTION) { if (sscanf(args[1],"%d",&val)) myDet->lockReceiver(val); @@ -3004,8 +3020,10 @@ string slsDetectorCommand::cmdLastClient(int narg, char *args[], int action) { return myDet->getLastClientIP(); } - else if(cmd=="r_lastclient") + else if(cmd=="r_lastclient"){ + myDet->setReceiverOnline(ONLINE_FLAG); return myDet->getReceiverLastClientIP(); + } return string("cannot decode command"); } @@ -3051,6 +3069,7 @@ string slsDetectorCommand::cmdOnline(int narg, char *args[], int action) { } else if(cmd=="activate"){ myDet->setOnline(ONLINE_FLAG); + myDet->setReceiverOnline(ONLINE_FLAG); if (action==PUT_ACTION) { if (!sscanf(args[1],"%d",&ival)) return string("Could not scan activate mode ")+string(args[1]); @@ -3072,11 +3091,12 @@ string slsDetectorCommand::cmdOnline(int narg, char *args[], int action) { else{ if (action==PUT_ACTION) return string("cannot set"); + myDet->setReceiverOnline(ONLINE_FLAG); strcpy(ans,myDet->checkReceiverOnline().c_str()); if(!strlen(ans)) strcpy(ans,"All receiver online"); else - strcat(ans," :Not receiver online"); + strcat(ans," :Not all receiver online"); } return ans; @@ -3113,6 +3133,7 @@ string slsDetectorCommand::cmdConfigureMac(int narg, char *args[], int action) { if (action==PUT_ACTION){ myDet->setOnline(ONLINE_FLAG); + myDet->setReceiverOnline(ONLINE_FLAG); ret=myDet->configureMAC(); } else @@ -3139,7 +3160,7 @@ string slsDetectorCommand::cmdDetectorSize(int narg, char *args[], int action) { if (action==HELP_ACTION) return helpDetectorSize(narg,args,action); int ret, val=-1, pos=-1,i; - char ans[1000], temp[100]; + char ans[1000]; myDet->setOnline(ONLINE_FLAG); @@ -3176,6 +3197,21 @@ string slsDetectorCommand::cmdDetectorSize(int narg, char *args[], int action) { myDet->setMaxNumberOfChannelsPerDetector(Y,val); } + if(cmd=="flippeddatax"){ + if ((!sscanf(args[1],"%d",&val)) || (val!=0 && val != 1)) + return string ("cannot scan flippeddata x mode: must be 0 or 1"); + myDet->setReceiverOnline(ONLINE_FLAG); + myDet->setFlippedData(X,val); + } + + if(cmd=="flippeddatay"){ + return string("Not required for this detector\n"); + if ((!sscanf(args[1],"%d",&val)) || (val!=0 && val != 1)) + return string ("cannot scan flippeddata y mode: must be 0 or 1"); + myDet->setReceiverOnline(ONLINE_FLAG); + myDet->setFlippedData(Y,val); + } + } if (cmd=="nmod" || cmd=="roimask") { @@ -3183,14 +3219,23 @@ string slsDetectorCommand::cmdDetectorSize(int narg, char *args[], int action) { } else if (cmd=="maxmod") { ret=myDet->getMaxNumberOfModules(); } else if (cmd=="dr") { + myDet->setReceiverOnline(ONLINE_FLAG); ret=myDet->setDynamicRange(val); } else if (cmd=="roi") { myDet->getROI(ret); } else if (cmd=="detsizechan") { - sprintf(ans,"%d",myDet->getMaxNumberOfChannelsPerDetector(X)); - sprintf(temp,"%d",myDet->getMaxNumberOfChannelsPerDetector(Y)); - strcat(ans," "); - strcat(ans,temp); + sprintf(ans,"%d %d",myDet->getMaxNumberOfChannelsPerDetector(X),myDet->getMaxNumberOfChannelsPerDetector(Y)); + return string(ans); + } + else if(cmd=="flippeddatax"){ + myDet->setReceiverOnline(ONLINE_FLAG); + sprintf(ans,"%d",myDet->getFlippedData(X)); + return string(ans); + } + else if(cmd=="flippeddatay"){ + return string("Not required for this detector\n"); + myDet->setReceiverOnline(ONLINE_FLAG); + sprintf(ans,"%d",myDet->getFlippedData(Y)); return string(ans); } else @@ -3214,6 +3259,8 @@ string slsDetectorCommand::helpDetectorSize(int narg, char *args[], int action) os << "dr i \n sets the dynamic range of the detector"<< std::endl; os << "roi i xmin xmax ymin ymax \n sets region of interest where i is number of rois;i=0 to clear rois"<< std::endl; os << "detsizechan x y \n sets the maximum number of channels for complete detector set in both directions; -1 is no limit"<< std::endl; + os << "flippeddatax x \n sets if the data should be flipped on the x axis"<< std::endl; + os << "flippeddatay y \n sets if the data should be flipped on the y axis"<< std::endl; } if (action==GET_ACTION || action==HELP_ACTION) { os << "nmod \n gets the number of modules of the detector"<< std::endl; @@ -3221,7 +3268,8 @@ string slsDetectorCommand::helpDetectorSize(int narg, char *args[], int action) os << "dr \n gets the dynamic range of the detector"<< std::endl; os << "roi \n gets region of interest"<< std::endl; os << "detsizechan \n gets the maximum number of channels for complete detector set in both directions; -1 is no limit"<< std::endl; - + os << "flippeddatax\n gets if the data will be flipped on the x axis respectively"<< std::endl; + os << "flippeddatay\n gets if the data will be flipped on the y axis respectively"<< std::endl; } return os.str(); @@ -3422,6 +3470,7 @@ string slsDetectorCommand::cmdSN(int narg, char *args[], int action) { } if (cmd=="receiverversion") { + myDet->setReceiverOnline(ONLINE_FLAG); sprintf(answer,"%llx",myDet->getId(RECEIVER_VERSION)); return string(answer); } @@ -4102,6 +4151,7 @@ string slsDetectorCommand::cmdTimer(int narg, char *args[], int action) { myDet->setOnline(ONLINE_FLAG); + myDet->setReceiverOnline(ONLINE_FLAG); ret=myDet->setTimer(index,t); if (index==ACQUISITION_TIME || index==SUBFRAME_ACQUISITION_TIME || index==FRAME_PERIOD || index==DELAY_AFTER_TRIGGER) @@ -4547,10 +4597,12 @@ string slsDetectorCommand::cmdConfiguration(int narg, char *args[], int action) } return sval; } else if (cmd=="rx_printconfig"){ + myDet->setReceiverOnline(ONLINE_FLAG); if (action==PUT_ACTION) return string("cannot put"); return string(""+myDet->printReceiverConfiguration()); }else if (cmd=="parameters") { + myDet->setReceiverOnline(ONLINE_FLAG); if (action==PUT_ACTION) { sval=string(args[1]); myDet->retrieveDetectorSetup(sval); @@ -4560,6 +4612,7 @@ string slsDetectorCommand::cmdConfiguration(int narg, char *args[], int action) } return sval; } else if (cmd=="setup") { + myDet->setReceiverOnline(ONLINE_FLAG); if (action==PUT_ACTION) { sval=string(args[1]); myDet->retrieveDetectorSetup(sval,2); @@ -4614,6 +4667,7 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) { myDet->setOnline(ONLINE_FLAG); + myDet->setReceiverOnline(ONLINE_FLAG); if(cmd=="receiver"){ if (action==PUT_ACTION) { diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index 190e3e2a4..fca29fac9 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -45,6 +45,7 @@ int slsDetectorUtils::acquire(int delflag){ struct timespec begin,end; clock_gettime(CLOCK_REALTIME, &begin); + //ensure acquire isnt started multiple times by same client if(getAcquiringFlag() == false) setAcquiringFlag(true); @@ -53,6 +54,10 @@ int slsDetectorUtils::acquire(int delflag){ return FAIL; } + //not in the loop for real time acqusition yet, + //in the real time acquisition loop, processing thread will wait for a post each time + sem_init(&sem_newRTAcquisition,1,0); + bool receiver = (setReceiverOnline()==ONLINE_FLAG); if(!receiver){ @@ -220,6 +225,10 @@ int slsDetectorUtils::acquire(int delflag){ ResetPositionIndex(); for (int ip=0; ip0) { @@ -286,12 +295,7 @@ int slsDetectorUtils::acquire(int delflag){ //send receiver file name pthread_mutex_lock(&mg); //cout << "lock"<< endl; setFileName(fileIO::getFileName()); - if(setReceiverOnline()==OFFLINE_FLAG){ - stopReceiver(); - *stoppedFlag=1; - pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; - break; - } + //start receiver if(startReceiver() == FAIL) { cout << "Start receiver failed " << endl; @@ -353,9 +357,15 @@ int slsDetectorUtils::acquire(int delflag){ } //online else{ - cout << "Stopping receiver " << endl;; + + if(setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG){ + stopAcquisition(); + stopReceiver(); + pthread_mutex_unlock(&mg); + break; + } stopReceiver(); - cout<<"***********receiver stopped"<