From 4813b5567ad93064312ab6278a3eb27aaedcdf68 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil <33750417+thattil@users.noreply.github.com> Date: Thu, 19 Mar 2020 02:01:32 -0400 Subject: [PATCH] Minimal shared memory for receiver --- ctbGui/ctbAcquisition.cpp | 37 +- ctbGui/ctbSignals.cpp | 54 +- python/slsdet/detector.py | 31 +- python/src/detector.cpp | 64 +- python/src/enums.cpp | 17 + python/src/network.cpp | 10 +- slsDetectorGui/src/qDrawPlot.cpp | 21 +- slsDetectorSoftware/src/CmdProxy.cpp | 77 ++ slsDetectorSoftware/src/CmdProxy.h | 23 +- slsDetectorSoftware/src/Detector.cpp | 36 +- slsDetectorSoftware/src/Module.cpp | 753 +++++++----------- slsDetectorSoftware/src/Module.h | 265 +----- .../tests/test-CmdProxy-gotthard2.cpp | 2 +- .../tests/test-CmdProxy-rx.cpp | 112 ++- slsDetectorSoftware/tests/test-CmdProxy.cpp | 48 -- slsReceiverSoftware/src/ClientInterface.cpp | 458 ++++++----- slsReceiverSoftware/src/ClientInterface.h | 26 +- slsReceiverSoftware/src/Implementation.cpp | 9 +- slsReceiverSoftware/src/receiver_defs.h | 9 + slsSupportLib/include/sls_detector_defs.h | 8 - slsSupportLib/include/sls_detector_funcs.h | 80 +- slsSupportLib/src/ClientSocket.cpp | 14 +- slsSupportLib/src/network_utils.cpp | 2 +- slsSupportLib/tests/test-network_utils.cpp | 6 + 24 files changed, 1045 insertions(+), 1117 deletions(-) diff --git a/ctbGui/ctbAcquisition.cpp b/ctbGui/ctbAcquisition.cpp index fa5bbb9a0..b2e74e533 100755 --- a/ctbGui/ctbAcquisition.cpp +++ b/ctbGui/ctbAcquisition.cpp @@ -1646,10 +1646,13 @@ void ctbAcquisition::update() { } - try { - dBitOffset = myDet->getRxDbitOffset().tsquash("Different values"); - } CATCH_DISPLAY ("Could not get receiver dbit offset", "ctbAcquisition::update") - + if (myDet->getDetectorType().squash() == slsDetectorDefs::MOENCH) { + dBitOffset = 0; + } else { + try { + dBitOffset = myDet->getRxDbitOffset().tsquash("Different values"); + } CATCH_DISPLAY ("Could not get receiver dbit offset", "ctbAcquisition::update") + } try { tenG = myDet->getTenGiga().tsquash("Different values"); } CATCH_DISPLAY ("Could not get ten giga enable", "ctbAcquisition::update") @@ -1735,9 +1738,13 @@ void ctbAcquisition::toggleAcquisition() { setDigitalSamples(retval); } CATCH_DISPLAY ("Could not get number of digital samples", "ctbAcquisition::toggleAcquisition") + if (myDet->getDetectorType().squash() == slsDetectorDefs::MOENCH) { + dBitOffset = 0; + } else { try { - dBitOffset = myDet->getRxDbitOffset().tsquash("Different values"); - } CATCH_DISPLAY ("Could not get receiver dbit offset", "ctbAcquisition::toggleAcquisition") + dBitOffset = myDet->getRxDbitOffset().tsquash("Different values"); + } CATCH_DISPLAY ("Could not get receiver dbit offset", "ctbAcquisition::toggleAcquisition") + } try { roMode = static_cast(myDet->getReadoutMode().tsquash("Different values")); @@ -1974,14 +1981,18 @@ void ctbAcquisition::setDbitEnable(Int_t reg){ void ctbAcquisition::updateChans() { // dbit list - try { - auto retval = myDet->getRxDbitList().tsquash("Different values"); + if (myDet->getDetectorType().squash() == slsDetectorDefs::MOENCH) { dbitlist.clear(); - if (!retval.empty()) { - for (const auto &value : retval) - dbitlist.push_back(value); - } - } CATCH_DISPLAY ("Could not get receiver dbit list.", "ctbAcquisition::updateChans") + } else { + try { + auto retval = myDet->getRxDbitList().tsquash("Different values"); + dbitlist.clear(); + if (!retval.empty()) { + for (const auto &value : retval) + dbitlist.push_back(value); + } + } CATCH_DISPLAY ("Could not get receiver dbit list.", "ctbAcquisition::updateChans") + } // adc mask try { diff --git a/ctbGui/ctbSignals.cpp b/ctbGui/ctbSignals.cpp index 3afbbe349..47237be47 100755 --- a/ctbGui/ctbSignals.cpp +++ b/ctbGui/ctbSignals.cpp @@ -374,33 +374,43 @@ void ctbSignals::update() { } CATCH_DISPLAY ("Could not get patternIOcontrol.", "ctbSignals::update") - try { - - auto dbitlist = myDet->getRxDbitList().tsquash("Different values"); + if (myDet->getDetectorType().squash() == slsDetectorDefs::MOENCH) { // enable all - if (dbitlist.empty()) { - for (int is=0; is<64; is++) { - signals[is]->setDbitList(1); - } - } - else { - // disable all - for (int is=0; is<64; is++) { - signals[is]->setDbitList(0); + for (int is=0; is<64; is++) { + signals[is]->setDbitList(1); + } + eDbitOffset->SetNumber(0); + } + + // ctb + else { + try { + + auto dbitlist = myDet->getRxDbitList().tsquash("Different values"); + // enable all + if (dbitlist.empty()) { + for (int is=0; is<64; is++) { + signals[is]->setDbitList(1); + } } - // enable selected - for (const auto &value : dbitlist) { - signals[value]->setDbitList(1); + else { + // disable all + for (int is=0; is<64; is++) { + signals[is]->setDbitList(0); + } + // enable selected + for (const auto &value : dbitlist) { + signals[value]->setDbitList(1); + } } - } - } CATCH_DISPLAY ("Could not get receiver dbit list.", "ctbSignals::update") - - try { - auto val = myDet->getRxDbitOffset().tsquash("Different values"); - eDbitOffset->SetNumber(val); - } CATCH_DISPLAY ("Could not get receiver dbit offset.", "ctbSignals::update") + } CATCH_DISPLAY ("Could not get receiver dbit list.", "ctbSignals::update") + try { + auto val = myDet->getRxDbitOffset().tsquash("Different values"); + eDbitOffset->SetNumber(val); + } CATCH_DISPLAY ("Could not get receiver dbit offset.", "ctbSignals::update") + } } diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index 0c49df11e..290ee010d 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -1,5 +1,6 @@ from _slsdet import CppDetectorApi from _slsdet import slsDetectorDefs +from _slsdet import IpAddr, MacAddr runStatus = slsDetectorDefs.runStatus speedLevel = slsDetectorDefs.speedLevel @@ -12,12 +13,13 @@ import datetime as dt from functools import wraps from collections import namedtuple +import socket def freeze(cls): cls._frozen = False def frozensetattr(self, key, value): - if self._frozen and not hasattr(self, key): + if self._frozen and not key in dir(self): raise AttributeError( "Class {} is frozen. Cannot set {} = {}".format( cls.__name__, key, value @@ -58,7 +60,6 @@ class Detector(CppDetectorApi): self._adc_register = Adc_register(self) - # CONFIGURATION def __len__(self): return self.size() @@ -71,9 +72,6 @@ class Detector(CppDetectorApi): def free(self): self.freeSharedMemory() - - - @property def config(self): return NotImplementedError("config is set only") @@ -92,6 +90,7 @@ class Detector(CppDetectorApi): @property def hostname(self): + print('getting host!') return self.getHostname() @hostname.setter @@ -422,7 +421,9 @@ class Detector(CppDetectorApi): @udp_dstip.setter def udp_dstip(self, ip): - self.getDestinationUDPIP(ip) + if ip == 'auto': + ip = socket.gethostbyname(self.rx_hostname) + self.setDestinationUDPIP(IpAddr(ip)) @property def udp_dstip2(self): @@ -430,7 +431,9 @@ class Detector(CppDetectorApi): @udp_dstip2.setter def udp_dstip2(self, ip): - self.getDestinationUDPIP2(ip) + if ip == 'auto': + ip = socket.gethostbyname(self.rx_hostname) + self.setDestinationUDPIP2(IpAddr(ip)) @property def udp_dstmac(self): @@ -438,7 +441,7 @@ class Detector(CppDetectorApi): @udp_dstmac.setter def udp_dstmac(self, mac): - self.getDestinationUDPMAC2(mac) + self.setDestinationUDPMAC(MacAddr(mac)) @property def udp_dstmac2(self): @@ -446,7 +449,7 @@ class Detector(CppDetectorApi): @udp_dstmac2.setter def udp_dstmac2(self, mac): - self.getDestinationUDPMAC2(mac) + self.setDestinationUDPMAC2(MacAddr(mac)) @property @@ -455,7 +458,7 @@ class Detector(CppDetectorApi): @udp_srcip.setter def udp_srcip(self, ip): - self.setSourceUDPIP(ip) + self.setSourceUDPIP(IpAddr(ip)) @property def udp_srcip2(self): @@ -487,7 +490,7 @@ class Detector(CppDetectorApi): @src_udpmac.setter def src_udpmac(self, mac): - self.setSourceUDPMAC(mac) + self.setSourceUDPMAC(MacAddr(mac)) @property def src_udpip2(self): @@ -495,7 +498,7 @@ class Detector(CppDetectorApi): @src_udpip2.setter def src_udpip2(self, ip): - self.setSourceUDPIP(ip) + self.setSourceUDPIP(IpAddr(ip)) @property def src_udpip(self): @@ -503,7 +506,7 @@ class Detector(CppDetectorApi): @src_udpip.setter def src_udpip(self, ip): - self.setSourceUDPIP(ip) + self.setSourceUDPIP(IpAddr(ip)) @property @@ -512,7 +515,7 @@ class Detector(CppDetectorApi): @src_udpmac2.setter def src_udpmac2(self, mac): - self.setSourceUDPMAC2(mac) + self.setSourceUDPMAC2(MacAddr(mac)) @property def vhighvoltage(self): diff --git a/python/src/detector.cpp b/python/src/detector.cpp index c45daeb74..2261bcbe1 100644 --- a/python/src/detector.cpp +++ b/python/src/detector.cpp @@ -92,6 +92,15 @@ void init_det(py::module &m) { py::arg() = Positions{}) .def("setADCPhaseInDegrees", &Detector::setADCPhaseInDegrees, py::arg(), py::arg() = Positions{}) + .def("getDBITPhase", &Detector::getDBITPhase, py::arg() = Positions{}) + .def("setDBITPhase", &Detector::setDBITPhase, py::arg(), + py::arg() = Positions{}) + .def("getMaxDBITPhaseShift", &Detector::getMaxDBITPhaseShift, + py::arg() = Positions{}) + .def("getDBITPhaseInDegrees", &Detector::getDBITPhaseInDegrees, + py::arg() = Positions{}) + .def("setDBITPhaseInDegrees", &Detector::setDBITPhaseInDegrees, + py::arg(), py::arg() = Positions{}) .def("getClockFrequency", &Detector::getClockFrequency, py::arg(), py::arg() = Positions{}) .def("setClockFrequency", &Detector::setClockFrequency, py::arg(), @@ -464,29 +473,9 @@ void init_det(py::module &m) { py::arg() = Positions{}) .def("setNumberOfAnalogSamples", &Detector::setNumberOfAnalogSamples, py::arg(), py::arg() = Positions{}) - .def("getNumberOfDigitalSamples", &Detector::getNumberOfDigitalSamples, - py::arg() = Positions{}) - .def("setNumberOfDigitalSamples", &Detector::setNumberOfDigitalSamples, - py::arg(), py::arg() = Positions{}) - .def("getReadoutMode", &Detector::getReadoutMode, - py::arg() = Positions{}) - .def("setReadoutMode", &Detector::setReadoutMode, py::arg(), - py::arg() = Positions{}) - .def("getDBITPhase", &Detector::getDBITPhase, py::arg() = Positions{}) - .def("setDBITPhase", &Detector::setDBITPhase, py::arg(), - py::arg() = Positions{}) - .def("getMaxDBITPhaseShift", &Detector::getMaxDBITPhaseShift, - py::arg() = Positions{}) - .def("getDBITPhaseInDegrees", &Detector::getDBITPhaseInDegrees, - py::arg() = Positions{}) - .def("setDBITPhaseInDegrees", &Detector::setDBITPhaseInDegrees, - py::arg(), py::arg() = Positions{}) .def("getADCClock", &Detector::getADCClock, py::arg() = Positions{}) .def("setADCClock", &Detector::setADCClock, py::arg(), py::arg() = Positions{}) - .def("getDBITClock", &Detector::getDBITClock, py::arg() = Positions{}) - .def("setDBITClock", &Detector::setDBITClock, py::arg(), - py::arg() = Positions{}) .def("getRUNClock", &Detector::getRUNClock, py::arg() = Positions{}) .def("setRUNClock", &Detector::setRUNClock, py::arg(), py::arg() = Positions{}) @@ -495,20 +484,10 @@ void init_det(py::module &m) { py::arg() = Positions{}) .def("setADCPipeline", &Detector::setADCPipeline, py::arg(), py::arg() = Positions{}) - .def("getDBITPipeline", &Detector::getDBITPipeline, - py::arg() = Positions{}) - .def("setDBITPipeline", &Detector::setDBITPipeline, py::arg(), - py::arg() = Positions{}) .def("getVoltage", &Detector::getVoltage, py::arg(), py::arg() = Positions{}) .def("setVoltage", &Detector::setVoltage, py::arg(), py::arg(), py::arg() = Positions{}) - .def("getMeasuredVoltage", &Detector::getMeasuredVoltage, py::arg(), - py::arg() = Positions{}) - .def("getMeasuredCurrent", &Detector::getMeasuredCurrent, py::arg(), - py::arg() = Positions{}) - .def("getSlowADC", &Detector::getSlowADC, py::arg(), - py::arg() = Positions{}) .def("getADCEnableMask", &Detector::getADCEnableMask, py::arg() = Positions{}) .def("setADCEnableMask", &Detector::setADCEnableMask, py::arg(), @@ -517,8 +496,26 @@ void init_det(py::module &m) { py::arg() = Positions{}) .def("setTenGigaADCEnableMask", &Detector::setTenGigaADCEnableMask, py::arg(), py::arg() = Positions{}) - .def("getADCInvert", &Detector::getADCInvert, py::arg() = Positions{}) - .def("setADCInvert", &Detector::setADCInvert, py::arg(), + .def("getNumberOfDigitalSamples", &Detector::getNumberOfDigitalSamples, + py::arg() = Positions{}) + .def("setNumberOfDigitalSamples", &Detector::setNumberOfDigitalSamples, + py::arg(), py::arg() = Positions{}) + .def("getReadoutMode", &Detector::getReadoutMode, + py::arg() = Positions{}) + .def("setReadoutMode", &Detector::setReadoutMode, py::arg(), + py::arg() = Positions{}) + .def("getDBITClock", &Detector::getDBITClock, py::arg() = Positions{}) + .def("setDBITClock", &Detector::setDBITClock, py::arg(), + py::arg() = Positions{}) + .def("getDBITPipeline", &Detector::getDBITPipeline, + py::arg() = Positions{}) + .def("setDBITPipeline", &Detector::setDBITPipeline, py::arg(), + py::arg() = Positions{}) + .def("getMeasuredVoltage", &Detector::getMeasuredVoltage, py::arg(), + py::arg() = Positions{}) + .def("getMeasuredCurrent", &Detector::getMeasuredCurrent, py::arg(), + py::arg() = Positions{}) + .def("getSlowADC", &Detector::getSlowADC, py::arg(), py::arg() = Positions{}) .def("getExternalSamplingSource", &Detector::getExternalSamplingSource, py::arg() = Positions{}) @@ -627,6 +624,9 @@ void init_det(py::module &m) { py::arg(), py::arg() = Positions{}) .def("getInitialChecks", &Detector::getInitialChecks) .def("setInitialChecks", &Detector::setInitialChecks, py::arg()) + .def("getADCInvert", &Detector::getADCInvert, py::arg() = Positions{}) + .def("setADCInvert", &Detector::setADCInvert, py::arg(), + py::arg() = Positions{}) .def("getControlPort", &Detector::getControlPort, py::arg() = Positions{}) .def("setControlPort", &Detector::setControlPort, py::arg(), diff --git a/python/src/enums.cpp b/python/src/enums.cpp index 9b857aa79..ab5e36887 100644 --- a/python/src/enums.cpp +++ b/python/src/enums.cpp @@ -184,6 +184,11 @@ void init_enums(py::module &m) { .value("VB_PIXBUF", slsDetectorDefs::dacIndex::VB_PIXBUF) .value("VIN_COM", slsDetectorDefs::dacIndex::VIN_COM) .value("VDD_PROT", slsDetectorDefs::dacIndex::VDD_PROT) + .value("VBP_COLBUF", slsDetectorDefs::dacIndex::VBP_COLBUF) + .value("VB_SDA", slsDetectorDefs::dacIndex::VB_SDA) + .value("VCASC_SFP", slsDetectorDefs::dacIndex::VCASC_SFP) + .value("VIPRE_CDS", slsDetectorDefs::dacIndex::VIPRE_CDS) + .value("IBIAS_SFP", slsDetectorDefs::dacIndex::IBIAS_SFP) .value("V_POWER_A", slsDetectorDefs::dacIndex::V_POWER_A) .value("V_POWER_B", slsDetectorDefs::dacIndex::V_POWER_B) .value("V_POWER_C", slsDetectorDefs::dacIndex::V_POWER_C) @@ -224,6 +229,18 @@ void init_enums(py::module &m) { .value("FORCESWITCHG2", slsDetectorDefs::detectorSettings::FORCESWITCHG2) .value("VERYLOWGAIN", slsDetectorDefs::detectorSettings::VERYLOWGAIN) + .value("G1_HIGHGAIN", slsDetectorDefs::detectorSettings::G1_HIGHGAIN) + .value("G1_LOWGAIN", slsDetectorDefs::detectorSettings::G1_LOWGAIN) + .value("G2_HIGHCAP_HIGHGAIN", + slsDetectorDefs::detectorSettings::G2_HIGHCAP_HIGHGAIN) + .value("G2_HIGHCAP_LOWGAIN", + slsDetectorDefs::detectorSettings::G2_HIGHCAP_LOWGAIN) + .value("G2_LOWCAP_HIGHGAIN", + slsDetectorDefs::detectorSettings::G2_LOWCAP_HIGHGAIN) + .value("G2_LOWCAP_LOWGAIN", + slsDetectorDefs::detectorSettings::G2_LOWCAP_LOWGAIN) + .value("G4_HIGHGAIN", slsDetectorDefs::detectorSettings::G4_HIGHGAIN) + .value("G4_LOWGAIN", slsDetectorDefs::detectorSettings::G4_LOWGAIN) .value("UNDEFINED", slsDetectorDefs::detectorSettings::UNDEFINED) .value("UNINITIALIZED", slsDetectorDefs::detectorSettings::UNINITIALIZED) diff --git a/python/src/network.cpp b/python/src/network.cpp index 000e84e16..c1b3bdc45 100644 --- a/python/src/network.cpp +++ b/python/src/network.cpp @@ -15,10 +15,11 @@ using sls::IpAddr; using sls::MacAddr; void init_network(py::module &m) { - py::class_ IpAddr(m, "IpAddr"); - IpAddr.def(py::init()) + py::class_ (m, "IpAddr") + .def(py::init()) .def(py::init()) .def(py::init()) + .def(py::init()) .def("hex", &IpAddr::hex) .def("uint32", &IpAddr::uint32) .def(py::self == py::self) @@ -26,10 +27,11 @@ void init_network(py::module &m) { .def("str", &IpAddr::str); - py::class_ MacAddr(m, "MacAddr"); - MacAddr.def(py::init()) + py::class_ (m, "MacAddr") + .def(py::init()) .def(py::init()) .def(py::init()) + .def(py::init()) .def("hex", &MacAddr::hex) .def(py::self == py::self) .def("uint64", &MacAddr::uint64) diff --git a/slsDetectorGui/src/qDrawPlot.cpp b/slsDetectorGui/src/qDrawPlot.cpp index c0c135a5b..3e79ba211 100644 --- a/slsDetectorGui/src/qDrawPlot.cpp +++ b/slsDetectorGui/src/qDrawPlot.cpp @@ -365,15 +365,18 @@ double qDrawPlot::GetYMaximum() { void qDrawPlot::SetDataCallBack(bool enable) { LOG(logINFO) << "Setting data call back to " << std::boolalpha << enable << std::noboolalpha; - if (enable) { - isPlot = true; - det->setRxZmqDataStream(true); - det->registerDataCallback(&(GetDataCallBack), this); - } else { - isPlot = false; - det->setRxZmqDataStream(false); - det->registerDataCallback(nullptr, this); - } + try { + if (enable) { + isPlot = true; + det->registerDataCallback(&(GetDataCallBack), this); + det->setRxZmqDataStream(true); + } else { + isPlot = false; + det->registerDataCallback(nullptr, this); + det->setRxZmqDataStream(false); + } + } CATCH_DISPLAY("Could not get set rxr data streaming enable.", + "qDrawPlot::SetDataCallBack") } void qDrawPlot::SetBinary(bool enable, int from, int to) { diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index a141bd7c3..d9a607edf 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -771,6 +771,83 @@ std::vector CmdProxy::DacCommands() { /* acquisition */ /* Network Configuration (Detector<->Receiver) */ + +std::string CmdProxy::UDPDestinationIP(int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == defs::HELP_ACTION) { + os << "[x.x.x.x] or auto\n\tIp address of the receiver (destination) udp interface. If 'auto' used, then ip is set to ip of rx_hostname." + << '\n'; + } else if (action == defs::GET_ACTION) { + auto t = det->getDestinationUDPIP({det_id}); + if (args.size() != 0) { + WrongNumberOfParameters(0); + } + os << OutString(t) << '\n'; + } else if (action == defs::PUT_ACTION) { + if (args.size() != 1) { + WrongNumberOfParameters(1); + } + if (args[0] == "auto") { + std::string rxHostname = det->getRxHostname({det_id}).squash("none"); + // Hostname could be ip try to decode otherwise look up the hostname + auto val = sls::IpAddr{rxHostname}; + if (val == 0) { + val = HostnameToIp(rxHostname.c_str()); + } + LOG(logINFO) << "Setting udp_dstip of detector " << + det_id << " to " << val; + det->setDestinationUDPIP(val, {det_id}); + os << val << '\n'; + } else { + auto val = IpAddr(args[0]); + det->setDestinationUDPIP(val, {det_id}); + os << args.front() << '\n'; + } + } else { + throw sls::RuntimeError("Unknown action"); + } + return os.str(); +} + +std::string CmdProxy::UDPDestinationIP2(int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == defs::HELP_ACTION) { + os << "[x.x.x.x] or auto\n\t[Jungfrau] Ip address of the receiver (destination) udp interface where the second half of detector data is sent to. If 'auto' used, then ip is set to ip of rx_hostname." + << '\n'; + } else if (action == defs::GET_ACTION) { + auto t = det->getDestinationUDPIP2({det_id}); + if (args.size() != 0) { + WrongNumberOfParameters(0); + } + os << OutString(t) << '\n'; + } else if (action == defs::PUT_ACTION) { + if (args.size() != 1) { + WrongNumberOfParameters(1); + } + if (args[0] == "auto") { + std::string rxHostname = det->getRxHostname({det_id}).squash("none"); + // Hostname could be ip try to decode otherwise look up the hostname + auto val = sls::IpAddr{rxHostname}; + if (val == 0) { + val = HostnameToIp(rxHostname.c_str()); + } + LOG(logINFO) << "Setting udp_dstip2 of detector " << + det_id << " to " << val; + det->setDestinationUDPIP2(val, {det_id}); + os << val << '\n'; + } else { + auto val = IpAddr(args[0]); + det->setDestinationUDPIP2(val, {det_id}); + os << args.front() << '\n'; + } + } else { + throw sls::RuntimeError("Unknown action"); + } + return os.str(); +} + /* Receiver Config */ /* File */ /* ZMQ Streaming Parameters (Receiver<->Client) */ diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index 57ecacd35..ca4c50a31 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -705,8 +705,8 @@ class CmdProxy { {"selinterface", &CmdProxy::selinterface}, {"udp_srcip", &CmdProxy::udp_srcip}, {"udp_srcip2", &CmdProxy::udp_srcip2}, - {"udp_dstip", &CmdProxy::udp_dstip}, - {"udp_dstip2", &CmdProxy::udp_dstip2}, + {"udp_dstip", &CmdProxy::UDPDestinationIP}, + {"udp_dstip2", &CmdProxy::UDPDestinationIP2}, {"udp_srcmac", &CmdProxy::udp_srcmac}, {"udp_srcmac2", &CmdProxy::udp_srcmac2}, {"udp_dstmac", &CmdProxy::udp_dstmac}, @@ -934,9 +934,10 @@ class CmdProxy { std::string DacList(int action); std::string DacValues(int action); std::vector DacCommands(); - std::string OnChipDac(int action); /* acquisition */ /* Network Configuration (Detector<->Receiver) */ + std::string UDPDestinationIP(int action); + std::string UDPDestinationIP2(int action); /* Receiver Config */ /* File */ /* ZMQ Streaming Parameters (Receiver<->Client) */ @@ -1394,12 +1395,6 @@ class CmdProxy { INTEGER_COMMAND(udp_srcip2, getSourceUDPIP2, setSourceUDPIP2, IpAddr, "[x.x.x.x]\n\t[Jungfrau] Ip address of the bottom half of detector (source) udp interface. Must be same subnet as destination udp ip2."); - INTEGER_COMMAND(udp_dstip, getDestinationUDPIP, setDestinationUDPIP, IpAddr, - "[x.x.x.x]\n\tIp address of the receiver (destination) udp interface."); - - INTEGER_COMMAND(udp_dstip2, getDestinationUDPIP2, setDestinationUDPIP2, IpAddr, - "[x.x.x.x]\n\t[Jungfrau] Ip address of the receiver (destination) udp interface where the second half of detector data is sent to."); - INTEGER_COMMAND(udp_srcmac, getSourceUDPMAC, setSourceUDPMAC, MacAddr, "[x:x:x:x:x:x]\n\tMac address of the detector (source) udp interface. "); @@ -1407,10 +1402,10 @@ class CmdProxy { "[x:x:x:x:x:x]\n\t[Jungfrau] Mac address of the bottom half of detector (source) udp interface. "); INTEGER_COMMAND(udp_dstmac, getDestinationUDPMAC, setDestinationUDPMAC, MacAddr, - "[x:x:x:x:x:x]\n\tMac address of the receiver (destination) udp interface. Can be unused as rx_hostname/udp_dstip retrieves it."); + "[x:x:x:x:x:x]\n\tMac address of the receiver (destination) udp interface. Can be unused as udp_dstip retrieves it."); INTEGER_COMMAND(udp_dstmac2, getDestinationUDPMAC2, setDestinationUDPMAC2, MacAddr, - "[x:x:x:x:x:x]\n\t[Jungfrau] Mac address of the receiver (destination) udp interface where the second half of detector data is sent to. Can be unused as rx_hostname/udp_dstip2 retrieves it."); + "[x:x:x:x:x:x]\n\t[Jungfrau] Mac address of the receiver (destination) udp interface where the second half of detector data is sent to. Can be unused as udp_dstip2 retrieves it."); INTEGER_COMMAND(udp_dstport, getDestinationUDPPort, setDestinationUDPPort, std::stoi, "[n]\n\tPort number of the receiver (destination) udp interface. Default is 50001."); @@ -1440,7 +1435,7 @@ class CmdProxy { /* Receiver Config */ STRING_COMMAND(rx_hostname, getRxHostname, setRxHostname, - "[hostname or ip address]\n\tReceiver hostname or IP. Used for TCP control communication between client and receiver to configure receiver."); + "[hostname or ip address]\n\tReceiver hostname or IP. Used for TCP control communication between client and receiver to configure receiver. Also updates receiver with detector parameters."); INTEGER_COMMAND(rx_tcpport, getRxPort, setRxPort, std::stoi, "[port]\n\tTCP port for client-receiver communication. Default is 1954. Must be different if multiple receivers on same pc. Must be first command to set a receiver parameter. Multi command will automatically increment for individual modules."); @@ -1544,7 +1539,7 @@ class CmdProxy { "[0, 1]\n\t[Eiger] Enable or disable store in ram mode."); INTEGER_COMMAND(flippeddatax, getBottom, setBottom, std::stoi, - "[0, 1]\n\t[Eiger] Top or Bottom Half of Eiger module. 1 is bottom, 0 is top. Used to let Receiver and Gui know to flip the bottom image over the x axis."); + "[0, 1]\n\t[Eiger] Top or Bottom Half of Eiger module. 1 is bottom, 0 is top. Used to let Receivers and Gui know to flip the bottom image over the x axis. Files are not written without the flip however."); INTEGER_COMMAND(trimval, getAllTrimbits, setAllTrimbits, std::stoi, "[n_trimval]\n\t[Eiger] All trimbits set to this value. A get returns -1 if all trimbits are different values."); @@ -1727,7 +1722,7 @@ class CmdProxy { /* Moench */ STRING_COMMAND(rx_jsonaddheader, getAdditionalJsonHeader, setAdditionalJsonHeader, - "[\"label1\":\"value1\"], [\"label2\":\"value2\"]\n\tAdditional json header to be streamd out from receiver via zmq. Default is empty. Use only if to be processed by an intermediate user process listening to receiver zmq packets."); + "[\\\"label1\\\":\\\"value1\\\"], [\\\"label2\\\":\\\"value2\\\"]\n\tAdditional json header to be streamd out from receiver via zmq. Default is empty. Use only if to be processed by an intermediate user process listening to receiver zmq packets."); INTEGER_COMMAND(framemode, getFrameMode, setFrameMode, sls::StringTo, "[pedestal|newpedestal|flatfield|newflatfield]\n\t[Moench] Frame mode (soft setting) in processor."); diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 0ea4c02bb..09982fef9 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -470,8 +470,17 @@ Result Detector::getNumberofUDPInterfaces(Positions pos) const { void Detector::setNumberofUDPInterfaces(int n, Positions pos) { int previouslyClientStreaming = pimpl->enableDataStreamingToClient(); - bool previouslyReceiverStreaming = getRxZmqDataStream(pos).squash(true); + bool useReceiver = getUseReceiverFlag().squash(false); + bool previouslyReceiverStreaming = false; + if (useReceiver) { + previouslyReceiverStreaming = getRxZmqDataStream(pos).squash(true); + } pimpl->Parallel(&Module::setNumberofUDPInterfaces, pos, n); + // ensure receiver zmq socket ports are multiplied by 2 (2 interfaces) + if (getUseReceiverFlag().squash(false) && size()) { + int startingPort = getRxZmqPort({0}).squash(0); + setRxZmqPort(startingPort, -1); + } // redo the zmq sockets if enabled if (previouslyClientStreaming != 0) { pimpl->enableDataStreamingToClient(0); @@ -675,18 +684,16 @@ void Detector::setRxFifoDepth(int nframes, Positions pos) { } Result Detector::getRxSilentMode(Positions pos) const { - return pimpl->Parallel(&Module::setReceiverSilentMode, pos, -1); + return pimpl->Parallel(&Module::getReceiverSilentMode, pos); } void Detector::setRxSilentMode(bool value, Positions pos) { - pimpl->Parallel(&Module::setReceiverSilentMode, pos, - static_cast(value)); + pimpl->Parallel(&Module::setReceiverSilentMode, pos, value); } Result Detector::getRxFrameDiscardPolicy(Positions pos) const { - return pimpl->Parallel(&Module::setReceiverFramesDiscardPolicy, pos, - defs::GET_FRAME_DISCARD_POLICY); + return pimpl->Parallel(&Module::getReceiverFramesDiscardPolicy, pos); } void Detector::setRxFrameDiscardPolicy(defs::frameDiscardPolicy f, @@ -797,18 +804,15 @@ void Detector::setFramesPerFile(int n, Positions pos) { // Zmq Streaming (Receiver<->Client) Result Detector::getRxZmqDataStream(Positions pos) const { - return pimpl->Parallel(&Module::enableDataStreamingFromReceiver, pos, - -1); + return pimpl->Parallel(&Module::getReceiverStreaming, pos); } void Detector::setRxZmqDataStream(bool value, Positions pos) { - pimpl->Parallel(&Module::enableDataStreamingFromReceiver, pos, - static_cast(value)); + pimpl->Parallel(&Module::setReceiverStreaming, pos, value); } Result Detector::getRxZmqFrequency(Positions pos) const { - return pimpl->Parallel(&Module::setReceiverStreamingFrequency, pos, - -1); + return pimpl->Parallel(&Module::getReceiverStreamingFrequency, pos); } void Detector::setRxZmqFrequency(int freq, Positions pos) { @@ -969,8 +973,7 @@ Result Detector::getBottom(Positions pos) const { } void Detector::setBottom(bool value, Positions pos) { - pimpl->Parallel(&Module::setFlippedDataX, pos, - static_cast(value)); + pimpl->Parallel(&Module::setFlippedDataX, pos, value); } Result Detector::getAllTrimbits(Positions pos) const { @@ -1034,12 +1037,11 @@ void Detector::setActive(bool active, Positions pos) { } Result Detector::getRxPadDeactivatedMode(Positions pos) const { - return pimpl->Parallel(&Module::setDeactivatedRxrPaddingMode, pos, -1); + return pimpl->Parallel(&Module::getDeactivatedRxrPaddingMode, pos); } void Detector::setRxPadDeactivatedMode(bool pad, Positions pos) { - pimpl->Parallel(&Module::setDeactivatedRxrPaddingMode, pos, - static_cast(pad)); + pimpl->Parallel(&Module::setDeactivatedRxrPaddingMode, pos, pad); } Result Detector::getPartialReset(Positions pos) const { diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index a50cb4df3..fbcc0e198 100755 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -407,55 +407,10 @@ void Module::initializeDetectorStructure(detectorType type) { sls::strcpy_safe(shm()->rxHostname, "none"); shm()->rxTCPPort = DEFAULT_PORTNO + 2; shm()->useReceiverFlag = false; - shm()->flippedDataX = false; shm()->zmqport = DEFAULT_ZMQ_CL_PORTNO + (detId * ((shm()->myDetectorType == EIGER) ? 2 : 1)); - shm()->rxZmqport = DEFAULT_ZMQ_RX_PORTNO + - (detId * ((shm()->myDetectorType == EIGER) ? 2 : 1)); - shm()->rxUpstream = false; - shm()->rxReadFreq = 1; shm()->zmqip = IpAddr{}; - shm()->rxZmqip = IpAddr{}; shm()->gappixels = 0U; - memset(shm()->rxAdditionalJsonHeader, 0, MAX_STR_LENGTH); - shm()->rxFrameDiscardMode = NO_DISCARD; - shm()->rxFramePadding = true; - shm()->activated = true; - shm()->rxPadDeactivatedModules = true; - shm()->rxSilentMode = false; - sls::strcpy_safe(shm()->rxFilePath, "/"); - sls::strcpy_safe(shm()->rxFileName, "run"); - shm()->rxFileIndex = 0; - shm()->rxFileFormat = BINARY; - switch (shm()->myDetectorType) { - case GOTTHARD: - shm()->rxFramesPerFile = MAX_FRAMES_PER_FILE; - break; - case EIGER: - shm()->rxFramesPerFile = EIGER_MAX_FRAMES_PER_FILE; - break; - case JUNGFRAU: - shm()->rxFramesPerFile = JFRAU_MAX_FRAMES_PER_FILE; - break; - case CHIPTESTBOARD: - shm()->rxFramesPerFile = CTB_MAX_FRAMES_PER_FILE; - break; - case MOENCH: - shm()->rxFramesPerFile = MOENCH_MAX_FRAMES_PER_FILE; - break; - case MYTHEN3: - shm()->rxFramesPerFile = MYTHEN3_MAX_FRAMES_PER_FILE; - break; - case GOTTHARD2: - shm()->rxFramesPerFile = GOTTHARD2_MAX_FRAMES_PER_FILE; - break; - default: - break; - } - shm()->rxFileWrite = true; - shm()->rxMasterFileWrite = true; - shm()->rxFileOverWrite = true; - shm()->rxDbitOffset = 0; shm()->numUDPInterfaces = 1; shm()->stoppedFlag = false; @@ -1163,7 +1118,9 @@ void Module::startAcquisition() { void Module::stopAcquisition() { // get status before stopping acquisition runStatus s = ERROR, r = ERROR; - if (shm()->rxUpstream) { + bool zmqstreaming = false; + if (shm()->useReceiverFlag && getReceiverStreaming()) { + zmqstreaming = true; s = getRunStatus(); r = getReceiverStatus(); } @@ -1172,7 +1129,7 @@ void Module::stopAcquisition() { shm()->stoppedFlag = true; LOG(logDEBUG1) << "Stopping Acquisition successful"; // if rxr streaming and acquisition finished, restream dummy stop packet - if ((shm()->rxUpstream) && (s == IDLE) && (r == IDLE)) { + if (zmqstreaming && (s == IDLE) && (r == IDLE)) { restreamStopFromReceiver(); } } @@ -1744,16 +1701,6 @@ std::string Module::setReceiverHostname(const std::string &receiverIP) { LOG(logDEBUG1) << printReceiverConfiguration(); setReceiverUDPSocketBufferSize(0); - setFilePath(shm()->rxFilePath); - setFileName(shm()->rxFileName); - setFileIndex(shm()->rxFileIndex); - setFileFormat(shm()->rxFileFormat); - setFramesPerFile(shm()->rxFramesPerFile); - setReceiverFramesDiscardPolicy(shm()->rxFrameDiscardMode); - setPartialFramesPadding(shm()->rxFramePadding); - setFileWrite(shm()->rxFileWrite); - setMasterFileWrite(shm()->rxMasterFileWrite); - setFileOverWrite(shm()->rxFileOverWrite); sendTotalNumFramestoReceiver(); setExptime(getExptime()); setPeriod(getPeriod()); @@ -1765,10 +1712,7 @@ std::string Module::setReceiverHostname(const std::string &receiverIP) { setSubExptime(getSubExptime()); setSubDeadTime(getSubDeadTime()); setDynamicRange(shm()->dynamicRange); - setFlippedDataX(-1); activate(-1); - setDeactivatedRxrPaddingMode( - static_cast(shm()->rxPadDeactivatedModules)); enableGapPixels(shm()->gappixels); enableTenGigabitEthernet(-1); setQuad(getQuad()); @@ -1781,8 +1725,6 @@ std::string Module::setReceiverHostname(const std::string &receiverIP) { setReadoutMode(getReadoutMode()); setADCEnableMask(getADCEnableMask()); setTenGigaADCEnableMask(getTenGigaADCEnableMask()); - setReceiverDbitOffset(shm()->rxDbitOffset); - setReceiverDbitList(shm()->rxDbitList); break; case MOENCH: @@ -1805,14 +1747,8 @@ std::string Module::setReceiverHostname(const std::string &receiverIP) { break; } - setReceiverSilentMode(static_cast(shm()->rxSilentMode)); - // data streaming - setReceiverStreamingFrequency(shm()->rxReadFreq); - setReceiverStreamingPort(getReceiverStreamingPort()); + // to use rx_hostname if empty and also update client zmqip updateReceiverStreamingIP(); - setAdditionalJsonHeader(shm()->rxAdditionalJsonHeader); - enableDataStreamingFromReceiver( - static_cast(enableDataStreamingFromReceiver(-1))); } return std::string(shm()->rxHostname); @@ -1897,7 +1833,7 @@ void Module::setDestinationUDPIP(const IpAddr ip) { if (shm()->useReceiverFlag) { sls::MacAddr retval(0LU); sendToReceiver(F_SET_RECEIVER_UDP_IP, ip, retval); - LOG(logINFO) << "Setting destination udp mac to " << retval; + LOG(logINFO) << "Setting destination udp mac of detector " << detId << " to " << retval; sendToDetector(F_SET_DEST_UDP_MAC, retval, nullptr); } } @@ -1912,15 +1848,9 @@ sls::IpAddr Module::getDestinationUDPIP() { void Module::updateRxDestinationUDPIP() { auto ip = getDestinationUDPIP(); - if (ip == 0) { - // Hostname could be ip try to decode otherwise look up the hostname - ip = sls::IpAddr{shm()->rxHostname}; - if (ip == 0) { - ip = HostnameToIp(shm()->rxHostname); - } - LOG(logINFO) << "Setting destination default udp ip to " << ip; + if (ip != 0) { + setDestinationUDPIP(ip); } - setDestinationUDPIP(ip); } void Module::setDestinationUDPIP2(const IpAddr ip) { @@ -1933,7 +1863,7 @@ void Module::setDestinationUDPIP2(const IpAddr ip) { if (shm()->useReceiverFlag) { sls::MacAddr retval(0LU); sendToReceiver(F_SET_RECEIVER_UDP_IP2, ip, retval); - LOG(logINFO) << "Setting destination udp mac2 to " << retval; + LOG(logINFO) << "Setting destination udp mac2 of detector " << detId << " to " << retval; sendToDetector(F_SET_DEST_UDP_MAC2, retval, nullptr); } } @@ -1948,15 +1878,9 @@ sls::IpAddr Module::getDestinationUDPIP2() { void Module::updateRxDestinationUDPIP2() { auto ip = getDestinationUDPIP2(); - if (ip == 0) { - // Hostname could be ip try to decode otherwise look up the hostname - ip = sls::IpAddr{shm()->rxHostname}; - if (ip == 0) { - ip = HostnameToIp(shm()->rxHostname); - } - LOG(logINFO) << "Setting destination default udp ip2 to " << ip; + if (ip != 0) { + setDestinationUDPIP2(ip); } - setDestinationUDPIP2(ip); } void Module::setDestinationUDPMAC(const MacAddr mac) { @@ -2067,16 +1991,18 @@ void Module::setClientStreamingPort(int port) { shm()->zmqport = port; } int Module::getClientStreamingPort() { return shm()->zmqport; } void Module::setReceiverStreamingPort(int port) { - if (shm()->useReceiverFlag) { - auto retval = sendToReceiver(F_SET_RECEIVER_STREAMING_PORT, port); - LOG(logDEBUG1) << "Receiver streaming port: " << retval; - shm()->rxZmqport = retval; - } else { - shm()->rxZmqport = port; - } + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (zmq port)"); + } + sendToReceiver(F_SET_RECEIVER_STREAMING_PORT, port, nullptr); } -int Module::getReceiverStreamingPort() { return shm()->rxZmqport; } +int Module::getReceiverStreamingPort() { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to get receiver parameters (zmq port)"); + } + return sendToReceiver(F_GET_RECEIVER_STREAMING_PORT); +} void Module::setClientStreamingIP(const sls::IpAddr ip) { LOG(logDEBUG1) << "Setting client zmq ip to " << ip; @@ -2089,29 +2015,25 @@ void Module::setClientStreamingIP(const sls::IpAddr ip) { sls::IpAddr Module::getClientStreamingIP() { return shm()->zmqip; } void Module::setReceiverStreamingIP(const sls::IpAddr ip) { - LOG(logDEBUG1) << "Setting rx zmq ip to " << ip; + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (streaming ip)"); + } if (ip == 0) { throw RuntimeError("Invalid receiver zmq ip address"); } - - // if zmqip is empty, update it + + // if client zmqip is empty, update it if (shm()->zmqip == 0) { shm()->zmqip = ip; } - - // send to receiver - if (shm()->useReceiverFlag) { - LOG(logDEBUG1) - << "Sending receiver streaming IP to receiver: " << ip; - sendToReceiver(F_RECEIVER_STREAMING_SRC_IP, ip, nullptr); - shm()->rxZmqip = ip; - } else { - shm()->rxZmqip = ip; - } + sendToReceiver(F_SET_RECEIVER_STREAMING_SRC_IP, ip, nullptr); } sls::IpAddr Module::getReceiverStreamingIP() { - return shm()->rxZmqip; + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (streaming ip)"); + } + return sendToReceiver(F_GET_RECEIVER_STREAMING_SRC_IP); } void Module::updateReceiverStreamingIP() { @@ -2122,12 +2044,11 @@ void Module::updateReceiverStreamingIP() { if (ip == 0) { ip = HostnameToIp(shm()->rxHostname); } - LOG(logINFO) << "Setting default receiver streaming zmq ip to " << ip; + LOG(logINFO) << "Setting default receiver " << detId << " streaming zmq ip to " << ip; } setReceiverStreamingIP(ip); } - bool Module::getTenGigaFlowControl() { int retval = -1; sendToDetector(F_GET_TEN_GIGA_FLOW_CONTROL, nullptr, retval); @@ -2178,36 +2099,22 @@ void Module::setTransmissionDelayRight(int value) { } -std::string -Module::setAdditionalJsonHeader(const std::string &jsonheader) { - int fnum = F_ADDITIONAL_JSON_HEADER; +void Module::setAdditionalJsonHeader(const std::string &jsonheader) { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (zmq json header)"); + } char args[MAX_STR_LENGTH]{}; - char retvals[MAX_STR_LENGTH]{}; sls::strcpy_safe(args, jsonheader.c_str()); - LOG(logDEBUG1) << "Sending additional json header " << args; - - if (shm()->useReceiverFlag) { - sendToReceiver(fnum, args, retvals); - LOG(logDEBUG1) << "Additional json header: " << retvals; - memset(shm()->rxAdditionalJsonHeader, 0, MAX_STR_LENGTH); - sls::strcpy_safe(shm()->rxAdditionalJsonHeader, retvals); - } else { - sls::strcpy_safe(shm()->rxAdditionalJsonHeader, jsonheader.c_str()); - } - return shm()->rxAdditionalJsonHeader; + sendToReceiver(F_SET_ADDITIONAL_JSON_HEADER, args, nullptr); } std::string Module::getAdditionalJsonHeader() { - int fnum = F_GET_ADDITIONAL_JSON_HEADER; + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (zmq json header)"); + } char retvals[MAX_STR_LENGTH]{}; - LOG(logDEBUG1) << "Getting additional json header "; - if (shm()->useReceiverFlag) { - sendToReceiver(fnum, nullptr, retvals); - LOG(logDEBUG1) << "Additional json header: " << retvals; - memset(shm()->rxAdditionalJsonHeader, 0, MAX_STR_LENGTH); - sls::strcpy_safe(shm()->rxAdditionalJsonHeader, retvals); - } - return std::string(shm()->rxAdditionalJsonHeader); + sendToReceiver(F_GET_ADDITIONAL_JSON_HEADER, nullptr, retvals); + return std::string(retvals); } std::string Module::setAdditionalJsonParameter(const std::string &key, @@ -2239,7 +2146,7 @@ std::string Module::setAdditionalJsonParameter(const std::string &key, valueLiteral.append("\""); } - std::string header(shm()->rxAdditionalJsonHeader); + std::string header = getAdditionalJsonHeader(); size_t keyPos = header.find(keyLiteral); // if key found, replace value @@ -2267,8 +2174,9 @@ std::string Module::setAdditionalJsonParameter(const std::string &key, std::string Module::getAdditionalJsonParameter(const std::string &key) { // additional json header is empty - if (strlen(shm()->rxAdditionalJsonHeader) == 0U) - return std::string(); + std::string jsonheader = getAdditionalJsonHeader(); + if (jsonheader.empty()) + return jsonheader; // add quotations before and after the key value std::string keyLiteral = key; @@ -2277,7 +2185,7 @@ std::string Module::getAdditionalJsonParameter(const std::string &key) { // loop through the parameters for (const auto ¶meter : - sls::split(shm()->rxAdditionalJsonHeader, ',')) { + sls::split(jsonheader, ',')) { // get a vector of key value pair for each parameter const auto &pairs = sls::split(parameter, ':'); // match for key @@ -2652,6 +2560,10 @@ int Module::setExternalSampling(int value) { int Module::getExternalSampling() { return setExternalSampling(-1); } void Module::setReceiverDbitList(const std::vector& list) { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (dbit list)"); + } + LOG(logDEBUG1) << "Setting Receiver Dbit List"; if (list.size() > 64) { @@ -2664,39 +2576,31 @@ void Module::setReceiverDbitList(const std::vector& list) { } } sls::FixedCapacityContainer arg = list; - if (shm()->useReceiverFlag) { - sendToReceiver(F_SET_RECEIVER_DBIT_LIST, arg, nullptr); - shm()->rxDbitList = list; - } else { - shm()->rxDbitList = list; - } + sendToReceiver(F_SET_RECEIVER_DBIT_LIST, arg, nullptr); } std::vector Module::getReceiverDbitList() const { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (dbit list)"); + } sls::FixedCapacityContainer retval; - LOG(logDEBUG1) << "Getting Receiver Dbit List"; - if (shm()->useReceiverFlag) { - sendToReceiver(F_GET_RECEIVER_DBIT_LIST, nullptr, retval); - shm()->rxDbitList = retval; - } - return shm()->rxDbitList; + sendToReceiver(F_GET_RECEIVER_DBIT_LIST, nullptr, retval); + return retval; } -int Module::setReceiverDbitOffset(int value) { - int retval = -1; - LOG(logDEBUG1) << "Setting digital bit offset in receiver to " - << value; - if (shm()->useReceiverFlag) { - sendToReceiver(F_RECEIVER_DBIT_OFFSET, value, retval); - LOG(logDEBUG1) << "Receiver digital bit offset: " << retval; - shm()->rxDbitOffset = value; - } else { - shm()->rxDbitOffset = value; - } - return shm()->rxDbitOffset; +void Module::setReceiverDbitOffset(int value) { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (dbit offset)"); + } + sendToReceiver(F_SET_RECEIVER_DBIT_OFFSET, value, nullptr); } -int Module::getReceiverDbitOffset() { return shm()->rxDbitOffset; } +int Module::getReceiverDbitOffset() { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (dbit offset)"); + } + return sendToReceiver(F_GET_RECEIVER_DBIT_OFFSET); +} void Module::writeAdcRegister(uint32_t addr, uint32_t val) { uint32_t args[]{addr, val}; @@ -2711,48 +2615,47 @@ int Module::activate(int enable) { sendToDetector(F_ACTIVATE, enable, retval); sendToDetectorStop(F_ACTIVATE, enable, retval); LOG(logDEBUG1) << "Activate: " << retval; - shm()->activated = static_cast(retval); if (shm()->useReceiverFlag) { - int fnum = F_RECEIVER_ACTIVATE; - enable = static_cast(shm()->activated); - retval = -1; - LOG(logDEBUG1) - << "Setting activate flag " << enable << " to receiver"; - sendToReceiver(fnum, enable, retval); + sendToReceiver(F_RECEIVER_ACTIVATE, retval, nullptr); } - return static_cast(shm()->activated); + return retval; } -bool Module::setDeactivatedRxrPaddingMode(int padding) { - int fnum = F_RECEIVER_DEACTIVATED_PADDING_ENABLE; - int retval = -1; - LOG(logDEBUG1) << "Deactivated Receiver Padding Enable: " << padding; - if (shm()->useReceiverFlag) { - sendToReceiver(fnum, padding, retval); - LOG(logDEBUG1) << "Deactivated Receiver Padding Enable:" << retval; - shm()->rxPadDeactivatedModules = static_cast(retval); - } else { - shm()->rxPadDeactivatedModules = padding; - } - return shm()->rxPadDeactivatedModules; +bool Module::getDeactivatedRxrPaddingMode() { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (deactivated padding)"); + } + return sendToReceiver(F_GET_RECEIVER_DEACTIVATED_PADDING); } -bool Module::getFlippedDataX() const { return shm()->flippedDataX; } +void Module::setDeactivatedRxrPaddingMode(bool padding) { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (deactivated padding)"); + } + int arg = static_cast(padding); + sendToReceiver(F_SET_RECEIVER_DEACTIVATED_PADDING, arg, nullptr); +} -void Module::setFlippedDataX(int value) { - // replace get with shm value (write to shm right away as it is a det value, - // not rx value) - if (value > -1) { - shm()->flippedDataX = (value > 0); +bool Module::getFlippedDataX() { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (flipped data x)"); } int retval = -1; - int arg = static_cast(shm()->flippedDataX); + int arg = -1; + sendToReceiver(F_SET_FLIPPED_DATA_RECEIVER, arg, retval); + LOG(logDEBUG1) << "Flipped data:" << retval; + return retval; +} + +void Module::setFlippedDataX(bool value) { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (flipped data x)"); + } + int retval = -1; + int arg = static_cast(value); LOG(logDEBUG1) << "Setting flipped data across x axis with value: " - << arg; - if (shm()->useReceiverFlag) { - sendToReceiver(F_SET_FLIPPED_DATA_RECEIVER, arg, retval); - LOG(logDEBUG1) << "Flipped data:" << retval; - } + << value; + sendToReceiver(F_SET_FLIPPED_DATA_RECEIVER, arg, retval); } int Module::setAllTrimbits(int val) { @@ -3184,101 +3087,16 @@ void Module::updateCachedReceiverVariables() const { sls::ClientSocket("Receiver", shm()->rxHostname, shm()->rxTCPPort); receiver.sendCommandThenRead(fnum, nullptr, 0, nullptr, 0); int n = 0, i32 = 0; - int64_t i64 = 0; - char cstring[MAX_STR_LENGTH]{}; IpAddr ip; n += receiver.Receive(&ip, sizeof(ip)); LOG(logDEBUG1) << "Updating receiver last modified by " << ip; - // filepath - n += receiver.Receive(cstring, sizeof(cstring)); - sls::strcpy_safe(shm()->rxFilePath, cstring); - - // filename - n += receiver.Receive(cstring, sizeof(cstring)); - sls::strcpy_safe(shm()->rxFileName, cstring); - - // index - n += receiver.Receive(&i64, sizeof(i64)); - shm()->rxFileIndex = i64; - - // file format - n += receiver.Receive(&i32, sizeof(i32)); - shm()->rxFileFormat = static_cast(i32); - - // frames per file - n += receiver.Receive(&i32, sizeof(i32)); - shm()->rxFramesPerFile = i32; - - // frame discard policy - n += receiver.Receive(&i32, sizeof(i32)); - shm()->rxFrameDiscardMode = static_cast(i32); - - // frame padding - n += receiver.Receive(&i32, sizeof(i32)); - shm()->rxFramePadding = static_cast(i32); - - // file write enable - n += receiver.Receive(&i32, sizeof(i32)); - shm()->rxFileWrite = static_cast(i32); - - // master file write enable - n += receiver.Receive(&i32, sizeof(i32)); - shm()->rxMasterFileWrite = static_cast(i32); - - // file overwrite enable - n += receiver.Receive(&i32, sizeof(i32)); - shm()->rxFileOverWrite = static_cast(i32); - // gap pixels n += receiver.Receive(&i32, sizeof(i32)); shm()->gappixels = i32; - // receiver read frequency - n += receiver.Receive(&i32, sizeof(i32)); - shm()->rxReadFreq = i32; - - // receiver streaming port - n += receiver.Receive(&i32, sizeof(i32)); - shm()->rxZmqport = i32; - - // streaming source ip - n += receiver.Receive(&ip, sizeof(ip)); - shm()->rxZmqip = ip; - - // additional json header - n += receiver.Receive(cstring, sizeof(cstring)); - sls::strcpy_safe(shm()->rxAdditionalJsonHeader, cstring); - - // receiver streaming enable - n += receiver.Receive(&i32, sizeof(i32)); - shm()->rxUpstream = static_cast(i32); - - // activate - n += receiver.Receive(&i32, sizeof(i32)); - shm()->activated = static_cast(i32); - - // deactivated padding enable - n += receiver.Receive(&i32, sizeof(i32)); - shm()->rxPadDeactivatedModules = static_cast(i32); - - // silent mode - n += receiver.Receive(&i32, sizeof(i32)); - shm()->rxSilentMode = static_cast(i32); - - // dbit list - { - sls::FixedCapacityContainer temp; - n += receiver.Receive(&temp, sizeof(temp)); - shm()->rxDbitList = temp; - } - - // dbit offset - n += receiver.Receive(&i32, sizeof(i32)); - shm()->rxDbitOffset = i32; - if (n == 0) { throw RuntimeError( "Could not update receiver: " + std::string(shm()->rxHostname) + @@ -3319,137 +3137,128 @@ void Module::setDetectorHostname() { } } -std::string Module::getFilePath() { return shm()->rxFilePath; } - -std::string Module::setFilePath(const std::string &path) { - if (!path.empty()) { - char args[MAX_STR_LENGTH]{}; - char retvals[MAX_STR_LENGTH]{}; - sls::strcpy_safe(args, path.c_str()); - LOG(logDEBUG1) << "Sending file path to receiver: " << args; - if (shm()->useReceiverFlag) { - sendToReceiver(F_SET_RECEIVER_FILE_PATH, args, retvals); - LOG(logDEBUG1) << "Receiver file path: " << retvals; - sls::strcpy_safe(shm()->rxFilePath, retvals); - } else { - sls::strcpy_safe(shm()->rxFilePath, args); - } - } - return shm()->rxFilePath; +std::string Module::getFilePath() { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (file path)"); + } + char retvals[MAX_STR_LENGTH]{}; + sendToReceiver(F_GET_RECEIVER_FILE_PATH, nullptr, retvals); + return std::string(retvals); } -std::string Module::getFileName() { return shm()->rxFileName; } - -std::string Module::setFileName(const std::string &fname) { - if (!fname.empty()) { - char args[MAX_STR_LENGTH]{}; - char retvals[MAX_STR_LENGTH]{}; - sls::strcpy_safe(args, fname.c_str()); - LOG(logDEBUG1) << "Sending file name to receiver: " << args; - if (shm()->useReceiverFlag) { - sendToReceiver(F_SET_RECEIVER_FILE_NAME, args, retvals); - LOG(logDEBUG1) << "Receiver file name: " << retvals; - sls::strcpy_safe(shm()->rxFileName, retvals); - } else { - sls::strcpy_safe(shm()->rxFileName, args); - } +void Module::setFilePath(const std::string &path) { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (file path)"); + } + if (path.empty()) { + throw RuntimeError("Cannot set empty file path"); } - return shm()->rxFileName; + char args[MAX_STR_LENGTH]{}; + sls::strcpy_safe(args, path.c_str()); + sendToReceiver(F_SET_RECEIVER_FILE_PATH, args, nullptr); } -int Module::setFramesPerFile(int n_frames) { - if (n_frames >= 0) { - LOG(logDEBUG1) - << "Setting receiver frames per file to " << n_frames; - if (shm()->useReceiverFlag) { - int retval = -1; - sendToReceiver(F_SET_RECEIVER_FRAMES_PER_FILE, n_frames, retval); - LOG(logDEBUG1) << "Receiver frames per file: " << retval; - shm()->rxFramesPerFile = retval; - } else { - shm()->rxFramesPerFile = n_frames; - } - } - return getFramesPerFile(); +std::string Module::getFileName() { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (file name prefix)"); + } + char retvals[MAX_STR_LENGTH]{}; + sendToReceiver(F_GET_RECEIVER_FILE_NAME, nullptr, retvals); + return std::string(retvals); } -int Module::getFramesPerFile() const { return shm()->rxFramesPerFile; } +void Module::setFileName(const std::string &fname) { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (file name prefix)"); + } + if (fname.empty()) { + throw RuntimeError("Cannot set empty file name prefix"); + } + char args[MAX_STR_LENGTH]{}; + sls::strcpy_safe(args, fname.c_str()); + sendToReceiver(F_SET_RECEIVER_FILE_NAME, args, nullptr); +} -slsDetectorDefs::frameDiscardPolicy -Module::setReceiverFramesDiscardPolicy(frameDiscardPolicy f) { +int64_t Module::getFileIndex() { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (file index)"); + } + return sendToReceiver(F_GET_RECEIVER_FILE_INDEX); +} + +void Module::setFileIndex(int64_t file_index) { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (file index)"); + } + sendToReceiver(F_SET_RECEIVER_FILE_INDEX, file_index, nullptr); +} + +void Module::incrementFileIndex() { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (increment file index)"); + } + sendToReceiver(F_INCREMENT_FILE_INDEX, nullptr, nullptr); +} + +slsDetectorDefs::fileFormat Module::getFileFormat() { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (file format)"); + } + return static_cast( + sendToReceiver(F_GET_RECEIVER_FILE_FORMAT)); +} + +void Module::setFileFormat(fileFormat f) { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (file format)"); + } int arg = static_cast(f); - LOG(logDEBUG1) << "Setting receiver frames discard policy to " << arg; - if (shm()->useReceiverFlag) { - auto retval = static_cast(-1); - sendToReceiver(F_RECEIVER_DISCARD_POLICY, arg, retval); - LOG(logDEBUG1) << "Receiver frames discard policy: " << retval; - shm()->rxFrameDiscardMode = retval; - } else { - shm()->rxFrameDiscardMode = f; - } - return shm()->rxFrameDiscardMode; + sendToReceiver(F_SET_RECEIVER_FILE_FORMAT, arg, nullptr); } -bool Module::setPartialFramesPadding(bool padding) { +int Module::getFramesPerFile() { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (frames per file)"); + } + return sendToReceiver(F_GET_RECEIVER_FRAMES_PER_FILE); +} + +void Module::setFramesPerFile(int n_frames) { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (frames per file)"); + } + sendToReceiver(F_SET_RECEIVER_FRAMES_PER_FILE, n_frames, nullptr); +} + +slsDetectorDefs::frameDiscardPolicy Module::getReceiverFramesDiscardPolicy() { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (frame discard policy)"); + } + return static_cast( + sendToReceiver(F_GET_RECEIVER_DISCARD_POLICY)); +} + +void Module::setReceiverFramesDiscardPolicy(frameDiscardPolicy f) { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (frame discard policy)"); + } + int arg = static_cast(f); + sendToReceiver(F_SET_RECEIVER_DISCARD_POLICY, arg, nullptr); +} + +bool Module::getPartialFramesPadding() { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (frame padding)"); + } + return sendToReceiver(F_GET_RECEIVER_PADDING); +} + +void Module::setPartialFramesPadding(bool padding) { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (frame padding)"); + } int arg = static_cast(padding); - int retval = static_cast(padding); - LOG(logDEBUG1) << "Setting receiver partial frames enable to " << arg; - if (shm()->useReceiverFlag) { - sendToReceiver(F_RECEIVER_PADDING_ENABLE, arg, retval); - LOG(logDEBUG1) << "Receiver partial frames enable: " << retval; - shm()->rxFramePadding = static_cast(retval); - } else { - shm()->rxFramePadding = padding; - } - return getPartialFramesPadding(); -} - -bool Module::getPartialFramesPadding() const { - return shm()->rxFramePadding; -} - -slsDetectorDefs::fileFormat Module::setFileFormat(fileFormat f) { - if (f != GET_FILE_FORMAT) { - auto arg = static_cast(f); - auto retval = static_cast(-1); - LOG(logDEBUG1) << "Setting receiver file format to " << arg; - if (shm()->useReceiverFlag) { - sendToReceiver(F_SET_RECEIVER_FILE_FORMAT, arg, retval); - LOG(logDEBUG1) << "Receiver file format: " << retval; - shm()->rxFileFormat = retval; - } else { - shm()->rxFileFormat = f; - } - } - return getFileFormat(); -} - -slsDetectorDefs::fileFormat Module::getFileFormat() const { - return shm()->rxFileFormat; -} - -int64_t Module::setFileIndex(int64_t file_index) { - if (file_index >= 0) { - int64_t retval = -1; - LOG(logDEBUG1) << "Setting file index to " << file_index; - if (shm()->useReceiverFlag) { - sendToReceiver(F_SET_RECEIVER_FILE_INDEX, file_index, retval); - LOG(logDEBUG1) << "Receiver file index: " << retval; - shm()->rxFileIndex = retval; - } else { - shm()->rxFileIndex = file_index; - } - } - return getFileIndex(); -} - -int64_t Module::getFileIndex() const { return shm()->rxFileIndex; } - -int64_t Module::incrementFileIndex() { - if (shm()->rxFileWrite) { - return setFileIndex(shm()->rxFileIndex + 1); - } - return shm()->rxFileIndex; + sendToReceiver(F_SET_RECEIVER_PADDING, arg, nullptr); } void Module::startReceiver() { @@ -3527,70 +3336,66 @@ uint64_t Module::getReceiverCurrentFrameIndex() const { return retval; } -bool Module::setFileWrite(bool value) { +void Module::setFileWrite(bool value) { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (file write enable)"); + } int arg = static_cast(value); - int retval = -1; - LOG(logDEBUG1) << "Sending enable file write to receiver: " << arg; - if (shm()->useReceiverFlag) { - sendToReceiver(F_ENABLE_RECEIVER_FILE_WRITE, arg, retval); - LOG(logDEBUG1) << "Receiver file write enable: " << retval; - shm()->rxFileWrite = static_cast(retval); - } else { - shm()->rxFileWrite = value; - } - return getFileWrite(); + sendToReceiver(F_SET_RECEIVER_FILE_WRITE, arg, nullptr); } -bool Module::getFileWrite() const { return shm()->rxFileWrite; } +bool Module::getFileWrite() { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (file_write enable)"); + } + return sendToReceiver(F_GET_RECEIVER_FILE_WRITE); +} -bool Module::setMasterFileWrite(bool value) { +void Module::setMasterFileWrite(bool value) { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (master file write enable)"); + } int arg = static_cast(value); - int retval = -1; - LOG(logDEBUG1) << "Sending enable master file write to receiver: " - << arg; - if (shm()->useReceiverFlag) { - sendToReceiver(F_ENABLE_RECEIVER_MASTER_FILE_WRITE, arg, retval); - LOG(logDEBUG1) << "Receiver master file write enable: " << retval; - shm()->rxMasterFileWrite = static_cast(retval); - } else { - shm()->rxMasterFileWrite = value; - } - return getMasterFileWrite(); + sendToReceiver(F_SET_RECEIVER_MASTER_FILE_WRITE, arg, nullptr); } -bool Module::getMasterFileWrite() const { - return shm()->rxMasterFileWrite; +bool Module::getMasterFileWrite() { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (master file write enable)"); + } + return sendToReceiver(F_GET_RECEIVER_MASTER_FILE_WRITE); } -bool Module::setFileOverWrite(bool value) { +void Module::setFileOverWrite(bool value) { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (file overwrite enable)"); + } int arg = static_cast(value); - int retval = -1; - LOG(logDEBUG1) << "Sending enable file overwrite to receiver: " << arg; - if (shm()->useReceiverFlag) { - sendToReceiver(F_ENABLE_RECEIVER_OVERWRITE, arg, retval); - LOG(logDEBUG1) << "Receiver file overwrite enable: " << retval; - shm()->rxFileOverWrite = static_cast(retval); - } else { - shm()->rxFileOverWrite = value; - } - return getFileOverWrite(); + sendToReceiver(F_SET_RECEIVER_OVERWRITE, arg, nullptr); } -bool Module::getFileOverWrite() const { return shm()->rxFileOverWrite; } +bool Module::getFileOverWrite() { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (file overwrite enable)"); + } + return sendToReceiver(F_GET_RECEIVER_OVERWRITE); +} -int Module::setReceiverStreamingFrequency(int freq) { - if (freq >= 0) { - LOG(logDEBUG1) << "Sending read frequency to receiver: " << freq; - if (shm()->useReceiverFlag) { - int retval = -1; - sendToReceiver(F_RECEIVER_STREAMING_FREQUENCY, freq, retval); - LOG(logDEBUG1) << "Receiver read frequency: " << retval; - shm()->rxReadFreq = retval; - } else { - shm()->rxReadFreq = freq; - } +int Module::getReceiverStreamingFrequency() { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (streaming/read frequency)"); } - return shm()->rxReadFreq; + return sendToReceiver(F_GET_RECEIVER_STREAMING_FREQUENCY); +} + +void Module::setReceiverStreamingFrequency(int freq) { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (streaming/read frequency)"); + } + if (freq < 0) { + throw RuntimeError("Invalid streaming frequency " + std::to_string(freq)); + } + sendToReceiver(F_SET_RECEIVER_STREAMING_FREQUENCY, freq, nullptr); } int Module::setReceiverStreamingTimer(int time_in_ms) { @@ -3603,19 +3408,19 @@ int Module::setReceiverStreamingTimer(int time_in_ms) { return retval; } -bool Module::enableDataStreamingFromReceiver(int enable) { - if (enable >= 0) { - LOG(logDEBUG1) << "Sending Data Streaming to receiver: " << enable; - if (shm()->useReceiverFlag) { - int retval = -1; - sendToReceiver(F_STREAM_DATA_FROM_RECEIVER, enable, retval); - LOG(logDEBUG1) << "Receiver Data Streaming: " << retval; - shm()->rxUpstream = static_cast(retval); - } else { - shm()->rxUpstream = enable; - } +bool Module::getReceiverStreaming() { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to get receiver parameters (zmq enable)"); } - return shm()->rxUpstream; + return sendToReceiver(F_GET_RECEIVER_STREAMING); +} + +void Module::setReceiverStreaming(bool enable) { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (zmq enable)"); + } + int arg = static_cast(enable); + sendToReceiver(F_SET_RECEIVER_STREAMING, arg, nullptr); } bool Module::enableTenGigabitEthernet(int value) { @@ -3643,17 +3448,19 @@ int Module::setReceiverFifoDepth(int n_frames) { return retval; } -bool Module::setReceiverSilentMode(int value) { - LOG(logDEBUG1) << "Sending Receiver Silent Mode: " << value; - if (shm()->useReceiverFlag) { - int retval = -1; - sendToReceiver(F_SET_RECEIVER_SILENT_MODE, value, retval); - LOG(logDEBUG1) << "Receiver Data Streaming: " << retval; - shm()->rxSilentMode = static_cast(retval); - } else { - shm()->rxSilentMode = value; - } - return shm()->rxSilentMode; +bool Module::getReceiverSilentMode() { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (silent mode)"); + } + return sendToReceiver(F_GET_RECEIVER_SILENT_MODE); +} + +void Module::setReceiverSilentMode(bool enable) { + if (!shm()->useReceiverFlag) { + throw RuntimeError("Set rx_hostname first to use receiver parameters (silent mode)"); + } + int arg = static_cast(enable); + sendToReceiver(F_SET_RECEIVER_SILENT_MODE, arg, nullptr); } void Module::restreamStopFromReceiver() { diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index f8e39f375..1567c6165 100755 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -13,7 +13,7 @@ class ServerInterface; #define SLS_SHMAPIVERSION 0x190726 -#define SLS_SHMVERSION 0x200309 +#define SLS_SHMVERSION 0x200318 namespace sls{ @@ -98,81 +98,18 @@ struct sharedSlsDetector { * unset if socket connection is not possible */ bool useReceiverFlag; - /** flipped data across x or y axis */ - bool flippedDataX; - /** tcp port from gui/different process to receiver (only data) */ int zmqport; - /** tcp port from receiver to gui/different process (only data) */ - int rxZmqport; - - /** data streaming (up stream) enable in receiver - * (needed for restreaming dummy packet) */ - bool rxUpstream; - - /* Receiver read frequency */ - int rxReadFreq; - /** zmq tcp src ip address in client (only data) **/ sls::IpAddr zmqip; - /** zmq tcp src ip address in receiver (only data) **/ - sls::IpAddr rxZmqip; - /** gap pixels enable */ int gappixels; /** gap pixels in each direction */ slsDetectorDefs::xy nGappixels; - /** additional json header */ - char rxAdditionalJsonHeader[MAX_STR_LENGTH]; - - /** receiver frames discard policy */ - slsDetectorDefs::frameDiscardPolicy rxFrameDiscardMode; - - /** receiver partial frames padding enable */ - bool rxFramePadding; - - /** activated receiver */ - bool activated; - - /** padding enable in deactivated receiver */ - bool rxPadDeactivatedModules; - - /** silent receiver */ - bool rxSilentMode; - - /** path of the output files */ - char rxFilePath[MAX_STR_LENGTH]; - - /** file name prefix */ - char rxFileName[MAX_STR_LENGTH]; - - /** file index */ - int64_t rxFileIndex; - - /** file format */ - slsDetectorDefs::fileFormat rxFileFormat; - - /** frames per file */ - int rxFramesPerFile; - - /** file write enable */ - bool rxFileWrite; - - /** master file write enable */ - bool rxMasterFileWrite; - - /** overwrite enable */ - bool rxFileOverWrite; - - sls::FixedCapacityContainer rxDbitList; - - /** reciever dbit offset */ - int rxDbitOffset; - /** num udp interfaces */ int numUDPInterfaces; @@ -1054,10 +991,8 @@ class Module : public virtual slsDetectorDefs { /** * Sets the additional json header\sa sharedSlsDetector * @param jsonheader additional json header - * @returns additional json header, returns "none" if default setting and no - * custom ip set */ - std::string setAdditionalJsonHeader(const std::string &jsonheader); + void setAdditionalJsonHeader(const std::string &jsonheader); /** * Returns the additional json header \sa sharedSlsDetector @@ -1247,31 +1182,12 @@ class Module : public virtual slsDetectorDefs { */ int getExternalSampling(); - /** - * Set external sampling enable (CTB only) - * @param list external sampling source (Option: 0-63) - * @param detPos -1 for all detectors in list or specific detector position - */ + /** digital data bits enable (CTB only) */ void setReceiverDbitList(const std::vector& list); - - /** - * Get external sampling source (CTB only) - * @param detPos -1 for all detectors in list or specific detector position - * @returns external sampling enable - */ std::vector getReceiverDbitList() const; - /** - * Set digital data offset in bytes (CTB only) - * @param value digital data offset in bytes - * @returns digital data offset in bytes - */ - int setReceiverDbitOffset(int value); - - /** - * Get digital data offset in bytes (CTB only) - * @returns digital data offset in bytes - */ + /** Set digital data offset in bytes (CTB only) */ + void setReceiverDbitOffset(int value); int getReceiverDbitOffset(); /** @@ -1289,27 +1205,25 @@ class Module : public virtual slsDetectorDefs { */ int activate(int const enable = -1); + bool getDeactivatedRxrPaddingMode(); + /** * Set deactivated Receiver padding mode (Eiger only) - * @param padding padding option for deactivated receiver. Can be 1 - * (padding), 0 (no padding), -1 (gets) - * @returns 1 (padding), 0 (no padding), -1 (inconsistent values) for - * padding option */ - bool setDeactivatedRxrPaddingMode(int padding = -1); + void setDeactivatedRxrPaddingMode(bool padding); /** * Returns the enable if data will be flipped across x axis (Eiger) * @returns if flipped across x axis */ - bool getFlippedDataX() const; + bool getFlippedDataX(); /** * Sets the enable which determines if * data will be flipped across x axis (Eiger) - * @param value 0 or 1 to reset/set or -1 to get value + * @param value 0 or 1 to reset/set */ - void setFlippedDataX(int value = -1); + void setFlippedDataX(bool value); /** * Sets all the trimbits to a particular value (Eiger) @@ -1546,88 +1460,24 @@ class Module : public virtual slsDetectorDefs { */ void setDetectorHostname(); - /** - * Returns output file directory - * @returns output file directory - */ + std::string getFilePath(); - - /** - * Sets up the file directory - * @param s file directory - * @returns file dir - */ - std::string setFilePath(const std::string &path); - - /** - * Returns file name prefix - * @returns file name prefix - */ + void setFilePath(const std::string &path); std::string getFileName(); + void setFileName(const std::string &fname); + int64_t getFileIndex(); + void setFileIndex(int64_t file_index); + void incrementFileIndex(); + fileFormat getFileFormat() ; + void setFileFormat(fileFormat f); + int getFramesPerFile(); + /** 0 will set frames per file to unlimited */ + void setFramesPerFile(int n_frames); + frameDiscardPolicy getReceiverFramesDiscardPolicy(); + void setReceiverFramesDiscardPolicy(frameDiscardPolicy f); + bool getPartialFramesPadding(); + void setPartialFramesPadding(bool padding); - /** - * Sets up the file name prefix - * @param s file name prefix - * @returns file name prefix - */ - std::string setFileName(const std::string &fname); - - /** - * Sets the max frames per file in receiver - * @param f max frames per file - * @returns max frames per file in receiver - */ - int setFramesPerFile(int n_frames); - - int getFramesPerFile() const; - - /** - * Sets the frames discard policy in receiver - * @param f frames discard policy - * @returns frames discard policy set in receiver - */ - frameDiscardPolicy setReceiverFramesDiscardPolicy( - frameDiscardPolicy f = GET_FRAME_DISCARD_POLICY); - - /** - * Sets the partial frames padding enable in receiver - * @param f partial frames padding enable - * @returns partial frames padding enable in receiver - */ - bool setPartialFramesPadding(bool padding); - bool getPartialFramesPadding() const; - - /** - * Returns file format - * @returns file format - */ - fileFormat getFileFormat() const; - - /** - * Sets up the file format - * @param f file format - * @returns file format - */ - fileFormat setFileFormat(fileFormat f); - - /** - * Sets up the file index - * @param i file index - * @returns file index - */ - int64_t setFileIndex(int64_t file_index); - - /** - * Gets the file index - * @returns file index - */ - - int64_t getFileIndex() const; - /** - * increments file index - * @returns the file index - */ - int64_t incrementFileIndex(); /** * Receiver starts listening to packets @@ -1660,44 +1510,15 @@ class Module : public virtual slsDetectorDefs { */ uint64_t getReceiverCurrentFrameIndex() const; - /** - * Sets/Gets receiver file write enable - * @param enable 1 or 0 to set/reset file write enable - * @returns file write enable - */ - bool setFileWrite(bool value); - /** - * Gets file write enable - * @returns file write enable - */ - bool getFileWrite() const; + void setFileWrite(bool value); + bool getFileWrite(); + void setMasterFileWrite(bool value); + bool getMasterFileWrite(); + void setFileOverWrite(bool value); + bool getFileOverWrite(); - /** - * Sets/Gets receiver master file write enable - * @param value 1 or 0 to set/reset master file write enable - * @returns master file write enable - */ - bool setMasterFileWrite(bool value); - - /** - * Gets master file write enable - * @returns master file write enable - */ - bool getMasterFileWrite() const; - - /** - * Sets file overwrite in the receiver - * @param enable true or false to set/reset file overwrite enable - * @returns file overwrite enable - */ - bool setFileOverWrite(bool value); - - /** - * Gets file overwrite in the receiver - * @returns file overwrite enable - */ - bool getFileOverWrite() const; + int getReceiverStreamingFrequency(); /** * (previously setReadReceiverFrequency) @@ -1705,9 +1526,8 @@ class Module : public virtual slsDetectorDefs { * @param freq nth frame streamed out, if 0, streamed out at a timer of 200 * ms * @param detPos -1 for all detectors in list or specific detector position - * @returns receiver streaming frequency */ - int setReceiverStreamingFrequency(int freq = -1); + void setReceiverStreamingFrequency(int freq); /** * (previously setReceiverReadTimer) @@ -1719,12 +1539,9 @@ class Module : public virtual slsDetectorDefs { */ int setReceiverStreamingTimer(int time_in_ms = 200); - /** - * Enable or disable streaming data from receiver to client - * @param enable 0 to disable 1 to enable -1 to only get the value - * @returns data streaming from receiver enable - */ - bool enableDataStreamingFromReceiver(int enable = -1); + bool getReceiverStreaming(); + + void setReceiverStreaming(bool enable); /** * Enable/disable or 10Gbe @@ -1740,12 +1557,8 @@ class Module : public virtual slsDetectorDefs { */ int setReceiverFifoDepth(int n_frames = -1); - /** - * Set/get receiver silent mode - * @param i is -1 to get, 0 unsets silent mode, 1 sets silent mode - * @returns the receiver silent mode enable - */ - bool setReceiverSilentMode(int value = -1); + bool getReceiverSilentMode(); + void setReceiverSilentMode(bool enable); /** * If data streaming in receiver is enabled, diff --git a/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp b/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp index a15564970..6b70975b7 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp @@ -272,7 +272,7 @@ TEST_CASE("burstperiod", "[.cmd]") { REQUIRE(oss_set.str() == "burstperiod 30ms\n"); proxy.Call("burstperiod", {}, -1, GET, oss_get); REQUIRE(oss_get.str() == "burstperiod 30ms\n"); - // Reset all dacs to previous value + // Reset to previous value for (int i = 0; i != det.size(); ++i) { det.setBurstPeriod(previous[i], {i}); } diff --git a/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp b/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp index 553186b05..f47d95864 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp @@ -29,7 +29,7 @@ python/scripts/list_tested_cmd.py to check if all commands are covered // std::cout << "end\n"; // } -TEST_CASE("rx_hostname", "[.cmd]") { +TEST_CASE("rx_hostname", "[.cmd][.rx]") { // TODO! find a proper way to test, now we read out the rx_hostname // and then put it to see that we don't crash Detector det; @@ -72,7 +72,7 @@ TEST_CASE("rx_hostname", "[.cmd]") { } } -TEST_CASE("rx_framescaught", "[.cmd]") { +TEST_CASE("rx_framescaught", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); @@ -97,7 +97,7 @@ TEST_CASE("rx_framescaught", "[.cmd]") { // } } -TEST_CASE("rx_status", "[.cmd]") { +TEST_CASE("rx_status", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); std::ostringstream oss; @@ -105,7 +105,7 @@ TEST_CASE("rx_status", "[.cmd]") { REQUIRE(oss.str() == "rx_status idle\n"); } -TEST_CASE("rx_version", "[.cmd]") { +TEST_CASE("rx_version", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); std::ostringstream oss; @@ -115,7 +115,7 @@ TEST_CASE("rx_version", "[.cmd]") { REQUIRE(oss.str() == vs.str()); } -TEST_CASE("rx_start", "[.cmd]") { +TEST_CASE("rx_start", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); // PUT only command @@ -132,7 +132,7 @@ TEST_CASE("rx_start", "[.cmd]") { } } -TEST_CASE("rx_stop", "[.cmd]") { +TEST_CASE("rx_stop", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); // PUT only command @@ -149,7 +149,7 @@ TEST_CASE("rx_stop", "[.cmd]") { } } -TEST_CASE("rx_missingpackets", "[.cmd]") { +TEST_CASE("rx_missingpackets", "[.cmd][.rx]") { // TODO! This only tests for no crash how can we test // for correct values? Detector det; @@ -157,7 +157,7 @@ TEST_CASE("rx_missingpackets", "[.cmd]") { proxy.Call("rx_missingpackets", {}, -1, GET); } -TEST_CASE("rx_frameindex", "[.cmd]") { +TEST_CASE("rx_frameindex", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); proxy.Call("rx_frameindex", {}, -1, GET); @@ -166,7 +166,7 @@ TEST_CASE("rx_frameindex", "[.cmd]") { REQUIRE_THROWS(proxy.Call("rx_frameindex", {"2"}, -1, PUT)); } -TEST_CASE("rx_lastclient", "[.cmd]") { +TEST_CASE("rx_lastclient", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); std::ostringstream oss; @@ -174,13 +174,13 @@ TEST_CASE("rx_lastclient", "[.cmd]") { REQUIRE(oss.str() == "rx_lastclient " + test::my_ip + "\n"); } -TEST_CASE("rx_printconfig", "[.cmd]") { +TEST_CASE("rx_printconfig", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); proxy.Call("rx_printconfig", {}, -1, GET); } -TEST_CASE("rx_fifodepth", "[.cmd]") { +TEST_CASE("rx_fifodepth", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); int prev_val = det.getRxFifoDepth().squash(); @@ -203,7 +203,7 @@ TEST_CASE("rx_fifodepth", "[.cmd]") { det.setRxFifoDepth(prev_val); } -TEST_CASE("rx_silent", "[.cmd]") { +TEST_CASE("rx_silent", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); { @@ -223,7 +223,7 @@ TEST_CASE("rx_silent", "[.cmd]") { } } -TEST_CASE("rx_jsonaddheader", "[.cmd]") { +TEST_CASE("rx_jsonaddheader", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); @@ -244,7 +244,7 @@ TEST_CASE("rx_jsonaddheader", "[.cmd]") { } } -TEST_CASE("rx_udpsocksize", "[.cmd]") { +TEST_CASE("rx_udpsocksize", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); { @@ -259,7 +259,7 @@ TEST_CASE("rx_udpsocksize", "[.cmd]") { } } -TEST_CASE("rx_realudpsocksize", "[.cmd]") { +TEST_CASE("rx_realudpsocksize", "[.cmd][.rx]") { // TODO! Is the real socket size always twice? Detector det; CmdProxy proxy(&det); @@ -279,7 +279,7 @@ TEST_CASE("rx_realudpsocksize", "[.cmd]") { } } -TEST_CASE("rx_framesperfile", "[.cmd]") { +TEST_CASE("rx_framesperfile", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); { @@ -299,7 +299,7 @@ TEST_CASE("rx_framesperfile", "[.cmd]") { } } -TEST_CASE("rx_discardpolicy", "[.cmd]") { +TEST_CASE("rx_discardpolicy", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); { @@ -324,7 +324,7 @@ TEST_CASE("rx_discardpolicy", "[.cmd]") { } } -TEST_CASE("rx_padding", "[.cmd]") { +TEST_CASE("rx_padding", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); { @@ -344,7 +344,7 @@ TEST_CASE("rx_padding", "[.cmd]") { } } -TEST_CASE("rx_readfreq", "[.cmd]") { +TEST_CASE("rx_readfreq", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); { @@ -364,7 +364,7 @@ TEST_CASE("rx_readfreq", "[.cmd]") { } } -TEST_CASE("rx_lock", "[.cmd]") { +TEST_CASE("rx_lock", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); { @@ -384,7 +384,7 @@ TEST_CASE("rx_lock", "[.cmd]") { } } -TEST_CASE("rx_zmqport", "[.cmd]") { +TEST_CASE("rx_zmqport", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); int socketsperdetector = 1; @@ -419,7 +419,7 @@ TEST_CASE("rx_zmqport", "[.cmd]") { } } -TEST_CASE("rx_datastream", "[.cmd]") { +TEST_CASE("rx_datastream", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); { @@ -441,7 +441,7 @@ TEST_CASE("rx_datastream", "[.cmd]") { } } -TEST_CASE("rx_tcpport", "[.cmd]") { +TEST_CASE("rx_tcpport", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); @@ -463,7 +463,7 @@ TEST_CASE("rx_tcpport", "[.cmd]") { } } -TEST_CASE("rx_zmqip", "[.cmd]") { +TEST_CASE("rx_zmqip", "[.cmd][.rx]") { Detector det; CmdProxy proxy(&det); { @@ -479,3 +479,67 @@ TEST_CASE("rx_zmqip", "[.cmd]") { } } +TEST_CASE("rx_dbitoffset", "[.cmd][.rx]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::CHIPTESTBOARD) { + auto previous = det.getRxDbitOffset(); + { + std::ostringstream oss; + proxy.Call("rx_dbitoffset", {"1"}, -1, PUT, oss); + REQUIRE(oss.str() == "rx_dbitoffset 1\n"); + } + { + std::ostringstream oss; + proxy.Call("rx_dbitoffset", {"0"}, -1, PUT, oss); + REQUIRE(oss.str() == "rx_dbitoffset 0\n"); + } + { + std::ostringstream oss; + proxy.Call("rx_dbitoffset", {"15"}, -1, PUT, oss); + REQUIRE(oss.str() == "rx_dbitoffset 15\n"); + } + { + std::ostringstream oss; + proxy.Call("rx_dbitoffset", {}, -1, GET, oss); + REQUIRE(oss.str() == "rx_dbitoffset 15\n"); + } + // Reset to previous value + for (int i = 0; i != det.size(); ++i) { + det.setRxDbitOffset(previous[i], {i}); + } + } else { + REQUIRE_THROWS(proxy.Call("rx_dbitoffset", {}, -1, GET)); + } +} + + + +TEST_CASE("rx_dbitlist", "[.cmd][.rx]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::CHIPTESTBOARD) { + auto previous = det.getRxDbitList(); + { + std::ostringstream oss; + proxy.Call("rx_dbitlist", {"0", "4", "5", "8", "9", "10", "52", "63"}, -1, PUT, oss); + REQUIRE(oss.str() == "rx_dbitlist [0, 4, 5, 8, 9, 10, 52, 63]\n"); + } + { + std::ostringstream oss; + proxy.Call("rx_dbitlist", {}, -1, GET, oss); + REQUIRE(oss.str() == "rx_dbitlist [0, 4, 5, 8, 9, 10, 52, 63]\n"); + } + REQUIRE_THROWS(proxy.Call("rx_dbitlist", {"67"}, -1, PUT)); + REQUIRE_THROWS(proxy.Call("rx_dbitlist", {"-1"}, -1, PUT)); + REQUIRE_NOTHROW(proxy.Call("rx_dbitlist", {"all"}, -1, PUT)); + // Reset to previous value + for (int i = 0; i != det.size(); ++i) { + det.setRxDbitList(previous[i], {i}); + } + } else { + REQUIRE_THROWS(proxy.Call("rx_dbitlist", {}, -1, GET)); + } +} \ No newline at end of file diff --git a/slsDetectorSoftware/tests/test-CmdProxy.cpp b/slsDetectorSoftware/tests/test-CmdProxy.cpp index 05837569a..a43b47381 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy.cpp @@ -709,54 +709,6 @@ TEST_CASE("stopport", "[.cmd]") { // } // } -// TEST_CASE("rx_dbitoffset", "[.cmd][.ctb]") { -// if (test::type == slsDetectorDefs::CHIPTESTBOARD) { -// { -// std::ostringstream oss; -// REQUIRE_NOTHROW(multiSlsDetectorClient("rx_dbitoffset 1", PUT, -// nullptr, oss)); REQUIRE(oss.str() == "rx_dbitoffset 1\n"); -// } -// { -// std::ostringstream oss; -// REQUIRE_NOTHROW(multiSlsDetectorClient("rx_dbitoffset 0", PUT, -// nullptr, oss)); REQUIRE(oss.str() == "rx_dbitoffset 0\n"); -// } -// { -// std::ostringstream oss; -// REQUIRE_NOTHROW(multiSlsDetectorClient("rx_dbitoffset 15", PUT, -// nullptr, oss)); REQUIRE(oss.str() == "rx_dbitoffset 15\n"); -// } -// { -// std::ostringstream oss; -// REQUIRE_NOTHROW(multiSlsDetectorClient("rx_dbitoffset", GET, -// nullptr, oss)); REQUIRE(oss.str() == "rx_dbitoffset 15\n"); -// } -// REQUIRE_NOTHROW(multiSlsDetectorClient("rx_dbitoffset 0", PUT)); -// } else { -// std::ostringstream oss; -// REQUIRE_NOTHROW(multiSlsDetectorClient("rx_dbitoffset", GET, -// nullptr, oss)); REQUIRE(oss.str() == "rx_dbitoffset 0\n"); -// } -// } - -// TEST_CASE("rx_dbitlist", "[.cmd][.ctb]") { -// if (test::type == slsDetectorDefs::CHIPTESTBOARD) { -// REQUIRE_NOTHROW(multiSlsDetectorClient("rx_dbitlist 0 4 5 8 9 10 52 -// 63", PUT)); -// { -// std::ostringstream oss; -// REQUIRE_NOTHROW(multiSlsDetectorClient("0:rx_dbitlist", GET, -// nullptr, oss)); REQUIRE(oss.str() == "rx_dbitlist [0, 4, 5, 8, 9, -// 10, 52, 63]\n"); -// } -// REQUIRE_NOTHROW(multiSlsDetectorClient("rx_dbitlist all", PUT)); -// } else { -// std::ostringstream oss; -// REQUIRE_NOTHROW(multiSlsDetectorClient("rx_dbitlist", GET, nullptr, -// oss)); REQUIRE(oss.str() == "rx_dbitlist []\n"); -// } -// } - // TEST_CASE("extsampling", "[.cmd][.ctb]") { // if (test::type == slsDetectorDefs::CHIPTESTBOARD) { // { diff --git a/slsReceiverSoftware/src/ClientInterface.cpp b/slsReceiverSoftware/src/ClientInterface.cpp index e287e0f3c..6fe9aed6b 100755 --- a/slsReceiverSoftware/src/ClientInterface.cpp +++ b/slsReceiverSoftware/src/ClientInterface.cpp @@ -126,47 +126,64 @@ int ClientInterface::functionTable(){ flist[F_RECEIVER_SET_SUB_EXPTIME] = &ClientInterface::set_subexptime; flist[F_RECEIVER_SET_SUB_DEADTIME] = &ClientInterface::set_subdeadtime; flist[F_SET_RECEIVER_DYNAMIC_RANGE] = &ClientInterface::set_dynamic_range; - flist[F_RECEIVER_STREAMING_FREQUENCY] = &ClientInterface::set_streaming_frequency; + flist[F_SET_RECEIVER_STREAMING_FREQUENCY] = &ClientInterface::set_streaming_frequency; + flist[F_GET_RECEIVER_STREAMING_FREQUENCY] = &ClientInterface::get_streaming_frequency; flist[F_GET_RECEIVER_STATUS] = &ClientInterface::get_status; flist[F_START_RECEIVER] = &ClientInterface::start_receiver; flist[F_STOP_RECEIVER] = &ClientInterface::stop_receiver; flist[F_SET_RECEIVER_FILE_PATH] = &ClientInterface::set_file_dir; + flist[F_GET_RECEIVER_FILE_PATH] = &ClientInterface::get_file_dir; flist[F_SET_RECEIVER_FILE_NAME] = &ClientInterface::set_file_name; + flist[F_GET_RECEIVER_FILE_NAME] = &ClientInterface::get_file_name; flist[F_SET_RECEIVER_FILE_INDEX] = &ClientInterface::set_file_index; + flist[F_GET_RECEIVER_FILE_INDEX] = &ClientInterface::get_file_index; flist[F_GET_RECEIVER_FRAME_INDEX] = &ClientInterface::get_frame_index; flist[F_GET_RECEIVER_FRAMES_CAUGHT] = &ClientInterface::get_frames_caught; flist[F_GET_NUM_MISSING_PACKETS] = &ClientInterface::get_missing_packets; - flist[F_ENABLE_RECEIVER_FILE_WRITE] = &ClientInterface::enable_file_write; - flist[F_ENABLE_RECEIVER_MASTER_FILE_WRITE] = &ClientInterface::enable_master_file_write; - flist[F_ENABLE_RECEIVER_OVERWRITE] = &ClientInterface::enable_overwrite; + flist[F_SET_RECEIVER_FILE_WRITE] = &ClientInterface::set_file_write; + flist[F_GET_RECEIVER_FILE_WRITE] = &ClientInterface::get_file_write; + flist[F_SET_RECEIVER_MASTER_FILE_WRITE] = &ClientInterface::set_master_file_write; + flist[F_GET_RECEIVER_MASTER_FILE_WRITE] = &ClientInterface::get_master_file_write; + flist[F_SET_RECEIVER_OVERWRITE] = &ClientInterface::set_overwrite; + flist[F_GET_RECEIVER_OVERWRITE] = &ClientInterface::get_overwrite; flist[F_ENABLE_RECEIVER_TEN_GIGA] = &ClientInterface::enable_tengiga; flist[F_SET_RECEIVER_FIFO_DEPTH] = &ClientInterface::set_fifo_depth; flist[F_RECEIVER_ACTIVATE] = &ClientInterface::set_activate; - flist[F_STREAM_DATA_FROM_RECEIVER] = &ClientInterface::set_data_stream_enable; + flist[F_SET_RECEIVER_STREAMING] = &ClientInterface::set_streaming; + flist[F_GET_RECEIVER_STREAMING] = &ClientInterface::get_streaming; flist[F_RECEIVER_STREAMING_TIMER] = &ClientInterface::set_streaming_timer; flist[F_SET_FLIPPED_DATA_RECEIVER] = &ClientInterface::set_flipped_data; flist[F_SET_RECEIVER_FILE_FORMAT] = &ClientInterface::set_file_format; + flist[F_GET_RECEIVER_FILE_FORMAT] = &ClientInterface::get_file_format; flist[F_SEND_RECEIVER_DETPOSID] = &ClientInterface::set_detector_posid; flist[F_SEND_RECEIVER_MULTIDETSIZE] = &ClientInterface::set_multi_detector_size; flist[F_SET_RECEIVER_STREAMING_PORT] = &ClientInterface::set_streaming_port; - flist[F_RECEIVER_STREAMING_SRC_IP] = &ClientInterface::set_streaming_source_ip; + flist[F_GET_RECEIVER_STREAMING_PORT] = &ClientInterface::get_streaming_port; + flist[F_SET_RECEIVER_STREAMING_SRC_IP] = &ClientInterface::set_streaming_source_ip; + flist[F_GET_RECEIVER_STREAMING_SRC_IP] = &ClientInterface::get_streaming_source_ip; flist[F_SET_RECEIVER_SILENT_MODE] = &ClientInterface::set_silent_mode; + flist[F_GET_RECEIVER_SILENT_MODE] = &ClientInterface::get_silent_mode; flist[F_ENABLE_GAPPIXELS_IN_RECEIVER] = &ClientInterface::enable_gap_pixels; flist[F_RESTREAM_STOP_FROM_RECEIVER] = &ClientInterface::restream_stop; - flist[F_ADDITIONAL_JSON_HEADER] = &ClientInterface::set_additional_json_header; + flist[F_SET_ADDITIONAL_JSON_HEADER] = &ClientInterface::set_additional_json_header; flist[F_GET_ADDITIONAL_JSON_HEADER] = &ClientInterface::get_additional_json_header; flist[F_RECEIVER_UDP_SOCK_BUF_SIZE] = &ClientInterface::set_udp_socket_buffer_size; flist[F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE]= &ClientInterface::get_real_udp_socket_buffer_size; flist[F_SET_RECEIVER_FRAMES_PER_FILE] = &ClientInterface::set_frames_per_file; + flist[F_GET_RECEIVER_FRAMES_PER_FILE] = &ClientInterface::get_frames_per_file; flist[F_RECEIVER_CHECK_VERSION] = &ClientInterface::check_version_compatibility; - flist[F_RECEIVER_DISCARD_POLICY] = &ClientInterface::set_discard_policy; - flist[F_RECEIVER_PADDING_ENABLE] = &ClientInterface::set_padding_enable; - flist[F_RECEIVER_DEACTIVATED_PADDING_ENABLE] = &ClientInterface::set_deactivated_padding_enable; + flist[F_SET_RECEIVER_DISCARD_POLICY] = &ClientInterface::set_discard_policy; + flist[F_GET_RECEIVER_DISCARD_POLICY] = &ClientInterface::get_discard_policy; + flist[F_SET_RECEIVER_PADDING] = &ClientInterface::set_padding_enable; + flist[F_GET_RECEIVER_PADDING] = &ClientInterface::get_padding_enable; + flist[F_SET_RECEIVER_DEACTIVATED_PADDING] = &ClientInterface::set_deactivated_padding_enable; + flist[F_GET_RECEIVER_DEACTIVATED_PADDING] = &ClientInterface::get_deactivated_padding_enable; flist[F_RECEIVER_SET_READOUT_MODE] = &ClientInterface::set_readout_mode; flist[F_RECEIVER_SET_ADC_MASK] = &ClientInterface::set_adc_mask; flist[F_SET_RECEIVER_DBIT_LIST] = &ClientInterface::set_dbit_list; flist[F_GET_RECEIVER_DBIT_LIST] = &ClientInterface::get_dbit_list; - flist[F_RECEIVER_DBIT_OFFSET] = &ClientInterface::set_dbit_offset; + flist[F_SET_RECEIVER_DBIT_OFFSET] = &ClientInterface::set_dbit_offset; + flist[F_GET_RECEIVER_DBIT_OFFSET] = &ClientInterface::get_dbit_offset; flist[F_SET_RECEIVER_QUAD] = &ClientInterface::set_quad_type; flist[F_SET_RECEIVER_READ_N_LINES] = &ClientInterface::set_read_n_lines; flist[F_SET_RECEIVER_UDP_IP] = &ClientInterface::set_udp_ip; @@ -176,6 +193,7 @@ int ClientInterface::functionTable(){ flist[F_SET_RECEIVER_NUM_INTERFACES] = &ClientInterface::set_num_interfaces; flist[F_RECEIVER_SET_ADC_MASK_10G] = &ClientInterface::set_adc_mask_10g; flist[F_RECEIVER_SET_NUM_COUNTERS] = &ClientInterface::set_num_counters; + flist[F_INCREMENT_FILE_INDEX] = &ClientInterface::increment_file_index; for (int i = NUM_DET_FUNCTIONS + 1; i < NUM_REC_FUNCTIONS ; i++) { LOG(logDEBUG1) << "function fnum: " << i << " (" << @@ -318,103 +336,15 @@ int ClientInterface::update_client(Interface &socket) { int ClientInterface::send_update(Interface &socket) { int n = 0; int i32 = -1; - int64_t i64 = -1; - char cstring[MAX_STR_LENGTH]{}; sls::IpAddr ip; ip = server->getLastClient(); n += socket.Send(&ip, sizeof(ip)); - // filepath - sls::strcpy_safe(cstring, receiver->getFilePath().c_str()); - n += socket.Send(cstring, sizeof(cstring)); - - // filename - sls::strcpy_safe(cstring, receiver->getFileName().c_str()); - n += socket.Send(cstring, sizeof(cstring)); - - // index - i64 = receiver->getFileIndex(); - n += socket.Send(&i64, sizeof(i64)); - - // file format - i32 = (int)receiver->getFileFormat(); - n += socket.Send(&i32, sizeof(i32)); - - // frames per file - i32 = (int)receiver->getFramesPerFile(); - n += socket.Send(&i32, sizeof(i32)); - - // frame discard policy - i32 = (int)receiver->getFrameDiscardPolicy(); - n += socket.Send(&i32, sizeof(i32)); - - // frame padding - i32 = (int)receiver->getFramePaddingEnable(); - n += socket.Send(&i32, sizeof(i32)); - - // file write enable - i32 = (int)receiver->getFileWriteEnable(); - n += socket.Send(&i32, sizeof(i32)); - - // master file write enable - i32 = (int)receiver->getMasterFileWriteEnable(); - n += socket.Send(&i32, sizeof(i32)); - - // file overwrite enable - i32 = (int)receiver->getOverwriteEnable(); - n += socket.Send(&i32, sizeof(i32)); - // gap pixels i32 = (int)receiver->getGapPixelsEnable(); n += socket.Send(&i32, sizeof(i32)); - // streaming frequency - i32 = (int)receiver->getStreamingFrequency(); - n += socket.Send(&i32, sizeof(i32)); - - // streaming port - i32 = (int)receiver->getStreamingPort(); - n += socket.Send(&i32, sizeof(i32)); - - // streaming source ip - ip = receiver->getStreamingSourceIP(); - n += socket.Send(&ip, sizeof(ip)); - - // additional json header - sls::strcpy_safe(cstring, receiver->getAdditionalJsonHeader().c_str()); - n += socket.Send(cstring, sizeof(cstring)); - - // data streaming enable - i32 = (int)receiver->getDataStreamEnable(); - n += socket.Send(&i32, sizeof(i32)); - - // activate - i32 = (int)receiver->getActivate(); - n += socket.Send(&i32, sizeof(i32)); - - // deactivated padding enable - i32 = (int)receiver->getDeactivatedPadding(); - n += socket.Send(&i32, sizeof(i32)); - - // silent mode - i32 = (int)receiver->getSilentMode(); - n += socket.Send(&i32, sizeof(i32)); - - // dbit list - { - std::vector list = receiver->getDbitList(); - int retvalsize = list.size(); - int retval[retvalsize]; - std::copy(std::begin(list), std::end(list), retval); - socket.Send(&retvalsize, sizeof(retvalsize)); - socket.Send(retval, sizeof(retval)); - } - - // dbit offset - i32 = receiver->getDbitOffset(); - n += socket.Send(&i32, sizeof(i32)); - return OK; } @@ -614,13 +544,22 @@ int ClientInterface::set_dynamic_range(Interface &socket) { int ClientInterface::set_streaming_frequency(Interface &socket) { auto index = socket.Receive(); - if (index >= 0) { - verifyIdle(socket); - LOG(logDEBUG1) << "Setting streaming frequency: " << index; - impl()->setStreamingFrequency(index); + if (index < 0) { + throw RuntimeError("Invalid streaming frequency: " + + std::to_string(index)); } + verifyIdle(socket); + LOG(logDEBUG1) << "Setting streaming frequency: " << index; + impl()->setStreamingFrequency(index); + int retval = impl()->getStreamingFrequency(); validate(index, retval, "set streaming frequency", DEC); + return socket.Send(OK); +} + +int ClientInterface::get_streaming_frequency(Interface &socket) { + int retval = impl()->getStreamingFrequency(); + LOG(logDEBUG1) << "streaming freq:" << retval; return socket.sendResult(retval); } @@ -658,12 +597,14 @@ int ClientInterface::set_file_dir(Interface &socket) { char retval[MAX_STR_LENGTH]{}; socket.Receive(fPath); - if (strlen(fPath) != 0) { - LOG(logDEBUG1) << "Setting file path: " << fPath; - if(fPath[0] != '/') - throw RuntimeError("Receiver path needs to be absolute path"); - impl()->setFilePath(fPath); + if (strlen(fPath) == 0) { + throw RuntimeError("Cannot set empty file path"); } + if(fPath[0] != '/') + throw RuntimeError("Receiver path needs to be absolute path"); + LOG(logDEBUG1) << "Setting file path: " << fPath; + impl()->setFilePath(fPath); + std::string s = impl()->getFilePath(); sls::strcpy_safe(retval, s.c_str()); if ((s.empty()) || (strlen(fPath) && strcasecmp(fPath, retval))) @@ -671,6 +612,14 @@ int ClientInterface::set_file_dir(Interface &socket) { else LOG(logDEBUG1) << "file path:" << retval; + return socket.Send(OK); +} + +int ClientInterface::get_file_dir(Interface &socket) { + char retval[MAX_STR_LENGTH]{}; + std::string s = impl()->getFilePath(); + sls::strcpy_safe(retval, s.c_str()); + LOG(logDEBUG1) << "file path:" << retval; return socket.sendResult(retval); } @@ -678,14 +627,21 @@ int ClientInterface::set_file_name(Interface &socket) { char fName[MAX_STR_LENGTH]{}; char retval[MAX_STR_LENGTH]{}; socket.Receive(fName); - if (strlen(fName) != 0) { - LOG(logDEBUG1) << "Setting file name: " << fName; - impl()->setFileName(fName); + if (strlen(fName) == 0) { + throw RuntimeError("Cannot set empty file name"); } + LOG(logDEBUG1) << "Setting file name: " << fName; + impl()->setFileName(fName); + std::string s = impl()->getFileName(); - if (s.empty()) - throw RuntimeError("file name is empty"); + sls::strcpy_safe(retval, s.c_str()); + LOG(logDEBUG1) << "file name:" << retval; + return socket.Send(OK); +} +int ClientInterface::get_file_name(Interface &socket) { + char retval[MAX_STR_LENGTH]{}; + std::string s = impl()->getFileName(); sls::strcpy_safe(retval, s.c_str()); LOG(logDEBUG1) << "file name:" << retval; return socket.sendResult(retval); @@ -693,14 +649,23 @@ int ClientInterface::set_file_name(Interface &socket) { int ClientInterface::set_file_index(Interface &socket) { auto index = socket.Receive(); - if (index >= 0) { - verifyIdle(socket); - LOG(logDEBUG1) << "Setting file index: " << index; - impl()->setFileIndex(index); + if (index < 0) { + throw RuntimeError("Invalid file index: " + + std::to_string(index)); } + verifyIdle(socket); + LOG(logDEBUG1) << "Setting file index: " << index; + impl()->setFileIndex(index); + int64_t retval = impl()->getFileIndex(); validate(index, retval, "set file index", DEC); LOG(logDEBUG1) << "file index:" << retval; + return socket.Send(OK); +} + +int ClientInterface::get_file_index(Interface &socket) { + int64_t retval = impl()->getFileIndex(); + LOG(logDEBUG1) << "file index:" << retval; return socket.sendResult(retval); } @@ -728,42 +693,68 @@ int ClientInterface::get_frames_caught(Interface &socket) { return socket.sendResult(retval); } -int ClientInterface::enable_file_write(Interface &socket) { +int ClientInterface::set_file_write(Interface &socket) { auto enable = socket.Receive(); - if (enable >= 0) { - verifyIdle(socket); - LOG(logDEBUG1) << "Setting File write enable:" << enable; - impl()->setFileWriteEnable(enable); + if (enable < 0) { + throw RuntimeError("Invalid file write enable: " + std::to_string(enable)); } + verifyIdle(socket); + LOG(logDEBUG1) << "Setting File write enable:" << enable; + impl()->setFileWriteEnable(enable); + int retval = impl()->getFileWriteEnable(); validate(enable, retval, "set file write enable", DEC); LOG(logDEBUG1) << "file write enable:" << retval; + return socket.Send(OK); +} + +int ClientInterface::get_file_write(Interface &socket) { + int retval = impl()->getFileWriteEnable(); + LOG(logDEBUG1) << "file write enable:" << retval; return socket.sendResult(retval); } -int ClientInterface::enable_master_file_write(Interface &socket) { +int ClientInterface::set_master_file_write(Interface &socket) { auto enable = socket.Receive(); - if (enable >= 0) { - verifyIdle(socket); - LOG(logDEBUG1) << "Setting Master File write enable:" << enable; - impl()->setMasterFileWriteEnable(enable); + if (enable < 0) { + throw RuntimeError("Invalid master file write enable: " + + std::to_string(enable)); } + verifyIdle(socket); + LOG(logDEBUG1) << "Setting Master File write enable:" << enable; + impl()->setMasterFileWriteEnable(enable); + int retval = impl()->getMasterFileWriteEnable(); validate(enable, retval, "set master file write enable", DEC); LOG(logDEBUG1) << "master file write enable:" << retval; + return socket.Send(OK); +} + +int ClientInterface::get_master_file_write(Interface &socket) { + int retval = impl()->getMasterFileWriteEnable(); + LOG(logDEBUG1) << "master file write enable:" << retval; return socket.sendResult(retval); } -int ClientInterface::enable_overwrite(Interface &socket) { +int ClientInterface::set_overwrite(Interface &socket) { auto index = socket.Receive(); - if (index >= 0) { - verifyIdle(socket); - LOG(logDEBUG1) << "Setting File overwrite enable:" << index; - impl()->setOverwriteEnable(index); + if (index < 0) { + throw RuntimeError("Invalid over write enable: " + + std::to_string(index)); } + verifyIdle(socket); + LOG(logDEBUG1) << "Setting File overwrite enable:" << index; + impl()->setOverwriteEnable(index); + int retval = impl()->getOverwriteEnable(); validate(index, retval, "set file overwrite enable", DEC); LOG(logDEBUG1) << "file overwrite enable:" << retval; + return socket.Send(OK); +} + +int ClientInterface::get_overwrite(Interface &socket) { + int retval = impl()->getOverwriteEnable(); + LOG(logDEBUG1) << "file overwrite enable:" << retval; return socket.sendResult(retval); } @@ -821,20 +812,29 @@ int ClientInterface::set_activate(Interface &socket) { return socket.sendResult(retval); } -int ClientInterface::set_data_stream_enable(Interface &socket) { +int ClientInterface::set_streaming(Interface &socket) { auto index = socket.Receive(); - if (index >= 0) { - verifyIdle(socket); - LOG(logDEBUG1) << "Setting data stream enable:" << index; - try { - impl()->setDataStreamEnable(index); - } catch(const RuntimeError &e) { - throw RuntimeError("Could not set data stream enable to " + std::to_string(index)); - } + if (index < 0) { + throw RuntimeError("Invalid streaming enable: " + + std::to_string(index)); } + verifyIdle(socket); + LOG(logDEBUG1) << "Setting data stream enable:" << index; + try { + impl()->setDataStreamEnable(index); + } catch(const RuntimeError &e) { + throw RuntimeError("Could not set data stream enable to " + std::to_string(index)); + } + auto retval = static_cast(impl()->getDataStreamEnable()); validate(index, retval, "set data stream enable", DEC); LOG(logDEBUG1) << "data streaming enable:" << retval; + return socket.Send(OK); +} + +int ClientInterface::get_streaming(Interface &socket) { + auto retval = static_cast(impl()->getDataStreamEnable()); + LOG(logDEBUG1) << "data streaming enable:" << retval; return socket.sendResult(retval); } @@ -871,14 +871,23 @@ int ClientInterface::set_flipped_data(Interface &socket) { int ClientInterface::set_file_format(Interface &socket) { fileFormat f = GET_FILE_FORMAT; socket.Receive(f); - if (f >= 0) { - verifyIdle(socket); - LOG(logDEBUG1) << "Setting file format:" << f; - impl()->setFileFormat(f); + if (f < 0 || f > NUM_FILE_FORMATS) { + throw RuntimeError("Invalid file format: " + + std::to_string(f)); } + verifyIdle(socket); + LOG(logDEBUG1) << "Setting file format:" << f; + impl()->setFileFormat(f); + auto retval = impl()->getFileFormat(); validate(f, retval, "set file format", DEC); LOG(logDEBUG1) << "File Format: " << retval; + return socket.Send(OK); +} + +int ClientInterface::get_file_format(Interface &socket) { + auto retval = impl()->getFileFormat(); + LOG(logDEBUG1) << "File Format: " << retval; return socket.sendResult(retval); } @@ -912,25 +921,38 @@ int ClientInterface::set_multi_detector_size(Interface &socket) { int ClientInterface::set_streaming_port(Interface &socket) { auto port = socket.Receive(); - if (port >= 0) { - verifyIdle(socket); - LOG(logDEBUG1) << "Setting streaming port:" << port; - impl()->setStreamingPort(port); + if (port < 0) { + throw RuntimeError("Invalid zmq port " + std::to_string(port)); } + verifyIdle(socket); + LOG(logDEBUG1) << "Setting streaming port:" << port; + impl()->setStreamingPort(port); + int retval = impl()->getStreamingPort(); validate(port, retval, "set streaming port", DEC); LOG(logDEBUG1) << "streaming port:" << retval; + return socket.Send(OK); +} + +int ClientInterface::get_streaming_port(Interface &socket) { + int retval = impl()->getStreamingPort(); + LOG(logDEBUG1) << "streaming port:" << retval; return socket.sendResult(retval); } int ClientInterface::set_streaming_source_ip(Interface &socket) { sls::IpAddr arg; socket.Receive(arg); + if (arg == 0) { + throw RuntimeError("Invalid zmq ip " + arg.str()); + } verifyIdle(socket); LOG(logDEBUG1) << "Setting streaming source ip:" << arg; impl()->setStreamingSourceIP(arg); + sls::IpAddr retval = impl()->getStreamingSourceIP(); - if (retval != arg) { + LOG(logDEBUG1) << "streaming IP:" << retval; + if (retval != arg && arg != 0) { std::ostringstream os; os << "Could not set streaming ip. Set " << arg << ", but read " << retval << '\n'; @@ -939,16 +961,31 @@ int ClientInterface::set_streaming_source_ip(Interface &socket) { return socket.Send(OK); } +int ClientInterface::get_streaming_source_ip(Interface &socket) { + sls::IpAddr retval = impl()->getStreamingSourceIP(); + LOG(logDEBUG1) << "streaming IP:" << retval; + return socket.sendResult(retval); +} + int ClientInterface::set_silent_mode(Interface &socket) { auto value = socket.Receive(); - if (value >= 0) { - verifyIdle(socket); - LOG(logDEBUG1) << "Setting silent mode:" << value; - impl()->setSilentMode(value); + if (value < 0) { + throw RuntimeError("Invalid silent mode: " + + std::to_string(value)); } + verifyIdle(socket); + LOG(logDEBUG1) << "Setting silent mode:" << value; + impl()->setSilentMode(value); + auto retval = static_cast(impl()->getSilentMode()); validate(value, retval, "set silent mode", DEC); LOG(logDEBUG1) << "silent mode:" << retval; + return socket.Send(OK); +} + +int ClientInterface::get_silent_mode(Interface &socket) { + auto retval = static_cast(impl()->getSilentMode()); + LOG(logDEBUG1) << "silent mode:" << retval; return socket.sendResult(retval); } @@ -986,14 +1023,11 @@ int ClientInterface::restream_stop(Interface &socket) { int ClientInterface::set_additional_json_header(Interface &socket) { char arg[MAX_STR_LENGTH]{}; - char retval[MAX_STR_LENGTH]{}; socket.Receive(arg); verifyIdle(socket); LOG(logDEBUG1) << "Setting additional json header: " << arg; impl()->setAdditionalJsonHeader(arg); - sls::strcpy_safe(retval, impl()->getAdditionalJsonHeader().c_str()); - LOG(logDEBUG1) << "additional json header:" << retval; - return socket.sendResult(retval); + return socket.Send(OK); } int ClientInterface::get_additional_json_header(Interface &socket) { @@ -1028,14 +1062,23 @@ int ClientInterface::get_real_udp_socket_buffer_size( int ClientInterface::set_frames_per_file(Interface &socket) { auto index = socket.Receive(); - if (index >= 0) { - verifyIdle(socket); - LOG(logDEBUG1) << "Setting frames per file: " << index; - impl()->setFramesPerFile(index); + if (index < 0) { + throw RuntimeError("Invalid frames per file: " + + std::to_string(index)); } + verifyIdle(socket); + LOG(logDEBUG1) << "Setting frames per file: " << index; + impl()->setFramesPerFile(index); + auto retval = static_cast(impl()->getFramesPerFile()); validate(index, retval, "set frames per file", DEC); LOG(logDEBUG1) << "frames per file:" << retval; + return socket.Send(OK); +} + +int ClientInterface::get_frames_per_file(Interface &socket) { + auto retval = static_cast(impl()->getFramesPerFile()); + LOG(logDEBUG1) << "frames per file:" << retval; return socket.sendResult(retval); } @@ -1069,44 +1112,71 @@ int ClientInterface::check_version_compatibility(Interface &socket) { int ClientInterface::set_discard_policy(Interface &socket) { auto index = socket.Receive(); - if (index >= 0) { - verifyIdle(socket); - LOG(logDEBUG1) << "Setting frames discard policy: " << index; - impl()->setFrameDiscardPolicy(static_cast(index)); + if (index < 0 || index > NUM_DISCARD_POLICIES) { + throw RuntimeError("Invalid discard policy " + std::to_string(index)); } + verifyIdle(socket); + LOG(logDEBUG1) << "Setting frames discard policy: " << index; + impl()->setFrameDiscardPolicy(static_cast(index)); int retval = impl()->getFrameDiscardPolicy(); validate(index, retval, "set discard policy", DEC); LOG(logDEBUG1) << "frame discard policy:" << retval; + return socket.Send(OK); +} + +int ClientInterface::get_discard_policy(Interface &socket) { + int retval = impl()->getFrameDiscardPolicy(); + LOG(logDEBUG1) << "frame discard policy:" << retval; return socket.sendResult(retval); } int ClientInterface::set_padding_enable(Interface &socket) { auto index = socket.Receive(); - if (index >= 0) { - verifyIdle(socket); - LOG(logDEBUG1) << "Setting frames padding enable: " << index; - impl()->setFramePaddingEnable(static_cast(index)); + if (index < 0) { + throw RuntimeError("Invalid padding enable: " + std::to_string(index)); } + verifyIdle(socket); + LOG(logDEBUG1) << "Setting frames padding enable: " << index; + impl()->setFramePaddingEnable(static_cast(index)); + auto retval = static_cast(impl()->getFramePaddingEnable()); validate(index, retval, "set frame padding enable", DEC); LOG(logDEBUG1) << "Frame Padding Enable:" << retval; + return socket.Send(OK); +} + +int ClientInterface::get_padding_enable(Interface &socket) { + auto retval = static_cast(impl()->getFramePaddingEnable()); + LOG(logDEBUG1) << "Frame Padding Enable:" << retval; return socket.sendResult(retval); } int ClientInterface::set_deactivated_padding_enable( Interface &socket) { auto enable = socket.Receive(); - if (myDetectorType != EIGER) + if (myDetectorType != EIGER) { functionNotImplemented(); - - if (enable >= 0) { - verifyIdle(socket); - LOG(logDEBUG1) << "Setting deactivated padding enable: " << enable; - impl()->setDeactivatedPadding(enable > 0); } + if (enable < 0) { + throw RuntimeError("Invalid Deactivated padding: " + + std::to_string(enable)); + } + verifyIdle(socket); + LOG(logDEBUG1) << "Setting deactivated padding enable: " << enable; + impl()->setDeactivatedPadding(enable > 0); + auto retval = static_cast(impl()->getDeactivatedPadding()); validate(enable, retval, "set deactivated padding enable", DEC); LOG(logDEBUG1) << "Deactivated Padding Enable: " << retval; + return socket.Send(OK); +} + +int ClientInterface::get_deactivated_padding_enable( + Interface &socket) { + if (myDetectorType != EIGER) + functionNotImplemented(); + auto retval = static_cast(impl()->getDeactivatedPadding()); + LOG(logDEBUG1) << "Deactivated Padding Enable: " << retval; return socket.sendResult(retval); } @@ -1155,6 +1225,8 @@ int ClientInterface::set_adc_mask(Interface &socket) { int ClientInterface::set_dbit_list(Interface &socket) { sls::FixedCapacityContainer args; socket.Receive(args); + if (myDetectorType != CHIPTESTBOARD) + functionNotImplemented(); LOG(logDEBUG1) << "Setting DBIT list"; for (auto &it : args) { LOG(logDEBUG1) << it << " "; @@ -1166,6 +1238,8 @@ int ClientInterface::set_dbit_list(Interface &socket) { } int ClientInterface::get_dbit_list(Interface &socket) { + if (myDetectorType != CHIPTESTBOARD) + functionNotImplemented(); sls::FixedCapacityContainer retval; retval = impl()->getDbitList(); LOG(logDEBUG1) << "Dbit list size retval:" << retval.size(); @@ -1174,14 +1248,27 @@ int ClientInterface::get_dbit_list(Interface &socket) { int ClientInterface::set_dbit_offset(Interface &socket) { auto arg = socket.Receive(); - if (arg >= 0) { - verifyIdle(socket); - LOG(logDEBUG1) << "Setting Dbit offset: " << arg; - impl()->setDbitOffset(arg); + if (myDetectorType != CHIPTESTBOARD) + functionNotImplemented(); + if (arg < 0) { + throw RuntimeError("Invalid dbit offset: " + + std::to_string(arg)); } + verifyIdle(socket); + LOG(logDEBUG1) << "Setting Dbit offset: " << arg; + impl()->setDbitOffset(arg); + int retval = impl()->getDbitOffset(); validate(arg, retval, "set dbit offset", DEC); LOG(logDEBUG1) << "Dbit offset retval: " << retval; + return socket.Send(OK); +} + +int ClientInterface::get_dbit_offset(Interface &socket) { + if (myDetectorType != CHIPTESTBOARD) + functionNotImplemented(); + int retval = impl()->getDbitOffset(); + LOG(logDEBUG1) << "Dbit offset retval: " << retval; return socket.sendResult(retval); } @@ -1236,7 +1323,7 @@ int ClientInterface::set_udp_ip(Interface &socket) { // get mac address auto retval = sls::InterfaceNameToMac(eth); if (retval == 0) { - throw RuntimeError("Failed to get udp mac adddress to listen to\n"); + throw RuntimeError("Failed to get udp mac adddress to listen to (eth:" + eth + ", ip:" + arg.str() + ")\n"); } LOG(logINFO) << "Receiver MAC Address: " << retval; return socket.sendResult(retval); @@ -1264,7 +1351,7 @@ int ClientInterface::set_udp_ip2(Interface &socket) { // get mac address auto retval = sls::InterfaceNameToMac(eth); if (retval == 0) { - throw RuntimeError("Failed to get udp mac adddress2 to listen to\n"); + throw RuntimeError("Failed to get udp mac adddress2 to listen to (eth:" + eth + ", ip:" + arg.str() + ")\n"); } LOG(logINFO) << "Receiver MAC Address2: " << retval; return socket.sendResult(retval); @@ -1331,4 +1418,11 @@ int ClientInterface::set_num_counters(Interface &socket) { LOG(logDEBUG1) << "Setting counters: " << arg; impl()->setNumberofCounters(arg); return socket.Send(OK); +} + +int ClientInterface::increment_file_index(Interface &socket) { + verifyIdle(socket); + LOG(logDEBUG1) << "Incrementing file index"; + impl()->setFileIndex(impl()->getFileIndex() + 1); + return socket.Send(OK); } \ No newline at end of file diff --git a/slsReceiverSoftware/src/ClientInterface.h b/slsReceiverSoftware/src/ClientInterface.h index ef6d9e317..6e1f3bc39 100755 --- a/slsReceiverSoftware/src/ClientInterface.h +++ b/slsReceiverSoftware/src/ClientInterface.h @@ -70,31 +70,43 @@ class ClientInterface : private virtual slsDetectorDefs { int set_subdeadtime(sls::ServerInterface &socket); int set_dynamic_range(sls::ServerInterface &socket); int set_streaming_frequency(sls::ServerInterface &socket); + int get_streaming_frequency(sls::ServerInterface &socket); int get_status(sls::ServerInterface &socket); int start_receiver(sls::ServerInterface &socket); int stop_receiver(sls::ServerInterface &socket); int set_file_dir(sls::ServerInterface &socket); + int get_file_dir(sls::ServerInterface &socket); int set_file_name(sls::ServerInterface &socket); + int get_file_name(sls::ServerInterface &socket); int set_file_index(sls::ServerInterface &socket); + int get_file_index(sls::ServerInterface &socket); int get_frame_index(sls::ServerInterface &socket); int get_missing_packets(sls::ServerInterface &socket); int get_frames_caught(sls::ServerInterface &socket); - int enable_file_write(sls::ServerInterface &socket); - int enable_master_file_write(sls::ServerInterface &socket); + int set_file_write(sls::ServerInterface &socket); + int get_file_write(sls::ServerInterface &socket); + int set_master_file_write(sls::ServerInterface &socket); + int get_master_file_write(sls::ServerInterface &socket); int enable_compression(sls::ServerInterface &socket); - int enable_overwrite(sls::ServerInterface &socket); + int set_overwrite(sls::ServerInterface &socket); + int get_overwrite(sls::ServerInterface &socket); int enable_tengiga(sls::ServerInterface &socket); int set_fifo_depth(sls::ServerInterface &socket); int set_activate(sls::ServerInterface &socket); - int set_data_stream_enable(sls::ServerInterface &socket); + int set_streaming(sls::ServerInterface &socket); + int get_streaming(sls::ServerInterface &socket); int set_streaming_timer(sls::ServerInterface &socket); int set_flipped_data(sls::ServerInterface &socket); int set_file_format(sls::ServerInterface &socket); + int get_file_format(sls::ServerInterface &socket); int set_detector_posid(sls::ServerInterface &socket); int set_multi_detector_size(sls::ServerInterface &socket); int set_streaming_port(sls::ServerInterface &socket); + int get_streaming_port(sls::ServerInterface &socket); int set_streaming_source_ip(sls::ServerInterface &socket); + int get_streaming_source_ip(sls::ServerInterface &socket); int set_silent_mode(sls::ServerInterface &socket); + int get_silent_mode(sls::ServerInterface &socket); int enable_gap_pixels(sls::ServerInterface &socket); int restream_stop(sls::ServerInterface &socket); int set_additional_json_header(sls::ServerInterface &socket); @@ -102,15 +114,20 @@ class ClientInterface : private virtual slsDetectorDefs { int set_udp_socket_buffer_size(sls::ServerInterface &socket); int get_real_udp_socket_buffer_size(sls::ServerInterface &socket); int set_frames_per_file(sls::ServerInterface &socket); + int get_frames_per_file(sls::ServerInterface &socket); int check_version_compatibility(sls::ServerInterface &socket); int set_discard_policy(sls::ServerInterface &socket); + int get_discard_policy(sls::ServerInterface &socket); int set_padding_enable(sls::ServerInterface &socket); + int get_padding_enable(sls::ServerInterface &socket); int set_deactivated_padding_enable(sls::ServerInterface &socket); + int get_deactivated_padding_enable(sls::ServerInterface &socket); int set_readout_mode(sls::ServerInterface &socket); int set_adc_mask(sls::ServerInterface &socket); int set_dbit_list(sls::ServerInterface &socket); int get_dbit_list(sls::ServerInterface &socket); int set_dbit_offset(sls::ServerInterface &socket); + int get_dbit_offset(sls::ServerInterface &socket); int set_quad_type(sls::ServerInterface &socket); int set_read_n_lines(sls::ServerInterface &socket); int set_udp_ip(sls::ServerInterface &socket); @@ -120,6 +137,7 @@ class ClientInterface : private virtual slsDetectorDefs { int set_num_interfaces(sls::ServerInterface &socket); int set_adc_mask_10g(sls::ServerInterface &socket); int set_num_counters(sls::ServerInterface &socket); + int increment_file_index(sls::ServerInterface &socket); Implementation *impl() { if (receiver != nullptr) { diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index 8f1b53faa..d5f323c4c 100755 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -59,11 +59,11 @@ void Implementation::InitializeMembers() { silentMode = false; fifoDepth = 0; frameDiscardMode = NO_DISCARD; - framePadding = false; + framePadding = true; // file parameters fileFormatType = BINARY; - filePath = ""; + filePath = "/"; fileName = "run"; fileIndex = 0; fileWriteEnable = true; @@ -340,6 +340,11 @@ void Implementation::setDetectorPositionId(const int id) { LOG(logDEBUG3) << __SHORT_AT__ << " called"; detID = id; LOG(logINFO) << "Detector Position Id:" << detID; + + // update zmq port + streamingPort = DEFAULT_ZMQ_RX_PORTNO + + (detID * (myDetectorType == EIGER ? 2 : 1)); + for (unsigned int i = 0; i < dataProcessor.size(); ++i) { dataProcessor[i]->SetupFileWriter( fileWriteEnable, (int *)numDet, &framesPerFile, &fileName, &filePath, diff --git a/slsReceiverSoftware/src/receiver_defs.h b/slsReceiverSoftware/src/receiver_defs.h index 8fc71782c..2880d28fb 100755 --- a/slsReceiverSoftware/src/receiver_defs.h +++ b/slsReceiverSoftware/src/receiver_defs.h @@ -14,6 +14,15 @@ //files +#define MAX_FRAMES_PER_FILE 20000 +#define SHORT_MAX_FRAMES_PER_FILE 100000 +#define MOENCH_MAX_FRAMES_PER_FILE 100000 +#define EIGER_MAX_FRAMES_PER_FILE 10000 +#define JFRAU_MAX_FRAMES_PER_FILE 10000 +#define CTB_MAX_FRAMES_PER_FILE 20000 +#define MYTHEN3_MAX_FRAMES_PER_FILE 10000 +#define GOTTHARD2_MAX_FRAMES_PER_FILE 20000 + #define DO_NOTHING (0) #define DO_EVERYTHING (1) diff --git a/slsSupportLib/include/sls_detector_defs.h b/slsSupportLib/include/sls_detector_defs.h index e9196b1c4..7e88d989d 100755 --- a/slsSupportLib/include/sls_detector_defs.h +++ b/slsSupportLib/include/sls_detector_defs.h @@ -61,14 +61,6 @@ /** default maximum string length */ #define MAX_STR_LENGTH 1000 -#define MAX_FRAMES_PER_FILE 20000 -#define SHORT_MAX_FRAMES_PER_FILE 100000 -#define MOENCH_MAX_FRAMES_PER_FILE 100000 -#define EIGER_MAX_FRAMES_PER_FILE 10000 -#define JFRAU_MAX_FRAMES_PER_FILE 10000 -#define CTB_MAX_FRAMES_PER_FILE 20000 -#define MYTHEN3_MAX_FRAMES_PER_FILE 10000 -#define GOTTHARD2_MAX_FRAMES_PER_FILE 20000 #define DEFAULT_STREAMING_TIMER_IN_MS 200 diff --git a/slsSupportLib/include/sls_detector_funcs.h b/slsSupportLib/include/sls_detector_funcs.h index fe9c5a17b..f4a4bd941 100755 --- a/slsSupportLib/include/sls_detector_funcs.h +++ b/slsSupportLib/include/sls_detector_funcs.h @@ -219,47 +219,64 @@ enum detFuncs{ F_RECEIVER_SET_SUB_EXPTIME, F_RECEIVER_SET_SUB_DEADTIME, F_SET_RECEIVER_DYNAMIC_RANGE, - F_RECEIVER_STREAMING_FREQUENCY, + F_SET_RECEIVER_STREAMING_FREQUENCY, + F_GET_RECEIVER_STREAMING_FREQUENCY, F_GET_RECEIVER_STATUS, F_START_RECEIVER, F_STOP_RECEIVER, F_SET_RECEIVER_FILE_PATH, + F_GET_RECEIVER_FILE_PATH, F_SET_RECEIVER_FILE_NAME, + F_GET_RECEIVER_FILE_NAME, F_SET_RECEIVER_FILE_INDEX, + F_GET_RECEIVER_FILE_INDEX, F_GET_RECEIVER_FRAME_INDEX, F_GET_RECEIVER_FRAMES_CAUGHT, F_GET_NUM_MISSING_PACKETS, - F_ENABLE_RECEIVER_FILE_WRITE, - F_ENABLE_RECEIVER_MASTER_FILE_WRITE, - F_ENABLE_RECEIVER_OVERWRITE, + F_SET_RECEIVER_FILE_WRITE, + F_GET_RECEIVER_FILE_WRITE, + F_SET_RECEIVER_MASTER_FILE_WRITE, + F_GET_RECEIVER_MASTER_FILE_WRITE, + F_SET_RECEIVER_OVERWRITE, + F_GET_RECEIVER_OVERWRITE, F_ENABLE_RECEIVER_TEN_GIGA, F_SET_RECEIVER_FIFO_DEPTH, F_RECEIVER_ACTIVATE, - F_STREAM_DATA_FROM_RECEIVER, + F_SET_RECEIVER_STREAMING, + F_GET_RECEIVER_STREAMING, F_RECEIVER_STREAMING_TIMER, F_SET_FLIPPED_DATA_RECEIVER, F_SET_RECEIVER_FILE_FORMAT, + F_GET_RECEIVER_FILE_FORMAT, F_SEND_RECEIVER_DETPOSID, F_SEND_RECEIVER_MULTIDETSIZE, F_SET_RECEIVER_STREAMING_PORT, - F_RECEIVER_STREAMING_SRC_IP, + F_GET_RECEIVER_STREAMING_PORT, + F_SET_RECEIVER_STREAMING_SRC_IP, + F_GET_RECEIVER_STREAMING_SRC_IP, F_SET_RECEIVER_SILENT_MODE, + F_GET_RECEIVER_SILENT_MODE, F_ENABLE_GAPPIXELS_IN_RECEIVER, F_RESTREAM_STOP_FROM_RECEIVER, - F_ADDITIONAL_JSON_HEADER, + F_SET_ADDITIONAL_JSON_HEADER, F_GET_ADDITIONAL_JSON_HEADER, F_RECEIVER_UDP_SOCK_BUF_SIZE, F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE, F_SET_RECEIVER_FRAMES_PER_FILE, + F_GET_RECEIVER_FRAMES_PER_FILE, F_RECEIVER_CHECK_VERSION, - F_RECEIVER_DISCARD_POLICY, - F_RECEIVER_PADDING_ENABLE, - F_RECEIVER_DEACTIVATED_PADDING_ENABLE, + F_SET_RECEIVER_DISCARD_POLICY, + F_GET_RECEIVER_DISCARD_POLICY, + F_SET_RECEIVER_PADDING, + F_GET_RECEIVER_PADDING, + F_SET_RECEIVER_DEACTIVATED_PADDING, + F_GET_RECEIVER_DEACTIVATED_PADDING, F_RECEIVER_SET_READOUT_MODE, F_RECEIVER_SET_ADC_MASK, F_SET_RECEIVER_DBIT_LIST, F_GET_RECEIVER_DBIT_LIST, - F_RECEIVER_DBIT_OFFSET, + F_SET_RECEIVER_DBIT_OFFSET, + F_GET_RECEIVER_DBIT_OFFSET, F_SET_RECEIVER_QUAD, F_SET_RECEIVER_READ_N_LINES, F_SET_RECEIVER_UDP_IP, @@ -269,6 +286,7 @@ enum detFuncs{ F_SET_RECEIVER_NUM_INTERFACES, F_RECEIVER_SET_ADC_MASK_10G, F_RECEIVER_SET_NUM_COUNTERS, + F_INCREMENT_FILE_INDEX, NUM_REC_FUNCTIONS }; @@ -484,47 +502,64 @@ static const char* getFunctionNameFromEnum(enum detFuncs func) { case F_RECEIVER_SET_SUB_EXPTIME: return "F_RECEIVER_SET_SUB_EXPTIME"; case F_RECEIVER_SET_SUB_DEADTIME: return "F_RECEIVER_SET_SUB_DEADTIME"; case F_SET_RECEIVER_DYNAMIC_RANGE: return "F_SET_RECEIVER_DYNAMIC_RANGE"; - case F_RECEIVER_STREAMING_FREQUENCY: return "F_RECEIVER_STREAMING_FREQUENCY"; + case F_SET_RECEIVER_STREAMING_FREQUENCY: return "F_SET_RECEIVER_STREAMING_FREQUENCY"; + case F_GET_RECEIVER_STREAMING_FREQUENCY: return "F_GET_RECEIVER_STREAMING_FREQUENCY"; case F_GET_RECEIVER_STATUS: return "F_GET_RECEIVER_STATUS"; case F_START_RECEIVER: return "F_START_RECEIVER"; case F_STOP_RECEIVER: return "F_STOP_RECEIVER"; case F_SET_RECEIVER_FILE_PATH: return "F_SET_RECEIVER_FILE_PATH"; + case F_GET_RECEIVER_FILE_PATH: return "F_GET_RECEIVER_FILE_PATH"; case F_SET_RECEIVER_FILE_NAME: return "F_SET_RECEIVER_FILE_NAME"; + case F_GET_RECEIVER_FILE_NAME: return "F_GET_RECEIVER_FILE_NAME"; case F_SET_RECEIVER_FILE_INDEX: return "F_SET_RECEIVER_FILE_INDEX"; + case F_GET_RECEIVER_FILE_INDEX: return "F_GET_RECEIVER_FILE_INDEX"; case F_GET_RECEIVER_FRAME_INDEX: return "F_GET_RECEIVER_FRAME_INDEX"; case F_GET_RECEIVER_FRAMES_CAUGHT: return "F_GET_RECEIVER_FRAMES_CAUGHT"; case F_GET_NUM_MISSING_PACKETS: return "F_GET_NUM_MISSING_PACKETS"; - case F_ENABLE_RECEIVER_FILE_WRITE: return "F_ENABLE_RECEIVER_FILE_WRITE"; - case F_ENABLE_RECEIVER_MASTER_FILE_WRITE: return "F_ENABLE_RECEIVER_MASTER_FILE_WRITE"; - case F_ENABLE_RECEIVER_OVERWRITE: return "F_ENABLE_RECEIVER_OVERWRITE"; + case F_SET_RECEIVER_FILE_WRITE: return "F_SET_RECEIVER_FILE_WRITE"; + case F_GET_RECEIVER_FILE_WRITE: return "F_GET_RECEIVER_FILE_WRITE"; + case F_SET_RECEIVER_MASTER_FILE_WRITE: return "F_SET_RECEIVER_MASTER_FILE_WRITE"; + case F_GET_RECEIVER_MASTER_FILE_WRITE: return "F_GET_RECEIVER_MASTER_FILE_WRITE"; + case F_SET_RECEIVER_OVERWRITE: return "F_SET_RECEIVER_OVERWRITE"; + case F_GET_RECEIVER_OVERWRITE: return "F_GET_RECEIVER_OVERWRITE"; case F_ENABLE_RECEIVER_TEN_GIGA: return "F_ENABLE_RECEIVER_TEN_GIGA"; case F_SET_RECEIVER_FIFO_DEPTH: return "F_SET_RECEIVER_FIFO_DEPTH"; case F_RECEIVER_ACTIVATE: return "F_RECEIVER_ACTIVATE"; - case F_STREAM_DATA_FROM_RECEIVER: return "F_STREAM_DATA_FROM_RECEIVER"; + case F_SET_RECEIVER_STREAMING: return "F_SET_RECEIVER_STREAMING"; + case F_GET_RECEIVER_STREAMING: return "F_GET_RECEIVER_STREAMING"; case F_RECEIVER_STREAMING_TIMER: return "F_RECEIVER_STREAMING_TIMER"; case F_SET_FLIPPED_DATA_RECEIVER: return "F_SET_FLIPPED_DATA_RECEIVER"; case F_SET_RECEIVER_FILE_FORMAT: return "F_SET_RECEIVER_FILE_FORMAT"; + case F_GET_RECEIVER_FILE_FORMAT: return "F_GET_RECEIVER_FILE_FORMAT"; case F_SEND_RECEIVER_DETPOSID: return "F_SEND_RECEIVER_DETPOSID"; case F_SEND_RECEIVER_MULTIDETSIZE: return "F_SEND_RECEIVER_MULTIDETSIZE"; case F_SET_RECEIVER_STREAMING_PORT: return "F_SET_RECEIVER_STREAMING_PORT"; - case F_RECEIVER_STREAMING_SRC_IP: return "F_RECEIVER_STREAMING_SRC_IP"; + case F_GET_RECEIVER_STREAMING_PORT: return "F_GET_RECEIVER_STREAMING_PORT"; + case F_SET_RECEIVER_STREAMING_SRC_IP: return "F_SET_RECEIVER_STREAMING_SRC_IP"; + case F_GET_RECEIVER_STREAMING_SRC_IP: return "F_GET_RECEIVER_STREAMING_SRC_IP"; case F_SET_RECEIVER_SILENT_MODE: return "F_SET_RECEIVER_SILENT_MODE"; + case F_GET_RECEIVER_SILENT_MODE: return "F_GET_RECEIVER_SILENT_MODE"; case F_ENABLE_GAPPIXELS_IN_RECEIVER: return "F_ENABLE_GAPPIXELS_IN_RECEIVER"; case F_RESTREAM_STOP_FROM_RECEIVER: return "F_RESTREAM_STOP_FROM_RECEIVER"; - case F_ADDITIONAL_JSON_HEADER: return "F_ADDITIONAL_JSON_HEADER"; + case F_SET_ADDITIONAL_JSON_HEADER: return "F_SET_ADDITIONAL_JSON_HEADER"; case F_GET_ADDITIONAL_JSON_HEADER: return "F_GET_ADDITIONAL_JSON_HEADER"; case F_RECEIVER_UDP_SOCK_BUF_SIZE: return "F_RECEIVER_UDP_SOCK_BUF_SIZE"; case F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE: return "F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE"; case F_SET_RECEIVER_FRAMES_PER_FILE: return "F_SET_RECEIVER_FRAMES_PER_FILE"; + case F_GET_RECEIVER_FRAMES_PER_FILE: return "F_GET_RECEIVER_FRAMES_PER_FILE"; case F_RECEIVER_CHECK_VERSION: return "F_RECEIVER_CHECK_VERSION"; - case F_RECEIVER_DISCARD_POLICY: return "F_RECEIVER_DISCARD_POLICY"; - case F_RECEIVER_PADDING_ENABLE: return "F_RECEIVER_PADDING_ENABLE"; - case F_RECEIVER_DEACTIVATED_PADDING_ENABLE: return "F_RECEIVER_DEACTIVATED_PADDING_ENABLE"; + case F_SET_RECEIVER_DISCARD_POLICY: return "F_SET_RECEIVER_DISCARD_POLICY"; + case F_GET_RECEIVER_DISCARD_POLICY: return "F_GET_RECEIVER_DISCARD_POLICY"; + case F_SET_RECEIVER_PADDING: return "F_SET_RECEIVER_PADDING"; + case F_GET_RECEIVER_PADDING: return "F_GET_RECEIVER_PADDING"; + case F_SET_RECEIVER_DEACTIVATED_PADDING: return "F_SET_RECEIVER_DEACTIVATED_PADDING"; + case F_GET_RECEIVER_DEACTIVATED_PADDING: return "F_GET_RECEIVER_DEACTIVATED_PADDING"; case F_RECEIVER_SET_READOUT_MODE: return "F_RECEIVER_SET_READOUT_MODE"; case F_RECEIVER_SET_ADC_MASK: return "F_RECEIVER_SET_ADC_MASK"; case F_SET_RECEIVER_DBIT_LIST: return "F_SET_RECEIVER_DBIT_LIST"; case F_GET_RECEIVER_DBIT_LIST: return "F_GET_RECEIVER_DBIT_LIST"; - case F_RECEIVER_DBIT_OFFSET: return "F_RECEIVER_DBIT_OFFSET"; + case F_SET_RECEIVER_DBIT_OFFSET: return "F_SET_RECEIVER_DBIT_OFFSET"; + case F_GET_RECEIVER_DBIT_OFFSET: return "F_GET_RECEIVER_DBIT_OFFSET"; case F_SET_RECEIVER_QUAD: return "F_SET_RECEIVER_QUAD"; case F_SET_RECEIVER_READ_N_LINES: return "F_SET_RECEIVER_READ_N_LINES"; case F_SET_RECEIVER_UDP_IP: return "F_SET_RECEIVER_UDP_IP"; @@ -534,6 +569,7 @@ static const char* getFunctionNameFromEnum(enum detFuncs func) { case F_SET_RECEIVER_NUM_INTERFACES: return "F_SET_RECEIVER_NUM_INTERFACES"; case F_RECEIVER_SET_ADC_MASK_10G: return "F_RECEIVER_SET_ADC_MASK_10G"; case F_RECEIVER_SET_NUM_COUNTERS: return "F_RECEIVER_SET_NUM_COUNTERS"; + case F_INCREMENT_FILE_INDEX: return "F_INCREMENT_FILE_INDEX"; case NUM_REC_FUNCTIONS: return "NUM_REC_FUNCTIONS"; diff --git a/slsSupportLib/src/ClientSocket.cpp b/slsSupportLib/src/ClientSocket.cpp index 531c752b7..0e0352c90 100755 --- a/slsSupportLib/src/ClientSocket.cpp +++ b/slsSupportLib/src/ClientSocket.cpp @@ -70,7 +70,19 @@ int ClientSocket::sendCommandThenRead(int fnum, const void *args, void ClientSocket::readReply(int &ret, void *retval, size_t retval_size) { - Receive(&ret, sizeof(ret)); + try { + Receive(&ret, sizeof(ret)); + } + // debugging + catch (sls::SocketError &e) { + if (socketType == "Receiver") { + throw ReceiverError("Receiver returned: " + std::string(e.what())); + } else if (socketType == "Detector") { + throw DetectorError("Detector returned: " + std::string(e.what())); + } else { + throw GuiError(e.what()); + } + } if (ret == slsDetectorDefs::FAIL) { char mess[MAX_STR_LENGTH]{}; // get error message diff --git a/slsSupportLib/src/network_utils.cpp b/slsSupportLib/src/network_utils.cpp index 707d572a6..24eadeed4 100755 --- a/slsSupportLib/src/network_utils.cpp +++ b/slsSupportLib/src/network_utils.cpp @@ -85,7 +85,7 @@ IpAddr HostnameToIp(const char *hostname) { hints.ai_socktype = SOCK_STREAM; if (getaddrinfo(hostname, nullptr, &hints, &result)) { freeaddrinfo(result); - throw RuntimeError("Could not convert hostname to ip"); + throw RuntimeError("Could not convert hostname (" + std::string(hostname) + ") to ip"); } uint32_t ip = ((sockaddr_in *)result->ai_addr)->sin_addr.s_addr; freeaddrinfo(result); diff --git a/slsSupportLib/tests/test-network_utils.cpp b/slsSupportLib/tests/test-network_utils.cpp index 33757d64c..bfbc86713 100755 --- a/slsSupportLib/tests/test-network_utils.cpp +++ b/slsSupportLib/tests/test-network_utils.cpp @@ -105,4 +105,10 @@ TEST_CASE("MAC Output operator gives same result as string", "[support]") { CHECK(os.str() == addr.str()); } +TEST_CASE("Copy construct a MacAddr"){ + MacAddr addr{"00:50:c2:46:d9:a6"}; + MacAddr addr2(addr); + CHECK(addr == addr2); +} + // TODO!(Erik) Look up a real hostname and verify the IP