From 24db999b7b63692868f12fa484e91c504c0f1e09 Mon Sep 17 00:00:00 2001 From: Stefal Date: Sun, 22 Dec 2024 10:40:39 +0000 Subject: [PATCH] Some cleaning --- tools/sept_tool.py | 11 +++++++++-- tools/septentrio/septentrio_cmd.py | 18 ++++++++++++++---- tools/unicore/unicore_gnss/unicore_cmd.py | 17 ++++++++--------- tools/unicore_tool.py | 2 +- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/tools/sept_tool.py b/tools/sept_tool.py index 843c190..36d118f 100644 --- a/tools/sept_tool.py +++ b/tools/sept_tool.py @@ -3,10 +3,15 @@ import os import sys import argparse +import logging from septentrio.septentrio_cmd import * from enum import Enum from operator import methodcaller +logging.basicConfig(format='%(levelname)s: %(message)s') +log = logging.getLogger(__name__) +log.setLevel('ERROR') + class CmdMapping(Enum): """Mapping human command to septentrio_cmd methods""" @@ -34,7 +39,8 @@ def arg_parse(): if __name__ == '__main__': args = arg_parse() if args.debug: - print(args) + log.setLevel('DEBUG') + log.debug(f"Arguments: {args}") command = args.command[0] retries = 0 retry_delay = 2 @@ -47,7 +53,8 @@ def arg_parse(): if args.store: gnss.set_config_permanent() break - except: + except Exception as e: + log.debug("Exception: ",e) retries += 1 if retries <= args.retry: print("Failed...retrying in {}s".format(retry_delay)) diff --git a/tools/septentrio/septentrio_cmd.py b/tools/septentrio/septentrio_cmd.py index 6788a9a..c7d1495 100644 --- a/tools/septentrio/septentrio_cmd.py +++ b/tools/septentrio/septentrio_cmd.py @@ -11,7 +11,9 @@ log.setLevel('ERROR') class SeptGnss: - """Class for sending command to Septentrio Gnss receivers""" + """Class for sending command to Septentrio Gnss receivers + Recommended use is on the ttyGNSS_CTRL port which doesn't receive + any rtcm/raw data""" def __init__( self, @@ -33,10 +35,15 @@ def __init__( self.connect() def connect(self) -> None: + ''' + Check the connection to the Septentrio receiver + ''' + log.debug("Connecting") try: - log.debug("Connecting") self.comm.device_serial.reset_input_buffer() self.comm.send('exeEchoMessage, COM1, "A:HELLO", none') + # The raw return should be + #b'$R: exeEchoMessage, COM1, "A:HELLO", none\r\n EchoMessage, COM1, "A:HELLO", none\r\nUSB2>' read = self.comm.read_until_line("A:HELLO") read = self.comm.device_serial.readline() #line we don't need read = self.comm.read_raw(5) #reading next 5 chars to get connection descriptor @@ -49,12 +56,13 @@ def connect(self) -> None: log.debug("GNSS receiver connected, debug mode enabled") log.debug("Connection descriptor: {}".format(self.comm.connection_descriptor)) except Exception as e: - print("GNSS receiver did not respond correctly") - log.debug(read) + log.warning("GNSS receiver did not respond correctly") + log.debug(read if read else "No response") log.debug("Exception: ", e) self.close() def close(self) -> None: + log.debug("Closing connection") self.comm.close() def __enter__(self): @@ -138,6 +146,7 @@ def set_config_permanent(self) -> None: def send_read_lines(self, cmd, *args) -> list: log.debug("Sending: {}{}{}".format(cmd, ', ' if args else '', ', '.join(args))) + self.comm.device_serial.reset_input_buffer() self.comm.send("{}{}{}".format(cmd, ', ' if args else '', ', '.join(args))) read = self.comm.read_lines() log.debug("Receiving: {}".format(read)) @@ -147,6 +156,7 @@ def send_read_lines(self, cmd, *args) -> list: def send_read_until(self, cmd, *args) -> list: log.debug("Sending: {}{}{}".format(cmd, ', ' if args else '', ', '.join(args))) + self.comm.device_serial.reset_input_buffer() self.comm.send("{}{}{}".format(cmd, ', ' if args else '', ', '.join(args))) read = self.comm.read_until() log.debug("Receiving: {}".format(read)) diff --git a/tools/unicore/unicore_gnss/unicore_cmd.py b/tools/unicore/unicore_gnss/unicore_cmd.py index 0d84472..0be3bce 100644 --- a/tools/unicore/unicore_gnss/unicore_cmd.py +++ b/tools/unicore/unicore_gnss/unicore_cmd.py @@ -38,7 +38,7 @@ def __init__( def connect(self) -> None: ''' - Connect to the Unicore receiver + Check the connection to the Unicore receiver ''' log.debug("Connecting...") try: @@ -46,20 +46,19 @@ def connect(self) -> None: # It was a problem when the ubxtool was sending some commands without LF just before the unicore detection script. self.comm.send('\r\n') if self.get_receiver_model(): - #print("GNSS receiver connected") + log.debug("GNSS receiver connected, debug mode enabled") + log.debug("read: {}".format(read)) return else: - raise Exception - log.debug("GNSS receiver connected, debug mode enabled") - log.debug("read: {}".format(read)) - + raise Exception except Exception as e: - log.warning("GNSS receiver did not respond correctly. Closing serial port.") - log.warning(e) - #log.debug(read) + log.warning("GNSS receiver did not respond correctly") + log.debug(read if read else "No response") + log.debug("Exception: ", e) self.close() def close(self) -> None: + log.debug("Closing connection") self.comm.close() def __enter__(self): diff --git a/tools/unicore_tool.py b/tools/unicore_tool.py index a0e9591..680f1f3 100644 --- a/tools/unicore_tool.py +++ b/tools/unicore_tool.py @@ -45,7 +45,7 @@ def arg_parse(): retry_delay = 2 while retries <= args.retry: try: - with UnicoGnss(args.port, baudrate=args.baudrate, timeout=2, debug=False) as gnss: + with UnicoGnss(args.port, baudrate=args.baudrate, timeout=2, debug=args.debug) as gnss: res = methodcaller(CmdMapping[command].value, *args.command[1:])(gnss) if type(res) is str: print(res)