SELKIELogger  1.0.0
GPSCommands.c
1 /*
2  * Copyright (C) 2023 Swansea University
3  *
4  * This file is part of the SELKIELogger suite of tools.
5  *
6  * SELKIELogger is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation, either version 3 of the License, or (at your option)
9  * any later version.
10  *
11  * SELKIELogger is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this SELKIELogger product.
18  * If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include <stdint.h>
22 
23 #include "GPSCommands.h"
24 #include "GPSMessages.h"
25 #include "GPSSerial.h"
26 #include "GPSTypes.h"
27 
28 /***
29  * Some common features of all messages:
30  * - Header:
31  * - 2 byte header
32  * - 2 byte message ID (category + type)
33  * - 2 byte / 1 word length
34  * - Footer:
35  * - 2 byte checksum
36  * An artefact of the internal representation of the messages is an additional
37  * trailing zero in the values used here. This ensures that the pointer to any
38  * extra data is set to zero
39  */
53 bool ubx_setBaudRate(const int handle, const uint32_t baud) {
54  ubx_message setBaud = {0xB5,
55  0x62, // Header bytes
56  0x06,
57  0x00, // CFG-PRT
58  0x0014, // 20 byte message
59  {
60  0x01, // Configure port 1 (UART)
61  0x00, // Reserved
62  0x00, 0x00, // No ready pin
63  0xd0, 0x08, 0x00, 0x00, // UART Mode
64  0x00, 0x00, 0x00, 0x00, // Baud (set below)
65  0x07, 0x00, // All protocols allowed as input
66  0x01, 0x00, // UBX protocol only output
67  0x00, 0x00, // Flags
68  0x00, 0x00 // Reserved
69  },
70  0xFF,
71  0xFF, // Checksum value calculated later
72  0x00}; // No extra data pointer
73 
74  setBaud.data[8] = (uint8_t)(baud & 0xFF);
75  setBaud.data[9] = (uint8_t)((baud >> 8) & 0xFF);
76  setBaud.data[10] = (uint8_t)((baud >> 16) & 0xFF);
77  setBaud.data[11] = (uint8_t)((baud >> 24) & 0xFF);
78 
79  ubx_set_checksum(&setBaud);
80  return ubx_writeMessage(handle, &setBaud);
81 }
82 
95 bool ubx_setMessageRate(const int handle, const uint8_t msgClass, const uint8_t msgID, const uint8_t rate) {
96  ubx_message setRate = {0xB5,
97  0x62,
98  0x06,
99  0x01, // Header, CFG-MSG
100  0x0008, // 8 byte message
101  {
102  msgClass, msgID,
103  0x00, // Disable on I2C
104  rate, // Every "rate" updates on UART1
105  0x00, // Disable UART 2
106  rate, // Also enable on USB direct
107  0x00, // Disable on SPI
108  0x00 // Disable on port 5
109  },
110  0xFF,
111  0xFF,
112  0x00};
113  ubx_set_checksum(&setRate);
114  return ubx_writeMessage(handle, &setRate);
115 }
116 
128 bool ubx_pollMessage(const int handle, const uint8_t msgClass, const uint8_t msgID) {
129  ubx_message poll = {0xB5, 0x62, msgClass, msgID, 0x0000, {0x00}, 0xFF, 0xFF, 0x00};
130  ubx_set_checksum(&poll);
131  return ubx_writeMessage(handle, &poll);
132 }
133 
140 bool ubx_enableGalileo(const int handle) {
141  ubx_message enableGalileo = {0xB5,
142  0x62, // Header
143  0x06, // CFG
144  0x3e, // ?
145  0x003C,
146  {0x00, 0x20, 0x20, 0x07, 0x00, 0x08, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01,
147  0x01, 0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x04, 0x08, 0x00,
148  0x01, 0x00, 0x01, 0x01, 0x03, 0x08, 0x10, 0x00, 0x00, 0x00, 0x01, 0x01,
149  0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x03, 0x05, 0x00, 0x03, 0x00,
150  0x01, 0x00, 0x01, 0x05, 0x06, 0x08, 0x0E, 0x00, 0x01, 0x00, 0x01, 0x01},
151  0xFF,
152  0xFF,
153  0x00};
154  ubx_set_checksum(&enableGalileo);
155  return ubx_writeMessage(handle, &enableGalileo);
156 }
157 
171 bool ubx_setNavigationRate(const int handle, const uint16_t interval, const uint16_t outputRate) {
172  ubx_message navRate = {0xB5,
173  0x62, // Header
174  0x06, // CFG
175  0x08, // RATE
176  0x0006,
177  {
178  (interval & 0xFF), ((interval >> 8) & 0xFF), (outputRate & 0xFF),
179  ((outputRate >> 8) & 0xFF), 0x00,
180  0x00 // Align measurements to UTC
181  },
182  0xFF,
183  0xFF,
184  0x00};
185  ubx_set_checksum(&navRate);
186  return ubx_writeMessage(handle, &navRate);
187 }
188 
199 bool ubx_enableLogMessages(const int handle) {
200  ubx_message enableInf = {0xB5,
201  0x62, // Header
202  0x06, // CFG
203  0x02, // INF
204  0x000A, // 10 bytes
205  {
206  0x00, // UBX
207  0x00, 0x00, 0x00, // Reserved
208  0x00, 0x07, 0x00, 0x00, 0x00,
209  0x00, // Error, warning and info on UART 1, disable all others
210  },
211  0xFF,
212  0xFF,
213  0x00};
214  ubx_set_checksum(&enableInf);
215  return ubx_writeMessage(handle, &enableInf);
216 }
217 
224 bool ubx_disableLogMessages(const int handle) {
225  ubx_message disableInf = {0xB5,
226  0x62,
227  0x06,
228  0x02, // Header, CFG-INF
229  0x000A, // 10 bytes
230  {
231  0x00, // UBX
232  0x00, 0x00, 0x00, // Reserved
233  0x00, 0x00, 0x00, 0x00, 0x00,
234  0x00, // Disable all
235  },
236  0xFF,
237  0xFF,
238  0x00};
239  ubx_set_checksum(&disableInf);
240  return ubx_writeMessage(handle, &disableInf);
241 }
242 
250 bool ubx_setI2CAddress(const int handle, const uint8_t addr) {
251  ubx_message setI2C = {0xB5,
252  0x62,
253  0x06,
254  0x00, // Header, CFG-INF
255  0x0014, // 20 bytes
256  {
257  0x00, // I2C/DDC
258  0x00, // Reserved
259  0x00, 0x00, // TXReady (disabled)
260  (addr << 1), 0x00, 0x00, 0x00, // Mode
261  0x00, 0x00, // Reserved
262  0x01, // UBX Only input
263  0x01, // UBX Only output
264  0x00, 0x00, 0x00, 0x00, // Flags, reserved
265  },
266  0xFF,
267  0xFF,
268  0x00};
269  ubx_set_checksum(&setI2C);
270  return ubx_writeMessage(handle, &setI2C);
271 }
bool ubx_writeMessage(int handle, const ubx_message *out)
Send message to attached device.
Definition: GPSSerial.c:298
bool ubx_pollMessage(const int handle, const uint8_t msgClass, const uint8_t msgID)
Request specific message by class and ID.
Definition: GPSCommands.c:128
bool ubx_setI2CAddress(const int handle, const uint8_t addr)
Set I2C address.
Definition: GPSCommands.c:250
bool ubx_setNavigationRate(const int handle, const uint16_t interval, const uint16_t outputRate)
Set UBX navigation calculation and reporting rate.
Definition: GPSCommands.c:171
bool ubx_enableGalileo(const int handle)
Enable Galileo constellation use.
Definition: GPSCommands.c:140
bool ubx_enableLogMessages(const int handle)
Enable log/information messages from GPS device.
Definition: GPSCommands.c:199
bool ubx_disableLogMessages(const int handle)
Disable log/information messages from GPS device.
Definition: GPSCommands.c:224
bool ubx_setMessageRate(const int handle, const uint8_t msgClass, const uint8_t msgID, const uint8_t rate)
Send UBX rate command to enable/disable message types.
Definition: GPSCommands.c:95
bool ubx_setBaudRate(const int handle, const uint32_t baud)
Send UBX port configuration to switch baud rate.
Definition: GPSCommands.c:53
void ubx_set_checksum(ubx_message *msg)
Set checksum bytes for UBX message.
Definition: GPSMessages.c:71
Internal representation of a UBX message.
Definition: GPSTypes.h:80
uint8_t data[256]
Data if length <= 256.
Definition: GPSTypes.h:86