隐蔽二进制64位时间戳从GPS纪元偏移到Python的datetime对象 [英] Covert binary 64-bit timestamp offset from the GPS epoch to python datetime object
问题描述
我想弄清楚我认为应该是一个8字节/ 64位的时间戳。
I'm trying to figure out what I think should be an 8byte/64-bit timestamp.
import datetime
GPS_EPOCH = datetime.datetime(1980, 1, 6)
t1 = "\x00\x00\xBF\x13\xDB\x79\xC0\x00" # expected: 2012-10-04 01:00:51.759
t2 = "\x00\x00\xC0\x13\xDB\x79\xC0\x00" # expected: 2012-10-04 01:00:51.760
t3 = "\x00\x00\xC2\x13\xDB\x79\xC0\x00" # expected: 2012-10-04 01:00:51.763
t4 = "\x00\x00\x80\xE7\xFB\x79\xC0\x00" # expected: 2012-10-04 01:45:40.960
我相信值(S?)从 T1结果
和 T2
应从GPS_EPOCH抵消。
不过,我似乎无法得到的结果相匹配的预期的结果日期时间。
I believe the value(s?) resulting from t1
and t2
should be offset from the GPS_EPOCH.
However, I can't seem to get the result to match the expected result datetime.
我已经读了,这似乎是合乎逻辑,这将被分成两个部分,一个是或许分数,另秒(4个字节?)。但是,我还没有发现,是基于关闭GPS纪元时间戳格式的任何引用。
I've been reading up and it seems logical that this would be split into 2 parts, with one perhaps being fractional and the other seconds (4 bytes each?). However, I haven't found any reference for timestamp formats that are based off the GPS epoch.
任何想法如何可能转化为预期的结果?
Any ideas how this could be transformed into the expected result?
推荐答案
我拥有它。您提供的只是足够的例子。
I have it. You provided just enough examples.
>>> t1 = "\x00\x00\xBF\x13\xDB\x79\xC0\x00" # expected: 2012-10-04 01:00:51.759
>>> import struct
>>> import datetime
>>> GPS_EPOCH = datetime.datetime(1980, 1, 6)
>>> t1_unpacked = struct.unpack('<q', t1)[0]
>>> t1_seconds = t1_unpacked / 52428800
>>> t1_us = int(round((t1_unpacked % 52428800) / 52.428800, 0))
>>> GPS_EPOCH + datetime.timedelta(seconds=t1_seconds, microseconds=t1_us)
datetime.datetime(2012, 10, 4, 1, 0, 51, 758750)
全部放在一起:
def gps_time(timestamp):
unpacked = struct.unpack('<q', timestamp)[0]
seconds = unpacked / 52428800
microseconds = int(round((unpacked % 52428800) / 52.428800, 0))
return GPS_EPOCH + datetime.timedelta(seconds=seconds, microseconds=microseconds)
>>> gps_time(t2)
datetime.datetime(2012, 10, 4, 1, 0, 51, 760000)
>>> gps_time(t3)
datetime.datetime(2012, 10, 4, 1, 0, 51, 762500)
>>> gps_time(t4)
datetime.datetime(2012, 10, 4, 1, 45, 40, 960000)
这篇关于隐蔽二进制64位时间戳从GPS纪元偏移到Python的datetime对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!