diff options
-rw-r--r-- | ROMFS/px4fmu_common/init.d/rc.fw_apps | 2 | ||||
-rw-r--r-- | src/drivers/gps/mtk.cpp | 22 | ||||
-rw-r--r-- | unittests/CMakeLists.txt | 3 | ||||
-rw-r--r-- | unittests/sf0x_test.cpp | 20 | ||||
-rw-r--r-- | unittests/st24_test.cpp | 31 |
5 files changed, 31 insertions, 47 deletions
diff --git a/ROMFS/px4fmu_common/init.d/rc.fw_apps b/ROMFS/px4fmu_common/init.d/rc.fw_apps index c97b3477f..9aca3fc5f 100644 --- a/ROMFS/px4fmu_common/init.d/rc.fw_apps +++ b/ROMFS/px4fmu_common/init.d/rc.fw_apps @@ -13,5 +13,3 @@ ekf_att_pos_estimator start # fw_att_control start fw_pos_control_l1 start - -bottle_drop start diff --git a/src/drivers/gps/mtk.cpp b/src/drivers/gps/mtk.cpp index c0c47073b..c112f65a8 100644 --- a/src/drivers/gps/mtk.cpp +++ b/src/drivers/gps/mtk.cpp @@ -264,7 +264,7 @@ MTK::handle_message(gps_mtk_packet_t &packet) _gps_position->satellites_used = packet.satellites; /* convert time and date information to unix timestamp */ - struct tm timeinfo; //TODO: test this conversion + struct tm timeinfo; uint32_t timeinfo_conversion_temp; timeinfo.tm_mday = packet.date * 1e-4; @@ -280,8 +280,24 @@ MTK::handle_message(gps_mtk_packet_t &packet) timeinfo_conversion_temp -= timeinfo.tm_sec * 1e3; time_t epoch = mktime(&timeinfo); - _gps_position->time_utc_usec = epoch * 1e6; //TODO: test this - _gps_position->time_utc_usec += timeinfo_conversion_temp * 1e3; + if (epoch > GPS_EPOCH_SECS) { + // FMUv2+ boards have a hardware RTC, but GPS helps us to configure it + // and control its drift. Since we rely on the HRT for our monotonic + // clock, updating it from time to time is safe. + + timespec ts; + ts.tv_sec = epoch; + ts.tv_nsec = timeinfo_conversion_temp * 1000000ULL; + if (clock_settime(CLOCK_REALTIME, &ts)) { + warn("failed setting clock"); + } + + _gps_position->time_utc_usec = static_cast<uint64_t>(epoch) * 1000000ULL; + _gps_position->time_utc_usec += timeinfo_conversion_temp * 1000ULL; + } else { + _gps_position->time_utc_usec = 0; + } + _gps_position->timestamp_position = _gps_position->timestamp_time = hrt_absolute_time(); // Position and velocity update always at the same time diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index c2990c59f..666570a71 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -61,16 +61,13 @@ add_executable(conversion_test conversion_test.cpp ${PX_SRC}/systemcmds/tests/te add_gtest(conversion_test) # sbus2_test -# TODO: move to gtest add_executable(sbus2_test sbus2_test.cpp hrt.cpp) add_gtest(sbus2_test) # st24_test -# TODO: move to gtest add_executable(st24_test st24_test.cpp hrt.cpp ${PX_SRC}/lib/rc/st24.c) add_gtest(st24_test) # sf0x_test -# TODO: move to gtest add_executable(sf0x_test sf0x_test.cpp ${PX_SRC}/drivers/sf0x/sf0x_parser.cpp) add_gtest(sf0x_test) diff --git a/unittests/sf0x_test.cpp b/unittests/sf0x_test.cpp index 1af128bbe..ffaaaf04a 100644 --- a/unittests/sf0x_test.cpp +++ b/unittests/sf0x_test.cpp @@ -1,19 +1,15 @@ - -#include <unistd.h> -#include <string.h> -#include <stdlib.h> #include <stdio.h> -#include <systemlib/err.h> -#include <drivers/drv_hrt.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <drivers/drv_hrt.h> #include <drivers/sf0x/sf0x_parser.h> +#include <systemlib/err.h> -int main(int argc, char *argv[]) -{ - warnx("SF0X test started"); - - int ret = 0; +#include "gtest/gtest.h" +TEST(SF0XTest, SF0X) { const char LINE_MAX = 20; char _linebuf[LINE_MAX]; _linebuf[0] = '\0'; @@ -60,6 +56,4 @@ int main(int argc, char *argv[]) } warnx("test finished"); - - return ret; } diff --git a/unittests/st24_test.cpp b/unittests/st24_test.cpp index 0c56df173..89c7ffb1c 100644 --- a/unittests/st24_test.cpp +++ b/unittests/st24_test.cpp @@ -1,4 +1,3 @@ - #include <stdio.h> #include <unistd.h> #include <string.h> @@ -7,30 +6,17 @@ #include <rc/st24.h> #include "../../src/systemcmds/tests/tests.h" -int main(int argc, char *argv[]) -{ - warnx("ST24 test started"); - - char* defaultfile = "testdata/st24_data.txt"; +#include "gtest/gtest.h" - char* filepath = 0; - - if (argc < 2) { - warnx("Too few arguments. Using default file: %s", defaultfile); - filepath = defaultfile; - } else { - filepath = argv[1]; - } +TEST(ST24Test, ST24) { + const char* filepath = "testdata/st24_data.txt"; warnx("loading data from: %s", filepath); FILE *fp; fp = fopen(filepath, "rt"); - - if (!fp) { - errx(1, "failed opening file"); - } + //ASSERT_TRUE(fp); float f; unsigned x; @@ -73,12 +59,5 @@ int main(int argc, char *argv[]) } } - if (ret == EOF) { - warnx("Test finished, reached end of file"); - ret = 0; - } else { - warnx("Test aborted, errno: %d", ret); - } - - return ret; + ASSERT_EQ(EOF, ret); } |