Browse Source

fix _set_modulation_format

https://github.com/fphammerle/python-cc1101/issues/23
https://github.com/fphammerle/python-cc1101/issues/18#issuecomment-761605309
Fabian Peter Hammerle 3 years ago
parent
commit
79dd977bcb
4 changed files with 28 additions and 2 deletions
  1. 1 1
      .github/workflows/python.yml
  2. 3 0
      CHANGELOG.md
  3. 1 1
      cc1101/__init__.py
  4. 23 0
      tests/config/test_0x12_mdmcfg2.py

+ 1 - 1
.github/workflows/python.yml

@@ -50,7 +50,7 @@ jobs:
       env:
         PYTHON_VERSION: ${{ matrix.python-version }}
     - run: pipenv graph
-    - run: pipenv run pytest --cov=cc1101 --cov-report=term-missing --cov-fail-under=87
+    - run: pipenv run pytest --cov=cc1101 --cov-report=term-missing --cov-fail-under=89
     - run: pipenv run pylint --load-plugins=pylint_import_requirements cc1101
     # https://github.com/PyCQA/pylint/issues/352
     - run: pipenv run pylint tests/*

+ 3 - 0
CHANGELOG.md

@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
 ## [Unreleased]
+### Fixed
+- private/unstable method `_set_modulation_format`:
+  fixed incorrect configuration of `MDMCFG2` register
 
 ## [2.6.0] - 2021-01-04
 ### Added

+ 1 - 1
cc1101/__init__.py

@@ -364,7 +364,7 @@ class CC1101:
 
     def _set_modulation_format(self, modulation_format: ModulationFormat) -> None:
         mdmcfg2 = self._read_single_byte(ConfigurationRegisterAddress.MDMCFG2)
-        mdmcfg2 &= ~(modulation_format << 4)
+        mdmcfg2 &= 0b10001111
         mdmcfg2 |= modulation_format << 4
         self._write_burst(ConfigurationRegisterAddress.MDMCFG2, [mdmcfg2])
 

+ 23 - 0
tests/config/test_0x12_mdmcfg2.py

@@ -42,6 +42,29 @@ def test_get_modulation_format(transceiver, mdmcfg2, mod_format):
     transceiver._spi.xfer.assert_called_once_with([0x12 | 0x80, 0])
 
 
+@pytest.mark.parametrize(
+    ("mdmcfg2_before", "mdmcfg2_after", "mod_format"),
+    [
+        (0b00000010, 0b00000010, ModulationFormat.FSK2),
+        (0b11111111, 0b10001111, ModulationFormat.FSK2),
+        (0b00000010, 0b00010010, ModulationFormat.GFSK),
+        (0b00000010, 0b00110010, ModulationFormat.ASK_OOK),
+        (0b00000010, 0b01000010, ModulationFormat.FSK4),
+        (0b01110101, 0b01000101, ModulationFormat.FSK4),
+        (0b11111111, 0b11001111, ModulationFormat.FSK4),
+        (0b00000010, 0b01110010, ModulationFormat.MSK),
+        (0b11111111, 0b11111111, ModulationFormat.MSK),
+    ],
+)
+def test__set_modulation_format(transceiver, mdmcfg2_before, mdmcfg2_after, mod_format):
+    transceiver._spi.xfer.return_value = [15, 15]
+    with unittest.mock.patch.object(
+        transceiver, "_read_single_byte", return_value=mdmcfg2_before
+    ):
+        transceiver._set_modulation_format(mod_format)
+    transceiver._spi.xfer.assert_called_once_with([0x12 | 0x40, mdmcfg2_after])
+
+
 @pytest.mark.parametrize(
     ("mdmcfg2", "sync_mode"),
     [