Skip to content

Commit

Permalink
Some cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefal committed Dec 22, 2024
1 parent 978fe21 commit 24db999
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
11 changes: 9 additions & 2 deletions tools/sept_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down
18 changes: 14 additions & 4 deletions tools/septentrio/septentrio_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down
17 changes: 8 additions & 9 deletions tools/unicore/unicore_gnss/unicore_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,27 @@ def __init__(

def connect(self) -> None:
'''
Connect to the Unicore receiver
Check the connection to the Unicore receiver
'''
log.debug("Connecting...")
try:
# Send a line return to clear the Unicore input buffer
# 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):
Expand Down
2 changes: 1 addition & 1 deletion tools/unicore_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 24db999

Please sign in to comment.