21static const uint8_t
kFrame[7] = {0x01, 0x11, 0x05, 0x00, 0x00, 0xBE, 0x3D};
28 TEST_ASSERT_EQUAL_UINT8(0xAB, len);
30 TEST_ASSERT_EQUAL_UINT(1,
chip.commands_logged());
40 TEST_ASSERT_EQUAL_UINT8(
sizeof kFrame, len);
41 TEST_ASSERT_EQUAL_HEX8_ARRAY(
kFrame, buf,
sizeof kFrame);
50 TEST_ASSERT_EQUAL_UINT(4,
chip.commands_logged());
63 TEST_ASSERT_EQUAL_HEX8_ARRAY(
kFrame, buf,
sizeof kFrame);
72 TEST_ASSERT_EQUAL_HEX16(0,
chip.irq());
80 for (
unsigned i = 0; i <
sizeof big; i++) {
81 big[i] =
static_cast<uint8_t
>(i * 7 + 1);
83 chip.packet_arrives(big,
sizeof big, 100);
87 TEST_ASSERT_EQUAL_UINT8(255, len);
88 TEST_ASSERT_EQUAL_HEX8_ARRAY(big, buf,
sizeof big);
97 radio.
receive(small,
sizeof small, len));
98 TEST_ASSERT_EQUAL_UINT8(0xAB, len);
100 TEST_ASSERT_EQUAL_UINT(3,
chip.commands_logged());
102 TEST_ASSERT_EQUAL_HEX16(0,
chip.irq());
104 radio.
receive(small,
sizeof small, len));
113 TEST_ASSERT_EQUAL_UINT8(0xAB, len);
114 TEST_ASSERT_EQUAL_UINT(2,
chip.commands_logged());
115 TEST_ASSERT_EQUAL_HEX16(0,
chip.irq());
124 TEST_ASSERT_EQUAL_UINT(2,
chip.commands_logged());
125 TEST_ASSERT_EQUAL_HEX16(0,
chip.irq());
134 TEST_ASSERT_EQUAL_UINT8(0xAB, len);
135 TEST_ASSERT_EQUAL_HEX16(0,
chip.irq());
141 chip.set_never_ready();
145 radio.
receive(buf,
sizeof buf, len));
146 TEST_ASSERT_EQUAL_UINT(0,
chip.transfers());
147 TEST_ASSERT_EQUAL_UINT8(0xAB, len);
156 TEST_ASSERT_EQUAL_UINT(
chip.transfers(),
chip.waits());
164 chip.set_stuck(0x00);
168 radio.
receive(buf,
sizeof buf, len));
173 chip.set_stuck(0xFF);
177 radio.
receive(buf,
sizeof buf, len));
184 chip.set_status(0x5A);
188 radio.
receive(buf,
sizeof buf, len));
196 chip.set_status(0x58);
200 radio.
receive(buf,
sizeof buf, len));
201 TEST_ASSERT_EQUAL_UINT8(0xAB, len);
208 const uint8_t expected[4] = {0x82, 0xFF, 0xFF, 0xFF};
209 TEST_ASSERT_EQUAL_UINT(4,
chip.last_len());
210 for (
unsigned i = 0; i < 4; i++) {
211 TEST_ASSERT_EQUAL_HEX8(expected[i],
chip.last_byte(i));
213 TEST_ASSERT_EQUAL_UINT(1,
chip.waits());
218 chip.set_never_ready();
220 TEST_ASSERT_EQUAL_UINT(0,
chip.transfers());
231 TEST_ASSERT_EQUAL_UINT32(2, radio.
crc_errors());
235 TEST_ASSERT_EQUAL_UINT32(2, radio.
crc_errors());
244 TEST_ASSERT_EQUAL_UINT(1,
chip.commands_logged());
245 TEST_ASSERT_EQUAL_UINT(5,
chip.last_len());
247 for (
unsigned i = 1; i < 5; i++) {
248 TEST_ASSERT_EQUAL_HEX8(0x00,
chip.last_byte(i));
256 chip.set_packet_status(0xB5, 0xEC, 0xC8);
259 TEST_ASSERT_EQUAL_INT16(-181, ps.
rssi_x2);
260 TEST_ASSERT_EQUAL_INT8(-20, ps.
snr_x4);
266 chip.set_packet_status(0x50, 0x28, 0x52);
269 TEST_ASSERT_EQUAL_INT16(-80, ps.
rssi_x2);
270 TEST_ASSERT_EQUAL_INT8(40, ps.
snr_x4);
276 chip.set_stuck(0x00);
279 TEST_ASSERT_EQUAL_INT16(7, ps.
rssi_x2);
280 TEST_ASSERT_EQUAL_INT8(7, ps.
snr_x4);
285 chip.set_never_ready();
288 TEST_ASSERT_EQUAL_UINT(0,
chip.transfers());
bool start_rx_continuous()
bool packet_status(PacketStatus &out)
RadioStatus receive(uint8_t *buf, uint8_t max_len, uint8_t &len)
uint32_t crc_errors() const
constexpr uint8_t kOpGetIrqStatus
constexpr uint8_t kOpGetRxBufferStatus
constexpr uint8_t kOpClearIrqStatus
constexpr uint16_t kIrqRxDone
constexpr uint16_t kIrqHeaderErr
constexpr uint16_t kIrqCrcErr
constexpr uint8_t kOpGetPacketStatus
constexpr uint8_t kOpReadBuffer
static void test_start_rx_continuous_sends_setrx_ffffff(void)
static void test_header_error_drops_the_packet(void)
static const uint8_t kFrame[7]
static void test_no_flags_returns_no_data(void)
static void test_biggest_packet_255_bytes_is_read_whole(void)
static void test_command_failure_status_reports_not_found(void)
static void test_radio_crc_error_drops_the_packet(void)
static void test_packet_flag_is_cleared_after_reading(void)
static void test_the_four_exchanges_happen_in_order(void)
static void test_zero_length_packet_is_dropped(void)
static void test_busy_is_checked_before_every_exchange(void)
static void test_packet_status_missing_chip_leaves_output_alone(void)
static void test_packet_status_sends_0x14_and_four_nops(void)
static void test_damaged_packets_are_counted(void)
static void test_packet_bigger_than_the_box_is_dropped(void)
static void test_packet_status_busy_never_clears(void)
static void test_chip_stuck_busy_reports_not_found(void)
static void test_bad_status_while_reading_a_packet_reports_not_found(void)
static void test_packet_is_read_with_the_right_bytes_and_length(void)
static void test_missing_chip_reading_zeros_reports_not_found(void)
static void test_start_position_in_the_chip_buffer_is_used(void)
static void test_packet_status_converts_rssi_and_negative_snr(void)
static void test_packet_status_positive_snr(void)
static void test_start_rx_continuous_fails_when_busy_never_clears(void)
static void test_missing_chip_reading_ones_reports_not_found(void)