@@ -8954,16 +8954,41 @@ int32_t SFE_UBLOX_GNSS::getNanosecond(uint16_t maxWait)
8954
8954
return (packetUBXNAVPVT->data.nano);
8955
8955
}
8956
8956
8957
- //Get the current Unix epoch - includes microseconds
8957
+ //Get the current Unix epoch time rounded up to the nearest second
8958
+ uint32_t SFE_UBLOX_GNSS::getUnixEpoch(uint16_t maxWait)
8959
+ {
8960
+ if (packetUBXNAVPVT == NULL) initPacketUBXNAVPVT(); //Check that RAM has been allocated for the PVT data
8961
+ if (packetUBXNAVPVT == NULL) //Bail if the RAM allocation failed
8962
+ return 0;
8963
+
8964
+ if (packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.sec == false)
8965
+ getPVT(maxWait);
8966
+ packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.year = false;
8967
+ packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.month = false;
8968
+ packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.day = false;
8969
+ packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.hour = false;
8970
+ packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.min = false;
8971
+ packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.sec = false;
8972
+ packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.all = false;
8973
+ // assemble time elements into time_t - credits to Thomas Roell @ https://github.com/GrumpyOldPizza
8974
+ uint32_t t = (uint32_t)(((((((packetUBXNAVPVT->data.year - 1970) * 365) + (((packetUBXNAVPVT->data.year - 1970) + 3) / 4)) +
8975
+ DAYS_SINCE_MONTH[(packetUBXNAVPVT->data.year - 1970) & 3][packetUBXNAVPVT->data.month] +
8976
+ (packetUBXNAVPVT->data.day - 1)) * 24 +
8977
+ packetUBXNAVPVT->data.hour) * 60 +
8978
+ packetUBXNAVPVT->data.min) * 60 +
8979
+ packetUBXNAVPVT->data.sec);
8980
+ return t;
8981
+ }
8982
+
8983
+ //Get the current Unix epoch including microseconds
8958
8984
uint32_t SFE_UBLOX_GNSS::getUnixEpoch(uint32_t& microsecond, uint16_t maxWait)
8959
8985
{
8960
8986
if (packetUBXNAVPVT == NULL) initPacketUBXNAVPVT(); //Check that RAM has been allocated for the PVT data
8961
8987
if (packetUBXNAVPVT == NULL) //Bail if the RAM allocation failed
8962
8988
return 0;
8963
8989
8964
- if (packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.confirmedTime == false)
8990
+ if (packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.nano == false)
8965
8991
getPVT(maxWait);
8966
- packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.confirmedTime = false;
8967
8992
packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.year = false;
8968
8993
packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.month = false;
8969
8994
packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.day = false;
@@ -8972,23 +8997,19 @@ uint32_t SFE_UBLOX_GNSS::getUnixEpoch(uint32_t& microsecond, uint16_t maxWait)
8972
8997
packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.sec = false;
8973
8998
packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.nano = false;
8974
8999
packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.all = false;
8975
- uint32_t t = 0;
8976
- if((bool)packetUBXNAVPVT->data.flags2.bits.confirmedTime)
8977
- {
8978
- // assemble time elements into time_t - credits to Thomas Roell @ https://github.com/GrumpyOldPizza
8979
- t = (uint32_t)(((((((packetUBXNAVPVT->data.year - 1970) * 365) + (((packetUBXNAVPVT->data.year - 1970) + 3) / 4)) +
9000
+ // assemble time elements into time_t - credits to Thomas Roell @ https://github.com/GrumpyOldPizza
9001
+ uint32_t t = (uint32_t)(((((((packetUBXNAVPVT->data.year - 1970) * 365) + (((packetUBXNAVPVT->data.year - 1970) + 3) / 4)) +
8980
9002
DAYS_SINCE_MONTH[(packetUBXNAVPVT->data.year - 1970) & 3][packetUBXNAVPVT->data.month] +
8981
9003
(packetUBXNAVPVT->data.day - 1)) * 24 +
8982
9004
packetUBXNAVPVT->data.hour) * 60 +
8983
9005
packetUBXNAVPVT->data.min) * 60 +
8984
9006
packetUBXNAVPVT->data.sec);
8985
- int32_t us = packetUBXNAVPVT->data.nano / 1000;
8986
- microsecond = (uint32_t)us;
8987
- // adjust t if nano is negative
8988
- if(us < 0) {
8989
- microsecond = (uint32_t)(us + 1000000);
8990
- t--;
8991
- }
9007
+ int32_t us = packetUBXNAVPVT->data.nano / 1000;
9008
+ microsecond = (uint32_t)us;
9009
+ // adjust t if nano is negative
9010
+ if(us < 0) {
9011
+ microsecond = (uint32_t)(us + 1000000);
9012
+ t--;
8992
9013
}
8993
9014
return t;
8994
9015
}
0 commit comments