Skip to content

Commit 783ec2d

Browse files
committed
GPS - Handle Config progress on UBX
1 parent 2330368 commit 783ec2d

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

src/components/gps/hardware.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ GPSHardware::~GPSHardware() {
4444
* @brief Helper function that reads and discards data requested by the I2C bus.
4545
*/
4646
void GPSHardware::I2cReadDiscard() {
47+
// TODO: Let's hope this works for UBX too! Remove if its ok
4748
_wire->flush();
4849
uint8_t bytes_requested = 32;
4950
_wire->requestFrom(_addr, bytes_requested);
@@ -104,8 +105,37 @@ bool GPSHardware::Handle_GPSConfig(wippersnapper_gps_GPSConfig *gps_config) {
104105
} else if (_driver_type == GPS_DRV_UBLOX) {
105106
WS_DEBUG_PRINTLN("[gps] Handling GPSConfig for U-Blox driver...");
106107
// 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+
109139
}
110140
} else {
111141
WS_DEBUG_PRINTLN("[gps] ERROR: Unsupported GPS driver type!");
@@ -198,6 +228,11 @@ bool GPSHardware::DetectUbxI2C(uint32_t addr) {
198228
_sfe_gps = new SFE_UBLOX_GNSS();
199229
if (!_sfe_gps->begin(*_wire, _addr))
200230
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
201236
_driver_type = GPS_DRV_UBLOX;
202237
return true;
203238
}

0 commit comments

Comments
 (0)