@@ -761,6 +761,9 @@ void SFE_UBLOX_GPS::processRTCM(uint8_t incoming)
761761// a subset of bytes within a larger packet.
762762void SFE_UBLOX_GPS::processUBX (uint8_t incoming, ubxPacket *incomingUBX, uint8_t requestedClass, uint8_t requestedID)
763763{
764+ size_t max_payload_size = (activePacketBuffer == SFE_UBLOX_PACKET_PACKETCFG) ? MAX_PAYLOAD_SIZE : 2 ;
765+ bool overrun = false ;
766+
764767 // Add all incoming bytes to the rolling checksum
765768 // Stop at len+4 as this is the checksum bytes to that should not be added to the rolling checksum
766769 if (incomingUBX->counter < incomingUBX->len + 4 )
@@ -926,25 +929,29 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX, uint8_t
926929 uint16_t startingSpot = incomingUBX->startingSpot ;
927930 if (incomingUBX->cls == UBX_CLASS_NAV && incomingUBX->id == UBX_NAV_PVT)
928931 startingSpot = 0 ;
929- // Begin recording if counter goes past startingSpot
930- if ((incomingUBX-> counter - 4 ) >= startingSpot )
932+ // Check if this is payload data which should be ignored
933+ if (ignoreThisPayload == false )
931934 {
932- // Check to see if we have room for this byte
933- if ((( incomingUBX->counter - 4 ) - startingSpot) < MAX_PAYLOAD_SIZE) // If counter = 208, starting spot = 200, we're good to record.
935+ // Begin recording if counter goes past startingSpot
936+ if ((incomingUBX->counter - 4 ) >= startingSpot)
934937 {
935- // Check if this is payload data which should be ignored
936- if (ignoreThisPayload == false )
938+ // Check to see if we have room for this byte
939+ if (((incomingUBX-> counter - 4 ) - startingSpot) < max_payload_size) // If counter = 208, starting spot = 200, we're good to record.
937940 {
938941 incomingUBX->payload [incomingUBX->counter - 4 - startingSpot] = incoming; // Store this byte into payload array
939942 }
943+ else
944+ {
945+ overrun = true ;
946+ }
940947 }
941948 }
942949 }
943950
944951 // Increment the counter
945952 incomingUBX->counter ++;
946953
947- if (incomingUBX->counter == MAX_PAYLOAD_SIZE)
954+ if (overrun or incomingUBX->counter == MAX_PAYLOAD_SIZE)
948955 {
949956 // Something has gone very wrong
950957 currentSentence = NONE; // Reset the sentence to being looking for a new start char
0 commit comments