Skip to content

Commit c5d088d

Browse files
committed
Add storage for multiple SFRBX data callbacks
1 parent 027040c commit c5d088d

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
lines changed

src/u-blox_GNSS.cpp

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4121,17 +4121,23 @@ void DevUBLOXGNSS::processUBXpacket(ubxPacket *msg)
41214121
packetUBXRXMSFRBX->moduleQueried = true;
41224122

41234123
// Check if we need to copy the data for the callback
4124-
if ((packetUBXRXMSFRBX->callbackData != nullptr) // If RAM has been allocated for the copy of the data
4125-
&& (packetUBXRXMSFRBX->automaticFlags.flags.bits.callbackCopyValid == false)) // AND the data is stale
4124+
if (packetUBXRXMSFRBX->callbackData != nullptr) // If RAM has been allocated for the copies of the data
41264125
{
4127-
memcpy(&packetUBXRXMSFRBX->callbackData->gnssId, &packetUBXRXMSFRBX->data.gnssId, sizeof(UBX_RXM_SFRBX_data_t));
4128-
packetUBXRXMSFRBX->automaticFlags.flags.bits.callbackCopyValid = true;
4126+
for (uint32_t i = 0; i < UBX_RXM_SFRBX_CALLBACK_BUFFERS; i++) // Check all available buffers
4127+
{
4128+
if ((packetUBXRXMSFRBX->automaticFlags.flags.bits.callbackCopyValid & (1 << i)) == 0) // AND the buffer is empty
4129+
{
4130+
memcpy(&packetUBXRXMSFRBX->callbackData[i].gnssId, &packetUBXRXMSFRBX->data.gnssId, sizeof(UBX_RXM_SFRBX_data_t));
4131+
packetUBXRXMSFRBX->automaticFlags.flags.bits.callbackCopyValid |= (1 << i);
4132+
break; // Only copy once - into first available buffer
4133+
}
4134+
}
41294135
}
41304136

41314137
// Check if we need to copy the data for the message callbacks
4132-
if (packetUBXRXMSFRBX->callbackMessageData != nullptr) // If RAM has been allocated for the copy of the data
4138+
if (packetUBXRXMSFRBX->callbackMessageData != nullptr) // If RAM has been allocated for the copies of the data
41334139
{
4134-
for (uint16_t i = 0; i < UBX_RXM_SFRBX_MESSAGE_CALLBACK_BUFFERS; i++) // Check all available buffers
4140+
for (uint32_t i = 0; i < UBX_RXM_SFRBX_CALLBACK_BUFFERS; i++) // Check all available buffers
41354141
{
41364142
if ((packetUBXRXMSFRBX->automaticFlags.flags.bits.callbackMessageCopyValid & (1 << i)) == 0) // AND the buffer is empty
41374143
{
@@ -4142,13 +4148,13 @@ void DevUBLOXGNSS::processUBXpacket(ubxPacket *msg)
41424148
packetUBXRXMSFRBX->callbackMessageData[i].lengthLSB = msg->len & 0xFF;
41434149
packetUBXRXMSFRBX->callbackMessageData[i].lengthMSB = msg->len >> 8;
41444150

4145-
memcpy(packetUBXRXMSFRBX->callbackMessageData[i].payload, msg->payload, msg->len);
4151+
memcpy(&packetUBXRXMSFRBX->callbackMessageData[i].payload, msg->payload, msg->len);
41464152

41474153
packetUBXRXMSFRBX->callbackMessageData[i].checksumA = msg->checksumA;
41484154
packetUBXRXMSFRBX->callbackMessageData[i].checksumB = msg->checksumB;
41494155

41504156
packetUBXRXMSFRBX->automaticFlags.flags.bits.callbackMessageCopyValid |= (1 << i);
4151-
break; // abort when added
4157+
break; // Only copy once - into first available buffer
41524158
}
41534159
}
41544160
}
@@ -5820,22 +5826,25 @@ void DevUBLOXGNSS::checkCallbacks(void)
58205826

