1414 */
1515#include " hardware.h"
1616
17+ // Define static member
18+ GPSHardware *GPSHardware::current_instance = nullptr ;
19+
1720/* !
1821 * @brief Constructor
1922 */
@@ -22,6 +25,8 @@ GPSHardware::GPSHardware() {
2225 _driver_type = GPS_DRV_NONE;
2326 _nmea_baud_rate = DEFAULT_MTK_NMEA_BAUD_RATE;
2427 _nmea_update_rate = DEFAULT_MTK_NMEA_UPDATE_RATE;
28+ current_instance = this ;
29+ is_nmea_valid = false ;
2530}
2631
2732/* !
@@ -38,6 +43,9 @@ GPSHardware::~GPSHardware() {
3843 delete _sfe_gps;
3944 _sfe_gps = nullptr ;
4045 }
46+ if (current_instance == this ) {
47+ current_instance = nullptr ;
48+ }
4149}
4250
4351/* !
@@ -558,7 +566,18 @@ void GPSHardware::PollStoreSentences() {
558566 }
559567 }
560568 } else if (_driver_type == GPS_DRV_UBLOX) {
561- // TODO!
569+ // Read from the GPS module for update_rate milliseconds
570+ ulong update_rate = 1000 / _nmea_update_rate;
571+ ulong start_time = millis ();
572+ WS_DEBUG_PRINTLN (" [gps] Polling u-blox GPS driver for new sentences..." );
573+ while (millis () - start_time < update_rate) {
574+ WS_DEBUG_PRINT (" ..." );
575+ _sfe_gps->checkUblox ();
576+ }
577+ WS_DEBUG_PRINTLN (" [gps] Polling complete for u-blox GPS driver!" );
578+ WS_DEBUG_PRINT (" Did We get a NMEA sentence? " );
579+ WS_DEBUG_PRINTLN (is_nmea_valid);
580+ // MONDAY: There is a crash right here!
562581 } else {
563582 WS_DEBUG_PRINTLN (" [gps] ERROR: Unsupported GPS driver type for polling!" );
564583 }
@@ -620,6 +639,7 @@ int GPSHardware::NmeaBufPop(char *sentence) {
620639bool GPSHardware::ParseNMEASentence (char *sentence) {
621640 if (!sentence)
622641 return false ;
642+
623643 if (_driver_type == GPS_DRV_MTK) {
624644 // Parse the NMEA sentence using Adafruit_GPS
625645 return _ada_gps->parse (sentence);
@@ -881,3 +901,50 @@ float GPSHardware::GetGeoidHeight() {
881901
882902 return 0 .0f ;
883903}
904+
905+ // TODO: Untested, leaving for MONDAY
906+ /* !
907+ * @brief Handles incoming NMEA characters for UBlox GPS processing
908+ * @param incoming The incoming NMEA character
909+ */
910+ void GPSHardware::HandleNmeaChar (char incoming) {
911+ static char nmea_buffer[256 ];
912+ static uint8_t nmea_buf_idx = 0 ;
913+
914+ // Add character to buffer
915+ if (nmea_buf_idx < sizeof (nmea_buffer) - 1 ) {
916+ nmea_buffer[nmea_buf_idx++] = incoming;
917+ }
918+
919+ // Check for sentence termination
920+ if (incoming == ' \n ' || incoming == ' \r ' ) {
921+ // Null terminate
922+ nmea_buffer[nmea_buf_idx] = ' \0 ' ;
923+
924+ // Push complete NMEA sentence if valid
925+ if (nmea_buf_idx > 0 && nmea_buffer[0 ] == ' $' ) {
926+ NmeaBufPush (nmea_buffer);
927+ is_nmea_valid = true ; // Mark NMEA as valid
928+ WS_DEBUG_PRINT (" [gps] Received NMEA sentence: " );
929+ WS_DEBUG_PRINTLN (nmea_buffer);
930+ }
931+
932+ // Reset for next sentence
933+ nmea_buf_idx = 0 ;
934+ }
935+
936+ // Safety reset if buffer gets too full
937+ if (nmea_buf_idx >= sizeof (nmea_buffer) - 1 ) {
938+ nmea_buf_idx = 0 ;
939+ }
940+ }
941+
942+ /* !
943+ * @brief Global override of the weak processNMEA function from UBlox library
944+ * @param incoming The incoming NMEA character from the UBlox GPS
945+ */
946+ void DevUBLOXGNSS::processNMEA (char incoming) {
947+ if (GPSHardware::current_instance) {
948+ GPSHardware::current_instance->HandleNmeaChar (incoming);
949+ }
950+ }
0 commit comments