From 1f3fd010a7e860970d5c8cfbd2611fd7284e2bf7 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 17 Jun 2020 15:25:59 +0200 Subject: [PATCH] reordering WIP --- slsDetectorSoftware/include/Detector.h | 2 +- slsDetectorSoftware/src/Detector.cpp | 23 +- slsDetectorSoftware/src/Module.cpp | 1786 +++++++++---------- slsDetectorSoftware/src/Module.h | 739 ++------ slsReceiverSoftware/src/ClientInterface.cpp | 46 +- slsReceiverSoftware/src/Implementation.cpp | 29 +- slsReceiverSoftware/src/Implementation.h | 6 +- slsSupportLib/include/ToString.h | 3 + slsSupportLib/include/sls_detector_defs.h | 2 +- slsSupportLib/src/ToString.cpp | 52 + 10 files changed, 1148 insertions(+), 1540 deletions(-) diff --git a/slsDetectorSoftware/include/Detector.h b/slsDetectorSoftware/include/Detector.h index c03e9638d..6ea27deae 100644 --- a/slsDetectorSoftware/include/Detector.h +++ b/slsDetectorSoftware/include/Detector.h @@ -43,7 +43,7 @@ class Detector { * ************************************************/ /* Free the shared memory of this detector and all modules - * belonging to it.*/ + * belonging to it */ void freeSharedMemory(); void loadConfig(const std::string &fname); diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index ce698f575..cf91efb03 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -376,25 +376,25 @@ void Detector::setClockDivider(int clkIndex, int value, Positions pos) { } Result Detector::getHighVoltage(Positions pos) const { - return pimpl->Parallel(&Module::setDAC, pos, -1, defs::HIGH_VOLTAGE, 0); + return pimpl->Parallel(&Module::getDAC, pos, defs::HIGH_VOLTAGE, false); } void Detector::setHighVoltage(int value, Positions pos) { - pimpl->Parallel(&Module::setDAC, pos, value, defs::HIGH_VOLTAGE, 0); + pimpl->Parallel(&Module::setDAC, pos, value, defs::HIGH_VOLTAGE, false); } Result Detector::getPowerChip(Positions pos) const { - return pimpl->Parallel(&Module::powerChip, pos, -1); + return pimpl->Parallel(&Module::getPowerChip, pos); } void Detector::setPowerChip(bool on, Positions pos) { if ((pos.empty() || pos[0] == -1) && on && pimpl->size() > 3) { for (int i = 0; i != pimpl->size(); ++i) { - pimpl->Parallel(&Module::powerChip, {i}, static_cast(on)); + pimpl->Parallel(&Module::setPowerChip, {i}, on); usleep(1000 * 1000); } } else { - pimpl->Parallel(&Module::powerChip, pos, static_cast(on)); + pimpl->Parallel(&Module::setPowerChip, pos, on); } } @@ -486,7 +486,7 @@ std::vector Detector::getDacList() const { Result Detector::getDAC(defs::dacIndex index, bool mV, Positions pos) const { - return pimpl->Parallel(&Module::setDAC, pos, -1, index, mV); + return pimpl->Parallel(&Module::getDAC, pos, index, mV); } void Detector::setDAC(defs::dacIndex index, int value, bool mV, Positions pos) { @@ -690,12 +690,11 @@ Result Detector::printRxConfiguration(Positions pos) const { } Result Detector::getTenGiga(Positions pos) const { - return pimpl->Parallel(&Module::enableTenGigabitEthernet, pos, -1); + return pimpl->Parallel(&Module::getTenGiga, pos); } void Detector::setTenGiga(bool value, Positions pos) { - pimpl->Parallel(&Module::enableTenGigabitEthernet, pos, - static_cast(value)); + pimpl->Parallel(&Module::setTenGiga, pos, value); } Result Detector::getTenGigaFlowControl(Positions pos) const { @@ -780,7 +779,7 @@ void Detector::setRxPort(int port, int module_id) { } Result Detector::getRxFifoDepth(Positions pos) const { - return pimpl->Parallel(&Module::setReceiverFifoDepth, pos, -1); + return pimpl->Parallel(&Module::getReceiverFifoDepth, pos); } void Detector::setRxFifoDepth(int nframes, Positions pos) { @@ -1440,7 +1439,7 @@ Result Detector::getVoltage(defs::dacIndex index, Positions pos) const { default: throw RuntimeError("Unknown Voltage Index"); } - return pimpl->Parallel(&Module::setDAC, pos, -1, index, 1); + return pimpl->Parallel(&Module::getDAC, pos, index, true); } void Detector::setVoltage(defs::dacIndex index, int value, Positions pos) { @@ -1456,7 +1455,7 @@ void Detector::setVoltage(defs::dacIndex index, int value, Positions pos) { default: throw RuntimeError("Unknown Voltage Index"); } - pimpl->Parallel(&Module::setDAC, pos, value, index, 1); + pimpl->Parallel(&Module::setDAC, pos, value, index, true); } Result Detector::getADCEnableMask(Positions pos) const { diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 09c62596c..bcf01e5be 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -20,9 +20,11 @@ namespace sls { -// create shm -Module::Module(detectorType type, int multi_id, int det_id, bool verify) - : detId(det_id), shm(multi_id, det_id) { +// Configuration + +// creating new shm +Module::Module(detectorType type, int det_id, int module_id, bool verify) + : moduleId(module_id), shm(det_id, module_id) { // ensure shared memory was not created before if (shm.IsExisting()) { @@ -32,68 +34,50 @@ Module::Module(detectorType type, int multi_id, int det_id, bool verify) shm.RemoveSharedMemory(); } - initSharedMemory(type, multi_id, verify); + initSharedMemory(type, det_id, verify); } -// pick up from shm -Module::Module(int multi_id, int det_id, bool verify) - : detId(det_id), shm(multi_id, det_id) { +// opening existing shm +Module::Module(int det_id, int module_id, bool verify) + : moduleId(module_id), shm(det_id, module_id) { - // getDetectorType From shm will check if it was already existing - detectorType type = getDetectorTypeFromShm(multi_id, verify); - initSharedMemory(type, multi_id, verify); + // getDetectorType From shm will check if existing + detectorType type = getDetectorTypeFromShm(det_id, verify); + initSharedMemory(type, det_id, verify); } Module::~Module() = default; +void Module::freeSharedMemory() { + if (shm.IsExisting()) { + shm.RemoveSharedMemory(); + } +} + bool Module::isFixedPatternSharedMemoryCompatible() { return (shm()->shmversion >= SLS_SHMAPIVERSION); } -void Module::checkDetectorVersionCompatibility() { - int fnum = F_CHECK_VERSION; - int64_t arg = 0; +std::string Module::getHostname() const { return shm()->hostname; } - // get api version number for detector server - switch (shm()->myDetectorType) { - case EIGER: - arg = APIEIGER; - break; - case JUNGFRAU: - arg = APIJUNGFRAU; - break; - case GOTTHARD: - arg = APIGOTTHARD; - break; - case CHIPTESTBOARD: - arg = APICTB; - break; - case MOENCH: - arg = APIMOENCH; - break; - case MYTHEN3: - arg = APIMYTHEN3; - break; - case GOTTHARD2: - arg = APIGOTTHARD2; - break; - default: - throw NotImplementedError( - "Check version compatibility is not implemented for this detector"); +void Module::setHostname(const std::string &hostname, + const bool initialChecks) { + sls::strcpy_safe(shm()->hostname, hostname.c_str()); + auto client = DetectorSocket(shm()->hostname, shm()->controlPort); + client.close(); + try { + checkDetectorVersionCompatibility(); + LOG(logINFO) << "Detector Version Compatibility - Success"; + } catch (const DetectorError &e) { + if (!initialChecks) { + LOG(logWARNING) << "Bypassing Initial Checks at your own risk!"; + } else { + throw; + } + } + if (shm()->myDetectorType == EIGER) { + setActivate(true); } - LOG(logDEBUG1) << "Checking version compatibility with detector with value " - << std::hex << arg << std::dec; - - sendToDetector(fnum, arg, nullptr); - sendToDetectorStop(fnum, arg, nullptr); -} - -void Module::checkReceiverVersionCompatibility() { - // TODO! Verify that this works as intended when version don't match - int64_t arg = APIRECEIVER; - LOG(logDEBUG1) << "Checking version compatibility with receiver with value " - << std::hex << arg << std::dec; - sendToReceiver(F_RECEIVER_CHECK_VERSION, arg, nullptr); } int64_t Module::getFirmwareVersion() { @@ -115,6 +99,659 @@ int64_t Module::getReceiverSoftwareVersion() const { return -1; } +// static function +slsDetectorDefs::detectorType +Module::getTypeFromDetector(const std::string &hostname, int cport) { + int fnum = F_GET_DETECTOR_TYPE; + int ret = FAIL; + detectorType retval = GENERIC; + LOG(logDEBUG1) << "Getting detector type "; + sls::ClientSocket cs("Detector", hostname, cport); + cs.Send(reinterpret_cast(&fnum), sizeof(fnum)); + cs.Receive(reinterpret_cast(&ret), sizeof(ret)); + cs.Receive(reinterpret_cast(&retval), sizeof(retval)); + LOG(logDEBUG1) << "Detector type is " << retval; + return retval; +} + +slsDetectorDefs::detectorType Module::getDetectorType() const { + return shm()->myDetectorType; +} + +void Module::updateNumberOfChannels() { + if (shm()->myDetectorType == CHIPTESTBOARD || + shm()->myDetectorType == MOENCH) { + std::array retvals{}; + sendToDetector(F_GET_NUM_CHANNELS, nullptr, retvals); + shm()->nChan.x = retvals[0]; + shm()->nChan.y = retvals[1]; + } +} + +slsDetectorDefs::xy Module::getNumberOfChannels() const { + slsDetectorDefs::xy coord{}; + coord.x = (shm()->nChan.x * shm()->nChip.x); + coord.y = (shm()->nChan.y * shm()->nChip.y); + return coord; +} + +void Module::updateNumberOfDetector(slsDetectorDefs::xy det) { + shm()->numberOfDetector = det; + int args[2] = {shm()->numberOfDetector.y, moduleId}; + sendToDetector(F_SET_POSITION, args, nullptr); +} + +slsDetectorDefs::detectorSettings Module::getSettings() { + auto r = sendToDetector(F_SET_SETTINGS, -1); + return static_cast(r); +} + +void Module::setSettings(detectorSettings isettings) { + if (shm()->myDetectorType == EIGER) { + throw RuntimeError( + "Cannot set settings for Eiger. Use threshold energy."); + } + sendToDetector(F_SET_SETTINGS, static_cast(isettings)); +} + +void Module::loadSettingsFile(const std::string &fname) { + std::string fn = fname; + std::ostringstream ostfn; + ostfn << fname; + + // find specific file if it has detid in file name (.snxxx) + if (shm()->myDetectorType == EIGER || shm()->myDetectorType == MYTHEN3) { + if (fname.find(".sn") == std::string::npos && + fname.find(".trim") == std::string::npos && + fname.find(".settings") == std::string::npos) { + ostfn << ".sn" << std::setfill('0') << std::setw(3) << std::dec + << getSerialNumber(); + } + } else { + throw RuntimeError("not implemented for this detector"); + } + fn = ostfn.str(); + auto myMod = readSettingsFile(fn); + setModule(myMod); +} + +int Module::getAllTrimbits() { + return sendToDetector(F_SET_ALL_TRIMBITS, -1); +} + +void Module::setAllTrimbits(int val) { + sendToDetector(F_SET_ALL_TRIMBITS, val); +} + +int64_t Module::getNumberOfFrames() { + return sendToDetector(F_GET_NUM_FRAMES); +} + +void Module::setNumberOfFrames(int64_t value) { + sendToDetector(F_SET_NUM_FRAMES, value, nullptr); + if (shm()->useReceiverFlag) { + sendToReceiver(F_RECEIVER_SET_NUM_FRAMES, value, nullptr); + } +} + +int64_t Module::getNumberOfTriggers() { + return sendToDetector(F_GET_NUM_TRIGGERS); +} + +void Module::setNumberOfTriggers(int64_t value) { + sendToDetector(F_SET_NUM_TRIGGERS, value, nullptr); + if (shm()->useReceiverFlag) { + sendToReceiver(F_SET_RECEIVER_NUM_TRIGGERS, value, nullptr); + } +} + +int64_t Module::getPeriod() { return sendToDetector(F_GET_PERIOD); } + +void Module::setPeriod(int64_t value) { + sendToDetector(F_SET_PERIOD, value, nullptr); + if (shm()->useReceiverFlag) { + sendToReceiver(F_RECEIVER_SET_PERIOD, value, nullptr); + } +} + +int64_t Module::getDelayAfterTrigger() { + return sendToDetector(F_GET_DELAY_AFTER_TRIGGER); +} + +void Module::setDelayAfterTrigger(int64_t value) { + sendToDetector(F_SET_DELAY_AFTER_TRIGGER, value, nullptr); +} + +int64_t Module::getNumberOfFramesLeft() const { + int64_t retval = -1; + sendToDetectorStop(F_GET_FRAMES_LEFT, nullptr, retval); + return retval; +} + +int64_t Module::getNumberOfTriggersLeft() const { + int64_t retval = -1; + sendToDetectorStop(F_GET_TRIGGERS_LEFT, nullptr, retval); + return retval; +} + +int64_t Module::getDelayAfterTriggerLeft() const { + int64_t retval = -1; + sendToDetectorStop(F_GET_DELAY_AFTER_TRIGGER_LEFT, nullptr, retval); + return retval; +} + +int64_t Module::getPeriodLeft() const { + int64_t retval = -1; + sendToDetectorStop(F_GET_PERIOD_LEFT, nullptr, retval); + return retval; +} + +slsDetectorDefs::timingMode Module::getTimingMode() { + return sendToDetector(F_SET_TIMING_MODE, -1); +} + +void Module::setTimingMode(timingMode value) { + timingMode retval = GET_TIMING_MODE; + sendToDetector(F_SET_TIMING_MODE, static_cast(value), retval); + if (shm()->useReceiverFlag) { + sendToReceiver(F_SET_RECEIVER_TIMING_MODE, value, nullptr); + } +} + +int Module::getClockDivider(int clkIndex) { + return sendToDetector(F_GET_CLOCK_DIVIDER, clkIndex); +} + +void Module::setClockDivider(int clkIndex, int value) { + int args[]{clkIndex, value}; + sendToDetector(F_SET_CLOCK_DIVIDER, args, nullptr); +} + +int Module::getClockPhase(int clkIndex, bool inDegrees) { + int args[]{clkIndex, static_cast(inDegrees)}; + return sendToDetector(F_GET_CLOCK_PHASE, args); +} + +void Module::setClockPhase(int clkIndex, int value, bool inDegrees) { + int args[]{clkIndex, value, static_cast(inDegrees)}; + sendToDetector(F_SET_CLOCK_PHASE, args, nullptr); +} + +int Module::getMaxClockPhaseShift(int clkIndex) { + return sendToDetector(F_GET_MAX_CLOCK_PHASE_SHIFT, clkIndex); +} + +int Module::getClockFrequency(int clkIndex) { + return sendToDetector(F_GET_CLOCK_FREQUENCY, clkIndex); +} + +void Module::setClockFrequency(int clkIndex, int value) { + int args[]{clkIndex, value}; + sendToDetector(F_SET_CLOCK_FREQUENCY, args, nullptr); +} + +int Module::getDAC(dacIndex index, bool mV) { + int args[]{static_cast(index), static_cast(mV), -1}; + return sendToDetector(F_SET_DAC, args); +} + +void Module::setDAC(int val, dacIndex index, bool mV) { + int args[]{static_cast(index), static_cast(mV), val}; + sendToDetector(F_SET_DAC, args); +} + +bool Module::getPowerChip() { + int arg = -1; + return sendToDetector(F_POWER_CHIP, arg); +} + +void Module::setPowerChip(bool on) { + sendToDetector(F_POWER_CHIP, static_cast(on)); +} + +int Module::getImageTestMode() { + return sendToDetector(F_GET_IMAGE_TEST_MODE); +} + +void Module::setImageTestMode(const int value) { + sendToDetector(F_SET_IMAGE_TEST_MODE, value, nullptr); +} + +int Module::getADC(dacIndex index) { + return sendToDetector(F_GET_ADC, static_cast(index)); +} + +int Module::getOnChipDAC(slsDetectorDefs::dacIndex index, int chipIndex) { + int args[]{static_cast(index), chipIndex}; + return sendToDetector(F_GET_ON_CHIP_DAC, args); +} + +void Module::setOnChipDAC(slsDetectorDefs::dacIndex index, int chipIndex, + int value) { + int args[]{static_cast(index), chipIndex, value}; + sendToDetector(F_SET_ON_CHIP_DAC, args, nullptr); +} + +void Module::startReceiver() { + shm()->stoppedFlag = false; + sendToReceiver(F_START_RECEIVER, nullptr, nullptr); +} + +void Module::stopReceiver() { + int arg = static_cast(shm()->stoppedFlag); + sendToReceiver(F_STOP_RECEIVER, arg, nullptr); +} + +void Module::prepareAcquisition() { sendToDetector(F_PREPARE_ACQUISITION); } + +void Module::startAcquisition() { + shm()->stoppedFlag = false; + sendToDetector(F_START_ACQUISITION); +} + +void Module::stopAcquisition() { + // get status before stopping acquisition + runStatus s = ERROR, r = ERROR; + bool zmqstreaming = false; + if (shm()->useReceiverFlag && getReceiverStreaming()) { + zmqstreaming = true; + s = getRunStatus(); + r = getReceiverStatus(); + } + sendToDetectorStop(F_STOP_ACQUISITION); + shm()->stoppedFlag = true; + // if rxr streaming and acquisition finished, restream dummy stop packet + if (zmqstreaming && (s == IDLE) && (r == IDLE)) { + restreamStopFromReceiver(); + } +} + +slsDetectorDefs::runStatus Module::getRunStatus() const { + return sendToDetectorStop(F_GET_RUN_STATUS); +} + +slsDetectorDefs::runStatus Module::getReceiverStatus() const { + return sendToReceiver(F_GET_RECEIVER_STATUS); +} + +int64_t Module::getFramesCaughtByReceiver() const { + return sendToReceiver(F_GET_RECEIVER_FRAMES_CAUGHT); +} + +std::vector Module::getNumMissingPackets() const { + // TODO!(Erik) Refactor + LOG(logDEBUG1) << "Getting num missing packets"; + if (shm()->useReceiverFlag) { + int fnum = F_GET_NUM_MISSING_PACKETS; + int ret = FAIL; + auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); + client.Send(&fnum, sizeof(fnum)); + client.Receive(&ret, sizeof(ret)); + if (ret == FAIL) { + char mess[MAX_STR_LENGTH]{}; + client.Receive(mess, MAX_STR_LENGTH); + throw RuntimeError("Receiver " + std::to_string(moduleId) + + " returned error: " + std::string(mess)); + } else { + int nports = -1; + client.Receive(&nports, sizeof(nports)); + uint64_t mp[nports]; + memset(mp, 0, sizeof(mp)); + client.Receive(mp, sizeof(mp)); + std::vector retval(mp, mp + nports); + LOG(logDEBUG1) << "Missing packets of Receiver" << moduleId << ": " + << sls::ToString(retval); + return retval; + } + } + throw RuntimeError("No receiver to get missing packets."); +} + +uint64_t Module::getStartingFrameNumber() { + return sendToDetector(F_GET_STARTING_FRAME_NUMBER); +} + +void Module::setStartingFrameNumber(uint64_t value) { + sendToDetector(F_SET_STARTING_FRAME_NUMBER, value, nullptr); +} + +void Module::sendSoftwareTrigger() { sendToDetectorStop(F_SOFTWARE_TRIGGER); } + +int Module::getNumberofUDPInterfacesFromShm() { + return shm()->numUDPInterfaces; +} + +int Module::getNumberofUDPInterfaces() { + shm()->numUDPInterfaces = sendToDetector(F_GET_NUM_INTERFACES); + return shm()->numUDPInterfaces; +} + +void Module::setNumberofUDPInterfaces(int n) { + sendToDetector(F_SET_NUM_INTERFACES, n, nullptr); + shm()->numUDPInterfaces = n; + if (shm()->useReceiverFlag) { + sendToReceiver(F_SET_RECEIVER_NUM_INTERFACES, n, nullptr); + } +} + +int Module::getSelectedUDPInterface() { + return sendToDetector(F_GET_INTERFACE_SEL); +} + +void Module::selectUDPInterface(int n) { + sendToDetector(F_SET_INTERFACE_SEL, n, nullptr); +} + +sls::IpAddr Module::getSourceUDPIP() { + return sendToDetector(F_GET_SOURCE_UDP_IP); +} + +void Module::setSourceUDPIP(const IpAddr ip) { + if (ip == 0) { + throw RuntimeError("Invalid source udp ip address"); + } + sendToDetector(F_SET_SOURCE_UDP_IP, ip, nullptr); +} + +sls::IpAddr Module::getSourceUDPIP2() { + return sendToDetector(F_GET_SOURCE_UDP_IP2); +} + +void Module::setSourceUDPIP2(const IpAddr ip) { + if (ip == 0) { + throw RuntimeError("Invalid source udp ip address2"); + } + sendToDetector(F_SET_SOURCE_UDP_IP2, ip, nullptr); +} + +sls::MacAddr Module::getSourceUDPMAC() { + return sendToDetector(F_GET_SOURCE_UDP_MAC); +} + +void Module::setSourceUDPMAC(const sls::MacAddr mac) { + if (mac == 0) { + throw RuntimeError("Invalid source udp mac address"); + } + sendToDetector(F_SET_SOURCE_UDP_MAC, mac, nullptr); +} + +sls::MacAddr Module::getSourceUDPMAC2() { + return sendToDetector(F_GET_SOURCE_UDP_MAC2); +} + +void Module::setSourceUDPMAC2(const sls::MacAddr mac) { + if (mac == 0) { + throw RuntimeError("Invalid source udp mac address2"); + } + sendToDetector(F_SET_SOURCE_UDP_MAC2, mac, nullptr); +} + +sls::IpAddr Module::getDestinationUDPIP() { + return sendToDetector(F_GET_DEST_UDP_IP); +} + +void Module::setDestinationUDPIP(const IpAddr ip) { + if (ip == 0) { + throw RuntimeError("Invalid destination udp ip address"); + } + sendToDetector(F_SET_DEST_UDP_IP, ip, nullptr); + if (shm()->useReceiverFlag) { + sls::MacAddr retval(0LU); + sendToReceiver(F_SET_RECEIVER_UDP_IP, ip, retval); + LOG(logINFO) << "Setting destination udp mac of detector " << moduleId + << " to " << retval; + sendToDetector(F_SET_DEST_UDP_MAC, retval, nullptr); + } +} + +sls::IpAddr Module::getDestinationUDPIP2() { + return sendToDetector(F_GET_DEST_UDP_IP2); +} + +void Module::setDestinationUDPIP2(const IpAddr ip) { + LOG(logDEBUG1) << "Setting destination udp ip2 to " << ip; + if (ip == 0) { + throw RuntimeError("Invalid destination udp ip address2"); + } + + sendToDetector(F_SET_DEST_UDP_IP2, ip, nullptr); + if (shm()->useReceiverFlag) { + sls::MacAddr retval(0LU); + sendToReceiver(F_SET_RECEIVER_UDP_IP2, ip, retval); + LOG(logINFO) << "Setting destination udp mac2 of detector " << moduleId + << " to " << retval; + sendToDetector(F_SET_DEST_UDP_MAC2, retval, nullptr); + } +} + +sls::MacAddr Module::getDestinationUDPMAC() { + return sendToDetector(F_GET_DEST_UDP_MAC); +} + +void Module::setDestinationUDPMAC(const MacAddr mac) { + if (mac == 0) { + throw RuntimeError("Invalid destination udp mac address"); + } + sendToDetector(F_SET_DEST_UDP_MAC, mac, nullptr); +} + +sls::MacAddr Module::getDestinationUDPMAC2() { + return sendToDetector(F_GET_DEST_UDP_MAC2); +} + +void Module::setDestinationUDPMAC2(const MacAddr mac) { + if (mac == 0) { + throw RuntimeError("Invalid desinaion udp mac address2"); + } + sendToDetector(F_SET_DEST_UDP_MAC2, mac, nullptr); +} + +int Module::getDestinationUDPPort() { + return sendToDetector(F_GET_DEST_UDP_PORT); +} + +void Module::setDestinationUDPPort(const int port) { + sendToDetector(F_SET_DEST_UDP_PORT, port, nullptr); + if (shm()->useReceiverFlag) { + sendToReceiver(F_SET_RECEIVER_UDP_PORT, port, nullptr); + } +} + +int Module::getDestinationUDPPort2() { + return sendToDetector(F_GET_DEST_UDP_PORT2); +} + +void Module::setDestinationUDPPort2(const int port) { + sendToDetector(F_SET_DEST_UDP_PORT2, port, nullptr); + if (shm()->useReceiverFlag) { + sendToReceiver(F_SET_RECEIVER_UDP_PORT2, port, nullptr); + } +} + +std::string Module::printReceiverConfiguration() { + std::ostringstream os; + os << "\n\nDetector " << moduleId << "\nReceiver Hostname:\t" + << getReceiverHostname(); + + if (shm()->myDetectorType == JUNGFRAU) { + os << "\nNumber of Interfaces:\t" << getNumberofUDPInterfaces() + << "\nSelected Interface:\t" << getSelectedUDPInterface(); + } + + os << "\nDetector UDP IP:\t" << getSourceUDPIP() << "\nDetector UDP MAC:\t" + << getSourceUDPMAC() << "\nReceiver UDP IP:\t" << getDestinationUDPIP() + << "\nReceiver UDP MAC:\t" << getDestinationUDPMAC(); + + if (shm()->myDetectorType == JUNGFRAU) { + os << "\nDetector UDP IP2:\t" << getSourceUDPIP2() + << "\nDetector UDP MAC2:\t" << getSourceUDPMAC2() + << "\nReceiver UDP IP2:\t" << getDestinationUDPIP2() + << "\nReceiver UDP MAC2:\t" << getDestinationUDPMAC2(); + } + os << "\nReceiver UDP Port:\t" << getDestinationUDPPort(); + if (shm()->myDetectorType == JUNGFRAU || shm()->myDetectorType == EIGER) { + os << "\nReceiver UDP Port2:\t" << getDestinationUDPPort2(); + } + os << "\n"; + return os.str(); +} + +bool Module::getTenGiga() { + int arg = -1; + return static_cast(sendToDetector(F_ENABLE_TEN_GIGA, arg)); +} + +void Module::setTenGiga(bool value) { + int arg = static_cast(value); + int retval = -1; + sendToDetector(F_ENABLE_TEN_GIGA, arg, retval); + sendToDetectorStop(F_ENABLE_TEN_GIGA, arg); + arg = retval; + if (shm()->useReceiverFlag && arg != -1) { + sendToReceiver(F_ENABLE_RECEIVER_TEN_GIGA, arg); + } +} + +bool Module::getTenGigaFlowControl() { + return sendToDetector(F_GET_TEN_GIGA_FLOW_CONTROL); +} + +void Module::setTenGigaFlowControl(bool enable) { + int arg = static_cast(enable); + sendToDetector(F_SET_TEN_GIGA_FLOW_CONTROL, arg, nullptr); +} + +int Module::getTransmissionDelayFrame() { + return sendToDetector(F_GET_TRANSMISSION_DELAY_FRAME); +} + +void Module::setTransmissionDelayFrame(int value) { + sendToDetector(F_SET_TRANSMISSION_DELAY_FRAME, value, nullptr); +} + +int Module::getTransmissionDelayLeft() { + return sendToDetector(F_GET_TRANSMISSION_DELAY_LEFT); +} + +void Module::setTransmissionDelayLeft(int value) { + sendToDetector(F_SET_TRANSMISSION_DELAY_LEFT, value, nullptr); +} + +int Module::getTransmissionDelayRight() { + return sendToDetector(F_GET_TRANSMISSION_DELAY_RIGHT); +} + +void Module::setTransmissionDelayRight(int value) { + sendToDetector(F_SET_TRANSMISSION_DELAY_RIGHT, value, nullptr); +} + +bool Module::getUseReceiverFlag() const { return shm()->useReceiverFlag; } + +std::string Module::getReceiverHostname() const { + return std::string(shm()->rxHostname); +} + +void Module::setReceiverHostname(const std::string &receiverIP) { + LOG(logDEBUG1) << "Setting up Receiver with " << receiverIP; + // recieverIP is none + if (receiverIP == "none") { + memset(shm()->rxHostname, 0, MAX_STR_LENGTH); + sls::strcpy_safe(shm()->rxHostname, "none"); + shm()->useReceiverFlag = false; + } + + // stop acquisition if running + if (getRunStatus() == RUNNING) { + LOG(logWARNING) << "Acquisition already running, Stopping it."; + stopAcquisition(); + } + + // start updating + std::string host = receiverIP; + auto res = sls::split(host, ':'); + if (res.size() > 1) { + host = res[0]; + shm()->rxTCPPort = std::stoi(res[1]); + } + sls::strcpy_safe(shm()->rxHostname, host.c_str()); + shm()->useReceiverFlag = true; + checkReceiverVersionCompatibility(); + + // populate parameters from detector + rxParameters retval; + sendToDetector(F_GET_RECEIVER_PARAMETERS, nullptr, retval); + + // populate from shared memory + retval.detType = shm()->myDetectorType; + retval.numberOfDetector.x = shm()->numberOfDetector.x; + retval.numberOfDetector.y = shm()->numberOfDetector.y; + retval.moduleId = moduleId; + memset(retval.hostname, 0, sizeof(retval.hostname)); + strcpy_safe(retval.hostname, shm()->hostname); + + sls::MacAddr retvals[2]; + sendToReceiver(F_SETUP_RECEIVER, retval, retvals); + // update detectors with dest mac + if (retval.udp_dstmac == 0 && retvals[0] != 0) { + LOG(logINFO) << "Setting destination udp mac of " + "detector " + << moduleId << " to " << retvals[0]; + sendToDetector(F_SET_DEST_UDP_MAC, retvals[0], nullptr); + } + if (retval.udp_dstmac2 == 0 && retvals[1] != 0) { + LOG(logINFO) << "Setting destination udp mac2 of " + "detector " + << moduleId << " to " << retvals[1]; + sendToDetector(F_SET_DEST_UDP_MAC2, retvals[1], nullptr); + } + + // update numinterfaces if different + shm()->numUDPInterfaces = retval.udpInterfaces; + + if (shm()->myDetectorType == MOENCH) { + setAdditionalJsonParameter("adcmask_1g", + std::to_string(retval.adcMask)); + setAdditionalJsonParameter("adcmask_10g", + std::to_string(retval.adc10gMask)); + } + + // to use rx_hostname if empty and also update client zmqip + updateReceiverStreamingIP(); +} + +int Module::getReceiverPort() const { return shm()->rxTCPPort; } + +int Module::setReceiverPort(int port_number) { + if (port_number >= 0 && port_number != shm()->rxTCPPort) { + if (shm()->useReceiverFlag) { + int retval = -1; + sendToReceiver(F_SET_RECEIVER_PORT, port_number, retval); + shm()->rxTCPPort = retval; + } else { + shm()->rxTCPPort = port_number; + } + } + return shm()->rxTCPPort; +} + +int Module::getReceiverFifoDepth() { + int arg = -1; + return sendToReceiver(F_SET_RECEIVER_FIFO_DEPTH, arg); +} + +void Module::setReceiverFifoDepth(int n_frames) { + sendToReceiver(F_SET_RECEIVER_FIFO_DEPTH, n_frames); +} + +bool Module::getReceiverSilentMode() { + return sendToReceiver(F_GET_RECEIVER_SILENT_MODE); +} + +void Module::setReceiverSilentMode(bool enable) { + sendToReceiver(F_SET_RECEIVER_SILENT_MODE, static_cast(enable), + nullptr); +} + void Module::sendToDetector(int fnum, const void *args, size_t args_size, void *retval, size_t retval_size) { auto client = DetectorSocket(shm()->hostname, shm()->controlPort); @@ -124,17 +761,31 @@ void Module::sendToDetector(int fnum, const void *args, size_t args_size, template void Module::sendToDetector(int fnum, const Arg &args, Ret &retval) { + LOG(logDEBUG1) << "Sending: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", nullptr, 0, " << typeid(Ret).name() << ", " + << sizeof(Ret) << "]"; sendToDetector(fnum, &args, sizeof(args), &retval, sizeof(retval)); + LOG(logDEBUG1) << "Got back: " << ToString(retval); } template void Module::sendToDetector(int fnum, const Arg &args, std::nullptr_t) { + LOG(logDEBUG1) << "Sending: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", " << typeid(Arg).name() << ", " << sizeof(Arg) + << ", nullptr, 0 ]"; sendToDetector(fnum, &args, sizeof(args), nullptr, 0); } template void Module::sendToDetector(int fnum, std::nullptr_t, Ret &retval) { + LOG(logDEBUG1) << "Sending: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", nullptr, 0, " << typeid(Ret).name() << ", " + << sizeof(Ret) << "]"; sendToDetector(fnum, nullptr, 0, &retval, sizeof(retval)); + LOG(logDEBUG1) << "Got back: " << ToString(retval); } void Module::sendToDetector(int fnum) { @@ -182,46 +833,111 @@ void Module::sendToDetectorStop(int fnum, const void *args, size_t args_size, template void Module::sendToDetectorStop(int fnum, const Arg &args, Ret &retval) { + LOG(logDEBUG1) << "Sending to Stop: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", " << args << ", " << sizeof(args) << ", " + << typeid(Ret).name() << ", " << sizeof(Ret) << "]"; sendToDetectorStop(fnum, &args, sizeof(args), &retval, sizeof(retval)); + LOG(logDEBUG1) << "Got back: " << ToString(retval); } template void Module::sendToDetectorStop(int fnum, const Arg &args, Ret &retval) const { + LOG(logDEBUG1) << "Sending to Stop: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", " << args << ", " << sizeof(args) << ", " + << typeid(Ret).name() << ", " << sizeof(Ret) << "]"; sendToDetectorStop(fnum, &args, sizeof(args), &retval, sizeof(retval)); + LOG(logDEBUG1) << "Got back: " << ToString(retval); } template void Module::sendToDetectorStop(int fnum, const Arg &args, std::nullptr_t) { + LOG(logDEBUG1) << "Sending to Stop: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", " << typeid(Arg).name() << ", " << sizeof(Arg) + << ", nullptr, 0 ]"; sendToDetectorStop(fnum, &args, sizeof(args), nullptr, 0); } template void Module::sendToDetectorStop(int fnum, const Arg &args, std::nullptr_t) const { + LOG(logDEBUG1) << "Sending to Stop: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", " << typeid(Arg).name() << ", " << sizeof(Arg) + << ", nullptr, 0 ]"; sendToDetectorStop(fnum, &args, sizeof(args), nullptr, 0); } template void Module::sendToDetectorStop(int fnum, std::nullptr_t, Ret &retval) { + LOG(logDEBUG1) << "Sending to Stop: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", nullptr, 0, " << typeid(Ret).name() << ", " + << sizeof(Ret) << "]"; sendToDetectorStop(fnum, nullptr, 0, &retval, sizeof(retval)); + LOG(logDEBUG1) << "Got back: " << retval; } template void Module::sendToDetectorStop(int fnum, std::nullptr_t, Ret &retval) const { + LOG(logDEBUG1) << "Sending to Stop: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", nullptr, 0, " << typeid(Ret).name() << ", " + << sizeof(Ret) << "]"; sendToDetectorStop(fnum, nullptr, 0, &retval, sizeof(retval)); + LOG(logDEBUG1) << "Got back: " << retval; } void Module::sendToDetectorStop(int fnum) { - LOG(logDEBUG1) << "Sending to detector stop: [" + LOG(logDEBUG1) << "Sending to Stop: [" << getFunctionNameFromEnum(static_cast(fnum)) - << "]"; + << ", nullptr, 0, nullptr, 0]"; sendToDetectorStop(fnum, nullptr, 0, nullptr, 0); } void Module::sendToDetectorStop(int fnum) const { + LOG(logDEBUG1) << "Sending to Stop: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", nullptr, 0, nullptr, 0]"; sendToDetectorStop(fnum, nullptr, 0, nullptr, 0); } +template Ret Module::sendToDetectorStop(int fnum) { + LOG(logDEBUG1) << "Sending to Stop: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", nullptr, 0, " << typeid(Ret).name() << ", " + << sizeof(Ret) << "]"; + Ret retval{}; + sendToDetectorStop(fnum, nullptr, 0, &retval, sizeof(retval)); + LOG(logDEBUG1) << "Got back: " << retval; + return retval; +} + +template Ret Module::sendToDetectorStop(int fnum) const { + LOG(logDEBUG1) << "Sending to Stop: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", nullptr, 0, " << typeid(Ret).name() << ", " + << sizeof(Ret) << "]"; + Ret retval{}; + sendToDetectorStop(fnum, nullptr, 0, &retval, sizeof(retval)); + LOG(logDEBUG1) << "Got back: " << retval; + return retval; +} + +template +Ret Module::sendToDetectorStop(int fnum, const Arg &args) { + LOG(logDEBUG1) << "Sending to Stop: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", " << args << ", " << sizeof(args) << ", " + << typeid(Ret).name() << ", " << sizeof(Ret) << "]"; + Ret retval{}; + sendToDetectorStop(fnum, &args, sizeof(args), &retval, sizeof(retval)); + LOG(logDEBUG1) << "Got back: " << ToString(retval); + return retval; +} + void Module::sendToReceiver(int fnum, const void *args, size_t args_size, void *retval, size_t retval_size) { static_cast(*this).sendToReceiver(fnum, args, args_size, @@ -243,36 +959,64 @@ void Module::sendToReceiver(int fnum, const void *args, size_t args_size, template void Module::sendToReceiver(int fnum, const Arg &args, Ret &retval) { + LOG(logDEBUG1) << "Sending to Receiver: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", " << args << ", " << sizeof(args) << ", " + << typeid(Ret).name() << ", " << sizeof(Ret) << "]"; sendToReceiver(fnum, &args, sizeof(args), &retval, sizeof(retval)); + LOG(logDEBUG1) << "Got back: " << retval; } template void Module::sendToReceiver(int fnum, const Arg &args, Ret &retval) const { + LOG(logDEBUG1) << "Sending to Receiver: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", " << args << ", " << sizeof(args) << ", " + << typeid(Ret).name() << ", " << sizeof(Ret) << "]"; sendToReceiver(fnum, &args, sizeof(args), &retval, sizeof(retval)); + LOG(logDEBUG1) << "Got back: " << ToString(retval); } template void Module::sendToReceiver(int fnum, const Arg &args, std::nullptr_t) { + LOG(logDEBUG1) << "Sending to Receiver: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", " << typeid(Arg).name() << ", " << sizeof(Arg) + << ", nullptr, 0 ]"; sendToReceiver(fnum, &args, sizeof(args), nullptr, 0); } template void Module::sendToReceiver(int fnum, const Arg &args, std::nullptr_t) const { + LOG(logDEBUG1) << "Sending to Receiver: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", " << typeid(Arg).name() << ", " << sizeof(Arg) + << ", nullptr, 0 ]"; sendToReceiver(fnum, &args, sizeof(args), nullptr, 0); } template void Module::sendToReceiver(int fnum, std::nullptr_t, Ret &retval) { + LOG(logDEBUG1) << "Sending to Receiver: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", nullptr, 0, " << typeid(Ret).name() << ", " + << sizeof(Ret) << "]"; sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval)); + LOG(logDEBUG1) << "Got back: " << ToString(retval); } template void Module::sendToReceiver(int fnum, std::nullptr_t, Ret &retval) const { + LOG(logDEBUG1) << "Sending to Receiver: [" + << getFunctionNameFromEnum(static_cast(fnum)) + << ", nullptr, 0, " << typeid(Ret).name() << ", " + << sizeof(Ret) << "]"; sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval)); + LOG(logDEBUG1) << "Got back: " << ToString(retval); } template Ret Module::sendToReceiver(int fnum) { - LOG(logDEBUG1) << "Sending: [" + LOG(logDEBUG1) << "Sending to Receiver: [" << getFunctionNameFromEnum(static_cast(fnum)) << ", nullptr, 0, " << typeid(Ret).name() << ", " << sizeof(Ret) << "]"; @@ -283,7 +1027,7 @@ template Ret Module::sendToReceiver(int fnum) { } template Ret Module::sendToReceiver(int fnum) const { - LOG(logDEBUG1) << "Sending: [" + LOG(logDEBUG1) << "Sending to Receiver: [" << getFunctionNameFromEnum(static_cast(fnum)) << ", nullptr, 0, " << typeid(Ret).name() << ", " << sizeof(Ret) << "]"; @@ -295,7 +1039,7 @@ template Ret Module::sendToReceiver(int fnum) const { template Ret Module::sendToReceiver(int fnum, const Arg &args) { - LOG(logDEBUG1) << "Sending: [" + LOG(logDEBUG1) << "Sending to Receiver: [" << getFunctionNameFromEnum(static_cast(fnum)) << ", " << args << ", " << sizeof(args) << ", " << typeid(Ret).name() << ", " << sizeof(Ret) << "]"; @@ -307,7 +1051,7 @@ Ret Module::sendToReceiver(int fnum, const Arg &args) { template Ret Module::sendToReceiver(int fnum, const Arg &args) const { - LOG(logDEBUG1) << "Sending: [" + LOG(logDEBUG1) << "Sending to Receiver: [" << getFunctionNameFromEnum(static_cast(fnum)) << ", " << args << ", " << sizeof(args) << ", " << typeid(Ret).name() << ", " << sizeof(Ret) << "]"; @@ -317,44 +1061,30 @@ Ret Module::sendToReceiver(int fnum, const Arg &args) const { return retval; } -// void Module::sendToReceiver(int fnum) { -// sendToReceiver(fnum, nullptr, 0, nullptr, 0); -// } - -// void Module::sendToReceiver(int fnum) const { -// sendToReceiver(fnum, nullptr, 0, nullptr, 0); -// } - -void Module::freeSharedMemory() { - if (shm.IsExisting()) { - shm.RemoveSharedMemory(); +slsDetectorDefs::detectorType Module::getDetectorTypeFromShm(int det_id, + bool verify) { + if (!shm.IsExisting()) { + throw SharedMemoryError("Shared memory " + shm.GetName() + + "does not exist.\n Corrupted Multi Shared " + "memory. Please free shared memory."); } + + shm.OpenSharedMemory(); + if (verify && shm()->shmversion != SLS_SHMVERSION) { + std::ostringstream ss; + ss << "Single shared memory (" << det_id << "-" << moduleId + << ":)version mismatch (expected 0x" << std::hex << SLS_SHMVERSION + << " but got 0x" << shm()->shmversion << ")" << std::dec + << ". Clear Shared memory to continue."; + shm.UnmapSharedMemory(); + throw SharedMemoryError(ss.str()); + } + auto type = shm()->myDetectorType; + return type; } -void Module::setHostname(const std::string &hostname, - const bool initialChecks) { - sls::strcpy_safe(shm()->hostname, hostname.c_str()); - auto client = DetectorSocket(shm()->hostname, shm()->controlPort); - client.close(); - try { - checkDetectorVersionCompatibility(); - LOG(logINFO) << "Detector Version Compatibility - Success"; - } catch (const DetectorError &e) { - if (!initialChecks) { - LOG(logWARNING) << "Bypassing Initial Checks at your own risk!"; - } else { - throw; - } - } - if (shm()->myDetectorType == EIGER) { - setActivate(true); - } -} - -std::string Module::getHostname() const { return shm()->hostname; } - -void Module::initSharedMemory(detectorType type, int multi_id, bool verify) { - shm = SharedMemory(multi_id, detId); +void Module::initSharedMemory(detectorType type, int det_id, bool verify) { + shm = SharedMemory(det_id, moduleId); if (!shm.IsExisting()) { shm.CreateSharedMemory(); initializeDetectorStructure(type); @@ -362,7 +1092,7 @@ void Module::initSharedMemory(detectorType type, int multi_id, bool verify) { shm.OpenSharedMemory(); if (verify && shm()->shmversion != SLS_SHMVERSION) { std::ostringstream ss; - ss << "Single shared memory (" << multi_id << "-" << detId + ss << "Single shared memory (" << det_id << "-" << moduleId << ":) version mismatch (expected 0x" << std::hex << SLS_SHMVERSION << " but got 0x" << shm()->shmversion << ")" << std::dec << ". Clear Shared memory to continue."; @@ -384,7 +1114,7 @@ void Module::initializeDetectorStructure(detectorType type) { shm()->rxTCPPort = DEFAULT_PORTNO + 2; shm()->useReceiverFlag = false; shm()->zmqport = DEFAULT_ZMQ_CL_PORTNO + - (detId * ((shm()->myDetectorType == EIGER) ? 2 : 1)); + (moduleId * ((shm()->myDetectorType == EIGER) ? 2 : 1)); shm()->zmqip = IpAddr{}; shm()->numUDPInterfaces = 1; shm()->stoppedFlag = false; @@ -398,6 +1128,52 @@ void Module::initializeDetectorStructure(detectorType type) { shm()->nDacs = parameters.nDacs; } +void Module::checkDetectorVersionCompatibility() { + int fnum = F_CHECK_VERSION; + int64_t arg = 0; + + // get api version number for detector server + switch (shm()->myDetectorType) { + case EIGER: + arg = APIEIGER; + break; + case JUNGFRAU: + arg = APIJUNGFRAU; + break; + case GOTTHARD: + arg = APIGOTTHARD; + break; + case CHIPTESTBOARD: + arg = APICTB; + break; + case MOENCH: + arg = APIMOENCH; + break; + case MYTHEN3: + arg = APIMYTHEN3; + break; + case GOTTHARD2: + arg = APIGOTTHARD2; + break; + default: + throw NotImplementedError( + "Check version compatibility is not implemented for this detector"); + } + LOG(logDEBUG1) << "Checking version compatibility with detector with value " + << std::hex << arg << std::dec; + + sendToDetector(fnum, arg, nullptr); + sendToDetectorStop(fnum, arg, nullptr); +} + +void Module::checkReceiverVersionCompatibility() { + // TODO! Verify that this works as intended when version don't match + int64_t arg = APIRECEIVER; + LOG(logDEBUG1) << "Checking version compatibility with receiver with value " + << std::hex << arg << std::dec; + sendToReceiver(F_RECEIVER_CHECK_VERSION, arg, nullptr); +} + int Module::sendModule(sls_detector_module *myMod, sls::ClientSocket &client) { TLogLevel level = logDEBUG1; LOG(level) << "Sending Module"; @@ -474,67 +1250,6 @@ int Module::receiveModule(sls_detector_module *myMod, return ts; } -slsDetectorDefs::detectorType Module::getDetectorTypeFromShm(int multi_id, - bool verify) { - if (!shm.IsExisting()) { - throw SharedMemoryError("Shared memory " + shm.GetName() + - "does not exist.\n Corrupted Multi Shared " - "memory. Please free shared memory."); - } - - shm.OpenSharedMemory(); - if (verify && shm()->shmversion != SLS_SHMVERSION) { - std::ostringstream ss; - ss << "Single shared memory (" << multi_id << "-" << detId - << ":)version mismatch (expected 0x" << std::hex << SLS_SHMVERSION - << " but got 0x" << shm()->shmversion << ")" << std::dec - << ". Clear Shared memory to continue."; - shm.UnmapSharedMemory(); - throw SharedMemoryError(ss.str()); - } - auto type = shm()->myDetectorType; - return type; -} - -// static function -slsDetectorDefs::detectorType -Module::getTypeFromDetector(const std::string &hostname, int cport) { - int fnum = F_GET_DETECTOR_TYPE; - int ret = FAIL; - detectorType retval = GENERIC; - LOG(logDEBUG1) << "Getting detector type "; - sls::ClientSocket cs("Detector", hostname, cport); - cs.Send(reinterpret_cast(&fnum), sizeof(fnum)); - cs.Receive(reinterpret_cast(&ret), sizeof(ret)); - cs.Receive(reinterpret_cast(&retval), sizeof(retval)); - LOG(logDEBUG1) << "Detector type is " << retval; - return retval; -} - -slsDetectorDefs::detectorType Module::getDetectorType() const { - return shm()->myDetectorType; -} - -void Module::updateNumberOfChannels() { - if (shm()->myDetectorType == CHIPTESTBOARD || - shm()->myDetectorType == MOENCH) { - LOG(logDEBUG1) << "Updating number of channels"; - std::array retvals{}; - sendToDetector(F_GET_NUM_CHANNELS, nullptr, retvals); - LOG(logDEBUG1) << "Number of channels retval: [" << retvals[0] << ", " - << retvals[1] << ']'; - shm()->nChan.x = retvals[0]; - shm()->nChan.y = retvals[1]; - } -} - -slsDetectorDefs::xy Module::getNumberOfChannels() const { - slsDetectorDefs::xy coord{}; - coord.x = (shm()->nChan.x * shm()->nChip.x); - coord.y = (shm()->nChan.y * shm()->nChip.y); - return coord; -} - bool Module::getQuad() { return sendToDetector(F_GET_QUAD) != 0; } void Module::setQuad(const bool enable) { @@ -558,12 +1273,6 @@ void Module::setReadNLines(const int value) { int Module::getReadNLines() { return sendToDetector(F_GET_READ_N_LINES); } -void Module::updateNumberOfDetector(slsDetectorDefs::xy det) { - shm()->numberOfDetector = det; - int args[2] = {shm()->numberOfDetector.y, detId}; - sendToDetector(F_SET_POSITION, args, nullptr); -} - int Module::setControlPort(int port_number) { int retval = -1; LOG(logDEBUG1) << "Setting control port to " << port_number; @@ -594,24 +1303,6 @@ int Module::setStopPort(int port_number) { return shm()->stopPort; } -int Module::setReceiverPort(int port_number) { - LOG(logDEBUG1) << "Setting reciever port to " << port_number; - if (port_number >= 0 && port_number != shm()->rxTCPPort) { - if (shm()->useReceiverFlag) { - int retval = -1; - sendToReceiver(F_SET_RECEIVER_PORT, port_number, retval); - shm()->rxTCPPort = retval; - LOG(logDEBUG1) << "Receiver port: " << retval; - - } else { - shm()->rxTCPPort = port_number; - } - } - return shm()->rxTCPPort; -} - -int Module::getReceiverPort() const { return shm()->rxTCPPort; } - int Module::getControlPort() const { return shm()->controlPort; } int Module::getStopPort() const { return shm()->stopPort; } @@ -633,7 +1324,7 @@ void Module::execCommand(const std::string &cmd) { LOG(logDEBUG1) << "Sending command to detector " << arg; sendToDetector(F_EXEC_COMMAND, arg, retval); if (strlen(retval) != 0U) { - LOG(logINFO) << "Detector " << detId << " returned:\n" << retval; + LOG(logINFO) << "Detector " << moduleId << " returned:\n" << retval; } } @@ -705,28 +1396,12 @@ std::vector Module::getConfigFileCommands() { std::vector commands; for (const auto &cmd : base) { std::ostringstream os; - os << detId << ':' << cmd; + os << moduleId << ':' << cmd; commands.emplace_back(os.str()); } return commands; } -slsDetectorDefs::detectorSettings Module::getSettings() { - auto r = sendToDetector(F_SET_SETTINGS, -1); - return static_cast(r); -} - -void Module::setSettings(detectorSettings isettings) { - if (shm()->myDetectorType == EIGER) { - throw RuntimeError( - "Cannot set settings for Eiger. Use threshold energy."); - } - int arg = static_cast(isettings); - int retval = -1; - LOG(logDEBUG1) << "Setting settings to " << arg; - sendToDetector(F_SET_SETTINGS, arg, retval); -} - int Module::getThresholdEnergy() { // moench - get threshold energy from processor (due to different clients, // diff shm) @@ -859,63 +1534,6 @@ std::string Module::setSettingsDir(const std::string &dir) { return shm()->settingsDir; } -void Module::loadSettingsFile(const std::string &fname) { - std::string fn = fname; - std::ostringstream ostfn; - ostfn << fname; - - // find specific file if it has detid in file name (.snxxx) - if (shm()->myDetectorType == EIGER || shm()->myDetectorType == MYTHEN3) { - if (fname.find(".sn") == std::string::npos && - fname.find(".trim") == std::string::npos && - fname.find(".settings") == std::string::npos) { - ostfn << ".sn" << std::setfill('0') << std::setw(3) << std::dec - << getSerialNumber(); - } - } else { - throw RuntimeError("not implemented for this detector"); - } - fn = ostfn.str(); - auto myMod = readSettingsFile(fn); - setModule(myMod); -} - -slsDetectorDefs::runStatus Module::getRunStatus() const { - runStatus retval = ERROR; - LOG(logDEBUG1) << "Getting status"; - sendToDetectorStop(F_GET_RUN_STATUS, nullptr, retval); - LOG(logDEBUG1) << "Detector status: " << ToString(retval); - return retval; -} - -void Module::prepareAcquisition() { sendToDetector(F_PREPARE_ACQUISITION); } - -void Module::startAcquisition() { - shm()->stoppedFlag = false; - sendToDetector(F_START_ACQUISITION); -} - -void Module::stopAcquisition() { - // get status before stopping acquisition - runStatus s = ERROR, r = ERROR; - bool zmqstreaming = false; - if (shm()->useReceiverFlag && getReceiverStreaming()) { - zmqstreaming = true; - s = getRunStatus(); - r = getReceiverStatus(); - } - LOG(logDEBUG1) << "Stopping Acquisition"; - sendToDetectorStop(F_STOP_ACQUISITION); - shm()->stoppedFlag = true; - LOG(logDEBUG1) << "Stopping Acquisition successful"; - // if rxr streaming and acquisition finished, restream dummy stop packet - if (zmqstreaming && (s == IDLE) && (r == IDLE)) { - restreamStopFromReceiver(); - } -} - -void Module::sendSoftwareTrigger() { sendToDetectorStop(F_SOFTWARE_TRIGGER); } - void Module::startAndReadAll() { shm()->stoppedFlag = false; sendToDetector(F_START_AND_READ_ALL); @@ -925,41 +1543,6 @@ void Module::startReadOut() { sendToDetector(F_START_READOUT); } void Module::readAll() { sendToDetector(F_READ_ALL); } -void Module::setStartingFrameNumber(uint64_t value) { - LOG(logDEBUG1) << "Setting starting frame number to " << value; - sendToDetector(F_SET_STARTING_FRAME_NUMBER, value, nullptr); -} - -uint64_t Module::getStartingFrameNumber() { - return sendToDetector(F_GET_STARTING_FRAME_NUMBER); -} - -int64_t Module::getNumberOfFrames() { - return sendToDetector(F_GET_NUM_FRAMES); -} - -void Module::setNumberOfFrames(int64_t value) { - LOG(logDEBUG1) << "Setting number of frames to " << value; - sendToDetector(F_SET_NUM_FRAMES, value, nullptr); - if (shm()->useReceiverFlag) { - LOG(logDEBUG1) << "Sending number of frames to Receiver: " << value; - sendToReceiver(F_RECEIVER_SET_NUM_FRAMES, value, nullptr); - } -} - -int64_t Module::getNumberOfTriggers() { - return sendToDetector(F_GET_NUM_TRIGGERS); -} - -void Module::setNumberOfTriggers(int64_t value) { - LOG(logDEBUG1) << "Setting number of triggers to " << value; - sendToDetector(F_SET_NUM_TRIGGERS, value, nullptr); - if (shm()->useReceiverFlag) { - LOG(logDEBUG1) << "Sending number of triggers to Receiver: " << value; - sendToReceiver(F_SET_RECEIVER_NUM_TRIGGERS, value, nullptr); - } -} - int64_t Module::getNumberOfBursts() { return sendToDetector(F_GET_NUM_BURSTS); } @@ -1072,26 +1655,6 @@ std::array Module::getGateDelayForAllGates() { return sendToDetector>(F_GET_GATE_DELAY_ALL_GATES); } -int64_t Module::getPeriod() { return sendToDetector(F_GET_PERIOD); } - -void Module::setPeriod(int64_t value) { - LOG(logDEBUG1) << "Setting period to " << value << "ns"; - sendToDetector(F_SET_PERIOD, value, nullptr); - if (shm()->useReceiverFlag) { - LOG(logDEBUG1) << "Sending period to Receiver: " << value; - sendToReceiver(F_RECEIVER_SET_PERIOD, value, nullptr); - } -} - -int64_t Module::getDelayAfterTrigger() { - return sendToDetector(F_GET_DELAY_AFTER_TRIGGER); -} - -void Module::setDelayAfterTrigger(int64_t value) { - LOG(logDEBUG1) << "Setting delay after trigger to " << value << "ns"; - sendToDetector(F_SET_DELAY_AFTER_TRIGGER, value, nullptr); -} - int64_t Module::getBurstPeriod() { return sendToDetector(F_GET_BURST_PERIOD); } @@ -1143,27 +1706,6 @@ void Module::setStorageCellDelay(int64_t value) { sendToDetector(F_SET_STORAGE_CELL_DELAY, value, nullptr); } -int64_t Module::getNumberOfFramesLeft() const { - int64_t retval = -1; - sendToDetectorStop(F_GET_FRAMES_LEFT, nullptr, retval); - LOG(logDEBUG1) << "number of frames left :" << retval; - return retval; -} - -int64_t Module::getNumberOfTriggersLeft() const { - int64_t retval = -1; - sendToDetectorStop(F_GET_TRIGGERS_LEFT, nullptr, retval); - LOG(logDEBUG1) << "number of triggers left :" << retval; - return retval; -} - -int64_t Module::getDelayAfterTriggerLeft() const { - int64_t retval = -1; - sendToDetectorStop(F_GET_DELAY_AFTER_TRIGGER_LEFT, nullptr, retval); - LOG(logDEBUG1) << "delay after trigger left :" << retval << "ns"; - return retval; -} - int64_t Module::getExptimeLeft() const { int64_t retval = -1; sendToDetectorStop(F_GET_EXPTIME_LEFT, nullptr, retval); @@ -1171,13 +1713,6 @@ int64_t Module::getExptimeLeft() const { return retval; } -int64_t Module::getPeriodLeft() const { - int64_t retval = -1; - sendToDetectorStop(F_GET_PERIOD_LEFT, nullptr, retval); - LOG(logDEBUG1) << "period left :" << retval << "ns"; - return retval; -} - int64_t Module::getMeasuredPeriod() const { int64_t retval = -1; sendToDetectorStop(F_GET_MEASURED_PERIOD, nullptr, retval); @@ -1213,20 +1748,6 @@ int64_t Module::getMeasurementTime() const { return retval; } -slsDetectorDefs::timingMode Module::getTimingMode() { - return sendToDetector(F_SET_TIMING_MODE, -1); -} - -void Module::setTimingMode(timingMode value) { - timingMode retval = GET_TIMING_MODE; - LOG(logDEBUG1) << "Setting timing mode to " << value; - sendToDetector(F_SET_TIMING_MODE, static_cast(value), retval); - if (shm()->useReceiverFlag) { - LOG(logDEBUG1) << "Sending timing mode to Receiver: " << value; - sendToReceiver(F_SET_RECEIVER_TIMING_MODE, value, nullptr); - } -} - int Module::getDynamicRange() { return sendToDetector(F_SET_DYNAMIC_RANGE, -1); } @@ -1266,38 +1787,6 @@ void Module::setDynamicRange(int n) { } } -int Module::setDAC(int val, dacIndex index, int mV) { - int args[]{static_cast(index), mV, val}; - int retval = -1; - LOG(logDEBUG1) << "Setting DAC " << index << " to " << val - << (mV != 0 ? "mV" : "dac units"); - sendToDetector(F_SET_DAC, args, retval); - LOG(logDEBUG1) << "Dac index " << index << ": " << retval - << (mV != 0 ? "mV" : "dac units"); - return retval; -} - -int Module::getOnChipDAC(slsDetectorDefs::dacIndex index, int chipIndex) { - int args[]{static_cast(index), chipIndex}; - int retval = -1; - sendToDetector(F_GET_ON_CHIP_DAC, args, retval); - LOG(logDEBUG1) << "On chip DAC " << index << " (chip index:" << chipIndex - << "): " << retval; - return retval; -} - -void Module::setOnChipDAC(slsDetectorDefs::dacIndex index, int chipIndex, - int value) { - int args[]{static_cast(index), chipIndex, value}; - LOG(logDEBUG1) << "Setting On chip DAC " << index - << " (chip index:" << chipIndex << ") to " << value; - sendToDetector(F_SET_ON_CHIP_DAC, args, nullptr); -} - -int Module::getADC(dacIndex index) { - return sendToDetector(F_GET_ADC, static_cast(index)); -} - slsDetectorDefs::externalSignalFlag Module::getExternalSignalFlags(int signalIndex) { return sendToDetector( @@ -1402,290 +1891,6 @@ uint32_t Module::clearBit(uint32_t addr, int n) { } } -void Module::setReceiverHostname(const std::string &receiverIP) { - LOG(logDEBUG1) << "Setting up Receiver with " << receiverIP; - // recieverIP is none - if (receiverIP == "none") { - memset(shm()->rxHostname, 0, MAX_STR_LENGTH); - sls::strcpy_safe(shm()->rxHostname, "none"); - shm()->useReceiverFlag = false; - } - - // stop acquisition if running - if (getRunStatus() == RUNNING) { - LOG(logWARNING) << "Acquisition already running, Stopping it."; - stopAcquisition(); - } - - // start updating - std::string host = receiverIP; - auto res = sls::split(host, ':'); - if (res.size() > 1) { - host = res[0]; - shm()->rxTCPPort = std::stoi(res[1]); - } - sls::strcpy_safe(shm()->rxHostname, host.c_str()); - shm()->useReceiverFlag = true; - checkReceiverVersionCompatibility(); - - // populate parameters from detector - rxParameters retval; - sendToDetector(F_GET_RECEIVER_PARAMETERS, nullptr, retval); - - // populate from shared memory - retval.detType = shm()->myDetectorType; - retval.numberOfDetector.x = shm()->numberOfDetector.x; - retval.numberOfDetector.y = shm()->numberOfDetector.y; - retval.detId = detId; - memset(retval.hostname, 0, sizeof(retval.hostname)); - strcpy_safe(retval.hostname, shm()->hostname); - - LOG(logDEBUG1) << "detType:" << retval.detType << std::endl - << "numberOfDetector.x:" << retval.numberOfDetector.x - << std::endl - << "numberOfDetector.y:" << retval.numberOfDetector.y - << std::endl - << "detId:" << retval.detId << std::endl - << "hostname:" << retval.hostname << std::endl - << "udpInterfaces:" << retval.udpInterfaces << std::endl - << "udp_dstport:" << retval.udp_dstport << std::endl - << "udp_dstip:" << sls::IpAddr(retval.udp_dstip) << std::endl - << "udp_dstmac:" << sls::MacAddr(retval.udp_dstmac) - << std::endl - << "udp_dstport2:" << retval.udp_dstport2 << std::endl - << "udp_dstip2:" << sls::IpAddr(retval.udp_dstip2) - << std::endl - << "udp_dstmac2:" << sls::MacAddr(retval.udp_dstmac2) - << std::endl - << "frames:" << retval.frames << std::endl - << "triggers:" << retval.triggers << std::endl - << "bursts:" << retval.bursts << std::endl - << "analogSamples:" << retval.analogSamples << std::endl - << "digitalSamples:" << retval.digitalSamples << std::endl - << "expTimeNs:" << retval.expTimeNs << std::endl - << "periodNs:" << retval.periodNs << std::endl - << "subExpTimeNs:" << retval.subExpTimeNs << std::endl - << "subDeadTimeNs:" << retval.subDeadTimeNs << std::endl - << "activate:" << retval.activate << std::endl - << "quad:" << retval.quad << std::endl - << "dynamicRange:" << retval.dynamicRange << std::endl - << "timMode:" << retval.timMode << std::endl - << "tenGiga:" << retval.tenGiga << std::endl - << "roMode:" << retval.roMode << std::endl - << "adcMask:" << retval.adcMask << std::endl - << "adc10gMask:" << retval.adc10gMask << std::endl - << "roi.xmin:" << retval.roi.xmin << std::endl - << "roi.xmax:" << retval.roi.xmax << std::endl - << "countermask:" << retval.countermask << std::endl - << "burstType:" << retval.burstType << std::endl - << "exptime1:" << retval.expTime1Ns << std::endl - << "exptime2:" << retval.expTime2Ns << std::endl - << "exptime3:" << retval.expTime3Ns << std::endl - << "gateDelay1:" << retval.gateDelay1Ns << std::endl - << "gateDelay2:" << retval.gateDelay2Ns << std::endl - << "gateDelay3:" << retval.gateDelay3Ns << std::endl - << "gates:" << retval.gates << std::endl; - - sls::MacAddr retvals[2]; - sendToReceiver(F_SETUP_RECEIVER, retval, retvals); - // update detectors with dest mac - if (retval.udp_dstmac == 0 && retvals[0] != 0) { - LOG(logINFO) << "Setting destination udp mac of " - "detector " - << detId << " to " << retvals[0]; - sendToDetector(F_SET_DEST_UDP_MAC, retvals[0], nullptr); - } - if (retval.udp_dstmac2 == 0 && retvals[1] != 0) { - LOG(logINFO) << "Setting destination udp mac2 of " - "detector " - << detId << " to " << retvals[1]; - sendToDetector(F_SET_DEST_UDP_MAC2, retvals[1], nullptr); - } - - // update numinterfaces if different - shm()->numUDPInterfaces = retval.udpInterfaces; - - if (shm()->myDetectorType == MOENCH) { - setAdditionalJsonParameter("adcmask_1g", - std::to_string(retval.adcMask)); - setAdditionalJsonParameter("adcmask_10g", - std::to_string(retval.adc10gMask)); - } - - // to use rx_hostname if empty and also update client zmqip - updateReceiverStreamingIP(); -} - -std::string Module::getReceiverHostname() const { - return std::string(shm()->rxHostname); -} - -void Module::setSourceUDPMAC(const sls::MacAddr mac) { - LOG(logDEBUG1) << "Setting source udp mac to " << mac; - if (mac == 0) { - throw RuntimeError("Invalid source udp mac address"); - } - sendToDetector(F_SET_SOURCE_UDP_MAC, mac, nullptr); -} - -sls::MacAddr Module::getSourceUDPMAC() { - return sendToDetector(F_GET_SOURCE_UDP_MAC); -} - -void Module::setSourceUDPMAC2(const sls::MacAddr mac) { - LOG(logDEBUG1) << "Setting source udp mac2 to " << mac; - if (mac == 0) { - throw RuntimeError("Invalid source udp mac address2"); - } - sendToDetector(F_SET_SOURCE_UDP_MAC2, mac, nullptr); -} - -sls::MacAddr Module::getSourceUDPMAC2() { - return sendToDetector(F_GET_SOURCE_UDP_MAC2); -} - -void Module::setSourceUDPIP(const IpAddr ip) { - LOG(logDEBUG1) << "Setting source udp ip to " << ip; - if (ip == 0) { - throw RuntimeError("Invalid source udp ip address"); - } - sendToDetector(F_SET_SOURCE_UDP_IP, ip, nullptr); -} - -sls::IpAddr Module::getSourceUDPIP() { - return sendToDetector(F_GET_SOURCE_UDP_IP); -} - -void Module::setSourceUDPIP2(const IpAddr ip) { - LOG(logDEBUG1) << "Setting source udp ip2 to " << ip; - if (ip == 0) { - throw RuntimeError("Invalid source udp ip address2"); - } - sendToDetector(F_SET_SOURCE_UDP_IP2, ip, nullptr); -} - -sls::IpAddr Module::getSourceUDPIP2() { - return sendToDetector(F_GET_SOURCE_UDP_IP2); -} - -void Module::setDestinationUDPIP(const IpAddr ip) { - LOG(logDEBUG1) << "Setting destination udp ip to " << ip; - if (ip == 0) { - throw RuntimeError("Invalid destination udp ip address"); - } - sendToDetector(F_SET_DEST_UDP_IP, ip, nullptr); - if (shm()->useReceiverFlag) { - sls::MacAddr retval(0LU); - sendToReceiver(F_SET_RECEIVER_UDP_IP, ip, retval); - LOG(logINFO) << "Setting destination udp mac of detector " << detId - << " to " << retval; - sendToDetector(F_SET_DEST_UDP_MAC, retval, nullptr); - } -} - -sls::IpAddr Module::getDestinationUDPIP() { - return sendToDetector(F_GET_DEST_UDP_IP); -} - -void Module::setDestinationUDPIP2(const IpAddr ip) { - LOG(logDEBUG1) << "Setting destination udp ip2 to " << ip; - if (ip == 0) { - throw RuntimeError("Invalid destination udp ip address2"); - } - - sendToDetector(F_SET_DEST_UDP_IP2, ip, nullptr); - if (shm()->useReceiverFlag) { - sls::MacAddr retval(0LU); - sendToReceiver(F_SET_RECEIVER_UDP_IP2, ip, retval); - LOG(logINFO) << "Setting destination udp mac2 of detector " << detId - << " to " << retval; - sendToDetector(F_SET_DEST_UDP_MAC2, retval, nullptr); - } -} - -sls::IpAddr Module::getDestinationUDPIP2() { - return sendToDetector(F_GET_DEST_UDP_IP2); -} - -void Module::setDestinationUDPMAC(const MacAddr mac) { - LOG(logDEBUG1) << "Setting destination udp mac to " << mac; - if (mac == 0) { - throw RuntimeError("Invalid destination udp mac address"); - } - sendToDetector(F_SET_DEST_UDP_MAC, mac, nullptr); -} - -sls::MacAddr Module::getDestinationUDPMAC() { - return sendToDetector(F_GET_DEST_UDP_MAC); -} - -void Module::setDestinationUDPMAC2(const MacAddr mac) { - LOG(logDEBUG1) << "Setting destination udp mac2 to " << mac; - if (mac == 0) { - throw RuntimeError("Invalid desinaion udp mac address2"); - } - sendToDetector(F_SET_DEST_UDP_MAC2, mac, nullptr); -} - -sls::MacAddr Module::getDestinationUDPMAC2() { - return sendToDetector(F_GET_DEST_UDP_MAC2); -} - -void Module::setDestinationUDPPort(const int port) { - LOG(logDEBUG1) << "Setting destination udp port to " << port; - sendToDetector(F_SET_DEST_UDP_PORT, port, nullptr); - if (shm()->useReceiverFlag) { - sendToReceiver(F_SET_RECEIVER_UDP_PORT, port, nullptr); - } -} - -int Module::getDestinationUDPPort() { - return sendToDetector(F_GET_DEST_UDP_PORT); -} - -void Module::setDestinationUDPPort2(const int port) { - LOG(logDEBUG1) << "Setting destination udp port2 to " << port; - sendToDetector(F_SET_DEST_UDP_PORT2, port, nullptr); - if (shm()->useReceiverFlag) { - sendToReceiver(F_SET_RECEIVER_UDP_PORT2, port, nullptr); - } -} - -int Module::getDestinationUDPPort2() { - return sendToDetector(F_GET_DEST_UDP_PORT2); -} - -void Module::setNumberofUDPInterfaces(int n) { - LOG(logDEBUG1) << "Setting number of udp interfaces to " << n; - sendToDetector(F_SET_NUM_INTERFACES, n, nullptr); - shm()->numUDPInterfaces = n; - if (shm()->useReceiverFlag) { - sendToReceiver(F_SET_RECEIVER_NUM_INTERFACES, n, nullptr); - } -} - -int Module::getNumberofUDPInterfacesFromShm() { - return shm()->numUDPInterfaces; -} - -int Module::getNumberofUDPInterfaces() { - int retval = -1; - LOG(logDEBUG1) << "Getting number of udp interfaces"; - sendToDetector(F_GET_NUM_INTERFACES, nullptr, retval); - LOG(logDEBUG1) << "Number of udp interfaces: " << retval; - shm()->numUDPInterfaces = retval; - return shm()->numUDPInterfaces; -} - -void Module::selectUDPInterface(int n) { - LOG(logDEBUG1) << "Setting selected udp interface to " << n; - sendToDetector(F_SET_INTERFACE_SEL, n, nullptr); -} - -int Module::getSelectedUDPInterface() { - return sendToDetector(F_GET_INTERFACE_SEL); -} - void Module::setClientStreamingPort(int port) { shm()->zmqport = port; } int Module::getClientStreamingPort() { return shm()->zmqport; } @@ -1731,49 +1936,12 @@ void Module::updateReceiverStreamingIP() { if (ip == 0) { ip = HostnameToIp(shm()->rxHostname); } - LOG(logINFO) << "Setting default receiver " << detId + LOG(logINFO) << "Setting default receiver " << moduleId << " streaming zmq ip to " << ip; } setReceiverStreamingIP(ip); } -bool Module::getTenGigaFlowControl() { - return sendToDetector(F_GET_TEN_GIGA_FLOW_CONTROL); -} - -void Module::setTenGigaFlowControl(bool enable) { - int arg = static_cast(enable); - LOG(logDEBUG1) << "Setting ten giga flow control to " << arg; - sendToDetector(F_SET_TEN_GIGA_FLOW_CONTROL, arg, nullptr); -} - -int Module::getTransmissionDelayFrame() { - return sendToDetector(F_GET_TRANSMISSION_DELAY_FRAME); -} - -void Module::setTransmissionDelayFrame(int value) { - LOG(logDEBUG1) << "Setting transmission delay frame to " << value; - sendToDetector(F_SET_TRANSMISSION_DELAY_FRAME, value, nullptr); -} - -int Module::getTransmissionDelayLeft() { - return sendToDetector(F_GET_TRANSMISSION_DELAY_LEFT); -} - -void Module::setTransmissionDelayLeft(int value) { - LOG(logDEBUG1) << "Setting transmission delay left to " << value; - sendToDetector(F_SET_TRANSMISSION_DELAY_LEFT, value, nullptr); -} - -int Module::getTransmissionDelayRight() { - return sendToDetector(F_GET_TRANSMISSION_DELAY_RIGHT); -} - -void Module::setTransmissionDelayRight(int value) { - LOG(logDEBUG1) << "Setting transmission delay right to " << value; - sendToDetector(F_SET_TRANSMISSION_DELAY_RIGHT, value, nullptr); -} - void Module::setAdditionalJsonHeader( const std::map &jsonHeader) { if (!shm()->useReceiverFlag) { @@ -1812,7 +1980,7 @@ void Module::setAdditionalJsonHeader( if (ret == FAIL) { char mess[MAX_STR_LENGTH]{}; client.Receive(mess, MAX_STR_LENGTH); - throw RuntimeError("Receiver " + std::to_string(detId) + + throw RuntimeError("Receiver " + std::to_string(moduleId) + " returned error: " + std::string(mess)); } } @@ -1831,7 +1999,7 @@ std::map Module::getAdditionalJsonHeader() { if (ret == FAIL) { char mess[MAX_STR_LENGTH]{}; client.Receive(mess, MAX_STR_LENGTH); - throw RuntimeError("Receiver " + std::to_string(detId) + + throw RuntimeError("Receiver " + std::to_string(moduleId) + " returned error: " + std::string(mess)); } else { client.Receive(&size, sizeof(size)); @@ -1895,15 +2063,6 @@ void Module::executeBusTest() { sendToDetector(F_SET_BUS_TEST); } -int Module::getImageTestMode() { - return sendToDetector(F_GET_IMAGE_TEST_MODE); -} - -void Module::setImageTestMode(const int value) { - LOG(logDEBUG1) << "Sending image test mode " << value; - sendToDetector(F_SET_IMAGE_TEST_MODE, value, nullptr); -} - std::array Module::getInjectChannel() { std::array retvals{}; sendToDetector(F_GET_INJECT_CHANNEL, nullptr, retvals); @@ -1930,7 +2089,7 @@ std::vector Module::getVetoPhoton(const int chipIndex) { if (ret == FAIL) { char mess[MAX_STR_LENGTH]{}; client.Receive(mess, MAX_STR_LENGTH); - throw RuntimeError("Detector " + std::to_string(detId) + + throw RuntimeError("Detector " + std::to_string(moduleId) + " returned error: " + std::string(mess)); } else { int nch = -1; @@ -2043,7 +2202,7 @@ void Module::setVetoPhoton(const int chipIndex, const int numPhotons, if (ret == FAIL) { char mess[MAX_STR_LENGTH]{}; client.Receive(mess, MAX_STR_LENGTH); - throw RuntimeError("Detector " + std::to_string(detId) + + throw RuntimeError("Detector " + std::to_string(moduleId) + " returned error: " + std::string(mess)); } } @@ -2276,14 +2435,6 @@ void Module::setFlippedDataX(bool value) { sendToReceiver(F_SET_FLIPPED_DATA_RECEIVER, static_cast(value)); } -int Module::getAllTrimbits() { - return sendToDetector(F_SET_ALL_TRIMBITS, -1); -} - -void Module::setAllTrimbits(int val) { - sendToDetector(F_SET_ALL_TRIMBITS, val); -} - int Module::setTrimEn(const std::vector &energies) { if (shm()->myDetectorType != EIGER) { throw RuntimeError("setTrimEn not implemented for this detector."); @@ -2379,7 +2530,7 @@ void Module::programFPGAviaBlackfin(std::vector buffer) { int ret = FAIL; char mess[MAX_STR_LENGTH] = {0}; LOG(logINFO) << "Sending programming binary (from pof) to detector " - << detId << " (" << shm()->hostname << ")"; + << moduleId << " (" << shm()->hostname << ")"; auto client = DetectorSocket(shm()->hostname, shm()->controlPort); client.Send(&fnum, sizeof(fnum)); @@ -2389,13 +2540,13 @@ void Module::programFPGAviaBlackfin(std::vector buffer) { if (ret == FAIL) { client.Receive(mess, sizeof(mess)); std::ostringstream os; - os << "Detector " << detId << " (" << shm()->hostname << ")" + os << "Detector " << moduleId << " (" << shm()->hostname << ")" << " returned error: " << mess; throw RuntimeError(os.str()); } // erasing flash - LOG(logINFO) << "Erasing Flash for detector " << detId << " (" + LOG(logINFO) << "Erasing Flash for detector " << moduleId << " (" << shm()->hostname << ")"; printf("%d%%\r", 0); std::cout << std::flush; @@ -2413,7 +2564,7 @@ void Module::programFPGAviaBlackfin(std::vector buffer) { std::cout << std::flush; } printf("\n"); - LOG(logINFO) << "Writing to Flash to detector " << detId << " (" + LOG(logINFO) << "Writing to Flash to detector " << moduleId << " (" << shm()->hostname << ")"; printf("%d%%\r", 0); std::cout << std::flush; @@ -2436,7 +2587,7 @@ void Module::programFPGAviaBlackfin(std::vector buffer) { printf("\n"); client.Receive(mess, sizeof(mess)); std::ostringstream os; - os << "Detector " << detId << " (" << shm()->hostname << ")" + os << "Detector " << moduleId << " (" << shm()->hostname << ")" << " returned error: " << mess; throw RuntimeError(os.str()); } @@ -2461,7 +2612,7 @@ void Module::programFPGAviaNios(std::vector buffer) { int ret = FAIL; char mess[MAX_STR_LENGTH] = {0}; LOG(logINFO) << "Sending programming binary (from rbf) to detector " - << detId << " (" << shm()->hostname << ")"; + << moduleId << " (" << shm()->hostname << ")"; auto client = DetectorSocket(shm()->hostname, shm()->controlPort); client.Send(&fnum, sizeof(fnum)); @@ -2471,7 +2622,7 @@ void Module::programFPGAviaNios(std::vector buffer) { if (ret == FAIL) { client.Receive(mess, sizeof(mess)); std::ostringstream os; - os << "Detector " << detId << " (" << shm()->hostname << ")" + os << "Detector " << moduleId << " (" << shm()->hostname << ")" << " returned error: " << mess; throw RuntimeError(os.str()); } @@ -2481,7 +2632,7 @@ void Module::programFPGAviaNios(std::vector buffer) { if (ret == FAIL) { client.Receive(mess, sizeof(mess)); std::ostringstream os; - os << "Detector " << detId << " (" << shm()->hostname << ")" + os << "Detector " << moduleId << " (" << shm()->hostname << ")" << " returned error: " << mess; throw RuntimeError(os.str()); } @@ -2507,10 +2658,6 @@ void Module::rebootController() { LOG(logINFO) << "Controller rebooted successfully!"; } -int Module::powerChip(int ival) { - return sendToDetector(F_POWER_CHIP, ival); -} - int Module::setAutoComparatorDisableMode(int ival) { return sendToDetector(F_AUTO_COMP_DISABLE, ival); } @@ -2531,7 +2678,7 @@ void Module::setModule(sls_detector_module &module, int tb) { if (ret == FAIL) { char mess[MAX_STR_LENGTH] = {0}; client.Receive(mess, sizeof(mess)); - throw RuntimeError("Detector " + std::to_string(detId) + + throw RuntimeError("Detector " + std::to_string(moduleId) + " returned error: " + mess); } } @@ -2565,36 +2712,6 @@ void Module::updateRateCorrection() { sendToDetector(F_UPDATE_RATE_CORRECTION); } -std::string Module::printReceiverConfiguration() { - std::ostringstream os; - os << "\n\nDetector " << detId << "\nReceiver Hostname:\t" - << getReceiverHostname(); - - if (shm()->myDetectorType == JUNGFRAU) { - os << "\nNumber of Interfaces:\t" << getNumberofUDPInterfaces() - << "\nSelected Interface:\t" << getSelectedUDPInterface(); - } - - os << "\nDetector UDP IP:\t" << getSourceUDPIP() << "\nDetector UDP MAC:\t" - << getSourceUDPMAC() << "\nReceiver UDP IP:\t" << getDestinationUDPIP() - << "\nReceiver UDP MAC:\t" << getDestinationUDPMAC(); - - if (shm()->myDetectorType == JUNGFRAU) { - os << "\nDetector UDP IP2:\t" << getSourceUDPIP2() - << "\nDetector UDP MAC2:\t" << getSourceUDPMAC2() - << "\nReceiver UDP IP2:\t" << getDestinationUDPIP2() - << "\nReceiver UDP MAC2:\t" << getDestinationUDPMAC2(); - } - os << "\nReceiver UDP Port:\t" << getDestinationUDPPort(); - if (shm()->myDetectorType == JUNGFRAU || shm()->myDetectorType == EIGER) { - os << "\nReceiver UDP Port2:\t" << getDestinationUDPPort2(); - } - os << "\n"; - return os.str(); -} - -bool Module::getUseReceiverFlag() const { return shm()->useReceiverFlag; } - int Module::lockReceiver(int lock) { return sendToReceiver(F_LOCK_RECEIVER, lock); } @@ -2689,55 +2806,6 @@ void Module::setPartialFramesPadding(bool padding) { sendToReceiver(F_SET_RECEIVER_PADDING, static_cast(padding), nullptr); } -void Module::startReceiver() { - LOG(logDEBUG1) << "Starting Receiver"; - shm()->stoppedFlag = false; - sendToReceiver(F_START_RECEIVER, nullptr, nullptr); -} - -void Module::stopReceiver() { - LOG(logDEBUG1) << "Stopping Receiver"; - int arg = static_cast(shm()->stoppedFlag); - sendToReceiver(F_STOP_RECEIVER, arg, nullptr); -} - -slsDetectorDefs::runStatus Module::getReceiverStatus() const { - return sendToReceiver(F_GET_RECEIVER_STATUS); -} - -int64_t Module::getFramesCaughtByReceiver() const { - return sendToReceiver(F_GET_RECEIVER_FRAMES_CAUGHT); -} - -std::vector Module::getNumMissingPackets() const { - // TODO!(Erik) Refactor - LOG(logDEBUG1) << "Getting num missing packets"; - if (shm()->useReceiverFlag) { - int fnum = F_GET_NUM_MISSING_PACKETS; - int ret = FAIL; - auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); - client.Send(&fnum, sizeof(fnum)); - client.Receive(&ret, sizeof(ret)); - if (ret == FAIL) { - char mess[MAX_STR_LENGTH]{}; - client.Receive(mess, MAX_STR_LENGTH); - throw RuntimeError("Receiver " + std::to_string(detId) + - " returned error: " + std::string(mess)); - } else { - int nports = -1; - client.Receive(&nports, sizeof(nports)); - uint64_t mp[nports]; - memset(mp, 0, sizeof(mp)); - client.Receive(mp, sizeof(mp)); - std::vector retval(mp, mp + nports); - LOG(logDEBUG1) << "Missing packets of Receiver" << detId << ": " - << sls::ToString(retval); - return retval; - } - } - throw RuntimeError("No receiver to get missing packets."); -} - uint64_t Module::getReceiverCurrentFrameIndex() const { return sendToReceiver(F_GET_RECEIVER_FRAME_INDEX); } @@ -2795,44 +2863,6 @@ void Module::setReceiverStreaming(bool enable) { sendToReceiver(F_SET_RECEIVER_STREAMING, static_cast(enable), nullptr); } -bool Module::enableTenGigabitEthernet(int value) { - int retval = -1; - LOG(logDEBUG1) << "Enabling / Disabling 10Gbe: " << value; - sendToDetector(F_ENABLE_TEN_GIGA, value, retval); - if (value != -1) { - int stopRetval = -1; - sendToDetectorStop(F_ENABLE_TEN_GIGA, value, stopRetval); - } - LOG(logDEBUG1) << "10Gbe: " << retval; - value = retval; - if (shm()->useReceiverFlag && value != -1) { - int retval = -1; - LOG(logDEBUG1) << "Sending 10Gbe enable to receiver: " << value; - sendToReceiver(F_ENABLE_RECEIVER_TEN_GIGA, value, retval); - LOG(logDEBUG1) << "Receiver 10Gbe enable: " << retval; - } - return static_cast(retval); -} - -int Module::setReceiverFifoDepth(int n_frames) { - int retval = -1; - LOG(logDEBUG1) << "Sending Receiver Fifo Depth: " << n_frames; - if (shm()->useReceiverFlag) { - sendToReceiver(F_SET_RECEIVER_FIFO_DEPTH, n_frames, retval); - LOG(logDEBUG1) << "Receiver Fifo Depth: " << retval; - } - return retval; -} - -bool Module::getReceiverSilentMode() { - return sendToReceiver(F_GET_RECEIVER_SILENT_MODE); -} - -void Module::setReceiverSilentMode(bool enable) { - sendToReceiver(F_SET_RECEIVER_SILENT_MODE, static_cast(enable), - nullptr); -} - void Module::restreamStopFromReceiver() { LOG(logDEBUG1) << "Restream stop dummy from Receiver via zmq"; if (shm()->useReceiverFlag) { @@ -2941,48 +2971,6 @@ void Module::setDigitalIODelay(uint64_t pinMask, int delay) { LOG(logDEBUG1) << "Digital IO Delay successful"; } -int Module::getClockFrequency(int clkIndex) { - return sendToDetector(F_GET_CLOCK_FREQUENCY, clkIndex); -} - -void Module::setClockFrequency(int clkIndex, int value) { - int args[]{clkIndex, value}; - LOG(logDEBUG1) << "Setting Clock " << clkIndex << " frequency to " << value; - sendToDetector(F_SET_CLOCK_FREQUENCY, args, nullptr); -} - -int Module::getClockPhase(int clkIndex, bool inDegrees) { - int args[]{clkIndex, static_cast(inDegrees)}; - int retval = -1; - LOG(logDEBUG1) << "Getting Clock " << clkIndex << " phase " - << (inDegrees ? "in degrees" : ""); - sendToDetector(F_GET_CLOCK_PHASE, args, retval); - LOG(logDEBUG1) << "Clock " << clkIndex << " frequency: " << retval - << (inDegrees ? "degrees" : ""); - return retval; -} - -void Module::setClockPhase(int clkIndex, int value, bool inDegrees) { - int args[]{clkIndex, value, static_cast(inDegrees)}; - LOG(logDEBUG1) << "Setting Clock " << clkIndex << " phase to " << value - << (inDegrees ? "degrees" : ""); - sendToDetector(F_SET_CLOCK_PHASE, args, nullptr); -} - -int Module::getMaxClockPhaseShift(int clkIndex) { - return sendToDetector(F_GET_MAX_CLOCK_PHASE_SHIFT, clkIndex); -} - -int Module::getClockDivider(int clkIndex) { - return sendToDetector(F_GET_CLOCK_DIVIDER, clkIndex); -} - -void Module::setClockDivider(int clkIndex, int value) { - int args[]{clkIndex, value}; - LOG(logDEBUG1) << "Setting Clock " << clkIndex << " divider to " << value; - sendToDetector(F_SET_CLOCK_DIVIDER, args, nullptr); -} - int Module::getPipeline(int clkIndex) { return sendToDetector(F_GET_PIPELINE, clkIndex); } diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index 2df993f46..c95527704 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -32,151 +32,194 @@ struct sharedSlsDetector { /** END OF FIXED PATTERN -----------------------------------------------*/ - /** Number of detectors in multi list in x dir and y dir */ slsDetectorDefs::xy numberOfDetector; - - /** is the port used for control functions */ int controlPort; - - /** is the port used to stop the acquisition */ int stopPort; - - /** path of the trimbits/settings files */ char settingsDir[MAX_STR_LENGTH]; - /** list of the energies at which the detector has been trimmed */ sls::StaticVector trimEnergies; - - /** number of channels per chip in one direction */ + /** number of channels per chip */ slsDetectorDefs::xy nChan; - - /** number of chips per module in one direction */ slsDetectorDefs::xy nChip; - - /** number of dacs per module*/ int nDacs; - - /** ip address/hostname of the receiver for client control via TCP */ char rxHostname[MAX_STR_LENGTH]; - - /** is the TCP port used to communicate between client and the receiver */ int rxTCPPort; - - /** is set if the receiver hostname given and is connected, - * unset if socket connection is not possible */ + /** if rxHostname and rxTCPPort can be connected to */ bool useReceiverFlag; - - /** tcp port from gui/different process to receiver (only data) */ + /** Listening tcp port from gui (only data) */ int zmqport; - - /** zmq tcp src ip address in client (only data) **/ + /** Listening tcp ip address from gui (only data) **/ sls::IpAddr zmqip; - - /** num udp interfaces */ int numUDPInterfaces; - - /** stopped flag to inform rxr */ + /** to inform rxr when stopping rxr */ bool stoppedFlag; }; class Module : public virtual slsDetectorDefs { public: - /** - * Constructor called when creating new shared memory - * @param type detector type - * @param multi_id multi detector shared memory id - * @param id sls detector id (position in detectors list) - * @param verify true to verify if shared memory version matches existing - * one - */ - explicit Module(detectorType type, int multi_id = 0, int det_id = 0, + /************************************************** + * * + * Configuration * + * * + * ************************************************/ + + /** creating new shared memory + @param verify if shared memory version matches existing one */ + explicit Module(detectorType type, int det_id = 0, int module_id = 0, bool verify = true); - /** - * Constructor called when opening existing shared memory - * @param multi_id multi detector shared memory id - * @param id sls detector id (position in detectors list) - * @param verify true to verify if shared memory version matches existing - * one - */ - explicit Module(int multi_id = 0, int det_id = 0, bool verify = true); + /** opening existing shared memory + @param verify if shared memory version matches existing one */ + explicit Module(int det_id = 0, int module_id = 0, bool verify = true); - /** - * Destructor - */ virtual ~Module(); - /** - * Returns false if it cannot get fixed pattern from an old version of shm - * (hostname, type), else true - */ - bool isFixedPatternSharedMemoryCompatible(); - - /** - * Check version compatibility with receiver software - */ - void checkReceiverVersionCompatibility(); - - /** - * Check version compatibility with detector software - */ - void checkDetectorVersionCompatibility(); - - int64_t getFirmwareVersion(); - - int64_t getDetectorServerVersion(); - - int64_t getSerialNumber(); - - /** - * Get Receiver Software version - */ - int64_t getReceiverSoftwareVersion() const; - - /** - * Free shared memory and delete shared memory structure - * occupied by the sharedSlsDetector structure - * Is only safe to call if one deletes the Module object afterward - * and frees multi shared memory/updates - * thisMultiDetector->numberOfDetectors - */ + /** Frees shared memory and deletes shared memory structure + Safe to call only if detector shm also deleted or its numberOfDetectors is + updated */ void freeSharedMemory(); - - /** - * Sets the hostname, if online flag is set connects to update the detector - * @param name hostname - * @param initialChecks enable or disable initial compatibility checks - * and other server start up checks. Enabled by default. Disable only - * for advanced users! - */ - void setHostname(const std::string &hostname, const bool initialChecks); - - /** - * Gets the hostname of detector - * @returns hostname - */ + bool isFixedPatternSharedMemoryCompatible(); std::string getHostname() const; - /** - * Get detector type by connecting to the detector - * @returns detector tpe or GENERIC if failed - */ + /** @param initialChecks enable or disable initial compatibility checks and + other server start up checks. Enabled by default. Disable only for advanced + users! */ + void setHostname(const std::string &hostname, const bool initialChecks); + + int64_t getFirmwareVersion(); + int64_t getDetectorServerVersion(); + int64_t getSerialNumber(); + int64_t getReceiverSoftwareVersion() const; static detectorType getTypeFromDetector(const std::string &hostname, int cport = DEFAULT_PORTNO); - /** - * Get Detector type from shared memory variable - * @returns detector type from shared memory variable - */ + /** Get Detector type from shared memory */ detectorType getDetectorType() const; - - /** - * Update total number of channels (chiptestboard or moench) - * from the detector server - */ void updateNumberOfChannels(); - slsDetectorDefs::xy getNumberOfChannels() const; + void updateNumberOfDetector(slsDetectorDefs::xy det); + detectorSettings getSettings(); + void setSettings(detectorSettings isettings); + void loadSettingsFile(const std::string &fname); + int getAllTrimbits(); + void setAllTrimbits(int val); + + /************************************************** + * * + * Acquisition Parameters * + * * + * ************************************************/ + int64_t getNumberOfFrames(); + void setNumberOfFrames(int64_t value); + int64_t getNumberOfTriggers(); + void setNumberOfTriggers(int64_t value); + /** [Mythen3] gatIndex: 0-2, [Others]: -1 always */ + int64_t getExptime(int gateIndex); + /** [Mythen3] gatIndex: -1 for all, 0-2, [Others]: -1 always */ + void setExptime(int gateIndex, int64_t value); + int64_t getPeriod(); + void setPeriod(int64_t value); + int64_t getDelayAfterTrigger(); + void setDelayAfterTrigger(int64_t value); + int64_t getNumberOfFramesLeft() const; + int64_t getNumberOfTriggersLeft() const; + int64_t getDelayAfterTriggerLeft() const; + int64_t getPeriodLeft() const; + timingMode getTimingMode(); + void setTimingMode(timingMode value); + int getClockDivider(int clkIndex); + void setClockDivider(int clkIndex, int value); + int getClockPhase(int clkIndex, bool inDegrees); + void setClockPhase(int clkIndex, int value, bool inDegrees); + int getMaxClockPhaseShift(int clkIndex); + int getClockFrequency(int clkIndex); + void setClockFrequency(int clkIndex, int value); + int getDAC(dacIndex index, bool mV); + void setDAC(int val, dacIndex index, bool mV); + bool getPowerChip(); + void setPowerChip(bool on); + int getImageTestMode(); + void setImageTestMode(const int value); + /* temperature in millidegrees */ + int getADC(dacIndex index); + int getOnChipDAC(slsDetectorDefs::dacIndex index, int chipIndex); + void setOnChipDAC(slsDetectorDefs::dacIndex index, int chipIndex, + int value); + + /************************************************** + * * + * Acquisition * + * * + * ************************************************/ + void startReceiver(); + void stopReceiver(); + void prepareAcquisition(); + void startAcquisition(); + void stopAcquisition(); + runStatus getRunStatus() const; + runStatus getReceiverStatus() const; + int64_t getFramesCaughtByReceiver() const; + std::vector getNumMissingPackets() const; + uint64_t getStartingFrameNumber(); + void setStartingFrameNumber(uint64_t value); + void sendSoftwareTrigger(); + + /************************************************** + * * + * Network Configuration (Detector<->Receiver) * + * * + * ************************************************/ + int getNumberofUDPInterfacesFromShm(); + int getNumberofUDPInterfaces(); + void setNumberofUDPInterfaces(int n); + int getSelectedUDPInterface(); + void selectUDPInterface(int n); + sls::IpAddr getSourceUDPIP(); + void setSourceUDPIP(const sls::IpAddr ip); + sls::IpAddr getSourceUDPIP2(); + void setSourceUDPIP2(const sls::IpAddr ip); + sls::MacAddr getSourceUDPMAC(); + void setSourceUDPMAC(const sls::MacAddr mac); + sls::MacAddr getSourceUDPMAC2(); + void setSourceUDPMAC2(const sls::MacAddr mac); + sls::IpAddr getDestinationUDPIP(); + void setDestinationUDPIP(const sls::IpAddr ip); + sls::IpAddr getDestinationUDPIP2(); + void setDestinationUDPIP2(const sls::IpAddr ip); + sls::MacAddr getDestinationUDPMAC(); + void setDestinationUDPMAC(const sls::MacAddr mac); + sls::MacAddr getDestinationUDPMAC2(); + void setDestinationUDPMAC2(const sls::MacAddr mac); + int getDestinationUDPPort(); + void setDestinationUDPPort(int udpport); + int getDestinationUDPPort2(); + void setDestinationUDPPort2(int udpport); + std::string printReceiverConfiguration(); + bool getTenGiga(); + void setTenGiga(bool value); + bool getTenGigaFlowControl(); + void setTenGigaFlowControl(bool enable); + int getTransmissionDelayFrame(); + void setTransmissionDelayFrame(int value); + int getTransmissionDelayLeft(); + void setTransmissionDelayLeft(int value); + int getTransmissionDelayRight(); + void setTransmissionDelayRight(int value); + + /************************************************** + * * + * Receiver Config * + * * + * ************************************************/ + bool getUseReceiverFlag() const; + std::string getReceiverHostname() const; + void setReceiverHostname(const std::string &receiver); + int getReceiverPort() const; + int setReceiverPort(int port_number); + int getReceiverFifoDepth(); + void setReceiverFifoDepth(int n_frames); + bool getReceiverSilentMode(); + void setReceiverSilentMode(bool enable); /** * Get Quad Type (Only for Eiger Quad detector hardware) @@ -206,7 +249,6 @@ class Module : public virtual slsDetectorDefs { * Set Detector offset in shared memory in dimension d * @param det detector size */ - void updateNumberOfDetector(slsDetectorDefs::xy det); int setControlPort(int port_number); @@ -224,14 +266,6 @@ class Module : public virtual slsDetectorDefs { */ int getStopPort() const; - int setReceiverPort(int port_number); - - /** - * Returns the receiver TCP port \sa sharedSlsDetector - * @returns the receiver TCP port - */ - int getReceiverPort() const; - /** * Lock server for this client IP * @param p 0 to unlock, 1 to lock (-1 gets) @@ -263,17 +297,6 @@ class Module : public virtual slsDetectorDefs { */ std::vector getConfigFileCommands(); - detectorSettings getSettings(); - - /** [Jungfrau] Options:DYNAMICGAIN, DYNAMICHG0, FIXGAIN1, FIXGAIN2, - * FORCESWITCHG1, FORCESWITCHG2 [Gotthard] Options: DYNAMICGAIN, HIGHGAIN, - * LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN [Gotthard2] Options: DYNAMICGAIN, - * FIXGAIN1, FIXGAIN2 [Moench] Options: G1_HIGHGAIN, G1_LOWGAIN, - * G2_HIGHCAP_HIGHGAIN, G2_HIGHCAP_LOWGAIN, G2_LOWCAP_HIGHGAIN, - * G2_LOWCAP_LOWGAIN, G4_HIGHGAIN, G4_LOWGAIN - */ - void setSettings(detectorSettings isettings); - /** * Get threshold energy (Mythen and Eiger) * @returns current threshold value in ev (-1 failed) @@ -312,35 +335,6 @@ class Module : public virtual slsDetectorDefs { */ std::string setSettingsDir(const std::string &dir); - /** [Eiger][Mythen3] */ - void loadSettingsFile(const std::string &fname); - - /** - * Get run status of the detector - * @returns the status of the detector - */ - runStatus getRunStatus() const; - - /** - * Prepares detector for acquisition (Eiger) - */ - void prepareAcquisition(); - - /** - * Start detector acquisition (Non blocking) - */ - void startAcquisition(); - - /** - * Stop detector acquisition - */ - void stopAcquisition(); - - /** - * Give an internal software trigger to the detector (Eiger only) - */ - void sendSoftwareTrigger(); - /** * Start detector acquisition and read all data (Blocking until end of * acquisition) @@ -363,26 +357,6 @@ class Module : public virtual slsDetectorDefs { */ void configureMAC(); - /** - * Set starting frame number for the next acquisition - * @param val starting frame number - */ - void setStartingFrameNumber(uint64_t value); - - /** - * Get starting frame number for the next acquisition - * @returns starting frame number - */ - uint64_t getStartingFrameNumber(); - - int64_t getNumberOfFrames(); - - void setNumberOfFrames(int64_t value); - - int64_t getNumberOfTriggers(); - - void setNumberOfTriggers(int64_t value); - /** [Gotthard2] only in burst mode and in auto timing mode */ int64_t getNumberOfBursts(); @@ -413,12 +387,6 @@ class Module : public virtual slsDetectorDefs { /** [Mythen3] */ void setNumberOfGates(int value); - /** [Mythen3] gatIndex: 0-2, [Others]: -1 always */ - int64_t getExptime(int gateIndex); - - /** [Mythen3] gatIndex: -1 for all, 0-2, [Others]: -1 always */ - void setExptime(int gateIndex, int64_t value); - /** [Mythen3] for all gates */ std::array getExptimeForAllGates(); @@ -431,16 +399,6 @@ class Module : public virtual slsDetectorDefs { /** [Mythen3] for all gates */ std::array getGateDelayForAllGates(); - int64_t getPeriod(); - - void setPeriod(int64_t value); - - /** [Gotthard][Jungfrau][CTB][Moench][Mythen3][Gotthard2] */ - int64_t getDelayAfterTrigger(); - - /** [Gotthard][Jungfrau][CTB][Moench][Mythen3][Gotthard2] */ - void setDelayAfterTrigger(int64_t value); - /** [Gotthard2] only in burst mode and in auto timing mode */ int64_t getBurstPeriod(); @@ -466,24 +424,9 @@ class Module : public virtual slsDetectorDefs { * Options: (0-1638375 ns (resolution of 25ns) */ void setStorageCellDelay(int64_t value); - /** [Gotthard][Jungfrau][CTB][Moench][Mythen3] - * [Gotthard2] only in continuous mode */ - int64_t getNumberOfFramesLeft() const; - - /** [Gotthard][Jungfrau][CTB][Moench][Mythen3] - * [Gotthard2] only in continuous mode */ - int64_t getNumberOfTriggersLeft() const; - - /** [Gotthard][Jungfrau][CTB][Moench] - * [Gotthard2] only in continuous mode */ - int64_t getDelayAfterTriggerLeft() const; - /** [Gotthard] */ int64_t getExptimeLeft() const; - /** [Gotthard][Jungfrau][CTB][Moench][Mythen3][Gotthard2] */ - int64_t getPeriodLeft() const; - /** [Eiger] minimum two frames */ int64_t getMeasuredPeriod() const; @@ -502,9 +445,6 @@ class Module : public virtual slsDetectorDefs { * [Gotthard2] only in continuous mode */ int64_t getMeasurementTime() const; - timingMode getTimingMode(); - void setTimingMode(timingMode value); - int getDynamicRange(); /** * Set/get dynamic range @@ -513,30 +453,6 @@ class Module : public virtual slsDetectorDefs { */ void setDynamicRange(int n); - /** - * Set/get dacs value - * @param val value (in V) - * @param index DAC index - * @param mV 0 in dac units or 1 in mV - * @returns current DAC value - */ - int setDAC(int val, dacIndex index, int mV); - - /* [Gotthard2] */ - int getOnChipDAC(slsDetectorDefs::dacIndex index, int chipIndex); - - /* [Gotthard2] */ - void setOnChipDAC(slsDetectorDefs::dacIndex index, int chipIndex, - int value); - - /** - * Get adc value - * @param index adc(DAC) index - * @returns current adc value (temperature for eiger and jungfrau in - * millidegrees) - */ - int getADC(dacIndex index); - externalSignalFlag getExternalSignalFlags(int signalIndex); void setExternalSignalFlags(int signalIndex, externalSignalFlag type); @@ -632,183 +548,7 @@ class Module : public virtual slsDetectorDefs { */ uint32_t clearBit(uint32_t addr, int n); - /** - * Validates and sets the receiver. - * Also updates the receiver with all the shared memory parameters - * significant for the receiver Also configures the detector to the receiver - * as UDP destination - * @param receiver receiver hostname or IP address - */ - void setReceiverHostname(const std::string &receiver); - void test(); - /** - * Returns the receiver IP address\sa sharedSlsDetector - * @returns the receiver IP address - */ - std::string getReceiverHostname() const; - - /** - * Validates the format of the detector MAC address and sets it - * @param mac detector MAC address - */ - void setSourceUDPMAC(const sls::MacAddr mac); - - /** - * Returns the detector MAC address - * @returns the detector MAC address - */ - sls::MacAddr getSourceUDPMAC(); - - /** - * Validates the format of the detector MAC address (bottom half) and sets - * it (Jungfrau only) - * @param mac detector MAC address (bottom half) - */ - void setSourceUDPMAC2(const sls::MacAddr mac); - - /** - * Returns the detector MAC address (bottom half) Jungfrau only - * @returns the detector MAC address (bottom half) - */ - sls::MacAddr getSourceUDPMAC2(); - - /** - * Validates the format of the detector IP address and sets it - * @param ip detector IP address - */ - void setSourceUDPIP(const sls::IpAddr ip); - - /** - * Returns the detector IP address - * @returns the detector IP address - */ - sls::IpAddr getSourceUDPIP(); - - /** - * Validates the format of the detector IP address (bottom half) and sets it - * (Jungfrau only) - * @param ip detector IP address (bottom half) - */ - void setSourceUDPIP2(const sls::IpAddr ip); - - /** - * Returns the detector IP address (bottom half) Jungfrau only - * @returns the detector IP address (bottom half) - */ - sls::IpAddr getSourceUDPIP2(); - - /** - * Validates the format of the receiver UDP IP address and sets it - * If slsReceiver used, Gets receiver udp mac address and sends it to the - * detector - * @param ip receiver UDP IP address - */ - void setDestinationUDPIP(const sls::IpAddr ip); - - /** - * Returns the receiver UDP IP address - * If slsReceiver used, Gets receiver udp mac address and sends it to the - * detector - * @returns the receiver UDP IP address - */ - sls::IpAddr getDestinationUDPIP(); - - /** - * Validates the format of the receiver UDP IP address (bottom half) and - * sets it(Jungfrau only) - * If slsReceiver used, Gets receiver udp mac address2 and sends it to the - * detector - * @param ip receiver UDP IP address (bottom half) - */ - void setDestinationUDPIP2(const sls::IpAddr ip); - - /** - * Returns the receiver UDP IP address (bottom half) Jungfrau only - * If slsReceiver used, Gets receiver udp mac address2 and sends it to the - * detector - * @returns the receiver UDP IP address (bottom half) - */ - sls::IpAddr getDestinationUDPIP2(); - - /** - * Validates the format of the receiver UDP MAC address and sets it - * @param mac receiver UDP MAC address - */ - void setDestinationUDPMAC(const sls::MacAddr mac); - - /** - * Returns the receiver UDP MAC address - * @returns the receiver UDP MAC address - */ - sls::MacAddr getDestinationUDPMAC(); - - /** - * Validates the format of the receiver UDP MAC address (bottom half) and - * sets it (Jungfrau only) - * @param mac receiver UDP MAC address (bottom half) - */ - void setDestinationUDPMAC2(const sls::MacAddr mac); - - /** - * Returns the receiver UDP MAC address (bottom half) Jungfrau only - * @returns the receiver UDP MAC address (bottom half) - */ - sls::MacAddr getDestinationUDPMAC2(); - - /** - * Sets the receiver UDP port\sa sharedSlsDetector - * @param udpport receiver UDP port - */ - void setDestinationUDPPort(int udpport); - - /** - * Returns the receiver UDP port\sa sharedSlsDetector - * @returns the receiver UDP port - */ - int getDestinationUDPPort(); - - /** - * Sets the receiver UDP port 2\sa sharedSlsDetector (Eiger and Jungfrau - * only) - * @param udpport receiver UDP port 2 - */ - void setDestinationUDPPort2(int udpport); - - /** - * Returns the receiver UDP port 2 of same interface\sa sharedSlsDetector - * (Eiger and Jungfrau only) - * @returns the receiver UDP port 2 of same interface - */ - int getDestinationUDPPort2(); - - /** [Jungfrau][Gotthard2] */ - void setNumberofUDPInterfaces(int n); - - /** Returns the number of udp interfaces from shared memory */ - int getNumberofUDPInterfacesFromShm(); - - /** - * Returns the number of UDP interfaces to stream data from detector - * (Jungfrau only) - * @returns the number of interfaces - */ - int getNumberofUDPInterfaces(); - - /** - * Selects the UDP interfaces to stream data from detector. Effective only - * when number of interfaces is 1. (Jungfrau only) - * @param n selected interface. Options 1 or 2. - * @returns the interface selected - */ - void selectUDPInterface(int n); - - /** - * Returns the UDP interfaces to stream data from detector. Effective only - * when number of interfaces is 1. (Jungfrau only) - * @returns the interface selected - */ - int getSelectedUDPInterface(); /** * Sets the client zmq port\sa sharedSlsDetector @@ -863,43 +603,6 @@ class Module : public virtual slsDetectorDefs { */ void updateReceiverStreamingIP(); - /** [Eiger, Jungfrau] */ - bool getTenGigaFlowControl(); - - /** [Eiger, Jungfrau] */ - void setTenGigaFlowControl(bool enable); - - /** [Eiger, Jungfrau] */ - int getTransmissionDelayFrame(); - - /** - * [Jungfrau]: Sets the transmission delay of the first UDP packet being - * streamed out of the module. Options: 0 - 31, each value represenets 1 ms - * [Eiger]: Sets the transmission delay of entire frame streamed out for - * both left and right UDP ports. Options: //TODO possible values - */ - void setTransmissionDelayFrame(int value); - - /** [Eiger] */ - int getTransmissionDelayLeft(); - - /** - * [Eiger] - * Sets the transmission delay of first packet streamed out of the left UDP - * port - */ - void setTransmissionDelayLeft(int value); - - /** [Eiger] */ - int getTransmissionDelayRight(); - - /** - * [Eiger] - * Sets the transmission delay of first packet streamed ut of the right UDP - * port - */ - void setTransmissionDelayRight(int value); - /** empty vector deletes entire additional json header */ void setAdditionalJsonHeader( const std::map &jsonHeader); @@ -937,15 +640,6 @@ class Module : public virtual slsDetectorDefs { /** [Gotthard][Jungfrau][CTB][Moench] */ void executeBusTest(); - /** [Gotthard][Eiger virtual] */ - int getImageTestMode(); - - /** [Gotthard] If 1, adds channel intensity with precalculated values. - * Default is 0 - * [Eiger virtual] If 1, pixels are saturated. If 0, increasing intensity - * Only for virtual servers */ - void setImageTestMode(const int value); - /** [Gotthard2] */ std::array getInjectChannel(); @@ -1110,9 +804,6 @@ class Module : public virtual slsDetectorDefs { */ void setFlippedDataX(bool value); - int getAllTrimbits(); - void setAllTrimbits(int val); - /** * Sets the number of trim energies and their value (Eiger) * \sa sharedSlsDetector @@ -1210,13 +901,6 @@ class Module : public virtual slsDetectorDefs { */ void rebootController(); - /** - * Power on/off Chip (Jungfrau) - * @param ival on is 1, off is 0, -1 to get - * @returns OK or FAIL - */ - int powerChip(int ival = -1); - /** * Automatic comparator disable (Jungfrau) * @param ival on is 1, off is 0, -1 to get @@ -1273,17 +957,6 @@ class Module : public virtual slsDetectorDefs { */ void updateRateCorrection(); - /** - * Prints receiver configuration - * @returns receiver configuration - */ - std::string printReceiverConfiguration(); - - /** - * Gets the use receiver flag from shared memory - */ - bool getUseReceiverFlag() const; - /** * Locks/Unlocks the connection to the receiver * @param lock sets (1), usets (0), gets (-1) the lock @@ -1321,31 +994,6 @@ class Module : public virtual slsDetectorDefs { bool getPartialFramesPadding(); void setPartialFramesPadding(bool padding); - /** - * Receiver starts listening to packets - */ - void startReceiver(); - - /** - * Stops the listening mode of receiver - */ - void stopReceiver(); - - /** - * Gets the status of the listening mode of receiver - * @returns status - */ - runStatus getReceiverStatus() const; - - /** - * Gets the number of frames caught by receiver - * @returns number of frames caught by receiver - */ - int64_t getFramesCaughtByReceiver() const; - - /** Gets number of missing packets */ - std::vector getNumMissingPackets() const; - /** * Gets the current frame index of receiver * @returns current frame index of receiver @@ -1385,23 +1033,6 @@ class Module : public virtual slsDetectorDefs { void setReceiverStreaming(bool enable); - /** - * Enable/disable or 10Gbe - * @param i is -1 to get, 0 to disable and 1 to enable - * @returns if 10Gbe is enabled - */ - bool enableTenGigabitEthernet(int value = -1); - - /** - * Set/get receiver fifo depth - * @param i is -1 to get, any other value to set the fifo deph - * @returns the receiver fifo depth - */ - int setReceiverFifoDepth(int n_frames = -1); - - bool getReceiverSilentMode(); - void setReceiverSilentMode(bool enable); - /** * If data streaming in receiver is enabled, * restream the stop dummy packet from receiver @@ -1516,27 +1147,6 @@ class Module : public virtual slsDetectorDefs { */ void setDigitalIODelay(uint64_t pinMask, int delay); - /** [Mythen3][Gotthard2] */ - int getClockFrequency(int clkIndex); - - /** [Mythen3][Gotthard2] */ - void setClockFrequency(int clkIndex, int value); - - /** [Mythen3][Gotthard2] */ - int getClockPhase(int clkIndex, bool inDegrees); - - /** [Mythen3][Gotthard2] */ - void setClockPhase(int clkIndex, int value, bool inDegrees); - - /** [Mythen3][Gotthard2] */ - int getMaxClockPhaseShift(int clkIndex); - - /** [Mythen3][Gotthard2] */ - int getClockDivider(int clkIndex); - - /** [Mythen3][Gotthard2] */ - void setClockDivider(int clkIndex, int value); - /** [Ctb][Moench] */ int getPipeline(int clkIndex); @@ -1610,6 +1220,13 @@ class Module : public virtual slsDetectorDefs { void sendToDetectorStop(int fnum) const; + template Ret sendToDetectorStop(int fnum); + + template Ret sendToDetectorStop(int fnum) const; + + template + Ret sendToDetectorStop(int fnum, const Arg &args); + /** * Send function parameters to receiver * @param fnum function enum @@ -1652,31 +1269,21 @@ class Module : public virtual slsDetectorDefs { template Ret sendToReceiver(int fnum, const Arg &args) const; - /** - * Get Detector Type from Shared Memory (opening shm without verifying size) - * @param multi_id multi detector Id - * @param verify true to verify if shm size matches existing one - * @returns detector type - */ - detectorType getDetectorTypeFromShm(int multi_id, bool verify = true); + /** Get Detector Type from Shared Memory + @param verify if shm size matches existing one */ + detectorType getDetectorTypeFromShm(int det_id, bool verify = true); - /** - * Initialize shared memory - * @param created true if shared memory must be created, else false to open - * @param type type of detector - * @param multi_id multi detector Id - * @param verify true to verify if shm size matches existing one - * @returns true if the shared memory was created now - */ - void initSharedMemory(detectorType type, int multi_id, bool verify = true); + /** Initialize shared memory + @param verify if shm size matches existing one */ + void initSharedMemory(detectorType type, int det_id, bool verify = true); - /** - * Initialize detector structure to defaults - * Called when new shared memory is created - * @param type type of detector - */ + /** Initialize detector structure to defaults, + Called when new shared memory is created */ void initializeDetectorStructure(detectorType type); + void checkDetectorVersionCompatibility(); + void checkReceiverVersionCompatibility(); + /** * Send a sls_detector_module structure over socket * @param myMod module structure to send @@ -1738,7 +1345,7 @@ class Module : public virtual slsDetectorDefs { sls_detector_module readSettingsFile(const std::string &fname, int tb = 1); /** Module Id or position in the detectors list */ - const int detId; + const int moduleId; /** Shared Memory object */ mutable sls::SharedMemory shm{0, 0}; diff --git a/slsReceiverSoftware/src/ClientInterface.cpp b/slsReceiverSoftware/src/ClientInterface.cpp index d1300c9b1..ca884d96c 100644 --- a/slsReceiverSoftware/src/ClientInterface.cpp +++ b/slsReceiverSoftware/src/ClientInterface.cpp @@ -338,49 +338,7 @@ int ClientInterface::get_version(Interface &socket) { int ClientInterface::setup_receiver(Interface &socket) { auto arg = socket.Receive(); - LOG(logDEBUG) << "detType:" << arg.detType << std::endl - << "numberOfDetector.x:" << arg.numberOfDetector.x - << std::endl - << "numberOfDetector.y:" << arg.numberOfDetector.y - << std::endl - << "detId:" << arg.detId << std::endl - << "hostname:" << arg.hostname << std::endl - << "udpInterfaces:" << arg.udpInterfaces << std::endl - << "udp_dstport:" << arg.udp_dstport << std::endl - << "udp_dstip:" << sls::IpAddr(arg.udp_dstip) << std::endl - << "udp_dstmac:" << sls::MacAddr(arg.udp_dstmac) << std::endl - << "udp_dstport2:" << arg.udp_dstport2 << std::endl - << "udp_dstip2:" << sls::IpAddr(arg.udp_dstip2) << std::endl - << "udp_dstmac2:" << sls::MacAddr(arg.udp_dstmac2) - << std::endl - << "frames:" << arg.frames << std::endl - << "triggers:" << arg.triggers << std::endl - << "bursts:" << arg.bursts << std::endl - << "analogSamples:" << arg.analogSamples << std::endl - << "digitalSamples:" << arg.digitalSamples << std::endl - << "expTimeNs:" << arg.expTimeNs << std::endl - << "periodNs:" << arg.periodNs << std::endl - << "subExpTimeNs:" << arg.subExpTimeNs << std::endl - << "subDeadTimeNs:" << arg.subDeadTimeNs << std::endl - << "activate:" << arg.activate << std::endl - << "quad:" << arg.quad << std::endl - << "dynamicRange:" << arg.dynamicRange << std::endl - << "timMode:" << arg.timMode << std::endl - << "tenGiga:" << arg.tenGiga << std::endl - << "roMode:" << arg.roMode << std::endl - << "adcMask:" << arg.adcMask << std::endl - << "adc10gMask:" << arg.adc10gMask << std::endl - << "roi.xmin:" << arg.roi.xmin << std::endl - << "roi.xmax:" << arg.roi.xmax << std::endl - << "countermask:" << arg.countermask << std::endl - << "burstType:" << arg.burstType << std::endl - << "exptime1:" << arg.expTime1Ns << std::endl - << "exptime2:" << arg.expTime2Ns << std::endl - << "exptime3:" << arg.expTime3Ns << std::endl - << "gateDelay1:" << arg.gateDelay1Ns << std::endl - << "gateDelay2:" << arg.gateDelay2Ns << std::endl - << "gateDelay3:" << arg.gateDelay3Ns << std::endl - << "gates:" << arg.gates << std::endl; + LOG(logDEBUG) << sls::ToString(arg); // if object exists, verify unlocked and idle, else only verify lock // (connecting first time) @@ -394,7 +352,7 @@ int ClientInterface::setup_receiver(Interface &socket) { int msize[2] = {arg.numberOfDetector.x, arg.numberOfDetector.y}; impl()->setDetectorSize(msize); } - impl()->setDetectorPositionId(arg.detId); + impl()->setModulePositionId(arg.moduleId); impl()->setDetectorHostname(arg.hostname); // udp setup diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index 6cc9c63be..621bdbcc4 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -55,7 +55,7 @@ void Implementation::InitializeMembers() { myDetectorType = GENERIC; for (int i = 0; i < MAX_DIMENSIONS; ++i) numDet[i] = 0; - detID = 0; + modulePos = 0; detHostname = ""; silentMode = false; fifoDepth = 0; @@ -350,31 +350,32 @@ void Implementation::setDetectorSize(const int *size) { LOG(logINFO) << log_message; } -int Implementation::getDetectorPositionId() const { +int Implementation::getModulePositionId() const { LOG(logDEBUG3) << __SHORT_AT__ << " called"; - return detID; + return modulePos; } -void Implementation::setDetectorPositionId(const int id) { +void Implementation::setModulePositionId(const int id) { LOG(logDEBUG3) << __SHORT_AT__ << " called"; - detID = id; - LOG(logINFO) << "Detector Position Id:" << detID; + modulePos = id; + LOG(logINFO) << "Module Position Id:" << modulePos; // update zmq port streamingPort = - DEFAULT_ZMQ_RX_PORTNO + (detID * (myDetectorType == EIGER ? 2 : 1)); + DEFAULT_ZMQ_RX_PORTNO + (modulePos * (myDetectorType == EIGER ? 2 : 1)); for (unsigned int i = 0; i < dataProcessor.size(); ++i) { dataProcessor[i]->SetupFileWriter( fileWriteEnable, (int *)numDet, &framesPerFile, &fileName, - &filePath, &fileIndex, &overwriteEnable, &detID, &numThreads, + &filePath, &fileIndex, &overwriteEnable, &modulePos, &numThreads, &numberOfTotalFrames, &dynamicRange, &udpPortNum[i], generalData); } assert(numDet[1] != 0); for (unsigned int i = 0; i < listener.size(); ++i) { uint16_t row = 0, col = 0; - row = (detID % numDet[1]) * ((numUDPInterfaces == 2) ? 2 : 1); // row - col = (detID / numDet[1]) * ((myDetectorType == EIGER) ? 2 : 1) + + row = + (modulePos % numDet[1]) * ((numUDPInterfaces == 2) ? 2 : 1); // row + col = (modulePos / numDet[1]) * ((myDetectorType == EIGER) ? 2 : 1) + i; // col for horiz. udp ports listener[i]->SetHardCodedPosition(row, col); } @@ -555,9 +556,9 @@ void Implementation::setFileWriteEnable(const bool b) { for (unsigned int i = 0; i < dataProcessor.size(); ++i) { dataProcessor[i]->SetupFileWriter( fileWriteEnable, (int *)numDet, &framesPerFile, &fileName, - &filePath, &fileIndex, &overwriteEnable, &detID, &numThreads, - &numberOfTotalFrames, &dynamicRange, &udpPortNum[i], - generalData); + &filePath, &fileIndex, &overwriteEnable, &modulePos, + &numThreads, &numberOfTotalFrames, &dynamicRange, + &udpPortNum[i], generalData); } } @@ -1064,7 +1065,7 @@ void Implementation::setNumberofUDPInterfaces(const int n) { // update (from 1 to 2 interface) & also for printout setDetectorSize(numDet); // update row and column in dataprocessor - setDetectorPositionId(detID); + setModulePositionId(modulePos); // update call backs if (rawDataReadyCallBack) { diff --git a/slsReceiverSoftware/src/Implementation.h b/slsReceiverSoftware/src/Implementation.h index 889fed2c3..403ceb412 100644 --- a/slsReceiverSoftware/src/Implementation.h +++ b/slsReceiverSoftware/src/Implementation.h @@ -30,8 +30,8 @@ class Implementation : private virtual slsDetectorDefs { void setDetectorType(const detectorType d); int *getDetectorSize() const; void setDetectorSize(const int *size); - int getDetectorPositionId() const; - void setDetectorPositionId(const int id); + int getModulePositionId() const; + void setModulePositionId(const int id); std::string getDetectorHostname() const; void setDetectorHostname(const std::string &c); bool getSilentMode() const; @@ -265,7 +265,7 @@ class Implementation : private virtual slsDetectorDefs { int numThreads; detectorType myDetectorType; int numDet[MAX_DIMENSIONS]; - int detID; + int modulePos; std::string detHostname; bool silentMode; uint32_t fifoDepth; diff --git a/slsSupportLib/include/ToString.h b/slsSupportLib/include/ToString.h index 7d7517e85..ff2db057f 100644 --- a/slsSupportLib/include/ToString.h +++ b/slsSupportLib/include/ToString.h @@ -41,6 +41,9 @@ std::string ToString(const defs::timingSourceType s); std::string ToString(const slsDetectorDefs::ROI &roi); std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::ROI &roi); +std::string ToString(const slsDetectorDefs::rxParameters &r); +std::ostream &operator<<(std::ostream &os, + const slsDetectorDefs::rxParameters &r); const std::string &ToString(const std::string &s); /** Convert std::chrono::duration with specified output unit */ diff --git a/slsSupportLib/include/sls_detector_defs.h b/slsSupportLib/include/sls_detector_defs.h index 78528006a..373f0707f 100644 --- a/slsSupportLib/include/sls_detector_defs.h +++ b/slsSupportLib/include/sls_detector_defs.h @@ -446,7 +446,7 @@ typedef struct { struct rxParameters { detectorType detType{GENERIC}; xy numberOfDetector; - int detId{0}; + int moduleId{0}; char hostname[MAX_STR_LENGTH]; int udpInterfaces{1}; int udp_dstport{0}; diff --git a/slsSupportLib/src/ToString.cpp b/slsSupportLib/src/ToString.cpp index 8b33f553d..e57727957 100644 --- a/slsSupportLib/src/ToString.cpp +++ b/slsSupportLib/src/ToString.cpp @@ -1,4 +1,5 @@ #include "ToString.h" +#include "network_utils.h" namespace sls { @@ -12,6 +13,57 @@ std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::ROI &roi) { return os << ToString(roi); } +std::string ToString(const slsDetectorDefs::rxParameters &r) { + std::ostringstream oss; + oss << '[' << "detType:" << r.detType << std::endl + << "numberOfDetector.x:" << r.numberOfDetector.x << std::endl + << "numberOfDetector.y:" << r.numberOfDetector.y << std::endl + << "moduleId:" << r.moduleId << std::endl + << "hostname:" << r.hostname << std::endl + << "udpInterfaces:" << r.udpInterfaces << std::endl + << "udp_dstport:" << r.udp_dstport << std::endl + << "udp_dstip:" << sls::IpAddr(r.udp_dstip) << std::endl + << "udp_dstmac:" << sls::MacAddr(r.udp_dstmac) << std::endl + << "udp_dstport2:" << r.udp_dstport2 << std::endl + << "udp_dstip2:" << sls::IpAddr(r.udp_dstip2) << std::endl + << "udp_dstmac2:" << sls::MacAddr(r.udp_dstmac2) << std::endl + << "frames:" << r.frames << std::endl + << "triggers:" << r.triggers << std::endl + << "bursts:" << r.bursts << std::endl + << "analogSamples:" << r.analogSamples << std::endl + << "digitalSamples:" << r.digitalSamples << std::endl + << "expTimeNs:" << r.expTimeNs << std::endl + << "periodNs:" << r.periodNs << std::endl + << "subExpTimeNs:" << r.subExpTimeNs << std::endl + << "subDeadTimeNs:" << r.subDeadTimeNs << std::endl + << "activate:" << r.activate << std::endl + << "quad:" << r.quad << std::endl + << "dynamicRange:" << r.dynamicRange << std::endl + << "timMode:" << r.timMode << std::endl + << "tenGiga:" << r.tenGiga << std::endl + << "roMode:" << r.roMode << std::endl + << "adcMask:" << r.adcMask << std::endl + << "adc10gMask:" << r.adc10gMask << std::endl + << "roi.xmin:" << r.roi.xmin << std::endl + << "roi.xmax:" << r.roi.xmax << std::endl + << "countermask:" << r.countermask << std::endl + << "burstType:" << r.burstType << std::endl + << "exptime1:" << r.expTime1Ns << std::endl + << "exptime2:" << r.expTime2Ns << std::endl + << "exptime3:" << r.expTime3Ns << std::endl + << "gateDelay1:" << r.gateDelay1Ns << std::endl + << "gateDelay2:" << r.gateDelay2Ns << std::endl + << "gateDelay3:" << r.gateDelay3Ns << std::endl + << "gates:" << r.gates << std::endl + << ']'; + return oss.str(); +} + +std::ostream &operator<<(std::ostream &os, + const slsDetectorDefs::rxParameters &r) { + return os << ToString(r); +} + std::string ToString(const defs::runStatus s) { switch (s) { case defs::ERROR: