test_cc1101.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import pytest
  2. import cc1101
  3. _FREQUENCY_CONTROL_WORD_HERTZ_PARAMS = [
  4. ([0x10, 0xA7, 0x62], 433000000),
  5. ([0x10, 0xAB, 0x85], 433420000),
  6. ([0x10, 0xB1, 0x3B], 434000000),
  7. ([0x21, 0x62, 0x76], 868000000),
  8. ]
  9. @pytest.mark.parametrize(
  10. ("control_word", "hertz"), _FREQUENCY_CONTROL_WORD_HERTZ_PARAMS
  11. )
  12. def test__frequency_control_word_to_hertz(control_word, hertz):
  13. assert cc1101.CC1101._frequency_control_word_to_hertz(
  14. control_word
  15. ) == pytest.approx(hertz, abs=200)
  16. @pytest.mark.parametrize(
  17. ("control_word", "hertz"), _FREQUENCY_CONTROL_WORD_HERTZ_PARAMS
  18. )
  19. def test__hertz_to_frequency_control_word(control_word, hertz):
  20. assert cc1101.CC1101._hertz_to_frequency_control_word(hertz) == control_word
  21. @pytest.mark.parametrize(
  22. ("mantissa", "exponent", "real"),
  23. [
  24. # > The default values give a data rate of 115.051 kBaud
  25. # > (closest setting to 115.2 kBaud), assuming a 26.0 MHz crystal.
  26. (34, 12, 115051),
  27. (34, 12 + 1, 115051 * 2),
  28. (34, 12 - 1, 115051 / 2),
  29. ],
  30. )
  31. def test__symbol_rate_floating_point_to_real(mantissa, exponent, real):
  32. assert cc1101.CC1101._symbol_rate_floating_point_to_real(
  33. mantissa=mantissa, exponent=exponent
  34. ) == pytest.approx(real, rel=1e-5)