Resolve issue #125 . Update Epoch and LS examples.
This commit is contained in:
@@ -54,7 +54,7 @@ void setup()
|
|||||||
myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
|
myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
|
||||||
//myGNSS.saveConfiguration(); //Optional: Save the current settings to flash and BBR
|
//myGNSS.saveConfiguration(); //Optional: Save the current settings to flash and BBR
|
||||||
|
|
||||||
Serial.println("Compare Unix Epoch given with reference one from https://www.epochconverter.com/");
|
Serial.println(F("Compare Unix Epoch given with reference one from https://www.epochconverter.com/"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,48 +70,48 @@ void loop()
|
|||||||
|
|
||||||
uint32_t us; //microseconds returned by getUnixEpoch()
|
uint32_t us; //microseconds returned by getUnixEpoch()
|
||||||
uint32_t epoch = myGNSS.getUnixEpoch();
|
uint32_t epoch = myGNSS.getUnixEpoch();
|
||||||
Serial.print("Unix Epoch rounded: ");
|
Serial.print(F("Unix Epoch rounded: "));
|
||||||
Serial.print(epoch, DEC);
|
Serial.print(epoch, DEC);
|
||||||
epoch = myGNSS.getUnixEpoch(us);
|
epoch = myGNSS.getUnixEpoch(us);
|
||||||
Serial.print(" Exact Unix Epoch: ");
|
Serial.print(F(" Exact Unix Epoch: "));
|
||||||
Serial.print(epoch, DEC);
|
Serial.print(epoch, DEC);
|
||||||
Serial.print(" micros: ");
|
Serial.print(F(" micros: "));
|
||||||
Serial.println(us, DEC);
|
Serial.println(us, DEC);
|
||||||
|
|
||||||
Serial.print(myGNSS.getYear());
|
Serial.print(myGNSS.getYear());
|
||||||
Serial.print("-");
|
Serial.print(F("-"));
|
||||||
Serial.print(myGNSS.getMonth());
|
Serial.print(myGNSS.getMonth());
|
||||||
Serial.print("-");
|
Serial.print(F("-"));
|
||||||
Serial.print(myGNSS.getDay());
|
Serial.print(myGNSS.getDay());
|
||||||
Serial.print(" ");
|
Serial.print(F(" "));
|
||||||
Serial.print(myGNSS.getHour());
|
Serial.print(myGNSS.getHour());
|
||||||
Serial.print(":");
|
Serial.print(F(":"));
|
||||||
Serial.print(myGNSS.getMinute());
|
Serial.print(myGNSS.getMinute());
|
||||||
Serial.print(":");
|
Serial.print(F(":"));
|
||||||
Serial.print(myGNSS.getSecond());
|
Serial.print(myGNSS.getSecond());
|
||||||
|
|
||||||
Serial.print(" Time is ");
|
Serial.print(F(" Time is "));
|
||||||
if (myGNSS.getTimeFullyResolved() == false)
|
if (myGNSS.getTimeFullyResolved() == false)
|
||||||
{
|
{
|
||||||
Serial.print("not fully resolved but ");
|
Serial.print(F("not fully resolved but "));
|
||||||
} else {
|
} else {
|
||||||
Serial.print("fully resolved and ");
|
Serial.print(F("fully resolved and "));
|
||||||
}
|
}
|
||||||
if (myGNSS.getTimeValid() == false)
|
if (myGNSS.getTimeValid() == false)
|
||||||
{
|
{
|
||||||
Serial.print("not ");
|
Serial.print(F("not "));
|
||||||
}
|
}
|
||||||
Serial.print("valid ");
|
Serial.print(F("valid "));
|
||||||
if (myGNSS.getConfirmedTime() == false)
|
if (myGNSS.getConfirmedTime() == false)
|
||||||
{
|
{
|
||||||
Serial.print("but not ");
|
Serial.print(F("but not "));
|
||||||
} else {
|
} else {
|
||||||
Serial.print("and ");
|
Serial.print(F("and "));
|
||||||
}
|
}
|
||||||
Serial.print("confirmed");
|
Serial.print(F("confirmed"));
|
||||||
|
|
||||||
byte SIV = myGNSS.getSIV();
|
byte SIV = myGNSS.getSIV();
|
||||||
Serial.print(F(" SIV: "));
|
Serial.print(F(" SIV: "));
|
||||||
Serial.println(SIV);
|
Serial.println(SIV);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ void setup()
|
|||||||
myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
|
myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
|
||||||
myGNSS.saveConfiguration(); //Optional: Save the current settings to flash and BBR
|
myGNSS.saveConfiguration(); //Optional: Save the current settings to flash and BBR
|
||||||
|
|
||||||
Serial.println("Compare Unix Epoch given with reference one from https://www.epochconverter.com/");
|
Serial.println(F("Compare Unix Epoch given with reference one from https://www.epochconverter.com/"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,69 +75,77 @@ void loop()
|
|||||||
|
|
||||||
uint32_t us; //microseconds returned by getUnixEpoch()
|
uint32_t us; //microseconds returned by getUnixEpoch()
|
||||||
uint32_t epoch = myGNSS.getUnixEpoch();
|
uint32_t epoch = myGNSS.getUnixEpoch();
|
||||||
Serial.print("Unix Epoch rounded: ");
|
Serial.print(F("Unix Epoch rounded: "));
|
||||||
Serial.print(epoch, DEC);
|
Serial.print(epoch, DEC);
|
||||||
epoch = myGNSS.getUnixEpoch(us);
|
epoch = myGNSS.getUnixEpoch(us);
|
||||||
Serial.print(" Exact Unix Epoch: ");
|
Serial.print(F(" Exact Unix Epoch: "));
|
||||||
Serial.print(epoch, DEC);
|
Serial.print(epoch, DEC);
|
||||||
Serial.print(" micros: ");
|
Serial.print(F(" micros: "));
|
||||||
Serial.println(us, DEC);
|
Serial.println(us, DEC);
|
||||||
int32_t timeToLeapSecEvent;
|
int32_t timeToLeapSecEvent;
|
||||||
ntp_LI_e leapIndicator = (ntp_LI_e)myGNSS.getLeapIndicator(timeToLeapSecEvent);
|
ntp_LI_e leapIndicator = (ntp_LI_e)myGNSS.getLeapIndicator(timeToLeapSecEvent);
|
||||||
Serial.print("NTP LI: ");
|
Serial.print(F("NTP LI: "));
|
||||||
Serial.print(leapIndicator, DEC);
|
Serial.print(leapIndicator, DEC);
|
||||||
switch (leapIndicator){
|
switch (leapIndicator){
|
||||||
case LI_NO_WARNING:
|
case LI_NO_WARNING:
|
||||||
Serial.print(" - No event scheduled");
|
Serial.print(F(" - No event scheduled"));
|
||||||
break;
|
break;
|
||||||
case LI_LAST_MINUTE_61_SEC:
|
case LI_LAST_MINUTE_61_SEC:
|
||||||
Serial.print(" - last minute will end at 23:60");
|
Serial.print(F(" - last minute will end at 23:60"));
|
||||||
break;
|
break;
|
||||||
case LI_LAST_MINUTE_59_SEC:
|
case LI_LAST_MINUTE_59_SEC:
|
||||||
Serial.print(" - last minute will end at 23:58");
|
Serial.print(F(" - last minute will end at 23:58"));
|
||||||
break;
|
break;
|
||||||
case LI_ALARM_CONDITION:
|
case LI_ALARM_CONDITION:
|
||||||
default:
|
default:
|
||||||
Serial.print(" - Unknown (clock not synchronized)");
|
Serial.print(F(" - Unknown (clock not synchronized)"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Serial.print(". Time to the next leap second event: ");
|
if (timeToLeapSecEvent < 0)
|
||||||
Serial.println(timeToLeapSecEvent, DEC);
|
{
|
||||||
|
Serial.print(F(". Time since the last leap second event: "));
|
||||||
|
Serial.println(timeToLeapSecEvent * -1, DEC);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial.print(F(". Time to the next leap second event: "));
|
||||||
|
Serial.println(timeToLeapSecEvent, DEC);
|
||||||
|
}
|
||||||
|
|
||||||
sfe_ublox_ls_src_e leapSecSource;
|
sfe_ublox_ls_src_e leapSecSource;
|
||||||
Serial.print("Leap seconds since GPS Epoch (Jan 6th, 1980): ");
|
Serial.print(F("Leap seconds since GPS Epoch (Jan 6th, 1980): "));
|
||||||
Serial.print(myGNSS.getCurrentLeapSeconds(leapSecSource), DEC);
|
Serial.print(myGNSS.getCurrentLeapSeconds(leapSecSource), DEC);
|
||||||
switch (leapSecSource){
|
switch (leapSecSource){
|
||||||
case SFE_UBLOX_LS_SRC_DEFAULT:
|
case SFE_UBLOX_LS_SRC_DEFAULT:
|
||||||
Serial.print(" - hardcoded");
|
Serial.print(F(" - hardcoded"));
|
||||||
break;
|
break;
|
||||||
case SFE_UBLOX_LS_SRC_GLONASS:
|
case SFE_UBLOX_LS_SRC_GLONASS:
|
||||||
Serial.print(" - derived from GPS and GLONASS time difference");
|
Serial.print(F(" - derived from GPS and GLONASS time difference"));
|
||||||
break;
|
break;
|
||||||
case SFE_UBLOX_LS_SRC_GPS:
|
case SFE_UBLOX_LS_SRC_GPS:
|
||||||
Serial.print(" - according to GPS");
|
Serial.print(F(" - according to GPS"));
|
||||||
break;
|
break;
|
||||||
case SFE_UBLOX_LS_SRC_SBAS:
|
case SFE_UBLOX_LS_SRC_SBAS:
|
||||||
Serial.print(" - according to SBAS");
|
Serial.print(F(" - according to SBAS"));
|
||||||
break;
|
break;
|
||||||
case SFE_UBLOX_LS_SRC_BEIDOU:
|
case SFE_UBLOX_LS_SRC_BEIDOU:
|
||||||
Serial.print(" - according to BeiDou");
|
Serial.print(F(" - according to BeiDou"));
|
||||||
break;
|
break;
|
||||||
case SFE_UBLOX_LS_SRC_GALILEO:
|
case SFE_UBLOX_LS_SRC_GALILEO:
|
||||||
Serial.print(" - according to Galileo");
|
Serial.print(F(" - according to Galileo"));
|
||||||
break;
|
break;
|
||||||
case SFE_UBLOX_LS_SRC_AIDED:
|
case SFE_UBLOX_LS_SRC_AIDED:
|
||||||
Serial.print(" - last minute will end at 23:58");
|
Serial.print(F(" - last minute will end at 23:58"));
|
||||||
break;
|
break;
|
||||||
case SFE_UBLOX_LS_SRC_CONFIGURED:
|
case SFE_UBLOX_LS_SRC_CONFIGURED:
|
||||||
Serial.print(" - as configured)");
|
Serial.print(F(" - as configured)"));
|
||||||
break;
|
break;
|
||||||
case SFE_UBLOX_LS_SRC_UNKNOWN:
|
case SFE_UBLOX_LS_SRC_UNKNOWN:
|
||||||
default:
|
default:
|
||||||
Serial.print(" - source unknown");
|
Serial.print(F(" - source unknown"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16102,7 +16102,7 @@ int32_t SFE_UBLOX_GNSS::getNanosecond(uint16_t maxWait)
|
|||||||
return (packetUBXNAVPVT->data.nano);
|
return (packetUBXNAVPVT->data.nano);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the current Unix epoch time rounded up to the nearest second
|
// Get the current Unix epoch time rounded to the nearest second
|
||||||
uint32_t SFE_UBLOX_GNSS::getUnixEpoch(uint16_t maxWait)
|
uint32_t SFE_UBLOX_GNSS::getUnixEpoch(uint16_t maxWait)
|
||||||
{
|
{
|
||||||
if (packetUBXNAVPVT == NULL)
|
if (packetUBXNAVPVT == NULL)
|
||||||
@@ -16119,16 +16119,16 @@ uint32_t SFE_UBLOX_GNSS::getUnixEpoch(uint16_t maxWait)
|
|||||||
packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.min = false;
|
packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.min = false;
|
||||||
packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.sec = false;
|
packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.sec = false;
|
||||||
packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.all = false;
|
packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.all = false;
|
||||||
// assemble time elements into time_t - credits to Thomas Roell @ https://github.com/GrumpyOldPizza
|
uint32_t t = SFE_UBLOX_DAYS_FROM_1970_TO_2020; // Jan 1st 2020 as days from Jan 1st 1970
|
||||||
uint32_t t = ((((((((uint32_t)packetUBXNAVPVT->data.year - 1970) * 365) + ((((uint32_t)packetUBXNAVPVT->data.year - 1970) + 3) / 4)) +
|
t += (uint32_t)SFE_UBLOX_DAYS_SINCE_2020[packetUBXNAVPVT->data.year - 2020]; // Add on the number of days since 2020
|
||||||
DAYS_SINCE_MONTH[((uint32_t)packetUBXNAVPVT->data.year - 1970) & 3][(uint32_t)packetUBXNAVPVT->data.month] +
|
t += (uint32_t)SFE_UBLOX_DAYS_SINCE_MONTH[packetUBXNAVPVT->data.year % 4 == 0 ? 0 : 1][packetUBXNAVPVT->data.month - 1]; // Add on the number of days since Jan 1st
|
||||||
((uint32_t)packetUBXNAVPVT->data.day - 1)) *
|
t += (uint32_t)packetUBXNAVPVT->data.day - 1; // Add on the number of days since the 1st of the month
|
||||||
24 +
|
t *= 24; // Convert to hours
|
||||||
(uint32_t)packetUBXNAVPVT->data.hour) *
|
t += (uint32_t)packetUBXNAVPVT->data.hour; // Add on the hour
|
||||||
60 +
|
t *= 60; // Convert to minutes
|
||||||
(uint32_t)packetUBXNAVPVT->data.min) *
|
t += (uint32_t)packetUBXNAVPVT->data.min; // Add on the minute
|
||||||
60 +
|
t *= 60; // Convert to seconds
|
||||||
(uint32_t)packetUBXNAVPVT->data.sec);
|
t += (uint32_t)packetUBXNAVPVT->data.sec; // Add on the second
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16150,23 +16150,23 @@ uint32_t SFE_UBLOX_GNSS::getUnixEpoch(uint32_t µsecond, uint16_t maxWait)
|
|||||||
packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.sec = false;
|
packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.sec = false;
|
||||||
packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.nano = false;
|
packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.nano = false;
|
||||||
packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.all = false;
|
packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.all = false;
|
||||||
// assemble time elements into time_t - credits to Thomas Roell @ https://github.com/GrumpyOldPizza
|
uint32_t t = SFE_UBLOX_DAYS_FROM_1970_TO_2020; // Jan 1st 2020 as days from Jan 1st 1970
|
||||||
uint32_t t = ((((((((uint32_t)packetUBXNAVPVT->data.year - 1970) * 365) + ((((uint32_t)packetUBXNAVPVT->data.year - 1970) + 3) / 4)) +
|
t += (uint32_t)SFE_UBLOX_DAYS_SINCE_2020[packetUBXNAVPVT->data.year - 2020]; // Add on the number of days since 2020
|
||||||
DAYS_SINCE_MONTH[((uint32_t)packetUBXNAVPVT->data.year - 1970) & 3][(uint32_t)packetUBXNAVPVT->data.month] +
|
t += (uint32_t)SFE_UBLOX_DAYS_SINCE_MONTH[packetUBXNAVPVT->data.year % 4 == 0 ? 0 : 1][packetUBXNAVPVT->data.month - 1]; // Add on the number of days since Jan 1st
|
||||||
((uint32_t)packetUBXNAVPVT->data.day - 1)) *
|
t += (uint32_t)packetUBXNAVPVT->data.day - 1; // Add on the number of days since the 1st of the month
|
||||||
24 +
|
t *= 24; // Convert to hours
|
||||||
(uint32_t)packetUBXNAVPVT->data.hour) *
|
t += (uint32_t)packetUBXNAVPVT->data.hour; // Add on the hour
|
||||||
60 +
|
t *= 60; // Convert to minutes
|
||||||
(uint32_t)packetUBXNAVPVT->data.min) *
|
t += (uint32_t)packetUBXNAVPVT->data.min; // Add on the minute
|
||||||
60 +
|
t *= 60; // Convert to seconds
|
||||||
(uint32_t)packetUBXNAVPVT->data.sec);
|
t += (uint32_t)packetUBXNAVPVT->data.sec; // Add on the second
|
||||||
int32_t us = packetUBXNAVPVT->data.nano / 1000;
|
int32_t us = packetUBXNAVPVT->data.nano / 1000; // Convert nanos to micros
|
||||||
microsecond = (uint32_t)us;
|
microsecond = (uint32_t)us; // Could be -ve!
|
||||||
// adjust t if nano is negative
|
// Adjust t if nano is negative
|
||||||
if (us < 0)
|
if (us < 0)
|
||||||
{
|
{
|
||||||
microsecond = (uint32_t)(us + 1000000);
|
microsecond = (uint32_t)(us + 1000000); // Make nano +ve
|
||||||
t--;
|
t--; // Decrement t by 1 second
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -622,12 +622,22 @@ typedef struct
|
|||||||
bool moduleQueried;
|
bool moduleQueried;
|
||||||
} moduleSWVersion_t;
|
} moduleSWVersion_t;
|
||||||
|
|
||||||
const uint16_t DAYS_SINCE_MONTH[4][16] =
|
const uint32_t SFE_UBLOX_DAYS_FROM_1970_TO_2020 = 18262; // Jan 1st 2020 Epoch = 1577836800 seconds
|
||||||
{
|
const uint16_t SFE_UBLOX_DAYS_SINCE_2020[80] =
|
||||||
{0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 335, 335, 335},
|
{
|
||||||
{0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 334, 334, 334},
|
0, 366, 731, 1096, 1461, 1827, 2192, 2557, 2922, 3288,
|
||||||
{0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 334, 334, 334},
|
3653, 4018, 4383, 4749, 5114, 5479, 5844, 6210, 6575, 6940,
|
||||||
{0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 334, 334, 334},
|
7305, 7671, 8036, 8401, 8766, 9132, 9497, 9862, 10227, 10593,
|
||||||
|
10958, 11323, 11688, 12054, 12419, 12784, 13149, 13515, 13880, 14245,
|
||||||
|
14610, 14976, 15341, 15706, 16071, 16437, 16802, 17167, 17532, 17898,
|
||||||
|
18263, 18628, 18993, 19359, 19724, 20089, 20454, 20820, 21185, 21550,
|
||||||
|
21915, 22281, 22646, 23011, 23376, 23742, 24107, 24472, 24837, 25203,
|
||||||
|
25568, 25933, 26298, 26664, 27029, 27394, 27759, 28125, 28490, 28855
|
||||||
|
};
|
||||||
|
const uint16_t SFE_UBLOX_DAYS_SINCE_MONTH[2][12] =
|
||||||
|
{
|
||||||
|
{0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}, // Leap Year (Year % 4 == 0)
|
||||||
|
{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334} // Normal Year
|
||||||
};
|
};
|
||||||
|
|
||||||
class SFE_UBLOX_GNSS
|
class SFE_UBLOX_GNSS
|
||||||
|
|||||||
Reference in New Issue
Block a user