diff --git a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer index 358b97764..f6da7ad81 100755 Binary files a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer and b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer differ diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index 97657bfaf..65ffa1a32 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -41,6 +41,8 @@ int dacValues[NDAC] = {0}; int onChipdacValues[ONCHIP_NDAC][NCHIP] = {0}; int defaultDacValues[NDAC] = {0}; int defaultOnChipdacValues[ONCHIP_NDAC][NCHIP] = {0}; +int injectedChannelsOffset = 0; +int injectedChannelsIncrement = 0; int detPos[2] = {0, 0}; int isInitCheckDone() { @@ -649,6 +651,7 @@ int setOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex, int val) { FILE_LOG(logINFO, ("Setting on chip dac[%d - %s]: 0x%x\n", (int)ind, names[ind], val)); char buffer[2]; + memset(buffer, 0, sizeof(buffer)); buffer[1] = ((val & 0xF) << 4) | (((int)ind) & 0xF); // LSB (4 bits) + ADDR (4 bits) buffer[0] = (val >> 4) & 0x3F; // MSB (6 bits) @@ -1057,6 +1060,43 @@ int getClockDivider(enum CLKINDEX ind) { return (getVCOFrequency(ind) / clkFrequency[ind]); } +int setInjectChannel(int offset, int increment) { + if (offset < 0 || increment < 1) { + FILE_LOG(logERROR, ("Cannot inject channel. Invalid offset %d or increment %d\n", offset, increment)); + return FAIL; + } + + FILE_LOG(logINFO, ("Injecting channels [offset:%d, increment:%d]\n", offset, increment)); + + // 4 bits of padding + 128 bits + 4 bits for address = 136 bits + char buffer[17]; + memset(buffer, 0, sizeof(buffer)); + int startCh = 4; // 4 due to padding + int ich = 0; + for (ich = startCh + offset; ich < startCh + NCHAN; ich = ich + increment) { + buffer[ich] = 1; + } + + for (ich = 0; ich < sizeof(buffer); ++ich) { + printf("%d : 0x%02hhx\n", ich, buffer[ich]); + } + + //int chipIndex = -1; // for all chips + //if (ASIC_Driver_Set(chipIndex, sizeof(buffer), buffer) == FAIL) { + // return FAIL; + //} + + injectedChannelsOffset = offset; + injectedChannelsIncrement = increment; + return OK; +} + +void getInjectedChannels(int* offset, int* increment) { + *offset = injectedChannelsOffset; + *increment = injectedChannelsIncrement; +} + + /* aquisition */ diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index 438569393..7a8040e0e 100755 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -448,6 +448,8 @@ int getVCOFrequency(enum CLKINDEX ind); int getMaxClockDivider(); int setClockDivider(enum CLKINDEX ind, int val); int getClockDivider(enum CLKINDEX ind); +int setInjectChannel(int offset, int increment); +void getInjectedChannels(int* offset, int* increment); #endif diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h index 2d66298eb..c7ec163fc 100755 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h @@ -194,4 +194,6 @@ int get_clock_divider(int); int set_pipeline(int); int get_pipeline(int); int set_on_chip_dac(int); -int get_on_chip_dac(int); \ No newline at end of file +int get_on_chip_dac(int); +int set_inject_channel(int); +int get_inject_channel(int); \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 832400826..acdda0e2d 100755 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -296,6 +296,8 @@ const char* getFunctionName(enum detFuncs func) { case F_GET_PIPELINE: return "F_GET_PIPELINE"; case F_SET_ON_CHIP_DAC: return "F_SET_ON_CHIP_DAC"; case F_GET_ON_CHIP_DAC: return "F_GET_ON_CHIP_DAC"; + case F_SET_INJECT_CHANNEL: return "F_SET_INJECT_CHANNEL"; + case F_GET_INJECT_CHANNEL: return "F_GET_INJECT_CHANNEL"; default: return "Unknown Function"; } @@ -469,6 +471,8 @@ void function_table() { flist[F_GET_PIPELINE] = &get_pipeline; flist[F_SET_ON_CHIP_DAC] = &set_on_chip_dac; flist[F_GET_ON_CHIP_DAC] = &get_on_chip_dac; + flist[F_SET_INJECT_CHANNEL] = &set_inject_channel; + flist[F_GET_INJECT_CHANNEL] = &get_inject_channel; // check if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { @@ -6145,4 +6149,60 @@ int get_on_chip_dac(int file_des) { } #endif return Server_SendResult(file_des, INT32, UPDATE, &retval, sizeof(retval)); -} \ No newline at end of file +} + + + +int set_inject_channel(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int args[2] = {-1, -1}; + + if (receiveData(file_des, args, sizeof(args), INT32) < 0) + return printSocketReadError(); + FILE_LOG(logINFO, ("Setting inject channel: [%d, %d]\n", args[0], args[1])); + +#ifndef GOTTHARD2D + functionNotImplemented(); +#else + // only set + if (Server_VerifyLock() == OK) { + int offset = args[0]; + int increment = args[1]; + if (offset < 0 || increment < 1) { + ret = FAIL; + sprintf(mess, "Could not inject channel. Invalid offset %d or increment %d\n", offset, increment); + FILE_LOG(logERROR, (mess)); + } else { + ret = setInjectChannel(offset, increment); + if (ret == FAIL) { + ret = FAIL; + sprintf(mess, "Could not inject channel\n", offset, increment); + FILE_LOG(logERROR, (mess)); + } + } + } +#endif + return Server_SendResult(file_des, INT32, UPDATE, NULL, 0); +} + + +int get_inject_channel(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int retvals[2] = {-1, -1}; + + FILE_LOG(logDEBUG1, ("Getting injected channels\n")); + +#ifndef GOTTHARD2D + functionNotImplemented(); +#else + // get only + int offset = -1, increment = -1; + getInjectedChannels(&offset, &increment); + FILE_LOG(logDEBUG1, ("Get Injected channels: [offset:%d, increment:%d]\n", offset, increment)); + retvals[0] = offset; + retvals[1] = increment; +#endif + return Server_SendResult(file_des, INT32, UPDATE, retvals, sizeof(retvals)); +} diff --git a/slsDetectorSoftware/include/CmdProxy.h b/slsDetectorSoftware/include/CmdProxy.h index 39e4186ad..60ebb3708 100644 --- a/slsDetectorSoftware/include/CmdProxy.h +++ b/slsDetectorSoftware/include/CmdProxy.h @@ -775,7 +775,9 @@ class CmdProxy { {"extsig", &CmdProxy::extsig}, {"imagetest", &CmdProxy::imagetest}, - /* Gotthard2 Specific */ + /* Gotthard2 Specific */ + {"inj_ch", &CmdProxy::InjectChannel}, + /* CTB Specific */ {"samples", &CmdProxy::Samples}, {"asamples", &CmdProxy::asamples}, diff --git a/slsDetectorSoftware/include/Detector.h b/slsDetectorSoftware/include/Detector.h index b29359cf0..6101b49ac 100644 --- a/slsDetectorSoftware/include/Detector.h +++ b/slsDetectorSoftware/include/Detector.h @@ -873,6 +873,19 @@ class Detector { * Default is 0 */ void setImageTestMode(const int value, Positions pos = {}); + /************************************************** + * * + * Gotthard2 Specific * + * * + * ************************************************/ + + /** [Gotthard2] offset channel, increment channel */ + Result> getInjectChannel(Positions pos = {}); + /** [Gotthard2] + * @param offsetChannel starting channel to be injected + * @param incrementChannel determines succeeding channels to be injected */ + void setInjectChannel(int offsetChannel, int incrementChannel, Positions pos = {}); + /************************************************** * * * CTB Specific * diff --git a/slsDetectorSoftware/include/slsDetector.h b/slsDetectorSoftware/include/slsDetector.h index ed58cb36b..a4c259f53 100755 --- a/slsDetectorSoftware/include/slsDetector.h +++ b/slsDetectorSoftware/include/slsDetector.h @@ -1102,6 +1102,15 @@ class slsDetector : public virtual slsDetectorDefs { * Default is 0 */ void setImageTestMode(const int value); + + /** [Gotthard2] */ + std::array getInjectChannel(); + + /** [Gotthard2] + * @param offsetChannel starting channel to be injected + * @param incrementChannel determines succeeding channels to be injected */ + void setInjectChannel(int offsetChannel, int incrementChannel); + /** * Set/get counter bit in detector (Gotthard) * @param i is -1 to get, 0 to reset and any other value to set the counter diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index e552ed9db..747888ee0 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1017,7 +1017,33 @@ std::string CmdProxy::ClearROI(int action) { return os.str(); } + /* Gotthard2 Specific */ + +std::string CmdProxy::InjectChannel(int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == defs::HELP_ACTION) { + os << "[offset] [increment]\n\t[Gotthard2] Inject channels with current source for calibration. Offset is starting channel that is injected, increment determines succeeding channels to be injected." << '\n'; + } else if (action == defs::GET_ACTION) { + if (args.size() != 0) { + WrongNumberOfParameters(0); + } + auto t = det->getInjectChannel({det_id}); + os << OutString(t) << '\n'; + } else if (action == defs::PUT_ACTION) { + if (args.size() != 2) { + WrongNumberOfParameters(2); + } + det->setInjectChannel(std::stoi(args[0]), std::stoi(args[1]),{det_id}); + os << sls::ToString(args) << '\n'; + } else { + throw sls::RuntimeError("Unknown action"); + } + return os.str(); +} + + /* CTB Specific */ std::string CmdProxy::Samples(int action) { diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index fdc5f4b9d..cd7cacb94 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -1086,6 +1086,16 @@ void Detector::setImageTestMode(int value, Positions pos) { pimpl->Parallel(&slsDetector::setImageTestMode, pos, value); } +// Gotthard2 Specific + +Result> Detector::getInjectChannel(Positions pos) { + return pimpl->Parallel(&slsDetector::getInjectChannel, pos); +} + +void Detector::setInjectChannel(int offsetChannel, int incrementChannel, Positions pos) { + pimpl->Parallel(&slsDetector::setInjectChannel, pos, offsetChannel, incrementChannel); +} + // CTB Specific Result Detector::getNumberOfAnalogSamples(Positions pos) const { diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index a1c6b2440..dded9c63a 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -2345,6 +2345,19 @@ void slsDetector::setImageTestMode(const int value) { sendToDetector(F_SET_IMAGE_TEST_MODE, value, nullptr); } +std::array slsDetector::getInjectChannel() { + std::array retvals{}; + sendToDetector(F_GET_INJECT_CHANNEL, nullptr, retvals); + FILE_LOG(logDEBUG1) << "Inject Channel: [offset: " << retvals[0] << ", increment: " << retvals[1] << ']'; + return retvals; +} + +void slsDetector::setInjectChannel(int offsetChannel, int incrementChannel) { + int args[]{offsetChannel, incrementChannel}; + FILE_LOG(logDEBUG1) << "Setting inject channels [offset: " << offsetChannel << ", increment: " << incrementChannel << ']'; + sendToDetector(F_SET_INJECT_CHANNEL, args, nullptr); +} + int slsDetector::setCounterBit(int cb) { int retval = -1; FILE_LOG(logDEBUG1) << "Sending counter bit " << cb; diff --git a/slsSupportLib/include/sls_detector_funcs.h b/slsSupportLib/include/sls_detector_funcs.h index 4c3ae2825..f92d64e85 100755 --- a/slsSupportLib/include/sls_detector_funcs.h +++ b/slsSupportLib/include/sls_detector_funcs.h @@ -177,6 +177,8 @@ enum detFuncs{ F_GET_PIPELINE, F_SET_ON_CHIP_DAC, F_GET_ON_CHIP_DAC, + F_SET_INJECT_CHANNEL, + F_GET_INJECT_CHANNEL, NUM_DET_FUNCTIONS, RECEIVER_ENUM_START = 256, /**< detector function should not exceed this (detector server should not compile anyway) */ @@ -418,6 +420,8 @@ static const char* getFunctionNameFromEnum(enum detFuncs func) { case F_GET_PIPELINE: return "F_GET_PIPELINE"; case F_SET_ON_CHIP_DAC: return "F_SET_ON_CHIP_DAC"; case F_GET_ON_CHIP_DAC: return "F_GET_ON_CHIP_DAC"; + case F_SET_INJECT_CHANNEL: return "F_SET_INJECT_CHANNEL"; + case F_GET_INJECT_CHANNEL: return "F_GET_INJECT_CHANNEL"; case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; diff --git a/slsSupportLib/include/versionAPI.h b/slsSupportLib/include/versionAPI.h index d87273b7c..378697e76 100644 --- a/slsSupportLib/include/versionAPI.h +++ b/slsSupportLib/include/versionAPI.h @@ -9,4 +9,4 @@ #define APIJUNGFRAU 0x191111 #define APIEIGER 0x191111 #define APIMYTHEN3 0x191111 -#define APIGOTTHARD2 0x191112 +#define APIGOTTHARD2 0x191113