Browse Source

command cc1101-export-config: append values of PATABLE register as comment

Fabian Peter Hammerle 3 years ago
parent
commit
9a7736aaf6
3 changed files with 18 additions and 1 deletions
  1. 1 0
      CHANGELOG.md
  2. 11 0
      cc1101/_cli.py
  3. 6 1
      tests/test_cli_export_config.py

+ 1 - 0
CHANGELOG.md

@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Added
 - method `set/get_output_power` to configure/retrieve output power settings
   (`PATABLE` and `FREND0.PA_POWER`)
+- command `cc1101-export-config`: append values of `PATABLE` register as comment
 
 ### Fixed
 - default config via private/unstable method `_set_power_amplifier_setting_index`:

+ 11 - 0
cc1101/_cli.py

@@ -111,6 +111,17 @@ def _export_config():
                 )
             )
         print("]")
+        print(
+            "# PATABLE = ({})".format(
+                # pylint: disable=protected-access; internal method
+                ", ".join(
+                    map(
+                        lambda s: "0" if s == 0 else "0x{:x}".format(s),
+                        transceiver._get_patable(),
+                    )
+                )
+            )
+        )
 
 
 def _transmit():

+ 6 - 1
tests/test_cli_export_config.py

@@ -60,6 +60,7 @@ def test_export_python_list(capsys, caplog):
             cc1101.addresses.ConfigurationRegisterAddress.IOCFG2: 0x29,
             cc1101.addresses.ConfigurationRegisterAddress.IOCFG1: 0x2E,
         }
+        transceiver_mock().__enter__()._get_patable.return_value = [0xC6] + [0] * 7
         with unittest.mock.patch("sys.argv", [""]):
             with caplog.at_level(logging.INFO):
                 cc1101._cli._export_config()
@@ -68,7 +69,11 @@ def test_export_python_list(capsys, caplog):
     ]
     out, err = capsys.readouterr()
     assert not err
-    assert out == "[\n0b00101001, # 0x29 IOCFG2\n0b00101110, # 0x2e IOCFG1\n]\n"
+    assert (
+        out
+        == "[\n0b00101001, # 0x29 IOCFG2\n0b00101110, # 0x2e IOCFG1\n]\n"
+        + "# PATABLE = (0xc6, 0, 0, 0, 0, 0, 0, 0)\n"
+    )
 
 
 @pytest.mark.parametrize(