Fix bug in handling unsupported READ_EXTERNAL_ID

This commit is contained in:
Andrew Kay
2021-10-18 20:05:38 -05:00
parent 9dfab54950
commit 42c3c51d66
2 changed files with 12 additions and 6 deletions

View File

@@ -229,12 +229,12 @@ class Poll(ReadCommand):
return (FrameFormat.WORD_DATA, command_word)
def unpack_inbound_frame(self, words):
if len(words) != 1:
raise ProtocolError(f'Expected 1 word POLL response: {words}')
if is_tt_ar(words):
return None
if len(words) != 1:
raise ProtocolError(f'Expected 1 word POLL response: {words}')
word = words[0]
if PollResponse.is_power_on_reset_complete(word):
@@ -296,6 +296,9 @@ class ReadExtendedId(ReadCommand):
return (FrameFormat.WORD_DATA, command_word)
def unpack_inbound_frame(self, words):
if is_tt_ar(words):
return None
if len(words) != 4:
raise ProtocolError(f'Expected 4 word READ_EXTENDED_ID response: {words}')
@@ -521,12 +524,12 @@ class ReadFeatureId(ReadCommand):
return (FrameFormat.WORD_DATA, command_word)
def unpack_inbound_frame(self, words):
if len(words) != 1:
raise ProtocolError(f'Expected 1 word READ_FEATURE_ID response: {words}')
if is_tt_ar(words):
return None
if len(words) != 1:
raise ProtocolError(f'Expected 1 word READ_FEATURE_ID response: {words}')
return unpack_data_word(words[0])
class EABReadData(ReadCommand):

View File

@@ -175,6 +175,9 @@ class ReadExtendedIdTestCase(unittest.TestCase):
def test_pack(self):
self.assertEqual(ReadExtendedId().pack_outbound_frame(), (FrameFormat.WORD_DATA, 0b000_00111_01))
def test_unpack_tt_ar(self):
self.assertIsNone(ReadFeatureId(7).unpack_inbound_frame([0b0000000000]))
def test_unpack_extended_id(self):
self.assertEqual(ReadExtendedId().unpack_inbound_frame([0b11000001_00, 0b00110100_00, 0b10000011_00, 0b00000000_00]), bytes.fromhex('c1 34 83 00'))