diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-01-23 11:00:02 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-01-23 11:00:02 +0100 |
commit | 201d711a1d3dfbe46d622871731005937598e790 (patch) | |
tree | e43a95ee027e1be6ca8621f9e2c78aaf932a3421 /python/lib | |
parent | 674228bedb325384f12602350ab36d075b5509a3 (diff) | |
parent | e0abfc3728fb56519fa2507d2468214e2a633c98 (diff) | |
download | dabmod-201d711a1d3dfbe46d622871731005937598e790.tar.gz dabmod-201d711a1d3dfbe46d622871731005937598e790.tar.bz2 dabmod-201d711a1d3dfbe46d622871731005937598e790.zip |
Merge branch 'next' into lime
Diffstat (limited to 'python/lib')
-rw-r--r-- | python/lib/yamlrpc.py | 9 | ||||
-rw-r--r-- | python/lib/zmqrc.py | 11 |
2 files changed, 12 insertions, 8 deletions
diff --git a/python/lib/yamlrpc.py b/python/lib/yamlrpc.py index d963601..67c65ff 100644 --- a/python/lib/yamlrpc.py +++ b/python/lib/yamlrpc.py @@ -23,6 +23,9 @@ """yamlrpc is json-rpc, except that it's yaml and not json.""" +# This maybe won't work over ethernet, but for localhost it's ok +UDP_PACKETSIZE = 2048 + # Same as jsonrpc version we're aiming to mirror in YAML YAMLRPC_VERSION = "2.0" @@ -80,9 +83,9 @@ class Socket: def receive_response(self, expected_msg_id: int): try: - data, addr = self.socket.recvfrom(512) + data, addr = self.socket.recvfrom(UDP_PACKETSIZE) except socket.timeout as to: - raise TimeoutError("Timeout: " + str(to)) + raise TimeoutError() y = yaml.load(data.decode()) @@ -117,7 +120,7 @@ class Socket: def receive_request(self): try: - data, addr = self.socket.recvfrom(512) + data, addr = self.socket.recvfrom(UDP_PACKETSIZE) except socket.timeout as to: raise TimeoutError("Timeout: " + str(to)) diff --git a/python/lib/zmqrc.py b/python/lib/zmqrc.py index 3897d7a..423f91d 100644 --- a/python/lib/zmqrc.py +++ b/python/lib/zmqrc.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # Copyright (C) 2018 @@ -22,15 +22,16 @@ # along with ODR-DabMod. If not, see <http://www.gnu.org/licenses/>. import zmq import json +from typing import List -class ModRemoteControl(object): +class ModRemoteControl: """Interact with ODR-DabMod using the ZMQ RC""" def __init__(self, mod_host, mod_port=9400): self._host = mod_host self._port = mod_port self._ctx = zmq.Context() - def _read(self, message_parts): + def _read(self, message_parts: List[str]): sock = zmq.Socket(self._ctx, zmq.REQ) sock.setsockopt(zmq.LINGER, 0) sock.connect("tcp://{}:{}".format(self._host, self._port)) @@ -70,14 +71,14 @@ class ModRemoteControl(object): return modules - def get_param_value(self, module, param): + def get_param_value(self, module: str, param: str) -> str: value = self._read(['get', module, param]) if value[0] == 'fail': raise ValueError("Error getting param: {}".format(value[1])) else: return value[0] - def set_param_value(self, module, param, value): + def set_param_value(self, module: str, param: str, value: str) -> None: ret = self._read(['set', module, param, value]) if ret[0] == 'fail': raise ValueError("Error setting param: {}".format(ret[1])) |