@@ -102,7 +102,6 @@ def csum(byte, sum1, sum2):
102
102
103
103
processed = - 1 # The number of bytes processed
104
104
messages = {} # The collected message types
105
- longest = 0 # The length of the longest UBX message
106
105
keepGoing = True
107
106
108
107
# Sync 'state machine'
@@ -132,6 +131,8 @@ def csum(byte, sum1, sum2):
132
131
ubx_checksum_B = 0
133
132
ubx_expected_checksum_A = 0
134
133
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
135
136
136
137
# Storage for NMEA messages
137
138
nmea_length = 0
@@ -145,8 +146,9 @@ def csum(byte, sum1, sum2):
145
146
nmea_csum2 = 0
146
147
nmea_expected_csum1 = 0
147
148
nmea_expected_csum2 = 0
149
+ longest_NMEA = 0 # The length of the longest valid NMEA message
148
150
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
150
152
sync_lost_at = - 1 # Record where we lost sync
151
153
rewind_to = - 1 # Keep a note of where we should rewind to if sync is lost
152
154
rewind_attempts = 0 # Keep a note of how many rewinds have been attempted
@@ -257,8 +259,7 @@ def csum(byte, sum1, sum2):
257
259
ubx_length = ubx_length + (c * 256 ) # Add the length MSB
258
260
ubx_expected_checksum_A = ubx_expected_checksum_A + c # Update the expected checksum
259
261
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
262
263
rewind_to = processed # If we lose sync due to dropped bytes then rewind to here
263
264
ubx_nmea_state = processing_payload # Now look for payload bytes (length: ubx_length)
264
265
elif (ubx_nmea_state == processing_payload ):
@@ -287,6 +288,8 @@ def csum(byte, sum1, sum2):
287
288
messages [message_type ] += 1 # if we have, increment its count
288
289
else :
289
290
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
290
293
rewind_in_progress = False # Clear rewind_in_progress
291
294
rewind_to = - 1
292
295
if (resync_in_progress == True ): # Check if we are resyncing
@@ -330,6 +333,8 @@ def csum(byte, sum1, sum2):
330
333
else : # ubx_length == 5
331
334
nmea_char_5 = c
332
335
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"
333
338
# Now check if this is an '*'
334
339
if (c == 0x2A ):
335
340
# Asterix received
@@ -389,6 +394,8 @@ def csum(byte, sum1, sum2):
389
394
messages [message_type ] += 1 # if we have, increment its count
390
395
else :
391
396
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
392
399
# LF was received so go back to looking for B5 or a $
393
400
ubx_nmea_state = looking_for_B5_dollar
394
401
rewind_in_progress = False # Clear rewind_in_progress
@@ -441,7 +448,9 @@ def csum(byte, sum1, sum2):
441
448
print ('File size was' ,filesize )
442
449
if (processed != filesize ):
443
450
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 )
445
454
if len (messages ) > 0 :
446
455
print ('Message types and totals were:' )
447
456
for key in messages .keys ():
0 commit comments