From 1fd55093f8facea767ab81fe621fa1af3bf0c5e7 Mon Sep 17 00:00:00 2001 From: Yannis Chatzikonstantinou Date: Mon, 25 Sep 2023 21:01:08 +0300 Subject: [PATCH 1/2] add bus, channel and bitrate arguments to dfu util --- studio/Python/tinymovr/dfu.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/studio/Python/tinymovr/dfu.py b/studio/Python/tinymovr/dfu.py index c93f258b..4b1c8d3e 100644 --- a/studio/Python/tinymovr/dfu.py +++ b/studio/Python/tinymovr/dfu.py @@ -1,12 +1,15 @@ """ Usage: - dfu.py --node_id=ID [--bin=PATH | --recovery] [--no-reset] + dfu.py --node_id=ID [--bin=PATH | --recovery] [--no-reset] [--bus=] [--chan=] [--bitrate=] Options: --node_id=ID The CAN Node ID of the device in DFU mode. --bin=PATH The path of the .bin file to upload. --recovery Perform recovery procedure for inaccessible DFU bootloader. --no-reset Do not perform a reset following successful flashing. + --bus= One or more interfaces to use, first available is used [default: canine,slcan_disco]. + --chan= The bus device "channel". + --bitrate= CAN bitrate [default: 1000000]. """ import sys @@ -123,15 +126,22 @@ def upload_bin(device, bin_path): def spawn(): # Parse command line arguments - args = docopt(__doc__) - node_id = int(args["--node_id"]) - bin_path = args["--bin"] + arguments = docopt(__doc__) + node_id = int(arguments["--node_id"]) + bin_path = arguments["--bin"] # Set up the device - params = get_bus_config(["canine", "slcan_disco"]) - params["bitrate"] = 1000000 + buses = arguments["--bus"].rsplit(sep=",") + channel = arguments["--chan"] + bitrate = int(arguments["--bitrate"]) - if args["--recovery"]: + if not channel: + params = get_bus_config(buses) + params["bitrate"] = bitrate + else: + params = {"bustype": buses[0], "channel": channel, "bitrate": bitrate} + + if arguments["--recovery"]: input("Please power off the device and then press any key to continue...") print("Now power on the device.") @@ -162,7 +172,7 @@ def spawn(): else: upload_bin(device, bin_path) compare_bin_w_device(device, bin_path, string="Verifying") - if not args["--no-reset"]: + if not arguments["--no-reset"]: print("Resetting device...") device.reset() destroy_tee() From cd115d295f8a487a56ea15a8e636d4ad505062ef Mon Sep 17 00:00:00 2001 From: Yannis Chatzikonstantinou Date: Mon, 25 Sep 2023 21:15:49 +0300 Subject: [PATCH 2/2] populate timing information --- studio/Python/tinymovr/gui/window.py | 4 ++-- studio/Python/tinymovr/gui/worker.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/studio/Python/tinymovr/gui/window.py b/studio/Python/tinymovr/gui/window.py index c42b2d54..1e411c79 100644 --- a/studio/Python/tinymovr/gui/window.py +++ b/studio/Python/tinymovr/gui/window.py @@ -319,9 +319,9 @@ def timings_updated(self, timings_dict): meas_freq = timings_dict["meas_freq"] meas_freq_str = "-" if meas_freq == 0 else "{:.1f}Hz".format(meas_freq) self.status_label.setText( - "{}\t CH:{:.0f}%\t RT:{:.1f}ms".format( + "{}\t Load:{:.0f}%\t RT:{:.1f}ms".format( meas_freq_str, - timings_dict["load"], + timings_dict["load"] * 100, timings_dict["getter_dt"] * 1000, ) ) diff --git a/studio/Python/tinymovr/gui/worker.py b/studio/Python/tinymovr/gui/worker.py index 24d4ea96..29b0e3b3 100644 --- a/studio/Python/tinymovr/gui/worker.py +++ b/studio/Python/tinymovr/gui/worker.py @@ -43,6 +43,10 @@ def __init__(self, busparams, logger): ) self.timed_getter = TimedGetter() + self.dt_update = 1 + self.dt_load = 0 + self.t_last_update = time.time() + @QtCore.Slot() def stop(self): destroy_tee() @@ -102,12 +106,17 @@ def _init_containers(self): self.dynamic_attrs_last_update = {} def _update(self): + t = time.time() + self.dt_update = self.dt_update * 0.95 + (t - self.t_last_update) * 0.05 + self.t_last_update = t self.mutx.lock() + t = time.time() last_updated = self._get_attr_values() + self.dt_load = self.dt_load * 0.95 + (time.time() - t) * 0.05 if len(last_updated) > 0: self.updateAttrsSignal.emit(last_updated) self.updateTimingsSignal.emit( - {"meas_freq": 0, "load": 0, "getter_dt": self.timed_getter.dt} + {"meas_freq": 1/self.dt_update, "load": self.dt_load/self.dt_update, "getter_dt": self.timed_getter.dt} ) self.mutx.unlock()