From e208d3ebe88a536463ff59482d8bb555833e5389 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 19 May 2020 18:59:07 +0200 Subject: [PATCH] WIP --- .../slsDetectorFunctionList.c | 52 +++++++-------- .../include/slsDetectorFunctionList.h | 6 +- .../src/slsDetectorServer_funcs.c | 66 ++++++++++--------- slsDetectorSoftware/src/CmdProxy.cpp | 8 ++- slsDetectorSoftware/src/Detector.cpp | 18 ++++- slsDetectorSoftware/src/Module.cpp | 14 ++-- slsDetectorSoftware/src/Module.h | 4 +- 7 files changed, 97 insertions(+), 71 deletions(-) diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index e541b5d01..97944f504 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -846,7 +846,7 @@ void setNumGates(int val) { } } -int getNumExtGates() { return bus_r(ASIC_EXP_EXT_GATE_NUMBER_REG); } +int getNumGates() { return bus_r(ASIC_EXP_EXT_GATE_NUMBER_REG); } void updateGatePeriod() { uint64_t max = 0; @@ -863,21 +863,27 @@ void updateGatePeriod() { ASIC_EXP_GATE_PERIOD_MSB_REG); } -int setExptime(int gateIndex, int64_t val) { +int64_t getGatePeriod() { + return get64BitReg(ASIC_EXP_GATE_PERIOD_LSB_REG, + ASIC_EXP_GATE_PERIOD_MSB_REG) / + (1E-9 * getFrequency(SYSTEM_C2)); +} + +int setExpTime(int gateIndex, int64_t val) { uint32_t alsb = 0; uint32_t amsb = 0; switch (gateIndex) { case 0: alsb = ASIC_EXP_GATE_0_WIDTH_LSB_REG; - blsb = ASIC_EXP_GATE_0_WIDTH_MSB_REG; + amsb = ASIC_EXP_GATE_0_WIDTH_MSB_REG; break; case 1: alsb = ASIC_EXP_GATE_1_WIDTH_LSB_REG; - blsb = ASIC_EXP_GATE_1_WIDTH_MSB_REG; + amsb = ASIC_EXP_GATE_1_WIDTH_MSB_REG; break; case 2: alsb = ASIC_EXP_GATE_2_WIDTH_LSB_REG; - blsb = ASIC_EXP_GATE_2_WIDTH_MSB_REG; + amsb = ASIC_EXP_GATE_2_WIDTH_MSB_REG; break; default: LOG(logERROR, ("Invalid gate index: %d\n", gateIndex)); @@ -905,19 +911,21 @@ int setExptime(int gateIndex, int64_t val) { return OK; } -int64_t getExptime(int gateIndex) { +int64_t getExpTime(int gateIndex) { + uint32_t alsb = 0; + uint32_t amsb = 0; switch (gateIndex) { case 0: alsb = ASIC_EXP_GATE_0_WIDTH_LSB_REG; - blsb = ASIC_EXP_GATE_0_WIDTH_MSB_REG; + amsb = ASIC_EXP_GATE_0_WIDTH_MSB_REG; break; case 1: alsb = ASIC_EXP_GATE_1_WIDTH_LSB_REG; - blsb = ASIC_EXP_GATE_1_WIDTH_MSB_REG; + amsb = ASIC_EXP_GATE_1_WIDTH_MSB_REG; break; case 2: alsb = ASIC_EXP_GATE_2_WIDTH_LSB_REG; - blsb = ASIC_EXP_GATE_2_WIDTH_MSB_REG; + amsb = ASIC_EXP_GATE_2_WIDTH_MSB_REG; break; default: LOG(logERROR, ("Invalid gate index: %d\n", gateIndex)); @@ -932,15 +940,15 @@ int setGateDelay(int gateIndex, int64_t val) { switch (gateIndex) { case 0: alsb = ASIC_EXP_GATE_0_DELAY_LSB_REG; - blsb = ASIC_EXP_GATE_0_DELAY_MSB_REG; + amsb = ASIC_EXP_GATE_0_DELAY_MSB_REG; break; case 1: alsb = ASIC_EXP_GATE_1_DELAY_LSB_REG; - blsb = ASIC_EXP_GATE_1_DELAY_MSB_REG; + amsb = ASIC_EXP_GATE_1_DELAY_MSB_REG; break; case 2: alsb = ASIC_EXP_GATE_2_DELAY_LSB_REG; - blsb = ASIC_EXP_GATE_2_DELAY_MSB_REG; + amsb = ASIC_EXP_GATE_2_DELAY_MSB_REG; break; default: LOG(logERROR, ("Invalid gate index: %d\n", gateIndex)); @@ -969,18 +977,20 @@ int setGateDelay(int gateIndex, int64_t val) { } int64_t getGateDelay(int gateIndex) { + uint32_t alsb = 0; + uint32_t amsb = 0; switch (gateIndex) { case 0: alsb = ASIC_EXP_GATE_0_DELAY_LSB_REG; - blsb = ASIC_EXP_GATE_0_DELAY_MSB_REG; + amsb = ASIC_EXP_GATE_0_DELAY_MSB_REG; break; case 1: alsb = ASIC_EXP_GATE_1_DELAY_LSB_REG; - blsb = ASIC_EXP_GATE_1_DELAY_MSB_REG; + amsb = ASIC_EXP_GATE_1_DELAY_MSB_REG; break; case 2: alsb = ASIC_EXP_GATE_2_DELAY_LSB_REG; - blsb = ASIC_EXP_GATE_2_DELAY_MSB_REG; + amsb = ASIC_EXP_GATE_2_DELAY_MSB_REG; break; default: LOG(logERROR, ("Invalid gate index: %d\n", gateIndex)); @@ -1205,16 +1215,6 @@ void setTiming(enum timingMode arg) { LOG(logERROR, ("Unknown timing mode %d\n", arg)); return; } - // internal gating - if (arg == AUTO_TIMING || arg == TRIGGER_EXPOSURE) { - setNumGates(1); // should be in firmware - // TOOD: number of counters-> set appropriate gatewidth and - // gatedelay to 0 - setMaxGatePulseWidth(); - } - // external gating - else { - } } } @@ -1942,7 +1942,7 @@ void *start_timer(void *arg) { int64_t periodNs = getPeriod(); int numFrames = (getNumFrames() * getNumTriggers()); - int64_t expUs = getExpTime() / 1000; + int64_t expUs = getGatePeriod() / 1000; // int dr = setDynamicRange(-1); int imagesize = calculateDataBytes(); diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index b36ad13d6..1cdbf2241 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -214,8 +214,10 @@ int64_t getPeriod(); void setNumIntGates(int val); void setNumGates(int val); int getNumGates(); -int setExptime(int gateIndex, int64_t val); -int64_t getExptime(int gateIndex); +void updateGatePeriod(); +int64_t getGatePeriod(); +int setExpTime(int gateIndex, int64_t val); +int64_t getExpTime(int gateIndex); int setGateDelay(int gateIndex, int64_t val); int64_t getGateDelay(int gateIndex); #endif diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 2e92c912b..9fecc7caf 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -329,12 +329,12 @@ void function_table() { flist[F_UPDATE_RATE_CORRECTION] = &update_rate_correction; flist[F_GET_RECEIVER_PARAMETERS] = &get_receiver_parameters; flist[F_START_PATTERN] = &start_pattern; - FLIST[F_SET_NUM_GATES] = &set_num_gates; - FLIST[F_GET_NUM_GATES] = &get_num_gates; - FLIST[F_SET_GATE_DELAY] = &set_gate_delay; - FLIST[F_GET_GATE_DELAY] = &get_gate_delay; - flist[F_GET_EXPTIME_ALL_GATES = &get_exptime_all_gates; - flist[F_GET_GATE_DELAY_ALL_GATES = &get_gate_delay_all_gates; + flist[F_SET_NUM_GATES] = &set_num_gates; + flist[F_GET_NUM_GATES] = &get_num_gates; + flist[F_SET_GATE_DELAY] = &set_gate_delay; + flist[F_GET_GATE_DELAY] = &get_gate_delay; + flist[F_GET_EXPTIME_ALL_GATES] = &get_exptime_all_gates; + flist[F_GET_GATE_DELAY_ALL_GATES] = &get_gate_delay_all_gates; // check if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { @@ -2107,7 +2107,7 @@ int get_exptime(int file_des) { gateIndex); LOG(logERROR, (mess)); } else { - retval = getExptime(gateIndex); + retval = getExpTime(gateIndex); LOG(logDEBUG1, ("retval exptime %lld ns\n", (long long int)retval)); } #else @@ -6953,8 +6953,12 @@ int get_receiver_parameters(int file_des) { if (n < 0) return printSocketReadError(); - // exptime + // exptime +#ifdef MYTHEN3D + i64 = getExpTime(0); +#else i64 = getExpTime(); +#endif n += sendData(file_des, &i64, sizeof(i64), INT64); if (n < 0) return printSocketReadError(); @@ -7212,6 +7216,7 @@ int set_gate_delay(int file_des) { } } } + } #endif return Server_SendResult(file_des, INT64, NULL, 0); } @@ -7228,19 +7233,18 @@ int get_gate_delay(int file_des) { #if !defined(MYTHEN3D) functionNotImplemented(); #else - // get only - if (gateIndex < 0 || gateIndex > 2) { - ret = FAIL; - sprintf(mess, - "Could not set gate delay. Invalid gate index %d. " - "Options [0-2]\n", - gateIndex); - LOG(logERROR, (mess)); - } else { - retval = getGateDelay(gateIndex); - LOG(logDEBUG1, - ("retval gate delay %lld ns\n", (long long int)retval)); - } + // get only + if (gateIndex < 0 || gateIndex > 2) { + ret = FAIL; + sprintf(mess, + "Could not set gate delay. Invalid gate index %d. " + "Options [0-2]\n", + gateIndex); + LOG(logERROR, (mess)); + } else { + retval = getGateDelay(gateIndex); + LOG(logDEBUG1, ("retval gate delay %lld ns\n", (long long int)retval)); + } #endif return Server_SendResult(file_des, INT64, &retval, sizeof(retval)); } @@ -7253,11 +7257,11 @@ int get_exptime_all_gates(int file_des) { #if !defined(MYTHEN3D) functionNotImplemented(); #else - for (int i = 0; i != 2; ++i) { - retvals[i] = getExpTime(i); - LOG(logDEBUG1, ("retval exptime %lld ns (index:%d)\n", - (long long int)retvals[i], i)); - } + for (int i = 0; i != 2; ++i) { + retvals[i] = getExpTime(i); + LOG(logDEBUG1, ("retval exptime %lld ns (index:%d)\n", + (long long int)retvals[i], i)); + } #endif return Server_SendResult(file_des, INT64, retvals, sizeof(retvals)); } @@ -7270,11 +7274,11 @@ int get_gate_delay_all_gates(int file_des) { #if !defined(MYTHEN3D) functionNotImplemented(); #else - for (int i = 0; i != 2; ++i) { - retvals[i] = getGateDelay(i); - LOG(logDEBUG1, ("retval gate delay %lld ns (index:%d)\n", - (long long int)retvals[i], i)); - } + for (int i = 0; i != 2; ++i) { + retvals[i] = getGateDelay(i); + LOG(logDEBUG1, ("retval gate delay %lld ns (index:%d)\n", + (long long int)retvals[i], i)); + } #endif return Server_SendResult(file_des, INT64, retvals, sizeof(retvals)); } diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index e0875d7fc..5bca7fd7b 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -381,7 +381,7 @@ std::string CmdProxy::Exptime(int action) { WrongNumberOfParameters(1); } // vector of exptimes - if (gateIndex == -1 & + if (gateIndex == -1 && det->getDetectorType().squash() == defs::MYTHEN3) { auto t = det->getExptimeForAllGates({det_id}); if (args.size() == 0) { @@ -410,14 +410,14 @@ std::string CmdProxy::Exptime(int action) { std::string time_str(args[0]); std::string unit = RemoveUnit(time_str); auto t = StringTo(time_str, unit); - if (type == MYTHEN3) { + if (type == defs::MYTHEN3) { det->setExptime(gateIndex, t, {det_id}); } else { det->setExptime(t, {det_id}); } } else if (args.size() == 2) { auto t = StringTo(args[0], args[1]); - if (type == MYTHEN3) { + if (type == defs::MYTHEN3) { det->setExptime(gateIndex, t, {det_id}); } else { det->setExptime(t, {det_id}); @@ -434,6 +434,7 @@ std::string CmdProxy::Exptime(int action) { } else { throw sls::RuntimeError("Unknown action"); } + return os.str(); } std::string CmdProxy::Speed(int action) { @@ -1777,6 +1778,7 @@ std::string CmdProxy::GateDelay(int action) { } else { throw sls::RuntimeError("Unknown action"); } + return os.str(); } /* CTB / Moench Specific */ diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 8af4d6ac7..76c2bbc9a 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -1275,7 +1275,14 @@ void Detector::setExptime(int gateIndex, ns t, Positions pos) { } Result> Detector::getExptimeForAllGates(Positions pos) const { - return pimpl->Parallel(&Module::getExptimeForAllGates, pos); + auto t = pimpl->Parallel(&Module::getExptimeForAllGates, pos); + Result> res(t.size()); + for (unsigned int i = 0; i < t.size(); ++i) { + for (unsigned int j = 0; j != 3; ++j) { + res[i][j] = static_cast(t[i][j]); + } + } + return res; } Result Detector::getGateDelay(int gateIndex, Positions pos) const { @@ -1288,7 +1295,14 @@ void Detector::setGateDelay(int gateIndex, ns t, Positions pos) { Result> Detector::getGateDelayForAllGates(Positions pos) const { - return pimpl->Parallel(&Module::getGateDelayForAllGates, pos); + auto t = pimpl->Parallel(&Module::getGateDelayForAllGates, pos); + Result> res(t.size()); + for (unsigned int i = 0; i < t.size(); ++i) { + for (unsigned int j = 0; j != 3; ++j) { + res[i][j] = static_cast(t[i][j]); + } + } + return res; } // CTB/ Moench Specific diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 8131cbcaf..6a2e06e51 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -1041,7 +1041,7 @@ int64_t Module::getExptime(int gateIndex) { void Module::setExptime(int gateIndex, int64_t value) { int64_t prevVal = value; if (shm()->myDetectorType == EIGER) { - prevVal = getExptime(); + prevVal = getExptime(-1); } LOG(logDEBUG1) << "Setting exptime to " << value << "ns (gateindex: " << gateIndex << ")"; @@ -1056,8 +1056,10 @@ void Module::setExptime(int gateIndex, int64_t value) { } } -std::array Module::getExptimeForAllGates() { - return sendToDetector(F_GET_EXPTIME_ALL_GATES); +std::array Module::getExptimeForAllGates() { + std::array retval; + sendToDetector(F_GET_EXPTIME_ALL_GATES, nullptr, retval); + return retval; } int64_t Module::getGateDelay(int gateIndex) { @@ -1071,8 +1073,10 @@ void Module::setGateDelay(int gateIndex, int64_t value) { sendToDetector(F_SET_GATE_DELAY, args, nullptr); } -std::array Module::getGateDelayForAllGates() { - return sendToDetector(F_GET_GATE_DELAY_ALL_GATES); +std::array Module::getGateDelayForAllGates() { + std::array retval; + sendToDetector(F_GET_GATE_DELAY_ALL_GATES, nullptr, retval); + return retval; } int64_t Module::getPeriod() { return sendToDetector(F_GET_PERIOD); } diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index fb42dd31c..03ba3a3d6 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -432,7 +432,7 @@ class Module : public virtual slsDetectorDefs { void setExptime(int gateIndex, int64_t value); /** [Mythen3] for all gates */ - std::array getExptimeForAllGates(); + std::array getExptimeForAllGates(); /** [Mythen3] gatIndex: 0-2 */ int64_t getGateDelay(int gateIndex); @@ -441,7 +441,7 @@ class Module : public virtual slsDetectorDefs { void setGateDelay(int gateIndex, int64_t value); /** [Mythen3] for all gates */ - std::array getGateDelayForAllGates(); + std::array getGateDelayForAllGates(); int64_t getPeriod();