Clang
This commit is contained in:
parent
8f6b59b218
commit
5eb550766a
6 changed files with 477 additions and 430 deletions
104
Adafruit_UBX.cpp
104
Adafruit_UBX.cpp
|
|
@ -5,8 +5,9 @@
|
||||||
*
|
*
|
||||||
* @section intro_sec Introduction
|
* @section intro_sec Introduction
|
||||||
*
|
*
|
||||||
* This is a library for parsing UBX protocol messages from u-blox GPS/RTK modules.
|
* This is a library for parsing UBX protocol messages from u-blox GPS/RTK
|
||||||
* It works with any Stream-based interface including UART and DDC (I2C).
|
* modules. It works with any Stream-based interface including UART and DDC
|
||||||
|
* (I2C).
|
||||||
*
|
*
|
||||||
* Designed specifically to work with u-blox GPS/RTK modules
|
* Designed specifically to work with u-blox GPS/RTK modules
|
||||||
* like NEO-M8P, ZED-F9P, etc.
|
* like NEO-M8P, ZED-F9P, etc.
|
||||||
|
|
@ -22,11 +23,10 @@
|
||||||
|
|
||||||
#include "Adafruit_UBX.h"
|
#include "Adafruit_UBX.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Constructor
|
* @brief Constructor
|
||||||
* @param stream Reference to a Stream object (Serial, Adafruit_UBloxDDC, etc.)
|
* @param stream Reference to a Stream object (Serial, Adafruit_UBloxDDC,
|
||||||
|
* etc.)
|
||||||
*/
|
*/
|
||||||
Adafruit_UBX::Adafruit_UBX(Stream &stream) {
|
Adafruit_UBX::Adafruit_UBX(Stream &stream) {
|
||||||
_stream = &stream;
|
_stream = &stream;
|
||||||
|
|
@ -42,9 +42,6 @@ bool Adafruit_UBX::begin() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Configure the GPS module to output only UBX protocol (disables NMEA)
|
* @brief Configure the GPS module to output only UBX protocol (disables NMEA)
|
||||||
* @param portID Port identifier (UBX_PORT_DDC, UBX_PORT_UART1, etc.)
|
* @param portID Port identifier (UBX_PORT_DDC, UBX_PORT_UART1, etc.)
|
||||||
|
|
@ -52,7 +49,8 @@ bool Adafruit_UBX::begin() {
|
||||||
* @param timeout_ms Maximum time to wait for acknowledgment in milliseconds
|
* @param timeout_ms Maximum time to wait for acknowledgment in milliseconds
|
||||||
* @return UBXSendStatus indicating success, failure, or timeout
|
* @return UBXSendStatus indicating success, failure, or timeout
|
||||||
*/
|
*/
|
||||||
UBXSendStatus Adafruit_UBX::setUBXOnly(UBXPortId portID, bool checkAck, uint16_t timeout_ms) {
|
UBXSendStatus Adafruit_UBX::setUBXOnly(UBXPortId portID, bool checkAck,
|
||||||
|
uint16_t timeout_ms) {
|
||||||
UBX_CFG_PRT_t cfgPrt;
|
UBX_CFG_PRT_t cfgPrt;
|
||||||
|
|
||||||
// Zero out the structure
|
// Zero out the structure
|
||||||
|
|
@ -103,7 +101,8 @@ UBXSendStatus Adafruit_UBX::setUBXOnly(UBXPortId portID, bool checkAck, uint16_t
|
||||||
|
|
||||||
// Send the message and wait for acknowledgment if requested
|
// Send the message and wait for acknowledgment if requested
|
||||||
if (checkAck) {
|
if (checkAck) {
|
||||||
return sendMessageWithAck(UBX_CLASS_CFG, UBX_CFG_PRT, cfgPrt.raw, sizeof(cfgPrt), timeout_ms);
|
return sendMessageWithAck(UBX_CLASS_CFG, UBX_CFG_PRT, cfgPrt.raw,
|
||||||
|
sizeof(cfgPrt), timeout_ms);
|
||||||
} else {
|
} else {
|
||||||
if (sendMessage(UBX_CLASS_CFG, UBX_CFG_PRT, cfgPrt.raw, sizeof(cfgPrt))) {
|
if (sendMessage(UBX_CLASS_CFG, UBX_CFG_PRT, cfgPrt.raw, sizeof(cfgPrt))) {
|
||||||
return UBX_SEND_SUCCESS;
|
return UBX_SEND_SUCCESS;
|
||||||
|
|
@ -113,12 +112,10 @@ UBXSendStatus Adafruit_UBX::setUBXOnly(UBXPortId portID, bool checkAck, uint16_t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Sets the callback function for UBX messages
|
* @brief Sets the callback function for UBX messages
|
||||||
* @param callback Function pointer to call when a complete UBX message is received
|
* @param callback Function pointer to call when a complete UBX message is
|
||||||
|
* received
|
||||||
*/
|
*/
|
||||||
void Adafruit_UBX::setMessageCallback(UBXMessageCallback callback) {
|
void Adafruit_UBX::setMessageCallback(UBXMessageCallback callback) {
|
||||||
onUBXMessage = callback;
|
onUBXMessage = callback;
|
||||||
|
|
@ -140,7 +137,8 @@ void Adafruit_UBX::resetParser() {
|
||||||
* @param checksumA Reference to store the first checksum byte
|
* @param checksumA Reference to store the first checksum byte
|
||||||
* @param checksumB Reference to store the second checksum byte
|
* @param checksumB Reference to store the second checksum byte
|
||||||
*/
|
*/
|
||||||
void Adafruit_UBX::calculateChecksum(uint8_t *buffer, uint16_t len, uint8_t &checksumA, uint8_t &checksumB) {
|
void Adafruit_UBX::calculateChecksum(uint8_t *buffer, uint16_t len,
|
||||||
|
uint8_t &checksumA, uint8_t &checksumB) {
|
||||||
checksumA = 0;
|
checksumA = 0;
|
||||||
checksumB = 0;
|
checksumB = 0;
|
||||||
|
|
||||||
|
|
@ -222,7 +220,8 @@ bool Adafruit_UBX::checkMessages() {
|
||||||
|
|
||||||
case GET_CHECKSUM_A:
|
case GET_CHECKSUM_A:
|
||||||
// Calculate expected checksum
|
// Calculate expected checksum
|
||||||
calculateChecksum(_buffer + 2, _payloadLength + 4, _checksumA, _checksumB);
|
calculateChecksum(_buffer + 2, _payloadLength + 4, _checksumA,
|
||||||
|
_checksumB);
|
||||||
|
|
||||||
if (incomingByte == _checksumA) {
|
if (incomingByte == _checksumA) {
|
||||||
_parserState = GET_CHECKSUM_B; // Checksum A matches
|
_parserState = GET_CHECKSUM_B; // Checksum A matches
|
||||||
|
|
@ -235,7 +234,8 @@ bool Adafruit_UBX::checkMessages() {
|
||||||
if (incomingByte == _checksumB) {
|
if (incomingByte == _checksumB) {
|
||||||
// We have a valid message!
|
// We have a valid message!
|
||||||
if (onUBXMessage != NULL) {
|
if (onUBXMessage != NULL) {
|
||||||
onUBXMessage(_msgClass, _msgId, _payloadLength, _buffer + 6); // Call the callback with the message
|
onUBXMessage(_msgClass, _msgId, _payloadLength,
|
||||||
|
_buffer + 6); // Call the callback with the message
|
||||||
}
|
}
|
||||||
messageReceived = true;
|
messageReceived = true;
|
||||||
|
|
||||||
|
|
@ -253,19 +253,23 @@ bool Adafruit_UBX::checkMessages() {
|
||||||
|
|
||||||
// Print header (sync chars, class, id, length)
|
// Print header (sync chars, class, id, length)
|
||||||
Serial.print("HDR[B5 62 ");
|
Serial.print("HDR[B5 62 ");
|
||||||
if (_msgClass < 0x10) Serial.print("0");
|
if (_msgClass < 0x10)
|
||||||
|
Serial.print("0");
|
||||||
Serial.print(_msgClass, HEX);
|
Serial.print(_msgClass, HEX);
|
||||||
Serial.print(" ");
|
Serial.print(" ");
|
||||||
if (_msgId < 0x10) Serial.print("0");
|
if (_msgId < 0x10)
|
||||||
|
Serial.print("0");
|
||||||
Serial.print(_msgId, HEX);
|
Serial.print(_msgId, HEX);
|
||||||
Serial.print(" ");
|
Serial.print(" ");
|
||||||
|
|
||||||
uint8_t lenLSB = _payloadLength & 0xFF;
|
uint8_t lenLSB = _payloadLength & 0xFF;
|
||||||
uint8_t lenMSB = (_payloadLength >> 8) & 0xFF;
|
uint8_t lenMSB = (_payloadLength >> 8) & 0xFF;
|
||||||
if (lenLSB < 0x10) Serial.print("0");
|
if (lenLSB < 0x10)
|
||||||
|
Serial.print("0");
|
||||||
Serial.print(lenLSB, HEX);
|
Serial.print(lenLSB, HEX);
|
||||||
Serial.print(" ");
|
Serial.print(" ");
|
||||||
if (lenMSB < 0x10) Serial.print("0");
|
if (lenMSB < 0x10)
|
||||||
|
Serial.print("0");
|
||||||
Serial.print(lenMSB, HEX);
|
Serial.print(lenMSB, HEX);
|
||||||
Serial.print("] ");
|
Serial.print("] ");
|
||||||
|
|
||||||
|
|
@ -273,7 +277,8 @@ bool Adafruit_UBX::checkMessages() {
|
||||||
if (verbose_debug > 1 && _payloadLength > 0) {
|
if (verbose_debug > 1 && _payloadLength > 0) {
|
||||||
Serial.print("PL[");
|
Serial.print("PL[");
|
||||||
for (uint16_t i = 0; i < _payloadLength; i++) {
|
for (uint16_t i = 0; i < _payloadLength; i++) {
|
||||||
if (_buffer[6 + i] < 0x10) Serial.print("0");
|
if (_buffer[6 + i] < 0x10)
|
||||||
|
Serial.print("0");
|
||||||
Serial.print(_buffer[6 + i], HEX);
|
Serial.print(_buffer[6 + i], HEX);
|
||||||
Serial.print(" ");
|
Serial.print(" ");
|
||||||
}
|
}
|
||||||
|
|
@ -282,10 +287,12 @@ bool Adafruit_UBX::checkMessages() {
|
||||||
|
|
||||||
// Print checksum
|
// Print checksum
|
||||||
Serial.print("CS[");
|
Serial.print("CS[");
|
||||||
if (_checksumA < 0x10) Serial.print("0");
|
if (_checksumA < 0x10)
|
||||||
|
Serial.print("0");
|
||||||
Serial.print(_checksumA, HEX);
|
Serial.print(_checksumA, HEX);
|
||||||
Serial.print(" ");
|
Serial.print(" ");
|
||||||
if (_checksumB < 0x10) Serial.print("0");
|
if (_checksumB < 0x10)
|
||||||
|
Serial.print("0");
|
||||||
Serial.print(_checksumB, HEX);
|
Serial.print(_checksumB, HEX);
|
||||||
Serial.println("]");
|
Serial.println("]");
|
||||||
}
|
}
|
||||||
|
|
@ -299,7 +306,6 @@ bool Adafruit_UBX::checkMessages() {
|
||||||
return messageReceived;
|
return messageReceived;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Send a UBX message and wait for acknowledgment
|
* @brief Send a UBX message and wait for acknowledgment
|
||||||
* @param msgClass Message class
|
* @param msgClass Message class
|
||||||
|
|
@ -309,7 +315,10 @@ bool Adafruit_UBX::checkMessages() {
|
||||||
* @param timeout_ms Maximum time to wait for acknowledgment
|
* @param timeout_ms Maximum time to wait for acknowledgment
|
||||||
* @return UBXSendStatus indicating success, failure, or timeout
|
* @return UBXSendStatus indicating success, failure, or timeout
|
||||||
*/
|
*/
|
||||||
UBXSendStatus Adafruit_UBX::sendMessageWithAck(uint8_t msgClass, uint8_t msgId, uint8_t *payload, uint16_t length, uint16_t timeout_ms = 500) {
|
UBXSendStatus Adafruit_UBX::sendMessageWithAck(uint8_t msgClass, uint8_t msgId,
|
||||||
|
uint8_t *payload,
|
||||||
|
uint16_t length,
|
||||||
|
uint16_t timeout_ms = 500) {
|
||||||
// First send the message
|
// First send the message
|
||||||
if (!sendMessage(msgClass, msgId, payload, length)) {
|
if (!sendMessage(msgClass, msgId, payload, length)) {
|
||||||
if (verbose_debug > 0) {
|
if (verbose_debug > 0) {
|
||||||
|
|
@ -332,10 +341,12 @@ UBXSendStatus Adafruit_UBX::sendMessageWithAck(uint8_t msgClass, uint8_t msgId,
|
||||||
if (_lastPayload[0] == msgClass && _lastPayload[1] == msgId) {
|
if (_lastPayload[0] == msgClass && _lastPayload[1] == msgId) {
|
||||||
if (verbose_debug > 0) {
|
if (verbose_debug > 0) {
|
||||||
Serial.print(F("UBX ACK: SUCCESS for message class 0x"));
|
Serial.print(F("UBX ACK: SUCCESS for message class 0x"));
|
||||||
if (msgClass < 0x10) Serial.print("0");
|
if (msgClass < 0x10)
|
||||||
|
Serial.print("0");
|
||||||
Serial.print(msgClass, HEX);
|
Serial.print(msgClass, HEX);
|
||||||
Serial.print(" ID 0x");
|
Serial.print(" ID 0x");
|
||||||
if (msgId < 0x10) Serial.print("0");
|
if (msgId < 0x10)
|
||||||
|
Serial.print("0");
|
||||||
Serial.println(msgId, HEX);
|
Serial.println(msgId, HEX);
|
||||||
}
|
}
|
||||||
return UBX_SEND_SUCCESS;
|
return UBX_SEND_SUCCESS;
|
||||||
|
|
@ -345,10 +356,12 @@ UBXSendStatus Adafruit_UBX::sendMessageWithAck(uint8_t msgClass, uint8_t msgId,
|
||||||
if (_lastPayload[0] == msgClass && _lastPayload[1] == msgId) {
|
if (_lastPayload[0] == msgClass && _lastPayload[1] == msgId) {
|
||||||
if (verbose_debug > 0) {
|
if (verbose_debug > 0) {
|
||||||
Serial.print(F("UBX ACK: NAK for message class 0x"));
|
Serial.print(F("UBX ACK: NAK for message class 0x"));
|
||||||
if (msgClass < 0x10) Serial.print("0");
|
if (msgClass < 0x10)
|
||||||
|
Serial.print("0");
|
||||||
Serial.print(msgClass, HEX);
|
Serial.print(msgClass, HEX);
|
||||||
Serial.print(" ID 0x");
|
Serial.print(" ID 0x");
|
||||||
if (msgId < 0x10) Serial.print("0");
|
if (msgId < 0x10)
|
||||||
|
Serial.print("0");
|
||||||
Serial.println(msgId, HEX);
|
Serial.println(msgId, HEX);
|
||||||
}
|
}
|
||||||
return UBX_SEND_NAK;
|
return UBX_SEND_NAK;
|
||||||
|
|
@ -362,28 +375,33 @@ UBXSendStatus Adafruit_UBX::sendMessageWithAck(uint8_t msgClass, uint8_t msgId,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose_debug > 0) {
|
if (verbose_debug > 0) {
|
||||||
Serial.print(F("UBX ACK: TIMEOUT waiting for ACK/NAK for message class 0x"));
|
Serial.print(
|
||||||
if (msgClass < 0x10) Serial.print("0");
|
F("UBX ACK: TIMEOUT waiting for ACK/NAK for message class 0x"));
|
||||||
|
if (msgClass < 0x10)
|
||||||
|
Serial.print("0");
|
||||||
Serial.print(msgClass, HEX);
|
Serial.print(msgClass, HEX);
|
||||||
Serial.print(" ID 0x");
|
Serial.print(" ID 0x");
|
||||||
if (msgId < 0x10) Serial.print("0");
|
if (msgId < 0x10)
|
||||||
|
Serial.print("0");
|
||||||
Serial.println(msgId, HEX);
|
Serial.println(msgId, HEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
return UBX_SEND_TIMEOUT;
|
return UBX_SEND_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Send a UBX message to the GPS module
|
* @brief Send a UBX message to the GPS module
|
||||||
* @param msgClass Message class
|
* @param msgClass Message class
|
||||||
* @param msgId Message ID
|
* @param msgId Message ID
|
||||||
* @param payload Pointer to the payload data (can be NULL for zero-length payload)
|
* @param payload Pointer to the payload data (can be NULL for zero-length
|
||||||
|
* payload)
|
||||||
* @param length Length of payload
|
* @param length Length of payload
|
||||||
* @return True if message was sent successfully
|
* @return True if message was sent successfully
|
||||||
*/
|
*/
|
||||||
bool Adafruit_UBX::sendMessage(uint8_t msgClass, uint8_t msgId, uint8_t *payload, uint16_t length) {
|
bool Adafruit_UBX::sendMessage(uint8_t msgClass, uint8_t msgId,
|
||||||
// Buffer for message (2 sync chars + class + id + 2 length bytes + payload + 2 checksum bytes)
|
uint8_t *payload, uint16_t length) {
|
||||||
|
// Buffer for message (2 sync chars + class + id + 2 length bytes + payload +
|
||||||
|
// 2 checksum bytes)
|
||||||
uint8_t msgBuffer[length + 8];
|
uint8_t msgBuffer[length + 8];
|
||||||
|
|
||||||
// Sync characters
|
// Sync characters
|
||||||
|
|
@ -417,7 +435,8 @@ bool Adafruit_UBX::sendMessage(uint8_t msgClass, uint8_t msgId, uint8_t *payload
|
||||||
// Print header (sync chars, class, id, length)
|
// Print header (sync chars, class, id, length)
|
||||||
Serial.print("HDR[");
|
Serial.print("HDR[");
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
if (msgBuffer[i] < 0x10) Serial.print("0");
|
if (msgBuffer[i] < 0x10)
|
||||||
|
Serial.print("0");
|
||||||
Serial.print(msgBuffer[i], HEX);
|
Serial.print(msgBuffer[i], HEX);
|
||||||
Serial.print(" ");
|
Serial.print(" ");
|
||||||
}
|
}
|
||||||
|
|
@ -427,7 +446,8 @@ bool Adafruit_UBX::sendMessage(uint8_t msgClass, uint8_t msgId, uint8_t *payload
|
||||||
if (verbose_debug > 1 && length > 0) {
|
if (verbose_debug > 1 && length > 0) {
|
||||||
Serial.print("PL[");
|
Serial.print("PL[");
|
||||||
for (uint16_t i = 0; i < length; i++) {
|
for (uint16_t i = 0; i < length; i++) {
|
||||||
if (msgBuffer[6 + i] < 0x10) Serial.print("0");
|
if (msgBuffer[6 + i] < 0x10)
|
||||||
|
Serial.print("0");
|
||||||
Serial.print(msgBuffer[6 + i], HEX);
|
Serial.print(msgBuffer[6 + i], HEX);
|
||||||
Serial.print(" ");
|
Serial.print(" ");
|
||||||
}
|
}
|
||||||
|
|
@ -436,10 +456,12 @@ bool Adafruit_UBX::sendMessage(uint8_t msgClass, uint8_t msgId, uint8_t *payload
|
||||||
|
|
||||||
// Print checksum
|
// Print checksum
|
||||||
Serial.print("CS[");
|
Serial.print("CS[");
|
||||||
if (checksumA < 0x10) Serial.print("0");
|
if (checksumA < 0x10)
|
||||||
|
Serial.print("0");
|
||||||
Serial.print(checksumA, HEX);
|
Serial.print(checksumA, HEX);
|
||||||
Serial.print(" ");
|
Serial.print(" ");
|
||||||
if (checksumB < 0x10) Serial.print("0");
|
if (checksumB < 0x10)
|
||||||
|
Serial.print("0");
|
||||||
Serial.print(checksumB, HEX);
|
Serial.print(checksumB, HEX);
|
||||||
Serial.println("]");
|
Serial.println("]");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@
|
||||||
#ifndef ADAFRUIT_UBX_H
|
#ifndef ADAFRUIT_UBX_H
|
||||||
#define ADAFRUIT_UBX_H
|
#define ADAFRUIT_UBX_H
|
||||||
|
|
||||||
|
#include "Adafruit_uBlox_typedef.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <Stream.h>
|
#include <Stream.h>
|
||||||
#include "Adafruit_uBlox_typedef.h"
|
|
||||||
|
|
||||||
// UBX protocol constants
|
// UBX protocol constants
|
||||||
#define UBX_SYNC_CHAR_1 0xB5 // First UBX protocol sync char (<28>)
|
#define UBX_SYNC_CHAR_1 0xB5 // First UBX protocol sync char (<28>)
|
||||||
|
|
@ -28,9 +28,10 @@
|
||||||
#define UBX_ACK_NAK 0x00 // Message Not Acknowledged
|
#define UBX_ACK_NAK 0x00 // Message Not Acknowledged
|
||||||
#define UBX_ACK_ACK 0x01 // Message Acknowledged
|
#define UBX_ACK_ACK 0x01 // Message Acknowledged
|
||||||
|
|
||||||
// Callback function type for UBX messages - defined at global scope so other classes can use it
|
// Callback function type for UBX messages - defined at global scope so other
|
||||||
typedef void (*UBXMessageCallback)(uint8_t msgClass, uint8_t msgId, uint16_t payloadLen, uint8_t *payload);
|
// classes can use it
|
||||||
|
typedef void (*UBXMessageCallback)(uint8_t msgClass, uint8_t msgId,
|
||||||
|
uint16_t payloadLen, uint8_t *payload);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Class for parsing UBX protocol messages from u-blox GPS/RTK modules
|
* @brief Class for parsing UBX protocol messages from u-blox GPS/RTK modules
|
||||||
|
|
@ -45,11 +46,15 @@ class Adafruit_UBX {
|
||||||
bool begin();
|
bool begin();
|
||||||
|
|
||||||
bool checkMessages(); // Message parsing
|
bool checkMessages(); // Message parsing
|
||||||
bool sendMessage(uint8_t msgClass, uint8_t msgId, uint8_t *payload, uint16_t length); // Send a UBX message
|
bool sendMessage(uint8_t msgClass, uint8_t msgId, uint8_t *payload,
|
||||||
UBXSendStatus sendMessageWithAck(uint8_t msgClass, uint8_t msgId, uint8_t *payload, uint16_t length, uint16_t timeout_ms = 500);
|
uint16_t length); // Send a UBX message
|
||||||
|
UBXSendStatus sendMessageWithAck(uint8_t msgClass, uint8_t msgId,
|
||||||
|
uint8_t *payload, uint16_t length,
|
||||||
|
uint16_t timeout_ms = 500);
|
||||||
|
|
||||||
// Configure port to use UBX protocol only (disable NMEA)
|
// Configure port to use UBX protocol only (disable NMEA)
|
||||||
UBXSendStatus setUBXOnly(UBXPortId portID, bool checkAck = true, uint16_t timeout_ms = 500);
|
UBXSendStatus setUBXOnly(UBXPortId portID, bool checkAck = true,
|
||||||
|
uint16_t timeout_ms = 500);
|
||||||
|
|
||||||
void setMessageCallback(UBXMessageCallback callback); // Set callback function
|
void setMessageCallback(UBXMessageCallback callback); // Set callback function
|
||||||
UBXMessageCallback onUBXMessage; // Callback for message received
|
UBXMessageCallback onUBXMessage; // Callback for message received
|
||||||
|
|
@ -59,7 +64,8 @@ class Adafruit_UBX {
|
||||||
|
|
||||||
// Buffer for reading messages
|
// Buffer for reading messages
|
||||||
static const uint16_t MAX_PAYLOAD_SIZE = 64; // Maximum UBX payload size
|
static const uint16_t MAX_PAYLOAD_SIZE = 64; // Maximum UBX payload size
|
||||||
uint8_t _buffer[MAX_PAYLOAD_SIZE + 8]; // Buffer for message (header, payload, checksum)
|
uint8_t _buffer[MAX_PAYLOAD_SIZE +
|
||||||
|
8]; // Buffer for message (header, payload, checksum)
|
||||||
|
|
||||||
// Parser state machine
|
// Parser state machine
|
||||||
enum ParserState {
|
enum ParserState {
|
||||||
|
|
@ -83,7 +89,8 @@ class Adafruit_UBX {
|
||||||
uint8_t _checksumB; // Running checksum B
|
uint8_t _checksumB; // Running checksum B
|
||||||
|
|
||||||
// Calculate checksum for a block of data
|
// Calculate checksum for a block of data
|
||||||
void calculateChecksum(uint8_t *buffer, uint16_t len, uint8_t &checksumA, uint8_t &checksumB);
|
void calculateChecksum(uint8_t *buffer, uint16_t len, uint8_t &checksumA,
|
||||||
|
uint8_t &checksumB);
|
||||||
|
|
||||||
// Reset parser state
|
// Reset parser state
|
||||||
void resetParser();
|
void resetParser();
|
||||||
|
|
|
||||||
|
|
@ -50,9 +50,7 @@ Adafruit_UBloxDDC::~Adafruit_UBloxDDC() {
|
||||||
* @brief Initializes the GPS module and I2C interface
|
* @brief Initializes the GPS module and I2C interface
|
||||||
* @return True if GPS module responds, false on any failure
|
* @return True if GPS module responds, false on any failure
|
||||||
*/
|
*/
|
||||||
bool Adafruit_UBloxDDC::begin() {
|
bool Adafruit_UBloxDDC::begin() { return _i2cDevice->begin(); }
|
||||||
return _i2cDevice->begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Gets the number of bytes available for reading
|
* @brief Gets the number of bytes available for reading
|
||||||
|
|
@ -62,7 +60,8 @@ int Adafruit_UBloxDDC::available() {
|
||||||
uint8_t buffer[2];
|
uint8_t buffer[2];
|
||||||
|
|
||||||
// Create a register for reading bytes available
|
// Create a register for reading bytes available
|
||||||
Adafruit_BusIO_Register bytesAvailableReg = Adafruit_BusIO_Register(_i2cDevice, REG_BYTES_AVAILABLE_MSB, 2);
|
Adafruit_BusIO_Register bytesAvailableReg =
|
||||||
|
Adafruit_BusIO_Register(_i2cDevice, REG_BYTES_AVAILABLE_MSB, 2);
|
||||||
|
|
||||||
if (!bytesAvailableReg.read(buffer, 2)) {
|
if (!bytesAvailableReg.read(buffer, 2)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -88,7 +87,8 @@ int Adafruit_UBloxDDC::read() {
|
||||||
uint8_t value;
|
uint8_t value;
|
||||||
|
|
||||||
// Create a register for the data stream
|
// Create a register for the data stream
|
||||||
Adafruit_BusIO_Register dataStreamReg = Adafruit_BusIO_Register(_i2cDevice, REG_DATA_STREAM, 1);
|
Adafruit_BusIO_Register dataStreamReg =
|
||||||
|
Adafruit_BusIO_Register(_i2cDevice, REG_DATA_STREAM, 1);
|
||||||
|
|
||||||
if (!dataStreamReg.read(&value, 1)) {
|
if (!dataStreamReg.read(&value, 1)) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -176,7 +176,8 @@ uint16_t Adafruit_UBloxDDC::readBytes(uint8_t* buffer, uint16_t length) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a register for the data stream
|
// Create a register for the data stream
|
||||||
Adafruit_BusIO_Register dataStreamReg = Adafruit_BusIO_Register(_i2cDevice, REG_DATA_STREAM, 1);
|
Adafruit_BusIO_Register dataStreamReg =
|
||||||
|
Adafruit_BusIO_Register(_i2cDevice, REG_DATA_STREAM, 1);
|
||||||
|
|
||||||
while (bytesRead < length) {
|
while (bytesRead < length) {
|
||||||
// Calculate chunk size (I2C has a limit on bytes per transfer)
|
// Calculate chunk size (I2C has a limit on bytes per transfer)
|
||||||
|
|
@ -219,4 +220,3 @@ uint8_t* Adafruit_UBloxDDC::readMessage(uint16_t* messageLength) {
|
||||||
*messageLength = readMessage(_buffer, MAX_BUFFER_SIZE);
|
*messageLength = readMessage(_buffer, MAX_BUFFER_SIZE);
|
||||||
return _buffer;
|
return _buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,10 @@
|
||||||
#ifndef ADAFRUIT_UBLOXDDC_H
|
#ifndef ADAFRUIT_UBLOXDDC_H
|
||||||
#define ADAFRUIT_UBLOXDDC_H
|
#define ADAFRUIT_UBLOXDDC_H
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include <Stream.h>
|
|
||||||
#include <Adafruit_BusIO_Register.h>
|
#include <Adafruit_BusIO_Register.h>
|
||||||
#include <Adafruit_I2CDevice.h>
|
#include <Adafruit_I2CDevice.h>
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <Stream.h>
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Arduino library for interfacing with u-blox GPS/RTK modules over I2C
|
* @brief Arduino library for interfacing with u-blox GPS/RTK modules over I2C
|
||||||
|
|
@ -31,12 +31,16 @@ class Adafruit_UBloxDDC : public Stream {
|
||||||
Adafruit_I2CDevice *_i2cDevice; ///< Underlying I2C device
|
Adafruit_I2CDevice *_i2cDevice; ///< Underlying I2C device
|
||||||
|
|
||||||
// Register addresses
|
// Register addresses
|
||||||
static const uint8_t REG_DATA_STREAM = 0xFF; ///< Register for reading data stream
|
static const uint8_t REG_DATA_STREAM =
|
||||||
static const uint8_t REG_BYTES_AVAILABLE_MSB = 0xFD; ///< MSB of bytes available
|
0xFF; ///< Register for reading data stream
|
||||||
static const uint8_t REG_BYTES_AVAILABLE_LSB = 0xFE; ///< LSB of bytes available
|
static const uint8_t REG_BYTES_AVAILABLE_MSB =
|
||||||
|
0xFD; ///< MSB of bytes available
|
||||||
|
static const uint8_t REG_BYTES_AVAILABLE_LSB =
|
||||||
|
0xFE; ///< LSB of bytes available
|
||||||
|
|
||||||
// Buffer for reading messages
|
// Buffer for reading messages
|
||||||
static const uint16_t MAX_BUFFER_SIZE = 128; ///< Maximum buffer size for messages
|
static const uint16_t MAX_BUFFER_SIZE =
|
||||||
|
128; ///< Maximum buffer size for messages
|
||||||
uint8_t _buffer[MAX_BUFFER_SIZE]; ///< Internal buffer for messages
|
uint8_t _buffer[MAX_BUFFER_SIZE]; ///< Internal buffer for messages
|
||||||
|
|
||||||
// Last byte read for peek() implementation
|
// Last byte read for peek() implementation
|
||||||
|
|
|
||||||
|
|
@ -18,22 +18,35 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
// NMEA Message Configuration Commands (CFG-MSG)
|
// NMEA Message Configuration Commands (CFG-MSG)
|
||||||
// Format: {msgClass, msgID, rate_I2C, rate_UART1, rate_UART2, rate_USB, rate_SPI, reserved}
|
// Format: {msgClass, msgID, rate_I2C, rate_UART1, rate_UART2, rate_USB,
|
||||||
|
// rate_SPI, reserved}
|
||||||
|
|
||||||
// Enable specific NMEA message sentences to output on the DDC interface
|
// Enable specific NMEA message sentences to output on the DDC interface
|
||||||
static uint8_t UBX_CFG_MSG_NMEA_GGA_ENABLE[] = {0xF0, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00};
|
static uint8_t UBX_CFG_MSG_NMEA_GGA_ENABLE[] = {0xF0, 0x00, 0x01, 0x00,
|
||||||
static uint8_t UBX_CFG_MSG_NMEA_GLL_ENABLE[] = {0xF0, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00};
|
0x00, 0x00, 0x00, 0x00};
|
||||||
static uint8_t UBX_CFG_MSG_NMEA_GSA_ENABLE[] = {0xF0, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00};
|
static uint8_t UBX_CFG_MSG_NMEA_GLL_ENABLE[] = {0xF0, 0x01, 0x01, 0x00,
|
||||||
static uint8_t UBX_CFG_MSG_NMEA_GSV_ENABLE[] = {0xF0, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00};
|
0x00, 0x00, 0x00, 0x00};
|
||||||
static uint8_t UBX_CFG_MSG_NMEA_RMC_ENABLE[] = {0xF0, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00};
|
static uint8_t UBX_CFG_MSG_NMEA_GSA_ENABLE[] = {0xF0, 0x02, 0x01, 0x00,
|
||||||
static uint8_t UBX_CFG_MSG_NMEA_VTG_ENABLE[] = {0xF0, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00};
|
0x00, 0x00, 0x00, 0x00};
|
||||||
|
static uint8_t UBX_CFG_MSG_NMEA_GSV_ENABLE[] = {0xF0, 0x03, 0x01, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00};
|
||||||
|
static uint8_t UBX_CFG_MSG_NMEA_RMC_ENABLE[] = {0xF0, 0x04, 0x01, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00};
|
||||||
|
static uint8_t UBX_CFG_MSG_NMEA_VTG_ENABLE[] = {0xF0, 0x05, 0x01, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00};
|
||||||
// Disable specific NMEA message sentences from outputting on the DDC interface
|
// Disable specific NMEA message sentences from outputting on the DDC interface
|
||||||
static uint8_t UBX_CFG_MSG_NMEA_GGA_DISABLE[] = {0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
static uint8_t UBX_CFG_MSG_NMEA_GGA_DISABLE[] = {0xF0, 0x00, 0x00, 0x00,
|
||||||
static uint8_t UBX_CFG_MSG_NMEA_GLL_DISABLE[] = {0xF0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
0x00, 0x00, 0x00, 0x00};
|
||||||
static uint8_t UBX_CFG_MSG_NMEA_GSA_DISABLE[] = {0xF0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
static uint8_t UBX_CFG_MSG_NMEA_GLL_DISABLE[] = {0xF0, 0x01, 0x00, 0x00,
|
||||||
static uint8_t UBX_CFG_MSG_NMEA_GSV_DISABLE[] = {0xF0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
0x00, 0x00, 0x00, 0x00};
|
||||||
static uint8_t UBX_CFG_MSG_NMEA_RMC_DISABLE[] = {0xF0, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
static uint8_t UBX_CFG_MSG_NMEA_GSA_DISABLE[] = {0xF0, 0x02, 0x00, 0x00,
|
||||||
static uint8_t UBX_CFG_MSG_NMEA_VTG_DISABLE[] = {0xF0, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
0x00, 0x00, 0x00, 0x00};
|
||||||
|
static uint8_t UBX_CFG_MSG_NMEA_GSV_DISABLE[] = {0xF0, 0x03, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00};
|
||||||
|
static uint8_t UBX_CFG_MSG_NMEA_RMC_DISABLE[] = {0xF0, 0x04, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00};
|
||||||
|
static uint8_t UBX_CFG_MSG_NMEA_VTG_DISABLE[] = {0xF0, 0x05, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00};
|
||||||
|
|
||||||
// Navigation Rate Configuration Commands (CFG-RATE)
|
// Navigation Rate Configuration Commands (CFG-RATE)
|
||||||
// Format: {measRate_ms (2 bytes), navRate, timeRef}
|
// Format: {measRate_ms (2 bytes), navRate, timeRef}
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,8 @@ typedef enum {
|
||||||
// Total size: 20 bytes
|
// Total size: 20 bytes
|
||||||
typedef union {
|
typedef union {
|
||||||
struct {
|
struct {
|
||||||
uint8_t portID; // Port identifier (0=DDC/I2C, 1=UART1, 2=UART2, 3=USB, 4=SPI)
|
uint8_t
|
||||||
|
portID; // Port identifier (0=DDC/I2C, 1=UART1, 2=UART2, 3=USB, 4=SPI)
|
||||||
uint8_t reserved1; // Reserved
|
uint8_t reserved1; // Reserved
|
||||||
uint16_t txReady; // TX ready PIN configuration
|
uint16_t txReady; // TX ready PIN configuration
|
||||||
uint32_t mode; // UART mode (bit field) or Reserved for non-UART ports
|
uint32_t mode; // UART mode (bit field) or Reserved for non-UART ports
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue