Skip to content
Snippets Groups Projects
Commit efc36c92 authored by angpre's avatar angpre Committed by Alberto Nidasio
Browse files

[UBXGPS] Added utc timestamp

parent b6312525
No related branches found
No related tags found
No related merge requests found
......@@ -27,13 +27,48 @@
namespace Boardcore
{
/**
* @brief Structure to handle UBX UTC time.
* Nanoseconds range from -5000000 (5 ms) to 994999999 (~995 ms) and when
* negative the other fields have been rounded to the nearest hundredth of a
* second.
* Because of leap seconds, minutes can be a second longer or shorter, so
* seconds range from 0 to 60.
*/
struct UBXDateTime
{
uint16_t year = 0; // Year (UTC) [y]
uint8_t month = 0; // Month, range 1..12 (UTC) [month]
uint8_t day = 0; // Day of month, range 1..31 (UTC) [d]
uint8_t hour = 0; // Hour of day, range 0..23 (UTC) [h]
uint8_t minute = 0; // Minute of hour, range 0..59 (UTC) [min]
uint8_t second = 0; // Seconds of minute, range 0..60 (UTC) [s]
int32_t nanosecond = 0; // Fraction of second, range -1e9 .. 1e9 (UTC) [ns]
uint32_t accuracy = 0; // Time accuracy estimate (UTC) [ns]
static std::string header()
{
return "year,month,day,hour,minute,second,nanosecond,accuracy";
}
void print(std::ostream &os) const
{
os << year << "," << (int)month << "," << (int)day << "," << (int)hour
<< "," << (int)minute << "," << (int)second << "," << nanosecond
<< "," << accuracy;
}
};
struct UBXGPSData : public GPSData
{
UBXDateTime ubxTime;
static std::string header()
{
return "gpsTimestamp,latitude,longitude,height,velocityNorth,"
"velocityEast,velocityDown,speed,track,positionDOP,satellites,"
"fix\n";
"fix," +
UBXDateTime::header() + "\n";
}
void print(std::ostream &os) const
......@@ -41,7 +76,11 @@ struct UBXGPSData : public GPSData
os << gpsTimestamp << "," << latitude << "," << longitude << ","
<< height << "," << velocityNorth << "," << velocityEast << ","
<< velocityDown << "," << speed << "," << track << "," << positionDOP
<< "," << (int)satellites << "," << (int)fix << "\n";
<< "," << (int)satellites << "," << (int)fix << ",";
ubxTime.print(os);
os << "\n";
}
};
......
......@@ -381,6 +381,14 @@ void UBXGPSSerial::run()
threadSample.positionDOP = (float)pvtP.pDOP / 1e2;
threadSample.satellites = pvtP.numSV;
threadSample.fix = pvtP.fixType;
threadSample.ubxTime = {.year = pvtP.year,
.month = pvtP.month,
.day = pvtP.day,
.hour = pvtP.hour,
.minute = pvtP.min,
.second = pvtP.sec,
.nanosecond = pvtP.nano,
.accuracy = pvtP.tAcc};
StackLogger::getInstance().updateStack(THID_GPS);
}
......
......@@ -130,6 +130,14 @@ UBXGPSData UBXGPSSpi::sampleImpl()
sample.positionDOP = (float)pvtP.pDOP / 1e2;
sample.satellites = pvtP.numSV;
sample.fix = pvtP.fixType;
sample.ubxTime = {.year = pvtP.year,
.month = pvtP.month,
.day = pvtP.day,
.hour = pvtP.hour,
.minute = pvtP.min,
.second = pvtP.sec,
.nanosecond = pvtP.nano,
.accuracy = pvtP.tAcc};
return sample;
}
......
......@@ -81,10 +81,13 @@ int main()
printf(
"[gps] timestamp: % 4.3f, fix: %01d lat: % f lon: % f "
"height: %4.1f nsat: %2d speed: %3.2f velN: % 3.2f velE: % 3.2f "
"track %3.1f\n",
"track %3.1f utc: %04u:%02u:%02u:%02u:%02u:%02u:%09ld\n",
(float)dataGPS.gpsTimestamp / 1000000, dataGPS.fix,
dataGPS.latitude, dataGPS.longitude, dataGPS.height,
dataGPS.satellites, dataGPS.speed, dataGPS.velocityNorth,
dataGPS.velocityEast, dataGPS.track);
dataGPS.velocityEast, dataGPS.track, dataGPS.ubxTime.year,
dataGPS.ubxTime.month, dataGPS.ubxTime.day, dataGPS.ubxTime.hour,
dataGPS.ubxTime.minute, dataGPS.ubxTime.second,
dataGPS.ubxTime.nanosecond);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment