@@ -22,7 +22,7 @@ GPSHardware::GPSHardware() {
22
22
_driver_type = GPS_DRV_NONE;
23
23
_nmea_baud_rate = DEFAULT_MTK_NMEA_BAUD_RATE;
24
24
_nmea_update_rate = DEFAULT_MTK_NMEA_UPDATE_RATE;
25
-
25
+
26
26
// Initialize NMEA buffer
27
27
_nmea_buff.head = 0 ;
28
28
_nmea_buff.tail = 0 ;
@@ -108,59 +108,61 @@ bool GPSHardware::Handle_GPSConfig(wippersnapper_gps_GPSConfig *gps_config) {
108
108
I2cReadDiscard ();
109
109
// Iterate through the command sentences and send them to the GPS module
110
110
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
+ } */
164
166
}
165
167
} else {
166
168
WS_DEBUG_PRINTLN (" [gps] ERROR: Unsupported GPS driver type!" );
@@ -544,24 +546,17 @@ void GPSHardware::PollStoreSentences() {
544
546
// hw serial for avability? more performant
545
547
ulong update_rate = 1000 / _nmea_update_rate;
546
548
ulong start_time = millis ();
547
- WS_DEBUG_PRINTLN (" [gps] Polling u-blox GPS driver for new sentences..." );
548
549
while (millis () - start_time < update_rate) {
549
550
_ubx_gps_ddc->available ();
550
551
}
551
- WS_DEBUG_PRINTLN (" [gps] Polling completed!" );
552
552
uint8_t buffer[MAX_LEN_NMEA_SENTENCE];
553
553
String nmeaBuffer = " " ;
554
554
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 );
558
555
size_t bytesRead;
556
+ size_t bytesToRead = min (bytesAvailable, 82 );
559
557
if (bytesAvailable > 0 ) {
560
558
bytesRead = _ubx_gps_ddc->readBytes (buffer, bytesToRead);
561
559
}
562
- WS_DEBUG_PRINT (" [gps] Read " );
563
- WS_DEBUG_PRINT (bytesAvailable);
564
- WS_DEBUG_PRINTLN (" bytes from u-blox GPS, parsing sentences...\n " );
565
560
// Build NMEA sentences and parse when complete
566
561
for (size_t i = 0 ; i < bytesRead; i++) {
567
562
char c = buffer[i];
@@ -572,18 +567,14 @@ void GPSHardware::PollStoreSentences() {
572
567
WS_DEBUG_PRINTLN (nmeaBuffer.c_str ());
573
568
// Push the NMEA sentence to the buffer
574
569
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 ) {
578
571
WS_DEBUG_PRINTLN (
579
572
" [gps] ERROR: Unable to push NMEA sentence to buffer!" );
573
+ } else {
574
+ nmeaBuffer = " " ; // Reset buffer for next sentence
580
575
}
581
- // Reset buffer for next sentence
582
- nmeaBuffer = " " ;
583
576
}
584
577
}
585
- // Done
586
- WS_DEBUG_PRINTLN (" [gps] u-blox GPS polling completed!" );
587
578
} else {
588
579
WS_DEBUG_PRINTLN (" [gps] ERROR: Unsupported GPS driver type for polling!" );
589
580
}
@@ -595,37 +586,23 @@ void GPSHardware::PollStoreSentences() {
595
586
* @return 0 on success, -1 if the buffer is full.
596
587
*/
597
588
int 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)
601
590
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 );
611
591
612
592
int next = _nmea_buff.head + 1 ; // points to head after the current write
613
593
if (next >= _nmea_buff.maxlen )
614
594
next = 0 ; // wrap around
615
595
616
- // If buffer is full, advance tail to overwrite oldest data
596
+ // If buffer is full, overwrite oldest data
617
597
if (next == _nmea_buff.tail ) {
618
598
_nmea_buff.tail = (_nmea_buff.tail + 1 ) % _nmea_buff.maxlen ;
619
599
}
620
600
621
- WS_DEBUG_PRINTLN (" [gps] About to call strncpy..." );
622
601
// Copy the new sentence into the buffer
623
602
strncpy (_nmea_buff.sentences [_nmea_buff.head ], new_sentence,
624
603
MAX_LEN_NMEA_SENTENCE - 1 );
625
- WS_DEBUG_PRINTLN (" [gps] strncpy completed, setting null terminator..." );
626
604
_nmea_buff.sentences [_nmea_buff.head ][MAX_LEN_NMEA_SENTENCE - 1 ] = ' \0 ' ;
627
605
_nmea_buff.head = next;
628
- WS_DEBUG_PRINTLN (" [gps] NmeaBufPush completed successfully" );
629
606
return 0 ;
630
607
}
631
608
@@ -659,8 +636,6 @@ int GPSHardware::NmeaBufPop(char *sentence) {
659
636
bool GPSHardware::ParseNMEASentence (char *sentence) {
660
637
if (!sentence)
661
638
return false ;
662
- WS_DEBUG_PRINT (" [gps] ParseNMEASentence: " );
663
- WS_DEBUG_PRINTLN (sentence);
664
639
return _ada_gps->parse (sentence);
665
640
}
666
641
0 commit comments