Skip to content

Commit

Permalink
Merge pull request #68 from sparkfun/release_candidate
Browse files Browse the repository at this point in the history
v3.1.8 - Adds "auto" support for UBX-MON-COMMS
  • Loading branch information
PaulZC authored Nov 6, 2024
2 parents bb33fa9 + d28022a commit 60a183f
Show file tree
Hide file tree
Showing 8 changed files with 543 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ uint8_t uartI2cRingBuffer[ringBufferSize];
uint16_t uartI2cBufferHead = 0;
uint16_t uartI2cBufferTail = 0;

const unsigned long uartI2cSendInterval_ms = 50;
const unsigned long uartI2cSendInterval_ms = 5;
unsigned long uartI2cLastSend_ms = 0;
const uint16_t uartI2cSendLimit = 16;

const unsigned long i2cUartSendInterval_ms = 50;
const unsigned long i2cUartSendInterval_ms = 5;
unsigned long i2cUartLastSend_ms = 0;
const uint16_t i2cUartSendLimit = 16;

Expand All @@ -66,12 +66,19 @@ const uint16_t i2cReadLimit = 16;
void setup()
{

delay(1000); // Wait for ESP32 to start up
delay(2000); // Wait for ESP32 and GNSS to start up

mySerial.begin(115200); // Baud rate for u-center

myWire.begin(); // Start I2C
myWire.setClock(400000); // 400kHz

// Give I2C a kickstart - if needed. Request UBX-MON-VER
const uint8_t pollUbxMonVer[] = { 0xB5, 0x62, 0x0A, 0x04, 0x00, 0x00, 0x0E, 0x34 };
for (int i = 0; i < (sizeof(pollUbxMonVer) / sizeof(uint8_t)); i++) {
addToUartI2cBuffer(pollUbxMonVer[i]);
}

} // /setup

void loop()
Expand Down Expand Up @@ -147,6 +154,7 @@ void loop()
i2cUartLastSend_ms = millis();
}
}

} // /loop

// Read how many bytes are available in the GNSS I2C buffer.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/*
Configuring the GNSS to automatically send MON COMMS reports over I2C and display them using a callback
By: Paul Clark
SparkFun Electronics
Date: Novenber 4th, 2024
License: MIT. See license file for more information.
This example shows how to configure the u-blox GNSS to send MON COMMS reports automatically
and access the data via a callback. No more polling!
Feel like supporting open source hardware?
Buy a board from SparkFun!
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
Hardware Connections:
Plug a Qwiic cable into the GPS and a BlackBoard
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
Open the serial monitor at 115200 baud to see the output
*/

#include <Wire.h> //Needed for I2C to GPS

#include <SparkFun_u-blox_GNSS_v3.h> //http://librarymanager/All#SparkFun_u-blox_GNSS_v3
SFE_UBLOX_GNSS myGNSS;

// Callback: newMONCOMMS will be called when new MON COMMS data arrives
// See u-blox_structs.h for the full definition of UBX_MON_COMMS_data_t
// _____ You can use any name you like for the callback. Use the same name when you call setAutoMONCOMMScallback
// / _____ This _must_ be UBX_MON_COMMS_data_t
// | / _____ You can use any name you like for the struct
// | | /
// | | |
void newMONCOMMS(UBX_MON_COMMS_data_t *ubxDataStruct)
{
Serial.println();

Serial.print(F("New MON COMMS data received. It contains data for "));
Serial.print(ubxDataStruct->header.nPorts);
if (ubxDataStruct->header.nPorts == 1)
Serial.println(F(" port."));
else
Serial.println(F(" ports."));

// Mimic the data shown in u-center
for (uint8_t port = 0; port < ubxDataStruct->header.nPorts; port++) // For each port
{
bool known = true;
switch (ubxDataStruct->port[port].portId) // Check the port ID is valid
{
case COM_PORT_ID_I2C:
case COM_PORT_ID_UART1:
case COM_PORT_ID_UART2:
case COM_PORT_ID_USB:
case COM_PORT_ID_SPI:
break;
default:
known = false;
break;
}
if (!known)
break; // Skip if port ID is not known

switch (ubxDataStruct->port[port].portId) // Print the port ID
{
case COM_PORT_ID_I2C:
Serial.print(F("I2C "));
break;
case COM_PORT_ID_UART1:
Serial.print(F("UART1 "));
break;
case COM_PORT_ID_UART2:
Serial.print(F("UART2 "));
break;
case COM_PORT_ID_USB:
Serial.print(F("USB "));
break;
case COM_PORT_ID_SPI:
Serial.print(F("SPI "));
break;
default:
Serial.print(F("UNKNOWN "));
//Serial.printf("0x%04X ", ubxDataStruct->port[port].portId);
break;
}

Serial.print(": txBytes ");
String txBytes = String(ubxDataStruct->port[port].txBytes);
Serial.print(txBytes);
for (int i = 0; i < 10 - txBytes.length(); i++)
Serial.print(" ");

Serial.print(" : rxBytes ");
String rxBytes = String(ubxDataStruct->port[port].rxBytes);
Serial.print(rxBytes);
for (int i = 0; i < 10 - rxBytes.length(); i++)
Serial.print(" ");

for (int i = 0; i < 4; i++)
{
if (ubxDataStruct->header.protIds[i] < 0xFF)
{
switch (ubxDataStruct->header.protIds[i])
{
case 0:
Serial.print(F(" : UBX "));
break;
case 1:
Serial.print(F(" : NMEA "));
break;
case 2:
Serial.print(F(" : RTCM2 "));
break;
case 5:
Serial.print(F(" : RTCM3 "));
break;
case 6:
Serial.print(F(" : SPARTN "));
break;
default:
Serial.print(F(" : UNKNOWN "));
break;
}
String msgs = String(ubxDataStruct->port[port].msgs[i]);
Serial.print(msgs);
for (int i = 0; i < 5 - msgs.length(); i++)
Serial.print(" ");
}
}

Serial.print(" : skipped ");
Serial.print(ubxDataStruct->port[port].skipped);

Serial.println();
}
}

