From 140996fae65c30e4261697a8b45844d05588b14e Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 6 Feb 2019 18:50:50 +0100 Subject: [PATCH] ctb adc fix, update detector fix, acq error fix --- .../slsDetectorFunctionList.c | 4 + .../slsDetectorServer_funcs.c | 173 +++++++++--------- .../slsDetector/slsDetector.cpp | 6 +- .../slsDetector/slsDetectorCommand.cpp | 64 +------ slsSupportLib/src/ClientSocket.cpp | 1 + 5 files changed, 103 insertions(+), 145 deletions(-) diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index 58b9bdd52..088cc2834 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -1339,16 +1339,19 @@ int getADC(enum ADCINDEX ind){ case V_PWR_B: case V_PWR_C: case V_PWR_D: + FILE_LOG(logDEBUG1, ("Reading I2C Voltage for device Id: %d\n", (int)ind)); return INA226_ReadVoltage(I2C_POWER_VIO_DEVICE_ID + (int)ind); case I_PWR_IO: case I_PWR_A: case I_PWR_B: case I_PWR_C: case I_PWR_D: + FILE_LOG(logDEBUG1, ("Reading I2C Current for device Id: %d\n", (int)ind)); return INA226_ReadCurrent(I2C_POWER_VIO_DEVICE_ID + (int)(ind - I_PWR_IO)); // slow adcs case SLOW_ADC_TEMP: + FILE_LOG(logDEBUG1, ("Reading Slow ADC Temperature\n")); return AD7689_GetTemperature(); case SLOW_ADC0: case SLOW_ADC1: @@ -1358,6 +1361,7 @@ int getADC(enum ADCINDEX ind){ case SLOW_ADC5: case SLOW_ADC6: case SLOW_ADC7: + FILE_LOG(logDEBUG1, ("Reading Slow ADC Channel %d\n", (int)ind - SLOW_ADC0)); return AD7689_GetChannel((int)ind - SLOW_ADC0); default: FILE_LOG(logERROR, ("Adc Index %d not defined \n", (int)ind)); diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c index 219ae35c5..9e409b642 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c @@ -990,6 +990,7 @@ int get_adc(int file_des) { default: #ifdef CHIPTESTBOARDD if (ind >= SLOW_ADC0 && ind <= SLOW_ADC_TEMP) { + serverAdcIndex = ind; break; } #endif @@ -1001,7 +1002,7 @@ int get_adc(int file_des) { if (ret == OK) { FILE_LOG(logDEBUG1, ("Getting ADC %d\n", serverAdcIndex)); retval = getADC(serverAdcIndex); - FILE_LOG(logDEBUG1, ("ADC(%d): %d\n", retval)); + FILE_LOG(logDEBUG1, ("ADC(%d): %d\n", serverAdcIndex, retval)); } #endif @@ -1515,105 +1516,107 @@ int set_timer(int file_des) { #ifdef EIGERD int64_t subexptime = 0; #endif - FILE_LOG(logDEBUG1, ("Setting timer %s(%d) to %lld ns\n", ind, timerName, tns)); + FILE_LOG(logDEBUG1, ("Setting timer %s(%d) to %lld ns\n", timerName, (int)ind, tns)); // set & get if ((tns == -1) || (Server_VerifyLock() == OK)) { - // check index - switch (ind) { - case FRAME_NUMBER: -#if !defined(CHIPTESTBOARDD) && !defined(MOENCHD) - case ACQUISITION_TIME: + // check index + switch (ind) { + case FRAME_NUMBER: +#if ((!defined(CHIPTESTBOARDD)) && (!defined(MOENCHD))) + case ACQUISITION_TIME: #endif - case FRAME_PERIOD: - case CYCLES_NUMBER: - case SAMPLES: + case FRAME_PERIOD: + case CYCLES_NUMBER: + case SAMPLES: #if defined(GOTTHARDD) || defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) - case DELAY_AFTER_TRIGGER: + case DELAY_AFTER_TRIGGER: #endif - retval = setTimer(ind, tns); - break; + retval = setTimer(ind, tns); + break; #ifdef JUNGFRAUD - case STORAGE_CELL_NUMBER: - if (tns > MAX_STORAGE_CELL_VAL) { - ret = FAIL; - strcpy(mess,"Max Storage cell number should not exceed 15\n"); - FILE_LOG(logERROR,(mess)); - break; - } - retval = setTimer(ind,tns); - break; + case STORAGE_CELL_NUMBER: + if (tns > MAX_STORAGE_CELL_VAL) { + ret = FAIL; + strcpy(mess,"Max Storage cell number should not exceed 15\n"); + FILE_LOG(logERROR,(mess)); + break; + } + retval = setTimer(ind,tns); + break; #endif #ifdef EIGERD - case SUBFRAME_ACQUISITION_TIME: - if (tns > ((int64_t)MAX_SUBFRAME_EXPOSURE_VAL_IN_10NS*10) ) { - ret = FAIL; - strcpy(mess,"Sub Frame exposure time should not exceed 5.368 seconds\n"); - FILE_LOG(logERROR,(mess)); - break; - } - retval = setTimer(ind,tns); - break; - case SUBFRAME_DEADTIME: - subexptime = setTimer(SUBFRAME_ACQUISITION_TIME, -1); - if ((tns + subexptime) > ((int64_t)MAX_SUBFRAME_EXPOSURE_VAL_IN_10NS*10) ) { - ret = FAIL; - sprintf(mess,"Sub Frame Period should not exceed 5.368 seconds. " - "So sub frame dead time should not exceed %lfu seconds " - "(subexptime = %lf seconds)\n", - ((((int64_t)MAX_SUBFRAME_EXPOSURE_VAL_IN_10NS*10) - subexptime)/1E9), - (subexptime/1E9)); - FILE_LOG(logERROR,(mess)); - break; - } - retval = setTimer(ind,tns); - break; + case SUBFRAME_ACQUISITION_TIME: + if (tns > ((int64_t)MAX_SUBFRAME_EXPOSURE_VAL_IN_10NS*10) ) { + ret = FAIL; + strcpy(mess,"Sub Frame exposure time should not exceed 5.368 seconds\n"); + FILE_LOG(logERROR,(mess)); + break; + } + retval = setTimer(ind,tns); + break; + case SUBFRAME_DEADTIME: + subexptime = setTimer(SUBFRAME_ACQUISITION_TIME, -1); + if ((tns + subexptime) > ((int64_t)MAX_SUBFRAME_EXPOSURE_VAL_IN_10NS*10) ) { + ret = FAIL; + sprintf(mess,"Sub Frame Period should not exceed 5.368 seconds. " + "So sub frame dead time should not exceed %lfu seconds " + "(subexptime = %lf seconds)\n", + ((((int64_t)MAX_SUBFRAME_EXPOSURE_VAL_IN_10NS*10) - subexptime)/1E9), + (subexptime/1E9)); + FILE_LOG(logERROR,(mess)); + break; + } + retval = setTimer(ind,tns); + break; #endif - default: - modeNotImplemented(timerName, (int)ind); - break; - } + default: + modeNotImplemented(timerName, (int)ind); + break; + } - // validate - char vtimerName[50] = {0}; - sprintf(vtimerName, "set %s", timerName); + // validate + if (ret != FAIL) { + char vtimerName[50] = {0}; + sprintf(vtimerName, "set %s", timerName); #ifdef EIGERD - validate64(tns, retval, vtimerName, DEC); // copied to server, not read from detector register + validate64(tns, retval, vtimerName, DEC); // copied to server, not read from detector register #else - switch(ind) { - case FRAME_NUMBER: - case CYCLES_NUMBER: - case STORAGE_CELL_NUMBER: - validate64(tns, retval, vtimerName, DEC); // no conversion, so all good - break; - case SAMPLES: - if (retval == -1) { - ret = FAIL; - retval = setTimer(ind, -1); - sprintf(mess, "Could not set samples to %lld. Could not allocate RAM\n", - (long long unsigned int)tns); - FILE_LOG(logERROR,(mess)); - } else - validate64(tns, retval, vtimerName, DEC); // no conversion, so all good - case ACQUISITION_TIME: - case FRAME_PERIOD: - case DELAY_AFTER_TRIGGER: - case SUBFRAME_ACQUISITION_TIME: - case SUBFRAME_DEADTIME: - // losing precision due to conversion to clock (also gotthard master delay is different) - if (validateTimer(ind, tns, retval) == FAIL) { - ret = FAIL; - sprintf(mess, "Could not %s. Set %lld, but read %lld\n", vtimerName, - (long long unsigned int)tns, (long long unsigned int)retval); - FILE_LOG(logERROR,(mess)); - } - break; + switch(ind) { + case FRAME_NUMBER: + case CYCLES_NUMBER: + case STORAGE_CELL_NUMBER: + validate64(tns, retval, vtimerName, DEC); // no conversion, so all good + break; + case SAMPLES: + if (retval == -1) { + ret = FAIL; + retval = setTimer(ind, -1); + sprintf(mess, "Could not set samples to %lld. Could not allocate RAM\n", + (long long unsigned int)tns); + FILE_LOG(logERROR,(mess)); + } else + validate64(tns, retval, vtimerName, DEC); // no conversion, so all good + case ACQUISITION_TIME: + case FRAME_PERIOD: + case DELAY_AFTER_TRIGGER: + case SUBFRAME_ACQUISITION_TIME: + case SUBFRAME_DEADTIME: + // losing precision due to conversion to clock (also gotthard master delay is different) + if (validateTimer(ind, tns, retval) == FAIL) { + ret = FAIL; + sprintf(mess, "Could not %s. Set %lld, but read %lld\n", vtimerName, + (long long unsigned int)tns, (long long unsigned int)retval); + FILE_LOG(logERROR,(mess)); + } + break; - default: - break; - } + default: + break; + } #endif + } } if (ret != FAIL) { FILE_LOG(logDEBUG1, ("Timer index %d: %lld\n", ind, retval)); @@ -2104,9 +2107,11 @@ int send_update(int file_des) { n = sendData(file_des,&i64,sizeof(i64),INT64); if (n < 0) return printSocketReadError(); +#ifndef CHIPTESTBOARDD i64 = setTimer(ACQUISITION_TIME,GET_FLAG); n = sendData(file_des,&i64,sizeof(i64),INT64); if (n < 0) return printSocketReadError(); +#endif #ifdef EIGERD i64 = setTimer(SUBFRAME_ACQUISITION_TIME,GET_FLAG); diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index e3b25b948..e46ac8fde 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -1050,8 +1050,10 @@ int slsDetector::updateDetectorNoWait(sls::ClientSocket &client) { n += client.receiveData(&i64, sizeof(i64)); thisDetector->timerValue[FRAME_NUMBER] = i64; - n += client.receiveData(&i64, sizeof(i64)); - thisDetector->timerValue[ACQUISITION_TIME] = i64; + if (thisDetector->myDetectorType != CHIPTESTBOARD) { + n += client.receiveData(&i64, sizeof(i64)); + thisDetector->timerValue[ACQUISITION_TIME] = i64; + } if (thisDetector->myDetectorType == EIGER) { n += client.receiveData(&i64, sizeof(i64)); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 4117bcf19..fed3075fa 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -4006,66 +4006,12 @@ std::string slsDetectorCommand::cmdADC(int narg, char *args[], int action, int d else if (action == PUT_ACTION) return std::string("cannot set ") + cmd; - if (sscanf(args[0], "adc:%d", &idac) == 1) { - // printf("chiptestboard!\n"); - adc = (dacIndex)(idac + 1000); - } else if (cmd == "temp_adc") - adc = TEMPERATURE_ADC; - else if (cmd == "temp_fpga") - adc = TEMPERATURE_FPGA; - else if (cmd == "temp_fpgaext") - adc = TEMPERATURE_FPGAEXT; - else if (cmd == "temp_10ge") - adc = TEMPERATURE_10GE; - else if (cmd == "temp_dcdc") - adc = TEMPERATURE_DCDC; - else if (cmd == "temp_sodl") - adc = TEMPERATURE_SODL; - else if (cmd == "temp_sodr") - adc = TEMPERATURE_SODR; - else if (cmd == "temp_fpgafl") - adc = TEMPERATURE_FPGA2; - else if (cmd == "temp_fpgafr") - adc = TEMPERATURE_FPGA3; - else if (cmd == "i_a") - adc = I_POWER_A; - else if (cmd == "i_b") - adc = I_POWER_B; - else if (cmd == "i_c") - adc = I_POWER_C; - else if (cmd == "i_d") - adc = I_POWER_D; - else if (cmd == "vm_a") - adc = V_POWER_A; - else if (cmd == "vm_b") - adc = V_POWER_B; - else if (cmd == "vm_c") - adc = V_POWER_C; - else if (cmd == "vm_d") - adc = V_POWER_D; - else if (cmd == "vm_io") - adc = V_POWER_IO; - else if (cmd == "i_io") - adc = I_POWER_IO; - else - return std::string("cannot decode adc ") + cmd; - - myDet->setOnline(ONLINE_FLAG, detPos); - if (myDet->getDetectorTypeAsEnum(detPos) == EIGER || myDet->getDetectorTypeAsEnum(detPos) == JUNGFRAU) { - int val = myDet->getADC(adc, detPos); - if (val == -1) - sprintf(answer, "%d", val); - else - sprintf(answer, "%.2f", (double)val / 1000.000); - } else - sprintf(answer, "%d", myDet->getADC(adc, detPos)); - if (sscanf(args[0],"adc:%d",&idac)==1) { // printf("chiptestboard!\n"); - adc=(dacIndex)(idac+1000); - if (idac < (SLOW_ADC0 - 1000) || idac > (SLOW_ADC_TEMP - 1000)) - return (std::string ("cannot set adc, must be between ") + std::to_string(SLOW_ADC0 - 1000) + - std::string (" and ") + std::to_string(SLOW_ADC_TEMP - 1000)); + adc=(dacIndex)(idac+SLOW_ADC0); + if (idac < 0 || idac > SLOW_ADC_TEMP - SLOW_ADC0) + return (std::string ("cannot set adc, must be between ") + std::to_string(0) + + std::string (" and ") + std::to_string(SLOW_ADC_TEMP - SLOW_ADC0)); } else if (cmd=="temp_adc") adc=TEMPERATURE_ADC; else if (cmd=="temp_fpga") @@ -4118,7 +4064,7 @@ std::string slsDetectorCommand::cmdADC(int narg, char *args[], int action, int d else sprintf(answer,"%d",myDet->getADC(adc, detPos)); //if ((adc == TEMPERATURE_ADC) || (adc == TEMPERATURE_FPGA)) - if (adc<=100) + if (adc<=100 || adc == SLOW_ADC_TEMP) strcat(answer,"°C"); else strcat(answer,"mV"); diff --git a/slsSupportLib/src/ClientSocket.cpp b/slsSupportLib/src/ClientSocket.cpp index 4ca000ef4..2d1f88891 100644 --- a/slsSupportLib/src/ClientSocket.cpp +++ b/slsSupportLib/src/ClientSocket.cpp @@ -51,6 +51,7 @@ void ClientSocket::readReply(int &ret, void *retval, size_t retval_size) { //get error message receiveData(mess, sizeof(mess)); // cprintf(RED, "%s %d returned error: %s", type.c_str(), index, mess); + cprintf(RED, "returned error: %s", mess); // unrecognized function, do not ask for retval if (strstr(mess, "Unrecognized Function") != nullptr)