1

我从车辆中集成的 GPS 接收到以下数据:

INS_Time::INS_Time_Millisec[ms]   # example of the value: 295584830.0
INS_Time::INS_Time_Week[Week]  # example of the value: 2077.0
INS_Time::Leap_seconds[s]  # example of the value: 18.0

我需要的是 UTC 时间戳,所以我假设我必须结合 GPS 的所有不同时间来获得 UTC 时间戳,但我不知道应该怎么做。如果有人可以指导我完成此操作,我将不胜感激。

example of the result I want to have: 1572430625230

我正在使用python 3.7,如果有一个库,这将非常有帮助,否则我也在寻找一个算法来做到这一点

4

1 回答 1

4

我猜 :

根据https://en.wikipedia.org/wiki/Epoch_(computing)#Notable_epoch_dates_in_computing,GPS 纪元是 1980 年 1 月 6 日,GPS counts weeks (a week is defined to start on Sunday) and 6 January is the first Sunday of 1980

并根据http://leapsecond.com/java/gpsclock.htmGPS time was zero at 0h 6-Jan-1980 and since it is not perturbed by leap seconds GPS is now ahead of UTC by 18 seconds.

因此,我们必须定义 agps_epoch并减去给定的闰秒才能获得 utc 日期时间

from datetime import datetime, timedelta
import pytz

def gps_datetime(time_week, time_ms, leap_seconds):
    gps_epoch = datetime(1980, 1, 6, tzinfo=pytz.utc)
    # gps_time - utc_time = leap_seconds
    return gps_epoch + timedelta(weeks=time_week, milliseconds=time_ms, seconds=-leap_seconds)

以你的例子

>>>gps_datetime(2077, 295584830.0,18.0)
datetime.datetime(2019, 10, 30, 10, 6, 6, 830000, tzinfo=<UTC>)
>>>gps_datetime(2077, 295584830.0,18.0).timestamp()
1572429966.83  

但我与您的预期结果相差甚远(1572430625230即使以 ms 表示)

不要忘记pip install pytz

于 2019-11-04T17:10:24.647 回答