@@ -197,7 +197,11 @@ void SFE_UBLOX_GPS::process(uint8_t incoming)
197197 else if (ubxFrameClass == CLASS_NOT_AN_ACK)
198198 processUBX (incoming, &packetCfg);
199199 else
200- ; // Serial.println("No frame class set");
200+ {
201+ #ifdef DEBUG
202+ debug.println (F (" No frame class set" ));
203+ #endif
204+ }
201205 }
202206 else if (currentSentence == NMEA)
203207 {
@@ -318,16 +322,20 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
318322
319323 if (incomingUBX->checksumA == tempA && incomingUBX->checksumB == tempB)
320324 {
321- // Serial.print("Frame cleared: ");
322- // printFrame(incomingUBX);
325+ #ifdef DEBUG
326+ debug.print (" Frame cleared: " );
327+ // printFrame(incomingUBX);
328+ #endif
323329
324330 incomingUBX->valid = true ;
325331 processUBXpacket (incomingUBX); // We've got a valid packet, now do something with it
326332 }
327333 }
328- else // Load this byte into the appropriate array
334+ else // Load this byte into the payload array
329335 {
330- incomingUBX->payload [incomingUBX->counter - 4 ] = incoming; // Store this byte into payload array
336+ // Check to see if we have room for this byte
337+ if ( (incomingUBX->counter - 4 ) < MAX_PAYLOAD_SIZE)
338+ incomingUBX->payload [incomingUBX->counter - 4 ] = incoming; // Store this byte into payload array
331339 }
332340
333341 incomingUBX->counter ++;
@@ -344,7 +352,10 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
344352 if (msg->payload [0 ] == packetCfg.cls && msg->payload [1 ] == packetCfg.id )
345353 {
346354 // The ack we just received matched the CLS/ID of last packetCfg sent
347- // Serial.println("Command sent/ack'd successfully");
355+ #ifdef DEBUG
356+ debug.println (" Command sent/ack'd successfully" );
357+ #endif
358+
348359 commandAck = true ;
349360 }
350361 }
@@ -474,8 +485,12 @@ boolean SFE_UBLOX_GPS::waitForResponse(uint16_t maxTime)
474485 if (commandAck == true ) return (true );
475486 if (packetCfg.valid == true ) return (true );
476487 }
477- // Serial.println("waitForResponse timeout");
478- return (false );
488+
489+ #ifdef DEBUG
490+ debug.println (F (" waitForResponse timeout" ));
491+ #endif
492+
493+ return (false );
479494}
480495
481496// Get the current TimeMode3 settings - these contain survey in statuses
@@ -735,4 +750,22 @@ int32_t SFE_UBLOX_GPS::getAltitude(uint16_t maxWait)
735750 alt |= payloadCfg[19 ] << 8 *3 ;
736751
737752 return (alt);
738- }
753+ }
754+
755+ // Get the current protocol version of the Ublox module we're communicating with
756+ // This is helpful when deiciding if we should call the high-precision Lat/Long (HPPOSLLH) or the regular (POSLLH)
757+ uint8_t SFE_UBLOX_GPS::getProtocolVersionHigh (uint16_t maxWait)
758+ {
759+ // Send packet with only CLS and ID, length of zero. This will cause the module to respond with the contents of that CLS/ID.
760+ packetCfg.cls = UBX_CLASS_MON;
761+ packetCfg.id = UBX_MON_VER;
762+ packetCfg.len = 0 ;
763+
764+ if (sendCommand (packetCfg, maxWait) == false )
765+ return (0 ); // If command send fails then bail
766+
767+ // We got a response, now find the extension that contains 'PROTVER'
768+ // The response for this register can be quite large, many hundreds of bytes so we have to use a new, much larger array
769+
770+ return (0 );
771+ }
0 commit comments