test_0x0d_0x0e_0x0f_freq.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # python-cc1101 - Python Library to Transmit RF Signals via CC1101 Transceivers
  2. #
  3. # Copyright (C) 2024 Fabian Peter Hammerle <fabian@hammerle.me>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. import pytest
  18. import cc1101
  19. # pylint: disable=protected-access
  20. @pytest.mark.parametrize(
  21. ("freq210", "frequency_hertz"),
  22. [((0x10, 0xB0, 0x71), 433920000), ((0x21, 0x62, 0x76), 868000000)],
  23. )
  24. def test_get_base_frequency_hertz(
  25. transceiver: cc1101.CC1101,
  26. freq210: tuple[int, int, int],
  27. frequency_hertz: int,
  28. ) -> None:
  29. transceiver._spi.xfer.return_value = [0] + list(freq210)
  30. assert transceiver.get_base_frequency_hertz() == pytest.approx(
  31. frequency_hertz, abs=170
  32. )
  33. transceiver._spi.xfer.assert_called_once_with([0x0D | 0xC0, 0, 0, 0])
  34. @pytest.mark.parametrize(
  35. ("freq210", "frequency_hertz"),
  36. [((0x10, 0xB0, 0x71), 433920000), ((0x21, 0x62, 0x76), 868000000)],
  37. )
  38. def test_set_base_frequency_hertz(
  39. transceiver: cc1101.CC1101,
  40. freq210: tuple[int, int, int],
  41. frequency_hertz: int,
  42. ) -> None:
  43. transceiver._spi.xfer.return_value = [15] * (1 + 3)
  44. transceiver.set_base_frequency_hertz(frequency_hertz)
  45. transceiver._spi.xfer.assert_called_once_with([0x0D | 0x40] + list(freq210))