Compare commits
10 commits
5eb550766a
...
6b90085793
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b90085793 | ||
|
|
57c7b6cb03 | ||
|
|
8081d05d6f | ||
|
|
2ffb9de69b | ||
|
|
0ca6e789eb | ||
|
|
c885a346fc | ||
|
|
431d1a98b7 | ||
|
|
e369e88efe | ||
|
|
739f2be25a | ||
|
|
569ff1495e |
9 changed files with 250 additions and 47 deletions
4
.github/workflows/githubci.yml
vendored
4
.github/workflows/githubci.yml
vendored
|
|
@ -25,8 +25,8 @@ jobs:
|
|||
- name: Check for correct documentation with doxygen
|
||||
env:
|
||||
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
|
||||
PRETTYNAME : "Adafruit Bus Ublox Library"
|
||||
PRETTYNAME : "Adafruit uBlox Library"
|
||||
run: bash ci/doxy_gen_and_deploy.sh
|
||||
|
||||
- name: Test the code on supported platforms
|
||||
run: python3 ci/build_platform.py main_platforms zero feather32u4
|
||||
run: python3 ci/build_platform.py main_platforms
|
||||
|
|
@ -33,6 +33,14 @@ Adafruit_UBX::Adafruit_UBX(Stream &stream) {
|
|||
onUBXMessage = NULL;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Destructor
|
||||
*/
|
||||
Adafruit_UBX::~Adafruit_UBX() {
|
||||
if (onUBXMessage)
|
||||
onUBXMessage = NULL;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Initializes the UBX parser
|
||||
* @return Always returns true (initialization is trivial)
|
||||
|
|
@ -318,7 +326,7 @@ bool Adafruit_UBX::checkMessages() {
|
|||
UBXSendStatus Adafruit_UBX::sendMessageWithAck(uint8_t msgClass, uint8_t msgId,
|
||||
uint8_t *payload,
|
||||
uint16_t length,
|
||||
uint16_t timeout_ms = 500) {
|
||||
uint16_t timeout_ms) {
|
||||
// First send the message
|
||||
if (!sendMessage(msgClass, msgId, payload, length)) {
|
||||
if (verbose_debug > 0) {
|
||||
|
|
|
|||
|
|
@ -17,19 +17,26 @@
|
|||
#ifndef ADAFRUIT_UBX_H
|
||||
#define ADAFRUIT_UBX_H
|
||||
|
||||
#include "Adafruit_uBlox_Ubx_Messages.h"
|
||||
#include "Adafruit_uBlox_typedef.h"
|
||||
#include <Arduino.h>
|
||||
#include <Stream.h>
|
||||
|
||||
// UBX protocol constants
|
||||
#define UBX_SYNC_CHAR_1 0xB5 // First UBX protocol sync char (<28>)
|
||||
#define UBX_SYNC_CHAR_2 0x62 // Second UBX protocol sync char (b)
|
||||
#define UBX_SYNC_CHAR_1 0xB5 ///< First UBX protocol sync char (<28>)
|
||||
#define UBX_SYNC_CHAR_2 0x62 ///< Second UBX protocol sync char (b)
|
||||
// UBX ACK Message IDs
|
||||
#define UBX_ACK_NAK 0x00 // Message Not Acknowledged
|
||||
#define UBX_ACK_ACK 0x01 // Message Acknowledged
|
||||
#define UBX_ACK_NAK 0x00 ///< Message Not Acknowledged
|
||||
#define UBX_ACK_ACK 0x01 ///< Message Acknowledged
|
||||
|
||||
// Callback function type for UBX messages - defined at global scope so other
|
||||
// classes can use it
|
||||
/*!
|
||||
* @brief Callback function type for UBX messages - defined at global scope so
|
||||
* other classes can use it
|
||||
* @param msgClass Message class
|
||||
* @param msgId Message ID
|
||||
* @param payloadLen Length of payload data
|
||||
* @param payload Pointer to payload data
|
||||
*/
|
||||
typedef void (*UBXMessageCallback)(uint8_t msgClass, uint8_t msgId,
|
||||
uint16_t payloadLen, uint8_t *payload);
|
||||
|
||||
|
|
@ -38,13 +45,11 @@ typedef void (*UBXMessageCallback)(uint8_t msgClass, uint8_t msgId,
|
|||
*/
|
||||
class Adafruit_UBX {
|
||||
public:
|
||||
// Constructor
|
||||
Adafruit_UBX(Stream &stream);
|
||||
uint8_t verbose_debug = 0; // 0=off, 1=basic, 2=verbose
|
||||
|
||||
~Adafruit_UBX();
|
||||
uint8_t verbose_debug = 0; ///< 0=off, 1=basic, 2=verbose
|
||||
// Basic methods
|
||||
bool begin();
|
||||
|
||||
bool checkMessages(); // Message parsing
|
||||
bool sendMessage(uint8_t msgClass, uint8_t msgId, uint8_t *payload,
|
||||
uint16_t length); // Send a UBX message
|
||||
|
|
@ -57,7 +62,7 @@ public:
|
|||
uint16_t timeout_ms = 500);
|
||||
|
||||
void setMessageCallback(UBXMessageCallback callback); // Set callback function
|
||||
UBXMessageCallback onUBXMessage; // Callback for message received
|
||||
UBXMessageCallback onUBXMessage; ///< Callback for message received
|
||||
|
||||
private:
|
||||
Stream *_stream; // Stream interface for reading data
|
||||
|
|
|
|||
|
|
@ -1,25 +1,23 @@
|
|||
/*!
|
||||
* @file Adafruit_UBloxDDC.cpp
|
||||
*
|
||||
* @mainpage Arduino library for u-blox GPS/RTK modules over DDC (I2C)
|
||||
*
|
||||
* @section intro_sec Introduction
|
||||
* @section ddc_intro_sec Introduction
|
||||
*
|
||||
* This is a library for the u-blox GPS/RTK modules using I2C interface (DDC)
|
||||
*
|
||||
* Designed specifically to work with u-blox GPS/RTK modules
|
||||
* like NEO-M8P, ZED-F9P, etc.
|
||||
*
|
||||
* @section dependencies Dependencies
|
||||
* @section ddc_dependencies Dependencies
|
||||
*
|
||||
* This library depends on:
|
||||
* <a href="https://github.com/adafruit/Adafruit_BusIO">Adafruit_BusIO</a>
|
||||
*
|
||||
* @section author Author
|
||||
* @section ddc_author Author
|
||||
*
|
||||
* Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
*
|
||||
* @section license License
|
||||
* @section ddc_license License
|
||||
*
|
||||
* MIT license, all text above must be included in any redistribution
|
||||
*/
|
||||
|
|
@ -181,7 +179,7 @@ uint16_t Adafruit_UBloxDDC::readBytes(uint8_t *buffer, uint16_t length) {
|
|||
|
||||
while (bytesRead < length) {
|
||||
// Calculate chunk size (I2C has a limit on bytes per transfer)
|
||||
uint16_t chunkSize = min(length - bytesRead, (uint16_t)32);
|
||||
uint16_t chunkSize = min((uint16_t)(length - bytesRead), (uint16_t)32);
|
||||
|
||||
if (!dataStreamReg.read(&buffer[bytesRead], chunkSize)) {
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include <Arduino.h>
|
||||
|
||||
// UBX Message Classes
|
||||
/** UBX protocol message class identifiers. */
|
||||
typedef enum {
|
||||
UBX_CLASS_NAV = 0x01, // Navigation Results
|
||||
UBX_CLASS_RXM = 0x02, // Receiver Manager Messages
|
||||
|
|
@ -36,7 +36,7 @@ typedef enum {
|
|||
UBX_CLASS_NMEA = 0xF0 // NMEA Standard Messages
|
||||
} UBXMessageClass;
|
||||
|
||||
// UBX CFG Message IDs
|
||||
/** UBX CFG Message IDs. */
|
||||
typedef enum {
|
||||
UBX_CFG_PRT = 0x00, // Port Configuration
|
||||
UBX_CFG_MSG = 0x01, // Message Configuration
|
||||
|
|
@ -48,7 +48,7 @@ typedef enum {
|
|||
UBX_CFG_PMS = 0x86 // Power Mode Setup
|
||||
} UBXCfgMessageId;
|
||||
|
||||
// Return values for functions that wait for acknowledgment
|
||||
/** Return values for functions that wait for acknowledgment. */
|
||||
typedef enum {
|
||||
UBX_SEND_SUCCESS = 0, // Message was acknowledged (ACK)
|
||||
UBX_SEND_NAK, // Message was not acknowledged (NAK)
|
||||
|
|
@ -56,7 +56,7 @@ typedef enum {
|
|||
UBX_SEND_TIMEOUT // Timed out waiting for ACK/NAK
|
||||
} UBXSendStatus;
|
||||
|
||||
// Port ID enum for different interfaces
|
||||
/** Port ID enum for different interfaces. */
|
||||
typedef enum {
|
||||
UBX_PORT_DDC = 0, // I2C / DDC port
|
||||
UBX_PORT_UART1 = 1, // UART1 port
|
||||
|
|
@ -65,7 +65,7 @@ typedef enum {
|
|||
UBX_PORT_SPI = 4 // SPI port
|
||||
} UBXPortId;
|
||||
|
||||
// UART mode flags (Charlen, Parity & Stop bit settings)
|
||||
/** UART mode flags (Charlen, Parity & Stop bit settings). */
|
||||
typedef enum {
|
||||
UBX_UART_MODE_8N1 = 0x000, // 8-bit, no parity, 1 stop bit
|
||||
UBX_UART_MODE_8E1 = 0x100, // 8-bit, even parity, 1 stop bit
|
||||
|
|
@ -82,27 +82,27 @@ typedef enum {
|
|||
} UBXUARTMode;
|
||||
|
||||
// Protocol flags for inProtoMask and outProtoMask
|
||||
#define UBX_PROTOCOL_UBX 0x0001 // UBX protocol
|
||||
#define UBX_PROTOCOL_NMEA 0x0002 // NMEA protocol
|
||||
#define UBX_PROTOCOL_RTCM 0x0004 // RTCM2 protocol (only for inProtoMask)
|
||||
#define UBX_PROTOCOL_RTCM3 0x0020 // RTCM3 protocol
|
||||
#define UBX_PROTOCOL_UBX 0x0001 ///< UBX protocol
|
||||
#define UBX_PROTOCOL_NMEA 0x0002 ///< NMEA protocol
|
||||
#define UBX_PROTOCOL_RTCM 0x0004 ///< RTCM2 protocol (only for inProtoMask)
|
||||
#define UBX_PROTOCOL_RTCM3 0x0020 ///< RTCM3 protocol
|
||||
|
||||
// CFG-PRT (Port Configuration) Message
|
||||
// Total size: 20 bytes
|
||||
/** UBX CFG-PRT (Port Configuration) message structure. 20 bytes total.
|
||||
*/
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t
|
||||
portID; // Port identifier (0=DDC/I2C, 1=UART1, 2=UART2, 3=USB, 4=SPI)
|
||||
uint8_t reserved1; // Reserved
|
||||
uint16_t txReady; // TX ready PIN configuration
|
||||
uint32_t mode; // UART mode (bit field) or Reserved for non-UART ports
|
||||
uint32_t baudRate; // Baudrate in bits/second (UART only)
|
||||
uint16_t inProtoMask; // Input protocol mask
|
||||
uint16_t outProtoMask; // Output protocol mask
|
||||
uint16_t flags; // Flags bit field
|
||||
uint16_t reserved2; // Reserved
|
||||
} fields;
|
||||
uint8_t raw[20];
|
||||
portID; ///< Port identifier (0=DDC/I2C, 1=UART1, 2=UART2, 3=USB, 4=SPI)
|
||||
uint8_t reserved1; ///< Reserved
|
||||
uint16_t txReady; ///< TX ready PIN configuration
|
||||
uint32_t mode; ///< UART mode (bit field) or Reserved for non-UART ports
|
||||
uint32_t baudRate; ///< Baudrate in bits/second (UART only)
|
||||
uint16_t inProtoMask; ///< Input protocol mask
|
||||
uint16_t outProtoMask; ///< Output protocol mask
|
||||
uint16_t flags; ///< Flags bit field
|
||||
uint16_t reserved2; ///< Reserved
|
||||
} fields; ///< Fields for CFG-PRT message
|
||||
uint8_t raw[20]; ///< Raw byte array for CFG-PRT message
|
||||
} UBX_CFG_PRT_t;
|
||||
|
||||
#endif // ADAFRUIT_UBLOX_TYPEDEF_H
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*!
|
||||
* @file ublox_ddc_example.ino
|
||||
* @file ublox_ddc.ino
|
||||
*
|
||||
* Example sketch demonstrating the use of the Adafruit_UBloxDDC library
|
||||
* with u-blox GPS/RTK modules over I2C (DDC) interface.
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
* MIT license, all text above must be included in any redistribution
|
||||
*/
|
||||
|
||||
#include "Adafruit_UBloxDDC.h"
|
||||
#include <Adafruit_UBloxDDC.h>
|
||||
|
||||
// Create Adafruit_UBloxDDC object with default I2C address (0x42)
|
||||
Adafruit_UBloxDDC gps;
|
||||
192
examples/ublox_ddc_parse_nmea/ublox_ddc_parse_nmea.ino
Normal file
192
examples/ublox_ddc_parse_nmea/ublox_ddc_parse_nmea.ino
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
/*!
|
||||
* @file ublox_ddc_parse_nmea.ino
|
||||
*
|
||||
* Example sketch demonstrating parsing NMEA sentences from a u-blox GPS/RTK module
|
||||
* using the Adafruit_GPS and Adafruit_UBX libraries.
|
||||
*
|
||||
* Written by Brent Rubell for Adafruit Industries.
|
||||
*
|
||||
* MIT license, all text above must be included in any redistribution
|
||||
*/
|
||||
|
||||
#include <Adafruit_GPS.h>
|
||||
#include <Adafruit_UBX.h>
|
||||
#include <Adafruit_UBloxDDC.h>
|
||||
|
||||
// Adafruit_UBloxDDC object with default I2C address (0x42)
|
||||
Adafruit_UBloxDDC gps;
|
||||
// Create Adafruit_UBX parser using the DDC object as input stream
|
||||
Adafruit_UBX ubx(gps);
|
||||
// Create Adafruit_GPS object for use as a NMEA parser only
|
||||
Adafruit_GPS NMEA;
|
||||
|
||||
// Buffer to store NMEA sentences from the module (may be partial sentences)
|
||||
const size_t SZ_NMEA_BUFFER = 128;
|
||||
uint8_t buffer[SZ_NMEA_BUFFER];
|
||||
uint32_t timer = millis();
|
||||
|
||||
/*!
|
||||
* @brief Sets the NMEA output to only RMC and GGA sentences and waits for an
|
||||
* acknowledgment. All other common NMEA sentences are disabled to increase
|
||||
* loop() performance by decreasing the amount of messages output by the UBlox
|
||||
* module.
|
||||
* @return Status indicating success, failure, or timeout
|
||||
*/
|
||||
UBXSendStatus SetNMEAOutputRMCGGAOnly() {
|
||||
UBXSendStatus status;
|
||||
// Disable all common NMEA messages
|
||||
status = ubx.sendMessageWithAck(UBX_CLASS_CFG, UBX_CFG_MSG,
|
||||
UBX_CFG_MSG_NMEA_GLL_DISABLE,
|
||||
sizeof(UBX_CFG_MSG_NMEA_GLL_DISABLE));
|
||||
if (status != UBX_SEND_SUCCESS)
|
||||
return status;
|
||||
status = ubx.sendMessageWithAck(UBX_CLASS_CFG, UBX_CFG_MSG,
|
||||
UBX_CFG_MSG_NMEA_GSA_DISABLE,
|
||||
sizeof(UBX_CFG_MSG_NMEA_GSA_DISABLE));
|
||||
if (status != UBX_SEND_SUCCESS)
|
||||
return status;
|
||||
status = ubx.sendMessageWithAck(UBX_CLASS_CFG, UBX_CFG_MSG,
|
||||
UBX_CFG_MSG_NMEA_GSV_DISABLE,
|
||||
sizeof(UBX_CFG_MSG_NMEA_GSV_DISABLE));
|
||||
if (status != UBX_SEND_SUCCESS)
|
||||
return status;
|
||||
status = ubx.sendMessageWithAck(UBX_CLASS_CFG, UBX_CFG_MSG,
|
||||
UBX_CFG_MSG_NMEA_VTG_DISABLE,
|
||||
sizeof(UBX_CFG_MSG_NMEA_VTG_DISABLE));
|
||||
if (status != UBX_SEND_SUCCESS)
|
||||
return status;
|
||||
// Enable only GGA and RMC messages
|
||||
status = ubx.sendMessageWithAck(UBX_CLASS_CFG, UBX_CFG_MSG,
|
||||
UBX_CFG_MSG_NMEA_GGA_ENABLE,
|
||||
sizeof(UBX_CFG_MSG_NMEA_GGA_ENABLE));
|
||||
if (status != UBX_SEND_SUCCESS)
|
||||
return status;
|
||||
status = ubx.sendMessageWithAck(UBX_CLASS_CFG, UBX_CFG_MSG,
|
||||
UBX_CFG_MSG_NMEA_RMC_ENABLE,
|
||||
sizeof(UBX_CFG_MSG_NMEA_RMC_ENABLE));
|
||||
return status;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// Initialize serial port for debugging
|
||||
Serial.begin(115200);
|
||||
while (!Serial) {
|
||||
; // Wait for serial port to connect
|
||||
}
|
||||
|
||||
// Initialize GPS module
|
||||
if (!gps.begin()) {
|
||||
Serial.println("Failed to initialize GPS module!");
|
||||
while (1); // Halt if initialization fails
|
||||
}
|
||||
Serial.println("GPS module initialized successfully!");
|
||||
|
||||
// Initialize the u-blox parser
|
||||
if (!ubx.begin()) {
|
||||
Serial.println("Failed to initialize u-blox parser!");
|
||||
while (1); // Halt if initialization fails
|
||||
}
|
||||
Serial.println("u-blox parser initialized successfully!");
|
||||
ubx.verbose_debug = 3; // Set debug level to verbose
|
||||
|
||||
// Set NMEA output on DDC to RMC and GGA sentences only
|
||||
UBXSendStatus status = SetNMEAOutputRMCGGAOnly();
|
||||
if (status != UBX_SEND_SUCCESS) {
|
||||
Serial.print("Failed to configure NMEA output [status code: ");
|
||||
Serial.print(status);
|
||||
Serial.println("]");
|
||||
while (1); // Halt if setting NMEA output fails
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
static char nmeaSentenceBuf[SZ_NMEA_BUFFER];
|
||||
static size_t nmeaSentenceIdx = 0;
|
||||
|
||||
// Check how many bytes are available
|
||||
int bytesAvailable = gps.available();
|
||||
|
||||
if (bytesAvailable > 0) {
|
||||
// Read up to SZ_NMEA_BUFFER bytes at a time
|
||||
size_t bytesToRead = min(bytesAvailable, (int)SZ_NMEA_BUFFER);
|
||||
size_t bytesRead = gps.readBytes(buffer, bytesToRead);
|
||||
|
||||
// Build NMEA sentences and parse when complete
|
||||
for (size_t i = 0; i < bytesRead; i++) {
|
||||
char c = buffer[i];
|
||||
|
||||
// Add to buffer if space available
|
||||
if (nmeaSentenceIdx < SZ_NMEA_BUFFER - 1) {
|
||||
nmeaSentenceBuf[nmeaSentenceIdx++] = c;
|
||||
}
|
||||
|
||||
// Check for end of NMEA sentence
|
||||
if (c == '\n') {
|
||||
nmeaSentenceBuf[nmeaSentenceIdx] = '\0';
|
||||
|
||||
// Parse the NMEA sentence
|
||||
if (NMEA.parse(nmeaSentenceBuf)) {
|
||||
// Successfully parsed sentence!
|
||||
Serial.println(nmeaSentenceBuf);
|
||||
// approximately every 2 seconds or so, print out the current stats
|
||||
if (millis() - timer > 2000) {
|
||||
timer = millis(); // reset the timer
|
||||
Serial.print("\nTime: ");
|
||||
if (NMEA.hour < 10) {
|
||||
Serial.print('0');
|
||||
}
|
||||
Serial.print(NMEA.hour, DEC);
|
||||
Serial.print(':');
|
||||
if (NMEA.minute < 10) {
|
||||
Serial.print('0');
|
||||
}
|
||||
Serial.print(NMEA.minute, DEC);
|
||||
Serial.print(':');
|
||||
if (NMEA.seconds < 10) {
|
||||
Serial.print('0');
|
||||
}
|
||||
Serial.print(NMEA.seconds, DEC);
|
||||
Serial.print('.');
|
||||
if (NMEA.milliseconds < 10) {
|
||||
Serial.print("00");
|
||||
} else if (NMEA.milliseconds > 9 && NMEA.milliseconds < 100) {
|
||||
Serial.print("0");
|
||||
}
|
||||
Serial.println(NMEA.milliseconds);
|
||||
Serial.print("Date: ");
|
||||
Serial.print(NMEA.day, DEC);
|
||||
Serial.print('/');
|
||||
Serial.print(NMEA.month, DEC);
|
||||
Serial.print("/20");
|
||||
Serial.println(NMEA.year, DEC);
|
||||
Serial.print("Fix: ");
|
||||
Serial.print((int)NMEA.fix);
|
||||
Serial.print(" quality: ");
|
||||
Serial.println((int)NMEA.fixquality);
|
||||
if (NMEA.fix) {
|
||||
Serial.print("Location: ");
|
||||
Serial.print(NMEA.latitude, 4);
|
||||
Serial.print(NMEA.lat);
|
||||
Serial.print(", ");
|
||||
Serial.print(NMEA.longitude, 4);
|
||||
Serial.println(NMEA.lon);
|
||||
Serial.print("Speed (knots): ");
|
||||
Serial.println(NMEA.speed);
|
||||
Serial.print("Angle: ");
|
||||
Serial.println(NMEA.angle);
|
||||
Serial.print("Altitude: ");
|
||||
Serial.println(NMEA.altitude);
|
||||
Serial.print("Satellites: ");
|
||||
Serial.println((int)NMEA.satellites);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Serial.println("Failed to parse sentence.");
|
||||
}
|
||||
nmeaSentenceIdx = 0; // Reset index for next sentence
|
||||
}
|
||||
}
|
||||
}
|
||||
// Short delay to prevent overwhelming the module
|
||||
delay(10);
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*!
|
||||
* @file ubx_mode_test.ino
|
||||
* @file ublox_ubxtest.ino
|
||||
*
|
||||
* Test sketch to verify switching to UBX protocol mode
|
||||
* This example uses I2C (DDC) to communicate with a u-blox module.
|
||||
|
|
@ -7,4 +7,4 @@ paragraph=Library for interfacing with u-blox GPS/RTK modules.
|
|||
category=Communication
|
||||
url=https://github.com/adafruit/Adafruit_uBlox/
|
||||
architectures=*
|
||||
depends=Adafruit BusIO
|
||||
depends=Adafruit BusIO, Adafruit GPS Library
|
||||
Loading…
Reference in a new issue