4 #include "../msp_native/mock_serial.h"
9 // Mock out the serial port using a string stream
13 // Create a CRSF object to test,
14 // using the StringStream as a mock UART
17 GENERIC_CRC8
test_crc(CRSF_CRC_POLY
);
19 void test_device_info(void)
21 uint8_t deviceInformation
[DEVICE_INFORMATION_LENGTH
];
23 TEST_ASSERT_EQUAL(22, DEVICE_INFORMATION_PAYLOAD_LENGTH
);
24 TEST_ASSERT_EQUAL(28, DEVICE_INFORMATION_LENGTH
);
26 crsf
.GetDeviceInformation(deviceInformation
, 0);
27 crsf
.SetExtendedHeaderAndCrc(deviceInformation
, CRSF_FRAMETYPE_DEVICE_INFO
, DEVICE_INFORMATION_FRAME_SIZE
, CRSF_ADDRESS_CRSF_RECEIVER
, CRSF_ADDRESS_FLIGHT_CONTROLLER
);
29 crsf_ext_header_t
*header
= (crsf_ext_header_t
*) deviceInformation
;
31 TEST_ASSERT_EQUAL(26, header
->frame_size
);
32 TEST_ASSERT_EQUAL(CRSF_FRAMETYPE_DEVICE_INFO
, header
->type
);
33 TEST_ASSERT_EQUAL(CRSF_ADDRESS_FLIGHT_CONTROLLER
, header
->dest_addr
);
34 TEST_ASSERT_EQUAL(CRSF_ADDRESS_FLIGHT_CONTROLLER
, header
->device_addr
);
35 TEST_ASSERT_EQUAL(CRSF_ADDRESS_CRSF_RECEIVER
, header
->orig_addr
);
36 TEST_ASSERT_EQUAL(DEVICE_INFORMATION_FRAME_SIZE
, header
->frame_size
);
38 uint8_t *data
= deviceInformation
+ sizeof(crsf_ext_header_t
);
39 uint8_t compare
[] = {0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x0, 0x45, 0x4c, 0x52, 0x53, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
41 for(int i
= 0; i
< DEVICE_INFORMATION_PAYLOAD_LENGTH
; i
++)
43 TEST_ASSERT_EQUAL(compare
[i
], data
[i
]);
46 TEST_ASSERT_EQUAL(test_crc
.calc(&deviceInformation
[2], DEVICE_INFORMATION_LENGTH
-3), deviceInformation
[DEVICE_INFORMATION_LENGTH
- 1]);
50 int main(int argc
, char **argv
)
53 RUN_TEST(test_device_info
);