TERMINAL RESPONSE: label as 'TERMINAL RESPONSE', keep command type as context
decode.py: split decode_tr_command() out of decode_cat(); TR (0x14) now stores the echoed proactive command type in 'response_to' instead of 'cat_command', so it no longer overrides the INS name. FETCH/ENVELOPE still use cat_command as the primary label. tests: TR now asserts response_to + no cat_command
This commit is contained in:
1 parent
083924c976
commit
e68df163a9
2 files changed
+27
-12
No files matched your search
@@ -497,10 +497,19 @@ def decode_cat(ins, body):
|
|||||||
return CAT_COMMAND_TYPES.get(v2[1])
|
return CAT_COMMAND_TYPES.get(v2[1])
|
||||||
elif ins == 0xC2: # ENVELOPE → envelope type
|
elif ins == 0xC2: # ENVELOPE → envelope type
|
||||||
return ENVELOPE_TYPES.get(body[0])
|
return ENVELOPE_TYPES.get(body[0])
|
||||||
elif ins == 0x14: # TERMINAL RESPONSE → echoes proactive command type
|
return None
|
||||||
for tag, _length, value in parse_tlv(body):
|
|
||||||
if tag == 0x81 and len(value) >= 2:
|
|
||||||
return CAT_COMMAND_TYPES.get(value[1])
|
def decode_tr_command(body):
|
||||||
|
"""Extract the proactive command type echoed in a TERMINAL RESPONSE body.
|
||||||
|
|
||||||
|
Returns the CAT command name (context the TR is responding to), or None.
|
||||||
|
"""
|
||||||
|
if not body:
|
||||||
|
return None
|
||||||
|
for tag, _length, value in parse_tlv(body):
|
||||||
|
if tag == 0x81 and len(value) >= 2:
|
||||||
|
return CAT_COMMAND_TYPES.get(value[1])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@@ -575,9 +584,14 @@ def decode_message(raw_data, prev=None):
|
|||||||
if h in fids:
|
if h in fids:
|
||||||
result['body']['note'] = fids[h]
|
result['body']['note'] = fids[h]
|
||||||
|
|
||||||
cat_command = decode_cat(ins, body)
|
if ins == 0x14:
|
||||||
if cat_command:
|
response_to = decode_tr_command(body)
|
||||||
result['cat_command'] = cat_command
|
if response_to:
|
||||||
|
result['response_to'] = response_to
|
||||||
|
else:
|
||||||
|
cat_command = decode_cat(ins, body)
|
||||||
|
if cat_command:
|
||||||
|
result['cat_command'] = cat_command
|
||||||
|
|
||||||
# SW
|
# SW
|
||||||
if sw_bytes:
|
if sw_bytes:
|
||||||
|
|||||||
@@ -66,11 +66,12 @@ class TestCatDecoding(unittest.TestCase):
|
|||||||
self.assertEqual(r['ins_name'], 'ENVELOPE')
|
self.assertEqual(r['ins_name'], 'ENVELOPE')
|
||||||
self.assertEqual(r['cat_command'], 'EVENT DOWNLOAD')
|
self.assertEqual(r['cat_command'], 'EVENT DOWNLOAD')
|
||||||
|
|
||||||
def test_tr_has_cat(self):
|
def test_tr_has_response_to(self):
|
||||||
r = decode_message(bytes.fromhex(
|
r = decode_message(bytes.fromhex(
|
||||||
'801400000C8103010500020282810301009130'))
|
'801400000C8103010500020282810301009130'))
|
||||||
self.assertEqual(r['ins_name'], 'TERMINAL RESPONSE')
|
self.assertEqual(r['ins_name'], 'TERMINAL RESPONSE')
|
||||||
self.assertEqual(r['cat_command'], 'SET UP EVENT LIST')
|
self.assertNotIn('cat_command', r)
|
||||||
|
self.assertEqual(r['response_to'], 'SET UP EVENT LIST')
|
||||||
|
|
||||||
def test_select_no_cat(self):
|
def test_select_no_cat(self):
|
||||||
r = decode_message(bytes.fromhex('a0a40000023f009000'))
|
r = decode_message(bytes.fromhex('a0a40000023f009000'))
|
||||||
@@ -124,17 +125,17 @@ class TestTerminalResponse(unittest.TestCase):
|
|||||||
r = decode_message(bytes.fromhex(
|
r = decode_message(bytes.fromhex(
|
||||||
'801400000C8103010500020282810301009130'))
|
'801400000C8103010500020282810301009130'))
|
||||||
self.assertEqual(r['ins_name'], 'TERMINAL RESPONSE')
|
self.assertEqual(r['ins_name'], 'TERMINAL RESPONSE')
|
||||||
self.assertEqual(r['cat_command'], 'SET UP EVENT LIST')
|
self.assertEqual(r['response_to'], 'SET UP EVENT LIST')
|
||||||
|
|
||||||
def test_tr_setup_menu(self):
|
def test_tr_setup_menu(self):
|
||||||
r = decode_message(bytes.fromhex(
|
r = decode_message(bytes.fromhex(
|
||||||
'801400000C810301250002028281830100910F'))
|
'801400000C810301250002028281830100910F'))
|
||||||
self.assertEqual(r['cat_command'], 'SET UP MENU')
|
self.assertEqual(r['response_to'], 'SET UP MENU')
|
||||||
|
|
||||||
def test_tr_poll_interval(self):
|
def test_tr_poll_interval(self):
|
||||||
r = decode_message(bytes.fromhex(
|
r = decode_message(bytes.fromhex(
|
||||||
'80140000108103010300020282810301000402011E9000'))
|
'80140000108103010300020282810301000402011E9000'))
|
||||||
self.assertEqual(r['cat_command'], 'POLL INTERVAL')
|
self.assertEqual(r['response_to'], 'POLL INTERVAL')
|
||||||
|
|
||||||
|
|
||||||
class TestGetResponseContext(unittest.TestCase):
|
class TestGetResponseContext(unittest.TestCase):
|
||||||
|
|||||||
Reference in new issue
Block a user