From cb43959238b70957f25caa99ef3410fa757d07c5 Mon Sep 17 00:00:00 2001 From: Fred Wright Date: Sat, 23 Mar 2019 18:22:53 -0700 Subject: ubxtool: Adds interface option for UBX-CFG-PRT. The UBX-CFG-PRT command can specify any port, though it defaults to the current port. This option allows the port ID to be specified, either as a name or as an integer. At present, it only affects the PRT preset, though it could be used for other port-related commands in the future. Note that the baud rate is only applicable to the UART port, so there's no point in applying this to the -S option. TESTED: Tested on LEA-6S, LEA-M8F, LEA-M8T, and LEA-M8N --- man/ubxtool.xml | 8 ++++++++ ubxtool | 25 ++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/man/ubxtool.xml b/man/ubxtool.xml index 97a897bd..a23e6c08 100644 --- a/man/ubxtool.xml +++ b/man/ubxtool.xml @@ -33,6 +33,7 @@ BSD terms apply: see the file COPYING in the distribution root for details. -f file/device -h + -i interface -m mode -P protver -p preset @@ -179,6 +180,13 @@ devices are opened read/write, unless the -r parameter is given. a usage message and exit. + + -i interface + + Specifies interface (port) for port-related commands. + + + -m mode diff --git a/ubxtool b/ubxtool index cbcc3b31..ffb22f52 100755 --- a/ubxtool +++ b/ubxtool @@ -84,6 +84,8 @@ opts = { 'input_speed': 9600, # default input wait time -w in seconds 'input_wait': 2.0, + # interface for port-related commands + 'interface': None, # optional mode to -p P 'mode': None, # the name of an OAF file, extension .jpo @@ -143,6 +145,7 @@ class ubx(object): 4: 'SPI', 0: 'DDC', # The inappropriate name for i2c used in the spec } + port_id_map = dict([x[::-1] for x in port_ids.items()]) def ack_ack(self, buf): "UBX-ACK-ACK decode" @@ -1946,17 +1949,25 @@ class ubx(object): gps_model.gps_send(6, 0x86, m_data) def send_cfg_prt(self): - "UBX-CFG-PRT, get I/O Port" - m_data = bytearray(0) + "UBX-CFG-PRT, get I/O Port settings" + port = opts['interface'] + if port is None: + m_data = bytearray() + else: + m_data = bytearray([port]) gps_model.gps_send(6, 0x0, m_data) def send_set_speed(self, speed): "UBX-CFG-PRT, set port" + # Note that this is only applicable to the UART port (1), + # so there's no need to pay attention to 'interface'. + # If there's any possibility for a receiver to have multiple + # UART ports, it's not mentioned in the doc. + # FIXME! Poll current masks, then adjust speed m_data = bytearray(20) - m_data[0] = 1 # port 1, UART 1 - # m_data[0] = 3 # port 3, USB + m_data[0] = 1 # port 1, UART m_data[4] = 0xc0 # 8N1 m_data[5] = 0x8 # 8N1 @@ -2390,6 +2401,7 @@ def usage(): ' -f F open F as file/device\n' ' default: %s\n' ' -h print help\n' + ' -i I interface (port) for UBX-CFG-PRT\n' ' -m M optional mode to -p P\n' ' -P P Protocol version for sending commands\n' ' default: %s\n' @@ -2434,7 +2446,7 @@ else: try: (options, arguments) = getopt.getopt(options, - "?c:d:e:f:hm:rP:p:s:w:v:R:S:V") + "?c:d:e:f:hi:m:rP:p:s:w:v:R:S:V") except getopt.GetoptError as err: sys.stderr.write("%s: %s\n" "Try '%s -h' for more information.\n" % @@ -2452,6 +2464,9 @@ for (opt, val) in options: opts['input_file_name'] = val elif opt == '-h' or opt == '-?': usage() + elif opt == '-i': + valnum = gps_model.port_id_map.get(val.upper()) + opts['interface'] = valnum if valnum is not None else int(val) elif opt == '-m': opts['mode'] = int(val) elif opt == '-P': -- cgit v1.2.1