From 724e61fa70d9ea91a9a2138ad88e305f2afbc336 Mon Sep 17 00:00:00 2001 From: Ryan Friedman Date: Sat, 11 May 2024 21:45:11 -0600 Subject: [PATCH] Tools: factor out common library for GSOF * Add tests too Signed-off-by: Ryan Friedman --- Tools/ardupilotwaf/ardupilotwaf.py | 1 + Tools/scripts/run_astyle.py | 1 + libraries/AP_GPS/AP_GPS_GSOF.cpp | 6 ++++-- libraries/AP_GSOF/tests/README.md | 3 +++ libraries/AP_GSOF/tests/gsof_gps.dat | Bin 0 -> 120 bytes libraries/AP_GSOF/tests/test_gsof.cpp | 20 +++++++++++++++++--- 6 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 libraries/AP_GSOF/tests/README.md create mode 100644 libraries/AP_GSOF/tests/gsof_gps.dat diff --git a/Tools/ardupilotwaf/ardupilotwaf.py b/Tools/ardupilotwaf/ardupilotwaf.py index 7234625594..1c807ccd6b 100644 --- a/Tools/ardupilotwaf/ardupilotwaf.py +++ b/Tools/ardupilotwaf/ardupilotwaf.py @@ -38,6 +38,7 @@ COMMON_VEHICLE_DEPENDENT_LIBRARIES = [ 'AP_Compass', 'AP_Declination', 'AP_GPS', + 'AP_GSOF', 'AP_HAL', 'AP_HAL_Empty', 'AP_InertialSensor', diff --git a/Tools/scripts/run_astyle.py b/Tools/scripts/run_astyle.py index c92fc9079f..7f5a694f73 100755 --- a/Tools/scripts/run_astyle.py +++ b/Tools/scripts/run_astyle.py @@ -23,6 +23,7 @@ class AStyleChecker(object): self.directories_to_check = [ 'libraries/AP_DDS', 'libraries/AP_ExternalControl', + 'libraries/AP_GSOF', ] self.files_to_check = [ pathlib.Path(s) for s in [ diff --git a/libraries/AP_GPS/AP_GPS_GSOF.cpp b/libraries/AP_GPS/AP_GPS_GSOF.cpp index 2b537fb08d..588265b533 100644 --- a/libraries/AP_GPS/AP_GPS_GSOF.cpp +++ b/libraries/AP_GPS/AP_GPS_GSOF.cpp @@ -157,7 +157,8 @@ AP_GPS_GSOF::requestGSOF(const uint8_t messageType, const HW_Port portIndex, con } bool -AP_GPS_GSOF::validate_com_port(const uint8_t com_port) const { +AP_GPS_GSOF::validate_com_port(const uint8_t com_port) const +{ switch(com_port) { case static_cast(HW_Port::COM1): case static_cast(HW_Port::COM2): @@ -168,7 +169,8 @@ AP_GPS_GSOF::validate_com_port(const uint8_t com_port) const { } void -AP_GPS_GSOF::pack_state_data() { +AP_GPS_GSOF::pack_state_data() +{ // TODO should we pack time data if there is no fix? state.time_week_ms = pos_time.time_week_ms; state.time_week = pos_time.time_week; diff --git a/libraries/AP_GSOF/tests/README.md b/libraries/AP_GSOF/tests/README.md new file mode 100644 index 0000000000..684c317474 --- /dev/null +++ b/libraries/AP_GSOF/tests/README.md @@ -0,0 +1,3 @@ +# GSOF Tests + +A UDP packet of binary GSOF data is attached in the `gsof_data` file. diff --git a/libraries/AP_GSOF/tests/gsof_gps.dat b/libraries/AP_GSOF/tests/gsof_gps.dat new file mode 100644 index 0000000000000000000000000000000000000000..8b856f475e4895f35d68c6e7e8e5bd37b09aaf38 GIT binary patch literal 120 wcmZSLa47o6z`)2QCu+WflapZz0|S!;0}jB!iz2}(fWifGc+}8Eu=81&0jrG!5C8xG literal 0 HcmV?d00001 diff --git a/libraries/AP_GSOF/tests/test_gsof.cpp b/libraries/AP_GSOF/tests/test_gsof.cpp index 7e23d9c3a6..628a6bf136 100644 --- a/libraries/AP_GSOF/tests/test_gsof.cpp +++ b/libraries/AP_GSOF/tests/test_gsof.cpp @@ -7,20 +7,34 @@ #include +#include +#include + const AP_HAL::HAL &hal = AP_HAL::get_HAL(); TEST(AP_GSOF, incomplete_packet) { AP_GSOF gsof; - EXPECT_FALSE(gsof.parse(0)); + EXPECT_FALSE(gsof.parse(0, 5)); } TEST(AP_GSOF, packet1) { - // 02084072580000010a1e02e0680909009400000218000000000000000000000000000000000000000000000000080d000000000000000000000000000910000000000000000000000000000000000c260000000000000000000000000000000000000000000000000000000000000000000000000000a503 + FILE* fp = std::fopen("libraries/AP_GSOF/tests/gsof_gps.dat", "rb"); + EXPECT_NE(fp, nullptr); AP_GSOF gsof; - EXPECT_FALSE(gsof.parse(0)); + char c = 0; + bool parsed = false; + while (c != EOF) { + c = fgetc (fp); + parsed |= gsof.parse((uint8_t)c, 5); + } + + EXPECT_TRUE(parsed); + + fclose(fp); + } AP_GTEST_MAIN()