From a8f39e103fac1fbdc0382e26e1bf73a2d8f16807 Mon Sep 17 00:00:00 2001 From: Stefal Date: Thu, 13 Jun 2024 18:24:12 +0200 Subject: [PATCH] add retry to the mosaic sept_tool and during the configuration --- tools/install.sh | 12 +++++------- tools/sept_tool.py | 24 +++++++++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/tools/install.sh b/tools/install.sh index 00d37dd..0d2ea1f 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -528,20 +528,18 @@ configure_gnss(){ sudo -u "${RTKBASE_USER}" sed -i -r '/^rtcm_/s/1107(\([0-9]+\))?,//' "${rtkbase_path}"/settings.conf && \ return $? - elif [[ $(python3 "${rtkbase_path}"/tools/sept_tool.py --port /dev/ttyGNSS_CTRL --baudrate ${com_port_settings%%:*} --command get_model) =~ 'mosaic-X5' ]] + elif [[ $(python3 "${rtkbase_path}"/tools/sept_tool.py --port /dev/ttyGNSS_CTRL --baudrate ${com_port_settings%%:*} --command get_model --retry 5) =~ 'mosaic-X5' ]] then #get mosaic-X5 firmware release - firmware="$(python3 "${rtkbase_path}"/tools/sept_tool.py --port /dev/ttyGNSS_CTRL --baudrate ${com_port_settings%%:*} --command get_firmware)" || firmware='?' + firmware="$(python3 "${rtkbase_path}"/tools/sept_tool.py --port /dev/ttyGNSS_CTRL --baudrate ${com_port_settings%%:*} --command get_firmware --retry 5)" || firmware='?' echo 'Mosaic-X5 Firmware: ' "${firmware}" sudo -u "${RTKBASE_USER}" sed -i s/^receiver_firmware=.*/receiver_firmware=\'${firmware}\'/ "${rtkbase_path}"/settings.conf #configure the mosaic-X5 for RTKBase echo 'Resetting the mosaic-X5 settings....' - python3 "${rtkbase_path}"/tools/sept_tool.py --port /dev/ttyGNSS_CTRL --baudrate ${com_port_settings%%:*} --command reset - sleep_time=60 - echo 'Waiting '$sleep_time's for mosaic-X5 reboot' - sleep $sleep_time + python3 "${rtkbase_path}"/tools/sept_tool.py --port /dev/ttyGNSS_CTRL --baudrate ${com_port_settings%%:*} --command reset --retry 5 + sleep_time=20 ; echo 'Waiting '$sleep_time's for mosaic-X5 reboot' ; sleep $sleep_time echo 'Sending settings....' - python3 "${rtkbase_path}"/tools/sept_tool.py --port /dev/ttyGNSS_CTRL --baudrate ${com_port_settings%%:*} --command send_config_file "${rtkbase_path}"/receiver_cfg/Septentrio_Mosaic-X5.cfg --store + python3 "${rtkbase_path}"/tools/sept_tool.py --port /dev/ttyGNSS_CTRL --baudrate ${com_port_settings%%:*} --command send_config_file "${rtkbase_path}"/receiver_cfg/Septentrio_Mosaic-X5.cfg --store --retry 5 systemctl enable --now rtkbase_gnss_web_proxy.service #won't work during installation but, needed after a detect&configure from the gui. sudo -u "${RTKBASE_USER}" sed -i s/^com_port_settings=.*/com_port_settings=\'115200:8:n:1\'/ "${rtkbase_path}"/settings.conf && \ sudo -u "${RTKBASE_USER}" sed -i s/^receiver=.*/receiver=\'Septentrio_Mosaic-X5\'/ "${rtkbase_path}"/settings.conf && \ diff --git a/tools/sept_tool.py b/tools/sept_tool.py index 87f26c5..5c06738 100644 --- a/tools/sept_tool.py +++ b/tools/sept_tool.py @@ -23,6 +23,7 @@ def arg_parse(): parser.add_argument("-b", "--baudrate", help="port baudrate", default=115200, type=int) parser.add_argument("-c", "--command", nargs='+', help="Command to send to the gnss receiver", type=str) parser.add_argument("-s", "--store", action='store_true', help="Store settings as permanent", default=False) + parser.add_argument("-r", "--retry", help="set a number of retry if the command fails", default=0, type=int) parser.add_argument("--version", action="version", version="%(prog)s 0.1") args = parser.parse_args() #print(args) @@ -32,10 +33,19 @@ def arg_parse(): args = arg_parse() #print(args) command = args.command[0] - with SeptGnss(args.port, baudrate=args.baudrate, timeout=30, debug=False) as gnss: - res = methodcaller(CmdMapping[command].value, *args.command[1:])(gnss) - if type(res) is str: - print(res) - if args.store: - gnss.set_config_permanent() - #methodcaller(args.command[0])(gnss) \ No newline at end of file + retries = 0 + retry_delay = 10 + while retries <= args.retry: + try: + with SeptGnss(args.port, baudrate=args.baudrate, timeout=30, debug=False) as gnss: + res = methodcaller(CmdMapping[command].value, *args.command[1:])(gnss) + if type(res) is str: + print(res) + if args.store: + gnss.set_config_permanent() + #methodcaller(args.command[0])(gnss) + break + except: + retries += 1 + print("Retrying in {}s".format(retry_delay)) + time.sleep(retry_delay) \ No newline at end of file