test_cc1101.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. _SYMBOL_RATE_MANTISSA_EXPONENT_REAL_PARAMS = [
  22. # > The default values give a data rate of 115.051 kBaud
  23. # > (closest setting to 115.2 kBaud), assuming a 26.0 MHz crystal.
  24. (34, 12, 115051),
  25. (34, 12 + 1, 115051 * 2),
  26. (34, 12 - 1, 115051 / 2),
  27. ]
  28. @pytest.mark.parametrize(
  29. ("mantissa", "exponent", "real"), _SYMBOL_RATE_MANTISSA_EXPONENT_REAL_PARAMS
  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)
  35. @pytest.mark.parametrize(
  36. ("mantissa", "exponent", "real"), _SYMBOL_RATE_MANTISSA_EXPONENT_REAL_PARAMS
  37. )
  38. def test__symbol_rate_real_to_floating_point(mantissa, exponent, real):
  39. assert cc1101.CC1101._symbol_rate_real_to_floating_point(real) == (
  40. mantissa,
  41. exponent,
  42. )