@@ -44,6 +44,7 @@ GPSHardware::~GPSHardware() {
44
44
* @brief Helper function that reads and discards data requested by the I2C bus.
45
45
*/
46
46
void GPSHardware::I2cReadDiscard () {
47
+ // TODO: Let's hope this works for UBX too! Remove if its ok
47
48
_wire->flush ();
48
49
uint8_t bytes_requested = 32 ;
49
50
_wire->requestFrom (_addr, bytes_requested);
@@ -104,8 +105,37 @@ bool GPSHardware::Handle_GPSConfig(wippersnapper_gps_GPSConfig *gps_config) {
104
105
} else if (_driver_type == GPS_DRV_UBLOX) {
105
106
WS_DEBUG_PRINTLN (" [gps] Handling GPSConfig for U-Blox driver..." );
106
107
// Iterate through the command sentences and send them to the GPS module
107
- for (size_t i = 0 ; i < gps_config->commands_ubxes ; i++) {
108
- // TODO
108
+ for (size_t i = 0 ; i < gps_config->commands_ubxes_count ; i++) {
109
+ // TODO - We are just printing here to debug
110
+ WS_DEBUG_PRINT (" [gps] UBX CMD #: " );
111
+ WS_DEBUG_PRINTLN (i);
112
+ WS_DEBUG_PRINT (" [gps] UBX CMDSZ: " );
113
+ WS_DEBUG_PRINTLN (gps_config->commands_ubxes [i].size );
114
+ WS_DEBUG_PRINT (" [gps] UBX CMD (HEX, spaced out): " );
115
+ for (pb_size_t i = 0 ; i < gps_config->commands_ubxes [i].size ; i++) {
116
+ WS_DEBUG_PRINT (gps_config->commands_ubxes [i].bytes [i], HEX);
117
+ WS_DEBUG_PRINT (" " );
118
+ }
119
+ // TODO: Push these to the module and ACK
120
+ WS_DEBUG_PRINT (" [gps] Flushing I2C buffers befor send..." );
121
+ I2cReadDiscard ();
122
+ WS_DEBUG_PRINTLN (" done!" );
123
+ // Write this to the GPS module
124
+ WS_DEBUG_PRINT (" [gps] TX'ing" );
125
+ _sfe_gps->pushRawData (
126
+ gps_config->commands_ubxes [i].bytes ,
127
+ gps_config->commands_ubxes [i].size );
128
+ WS_DEBUG_PRINTLN (" done!" );
129
+ // Wait for the ACK response from the GPS module
130
+ WS_DEBUG_PRINT (" [gps] Waiting for ACK response..." );
131
+ ulong start_time = millis ();
132
+ while (millis () - start_time < 1000 ) {
133
+ _sfe_gps->checkUblox (); // See if new data is available. Process bytes as they come in.
134
+ if (_sfe_gps->processedAck ()) {
135
+ WS_DEBUG_PRINTLN (" done!" );
136
+ break ; // Exit the loop if ACK is received
137
+ }
138
+
109
139
}
110
140
} else {
111
141
WS_DEBUG_PRINTLN (" [gps] ERROR: Unsupported GPS driver type!" );
@@ -198,6 +228,11 @@ bool GPSHardware::DetectUbxI2C(uint32_t addr) {
198
228
_sfe_gps = new SFE_UBLOX_GNSS ();
199
229
if (!_sfe_gps->begin (*_wire, _addr))
200
230
return false ;
231
+ // Configure the u-blox GPS module
232
+ _sfe_gps->setI2COutput (COM_TYPE_UBX | COM_TYPE_NMEA); // Set the I2C port to output both NMEA and UBX messages
233
+ _sfe_gps->saveConfigSelective (VAL_CFG_SUBSEC_IOPORT); // Save (only) the communications port settings to flash and BBR
234
+ _sfe_gps->setProcessNMEAMask (SFE_UBLOX_FILTER_NMEA_ALL); // Make sure the library is passing all NMEA messages to processNMEA
235
+ _sfe_gps->setProcessNMEAMask (SFE_UBLOX_FILTER_NMEA_GGA); // Or, we can be kind to MicroNMEA and _only_ pass the GGA messages to it
201
236
_driver_type = GPS_DRV_UBLOX;
202
237
return true ;
203
238
}
0 commit comments