void setup()
{
Serial.begin(115200);
while (!Serial); //Wait for user to open terminal
Serial.println("SparkFun u-blox Example");

Wire.begin();

//myGNSS.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
//myGNSS.enableDebugging(Serial, true); // Uncomment this line to enable only the major debug messages on Serial

if (myGNSS.begin() == false) //Connect to the u-blox module using Wire port
{
Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing."));
while (1);
}

myGNSS.setI2COutput(COM_TYPE_NMEA | COM_TYPE_UBX); //Set the I2C port to output NMEA and UBX
myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR

myGNSS.setNavigationFrequency(1); //Produce one solution per second

// Just to prove we can, poll the MON COMMS data manually
Serial.println("Polling MON COMMS data:");
UBX_MON_COMMS_data_t portInfo;
if (myGNSS.getCommsPortInfo(&portInfo))
newMONCOMMS(&portInfo); // Call the callback manually to print the data
else
Serial.println("getCommsPortInfo failed!");

// Now enable automatic (periodic) MON COMMS messages with callback to newMONCOMMS
myGNSS.setAutoMONCOMMScallbackPtr(&newMONCOMMS);
}

void loop()
{
myGNSS.checkUblox(); // Check for the arrival of new data and process it.
myGNSS.checkCallbacks(); // Check if any callbacks are waiting to be processed.

Serial.print(".");
delay(50);
}
9 changes: 9 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ setESFAutoAlignment KEYWORD2

getRFinformation KEYWORD2

getCommsPortInfo KEYWORD2
getHWstatus KEYWORD2
getAntennaStatus KEYWORD2
getHW2status KEYWORD2
Expand Down Expand Up @@ -538,6 +539,14 @@ assumeAutoMONHW KEYWORD2
flushMONHW KEYWORD2
logMONHW KEYWORD2

getMONCOMMS KEYWORD2
setAutoMONCOMMS KEYWORD2
setAutoMONCOMMSrate KEYWORD2
setAutoMONCOMMScallbackPtr KEYWORD2
assumeAutoMONCOMMS KEYWORD2
flushMONCOMMS KEYWORD2
logMONCOMMS KEYWORD2

getEsfAlignment KEYWORD2
getESFALG KEYWORD2
setAutoESFALG KEYWORD2
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SparkFun u-blox GNSS v3
version=3.1.7
version=3.1.8
author=SparkFun Electronics <[email protected]>
maintainer=SparkFun Electronics <sparkfun.com>
sentence=Library for I2C, Serial and SPI Communication with u-blox GNSS modules<br/><br/>
Expand Down
8 changes: 8 additions & 0 deletions src/u-blox_Class_and_ID.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,14 @@ const uint8_t COM_PORT_UART2 = 2;
const uint8_t COM_PORT_USB = 3;
const uint8_t COM_PORT_SPI = 4;

// Port IDs used by MON-COMMS
// UBX-18010802 - R15 also documents 0x0101 and 0x0200 - both are "Reserved"
const uint16_t COM_PORT_ID_I2C = 0x0000; // Port IDs used by MON-COMMS
const uint16_t COM_PORT_ID_UART1 = 0x0100;
const uint16_t COM_PORT_ID_UART2 = 0x0201;
const uint16_t COM_PORT_ID_USB = 0x0300;
const uint16_t COM_PORT_ID_SPI = 0x0400;

const uint8_t COM_TYPE_UBX = (1 << 0);
const uint8_t COM_TYPE_NMEA = (1 << 1);
const uint8_t COM_TYPE_RTCM3 = (1 << 5);
Expand Down
Loading

0 comments on commit 60a183f

Please sign in to comment.