diff options
author | Fred Wright <fw@fwright.net> | 2019-03-27 13:26:03 -0700 |
---|---|---|
committer | Fred Wright <fw@fwright.net> | 2019-03-27 20:26:33 -0700 |
commit | e2d066957943218cd95406d211bf6360a8f5a3a7 (patch) | |
tree | 564f02f30d2c92512cc098c1ba0dc7c83a8233f8 | |
parent | cb43959238b70957f25caa99ef3410fa757d07c5 (diff) | |
download | gpsd-e2d066957943218cd95406d211bf6360a8f5a3a7.tar.gz |
ubxtool: Reworks -c option so that it's usable.
It appears that the -c code was more or less inherited from zerk and
essentially useless for the UBX message format. This reworks it so
that the argument is a comma-separated list of hex bytes giving the
class, ID, and any payload. The header, length, and checksum are
added automatically, making it reasonably convenient to specify
arbitrary commands. The only limitation is the need to specify
multibyte quantities as individual bytes.
TESTED:
Tested on LEA-6S, LEA-M8F, LEA-M8T, and LEA-M8N
-rw-r--r-- | man/ubxtool.xml | 6 | ||||
-rwxr-xr-x | ubxtool | 23 |
2 files changed, 20 insertions, 9 deletions
diff --git a/man/ubxtool.xml b/man/ubxtool.xml index a23e6c08..fa69e9aa 100644 --- a/man/ubxtool.xml +++ b/man/ubxtool.xml @@ -72,9 +72,9 @@ running gpsd instance.</para> <varlistentry> <term>-c COMMAND</term> <listitem> - <para>Send a text string to the GPS. Accepts one parameter, COMMAND, -the command string to send to the GPS. The string is sent verbatim, except -a newline is appended. + <para>Send a command to the GPS. Accepts one parameter, COMMAND, +a comma-separated list of hexadecimal bytes specifying the class, the ID, +and any needed payload. The header, length, and checksum are added automatically. </para> </listitem> </varlistentry> @@ -29,7 +29,9 @@ usage: ubxtool [OPTIONS] [server[:port[:device]]] from __future__ import absolute_import, print_function, division import binascii # for binascii.hexlify() +from functools import reduce # pylint: disable=redefined-builtin import getopt # for getopt.getopt(), to parse CLI options +import operator # for or_ import os # for os.environ import socket # for socket.error import stat # for stat.S_ISBLK() @@ -2395,7 +2397,7 @@ def usage(): "Ouput usage information, and exit" print('usage: %s [-c C] [-f F] [-r] [-p P] [-s S] [-v V]\n' ' [-hV?] [-S S]\n' - ' -c C send raw command C to GPS\n' + ' -c C send raw command C (cls,id...) to GPS\n' ' -d D disable D\n' ' -e E enable E\n' ' -f F open F as file/device\n' @@ -2593,13 +2595,22 @@ try: gps_model.send_set_speed(opts['set_speed']) elif opts['command'] is not None: - # zero length is OK to send - # add trailing new line - opts['command'] += "\n" - + cmd_list = opts['command'].split(',') + try: + cmd_data = [int(x, 16) for x in cmd_list] + except ValueError: + badarg = True + else: + data_or = reduce(operator.or_, cmd_data) + badarg = data_or != data_or & 0xFF + if badarg or len(cmd_list) < 2: + sys.stderr.write('%s: Argument format (hex bytes) is' + ' class,id[,payload...]\n' % PROG_NAME) + sys.exit(1) + payload = bytearray(cmd_data[2:]) if VERB_QUIET < opts['verbosity']: sys.stderr.write('%s: command %s\n' % (PROG_NAME, opts['command'])) - gps_model.gps_send_raw(opts['command']) + gps_model.gps_send(cmd_data[0], cmd_data[1], payload) exit_code = io_handle.read(opts) |