Skip to content

Commit

Permalink
Merge pull request #448 from Stefal/unicore_um980
Browse files Browse the repository at this point in the history
support for Unicore um98x (rtcm3 mode)
  • Loading branch information
Stefal authored Dec 21, 2024
2 parents 8507b38 + 823d0dc commit 3cfade8
Show file tree
Hide file tree
Showing 14 changed files with 684 additions and 18 deletions.
17 changes: 17 additions & 0 deletions receiver_cfg/Unicore_UM980_rtcm3.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Config file for using a Unicore UM980 with RTKBase (RTCM3)
# SIGNALGROUP will reset the device
CONFIG SIGNALGROUP 2
CONFIG SBAS ENABLE AUTO
MODE BASE 1 TIME 60 1
rtcm1019 1
rtcm1020 1
rtcm1042 1
rtcm1044 1
rtcm1045 1
rtcm1046 1
rtcm1077 1
rtcm1087 1
rtcm1097 1
rtcm1107 1
rtcm1117 1
rtcm1127 1
17 changes: 17 additions & 0 deletions receiver_cfg/Unicore_UM982_rtcm3.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Config file for using a Unicore UM982 with RTKBase (RTCM3)
# SIGNALGROUP will reset the device
CONFIG SIGNALGROUP 7 0
CONFIG SBAS ENABLE AUTO
MODE BASE 1 TIME 60 1
rtcm1019 1
rtcm1020 1
rtcm1042 1
rtcm1044 1
rtcm1045 1
rtcm1046 1
rtcm1077 1
rtcm1087 1
rtcm1097 1
rtcm1107 1
rtcm1117 1
rtcm1127 1
44 changes: 38 additions & 6 deletions tools/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ install_unit_files() {
#Add dialout group to user
usermod -a -G dialout "${RTKBASE_USER}"
else
echo 'RtkBase not installed, use option --rtkbase-release or any other rtkbase installation option.'
echo 'RtkBase is not installed, use option --rtkbase-release or any other rtkbase installation option.'
fi
}

