UBX-NAV-TIMELS support added for leap second event

This commit is contained in:
UT2UH
2021-04-14 19:33:31 +03:00
parent c97f192acf
commit c351fb5b76
5 changed files with 337 additions and 0 deletions
@@ -789,6 +789,9 @@ boolean SFE_UBLOX_GNSS::checkAutomatic(uint8_t Class, uint8_t ID)
case UBX_NAV_CLOCK:
if (packetUBXNAVCLOCK != NULL) result = true;
break;
case UBX_NAV_TIMELS:
if (packetUBXNAVTIMELS != NULL) result = true;
break;
case UBX_NAV_SVIN:
if (packetUBXNAVSVIN != NULL) result = true;
break;
@@ -916,6 +919,9 @@ uint16_t SFE_UBLOX_GNSS::getMaxPayloadSize(uint8_t Class, uint8_t ID)
case UBX_NAV_CLOCK:
maxSize = UBX_NAV_CLOCK_LEN;
break;
case UBX_NAV_TIMELS:
maxSize = UBX_NAV_TIMELS_LEN;
break;
case UBX_NAV_SVIN:
maxSize = UBX_NAV_SVIN_LEN;
break;
@@ -1949,6 +1955,26 @@ void SFE_UBLOX_GNSS::processUBXpacket(ubxPacket *msg)
}
}
}
else if (msg->id == UBX_NAV_TIMELS && msg->len == UBX_NAV_TIMELS_LEN)
{
//Parse various byte fields into storage - but only if we have memory allocated for it
if (packetUBXNAVTIMELS != NULL)
{
packetUBXNAVTIMELS->data.iTOW = extractLong(msg, 0);
packetUBXNAVTIMELS->data.version = extractByte(msg, 4);
packetUBXNAVTIMELS->data.srcOfCurrLs = extractByte(msg, 8);
packetUBXNAVTIMELS->data.currLs = extractSignedChar(msg, 9);
packetUBXNAVTIMELS->data.srcOfLsChange = extractByte(msg, 10);
packetUBXNAVTIMELS->data.lsChange = extractSignedChar(msg, 11);
packetUBXNAVTIMELS->data.timeToLsEvent = extractSignedLong(msg, 12);
packetUBXNAVTIMELS->data.dateOfLsGpsWn = extractInt(msg, 16);
packetUBXNAVTIMELS->data.dateOfLsGpsDn = extractInt(msg, 18);
packetUBXNAVTIMELS->data.valid = extractSignedChar(msg, 23);
//Mark all datums as fresh (not read before)
packetUBXNAVTIMELS->moduleQueried.moduleQueried.all = 0xFFFFFFFF;
}
}
else if (msg->id == UBX_NAV_SVIN && msg->len == UBX_NAV_SVIN_LEN)
{
//Parse various byte fields into storage - but only if we have memory allocated for it
@@ -6862,6 +6888,53 @@ void SFE_UBLOX_GNSS::logNAVCLOCK(boolean enabled)
packetUBXNAVCLOCK->automaticFlags.flags.bits.addToFileBuffer = (uint8_t)enabled;
}
// ***** NAV TIMELS automatic support
//Reads leap second event information and sets the global variables
//for future leap second change and number of leap seconds since GPS epoch
//Returns true if commands was successful
boolean SFE_UBLOX_GNSS::getLeapSecondEvent(uint16_t maxWait)
{
if (packetUBXNAVTIMELS == NULL) initPacketUBXNAVTIMELS(); //Check that RAM has been allocated for the TIMELS data
if (packetUBXNAVTIMELS == NULL) // Abort if the RAM allocation failed
return (false);
packetCfg.cls = UBX_CLASS_NAV;
packetCfg.id = UBX_NAV_TIMELS;
packetCfg.len = 0;
packetCfg.startingSpot = 0;
//The data is parsed as part of processing the response
sfe_ublox_status_e retVal = sendCommand(&packetCfg, maxWait);
if (retVal == SFE_UBLOX_STATUS_DATA_RECEIVED)
return (true);
if (retVal == SFE_UBLOX_STATUS_DATA_OVERWRITTEN)
{
return (true);
}
return (false);
}
// PRIVATE: Allocate RAM for packetUBXNAVTIMELS and initialize it
boolean SFE_UBLOX_GNSS::initPacketUBXNAVTIMELS()
{
packetUBXNAVTIMELS = new UBX_NAV_TIMELS_t; //Allocate RAM for the main struct
if (packetUBXNAVTIMELS == NULL)
{
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
_debugSerial->println(F("initPacketUBXNAVTIMELS: PANIC! RAM allocation failed!"));
return (false);
}
packetUBXNAVTIMELS->automaticFlags.flags.all = 0;
packetUBXNAVTIMELS->callbackPointer = NULL;
packetUBXNAVTIMELS->callbackData = NULL;
packetUBXNAVTIMELS->moduleQueried.moduleQueried.all = 0;
return (true);
}
// ***** NAV SVIN automatic support
//Reads survey in status and sets the global variables
@@ -10178,6 +10251,45 @@ float SFE_UBLOX_GNSS::getSurveyInMeanAccuracy(uint16_t maxWait) // Returned as m
return (((float)tempFloat) / 10000.0); //Convert 0.1mm to m
}
// ***** TIMELS Helper Functions
uint8_t SFE_UBLOX_GNSS::getLeapIndicator(int32_t& timeToLsEvent, uint16_t maxWait)
{
if (packetUBXNAVTIMELS == NULL) initPacketUBXNAVTIMELS(); //Check that RAM has been allocated for the TIMELS data
if (packetUBXNAVTIMELS == NULL) //Bail if the RAM allocation failed
return 3;
if (packetUBXNAVTIMELS->moduleQueried.moduleQueried.bits.valid == false)
getLeapSecondEvent(maxWait);
packetUBXNAVTIMELS->moduleQueried.moduleQueried.bits.valid = false; //Since we are about to give this to user, mark this data as stale
packetUBXNAVTIMELS->moduleQueried.moduleQueried.bits.lsChange = false;
packetUBXNAVTIMELS->moduleQueried.moduleQueried.bits.timeToLsEvent = false;
packetUBXNAVTIMELS->moduleQueried.moduleQueried.bits.all = false;
timeToLsEvent = packetUBXNAVTIMELS->data.timeToLsEvent;
// returns NTP Leap Indicator
// 0 -no warning
// 1 -last minute of the day has 61 seconds
// 2 -last minute of the day has 59 seconds
// 3 -unknown (clock unsynchronized)
return ((boolean)packetUBXNAVTIMELS->data.valid ? (uint8_t)(packetUBXNAVTIMELS->data.lsChange == -1 ? 2 : packetUBXNAVTIMELS->data.lsChange) : 3);
}
int8_t SFE_UBLOX_GNSS::getCurrentLeapSeconds(sfe_ublox_ls_src_e& source, uint16_t maxWait)
{
if (packetUBXNAVTIMELS == NULL) initPacketUBXNAVTIMELS(); //Check that RAM has been allocated for the TIMELS data
if (packetUBXNAVTIMELS == NULL) //Bail if the RAM allocation failed
return false;
if (packetUBXNAVTIMELS->moduleQueried.moduleQueried.bits.valid == false)
getLeapSecondEvent(maxWait);
packetUBXNAVTIMELS->moduleQueried.moduleQueried.bits.valid = false; //Since we are about to give this to user, mark this data as stale
packetUBXNAVTIMELS->moduleQueried.moduleQueried.bits.srcOfCurrLs = false;
packetUBXNAVTIMELS->moduleQueried.moduleQueried.bits.currLs = false;
packetUBXNAVTIMELS->moduleQueried.moduleQueried.bits.all = false;
source = ((sfe_ublox_ls_src_e)packetUBXNAVTIMELS->data.srcOfCurrLs);
return ((int8_t)packetUBXNAVTIMELS->data.currLs);
}
// ***** RELPOSNED Helper Functions and automatic support
float SFE_UBLOX_GNSS::getRelPosN(uint16_t maxWait) // Returned as m
@@ -407,6 +407,20 @@ enum sfe_ublox_gnss_ids_e
SFE_UBLOX_GNSS_ID_GLONASS
};
// The GNSS identifiers of leap second event info source - used by UBX-NAV-TIMELS
enum sfe_ublox_ls_src_e
{
SFE_UBLOX_LS_SRC_DEFAULT,
SFE_UBLOX_LS_SRC_GLONASS,
SFE_UBLOX_LS_SRC_GPS,
SFE_UBLOX_LS_SRC_SBAS,
SFE_UBLOX_LS_SRC_BEIDOU,
SFE_UBLOX_LS_SRC_GALILEO,
SFE_UBLOX_LS_SRC_AIDED,
SFE_UBLOX_LS_SRC_CONFIGURED,
SFE_UBLOX_LS_SRC_UNKNOWN = 255
};
#ifndef MAX_PAYLOAD_SIZE
// v2.0: keep this for backwards-compatibility, but this is largely superseded by setPacketCfgPayloadSize
#define MAX_PAYLOAD_SIZE 256 //We need ~220 bytes for getProtocolVersion on most ublox modules
@@ -800,6 +814,9 @@ public:
// Add "auto" support for NAV SVIN - to avoid needing 'global' storage
boolean getSurveyStatus(uint16_t maxWait); //Reads survey in status
// Add "auto" support for NAV TIMELS - to avoid needing 'global' storage
boolean getLeapSecondEvent(uint16_t maxWait); //Reads leap second event info
boolean getRELPOSNED(uint16_t maxWait = defaultMaxWait); //Get Relative Positioning Information of the NED frame
boolean setAutoRELPOSNED(boolean enabled, uint16_t maxWait = defaultMaxWait); //Enable/disable automatic RELPOSNED reports
boolean setAutoRELPOSNED(boolean enabled, boolean implicitUpdate, uint16_t maxWait = defaultMaxWait); //Enable/disable automatic RELPOSNED, with implicitUpdate == false accessing stale data will not issue parsing of data in the rxbuffer of your interface, instead you have to call checkUblox when you want to perform an update
@@ -1032,6 +1049,11 @@ public:
uint16_t getSurveyInObservationTime(uint16_t maxWait = defaultMaxWait); // Truncated to 65535 seconds
float getSurveyInMeanAccuracy(uint16_t maxWait = defaultMaxWait); // Returned as m
// Helper functions for TIMELS
uint8_t getLeapIndicator(int32_t& timeToLsEvent, uint16_t maxWait = defaultMaxWait);
int8_t getCurrentLeapSeconds(sfe_ublox_ls_src_e& source, uint16_t maxWait = defaultMaxWait);
// Helper functions for RELPOSNED
float getRelPosN(uint16_t maxWait = defaultMaxWait); // Returned as m
@@ -1084,6 +1106,7 @@ public:
UBX_NAV_HPPOSECEF_t *packetUBXNAVHPPOSECEF = NULL; // Pointer to struct. RAM will be allocated for this if/when necessary
UBX_NAV_HPPOSLLH_t *packetUBXNAVHPPOSLLH = NULL; // Pointer to struct. RAM will be allocated for this if/when necessary
UBX_NAV_CLOCK_t *packetUBXNAVCLOCK = NULL; // Pointer to struct. RAM will be allocated for this if/when necessary
UBX_NAV_TIMELS_t *packetUBXNAVTIMELS = NULL; // Pointer to struct. RAM will be allocated for this if/when necessary
UBX_NAV_SVIN_t *packetUBXNAVSVIN = NULL; // Pointer to struct. RAM will be allocated for this if/when necessary
UBX_NAV_RELPOSNED_t *packetUBXNAVRELPOSNED = NULL; // Pointer to struct. RAM will be allocated for this if/when necessary
@@ -1157,6 +1180,7 @@ private:
boolean initPacketUBXNAVHPPOSECEF(); // Allocate RAM for packetUBXNAVHPPOSECEF and initialize it
boolean initPacketUBXNAVHPPOSLLH(); // Allocate RAM for packetUBXNAVHPPOSLLH and initialize it
boolean initPacketUBXNAVCLOCK(); // Allocate RAM for packetUBXNAVCLOCK and initialize it
boolean initPacketUBXNAVTIMELS(); // Allocate RAM for packetUBXNAVTIMELS and initialize it
boolean initPacketUBXNAVSVIN(); // Allocate RAM for packetUBXNAVSVIN and initialize it
boolean initPacketUBXNAVRELPOSNED(); // Allocate RAM for packetUBXNAVRELPOSNED and initialize it
boolean initPacketUBXRXMSFRBX(); // Allocate RAM for packetUBXRXMSFRBX and initialize it
+51
View File
@@ -854,6 +854,57 @@ typedef struct
UBX_NAV_CLOCK_data_t *callbackData;
} UBX_NAV_CLOCK_t;
// UBX-NAV-TIMELS (0x01 0x26): Leap second event information
const uint16_t UBX_NAV_TIMELS_LEN = 24;
typedef struct
{
uint32_t iTOW; // GPS time of week of the navigation epoch: ms
uint8_t version; // Message version (0x00 for this version)
uint8_t reserved1[3];
uint8_t srcOfCurrLs; //Information source for the current number of leap seconds
int8_t currLs; //Current number of leap seconds since start of GPS (Jan 6, 1980), s
uint8_t srcOfLsChange; //Information source for the future leap second event
int8_t lsChange; //Future leap second change if one is scheduled, +1, 0, -1s
int32_t timeToLsEvent; //Num of secs until the next or from the last leap second, s
uint16_t dateOfLsGpsWn; //GPS week num (WN) of the next or the last leap second event
uint16_t dateOfLsGpsDn; //GPS day of week num (DN) for the next or last leap second event
uint8_t reserved2[3];
int8_t valid; // Validity flag, 1 = valid, otherwise 0
} UBX_NAV_TIMELS_data_t;
typedef struct
{
union
{
uint32_t all;
struct
{
uint32_t all : 1;
uint32_t iTOW : 1;
uint32_t version : 1;
uint32_t srcOfCurrLs : 1;
uint32_t currLs : 1;
uint32_t srcOfLsChange : 1;
uint32_t lsChange : 1;
uint32_t timeToLsEvent : 1;
uint32_t dateOfLsGpsWn : 1;
uint32_t dateOfLsGpsDn : 1;
uint32_t valid : 1;
} bits;
} moduleQueried;
} UBX_NAV_TIMELS_moduleQueried_t;
typedef struct
{
ubxAutomaticFlags automaticFlags;
UBX_NAV_TIMELS_data_t data;
UBX_NAV_TIMELS_moduleQueried_t moduleQueried;
void (*callbackPointer)(UBX_NAV_TIMELS_data_t);
UBX_NAV_TIMELS_data_t *callbackData;
} UBX_NAV_TIMELS_t;
// UBX-NAV-SVIN (0x01 0x3B): Survey-in data
const uint16_t UBX_NAV_SVIN_LEN = 40;