From 2bc33ad34aaa48e719ac028bd42f27b8759ae40d Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Thu, 10 Sep 2020 14:45:31 +0200 Subject: [PATCH 1/8] default value for setDAC --- python/scripts/generate_functions.py | 20 +++++++++++++++++++- python/src/detector.cpp | 17 +++++++++-------- slsDetectorSoftware/include/Detector.h | 4 ++-- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/python/scripts/generate_functions.py b/python/scripts/generate_functions.py index 095a57a70..5a955e63b 100644 --- a/python/scripts/generate_functions.py +++ b/python/scripts/generate_functions.py @@ -60,6 +60,23 @@ def get_arguments(node): args = f", {args}" return args +def get_arguments_with_default(node): + args = [] + for arg in node.get_arguments(): + tokens = [t.spelling for t in arg.get_tokens()] + print(tokens) + if '=' in tokens: + if arg.type.spelling == "sls::Positions": #TODO! automate + args.append("py::arg() = Positions{}") + else: + args.append('py::arg()' + ''.join(tokens[tokens.index('='):])) + else: + args.append('py::arg()') + args = ", ".join(args) + if args: + args = f", {args}" + return args + def get_fdec(node): args = [a.type.spelling for a in node.get_arguments()] @@ -86,7 +103,8 @@ def visit(node): and child.access_specifier == cindex.AccessSpecifier.PUBLIC ): m.append(child) - args = get_arguments(child) + # args = get_arguments(child) + args = get_arguments_with_default(child) fs = get_fdec(child) lines.append( f'.def("{child.spelling}",{fs} &Detector::{child.spelling}{args})' diff --git a/python/src/detector.cpp b/python/src/detector.cpp index d3e61c998..f5d0cbf72 100644 --- a/python/src/detector.cpp +++ b/python/src/detector.cpp @@ -322,11 +322,11 @@ void init_det(py::module &m) { (Result(Detector::*)(defs::dacIndex, bool, sls::Positions) const) & Detector::getDAC, - py::arg(), py::arg(), py::arg() = Positions{}) + py::arg(), py::arg() = false, py::arg() = Positions{}) .def("setDAC", (void (Detector::*)(defs::dacIndex, int, bool, sls::Positions)) & Detector::setDAC, - py::arg(), py::arg(), py::arg(), py::arg() = Positions{}) + py::arg(), py::arg(), py::arg() = false, py::arg() = Positions{}) .def("getOnChipDAC", (Result(Detector::*)(defs::dacIndex, int, sls::Positions) const) & @@ -488,14 +488,14 @@ void init_det(py::module &m) { py::arg() = Positions{}) .def("setDestinationUDPPort", (void (Detector::*)(int, int)) & Detector::setDestinationUDPPort, - py::arg(), py::arg()) + py::arg(), py::arg() = -1) .def("getDestinationUDPPort2", (Result(Detector::*)(sls::Positions) const) & Detector::getDestinationUDPPort2, py::arg() = Positions{}) .def("setDestinationUDPPort2", (void (Detector::*)(int, int)) & Detector::setDestinationUDPPort2, - py::arg(), py::arg()) + py::arg(), py::arg() = -1) .def("reconfigureUDPDestination", (void (Detector::*)(sls::Positions)) & Detector::reconfigureUDPDestination, @@ -568,7 +568,7 @@ void init_det(py::module &m) { Detector::getRxPort, py::arg() = Positions{}) .def("setRxPort", (void (Detector::*)(int, int)) & Detector::setRxPort, - py::arg(), py::arg()) + py::arg(), py::arg() = -1) .def("getRxFifoDepth", (Result(Detector::*)(sls::Positions) const) & Detector::getRxFifoDepth, @@ -730,7 +730,7 @@ void init_det(py::module &m) { py::arg() = Positions{}) .def("setRxZmqPort", (void (Detector::*)(int, int)) & Detector::setRxZmqPort, py::arg(), - py::arg()) + py::arg() = -1) .def("getRxZmqIP", (Result(Detector::*)(sls::Positions) const) & Detector::getRxZmqIP, @@ -745,7 +745,7 @@ void init_det(py::module &m) { py::arg() = Positions{}) .def("setClientZmqPort", (void (Detector::*)(int, int)) & Detector::setClientZmqPort, - py::arg(), py::arg()) + py::arg(), py::arg() = -1) .def("getClientZmqIp", (Result(Detector::*)(sls::Positions) const) & Detector::getClientZmqIp, @@ -778,7 +778,8 @@ void init_det(py::module &m) { (void (Detector::*)(int, defs::detectorSettings, bool, sls::Positions)) & Detector::setThresholdEnergy, - py::arg(), py::arg(), py::arg(), py::arg() = Positions{}) + py::arg(), py::arg() = defs::STANDARD, py::arg() = true, + py::arg() = Positions{}) .def("getSettingsPath", (Result(Detector::*)(sls::Positions) const) & Detector::getSettingsPath, diff --git a/slsDetectorSoftware/include/Detector.h b/slsDetectorSoftware/include/Detector.h index 217e5dcd2..ddea67c0d 100644 --- a/slsDetectorSoftware/include/Detector.h +++ b/slsDetectorSoftware/include/Detector.h @@ -367,9 +367,9 @@ class Detector { /** gets list of dac enums for this detector */ std::vector getDacList() const; - Result getDAC(defs::dacIndex index, bool mV, Positions pos = {}) const; + Result getDAC(defs::dacIndex index, bool mV = false, Positions pos = {}) const; - void setDAC(defs::dacIndex index, int value, bool mV, Positions pos = {}); + void setDAC(defs::dacIndex index, int value, bool mV = false, Positions pos = {}); /* [Gotthard2] */ Result getOnChipDAC(defs::dacIndex index, int chipIndex, From b879a377ba35014caf1cfaa9b9390e0cbbf2a4c1 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Thu, 10 Sep 2020 15:28:29 +0200 Subject: [PATCH 2/8] python cmds --- python/scripts/cmd_python.py | 3 +++ python/slsdet/detector.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/python/scripts/cmd_python.py b/python/scripts/cmd_python.py index b882dacdc..3e71e6ffc 100644 --- a/python/scripts/cmd_python.py +++ b/python/scripts/cmd_python.py @@ -87,6 +87,9 @@ intentionally_missing = [ 'udp_validate', #use validateUdpConfiguration 'udp_reconfigure', #use reconfigureUdpDestination 'emin', #use rx_jsonpara + 'pulse', # use pulseChip pulsePixel pulsePixelNmove + 'pulsechip', + 'pulsenmove', ] pycmd += intentionally_missing diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index 4f52abacc..b2c7089a5 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -141,6 +141,15 @@ class Detector(CppDetectorApi): raise ValueError("hostname needs to be string or list of strings") + @property + @element + def port(self): + return self.getControlPort() + + @port.setter + def port(self, value): + ut.set_using_dict(self.setControlPort, value) + @property @element def stopport(self): @@ -235,6 +244,20 @@ class Detector(CppDetectorApi): def frames(self, n_frames): self.setNumberOfFrames(n_frames) + @property + @element + def nframes(self): + return self.getNumberOfFramesFromStart() + + @property + @element + def powerchip(self): + return self.getPowerChip() + + @powerchip.setter + def powerchip(self, value): + ut.set_using_dict(self.setPowerChip, value) + @property def triggers(self): return element_if_equal(self.getNumberOfTriggers()) @@ -1290,6 +1313,15 @@ class Detector(CppDetectorApi): def subexptime(self, t): ut.set_time_using_dict(self.setSubExptime, t) + @property + @element + def readnlines(self): + return self.getPartialReadout() + + @readnlines.setter + def readnlines(self, value): + ut.set_using_dict(self.setPartialReadout, value) + @property def subdeadtime(self): From c94dfde17c53660b85f9d964636d57d51b49b13a Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Thu, 10 Sep 2020 15:48:25 +0200 Subject: [PATCH 3/8] updated compare script --- python/scripts/cmd_python.py | 103 ---------------- python/scripts/compare_with_commandline.py | 133 +++++++++++++++++++++ 2 files changed, 133 insertions(+), 103 deletions(-) delete mode 100644 python/scripts/cmd_python.py create mode 100644 python/scripts/compare_with_commandline.py diff --git a/python/scripts/cmd_python.py b/python/scripts/cmd_python.py deleted file mode 100644 index 3e71e6ffc..000000000 --- a/python/scripts/cmd_python.py +++ /dev/null @@ -1,103 +0,0 @@ -import subprocess -import locale -out = subprocess.run(['g', 'list'], stdout = subprocess.PIPE, encoding=locale.getpreferredencoding()) -cmd = out.stdout.splitlines() -cmd.pop(0) - -from slsdet import Detector, Eiger, Ctb - -pycmd = dir(Detector)+dir(Eiger)+dir(Ctb) - -#Add commands that we should not expect as direct commands in python -pycmd += ['vrf', 'vtr', 'vrs', 'vtgstv', 'vsvn', 'vtrim', -'vsvp', 'vth1', 'vth2', 'vth3', 'vshaper', 'vshaperneg', 'rxb_rb', -'rxb_lb', 'vref_prech', 'vref_rstore', 'vref_cds', -'vpreamp', 'vref_comp', 'vref_comp_fe vref_ds', 'vref_h_adc', -'vref_l_adc', 'iodelay', 'list', 'vref_ds', 'vis', 'vpl', -'vref_comp_fe', 'vph', 'vout_cm', 'vcp', 'vcn', 'vcmp_ll', 'vcmp_lr' - -] - - -# dacs are in general not included in the python commands and we expect to -# set them from the specialized class or using an enum -dacs = [ - 'adcvpp', - 'vicin', - 'vcassh', - 'vcal_n', - 'vcal_p' - 'vipre_out', - 'vipre_cds', - 'vdd_prot', - 'vcmp_rl', - 'vcmp_rr', - 'vcal', 'vcas', - 'vipre', - 'vin_com', - 'vin_cm', - 'vrshaper', - 'vrshaper_n', - 'vrpreamp', - 'vishaper', - 'vipre_out', - 'vcom_adc1', - 'vcom_adc2', - 'vcom_cds', - 'vdcsh', - 'v_chip', - 'vb_comp', - 'vb_comp_adc', - 'vb_comp_fe', - 'vb_cs', - 'vb_ds', - 'vb_opa_1st', - 'vb_opa_fd', - 'vb_pixbuf', - 'vb_sda', - 'vbp_colbuf', - 'vcal_p', - 'vcasc_out', - 'vcasc_sfp', - 'vcascn_pb', - 'vcascp_pb', - 'vchip_comp_adc', - 'vchip_comp_fe', - 'vchip_cs', - 'vchip_opa_1st', - 'vchip_opa_fd', - 'vchip_ref_comp_fe', - -] - -intentionally_missing = [ - 'activate', #use getActive and getRxPadDeactivatedMode syntax is not a good fit for python - 'temp_10ge', #temperatures already available from enum or specialized class - 'temp_adc', - 'temp_dcdc', - 'temp_fpga', - 'temp_fpgaext', - 'temp_fpgafl', - 'temp_fpgafr', - 'temp_slowadc', - 'temp_sodl', - 'temp_sodr', - 'trigger', #use sendSoftwareTrigger - 'update', #use updateServerAndFirmare - 'udp_validate', #use validateUdpConfiguration - 'udp_reconfigure', #use reconfigureUdpDestination - 'emin', #use rx_jsonpara - 'pulse', # use pulseChip pulsePixel pulsePixelNmove - 'pulsechip', - 'pulsenmove', -] - -pycmd += intentionally_missing -pycmd += dacs -missing = [] -for c in cmd: - if c not in pycmd: - print(c) - missing.append(c) - -print(f'Missing: {len(missing)} commands') \ No newline at end of file diff --git a/python/scripts/compare_with_commandline.py b/python/scripts/compare_with_commandline.py new file mode 100644 index 000000000..5d673c233 --- /dev/null +++ b/python/scripts/compare_with_commandline.py @@ -0,0 +1,133 @@ +import subprocess +import locale +out = subprocess.run(['g', 'list'], stdout = subprocess.PIPE, encoding=locale.getpreferredencoding()) +cmd = out.stdout.splitlines() +cmd.pop(0) + +from slsdet import Detector + +pycmd = dir(Detector) + +#Add commands that we should not expect as direct commands in python + + +# dacs are in general not included in the python commands and we expect to +# set them from the specialized class or using an enum +dacs = [ + 'adcvpp', + 'iodelay', + 'list', + 'rxb_lb', + 'rxb_rb', + 'v_chip', + 'vb_comp', + 'vb_comp_adc', + 'vb_comp_fe', + 'vb_cs', + 'vb_ds', + 'vb_opa_1st', + 'vb_opa_fd', + 'vb_pixbuf', + 'vb_sda', + 'vbp_colbuf', + 'vcal', + 'vcal_n', + 'vcal_p', + 'vipre_out', + 'vcas', + 'vcasc_out', + 'vcasc_sfp', + 'vcascn_pb', + 'vcascp_pb', + 'vcassh', + 'vchip_comp_adc', + 'vchip_comp_fe', + 'vchip_cs', + 'vchip_opa_1st', + 'vchip_opa_fd', + 'vchip_ref_comp_fe', + 'vcmp_ll', + 'vcmp_lr', + 'vcmp_rl', + 'vcmp_rr', + 'vcn', + 'vcom_adc1', + 'vcom_adc2', + 'vcom_cds', + 'vcp', + 'vdcsh', + 'vdd_prot', + 'vicin', + 'vin_cm', + 'vin_com', + 'vipre', + 'vipre_cds', + 'vipre_out', + 'vishaper', + 'vout_cm', + 'vref_cds', + 'vref_comp', + 'vref_comp_fe', + 'vref_ds', + 'vref_h_adc', + 'vref_l_adc', + 'vref_prech', + 'vref_rstore', + 'vrpreamp', + 'vrshaper', + 'vrshaper_n', + 'vsvn', + 'vsvp', + 'vtgstv', + 'vth1', + 'vth2', + 'vth3', + 'vtrim' +] + +intentionally_missing = [ + 'activate', #use getActive and getRxPadDeactivatedMode syntax is not a good fit for python + 'temp_10ge', #temperatures already available from enum or specialized class + 'temp_adc', + 'temp_dcdc', + 'temp_fpga', + 'temp_fpgaext', + 'temp_fpgafl', + 'temp_fpgafr', + 'temp_slowadc', + 'temp_sodl', + 'temp_sodr', + 'trigger', #use sendSoftwareTrigger + 'update', #use updateServerAndFirmare + 'udp_validate', #use validateUdpConfiguration + 'udp_reconfigure', #use reconfigureUdpDestination + 'pulse', # use pulseChip pulsePixel pulsePixelNmove + 'pulsechip', + 'pulsenmove', +] + +pycmd += intentionally_missing +pycmd += dacs +missing = [] +for c in cmd: + if c not in pycmd: + print(c) + missing.append(c) + +print(f'\nMissing: {len(missing)} commands') +print(f'Excluded: {len(dacs)} dacs') +print(f'Excluded: {len(intentionally_missing)} other commands') + + +not_in_cmd = [] +for c in pycmd: + if c.islower() and not c.startswith('_'): + if c not in cmd: + not_in_cmd.append(c) +print(f'\nCommands in Python and NOT in command line: {len(not_in_cmd)}') +for c in not_in_cmd: + print(c) + + + +# print(',\n'.join([f'\'{d}\'' for d in sorted(dacs)])) From 6cfaa92b61cee6a3fec974da81895316a17c99c0 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Thu, 10 Sep 2020 15:54:45 +0200 Subject: [PATCH 4/8] removed wrongly named functions --- python/slsdet/detector.py | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index b2c7089a5..90f10682b 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -884,38 +884,6 @@ class Detector(CppDetectorApi): def udp_dstport2(self, port): self.setDestinationUDPPort2(port) - @property - def src_udpmac(self): - return element_if_equal(self.getSourceUDPMAC()) - - @src_udpmac.setter - def src_udpmac(self, mac): - self.setSourceUDPMAC(MacAddr(mac)) - - @property - def src_udpip2(self): - return element_if_equal(self.getSourceUDPIP()) - - @src_udpip2.setter - def src_udpip2(self, ip): - self.setSourceUDPIP(IpAddr(ip)) - - @property - def src_udpip(self): - return element_if_equal(self.getSourceUDPIP()) - - @src_udpip.setter - def src_udpip(self, ip): - self.setSourceUDPIP(IpAddr(ip)) - - @property - def src_udpmac2(self): - return element_if_equal(self.getSourceUDPMAC2()) - - @src_udpmac2.setter - def src_udpmac2(self, mac): - self.setSourceUDPMAC2(MacAddr(mac)) - @property def highvoltage(self): """High voltage to the sensor in Voltage. From d70090967ddfdeb78e148911011f3b1a880b7721 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Thu, 10 Sep 2020 16:47:34 +0200 Subject: [PATCH 5/8] python funcs --- python/CMakeLists.txt | 3 +- python/scripts/compare_with_commandline.py | 3 +- python/slsdet/detector.py | 50 +++++++++++++++------- python/slsdet/jsonproxy.py | 30 ------------- python/slsdet/slowadcproxy.py | 25 ----------- python/slsdet/utils.py | 4 +- 6 files changed, 38 insertions(+), 77 deletions(-) delete mode 100644 python/slsdet/jsonproxy.py delete mode 100644 python/slsdet/slowadcproxy.py diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 2af935c94..b6017d79a 100755 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -35,8 +35,7 @@ set( PYTHON_FILES gotthard.py gotthard2.py moench.py - jsonproxy.py - slowadcproxy.py + proxy.py ctb.py jungfrau.py mythen3.py diff --git a/python/scripts/compare_with_commandline.py b/python/scripts/compare_with_commandline.py index 5d673c233..9f70004c4 100644 --- a/python/scripts/compare_with_commandline.py +++ b/python/scripts/compare_with_commandline.py @@ -8,8 +8,6 @@ from slsdet import Detector pycmd = dir(Detector) -#Add commands that we should not expect as direct commands in python - # dacs are in general not included in the python commands and we expect to # set them from the specialized class or using an enum @@ -119,6 +117,7 @@ print(f'Excluded: {len(dacs)} dacs') print(f'Excluded: {len(intentionally_missing)} other commands') + not_in_cmd = [] for c in pycmd: if c.islower() and not c.startswith('_'): diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index 90f10682b..4f1d63c18 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -11,8 +11,7 @@ detectorType = slsDetectorDefs.detectorType from .utils import element_if_equal, all_equal, get_set_bits, list_to_bitmask from .utils import Geometry, to_geo, element, reduce_time, is_iterable from . import utils as ut -from .jsonproxy import JsonProxy -from .slowadcproxy import SlowAdcProxy +from .proxy import JsonProxy, SlowAdcProxy from .registers import Register, Adc_register import datetime as dt @@ -195,6 +194,10 @@ class Detector(CppDetectorApi): def dr(self, dr): self.setDynamicRange(dr) + @property + def drlist(self): + return self.getDynamicRangeList() + @property def module_geometry(self): return to_geo(self.getModuleGeometry()) @@ -205,7 +208,7 @@ class Detector(CppDetectorApi): return element_if_equal(ms) @property - def detector_size(self): + def detsize(self): return to_geo(self.getDetectorSize()) @property @@ -244,6 +247,11 @@ class Detector(CppDetectorApi): def frames(self, n_frames): self.setNumberOfFrames(n_frames) + @property + @element + def framesl(self): + return self.getNumberOfFramesLeft() + @property @element def nframes(self): @@ -596,13 +604,14 @@ class Detector(CppDetectorApi): self.setFileFormat(format) @property + @element def findex(self): """File or Acquisition index in receiver.""" - return element_if_equal(self.getAcquisitionIndex()) + return self.getAcquisitionIndex() @findex.setter def findex(self, index): - self.setAcquisitionIndex(index) + ut.set_using_dict(self.setAcquisitionIndex, index) @property def fname(self): @@ -687,6 +696,7 @@ class Detector(CppDetectorApi): # ZMQ Streaming Parameters (Receiver<->Client) @property + @element def rx_zmqstream(self): """ Enable/ disable data streaming from receiver via zmq (eg. to GUI or to another process for further processing). \n @@ -694,11 +704,11 @@ class Detector(CppDetectorApi): Switching to Gui automatically enables data streaming in receiver. \n Switching back to command line acquire will require disabling data streaming in receiver for fast applications. """ - return element_if_equal(self.getRxZmqDataStream()) + return self.getRxZmqDataStream() @rx_zmqstream.setter - def rx_zmqdatastream(self, enable): - self.setRxZmqDataStream(enable) + def rx_zmqstream(self, enable): + ut.set_using_dict(self.setRxZmqDataStream, enable) @property def rx_zmqfreq(self): @@ -1180,19 +1190,17 @@ class Detector(CppDetectorApi): return JsonProxy(self) - - @rx_jsonpara.setter - def rx_jsonpara(self, args): - for key, value in args.items(): - self.setAdditionalJsonParameter(key, str(value)) - @property @element def rx_jsonaddheader(self): return self.getAdditionalJsonHeader() + @rx_jsonaddheader.setter + def rx_jsonaddheader(self, args): + ut.set_using_dict(self.setAdditionalJsonHeader, args) + @property - def frameindex(self): + def rx_frameindex(self): return self.getRxCurrentFrameIndex() @property @@ -1243,7 +1251,7 @@ class Detector(CppDetectorApi): """ - <<>> + <<<-----------------------Eiger specific----------------------->>> """ @@ -2263,3 +2271,13 @@ class Detector(CppDetectorApi): + """ + + <<<-----------------------Gotthard specific----------------------->>> + + """ + + @property + def exptimel(self): + t = self.getExptimeLeft() + return reduce_time(t) diff --git a/python/slsdet/jsonproxy.py b/python/slsdet/jsonproxy.py deleted file mode 100644 index a85adf630..000000000 --- a/python/slsdet/jsonproxy.py +++ /dev/null @@ -1,30 +0,0 @@ -from .utils import element_if_equal - -class JsonProxy: - """ - Proxy class to allow for intuitive setting and getting of rx_jsonpara - This class is returned by Detectr.rx_jsonpara - """ - def __init__(self, det): - self.det = det - - def __getitem__(self, key): - return element_if_equal(self.det.getAdditionalJsonParameter(key)) - - def __setitem__(self, key, value): - self.det.setAdditionalJsonParameter(key, str(value)) - - def __repr__(self): - r = element_if_equal(self.det.getAdditionalJsonHeader()) - if isinstance(r, list): - rstr = '' - for i, list_item in enumerate(r): - list_item = dict(list_item) - rstr += ''.join([f'{i}:{key}: {value}\n' for key, value in list_item.items()]) - - return rstr.strip('\n') - else: - r = dict(r) - return '\n'.join([f'{key}: {value}' for key, value in r.items()]) - - diff --git a/python/slsdet/slowadcproxy.py b/python/slsdet/slowadcproxy.py deleted file mode 100644 index 291f526a8..000000000 --- a/python/slsdet/slowadcproxy.py +++ /dev/null @@ -1,25 +0,0 @@ -from .utils import element_if_equal -from .enums import dacIndex -class SlowAdcProxy: - """ - Proxy class to allow for more intuitive reading the slow ADCs - """ - def __init__(self, det): - self.det = det - - def __getitem__(self, key): - dac_index = dacIndex(int(dacIndex.SLOW_ADC0)+key) - return element_if_equal(self.det.getSlowADC(dac_index)) - - def __repr__(self): - rstr = '' - for i in range(7): - r = element_if_equal(self.__getitem__(i)) - if isinstance(r, list): - rstr += ' '.join(f'{item} mV' for item in r) - else: - rstr += f'{i}: {r} mV\n' - - return rstr.strip('\n') - - diff --git a/python/slsdet/utils.py b/python/slsdet/utils.py index 3474cda0e..687063bda 100755 --- a/python/slsdet/utils.py +++ b/python/slsdet/utils.py @@ -111,14 +111,14 @@ def make_string_path(path): def set_using_dict(func, args): - if isinstance(args, dict): + if isinstance(args, dict) and all(isinstance(k, int) for k in args.keys()): for key, value in args.items(): func(value, [key]) else: func(args) def set_time_using_dict(func, args): - if isinstance(args, dict): + if isinstance(args, dict) and all(isinstance(k, int) for k in args.keys()): for key, value in args.items(): if isinstance(value, int): value = float(value) From 3fd32b2c9c5292143233f659af69e827af59d4fe Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Thu, 10 Sep 2020 16:47:51 +0200 Subject: [PATCH 6/8] missing file --- python/slsdet/proxy.py | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 python/slsdet/proxy.py diff --git a/python/slsdet/proxy.py b/python/slsdet/proxy.py new file mode 100644 index 000000000..9467bb288 --- /dev/null +++ b/python/slsdet/proxy.py @@ -0,0 +1,53 @@ +from .utils import element_if_equal +from .enums import dacIndex + +class JsonProxy: + """ + Proxy class to allow for intuitive setting and getting of rx_jsonpara + This class is returned by Detectr.rx_jsonpara + """ + def __init__(self, det): + self.det = det + + def __getitem__(self, key): + return element_if_equal(self.det.getAdditionalJsonParameter(key)) + + def __setitem__(self, key, value): + self.det.setAdditionalJsonParameter(key, str(value)) + + def __repr__(self): + r = element_if_equal(self.det.getAdditionalJsonHeader()) + if isinstance(r, list): + rstr = '' + for i, list_item in enumerate(r): + list_item = dict(list_item) + rstr += ''.join([f'{i}:{key}: {value}\n' for key, value in list_item.items()]) + + return rstr.strip('\n') + else: + r = dict(r) + return '\n'.join([f'{key}: {value}' for key, value in r.items()]) + + + +class SlowAdcProxy: + """ + Proxy class to allow for more intuitive reading the slow ADCs + """ + def __init__(self, det): + self.det = det + + def __getitem__(self, key): + dac_index = dacIndex(int(dacIndex.SLOW_ADC0)+key) + return element_if_equal(self.det.getSlowADC(dac_index)) + + def __repr__(self): + rstr = '' + for i in range(7): + r = element_if_equal(self.__getitem__(i)) + if isinstance(r, list): + rstr += ' '.join(f'{item} mV' for item in r) + else: + rstr += f'{i}: {r} mV\n' + + return rstr.strip('\n') \ No newline at end of file From be8284f5c22241e39df50b95343bd76e43ac325b Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 10 Sep 2020 16:57:30 +0200 Subject: [PATCH 7/8] nmod added to command line --- slsDetectorSoftware/src/CmdProxy.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index f19d06ba6..917b2fbbc 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -650,6 +650,7 @@ class CmdProxy { {"rx_version", &CmdProxy::rx_version}, {"detectornumber", &CmdProxy::detectornumber}, {"type", &CmdProxy::type}, + {"nmod", &CmdProxy::nmod}, {"detsize", &CmdProxy::DetectorSize}, {"settingslist", &CmdProxy::settingslist}, {"settings", &CmdProxy::settings}, @@ -1126,6 +1127,8 @@ class CmdProxy { GET_COMMAND(type, getDetectorType, "\n\tSerial number or MAC of detector (hex)."); + GET_COMMAND_NOID(nmod, size, "\n\tNumber of modules in shared memory."); + GET_COMMAND_NOID(settingslist, getSettingsList, "\n\tList of settings implemented for this detector."); From 00f780665f6b2ef0aee78a6d76e355146285e81e Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 10 Sep 2020 18:41:31 +0200 Subject: [PATCH 8/8] using common.c to extract date and using nios.c to check kernel version(a bit specific to nios) and using c api instead of system command to get uname --- .../slsDetectorFunctionList.c | 43 +-------------- .../slsDetectorFunctionList.c | 42 +------------- .../slsDetectorServer/include/common.h | 5 +- .../slsDetectorServer/include/nios.h | 4 ++ .../slsDetectorServer/src/common.c | 10 ++++ .../slsDetectorServer/src/nios.c | 55 ++++++++++++++++++- 6 files changed, 74 insertions(+), 85 deletions(-) diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index 15f2ac1e5..6dbebe529 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -1,4 +1,3 @@ -#define _GNU_SOURCE // needed for strptime to be at the top #include "slsDetectorFunctionList.h" #include "ALTERA_PLL_CYCLONE10.h" #include "ASIC_Driver.h" @@ -15,10 +14,10 @@ #include #include -#include #include // usleep #ifdef VIRTUAL #include +#include #endif // Global variable from slsDetectorServer_funcs @@ -182,45 +181,7 @@ int checkKernelVersion() { #ifdef VIRTUAL return OK; #endif - - // extract kernel date string - char output[256]; - memset(output, 0, 256); - FILE *sysFile = popen("uname -a | cut -d ' ' -f5-10", "r"); - fgets(output, sizeof(output), sysFile); - pclose(sysFile); - // remove end line - output[strlen(output) - 1] = '\0'; - - // convert kernel date string into time - struct tm kernelDate; - if (NULL == strptime(output, "%a %b %d %H:%M:%S %Z %Y", &kernelDate)) { - LOG(logERROR, ("Could not parse retrieved kernel date, %s\n", output)); - return FAIL; - } - time_t t_kernelDate = mktime(&kernelDate); - - // convert expected date into time - struct tm expDate; - if (NULL == - strptime(KERNEL_DATE_VRSN, "%a %b %d %H:%M:%S %Z %Y", &expDate)) { - LOG(logERROR, - ("Could not parse expected kernel date, %s\n", KERNEL_DATE_VRSN)); - return FAIL; - } - time_t t_expDate = mktime(&expDate); - - // compare if kernel time is older than expected time - if (t_kernelDate < t_expDate) { - LOG(logERROR, - ("Kernel Version Incompatible (too old)! Expected: %s, Got %s\n", - KERNEL_DATE_VRSN, output)); - return FAIL; - } - - LOG(logINFOBLUE, ("Kernel Version Compatible: %s [min.: %s]\n", output, - KERNEL_DATE_VRSN)); - return OK; + return Nios_checkKernelVersion(KERNEL_DATE_VRSN); } int checkType() { diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index 178f380d4..a220412ff 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -1,4 +1,3 @@ -#define _GNU_SOURCE // needed for strptime to be at the top #include "slsDetectorFunctionList.h" #include "ALTERA_PLL_CYCLONE10.h" #include "DAC6571.h" @@ -14,10 +13,10 @@ #include #include -#include #include // usleep #ifdef VIRTUAL #include +#include #endif // Global variable from slsDetectorServer_funcs @@ -169,44 +168,7 @@ int checkKernelVersion() { return OK; #endif - // extract kernel date string - char output[256]; - memset(output, 0, 256); - FILE *sysFile = popen("uname -a | cut -d ' ' -f5-10", "r"); - fgets(output, sizeof(output), sysFile); - pclose(sysFile); - // remove end line - output[strlen(output) - 1] = '\0'; - - // convert kernel date string into time - struct tm kernelDate; - if (NULL == strptime(output, "%a %b %d %H:%M:%S %Z %Y", &kernelDate)) { - LOG(logERROR, ("Could not parse retrieved kernel date, %s\n", output)); - return FAIL; - } - time_t t_kernelDate = mktime(&kernelDate); - - // convert expected date into time - struct tm expDate; - if (NULL == - strptime(KERNEL_DATE_VRSN, "%a %b %d %H:%M:%S %Z %Y", &expDate)) { - LOG(logERROR, - ("Could not parse expected kernel date, %s\n", KERNEL_DATE_VRSN)); - return FAIL; - } - time_t t_expDate = mktime(&expDate); - - // compare if kernel time is older than expected time - if (t_kernelDate < t_expDate) { - LOG(logERROR, - ("Kernel Version Incompatible (too old)! Expected: %s, Got %s\n", - KERNEL_DATE_VRSN, output)); - return FAIL; - } - - LOG(logINFOBLUE, ("Kernel Version Compatible: %s [min.: %s]\n", output, - KERNEL_DATE_VRSN)); - return OK; + return Nios_checkKernelVersion(KERNEL_DATE_VRSN); } int checkType() { diff --git a/slsDetectorServers/slsDetectorServer/include/common.h b/slsDetectorServers/slsDetectorServer/include/common.h index fed3cbbf2..1f2ebbe42 100644 --- a/slsDetectorServers/slsDetectorServer/include/common.h +++ b/slsDetectorServers/slsDetectorServer/include/common.h @@ -1,6 +1,7 @@ #pragma once #include +#include /** * Convert a value from a range to a different range (eg voltage to dac or vice @@ -16,4 +17,6 @@ int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int outputMax, int inputValue, int *outputValue); -int getAbsPath(char *buf, size_t bufSize, char *fname); \ No newline at end of file +int getAbsPath(char *buf, size_t bufSize, char *fname); + +int GetTimeFromString(char *buf, time_t *result); \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/include/nios.h b/slsDetectorServers/slsDetectorServer/include/nios.h index d8b0ac2b4..128f556cf 100644 --- a/slsDetectorServers/slsDetectorServer/include/nios.h +++ b/slsDetectorServers/slsDetectorServer/include/nios.h @@ -87,3 +87,7 @@ int mapCSP0(void); * Get Nios base address */ u_int32_t *Nios_getBaseAddress(); + +/** check kernel version against expected version string (complain if too old) + * @returns OK or FAIL */ +int Nios_checkKernelVersion(char *expectedVersion); \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/common.c b/slsDetectorServers/slsDetectorServer/src/common.c index 04af3bb11..5d2cb5c1a 100644 --- a/slsDetectorServers/slsDetectorServer/src/common.c +++ b/slsDetectorServers/slsDetectorServer/src/common.c @@ -1,3 +1,4 @@ +#define _GNU_SOURCE // needed for strptime to be at the top #include "common.h" #include "clogger.h" #include "sls_detector_defs.h" @@ -59,4 +60,13 @@ int getAbsPath(char *buf, size_t bufSize, char *fname) { sprintf(buf, "%s/%s", dir, fname); LOG(logDEBUG1, ("full path for %s: %s\n", fname, buf)); return OK; +} + +int GetTimeFromString(char *buf, time_t *result) { + struct tm t; + if (NULL == strptime(buf, "%a %b %d %H:%M:%S %Z %Y", &t)) { + return FAIL; + } + *result = mktime(&t); + return OK; } \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/nios.c b/slsDetectorServers/slsDetectorServer/src/nios.c index 7a1e4b619..82fbbcc07 100644 --- a/slsDetectorServers/slsDetectorServer/src/nios.c +++ b/slsDetectorServers/slsDetectorServer/src/nios.c @@ -2,10 +2,13 @@ #include "RegisterDefs.h" #include "ansi.h" #include "clogger.h" +#include "common.h" #include "sls_detector_defs.h" -#include // open -#include // mmap +#include // open +#include +#include // mmap +#include // uname /* global variables */ u_int32_t *csp0base = 0; @@ -126,4 +129,50 @@ int mapCSP0(void) { return OK; } -u_int32_t *Nios_getBaseAddress() { return csp0base; } \ No newline at end of file +u_int32_t *Nios_getBaseAddress() { return csp0base; } + +int Nios_checkKernelVersion(char *expectedVersion) { + // extract kernel date string + struct utsname buf; + if (uname(&buf) == -1) { + LOG(logERROR, ("Could not get kernel version\n")); + return FAIL; + } + + // remove first word (#version number) + const char *ptr = strchr(buf.version, ' '); + if (ptr == NULL) { + LOG(logERROR, ("Could not parse kernel version\n")); + return FAIL; + } + char output[256]; + memset(output, 0, 256); + strcpy(output, buf.version + (ptr - buf.version + 1)); + + // convert kernel date string into time + time_t kernelDate; + if (GetTimeFromString(output, &kernelDate) == FAIL) { + LOG(logERROR, ("Could not parse retrieved kernel date, %s\n", output)); + return FAIL; + } + + // convert expected date into time + time_t expDate; + if (GetTimeFromString(expectedVersion, &expDate) == FAIL) { + LOG(logERROR, + ("Could not parse expected kernel date, %s\n", expectedVersion)); + return FAIL; + } + + // compare if kernel time is older than expected time + if (kernelDate < expDate) { + LOG(logERROR, ("Kernel Version Incompatible (too old)! Expected: [%s], " + "Got [%s]\n", + expectedVersion, output)); + return FAIL; + } + + LOG(logINFOBLUE, ("Kernel Version Compatible: %s [min.: %s]\n", output, + expectedVersion)); + return OK; +} \ No newline at end of file