summaryrefslogtreecommitdiff
path: root/ubxtool
diff options
context:
space:
mode:
authorFred Wright <fw@fwright.net>2019-03-27 13:26:03 -0700
committerFred Wright <fw@fwright.net>2019-03-27 20:26:33 -0700
commite2d066957943218cd95406d211bf6360a8f5a3a7 (patch)
tree564f02f30d2c92512cc098c1ba0dc7c83a8233f8 /ubxtool
parentcb43959238b70957f25caa99ef3410fa757d07c5 (diff)
downloadgpsd-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
Diffstat (limited to 'ubxtool')
-rwxr-xr-xubxtool23
1 files changed, 17 insertions, 6 deletions
diff --git a/ubxtool b/ubxtool
index ffb22f52..884295de 100755
--- a/ubxtool
+++ b/ubxtool
@@ -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)