Skip to content

Commit f3e7d2b

Browse files
committed
Add extra extract methods
1 parent 8520013 commit f3e7d2b

File tree

3 files changed

+52
-13
lines changed

3 files changed

+52
-13
lines changed

keywords.txt

+5
Original file line numberDiff line numberDiff line change
@@ -687,12 +687,17 @@ setNMEAGPZDAcallbackPtr KEYWORD2
687687
getLatestNMEAGNZDA KEYWORD2
688688
setNMEAGNZDAcallbackPtr KEYWORD2
689689

690+
extractLongLong KEYWORD2
691+
extractSignedLongLong KEYWORD2
690692
extractLong KEYWORD2
691693
extractSignedLong KEYWORD2
692694
extractInt KEYWORD2
693695
extractSignedInt KEYWORD2
694696
extractByte KEYWORD2
695697
extractSignedChar KEYWORD2
698+
extractFloat KEYWORD2
699+
extractDouble KEYWORD2
700+
696701

697702
#######################################
698703
# Constants (LITERAL1)

src/u-blox_GNSS.cpp

+32-13
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,7 @@ void DevUBLOXGNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t req
15601560
// Check if it should be passed to processNMEA
15611561
if (processThisNMEA())
15621562
{
1563-
for(uint8_t i = 0; i < 6; i++)
1563+
for (uint8_t i = 0; i < 6; i++)
15641564
{
15651565
processNMEA(nmeaAddressField[i]); // Process the start character and address field
15661566
// If user has assigned an output port then pipe the characters there,
@@ -7992,12 +7992,7 @@ bool DevUBLOXGNSS::addCfgValsetFloat(uint32_t key, float value)
79927992
}
79937993

79947994
// Define a union to convert from float to uint32_t
7995-
union
7996-
{
7997-
float flt;
7998-
uint32_t unsigned32;
7999-
//uint8_t bytes[4]; // Could be useful for endian byte reversal?
8000-
} convert32;
7995+
unsigned32float convert32;
80017996

80027997
convert32.flt = value;
80037998

@@ -8021,12 +8016,7 @@ bool DevUBLOXGNSS::addCfgValsetDouble(uint32_t key, double value)
80218016
}
80228017

80238018
// Define a union to convert from double to uint64_t
8024-
union
8025-
{
8026-
double dbl;
8027-
uint64_t unsigned64;
8028-
//uint8_t bytes[8]; // Could be useful for endian byte reversal?
8029-
} convert64;
8019+
unsigned64double convert64;
80308020

80318021
convert64.dbl = value;
80328022

@@ -15858,6 +15848,19 @@ uint64_t DevUBLOXGNSS::extractLongLong(ubxPacket *msg, uint16_t spotToStart)
1585815848
return (val);
1585915849
}
1586015850

15851+
// Given a spot in the payload array, extract eight bytes and build a int64_t
15852+
int64_t DevUBLOXGNSS::extractSignedLongLong(ubxPacket *msg, uint16_t spotToStart)
15853+
{
15854+
union
15855+
{
15856+
uint64_t unsigned64;
15857+
int64_t signed64;
15858+
} converter64;
15859+
15860+
converter64.unsigned64 = extractLongLong(msg, spotToStart);
15861+
return (converter64.signed64);
15862+
}
15863+
1586115864
// Given a spot in the payload array, extract four bytes and build a long
1586215865
uint32_t DevUBLOXGNSS::extractLong(ubxPacket *msg, uint16_t spotToStart)
1586315866
{
@@ -15905,3 +15908,19 @@ int8_t DevUBLOXGNSS::extractSignedChar(ubxPacket *msg, uint16_t spotToStart)
1590515908
converter.unsigned8 = extractByte(msg, spotToStart);
1590615909
return (converter.signed8);
1590715910
}
15911+
15912+
// Given a spot, extract a signed 32-bit float from the payload
15913+
float DevUBLOXGNSS::extractFloat(ubxPacket *msg, uint16_t spotToStart)
15914+
{
15915+
unsigned32float converter;
15916+
converter.unsigned32 = extractLong(msg, spotToStart);
15917+
return (converter.flt);
15918+
}
15919+
15920+
// Given a spot, extract a signed 32-bit float from the payload
15921+
double DevUBLOXGNSS::extractDouble(ubxPacket *msg, uint16_t spotToStart)
15922+
{
15923+
unsigned64double converter;
15924+
converter.unsigned64 = extractLongLong(msg, spotToStart);
15925+
return (converter.dbl);
15926+
}

src/u-blox_GNSS.h

+15
Original file line numberDiff line numberDiff line change
@@ -989,12 +989,15 @@ class DevUBLOXGNSS
989989
// Functions to extract signed and unsigned 8/16/32-bit data from a ubxPacket
990990
// From v2.0: These are public. The user can call these to extract data from custom packets
991991
uint64_t extractLongLong(ubxPacket *msg, uint16_t spotToStart); // Combine eight bytes from payload into uint64_t
992+
int64_t extractSignedLongLong(ubxPacket *msg, uint16_t spotToStart); // Combine eight bytes from payload into uint64_t
992993
uint32_t extractLong(ubxPacket *msg, uint16_t spotToStart); // Combine four bytes from payload into long
993994
int32_t extractSignedLong(ubxPacket *msg, uint16_t spotToStart); // Combine four bytes from payload into signed long (avoiding any ambiguity caused by casting)
994995
uint16_t extractInt(ubxPacket *msg, uint16_t spotToStart); // Combine two bytes from payload into int
995996
int16_t extractSignedInt(ubxPacket *msg, uint16_t spotToStart);
996997
uint8_t extractByte(ubxPacket *msg, uint16_t spotToStart); // Get byte from payload
997998
int8_t extractSignedChar(ubxPacket *msg, uint16_t spotToStart); // Get signed 8-bit value from payload
999+
float extractFloat(ubxPacket *msg, uint16_t spotToStart); // Get signed 32-bit float (R4) from payload
1000+
double extractDouble(ubxPacket *msg, uint16_t spotToStart); // Get signed 64-bit double (R8) from payload
9981001

9991002
// Pointers to storage for the "automatic" messages
10001003
// RAM is allocated for these if/when required.
@@ -1261,4 +1264,16 @@ class DevUBLOXGNSS
12611264
uint8_t unsigned8;
12621265
int8_t signed8;
12631266
} unsignedSigned8;
1267+
1268+
typedef union
1269+
{
1270+
uint32_t unsigned32;
1271+
float flt;
1272+
} unsigned32float;
1273+
1274+
typedef union
1275+
{
1276+
uint64_t unsigned64;
1277+
double dbl;
1278+
} unsigned64double;
12641279
};

0 commit comments

Comments
 (0)