From debe68c4c3ccc3bf9fd487990e8c5e9ba7a57b5f Mon Sep 17 00:00:00 2001 From: Andrew Kay Date: Fri, 13 Mar 2020 08:13:42 -0500 Subject: [PATCH] Drop address from command packing functions --- pycoax/coax/protocol.py | 13 ++++++------- pycoax/tests/test_protocol.py | 18 +++--------------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/pycoax/coax/protocol.py b/pycoax/coax/protocol.py index eaefa5e..de18cf8 100644 --- a/pycoax/coax/protocol.py +++ b/pycoax/coax/protocol.py @@ -313,9 +313,9 @@ def diagnostic_reset(interface): """Execute a DIAGNOSTIC_RESET command.""" raise NotImplementedError -def pack_command_word(command, address=0): - """Pack a command and address into a 10-bit command word.""" - return (address << 7) | (command.value << 2) | 0x1 +def pack_command_word(command): + """Pack a command into a 10-bit command word.""" + return (command.value << 2) | 0x1 def is_command_word(word): """Is command word bit set?""" @@ -326,10 +326,9 @@ def unpack_command_word(word): if not is_command_word(word): raise ProtocolError('Word does not have command bit set') - address = (word >> 7) & 0x7 command = (word >> 2) & 0x1f - return (address, Command(command)) + return Command(command) def is_data_word(word): """Is data word bit set?""" @@ -362,7 +361,7 @@ def _execute_read_command(interface, command_word, response_length=1, return trta_value if validate_response_length and len(response) != response_length: - (_, command) = unpack_command_word(command_word) + command = unpack_command_word(command_word) raise ProtocolError(f'Expected {response_length} word {command.name} response') @@ -373,7 +372,7 @@ def _execute_write_command(interface, command_word, data=None, **kwargs): response = interface.execute(command_word, data, **kwargs) if len(response) != 1: - (_, command) = unpack_command_word(command_word) + command = unpack_command_word(command_word) raise ProtocolError(f'Expected 1 word {command.name} response') diff --git a/pycoax/tests/test_protocol.py b/pycoax/tests/test_protocol.py index 8841f07..cc8575b 100644 --- a/pycoax/tests/test_protocol.py +++ b/pycoax/tests/test_protocol.py @@ -96,27 +96,15 @@ class SecondaryControlTestCase(unittest.TestCase): self.assertEqual(control.value, 0b00000001) class PackCommandWordTestCase(unittest.TestCase): - def test_without_address(self): + def test(self): self.assertEqual(pack_command_word(Command.POLL_ACK), 0b0001000101) - def test_with_address(self): - self.assertEqual(pack_command_word(Command.POLL_ACK, address=7), 0b1111000101) - class UnpackCommandWordTestCase(unittest.TestCase): - def test_without_address(self): + def test(self): # Act - (address, command) = unpack_command_word(0b0001000101) + command = unpack_command_word(0b0001000101) # Assert - self.assertEqual(address, 0) - self.assertEqual(command, Command.POLL_ACK) - - def test_with_address(self): - # Act - (address, command) = unpack_command_word(0b1111000101) - - # Assert - self.assertEqual(address, 7) self.assertEqual(command, Command.POLL_ACK) def test_command_bit_not_set_error(self):