test_0x0d_0x0e_0x0f_freq.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 typing
  18. import pytest
  19. import cc1101
  20. # pylint: disable=protected-access
  21. @pytest.mark.parametrize(
  22. ("freq210", "frequency_hertz"),
  23. [((0x10, 0xB0, 0x71), 433920000), ((0x21, 0x62, 0x76), 868000000)],
  24. )
  25. def test_get_base_frequency_hertz(
  26. transceiver: cc1101.CC1101,
  27. freq210: typing.Tuple[int, int, int],
  28. frequency_hertz: int,
  29. ) -> None:
  30. transceiver._spi.xfer.return_value = [0] + list(freq210)
  31. assert transceiver.get_base_frequency_hertz() == pytest.approx(
  32. frequency_hertz, abs=170
  33. )
  34. transceiver._spi.xfer.assert_called_once_with([0x0D | 0xC0, 0, 0, 0])
  35. @pytest.mark.parametrize(
  36. ("freq210", "frequency_hertz"),
  37. [((0x10, 0xB0, 0x71), 433920000), ((0x21, 0x62, 0x76), 868000000)],
  38. )
  39. def test_set_base_frequency_hertz(
  40. transceiver: cc1101.CC1101,
  41. freq210: typing.Tuple[int, int, int],
  42. frequency_hertz: int,
  43. ) -> None:
  44. transceiver._spi.xfer.return_value = [15] * (1 + 3)
  45. transceiver.set_base_frequency_hertz(frequency_hertz)
  46. transceiver._spi.xfer.assert_called_once_with([0x0D | 0x40] + list(freq210))