Browse Source

added method _set_patable

https://github.com/fphammerle/python-cc1101/issues/30#issuecomment-766094920
Fabian Peter Hammerle 3 years ago
parent
commit
e17e2a00f8
2 changed files with 26 additions and 5 deletions
  1. 9 5
      cc1101/__init__.py
  2. 17 0
      tests/config/test_0x3e_patable.py

+ 9 - 5
cc1101/__init__.py

@@ -109,9 +109,6 @@ class _ReceivedPacket:  # unstable
         )
 
 
-_PatableSetting = typing.Tuple[int, ...]
-
-
 class CC1101:
 
     # pylint: disable=too-many-public-methods
@@ -252,7 +249,9 @@ class CC1101:
 
     def _write_burst(
         self,
-        start_register: typing.Union[ConfigurationRegisterAddress, FIFORegisterAddress],
+        start_register: typing.Union[
+            ConfigurationRegisterAddress, PatableAddress, FIFORegisterAddress
+        ],
         values: typing.List[int],
     ) -> None:
         _LOGGER.debug(
@@ -783,7 +782,7 @@ class CC1101:
             start_register=ConfigurationRegisterAddress.PKTCTRL0, values=[pktctrl0]
         )
 
-    def _get_patable(self) -> _PatableSetting:
+    def _get_patable(self) -> typing.Tuple[int, ...]:
         """
         see "10.6 PATABLE Access" and "24 Output Power Programming"
 
@@ -795,6 +794,11 @@ class CC1101:
             )
         )
 
+    def _set_patable(self, setting: typing.Iterable[int]):
+        setting = list(setting)
+        assert 0 < len(setting) <= self._PATABLE_LENGTH_BYTES, setting
+        self._write_burst(start_register=PatableAddress.PATABLE, values=setting)
+
     def _flush_tx_fifo_buffer(self) -> None:
         # > Only issue SFTX in IDLE or TXFIFO_UNDERFLOW states.
         _LOGGER.debug("flushing tx fifo buffer")

+ 17 - 0
tests/config/test_0x3e_patable.py

@@ -32,3 +32,20 @@ def test__get_patable(transceiver, patable):
     transceiver._spi.xfer.return_value = [0] + list(patable)
     assert transceiver._get_patable() == patable
     transceiver._spi.xfer.assert_called_once_with([0x3E | 0xC0] + [0] * 8)
+
+
+@pytest.mark.parametrize(
+    "patable",
+    (
+        (198, 0, 0, 0, 0, 0, 0, 0),  # default
+        [198, 0, 0, 0, 0, 0, 0, 0],
+        (0, 198, 0, 0, 0, 0, 0, 0),  # OOK
+        (1, 2, 3, 4, 5, 6, 7, 8),
+        (1, 2, 3),
+        (1,),
+    ),
+)
+def test__set_patable(transceiver, patable):
+    transceiver._spi.xfer.return_value = [0b00000111] * (len(patable) + 1)
+    transceiver._set_patable(patable)
+    transceiver._spi.xfer.assert_called_once_with([0x3E | 0x40] + list(patable))