diff --git a/html/_adafruit___u_b_x_8h_source.html b/html/_adafruit___u_b_x_8h_source.html index 8690b2b..7fa9699 100644 --- a/html/_adafruit___u_b_x_8h_source.html +++ b/html/_adafruit___u_b_x_8h_source.html @@ -62,19 +62,19 @@ $(function() {
Adafruit_UBX.h
-Go to the documentation of this file.
1 
17 #ifndef ADAFRUIT_UBX_H
18 #define ADAFRUIT_UBX_H
19 
21 #include "Adafruit_uBlox_typedef.h"
22 #include <Arduino.h>
23 #include <Stream.h>
24 
25 // UBX protocol constants
26 #define UBX_SYNC_CHAR_1 0xB5
27 #define UBX_SYNC_CHAR_2 0x62
28 // UBX ACK Message IDs
29 #define UBX_ACK_NAK 0x00
30 #define UBX_ACK_ACK 0x01
31 
32 
40 typedef void (*UBXMessageCallback)(uint8_t msgClass, uint8_t msgId,
41  uint16_t payloadLen, uint8_t *payload);
42 
46 class Adafruit_UBX {
47 public:
48  Adafruit_UBX(Stream &stream);
49  ~Adafruit_UBX();
50  uint8_t verbose_debug = 0;
51  // Basic methods
52  bool begin();
53  bool checkMessages(); // Message parsing
54  bool sendMessage(uint8_t msgClass, uint8_t msgId, uint8_t *payload,
55  uint16_t length); // Send a UBX message
56  UBXSendStatus sendMessageWithAck(uint8_t msgClass, uint8_t msgId,
57  uint8_t *payload, uint16_t length,
58  uint16_t timeout_ms = 500);
59 
60  // Configure port to use UBX protocol only (disable NMEA)
61  UBXSendStatus setUBXOnly(UBXPortId portID, bool checkAck = true,
62  uint16_t timeout_ms = 500);
63 
64  void setMessageCallback(UBXMessageCallback callback); // Set callback function
66 
67 private:
68  Stream *_stream; // Stream interface for reading data
69 
70  // Buffer for reading messages
71  static const uint16_t MAX_PAYLOAD_SIZE = 64; // Maximum UBX payload size
72  uint8_t _buffer[MAX_PAYLOAD_SIZE +
73  8]; // Buffer for message (header, payload, checksum)
74 
75  // Parser state machine
76  enum ParserState {
77  WAIT_SYNC_1, // Waiting for first sync char (0xB5)
78  WAIT_SYNC_2, // Waiting for second sync char (0x62)
79  GET_CLASS, // Reading message class
80  GET_ID, // Reading message ID
81  GET_LENGTH_1, // Reading length LSB
82  GET_LENGTH_2, // Reading length MSB
83  GET_PAYLOAD, // Reading payload
84  GET_CHECKSUM_A, // Reading checksum A
85  GET_CHECKSUM_B // Reading checksum B
86  };
87 
88  ParserState _parserState = WAIT_SYNC_1; // Current state of the parser
89  uint8_t _msgClass; // Message class of current message
90  uint8_t _msgId; // Message ID of current message
91  uint16_t _payloadLength; // Length of current message payload
92  uint16_t _payloadCounter; // Counter for payload bytes received
93  uint8_t _checksumA; // Running checksum A
94  uint8_t _checksumB; // Running checksum B
95 
96  // Calculate checksum for a block of data
97  void calculateChecksum(uint8_t *buffer, uint16_t len, uint8_t &checksumA,
98  uint8_t &checksumB);
99 
100  // Reset parser state
101  void resetParser();
102 
103  // Add to private section of Adafruit_UBX.h
104  uint8_t _lastMsgClass; // Class of last message
105  uint8_t _lastMsgId; // ID of last message
106  uint16_t _lastPayloadLength; // Length of last message payload
107  uint8_t _lastPayload[8]; // Buffer for small payloads (like ACK messages)
108 };
109 
110 #endif // ADAFRUIT_UBX_H
void setMessageCallback(UBXMessageCallback callback)
Sets the callback function for UBX messages.
Definition: Adafruit_UBX.cpp:130
+Go to the documentation of this file.
1 
17 #ifndef ADAFRUIT_UBX_H
18 #define ADAFRUIT_UBX_H
19 
21 #include "Adafruit_uBlox_typedef.h"
22 #include <Arduino.h>
23 #include <Stream.h>
24 
25 // UBX protocol constants
26 #define UBX_SYNC_CHAR_1 0xB5
27 #define UBX_SYNC_CHAR_2 0x62
28 // UBX ACK Message IDs
29 #define UBX_ACK_NAK 0x00
30 #define UBX_ACK_ACK 0x01
31 
32 
40 typedef void (*UBXMessageCallback)(uint8_t msgClass, uint8_t msgId,
41  uint16_t payloadLen, uint8_t *payload);
42 
46 class Adafruit_UBX {
47 public:
48  Adafruit_UBX(Stream &stream);
49  ~Adafruit_UBX();
50  uint8_t verbose_debug = 0;
51  // Basic methods
52  bool begin();
53  bool checkMessages(); // Message parsing
54  bool sendMessage(uint8_t msgClass, uint8_t msgId, uint8_t *payload,
55  uint16_t length); // Send a UBX message
56  UBXSendStatus sendMessageWithAck(uint8_t msgClass, uint8_t msgId,
57  uint8_t *payload, uint16_t length,
58  uint16_t timeout_ms = 500);
59 
60  // Configure port to use UBX protocol only (disable NMEA)
61  UBXSendStatus setUBXOnly(UBXPortId portID, bool checkAck = true,
62  uint16_t timeout_ms = 500);
63 
64  void setMessageCallback(UBXMessageCallback callback); // Set callback function
66 
67 private:
68  Stream *_stream; // Stream interface for reading data
69 
70  // Buffer for reading messages
71  static const uint16_t MAX_PAYLOAD_SIZE = 64; // Maximum UBX payload size
72  uint8_t _buffer[MAX_PAYLOAD_SIZE +
73  8]; // Buffer for message (header, payload, checksum)
74 
75  // Parser state machine
76  enum ParserState {
77  WAIT_SYNC_1, // Waiting for first sync char (0xB5)
78  WAIT_SYNC_2, // Waiting for second sync char (0x62)
79  GET_CLASS, // Reading message class
80  GET_ID, // Reading message ID
81  GET_LENGTH_1, // Reading length LSB
82  GET_LENGTH_2, // Reading length MSB
83  GET_PAYLOAD, // Reading payload
84  GET_CHECKSUM_A, // Reading checksum A
85  GET_CHECKSUM_B // Reading checksum B
86  };
87 
88  ParserState _parserState = WAIT_SYNC_1; // Current state of the parser
89  uint8_t _msgClass; // Message class of current message
90  uint8_t _msgId; // Message ID of current message
91  uint16_t _payloadLength; // Length of current message payload
92  uint16_t _payloadCounter; // Counter for payload bytes received
93  uint8_t _checksumA; // Running checksum A
94  uint8_t _checksumB; // Running checksum B
95 
96  // Calculate checksum for a block of data
97  void calculateChecksum(uint8_t *buffer, uint16_t len, uint8_t &checksumA,
98  uint8_t &checksumB);
99 
100  // Reset parser state
101  void resetParser();
102 
103  // Add to private section of Adafruit_UBX.h
104  uint8_t _lastMsgClass; // Class of last message
105  uint8_t _lastMsgId; // ID of last message
106  uint16_t _lastPayloadLength; // Length of last message payload
107  uint8_t _lastPayload[8]; // Buffer for small payloads (like ACK messages)
108 };
109 
110 #endif // ADAFRUIT_UBX_H
void setMessageCallback(UBXMessageCallback callback)
Sets the callback function for UBX messages.
Definition: Adafruit_UBX.cpp:128
void(* UBXMessageCallback)(uint8_t msgClass, uint8_t msgId, uint16_t payloadLen, uint8_t *payload)
Callback function type for UBX messages - defined at global scope so other classes can use it...
Definition: Adafruit_UBX.h:40
-
UBXSendStatus sendMessageWithAck(uint8_t msgClass, uint8_t msgId, uint8_t *payload, uint16_t length, uint16_t timeout_ms=500)
Send a UBX message and wait for acknowledgment.
Definition: Adafruit_UBX.cpp:328
+
UBXSendStatus sendMessageWithAck(uint8_t msgClass, uint8_t msgId, uint8_t *payload, uint16_t length, uint16_t timeout_ms=500)
Send a UBX message and wait for acknowledgment.
Definition: Adafruit_UBX.cpp:326
-
bool checkMessages()
Check for new UBX messages and parse them.
Definition: Adafruit_UBX.cpp:165
+
bool checkMessages()
Check for new UBX messages and parse them.
Definition: Adafruit_UBX.cpp:163
UBXMessageCallback onUBXMessage
Callback for message received.
Definition: Adafruit_UBX.h:65
UBXPortId
Definition: Adafruit_uBlox_typedef.h:60
Class for parsing UBX protocol messages from u-blox GPS/RTK modules.
Definition: Adafruit_UBX.h:46
-
bool begin()
Initializes the UBX parser.
Definition: Adafruit_UBX.cpp:50
+
bool begin()
Initializes the UBX parser.
Definition: Adafruit_UBX.cpp:48
~Adafruit_UBX()
Destructor.
Definition: Adafruit_UBX.cpp:39
-
UBXSendStatus setUBXOnly(UBXPortId portID, bool checkAck=true, uint16_t timeout_ms=500)
Configure the GPS module to output only UBX protocol (disables NMEA)
Definition: Adafruit_UBX.cpp:62
-
bool sendMessage(uint8_t msgClass, uint8_t msgId, uint8_t *payload, uint16_t length)
Send a UBX message to the GPS module.
Definition: Adafruit_UBX.cpp:411
+
UBXSendStatus setUBXOnly(UBXPortId portID, bool checkAck=true, uint16_t timeout_ms=500)
Configure the GPS module to output only UBX protocol (disables NMEA)
Definition: Adafruit_UBX.cpp:60
+
bool sendMessage(uint8_t msgClass, uint8_t msgId, uint8_t *payload, uint16_t length)
Send a UBX message to the GPS module.
Definition: Adafruit_UBX.cpp:409
UBXSendStatus
Definition: Adafruit_uBlox_typedef.h:52
uint8_t verbose_debug
0=off, 1=basic, 2=verbose
Definition: Adafruit_UBX.h:50
Adafruit_UBX(Stream &stream)
Constructor.
Definition: Adafruit_UBX.cpp:31