From 791dfbd6d33355f0fdd0b59517ca061ef7b76b37 Mon Sep 17 00:00:00 2001 From: Damian Miralles Date: Thu, 26 Oct 2017 18:43:18 -0600 Subject: [PATCH] bugfix: Adjusting time of week (TOW) computation for GLONASS Fixing the time of week computation for GLONASS by treating N_T as a day offset from January 1. It also adds more units test for TOW checks --- .../glonass_gnav_ephemeris.cc | 11 +---- .../glonass_gnav_ephemeris_test.cc | 47 +++++++++++++++++-- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/core/system_parameters/glonass_gnav_ephemeris.cc b/src/core/system_parameters/glonass_gnav_ephemeris.cc index 43d337cc4..b1c9d2632 100644 --- a/src/core/system_parameters/glonass_gnav_ephemeris.cc +++ b/src/core/system_parameters/glonass_gnav_ephemeris.cc @@ -118,7 +118,6 @@ void Glonass_Gnav_Ephemeris::glot_to_gpst(double tod_offset, double glot2utc_cor double days = 0.0; double total_sec = 0.0, sec_of_day = 0.0; int i = 0; - boost::gregorian::days d3(0); boost::gregorian::date gps_epoch { 1980, 1, 6 }; @@ -129,14 +128,8 @@ void Glonass_Gnav_Ephemeris::glot_to_gpst(double tod_offset, double glot2utc_cor boost::posix_time::time_duration t(0, 0, tod); boost::gregorian::date d1(d_yr, 1, 1); - boost::gregorian::days d2(d_N_T); - - if(tod < 0) - { - d3 = boost::gregorian::days(-1); - } - - boost::posix_time::ptime glonass_time(d1+d2+d3, t); + boost::gregorian::days d2(d_N_T-1); + boost::posix_time::ptime glonass_time(d1+d2, t); boost::gregorian::date utc_date = glonass_time.date(); // Total number of days diff --git a/src/tests/unit-tests/system-parameters/glonass_gnav_ephemeris_test.cc b/src/tests/unit-tests/system-parameters/glonass_gnav_ephemeris_test.cc index 1d084ab4b..71aa40ac1 100644 --- a/src/tests/unit-tests/system-parameters/glonass_gnav_ephemeris_test.cc +++ b/src/tests/unit-tests/system-parameters/glonass_gnav_ephemeris_test.cc @@ -64,11 +64,12 @@ TEST(GlonassGnavEphemerisTest, ComputeGlonassTime) ASSERT_TRUE(expected_gtime.seconds() - t.seconds() < FLT_EPSILON ); } -TEST(GlonassGnavEphemerisTest, ConvertGlonassT2GpsT) +// testing case where calendar +TEST(GlonassGnavEphemerisTest, ConvertGlonassT2GpsT1) { Glonass_Gnav_Ephemeris gnav_eph; - gnav_eph.d_yr = 2005; - gnav_eph.d_N_T = 32; + gnav_eph.d_yr = 2004; + gnav_eph.d_N_T = 366+28; double tod = 70200; double week = 0.0; @@ -83,3 +84,43 @@ TEST(GlonassGnavEphemerisTest, ConvertGlonassT2GpsT) ASSERT_TRUE(week - true_week < FLT_EPSILON ); ASSERT_TRUE(tow - true_week < FLT_EPSILON ); } + +TEST(GlonassGnavEphemerisTest, ConvertGlonassT2GpsT2) +{ + Glonass_Gnav_Ephemeris gnav_eph; + gnav_eph.d_yr = 2016; + gnav_eph.d_N_T = 268; + + double tod = 7560; + double week = 0.0; + double tow = 0.0; + double true_leap_sec = 13; + double true_week = 1915; + double true_tow = 480600+true_leap_sec; + + gnav_eph.glot_to_gpst(tod, 0.0, 0.0, &week, &tow); + + // Perform assertions of decoded fields + ASSERT_TRUE(week - true_week < FLT_EPSILON ); + ASSERT_TRUE(tow - true_week < FLT_EPSILON ); +} + +TEST(GlonassGnavEphemerisTest, ConvertGlonassT2GpsT3) +{ + Glonass_Gnav_Ephemeris gnav_eph; + gnav_eph.d_yr = 2016; + gnav_eph.d_N_T = 62; + + double tod = 7560 + 6*3600; + double week = 0.0; + double tow = 0.0; + double true_leap_sec = 13; + double true_week = 1307; + double true_tow = 480600+true_leap_sec; + + gnav_eph.glot_to_gpst(tod, 0.0, 0.0, &week, &tow); + + // Perform assertions of decoded fields + ASSERT_TRUE(week - true_week < FLT_EPSILON ); + ASSERT_TRUE(tow - true_week < FLT_EPSILON ); +}