From: Lauri Myllari Date: Mon, 12 Jan 2015 04:35:40 +0000 (-0800) Subject: dvb_support: add helper to convert GPS time to Unix time X-Git-Tag: v4.2.1~1823 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=80c945acc58de514d23919ef3077c8228dfc9449;p=thirdparty%2Ftvheadend.git dvb_support: add helper to convert GPS time to Unix time --- diff --git a/src/input/mpegts/dvb.h b/src/input/mpegts/dvb.h index b08c9ad1d..9ca170ae9 100644 --- a/src/input/mpegts/dvb.h +++ b/src/input/mpegts/dvb.h @@ -209,7 +209,7 @@ int atsc_get_string #define bcdtoint(i) ((((i & 0xf0) >> 4) * 10) + (i & 0x0f)) time_t dvb_convert_date(const uint8_t *dvb_buf, int local); - +time_t atsc_convert_gpstime(uint32_t gpstime); void atsc_utf16_to_utf8(const uint8_t *src, int len, char *buf, int buflen); /* diff --git a/src/input/mpegts/dvb_support.c b/src/input/mpegts/dvb_support.c index 2fb1f5c33..749cf6dbb 100644 --- a/src/input/mpegts/dvb_support.c +++ b/src/input/mpegts/dvb_support.c @@ -506,6 +506,43 @@ dvb_convert_date(const uint8_t *dvb_buf, int local) return local ? mktime(&dvb_time) : timegm(&dvb_time); } +static time_t _gps_leap_seconds[17] = { + 362793600, + 394329600, + 425865600, + 489024000, + 567993600, + 631152000, + 662688000, + 709948800, + 741484800, + 773020800, + 820454400, + 867715200, + 915148800, + 1136073600, + 1230768000, + 1341100800, + 1435708800, +}; + +time_t +atsc_convert_gpstime(uint32_t gpstime) +{ + int i; + time_t out = gpstime + 315964800; // Add Unix - GPS epoch + + for (i = (sizeof(_gps_leap_seconds)/sizeof(time_t)) - 1; i >= 0; i--) { + if (out > _gps_leap_seconds[i]) { + tvhwarn("gpstime", "leap seconds: %d", i+1); + out -= i+1; + break; + } + } + + return out; +} + /* * DVB API helpers */