// ============================================================ // Test nativi (no hardware) per lib/Ltm: verifica byte-per-byte // di header, payload little-endian e CRC (XOR del payload) per // i frame G/A/S, inclusi casi limite (valori negativi). // // Vettori attesi calcolati indipendentemente in Python (struct.pack // little-endian + XOR), non copiati dall'implementazione. // ============================================================ #include #include #include "Ltm.h" void setUp(void) {} void tearDown(void) {} static void assertBytes(const uint8_t* actual, const uint8_t* expected, size_t n) { char msg[64]; for (size_t i = 0; i < n; ++i) { snprintf(msg, sizeof(msg), "byte[%zu]", i); TEST_ASSERT_EQUAL_UINT8_MESSAGE(expected[i], actual[i], msg); } } // ---- G-frame ------------------------------------------------ void test_gframe_typical(void) { static const uint8_t expected[] = {36, 84, 71, 180, 73, 25, 27, 96, 72, 122, 5, 5, 96, 59, 0, 0, 47, 217}; uint8_t out[18]; size_t n = Ltm::gframe(out, 454642100, 91900000, 5, 15200, 11, 3); TEST_ASSERT_EQUAL_size_t(18, n); assertBytes(out, expected, sizeof(expected)); } void test_gframe_negative_lat_lon_alt_no_fix(void) { static const uint8_t expected[] = {36, 84, 71, 235, 50, 164, 248, 79, 151, 33, 197, 0, 12, 254, 255, 255, 1, 74}; uint8_t out[18]; size_t n = Ltm::gframe(out, -123456789, -987654321, 0, -500, 0, 1); TEST_ASSERT_EQUAL_size_t(18, n); assertBytes(out, expected, sizeof(expected)); } // ---- A-frame -------------------------------------------------- void test_aframe_typical(void) { static const uint8_t expected[] = {36, 84, 65, 45, 0, 166, 255, 14, 1, 123}; uint8_t out[10]; size_t n = Ltm::aframe(out, 45, -90, 270); TEST_ASSERT_EQUAL_size_t(10, n); assertBytes(out, expected, sizeof(expected)); } void test_aframe_negative_pitch_full_roll(void) { static const uint8_t expected[] = {36, 84, 65, 76, 255, 180, 0, 0, 0, 7}; uint8_t out[10]; size_t n = Ltm::aframe(out, -180, 180, 0); TEST_ASSERT_EQUAL_size_t(10, n); assertBytes(out, expected, sizeof(expected)); } // ---- S-frame -------------------------------------------------- void test_sframe_typical(void) { static const uint8_t expected[] = {36, 84, 83, 16, 64, 176, 4, 254, 12, 0, 22}; uint8_t out[11]; size_t n = Ltm::sframe(out, 16400, 1200, 254, 12, 0, 0); TEST_ASSERT_EQUAL_size_t(11, n); assertBytes(out, expected, sizeof(expected)); } void test_sframe_all_zero(void) { static const uint8_t expected[] = {36, 84, 83, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t out[11]; size_t n = Ltm::sframe(out, 0, 0, 0, 0, 0, 0); TEST_ASSERT_EQUAL_size_t(11, n); assertBytes(out, expected, sizeof(expected)); } int main(int argc, char** argv) { UNITY_BEGIN(); RUN_TEST(test_gframe_typical); RUN_TEST(test_gframe_negative_lat_lon_alt_no_fix); RUN_TEST(test_aframe_typical); RUN_TEST(test_aframe_negative_pitch_full_roll); RUN_TEST(test_sframe_typical); RUN_TEST(test_sframe_all_zero); return UNITY_END(); }