Skip to content

Commit d3e898c

Browse files
committed
Add sfe_ublox_spartn_header_t. Return the header in parseSPARTN
1 parent 3960183 commit d3e898c

File tree

3 files changed

+57
-52
lines changed

3 files changed

+57
-52
lines changed

src/u-blox_GNSS.cpp

Lines changed: 43 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9106,7 +9106,7 @@ uint32_t DevUBLOXGNSS::uSpartnCrc32(const uint8_t *pU8Msg, size_t size)
91069106
}
91079107

91089108
// Parse SPARTN data
9109-
uint8_t * DevUBLOXGNSS::parseSPARTN(uint8_t incoming, bool &valid, uint16_t &len)
9109+
uint8_t * DevUBLOXGNSS::parseSPARTN(uint8_t incoming, bool &valid, uint16_t &len, sfe_ublox_spartn_header_t *header)
91109110
{
91119111
typedef enum {
91129112
waitingFor73,
@@ -9121,17 +9121,9 @@ uint8_t * DevUBLOXGNSS::parseSPARTN(uint8_t incoming, bool &valid, uint16_t &len
91219121

91229122
static uint8_t spartn[1100];
91239123

9124+
static sfe_ublox_spartn_header_t _header;
91249125
static uint16_t frameCount;
9125-
static uint8_t messageType;
9126-
static uint16_t payloadLength;
9127-
static uint16_t EAF;
9128-
static uint8_t crcType;
91299126
static uint16_t crcBytes;
9130-
static uint8_t frameCRC;
9131-
static uint8_t messageSubtype;
9132-
static uint16_t timeTagType;
9133-
static uint16_t authenticationIndicator;
9134-
static uint16_t embeddedApplicationLengthBytes;
91359127
static uint16_t TF007toTF016;
91369128

91379129
valid = false;
@@ -9150,21 +9142,21 @@ uint8_t * DevUBLOXGNSS::parseSPARTN(uint8_t incoming, bool &valid, uint16_t &len
91509142
spartn[1 + frameCount] = incoming;
91519143
if (frameCount == 0)
91529144
{
9153-
messageType = incoming >> 1;
9154-
payloadLength = incoming & 0x01;
9145+
_header.messageType = incoming >> 1;
9146+
_header.payloadLength = incoming & 0x01;
91559147
}
91569148
if (frameCount == 1)
91579149
{
9158-
payloadLength <<= 8;
9159-
payloadLength |= incoming;
9150+
_header.payloadLength <<= 8;
9151+
_header.payloadLength |= incoming;
91609152
}
91619153
if (frameCount == 2)
91629154
{
9163-
payloadLength <<= 1;
9164-
payloadLength |= incoming >> 7;
9165-
EAF = (incoming >> 6) & 0x01;
9166-
crcType = (incoming >> 4) & 0x03;
9167-
switch (crcType)
9155+
_header.payloadLength <<= 1;
9156+
_header.payloadLength |= incoming >> 7;
9157+
_header.EAF = (incoming >> 6) & 0x01;
9158+
_header.crcType = (incoming >> 4) & 0x03;
9159+
switch (_header.crcType)
91689160
{
91699161
case 0:
91709162
crcBytes = 1;
@@ -9179,21 +9171,21 @@ uint8_t * DevUBLOXGNSS::parseSPARTN(uint8_t incoming, bool &valid, uint16_t &len
91799171
crcBytes = 4;
91809172
break;
91819173
}
9182-
frameCRC = incoming & 0x0F;
9174+
_header.frameCRC = incoming & 0x0F;
91839175
spartn[3] = spartn[3] & 0xF0; // Zero the 4 LSBs before calculating the CRC
9184-
if (uSpartnCrc4(&spartn[1], 3) == frameCRC)
9176+
if (uSpartnCrc4(&spartn[1], 3) == _header.frameCRC)
91859177
{
91869178
spartn[3] = incoming; // Restore TF005 and TF006 now we know the data is valid
91879179
parseState = TF007;
91889180
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
91899181
if (_printDebug == true)
91909182
{
91919183
_debugSerial.print(F("SPARTN Header CRC is valid: payloadLength "));
9192-
_debugSerial.print(payloadLength);
9184+
_debugSerial.print(_header.payloadLength);
91939185
_debugSerial.print(F(" EAF "));
9194-
_debugSerial.print(EAF);
9186+
_debugSerial.print(_header.EAF);
91959187
_debugSerial.print(F(" crcType "));
9196-
_debugSerial.println(crcType);
9188+
_debugSerial.println(_header.crcType);
91979189
}
91989190
#endif
91999191
}
@@ -9212,20 +9204,20 @@ uint8_t * DevUBLOXGNSS::parseSPARTN(uint8_t incoming, bool &valid, uint16_t &len
92129204
break;
92139205
case TF007:
92149206
spartn[4] = incoming;
9215-
messageSubtype = incoming >> 4;
9216-
timeTagType = (incoming >> 3) & 0x01;
9207+
_header.messageSubtype = incoming >> 4;
9208+
_header.timeTagType = (incoming >> 3) & 0x01;
92179209
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
92189210
if (_printDebug == true)
92199211
{
92209212
_debugSerial.print(F("SPARTN timeTagType "));
9221-
_debugSerial.println(timeTagType);
9213+
_debugSerial.println(_header.timeTagType);
92229214
}
92239215
#endif
9224-
if (timeTagType == 0)
9216+
if (_header.timeTagType == 0)
92259217
TF007toTF016 = 4;
92269218
else
92279219
TF007toTF016 = 6;
9228-
if (EAF > 0)
9220+
if (_header.EAF > 0)
92299221
TF007toTF016 += 2;
92309222
parseState = TF009;
92319223
frameCount = 1;
@@ -9235,49 +9227,49 @@ uint8_t * DevUBLOXGNSS::parseSPARTN(uint8_t incoming, bool &valid, uint16_t &len
92359227
frameCount++;
92369228
if (frameCount == TF007toTF016)
92379229
{
9238-
if (EAF == 0)
9230+
if (_header.EAF == 0)
92399231
{
9240-
authenticationIndicator = 0;
9241-
embeddedApplicationLengthBytes = 0;
9232+
_header.authenticationIndicator = 0;
9233+
_header.embeddedApplicationLengthBytes = 0;
92429234
}
92439235
else
92449236
{
9245-
authenticationIndicator = (incoming >> 3) & 0x07;
9237+
_header.authenticationIndicator = (incoming >> 3) & 0x07;
92469238
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
92479239
if (_printDebug == true)
92489240
{
92499241
_debugSerial.print(F("SPARTN authenticationIndicator "));
9250-
_debugSerial.println(authenticationIndicator);
9242+
_debugSerial.println(_header.authenticationIndicator);
92519243
}
92529244
#endif
9253-
if (authenticationIndicator <= 1)
9254-
embeddedApplicationLengthBytes = 0;
9245+
if (_header.authenticationIndicator <= 1)
9246+
_header.embeddedApplicationLengthBytes = 0;
92559247
else
92569248
{
92579249
switch(incoming & 0x07)
92589250
{
92599251
case 0:
9260-
embeddedApplicationLengthBytes = 8; // 64 bits
9252+
_header.embeddedApplicationLengthBytes = 8; // 64 bits
92619253
break;
92629254
case 1:
9263-
embeddedApplicationLengthBytes = 12; // 96 bits
9255+
_header.embeddedApplicationLengthBytes = 12; // 96 bits
92649256
break;
92659257
case 2:
9266-
embeddedApplicationLengthBytes = 16; // 128 bits
9258+
_header.embeddedApplicationLengthBytes = 16; // 128 bits
92679259
break;
92689260
case 3:
9269-
embeddedApplicationLengthBytes = 32; // 256 bits
9261+
_header.embeddedApplicationLengthBytes = 32; // 256 bits
92709262
break;
92719263
default:
9272-
embeddedApplicationLengthBytes = 64; // 512 / TBD bits
9264+
_header.embeddedApplicationLengthBytes = 64; // 512 / TBD bits
92739265
break;
92749266
}
92759267
}
92769268
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
92779269
if (_printDebug == true)
92789270
{
92799271
_debugSerial.print(F("SPARTN embeddedApplicationLengthBytes "));
9280-
_debugSerial.println(embeddedApplicationLengthBytes);
9272+
_debugSerial.println(_header.embeddedApplicationLengthBytes);
92819273
}
92829274
#endif
92839275
}
@@ -9288,9 +9280,9 @@ uint8_t * DevUBLOXGNSS::parseSPARTN(uint8_t incoming, bool &valid, uint16_t &len
92889280
case TF016:
92899281
spartn[4 + TF007toTF016 + frameCount] = incoming;
92909282
frameCount++;
9291-
if (frameCount == payloadLength)
9283+
if (frameCount == _header.payloadLength)
92929284
{
9293-
if (embeddedApplicationLengthBytes > 0)
9285+
if (_header.embeddedApplicationLengthBytes > 0)
92949286
{
92959287
parseState = TF017;
92969288
frameCount = 0;
@@ -9303,21 +9295,21 @@ uint8_t * DevUBLOXGNSS::parseSPARTN(uint8_t incoming, bool &valid, uint16_t &len
93039295
}
93049296
break;
93059297
case TF017:
9306-
spartn[4 + TF007toTF016 + payloadLength + frameCount] = incoming;
9298+
spartn[4 + TF007toTF016 + _header.payloadLength + frameCount] = incoming;
93079299
frameCount++;
9308-
if (frameCount == embeddedApplicationLengthBytes)
9300+
if (frameCount == _header.embeddedApplicationLengthBytes)
93099301
{
93109302
parseState = TF018;
93119303
frameCount = 0;
93129304
}
93139305
break;
93149306
case TF018:
9315-
spartn[4 + TF007toTF016 + payloadLength + embeddedApplicationLengthBytes + frameCount] = incoming;
9307+
spartn[4 + TF007toTF016 + _header.payloadLength + _header.embeddedApplicationLengthBytes + frameCount] = incoming;
93169308
frameCount++;
93179309
if (frameCount == crcBytes)
93189310
{
93199311
parseState = waitingFor73;
9320-
uint16_t numBytes = 4 + TF007toTF016 + payloadLength + embeddedApplicationLengthBytes;
9312+
uint16_t numBytes = 4 + TF007toTF016 + _header.payloadLength + _header.embeddedApplicationLengthBytes;
93219313
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
93229314
if (_printDebug == true)
93239315
{
@@ -9326,7 +9318,7 @@ uint8_t * DevUBLOXGNSS::parseSPARTN(uint8_t incoming, bool &valid, uint16_t &len
93269318
}
93279319
#endif
93289320
uint8_t *ptr = &spartn[numBytes];
9329-
switch (crcType)
9321+
switch (_header.crcType)
93309322
{
93319323
case 0:
93329324
{
@@ -9398,8 +9390,8 @@ uint8_t * DevUBLOXGNSS::parseSPARTN(uint8_t incoming, bool &valid, uint16_t &len
93989390
break;
93999391
}
94009392

9401-
(void)messageType; // Avoid pesky compiler warnings-as-errors
9402-
(void)messageSubtype;
9393+
if (header != nullptr)
9394+
memcpy(header, &_header, sizeof(sfe_ublox_spartn_header_t));
94039395

94049396
return &spartn[0];
94059397
}

src/u-blox_GNSS.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ class DevUBLOXGNSS
470470
uint16_t uSpartnCrc16(const uint8_t *pU8Msg, size_t size);
471471
uint32_t uSpartnCrc24(const uint8_t *pU8Msg, size_t size);
472472
uint32_t uSpartnCrc32(const uint8_t *pU8Msg, size_t size);
473-
uint8_t * parseSPARTN(uint8_t incoming, bool &valid, uint16_t &len);
473+
uint8_t * parseSPARTN(uint8_t incoming, bool &valid, uint16_t &len, sfe_ublox_spartn_header_t *header = nullptr);
474474

475475
// Get unique chip ID - UBX-SEC-UNIQID
476476
bool getUniqueChipId(UBX_SEC_UNIQID_data_t *data = nullptr, uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Get the unique chip ID using UBX_SEC_UNIQID

src/u-blox_external_typedefs.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,19 @@ const uint32_t SFE_UBLOX_SECS_PER_WEEK = 60 * 60 * 24 * 7; // Seconds per week
342342
// SPARTN CRC calculation
343343
// Stolen from https://github.com/u-blox/ubxlib/blob/master/common/spartn/src/u_spartn_crc.c
344344

345+
typedef struct
346+
{
347+
uint8_t messageType;
348+
uint16_t payloadLength;
349+
uint16_t EAF;
350+
uint8_t crcType;
351+
uint8_t frameCRC;
352+
uint8_t messageSubtype;
353+
uint16_t timeTagType;
354+
uint16_t authenticationIndicator;
355+
uint16_t embeddedApplicationLengthBytes;
356+
} sfe_ublox_spartn_header_t;
357+
345358
const uint8_t sfe_ublox_u8Crc4Table[] = {
346359
0x00U, 0x0BU, 0x05U, 0x0EU, 0x0AU, 0x01U, 0x0FU, 0x04U,
347360
0x07U, 0x0CU, 0x02U, 0x09U, 0x0DU, 0x06U, 0x08U, 0x03U,

0 commit comments

Comments
 (0)