Browse Source

_wait_for_packet: disable receive mode after reaching timeout

Fabian Peter Hammerle 3 years ago
parent
commit
30b26dcdef
2 changed files with 10 additions and 1 deletions
  1. 5 0
      cc1101/__init__.py
  2. 5 1
      tests/test_receive.py

+ 5 - 0
cc1101/__init__.py

@@ -990,5 +990,10 @@ class CC1101:
         gdo0_line.request(gdo0_line_request)
         self._enable_receive_mode()
         if not gdo0_line.event_wait(timeout=timeout):
+            self._command_strobe(StrobeAddress.SIDLE)
+            _LOGGER.debug(
+                "reached timeout of %f seconds while waiting for packet",
+                timeout.total_seconds(),
+            )
             return None  # timeout
         return self._get_received_packet()

+ 5 - 1
tests/test_receive.py

@@ -64,7 +64,9 @@ def test__wait_for_packet(
         transceiver, "_get_received_packet"
     ) as get_received_packet_mock, unittest.mock.patch.object(
         transceiver, "_enable_receive_mode"
-    ) as enable_receive_mode_mock:
+    ) as enable_receive_mode_mock, unittest.mock.patch.object(
+        transceiver, "_command_strobe"
+    ) as command_strobe_mock:
         get_line_mock.return_value = line_mock
         get_received_packet_mock.return_value = "packet-dummy"
         packet = transceiver._wait_for_packet(
@@ -87,7 +89,9 @@ def test__wait_for_packet(
     line_mock.event_wait.assert_called_once_with(timeout=timeout)
     if reached_timeout:
         assert packet is None
+        command_strobe_mock.assert_called_once_with(0x36)  # SIDLE
         get_received_packet_mock.assert_not_called()
     else:
+        command_strobe_mock.assert_not_called()
         get_received_packet_mock.assert_called_once_with()
         assert packet == "packet-dummy"