@@ -1592,6 +1592,7 @@ void DevUBLOXGNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t req
1592
1592
// by other threads without overwriting the requested / expected Class and ID.
1593
1593
volatile static uint8_t storedClass = 0;
1594
1594
volatile static uint8_t storedID = 0;
1595
+ static size_t payloadAutoBytes;
1595
1596
if (requestedClass || requestedID) // If either is non-zero, store the requested Class and ID
1596
1597
{
1597
1598
storedClass = requestedClass;
@@ -1695,21 +1696,28 @@ void DevUBLOXGNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t req
1695
1696
}
1696
1697
#endif
1697
1698
}
1698
- if (payloadAuto != nullptr) // Check if memory is already allocated - this should be impossible!
1699
+
1700
+ // Determine the payload length
1701
+ if ((!logBecauseAuto) && (logBecauseEnabled))
1702
+ maxPayload = SFE_UBX_MAX_LENGTH;
1703
+
1704
+ // Increase the payloadAuto buffer size if necessary, by removing
1705
+ // the previous buffer
1706
+ if (payloadAuto && (payloadAutoBytes < maxPayload))
1699
1707
{
1700
- #ifndef SFE_UBLOX_REDUCED_PROG_MEM
1701
- if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
1702
- {
1703
- _debugSerial.println(F("process: memory is already allocated for payloadAuto! Deleting..."));
1704
- }
1705
- #endif
1706
- delete[] payloadAuto; // Created with new[]
1708
+ delete[] payloadAuto; // Created with new[] below
1707
1709
payloadAuto = nullptr;
1708
- packetAuto.payload = payloadAuto ;
1710
+ payloadAutoBytes = 0 ;
1709
1711
}
1710
- if ((!logBecauseAuto) && (logBecauseEnabled))
1711
- maxPayload = SFE_UBX_MAX_LENGTH;
1712
- payloadAuto = new uint8_t[maxPayload]; // Allocate RAM for payloadAuto
1712
+
1713
+ // Allocate the payloadAuto buffer if necessary
1714
+ if (payloadAuto == nullptr)
1715
+ {
1716
+ payloadAuto = new uint8_t[maxPayload];
1717
+ if (payloadAuto)
1718
+ payloadAutoBytes = maxPayload;
1719
+ }
1720
+
1713
1721
packetAuto.payload = payloadAuto;
1714
1722
if (payloadAuto == nullptr) // Check if the alloc failed
1715
1723
{
@@ -3271,11 +3279,7 @@ void DevUBLOXGNSS::processUBX(uint8_t incoming, ubxPacket *incomingUBX, uint8_t
3271
3279
// Now that the packet is complete and has been processed, we need to delete the memory
3272
3280
// allocated for packetAuto
3273
3281
if (activePacketBuffer == SFE_UBLOX_PACKET_PACKETAUTO)
3274
- {
3275
- delete[] payloadAuto; // Created with new[]
3276
- payloadAuto = nullptr;
3277
- packetAuto.payload = payloadAuto;
3278
- }
3282
+ packetAuto.payload = nullptr;
3279
3283
}
3280
3284
else // Load this byte into the payload array
3281
3285
{
0 commit comments