58215827
if (packetUBXRXMSFRBX != nullptr) // If RAM has been allocated for message storage
58225828
{
5823-
if (packetUBXRXMSFRBX->callbackData != nullptr) // If RAM has been allocated for the copy of the data
5829+
if (packetUBXRXMSFRBX->callbackData != nullptr) // If RAM has been allocated for the copies of the data
58245830
{
5825-
if (packetUBXRXMSFRBX->automaticFlags.flags.bits.callbackCopyValid == true) // If the copy of the data is valid
5831+
for (uint32_t i = 0; i < UBX_RXM_SFRBX_CALLBACK_BUFFERS; i++)
58265832
{
5827-
if (packetUBXRXMSFRBX->callbackPointerPtr != nullptr) // If the pointer to the callback has been defined
5833+
if ((packetUBXRXMSFRBX->automaticFlags.flags.bits.callbackCopyValid & (1 << i)) != 0) // If the copy of the data is valid
58285834
{
5829-
packetUBXRXMSFRBX->callbackPointerPtr(packetUBXRXMSFRBX->callbackData); // Call the callback
5835+
if (packetUBXRXMSFRBX->callbackPointerPtr != nullptr) // If the pointer to the callback has been defined
5836+
{
5837+
packetUBXRXMSFRBX->callbackPointerPtr(&packetUBXRXMSFRBX->callbackData[i]); // Call the callback
5838+
}
5839+
packetUBXRXMSFRBX->automaticFlags.flags.bits.callbackCopyValid &= ~(1 << i); // Mark the data as stale
58305840
}
5831-
packetUBXRXMSFRBX->automaticFlags.flags.bits.callbackCopyValid = false; // Mark the data as stale
58325841
}
58335842
}
5834-
if (packetUBXRXMSFRBX->callbackMessageData != nullptr) // If RAM has been allocated for the copy of the data
5843+
if (packetUBXRXMSFRBX->callbackMessageData != nullptr) // If RAM has been allocated for the copies of the data
58355844
{
5836-
for (uint16_t i = 0; i < UBX_RXM_SFRBX_MESSAGE_CALLBACK_BUFFERS; i++)
5845+
for (uint32_t i = 0; i < UBX_RXM_SFRBX_CALLBACK_BUFFERS; i++)
58375846
{
5838-
if ((packetUBXRXMSFRBX->automaticFlags.flags.bits.callbackMessageCopyValid & (1 << i)) > 0) // If the copy of the data is valid
5847+
if ((packetUBXRXMSFRBX->automaticFlags.flags.bits.callbackMessageCopyValid & (1 << i)) != 0) // If the copy of the data is valid
58395848
{
58405849
if (packetUBXRXMSFRBX->callbackMessagePointerPtr != nullptr) // If the pointer to the callback has been defined
58415850
{
@@ -13163,7 +13172,7 @@ bool DevUBLOXGNSS::setAutoRXMSFRBXcallbackPtr(void (*callbackPointerPtr)(UBX_RXM
1316313172

1316413173
if (packetUBXRXMSFRBX->callbackData == nullptr) // Check if RAM has been allocated for the callback copy
1316513174
{
13166-
packetUBXRXMSFRBX->callbackData = new UBX_RXM_SFRBX_data_t; // Allocate RAM for the main struct
13175+
packetUBXRXMSFRBX->callbackData = new UBX_RXM_SFRBX_data_t[UBX_RXM_SFRBX_CALLBACK_BUFFERS]; // Allocate RAM for the main struct
1316713176
}
1316813177

1316913178
if (packetUBXRXMSFRBX->callbackData == nullptr)
@@ -13188,7 +13197,7 @@ bool DevUBLOXGNSS::setAutoRXMSFRBXmessageCallbackPtr(void (*callbackMessagePoint
1318813197

1318913198
if (packetUBXRXMSFRBX->callbackMessageData == nullptr) // Check if RAM has been allocated for the callback copy
1319013199
{
13191-
packetUBXRXMSFRBX->callbackMessageData = new UBX_RXM_SFRBX_message_data_t[UBX_RXM_SFRBX_MESSAGE_CALLBACK_BUFFERS]; // Allocate RAM for the main struct
13200+
packetUBXRXMSFRBX->callbackMessageData = new UBX_RXM_SFRBX_message_data_t[UBX_RXM_SFRBX_CALLBACK_BUFFERS]; // Allocate RAM for the main struct
1319213201
}
1319313202

1319413203
if (packetUBXRXMSFRBX->callbackMessageData == nullptr)

src/u-blox_GNSS.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,7 @@ class DevUBLOXGNSS
928928

929929
bool setRXMCORcallbackPtr(void (*callbackPointerPtr)(UBX_RXM_COR_data_t *)); // RXM COR
930930

931+
// Note: RXM-SFRBX is output-only. It cannot be polled. Strictly getRXMSFRBX should be deprecated
931932
bool getRXMSFRBX(uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // RXM SFRBX
932933
bool setAutoRXMSFRBX(bool enabled, uint8_t layer = VAL_LAYER_RAM_BBR, uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Enable/disable automatic RXM SFRBX reports at the navigation frequency
933934
bool setAutoRXMSFRBX(bool enabled, bool implicitUpdate, uint8_t layer = VAL_LAYER_RAM_BBR, uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Enable/disable automatic RXM SFRBX reports at the navigation frequency, 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

src/u-blox_structs.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,10 +1426,11 @@ typedef struct
14261426
// RXM-specific structs
14271427

14281428
// UBX-RXM-SFRBX (0x02 0x13): Broadcast navigation data subframe
1429+
// Note: SFRBX is output-only. Polling is not possible
14291430
// Note: length is variable
14301431
// Note: on protocol version 17: numWords is (0..16)
14311432
// on protocol version 18+: numWords is (0..10)
1432-
#define UBX_RXM_SFRBX_MESSAGE_CALLBACK_BUFFERS 12
1433+
#define UBX_RXM_SFRBX_CALLBACK_BUFFERS 14 // 14 data buffers, 14 message buffers, 3 flags, in uint32_t
14331434
const uint8_t UBX_RXM_SFRBX_MAX_WORDS = 16;
14341435
const uint16_t UBX_RXM_SFRBX_MAX_LEN = 8 + (4 * UBX_RXM_SFRBX_MAX_WORDS);
14351436

@@ -1465,14 +1466,14 @@ struct ubxSFRBXAutomaticFlags
14651466
{
14661467
union
14671468
{
1468-
uint16_t all;
1469+
uint32_t all;
14691470
struct
14701471
{
1471-
uint16_t automatic : 1; // Will this message be delivered and parsed "automatically" (without polling)
1472-
uint16_t implicitUpdate : 1; // Is the update triggered by accessing stale data (=true) or by a call to checkUblox (=false)
1473-
uint16_t addToFileBuffer : 1; // Should the raw UBX data be added to the file buffer?
1474-
uint16_t callbackCopyValid : 1; // Is the copy of the data struct used by the callback valid/fresh?
1475-
uint16_t callbackMessageCopyValid : UBX_RXM_SFRBX_MESSAGE_CALLBACK_BUFFERS; // Are the copies of the data structs used by the callback valid/fresh?
1472+
uint32_t automatic : 1; // Will this message be delivered and parsed "automatically" (without polling)
1473+
uint32_t implicitUpdate : 1; // Is the update triggered by accessing stale data (=true) or by a call to checkUblox (=false)
1474+
uint32_t addToFileBuffer : 1; // Should the raw UBX data be added to the file buffer?
1475+
uint32_t callbackCopyValid : UBX_RXM_SFRBX_CALLBACK_BUFFERS; // Are the copies of the data struct used by the callback valid/fresh?
1476+
uint32_t callbackMessageCopyValid : UBX_RXM_SFRBX_CALLBACK_BUFFERS; // Are the copies of the data structs used by the callback valid/fresh?
14761477
} bits;
14771478
} flags;
14781479
};
@@ -1483,9 +1484,9 @@ typedef struct
14831484
UBX_RXM_SFRBX_data_t data;
14841485
bool moduleQueried;
14851486
void (*callbackPointerPtr)(UBX_RXM_SFRBX_data_t *);
1486-
UBX_RXM_SFRBX_data_t *callbackData;
1487+
UBX_RXM_SFRBX_data_t *callbackData; // This is an array of buffers
14871488
void (*callbackMessagePointerPtr)(UBX_RXM_SFRBX_message_data_t *);
1488-
UBX_RXM_SFRBX_message_data_t *callbackMessageData;
1489+
UBX_RXM_SFRBX_message_data_t *callbackMessageData; // This is an array of buffers
14891490
} UBX_RXM_SFRBX_t;
14901491

14911492
// UBX-RXM-MEASX (0x02 0x14): Receiver Manager Messages: i.e. Satellite Status, RTC Status.

0 commit comments

Comments
 (0)