@@ -22,7 +22,7 @@ GPSHardware::GPSHardware() {
2222 _driver_type = GPS_DRV_NONE;
2323 _nmea_baud_rate = DEFAULT_MTK_NMEA_BAUD_RATE;
2424 _nmea_update_rate = DEFAULT_MTK_NMEA_UPDATE_RATE;
25-
25+
2626 // Initialize NMEA buffer
2727 _nmea_buff.head = 0 ;
2828 _nmea_buff.tail = 0 ;
@@ -108,59 +108,61 @@ bool GPSHardware::Handle_GPSConfig(wippersnapper_gps_GPSConfig *gps_config) {
108108 I2cReadDiscard ();
109109 // Iterate through the command sentences and send them to the GPS module
110110 for (size_t i = 0 ; i < gps_config->commands_ubxes_count ; i++) {
111- // TODO: Tuesday fix this frame decoder!
112- /* pb_bytes_array_t *ubx_frame = &gps_config->commands_ubxes[i];
113- // Validate minimum frame size
114- if (ubx_frame->size < 8) {
115- WS_DEBUG_PRINT("[gps] Invalid UBX frame size: ");
116- WS_DEBUG_PRINTLN(ubx_frame->size);
117- continue;
118- }
119-
120- // Validate sync bytes
121- if (ubx_frame->bytes[0] != 0xB5 || ubx_frame->bytes[1] != 0x62) {
122- WS_DEBUG_PRINTLN("[gps] Invalid UBX sync bytes");
123- continue;
124- }
125-
126- // Validate frame size
127- size_t expectedSize = 8 + payloadLength;
128- if (ubx_frame->size != expectedSize) {
129- WS_DEBUG_PRINT("[gps] Frame size mismatch. Expected: ");
130- WS_DEBUG_PRINT(expectedSize);
131- WS_DEBUG_PRINT(", Got: ");
132- WS_DEBUG_PRINTLN(ubx_frame->size);
133- continue;
134- }
135-
136- // Extract message components
137- uint8_t msgClass = ubx_frame->bytes[2];
138- uint8_t msgId = ubx_frame->bytes[3];
139- uint16_t payloadLength = ubx_frame->bytes[4] | (ubx_frame->bytes[5] << 8);
140-
141- // Get payload
142- uint8_t *payload = NULL;
143- if (payloadLength > 0) {
144- payload = &ubx_frame->bytes[6];
145- }
146-
147- WS_DEBUG_PRINT("[gps] Sending UBX CMD #");
148- WS_DEBUG_PRINT(i);
149- WS_DEBUG_PRINT(" - Class: 0x");
150- WS_DEBUG_PRINT(msgClass, HEX);
151- WS_DEBUG_PRINT(", ID: 0x");
152- WS_DEBUG_PRINT(msgId, HEX);
153- WS_DEBUG_PRINT(", Payload len: ");
154- WS_DEBUG_PRINTLN(payloadLength);
155-
156- // Send the message
157- UBXSendStatus status = _ubx_gps->sendMessageWithAck(msgClass, msgId, payload, payloadLength);
158-
159- if (status != UBXSendStatus::UBX_SEND_SUCCESS) {
160- WS_DEBUG_PRINTLN("[gps] Failed to send UBX message");
161- } else {
162- WS_DEBUG_PRINTLN("[gps] OK");
163- } */
111+ // TODO: Tuesday fix this frame decoder!
112+ /* pb_bytes_array_t *ubx_frame = &gps_config->commands_ubxes[i];
113+ // Validate minimum frame size
114+ if (ubx_frame->size < 8) {
115+ WS_DEBUG_PRINT("[gps] Invalid UBX frame size: ");
116+ WS_DEBUG_PRINTLN(ubx_frame->size);
117+ continue;
118+ }
119+
120+ // Validate sync bytes
121+ if (ubx_frame->bytes[0] != 0xB5 || ubx_frame->bytes[1] != 0x62) {
122+ WS_DEBUG_PRINTLN("[gps] Invalid UBX sync bytes");
123+ continue;
124+ }
125+
126+ // Validate frame size
127+ size_t expectedSize = 8 + payloadLength;
128+ if (ubx_frame->size != expectedSize) {
129+ WS_DEBUG_PRINT("[gps] Frame size mismatch. Expected: ");
130+ WS_DEBUG_PRINT(expectedSize);
131+ WS_DEBUG_PRINT(", Got: ");
132+ WS_DEBUG_PRINTLN(ubx_frame->size);
133+ continue;
134+ }
135+
136+ // Extract message components
137+ uint8_t msgClass = ubx_frame->bytes[2];
138+ uint8_t msgId = ubx_frame->bytes[3];
139+ uint16_t payloadLength = ubx_frame->bytes[4] | (ubx_frame->bytes[5]
140+ << 8);
141+
142+ // Get payload
143+ uint8_t *payload = NULL;
144+ if (payloadLength > 0) {
145+ payload = &ubx_frame->bytes[6];
146+ }
147+
148+ WS_DEBUG_PRINT("[gps] Sending UBX CMD #");
149+ WS_DEBUG_PRINT(i);
150+ WS_DEBUG_PRINT(" - Class: 0x");
151+ WS_DEBUG_PRINT(msgClass, HEX);
152+ WS_DEBUG_PRINT(", ID: 0x");
153+ WS_DEBUG_PRINT(msgId, HEX);
154+ WS_DEBUG_PRINT(", Payload len: ");
155+ WS_DEBUG_PRINTLN(payloadLength);
156+
157+ // Send the message
158+ UBXSendStatus status = _ubx_gps->sendMessageWithAck(msgClass, msgId,
159+ payload, payloadLength);
160+
161+ if (status != UBXSendStatus::UBX_SEND_SUCCESS) {
162+ WS_DEBUG_PRINTLN("[gps] Failed to send UBX message");
163+ } else {
164+ WS_DEBUG_PRINTLN("[gps] OK");
165+ } */
164166 }
165167 } else {
166168 WS_DEBUG_PRINTLN (" [gps] ERROR: Unsupported GPS driver type!" );
@@ -544,24 +546,17 @@ void GPSHardware::PollStoreSentences() {
544546 // hw serial for avability? more performant
545547 ulong update_rate = 1000 / _nmea_update_rate;
546548 ulong start_time = millis ();
547- WS_DEBUG_PRINTLN (" [gps] Polling u-blox GPS driver for new sentences..." );
548549 while (millis () - start_time < update_rate) {
549550 _ubx_gps_ddc->available ();
550551 }
551- WS_DEBUG_PRINTLN (" [gps] Polling completed!" );
552552 uint8_t buffer[MAX_LEN_NMEA_SENTENCE];
553553 String nmeaBuffer = " " ;
554554 int bytesAvailable = _ubx_gps_ddc->available ();
555- WS_DEBUG_PRINT (" [gps] Reading u-blox GPS data, bytes available: " );
556- WS_DEBUG_PRINTLN (bytesAvailable);
557- size_t bytesToRead = min (bytesAvailable, 82 );
558555 size_t bytesRead;
556+ size_t bytesToRead = min (bytesAvailable, 82 );
559557 if (bytesAvailable > 0 ) {
560558 bytesRead = _ubx_gps_ddc->readBytes (buffer, bytesToRead);
561559 }
562- WS_DEBUG_PRINT (" [gps] Read " );
563- WS_DEBUG_PRINT (bytesAvailable);
564- WS_DEBUG_PRINTLN (" bytes from u-blox GPS, parsing sentences...\n " );
565560 // Build NMEA sentences and parse when complete
566561 for (size_t i = 0 ; i < bytesRead; i++) {
567562 char c = buffer[i];
@@ -572,18 +567,14 @@ void GPSHardware::PollStoreSentences() {
572567 WS_DEBUG_PRINTLN (nmeaBuffer.c_str ());
573568 // Push the NMEA sentence to the buffer
574569 WS_DEBUG_PRINTLN (" [gps] Pushing NMEA sentence to buffer..." );
575- if (NmeaBufPush (nmeaBuffer.c_str ()) == 0 ) {
576- WS_DEBUG_PRINTLN (" [gps] NMEA sentence pushed to buffer." );
577- } else {
570+ if (NmeaBufPush (nmeaBuffer.c_str ()) != 0 ) {
578571 WS_DEBUG_PRINTLN (
579572 " [gps] ERROR: Unable to push NMEA sentence to buffer!" );
573+ } else {
574+ nmeaBuffer = " " ; // Reset buffer for next sentence
580575 }
581- // Reset buffer for next sentence
582- nmeaBuffer = " " ;
583576 }
584577 }
585- // Done
586- WS_DEBUG_PRINTLN (" [gps] u-blox GPS polling completed!" );
587578 } else {
588579 WS_DEBUG_PRINTLN (" [gps] ERROR: Unsupported GPS driver type for polling!" );
589580 }
@@ -595,37 +586,23 @@ void GPSHardware::PollStoreSentences() {
595586 * @return 0 on success, -1 if the buffer is full.
596587 */
597588int GPSHardware::NmeaBufPush (const char *new_sentence) {
598- WS_DEBUG_PRINT (" [gps] NmeaBufPush called with sentence: " );
599- if (!new_sentence) {
600- WS_DEBUG_PRINTLN (" NULL" );
589+ if (!new_sentence)
601590 return -1 ;
602- }
603- WS_DEBUG_PRINTLN (new_sentence);
604-
605- WS_DEBUG_PRINT (" [gps] Buffer state - head: " );
606- WS_DEBUG_PRINT (_nmea_buff.head );
607- WS_DEBUG_PRINT (" , tail: " );
608- WS_DEBUG_PRINT (_nmea_buff.tail );
609- WS_DEBUG_PRINT (" , maxlen: " );
610- WS_DEBUG_PRINTLN (_nmea_buff.maxlen );
611591
612592 int next = _nmea_buff.head + 1 ; // points to head after the current write
613593 if (next >= _nmea_buff.maxlen )
614594 next = 0 ; // wrap around
615595
616- // If buffer is full, advance tail to overwrite oldest data
596+ // If buffer is full, overwrite oldest data
617597 if (next == _nmea_buff.tail ) {
618598 _nmea_buff.tail = (_nmea_buff.tail + 1 ) % _nmea_buff.maxlen ;
619599 }
620600
621- WS_DEBUG_PRINTLN (" [gps] About to call strncpy..." );
622601 // Copy the new sentence into the buffer
623602 strncpy (_nmea_buff.sentences [_nmea_buff.head ], new_sentence,
624603 MAX_LEN_NMEA_SENTENCE - 1 );
625- WS_DEBUG_PRINTLN (" [gps] strncpy completed, setting null terminator..." );
626604 _nmea_buff.sentences [_nmea_buff.head ][MAX_LEN_NMEA_SENTENCE - 1 ] = ' \0 ' ;
627605 _nmea_buff.head = next;
628- WS_DEBUG_PRINTLN (" [gps] NmeaBufPush completed successfully" );
629606 return 0 ;
630607}
631608
@@ -659,8 +636,6 @@ int GPSHardware::NmeaBufPop(char *sentence) {
659636bool GPSHardware::ParseNMEASentence (char *sentence) {
660637 if (!sentence)
661638 return false ;
662- WS_DEBUG_PRINT (" [gps] ParseNMEASentence: " );
663- WS_DEBUG_PRINTLN (sentence);
664639 return _ada_gps->parse (sentence);
665640}
666641
0 commit comments