Skip to content

Commit

Permalink
tagcore/ubx: add decoder/emitter for UPD_SOS save on shutdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
cire831 committed Jun 30, 2021
1 parent a281b6d commit cf5e63a
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tools/utils/tagcore/tagcore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@author: Eric B. Decker
"""

__version__ = '0.4.10.dev0'
__version__ = '0.4.10.dev1'

__all__ = [
'CORE_REV', # core_rev.py
Expand Down
57 changes: 57 additions & 0 deletions tools/utils/tagcore/tagcore/ubx_emitters.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,60 @@ def emit_ubx_tim_tp(level, offset, buf, obj, xdir):
towMS, fstr, raim, towSubMS, qErr, week, flags, refInfo, utcstd, timeref))
if level >= 1:
print(' {}'.format(obj))


upd_sos_cmd = {
0: 'create',
1: 'clear',
2: 'sos_ack',
3: 'restored',
}

upd_sos_create_ack = {
0: 'nack',
1: 'ack',
}

upd_sos_restore_rsp = {
0: 'unknown',
1: 'failed',
2: 'restored',
3: 'no backup',
}

def emit_ubx_upd_sos(level, offset, buf, obj, xdir):
ubx = obj['ubx']
xlen = ubx['len'].val
if xlen == 0: # poll
if xdir:
print('poll')
else:
print('poll, weird')
elif xlen == 4:
cmd = obj['var']['cmd'].val
cmd_str = upd_sos_cmd.get(cmd, 'cmd/{:d}'.format(cmd))
if xdir == -1:
xtype = 'cmd'
else:
xtype = 'cmd' if xdir else 'rsp'
print('{:3s} {:s}'.format(xtype, cmd_str))
elif xlen == 8:
cmd = obj['var']['cmd'].val
cmd_str = upd_sos_cmd.get(cmd, 'cmd/{:d}'.format(cmd))
rsp = obj['var']['rsp'].val
if cmd == 2:
# create ack
rsp_str = upd_sos_create_ack.get(rsp, 'rsp/{:d}'.format(rsp))
elif cmd == 3:
rsp_str = upd_sos_restore_rsp.get(rsp, 'rsp/{:d}'.format(rsp))
else:
rsp_str = 'rsp/{:d}'.format(rsp)
if xdir == -1:
xtype = 'rsp'
else:
xtype = 'cmd' if xdir else 'rsp'
print('{:3s} {:s} {:s}'.format(xtype, cmd_str, rsp_str))
else:
print('weird')
if level >= 1:
print(' {}'.format(obj))
46 changes: 45 additions & 1 deletion tools/utils/tagcore/tagcore/ubx_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from __future__ import print_function

__version__ = '0.4.10.dev0'
__version__ = '0.4.10.dev1'

import binascii
from collections import OrderedDict
Expand Down Expand Up @@ -580,6 +580,28 @@ def obj_ubx_tim_tp():
]))


# ubx.len 4 or 8 has cmd
def obj_ubx_upd_sos_4():
return aggie(OrderedDict([
('cmd', atom(('<B', '{}'))),
('reserved1', atom(('3s', '{}', binascii.hexlify))),
]))

# ubx.len 8 has rsp too
def obj_ubx_upd_sos_8():
return aggie(OrderedDict([
('cmd', atom(('<B', '{}'))),
('reserved1', atom(('3s', '{}', binascii.hexlify))),
('rsp', atom(('<B', '{}'))),
('reserved2', atom(('3s', '{}', binascii.hexlify))),
]))

def obj_ubx_upd_sos():
return aggie(OrderedDict([
('ubx', obj_ubx_hdr()),
]))


########################################################################
#
# Ublox Decoders
Expand Down Expand Up @@ -783,3 +805,25 @@ def decode_ubx_rxm_pmreq(level, offset, buf, obj):
return consumed

return consumed


def decode_ubx_upd_sos(level, offset, buf, obj):
if obj.get('var') is not None:
del(obj['var'])

# variable has been removed, should have a ubx_hdr left ('ubx')
# populate it.
consumed = obj.set(buf)
xlen = obj['ubx']['len'].val

if xlen == 4:
obj['var'] = obj_ubx_upd_sos_4();
consumed += obj['var'].set(buf[consumed:])
return consumed

if xlen == 8:
obj['var'] = obj_ubx_upd_sos_8();
consumed += obj['var'].set(buf[consumed:])
return consumed

return consumed
4 changes: 2 additions & 2 deletions tools/utils/tagcore/tagcore/ubx_populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def decode_null(level, offset, buf, obj):

ubx.cid_table[0x0641] = (decode_ubx_cfg_otp, [ emit_ubx_cfg_otp ], obj_ubx_cfg_otp(), 'cfg/otp', 'obj_ubx_cfg_otp')

ubx.cid_table[0x0914] = (decode_ubx_upd_sos, [ emit_ubx_upd_sos ], obj_ubx_upd_sos(), 'upd/sos', 'obj_ubx_upd_sos')

ubx.cid_table[0x0a04] = (decode_null, None, None, 'mon/ver', 'none')
ubx.cid_table[0x0a09] = (decode_ubx_mon_hw, [ emit_ubx_mon_hw ], obj_ubx_mon_hw(), 'mon/hw', 'obj_ubx_mon_hw')

Expand Down Expand Up @@ -126,8 +128,6 @@ def decode_null(level, offset, buf, obj):
ubx.cid_table[0x068D] = (decode_null, None, None, 'cfg/slas', 'none')
ubx.cid_table[0x0693] = (decode_null, None, None, 'cfg/batch', 'none')

ubx.cid_table[0x0914] = (decode_null, None, None, 'upd/sos', 'none')

ubx.cid_table[0x0a02] = (decode_null, None, None, 'mon/io', 'none')
ubx.cid_table[0x0a06] = (decode_null, None, None, 'mon/msgpp', 'none')
ubx.cid_table[0x0a07] = (decode_null, None, None, 'mon/rxbuf', 'none')
Expand Down
2 changes: 1 addition & 1 deletion tools/utils/ubxdump/ubxdump/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
@author: Eric B. Decker
"""

__version__ = '0.5.0.dev2'
__version__ = '0.5.0.dev3'
2 changes: 1 addition & 1 deletion tools/utils/ubxdump/ubxdump/ubxdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def count_cid(cid):
print('*** no emitters defined for cid x{:04x}'.format(cid))
else:
for e in emitters:
e(verbose, rec_offset, rec_buf, obj, 0)
e(verbose, rec_offset, rec_buf, obj, -1)
except struct.error:
print()
print('*** decode error: (len: {}, cid: x{:04x} {}, '
Expand Down

0 comments on commit cf5e63a

Please sign in to comment.