Expand Down Expand Up @@ -420,7 +420,8 @@ detect_gnss() {
echo 'UART GNSS RECEIVER DETECTION'
echo '################################'
systemctl is-active --quiet str2str_tcp.service && sudo systemctl stop str2str_tcp.service && echo 'Stopping str2str_tcp service'
for port in ttyS1 serial0 ttyS2 ttyS3 ttyS0; do
# TODO remove port if not available in /dev/
for port in ttyS0 ttyUSB0 ttyUSB1 ttyUSB2 serial0 ttyS1 ttyS2 ttyS3; do
for port_speed in 115200 57600 38400 19200 9600; do
echo 'DETECTION ON ' $port ' at ' $port_speed
if [[ $(python3 "${rtkbase_path}"/tools/ubxtool -f /dev/$port -s $port_speed -p MON-VER -w 5 2>/dev/null) =~ 'ZED-F9P' ]]; then
Expand All @@ -429,6 +430,12 @@ detect_gnss() {
detected_gnss[2]=$port_speed
#echo 'U-blox ZED-F9P DETECTED ON '$port $port_speed
break
elif { model=$(python3 "${rtkbase_path}"/tools/unicore_tool.py --port /dev/$port --baudrate $port_speed --command get_model 2>/dev/null) ; [[ "${model}" == 'UM98'[0-2] ]] ;}; then
detected_gnss[0]=$port
detected_gnss[1]='unicore'
detected_gnss[2]=$port_speed
#echo 'Unicore ' "${model}" ' DETECTED ON '$port $port_speed
break
fi
sleep 1
done
Expand Down Expand Up @@ -530,6 +537,7 @@ configure_gnss(){
if [[ $? -eq 0 ]]
then
echo 'Septentrio Mosaic-X5 successfuly configured'
# Enable the proxy for the Mosaic Web interface.
systemctl list-unit-files rtkbase_gnss_web_proxy.service &>/dev/null && \
systemctl enable --now rtkbase_gnss_web_proxy.service && \
sudo -u "${RTKBASE_USER}" sed -i s/^com_port_settings=.*/com_port_settings=\'115200:8:n:1\'/ "${rtkbase_path}"/settings.conf && \
Expand All @@ -539,17 +547,41 @@ configure_gnss(){
sudo -u "${RTKBASE_USER}" sed -i s/^min_free_space=.*/min_free_space=\'1500\'/ "${rtkbase_path}"/settings.conf

return $?
else
echo 'Failed to configure the Gnss receiver'
return 1
fi

elif { model=$(python3 "${rtkbase_path}"/tools/unicore_tool.py --port /dev/${com_port} --baudrate ${com_port_settings%%:*} --command get_model 2>/dev/null) ; [[ "${model}" == 'UM98'[0-2] ]] ;}
then
#get UM98x firmware release
firmware="$(python3 "${rtkbase_path}"/tools/unicore_tool.py --port /dev/${com_port} --baudrate ${com_port_settings%%:*} --command get_firmware 2>/dev/null)" || firmware='?'
echo 'Unicore-' "${model}" 'Firmware: ' "${firmware}"
sudo -u "${RTKBASE_USER}" sed -i s/^receiver_firmware=.*/receiver_firmware=\'${firmware}\'/ "${rtkbase_path}"/settings.conf
#configure the UM980/UM982 for RTKBase
echo 'Resetting the ' "${model}" ' settings....'
python3 "${rtkbase_path}"/tools/unicore_tool.py --port /dev/${com_port} --baudrate ${com_port_settings%%:*} --command reset --retry 5
sleep_time=10 ; echo 'Waiting '$sleep_time's for ' "${model}" ' reboot' ; sleep $sleep_time
echo 'Sending settings....'
python3 "${rtkbase_path}"/tools/unicore_tool.py --port /dev/${com_port} --baudrate ${com_port_settings%%:*} --command send_config_file "${rtkbase_path}"/receiver_cfg/Unicore_"${model}"_rtcm3.cfg --store --retry 2
if [[ $? -eq 0 ]]
then
echo 'Unicore UM980 successfuly configured'
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=\'Unicore_$model\'/ "${rtkbase_path}"/settings.conf && \
sudo -u "${RTKBASE_USER}" sed -i s/^receiver_format=.*/receiver_format=\'rtcm3\'/ "${rtkbase_path}"/settings.conf
#UM980 archives a bigger, we need more remaining space to compress archives
sudo -u "${RTKBASE_USER}" sed -i s/^min_free_space=.*/min_free_space=\'1500\'/ "${rtkbase_path}"/settings.conf

return $?
else
echo 'Failed to configure the Gnss receiver'
return 1
fi

else
echo 'No Gnss receiver has been set. We can'\''t configure'
return 1
fi
else
echo 'RtkBase not installed, use option --rtkbase-release'
echo 'RtkBase is not installed, use option --rtkbase-release'
return 1
fi
}
Expand Down
21 changes: 11 additions & 10 deletions tools/sept_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
from operator import methodcaller

class CmdMapping(Enum):
"""Mapping human command to septentrio methods"""
"""Mapping human command to septentrio_cmd methods"""

#get_model = methodcaller('get_receiver_model')
get_model = 'get_receiver_model'
get_firmware = 'get_receiver_firmware'
get_ip = 'get_receiver_ip'
Expand All @@ -21,36 +20,38 @@ def arg_parse():
""" Parse the command line you use to launch the script """

parser= argparse.ArgumentParser(prog='Septentrio tool', description="A tool to send comment to a Septentrio GNSS receiver")
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-p", "--port", help="Port to connect to", type=str)
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("-c", "--command", nargs='+', help="Command to send to the gnss receiver.\nAvailable commands are: 'get_model' 'get_firmware' 'reset' 'send_config_file'", 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 1.0")
parser.add_argument("-d", "--debug", action='store_true')
parser.add_argument("--version", action="version", version="%(prog)s 1.1")
args = parser.parse_args()
#print(args)
return args

if __name__ == '__main__':
args = arg_parse()
#print(args)
if args.debug:
print(args)
command = args.command[0]
retries = 0
retry_delay = 10
while retries <= args.retry:
try:
with SeptGnss(args.port, baudrate=args.baudrate, timeout=30, debug=False) as gnss:
with SeptGnss(args.port, baudrate=args.baudrate, timeout=30, debug=args.debug) 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("Failed...retrying in {}s".format(retry_delay))
time.sleep(retry_delay)
if retries <= args.retry:
print("Failed...retrying in {}s".format(retry_delay))
time.sleep(retry_delay)
if retries > args.retry:
print("Command failed!")
sys.exit(1)
9 changes: 9 additions & 0 deletions tools/unicore/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

[project]
name = "unicore_gnss"
version = "0.0.1"
dependencies = ["pyserial",]

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
Empty file.
65 changes: 65 additions & 0 deletions tools/unicore/unicore_gnss/serial_comm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#! /usr/bin/env python3
import serial
import time


class SerialComm:
def __init__(
self,
address,
baudrate=115200,
timeout=5,
write_timeout=5,
cmd_delay=0.1,
on_error=None,
byte_encoding="ISO-8859-1",
):
self.cmd_delay = cmd_delay
self.on_error = on_error
self.byte_encoding = byte_encoding
self.device_serial = serial.Serial(
port=address,
baudrate=baudrate,
timeout=timeout,
write_timeout=write_timeout,
bytesize = serial.EIGHTBITS,
parity = serial.PARITY_NONE,
stopbits = serial.STOPBITS_ONE,
xonxoff = False,
rtscts = False,
dsrdtr = False,
)

def send(self, cmd) -> str or None:
self.device_serial.write(cmd.encode(self.byte_encoding) + b"\r\n")
time.sleep(self.cmd_delay)

def send_raw(self, cmd):
self.device_serial.write(cmd)
time.sleep(self.cmd_delay)

def read_lines(self) -> list:
read = self.device_serial.readlines()
for i, line in enumerate(read):
read[i] = line.decode(self.byte_encoding, errors='ignore').strip()
return read

def read_until(self, expected='\r\n') -> list:
read = self.device_serial.read_until(expected = expected.encode())
read = read.decode(self.byte_encoding, errors='ignore').strip().splitlines()
read = [ val for val in read if val != '']
return read

def read_until_line(self, expected='\r\n', eol='\r\n') -> str:
#while True:
read_start = self.device_serial.read_until(expected = expected.encode())
read_start = read_start.decode(self.byte_encoding, errors='ignore').strip().splitlines()[-1]
if expected in read_start:
read_end = self.device_serial.readline().decode(self.byte_encoding, errors='ignore')
return read_start + read_end

def read_raw(self, size: int):
return self.device_serial.read(size)

def close(self):
self.device_serial.close()
18 changes: 18 additions & 0 deletions tools/unicore/unicore_gnss/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#! /usr/bin/env python3
from . unicore_cmd import UnicoGnss

def test_checksum():
c = object.__new__(UnicoGnss)
assert c._xor8_checksum('VERSIONA') == '1B'

def test_expected_res():
c = object.__new__(UnicoGnss)
c.debug = False
assert c._expected_res_for('VERSIONA') == '$command,VERSIONA,response: OK*45'
assert c._expected_res_for('FRESET') == '$command,FRESET,response: OK*4D'

def test_cmd_with_checksum():
c = object.__new__(UnicoGnss)
assert c._cmd_with_checksum('VERSIONA') == '$VERSIONA*1B'
assert c._cmd_with_checksum('SAVECONFIG') == '$SAVECONFIG*0B'

Loading

0 comments on commit 3cfade8

Please sign in to comment.