Skip to content

Commit b2e44ea

Browse files
committed
Add storage for multiple ESF MEAS callback copies
1 parent d57720f commit b2e44ea

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

src/u-blox_GNSS.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ void DevUBLOXGNSS::end(void)
469469
{
470470
if (packetUBXESFMEAS->callbackData != nullptr)
471471
{
472-
delete packetUBXESFMEAS->callbackData;
472+
delete[] packetUBXESFMEAS->callbackData;
473473
}
474474
delete packetUBXESFMEAS;
475475
packetUBXESFMEAS = nullptr;
@@ -4466,11 +4466,17 @@ void DevUBLOXGNSS::processUBXpacket(ubxPacket *msg)
44664466
packetUBXESFMEAS->data.calibTtag = extractLong(msg, 8 + (packetUBXESFMEAS->data.flags.bits.numMeas * 4));
44674467

44684468
// Check if we need to copy the data for the callback
4469-
if ((packetUBXESFMEAS->callbackData != nullptr) // If RAM has been allocated for the copy of the data
4470-
&& (packetUBXESFMEAS->automaticFlags.flags.bits.callbackCopyValid == false)) // AND the data is stale
4469+
if (packetUBXESFMEAS->callbackData != nullptr) // If RAM has been allocated for the copy of the data
44714470
{
4472-
memcpy(&packetUBXESFMEAS->callbackData->timeTag, &packetUBXESFMEAS->data.timeTag, sizeof(UBX_ESF_MEAS_data_t));
4473-
packetUBXESFMEAS->automaticFlags.flags.bits.callbackCopyValid = true;
4471+
for (uint16_t i = 0; i < UBX_ESF_MEAS_CALLBACK_BUFFERS; i++)
4472+
{
4473+
if ((packetUBXESFMEAS->automaticFlags.flags.bits.callbackCopyValid & (1 << i)) == 0) // AND the data is stale
4474+
{
4475+
memcpy(&packetUBXESFMEAS->callbackData[i].timeTag, &packetUBXESFMEAS->data.timeTag, sizeof(UBX_ESF_MEAS_data_t));
4476+
packetUBXESFMEAS->automaticFlags.flags.bits.callbackCopyValid |= (1 << i);
4477+
break; // Only copy once
4478+
}
4479+
}
44744480
}
44754481

44764482
// Check if we need to copy the data into the file buffer
@@ -5937,13 +5943,16 @@ void DevUBLOXGNSS::checkCallbacks(void)
59375943

59385944
if (packetUBXESFMEAS != nullptr) // If RAM has been allocated for message storage
59395945
if (packetUBXESFMEAS->callbackData != nullptr) // If RAM has been allocated for the copy of the data
5940-
if (packetUBXESFMEAS->automaticFlags.flags.bits.callbackCopyValid == true) // If the copy of the data is valid
5946+
for (uint16_t i = 0; i < UBX_ESF_MEAS_CALLBACK_BUFFERS; i++)
59415947
{
5942-
if (packetUBXESFMEAS->callbackPointerPtr != nullptr) // If the pointer to the callback has been defined
5948+
if ((packetUBXESFMEAS->automaticFlags.flags.bits.callbackCopyValid & (1 << i)) != 0) // If the copy of the data is valid
59435949
{
5944-
packetUBXESFMEAS->callbackPointerPtr(packetUBXESFMEAS->callbackData); // Call the callback
5950+
if (packetUBXESFMEAS->callbackPointerPtr != nullptr) // If the pointer to the callback has been defined
5951+
{
5952+
packetUBXESFMEAS->callbackPointerPtr(&packetUBXESFMEAS->callbackData[i]); // Call the callback
5953+
}
5954+
packetUBXESFMEAS->automaticFlags.flags.bits.callbackCopyValid &= ~(1 << i); // Mark the data as stale
59455955
}
5946-
packetUBXESFMEAS->automaticFlags.flags.bits.callbackCopyValid = false; // Mark the data as stale
59475956
}
59485957

59495958
if (packetUBXESFRAW != nullptr) // If RAM has been allocated for message storage
@@ -14693,7 +14702,7 @@ bool DevUBLOXGNSS::setAutoESFMEAScallbackPtr(void (*callbackPointerPtr)(UBX_ESF_
1469314702

1469414703
if (packetUBXESFMEAS->callbackData == nullptr) // Check if RAM has been allocated for the callback copy
1469514704
{
14696-
packetUBXESFMEAS->callbackData = new UBX_ESF_MEAS_data_t; // Allocate RAM for the main struct
14705+
packetUBXESFMEAS->callbackData = new UBX_ESF_MEAS_data_t[UBX_ESF_MEAS_CALLBACK_BUFFERS]; // Allocate RAM for the main struct
1469714706
}
1469814707

1469914708
if (packetUBXESFMEAS->callbackData == nullptr)

src/u-blox_structs.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,6 +2237,7 @@ typedef struct
22372237
// UBX-ESF-MEAS (0x10 0x02): External sensor fusion measurements
22382238
// Note: length is variable
22392239
// Note: ESF RAW data cannot be polled. It is "Output" only
2240+
#define UBX_ESF_MEAS_CALLBACK_BUFFERS 6
22402241
const uint16_t UBX_ESF_MEAS_MAX_LEN = 8 + (4 * DEF_MAX_NUM_ESF_MEAS) + 4;
22412242

22422243
typedef struct
@@ -2273,12 +2274,27 @@ typedef struct
22732274
uint32_t calibTtag; // OPTIONAL: Receiver local time calibrated: ms
22742275
} UBX_ESF_MEAS_data_t;
22752276

2277+
struct ubxESFMEASAutomaticFlags
2278+
{
2279+
union
2280+
{
2281+
uint16_t all;
2282+
struct
2283+
{
2284+
uint16_t automatic : 1; // Will this message be delivered and parsed "automatically" (without polling)
2285+
uint16_t implicitUpdate : 1; // Is the update triggered by accessing stale data (=true) or by a call to checkUblox (=false)
2286+
uint16_t addToFileBuffer : 1; // Should the raw UBX data be added to the file buffer?
2287+
uint16_t callbackCopyValid : UBX_ESF_MEAS_CALLBACK_BUFFERS; // Are the copies of the data struct used by the callback valid/fresh?
2288+
} bits;
2289+
} flags;
2290+
};
2291+
22762292
typedef struct
22772293
{
2278-
ubxAutomaticFlags automaticFlags;
2294+
ubxESFMEASAutomaticFlags automaticFlags;
22792295
UBX_ESF_MEAS_data_t data;
22802296
void (*callbackPointerPtr)(UBX_ESF_MEAS_data_t *);
2281-
UBX_ESF_MEAS_data_t *callbackData;
2297+
UBX_ESF_MEAS_data_t *callbackData; // This is an array of buffers
22822298
} UBX_ESF_MEAS_t;
22832299

22842300
// UBX-ESF-RAW (0x10 0x03): Raw sensor measurements

0 commit comments

Comments
 (0)