Skip to content

Commit c64b230

Browse files
committed
Update UBX_Integrity_Checker.py
1 parent 0b298e7 commit c64b230

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

Utils/UBX_Integrity_Checker.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ def csum(byte, sum1, sum2):
102102

103103
processed = -1 # The number of bytes processed
104104
messages = {} # The collected message types
105-
longest = 0 # The length of the longest UBX message
106105
keepGoing = True
107106

108107
# Sync 'state machine'
@@ -132,6 +131,8 @@ def csum(byte, sum1, sum2):
132131
ubx_checksum_B = 0
133132
ubx_expected_checksum_A = 0
134133
ubx_expected_checksum_B = 0
134+
longest_UBX = 0 # The length of the longest UBX message
135+
longest_UBX_candidate = 0 # Candidate for the length of the longest valid UBX message
135136

136137
# Storage for NMEA messages
137138
nmea_length = 0
@@ -145,8 +146,9 @@ def csum(byte, sum1, sum2):
145146
nmea_csum2 = 0
146147
nmea_expected_csum1 = 0
147148
nmea_expected_csum2 = 0
149+
longest_NMEA = 0 # The length of the longest valid NMEA message
148150

149-
max_nmea_len = 100 # Maximum length for an NMEA message: use this to detect if we have lost sync while receiving an NMEA message
151+
max_nmea_len = 128 # Maximum length for an NMEA message: use this to detect if we have lost sync while receiving an NMEA message
150152
sync_lost_at = -1 # Record where we lost sync
151153
rewind_to = -1 # Keep a note of where we should rewind to if sync is lost
152154
rewind_attempts = 0 # Keep a note of how many rewinds have been attempted
@@ -257,8 +259,7 @@ def csum(byte, sum1, sum2):
257259
ubx_length = ubx_length + (c * 256) # Add the length MSB
258260
ubx_expected_checksum_A = ubx_expected_checksum_A + c # Update the expected checksum
259261
ubx_expected_checksum_B = ubx_expected_checksum_B + ubx_expected_checksum_A
260-
if (ubx_length > longest): # Update the longest UBX message length
261-
longest = ubx_length
262+
longest_UBX_candidate = ubx_length + 8 # Update the longest UBX message length candidate. Include the header, class, ID, length and checksum bytes
262263
rewind_to = processed # If we lose sync due to dropped bytes then rewind to here
263264
ubx_nmea_state = processing_payload # Now look for payload bytes (length: ubx_length)
264265
elif (ubx_nmea_state == processing_payload):
@@ -287,6 +288,8 @@ def csum(byte, sum1, sum2):
287288
messages[message_type] += 1 # if we have, increment its count
288289
else:
289290
messages[message_type] = 1 # if we have not, set its count to 1
291+
if (longest_UBX_candidate > longest_UBX): # Update the longest UBX message length
292+
longest_UBX = longest_UBX_candidate
290293
rewind_in_progress = False # Clear rewind_in_progress
291294
rewind_to = -1
292295
if (resync_in_progress == True): # Check if we are resyncing
@@ -330,6 +333,8 @@ def csum(byte, sum1, sum2):
330333
else: # ubx_length == 5
331334
nmea_char_5 = c
332335
message_type = chr(nmea_char_1) + chr(nmea_char_2) + chr(nmea_char_3) + chr(nmea_char_4) + chr(nmea_char_5) # Record the message type
336+
if (message_type == "PUBX,"): # Remove the comma from PUBX
337+
message_type = "PUBX"
333338
# Now check if this is an '*'
334339
if (c == 0x2A):
335340
# Asterix received
@@ -389,6 +394,8 @@ def csum(byte, sum1, sum2):
389394
messages[message_type] += 1 # if we have, increment its count
390395
else:
391396
messages[message_type] = 1 # if we have not, set its count to 1
397+
if (nmea_length > longest_NMEA): # Update the longest NMEA message length
398+
longest_NMEA = nmea_length
392399
# LF was received so go back to looking for B5 or a $
393400
ubx_nmea_state = looking_for_B5_dollar
394401
rewind_in_progress = False # Clear rewind_in_progress
@@ -441,7 +448,9 @@ def csum(byte, sum1, sum2):
441448
print('File size was',filesize)
442449
if (processed != filesize):
443450
print('FILE SIZE MISMATCH!!')
444-
print('Longest UBX message was %i data bytes'%longest)
451+
print('Longest valid UBX message was %i bytes'%longest_UBX)
452+
if (containsNMEA == True):
453+
print('Longest valid NMEA message was %i characters'%longest_NMEA)
445454
if len(messages) > 0:
446455
print('Message types and totals were:')
447456
for key in messages.keys():

0 commit comments

Comments
 (0)