简体   繁体   中英

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. The Nav unit sends out a 72 byte UDP packet. According to the Nav manual, bytes 63, 64, 65, and 66 contain the 32 bit GPS time. 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 .

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.

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. Thanks anyway

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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