From 18422ce2153915a1cbc730638a0fa72748023a30 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 1 Dec 2017 09:18:42 +0100 Subject: [PATCH] setbit and clear bit moved to slsdet, readreg, writereg,setbit,clearbit in multi cannot give -1, instead api gives error if checked --- slsDetectorSoftware/commonFiles/error_defs.h | 9 +- .../multiSlsDetector/multiSlsDetector.cpp | 149 +++++++---- .../multiSlsDetector/multiSlsDetector.h | 21 ++ .../slsDetector/slsDetector.cpp | 236 ++++++++++-------- slsDetectorSoftware/slsDetector/slsDetector.h | 21 ++ .../slsDetector/slsDetectorCommand.cpp | 4 +- .../slsDetector/slsDetectorUtils.h | 24 ++ 7 files changed, 311 insertions(+), 153 deletions(-) diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h index 8ba6f5f85..868af8836 100644 --- a/slsDetectorSoftware/commonFiles/error_defs.h +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -20,8 +20,12 @@ using namespace std; /** Error flags */ /*Assumption: Only upto 63 detectors */ +// multi errors +// 0xFFF0000000000000ULL #define MULTI_DETECTORS_NOT_ADDED 0x8000000000000000ULL +#define MULTI_HAVE_DIFFERENT_VALUES 0x4000000000000000ULL +// sls errors #define CRITICAL_ERROR_MASK 0xFFFFFFF // 0xFFFFFFF000000000ULL @@ -45,6 +49,7 @@ using namespace std; #define RECEIVER_MULTI_DET_SIZE_NOT_SET 0x0000200000000000ULL #define PREPARE_ACQUISITION 0x0000100000000000ULL #define CLEANUP_ACQUISITION 0x0000080000000000ULL +#define REGISER_WRITE_READ 0x0000040000000000ULL // 0xFFFFFFF000000000ULL // 0x0000000FFFFFFFFFULL @@ -83,6 +88,7 @@ using namespace std; #define RECEIVER_SUBF_TIME_NOT_SET 0x0000000100000000ULL #define RECEIVER_SILENT_MODE_NOT_SET 0x0000000200000000ULL #define RESTREAM_STOP_FROM_RECEIVER 0x0000000400000000ULL + // 0x0000000FFFFFFFFFULL /** @short class returning all error messages for error mask */ @@ -155,7 +161,8 @@ public: if(slsErrorMask&CLEANUP_ACQUISITION) retval.append("Could not clean up after acquisition in detector\n"); - + if(slsErrorMask®ISER_WRITE_READ) + retval.append("Could not read/write register in detector\n"); diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 7f9607fec..8f2b008d4 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -4635,66 +4635,116 @@ int multiSlsDetector::saveCalibrationFile(string fname, int imod) { int multiSlsDetector::writeRegister(int addr, int val){ - int i;//imi, ima, - int ret, ret1=-100; + int ret, ret1=-100; - for (i=0; inumberOfDetectors; ++i) { - if (detectors[i]) { - ret=detectors[i]->writeRegister(addr,val); - if(detectors[i]->getErrorMask()) - setErrorMask(getErrorMask()|(1<numberOfDetectors; ++i) { + if (detectors[i]) { + ret=detectors[i]->writeRegister(addr,val); + if(detectors[i]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors; ++i) { - if (detectors[i]) { - ret=detectors[i]->writeAdcRegister(addr,val); - if(detectors[i]->getErrorMask()) - setErrorMask(getErrorMask()|(1<numberOfDetectors; ++i) { + if (detectors[i]) { + ret=detectors[i]->writeAdcRegister(addr,val); + if(detectors[i]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors; ++i) { - if (detectors[i]) { - ret=detectors[i]->readRegister(addr); - if(detectors[i]->getErrorMask()) - setErrorMask(getErrorMask()|(1<numberOfDetectors; ++i) { + if (detectors[i]) { + ret=detectors[i]->readRegister(addr); + if(detectors[i]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors; ++i) { + if (detectors[i]) { + ret1=detectors[i]->setBit(addr,n); + if(detectors[i]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors; ++i) { + if (detectors[i]) { + ret1=detectors[i]->clearBit(addr,n); + if(detectors[i]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors; ++idet) { if (detectors[idet]) { diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 2c5554c48..638adcbae 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -1043,6 +1043,27 @@ class multiSlsDetector : public slsDetectorUtils { int readRegister(int addr); + /** + sets a bit in a register + \param addr address + \param n nth bit ranging from 0 to 31 + \returns current register value + + DO NOT USE!!! ONLY EXPERT USER!!! + */ + int setBit(int addr, int n); + + + /** + clear a bit in a register + \param addr address + \param n nth bit ranging from 0 to 31 + \returns current register value + + DO NOT USE!!! ONLY EXPERT USER!!! + */ + int clearBit(int addr, int n); + int setTrimEn(int nen, int *en=NULL); diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 96a5b5bf1..0541b43c3 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -2308,90 +2308,86 @@ int slsDetector::digitalTest( digitalTestMode mode, int imod){ int slsDetector::writeRegister(int addr, int val){ - - int retval; - int fnum=F_WRITE_REGISTER; - int ret=FAIL; - - char mess[MAX_STR_LENGTH]=""; - - int arg[2]; - arg[0]=addr; - arg[1]=val; - + int retval=-1; + int fnum=F_WRITE_REGISTER; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + int arg[2]; + arg[0]=addr; + arg[1]=val; #ifdef VERBOSE - std::cout<< std::endl; - std::cout<< "Writing to register "<< hex<onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(arg,sizeof(arg)); - 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; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(arg,sizeof(arg)); + 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; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } #ifdef VERBOSE - std::cout<< "Register returned "<< retval << std::endl; + std::cout<< "Register returned "<< retval << std::endl; #endif - if (ret==FAIL) { - std::cout<< "Write to register failed " << std::endl; - } - return retval; + if (ret==FAIL) { + std::cout<< "Write to register failed " << std::endl; + setErrorMask((getErrorMask())|(REGISER_WRITE_READ)); + } + + return retval; +} -}; -/* write or read register */ int slsDetector::writeAdcRegister(int addr, int val){ + int retval=-1; + int fnum=F_WRITE_ADC_REG; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; - int retval; - int fnum=F_WRITE_ADC_REG; - int ret=FAIL; - - char mess[MAX_STR_LENGTH]=""; - - int arg[2]; - arg[0]=addr; - arg[1]=val; + int arg[2]; + arg[0]=addr; + arg[1]=val; #ifdef VERBOSE - std::cout<< std::endl; - std::cout<< "Writing to adc register "<< hex<onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(arg,sizeof(arg)); - 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; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(arg,sizeof(arg)); + 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; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } #ifdef VERBOSE - std::cout<< "ADC Register returned "<< retval << std::endl; + std::cout<< "ADC Register returned "<< retval << std::endl; #endif - if (ret==FAIL) { - std::cout<< "Write ADC to register failed " << std::endl; - } - return retval; + if (ret==FAIL) { + std::cout<< "Write ADC to register failed " << std::endl; + setErrorMask((getErrorMask())|(REGISER_WRITE_READ)); + } + return retval; }; @@ -2400,49 +2396,81 @@ int slsDetector::writeAdcRegister(int addr, int val){ int slsDetector::readRegister(int addr){ - - int retval; - int fnum=F_READ_REGISTER; - int ret=FAIL; - - char mess[MAX_STR_LENGTH]=""; - - int arg; - arg=addr; + int retval=-1; + int fnum=F_READ_REGISTER; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + int arg; + arg=addr; #ifdef VERBOSE - std::cout<< std::endl; - std::cout<< "Reading register "<< hex<onlineFlag==ONLINE_FLAG) { - // if (connectControl() == OK){ - if (stopSocket) { - if (connectStop() == OK) { - stopSocket->SendDataOnly(&fnum,sizeof(fnum)); - stopSocket->SendDataOnly(&arg,sizeof(arg)); - stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else { - stopSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectStop(); - // if (ret==FORCE_UPDATE) - // updateDetector(); - } - } - } + if (thisDetector->onlineFlag==ONLINE_FLAG) { + // if (connectControl() == OK){ + if (stopSocket) { + if (connectStop() == OK) { + stopSocket->SendDataOnly(&fnum,sizeof(fnum)); + stopSocket->SendDataOnly(&arg,sizeof(arg)); + stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); + else { + stopSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectStop(); + } + } + } #ifdef VERBOSE - std::cout<< "Register returned "<< retval << std::endl; + std::cout<< "Register returned "<< retval << std::endl; #endif - if (ret==FAIL) { - std::cout<< "Read register failed " << std::endl; - } - return retval; + if (ret==FAIL) { + std::cout<< "Read register failed " << std::endl; + setErrorMask((getErrorMask())|(REGISER_WRITE_READ)); + } + return retval; -}; +} + + +int slsDetector::setBit(int addr, int n) { + if (n<0 || n>31) { + std::cout << "Bit number out of Range" << std:: endl; + setErrorMask((getErrorMask())|(REGISER_WRITE_READ)); + } + + // normal bit range + else { + int val = readRegister(addr); + if (val != -1) { + writeRegister(addr,val | 1<31) { + std::cout << "Bit number out of Range" << std:: endl; + setErrorMask((getErrorMask())|(REGISER_WRITE_READ)); + } + + // normal bit range + else { + int val = readRegister(addr); + if (val != -1) { + writeRegister(addr,val & ~(1<writeRegister(addr,myDet->readRegister(addr)| 1<setBit(addr,n)); if (cmd=="clearbit") - sprintf(answer,"0x%x",myDet->writeRegister(addr,myDet->readRegister(addr) & ~(1<clearBit(addr,n)); } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index b59510599..5774e6b0b 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -519,6 +519,30 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { DO NOT USE!!! ONLY EXPERT USER!!! */ virtual int readRegister(int addr)=0; + + + /** + sets a bit in a register + \param addr address + \param n nth bit ranging from 0 to 31 + \returns current register value + + DO NOT USE!!! ONLY EXPERT USER!!! + */ + virtual int setBit(int addr, int n)=0; + + + /** + clear a bit in a register + \param addr address + \param n nth bit ranging from 0 to 31 + \returns current register value + + DO NOT USE!!! ONLY EXPERT USER!!! + */ + virtual int clearBit(int addr, int n)=0; + + /** Returns the IP of the last client connecting to the detector */