简体   繁体   English

C ++从32位整数获取GPS时间

[英]C++ Get GPS Time from 32-bit Integer

Sorry if this sounds confusing, but I have a program that I am writing that needs to retrieve the GPS time (Epoch time) in minutes from a Nav unit. 抱歉,这听起来令人困惑,但是我正在编写一个程序,该程序需要从Nav单位获取以分钟为单位的GPS时间(Epoch时间)。 The Nav unit sends out a 72 byte UDP packet. 导航单元发出72字节的UDP数据包。 According to the Nav manual, bytes 63, 64, 65, and 66 contain the 32 bit GPS time. 根据Nav手册,字节63、64、65和66包含32位GPS时间。 I have tried to retrieve the time correctly but the time seems to be out. 我试图正确检索时间,但时间似乎已到。 The value I'm getting is around 18754849 where i'm pretty sure the current GPS time should be around 24020957 according to this . 我得到的价值大约是18754849在那里我敢肯定目前的GPS时间应根据被周围24020957

The code I am using to retrieve the time is below. 我用来检索时间的代码如下。 This was from a person who was working on the program previously and my maths isn't very good so I am not sure if it's right or not. 这是一个以前在该程序上工作的人提供的,我的数学不是很好,所以我不确定它是否正确。 Can anyone see any obvious errors here? 有人可以在这里看到任何明显的错误吗? Also this is where the buf value comes in. 这也是buf值的来源。

iResult = recvfrom(sock, buf, sizeof (buf), 0, 0, 0);

Thanks 谢谢

minutes = (unsigned char)buf[66]*0x1000000 + (unsigned char)buf[65]*0x10000 + (unsigned char)buf[64]*0x100 + (unsigned char)buf[63];

Solved my own problem. 解决了我自己的问题。 Turns out the GPS time is from Jan 6th 1980 where the EPOCH time is from Jan 1st 1970. I thought they were the same thing, I feel pretty stupid now. 原来GPS时间是1980年1月6日,而EPOCH时间是1970年1月1日。我以为他们是同一回事,现在我觉得很愚蠢。 Thanks anyway 不管怎么说,还是要谢谢你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM