Compare commits

...

7 Commits

Author SHA1 Message Date
Vadim Yanitskiy 73c644a2f3 sedbgmux-dump.py: add option to show only ConnData messages 2023-01-27 04:14:45 +07:00
Vadim Yanitskiy 8c44290e7c sedbgmux-dump.py: parse: hierarchical output formatting 2023-01-27 04:14:45 +07:00
Vadim Yanitskiy 61302bf5ee DumpIONative: use Default instead of Rebuild in DumpRecord 2023-01-27 04:14:45 +07:00
Vadim Yanitskiy 66580927bf DbgMuxPingPong: make logging messages consistent
[INFO] ping_pong.py:38 Tx Ping with payload 'Knock, knock!'
[INFO] ping_pong.py:51 Rx Pong with payload 'Knock, knock!'
2023-01-27 04:14:45 +07:00
Vadim Yanitskiy e9c6a37b94 DbgMuxFrame: use HexDump decorator in MsgConnData 2023-01-27 04:14:45 +07:00
Vadim Yanitskiy 8d276bd9dc DbgMuxFrame: use Hex decorator for DPRef and ConnRef fields 2023-01-27 04:14:45 +07:00
Vadim Yanitskiy 507ee24424 DbgMuxFrame: use Struct in definition of MsgPingPong
... for consistency with the other message definitions.
2023-01-27 02:13:41 +07:00
5 changed files with 30 additions and 18 deletions

View File

@ -87,16 +87,24 @@ class SEDbgMuxDumpApp:
def _print_record(self, record: dict) -> None:
frame = DbgMuxFrame.Frame.parse(record['data'])
print('Record #{nr:04d} @ {timestamp:f} {dir} frame'.format(**record),
if argv.conn_data: # print only ConnData messages
if frame['MsgType'] != DbgMuxFrame.MsgType.ConnData:
return
# Record information
print('Record #{nr:04d} @ {timestamp:f} {dir}'.format(**record),
record['data'].hex())
# DebugMux frame header
print(' DebugMux {} frame'.format(record['dir']),
'(Ns={TxCount:03d}, Nr={RxCount:03d}, fcs=0x{FCS:04x})'.format(**frame),
'{} {}'.format(frame['MsgType'], frame['MsgData'].hex()))
frame['MsgType'], frame['MsgData'].hex())
fcs: int = DbgMuxFrame.fcs_func(record['data'][:-2])
if fcs != frame['FCS']:
msg: str = 'Indicated 0x{ind:04x} != calculated 0x{calc:04x}' \
.format(ind=frame['FCS'], calc=fcs)
if not argv.ignore_bad_fcs:
raise DumpIOFcsError(msg)
print('Bad FCS: ' + msg)
print(' Bad FCS: ' + msg)
# DebugMux frame payload
if argv.decode_payload:
msg = DbgMuxFrame.Msg.parse(frame['MsgData'], MsgType=frame['MsgType'])
if msg != b'':
@ -119,6 +127,8 @@ parse.add_argument('-f', '--format', type=str, default='auto',
help='input file format (default: %(default)s)')
parse.add_argument('-dp', '--decode-payload', action='store_true',
help='decode DebugMux frame contents')
parse.add_argument('-cd', '--conn-data', action='store_true',
help='show only ConnData messages')
parse.add_argument('-nr', '--num-records', type=int, default=math.inf,
help='number of records to parse (default: all)')
parse.add_argument('--ignore-bad-fcs', action='store_true',

View File

@ -157,7 +157,7 @@ class DbgMuxClient:
elif MsgType == DbgMuxFrame.MsgType.DPAnnounce:
self._handle_dp_announce(Msg)
elif MsgType == DbgMuxFrame.MsgType.Pong:
self.ping_pong._handle_pong(Msg)
self.ping_pong._handle_pong(Msg['Data'])
elif MsgType == DbgMuxFrame.MsgType.ConnEstablished:
self._handle_conn_est(Msg)
self._ev_conn_est.set()

View File

@ -35,7 +35,7 @@ class DumpIONative(DumpIO):
'Tag' / Const(b'\x01'),
'Length' / Rebuild(Int16ul, lambda ctx: len(ctx.Data) + 5),
'Direction' / Enum(subcon=Int8ul, Rx=0x00, Tx=0x01),
'Timestamp' / Rebuild(Float64l, lambda ctx: ctx.get('Timestamp') or time.time()),
'Timestamp' / Default(Float64l, lambda ctx: time.time()),
'Data' / Bytes(lambda ctx: ctx.Length - 5),
)

View File

@ -35,10 +35,10 @@ class DbgMuxPingPong:
self._expect_pong: bool = False
def ping(self, payload: str) -> bool:
log.info('Sending Ping with payload \'%s\'', payload)
log.info('Tx Ping with payload \'%s\'', payload)
self._pong.clear()
self._expect_pong = True
self.peer.send(DbgMuxFrame.MsgType.Ping, payload)
self.peer.send(DbgMuxFrame.MsgType.Ping, dict(Data=payload))
if not self._pong.wait(timeout=self.timeout):
log.warning('Timeout waiting for Pong')
return False

View File

@ -60,38 +60,40 @@ class DbgMuxFrame:
)
# MsgType.{Ping,Pong} structure
MsgPingPong = PascalString(Int8ul, 'ascii')
MsgPingPong = Struct(
'Data' / PascalString(Int8ul, 'ascii'),
)
# MsgType.DPAnnounce structure
MsgDPAnnounce = Struct(
'DPRef' / Int16ul,
'DPRef' / Hex(Int16ul),
'Name' / PascalString(Int8ul, 'ascii'),
)
# MsgType.ConnEstablish[ed] structure
MsgConnEstablish = Struct('DPRef' / Int16ul)
MsgConnEstablish = Struct('DPRef' / Hex(Int16ul))
MsgConnEstablished = Struct(
'DPRef' / Int16ul,
'ConnRef' / Int16ul,
'DPRef' / Hex(Int16ul),
'ConnRef' / Hex(Int16ul),
'DataBlockLimit' / Int16ul,
)
# MsgType.ConnTerminate[ed] structure
MsgConnTerminate = Struct('ConnRef' / Int16ul)
MsgConnTerminate = Struct('ConnRef' / Hex(Int16ul))
MsgConnTerminated = Struct(
'DPRef' / Int16ul,
'ConnRef' / Int16ul,
'DPRef' / Hex(Int16ul),
'ConnRef' / Hex(Int16ul),
)
# MsgType.ConnData structure
MsgConnData = Struct(
'ConnRef' / Int16ul,
'Data' / GreedyBytes,
'ConnRef' / Hex(Int16ul),
'Data' / HexDump(GreedyBytes),
)
# MsgType.FlowControl structure
MsgFlowControl = Struct(
'ConnRef' / Int16ul,
'ConnRef' / Hex(Int16ul),
'DataBlockLimit' / Int8ul,
)