STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
ubx.h
Go to the documentation of this file.
1#ifndef STAR_UBX_H
2#define STAR_UBX_H
3
4/*
5 * u-blox UBX protocol pieces for the MAX-M10S (MD1). Interface Description
6 * "u-blox M10 SPG 5.10", UBX-21035062 R02:
7 * frame B5 62 class id len16 payload CK_A CK_B, 8-bit Fletcher over
8 * class..payload
9 * VALSET 0x06 0x8A: version 0, layers, 2 reserved, key/value pairs
10 * (3.10.5.1, p.55); this code writes the RAM layer only, so the
11 * configuration is re-sent on every power-up
12 * ACK 0x05 0x01 ACK / 0x05 0x00 NAK, payload = acked class, id
13 * NAV-PVT 0x01 0x07, 92 bytes (3.15.11, p.95)
14 * NAV-SAT 0x01 0x35, 8 + numSvs*12 bytes (3.15.13, p.98)
15 * MON-RF 0x0A 0x38, 4 + nBlocks*24 bytes (3.14.6, p.86)
16 * A message with an empty payload polls the module for that message.
17 * Keys used (Section 6, p.136-154): CFG-UART1-BAUDRATE 0x40520001 U4,
18 * CFG-UART1OUTPROT-NMEA 0x10740002 L, CFG-MSGOUT-UBX_NAV_PVT_UART1
19 * 0x20910007 U1, CFG-RATE-MEAS 0x30210001 U2 (ms), CFG-NAVSPG-DYNMODEL
20 * 0x20110021 E1 (AIR4 = 8, "airborne <4g", Table 23 p.141).
21 */
22
23#include <stdbool.h>
24#include <stddef.h>
25#include <stdint.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#define UBX_CLASS_NAV 0x01U
32#define UBX_CLASS_ACK 0x05U
33#define UBX_CLASS_CFG 0x06U
34#define UBX_CLASS_MON 0x0AU
35#define UBX_ID_NAV_PVT 0x07U
36#define UBX_ID_NAV_SAT 0x35U
37#define UBX_ID_MON_RF 0x38U
38#define UBX_ID_ACK_ACK 0x01U
39#define UBX_ID_ACK_NAK 0x00U
40#define UBX_ID_CFG_VALSET 0x8AU
41#define UBX_NAV_PVT_LEN 92U
42
43#define UBX_KEY_UART1_BAUDRATE 0x40520001UL
44#define UBX_KEY_UART1OUTPROT_NMEA 0x10740002UL
45#define UBX_KEY_MSGOUT_NAV_PVT_UART1 0x20910007UL
46#define UBX_KEY_RATE_MEAS 0x30210001UL
47#define UBX_KEY_NAVSPG_DYNMODEL 0x20110021UL
48#define UBX_DYNMODEL_AIR4 8U
49
50typedef struct {
51 uint32_t key;
52 uint8_t size; /* 1, 2 or 4 bytes (L/U1/E1, U2, U4) */
53 uint32_t value;
55
56/* Whole frame into out; returns its length, 0 if it does not fit. */
57size_t ubx_frame(uint8_t* out, size_t cap, uint8_t cls, uint8_t id,
58 const uint8_t* payload, uint16_t len);
59
60/* UBX-CFG-VALSET to the RAM layer; returns frame length, 0 on error. */
61size_t ubx_valset(uint8_t* out, size_t cap, const ubx_item_t* items,
62 size_t count);
63
64typedef struct {
65 uint32_t itow_ms;
66 uint16_t year;
67 uint8_t month, day, hour, min, sec, valid;
68 uint8_t fix_type; /* 0 none, 2 2D, 3 3D */
69 uint8_t flags; /* bit 0 gnssFixOK */
70 uint8_t num_sv;
71 int32_t lon_e7, lat_e7; /* 1e-7 deg */
73 uint32_t hacc_mm, vacc_mm;
75 uint32_t sacc_mms;
76 uint16_t pdop_e2;
77} ubx_pvt_t;
78
79/* Decode a NAV-PVT payload (exactly 92 bytes). */
80bool ubx_parse_nav_pvt(const uint8_t* payload, uint16_t len, ubx_pvt_t* out);
81
82/* A poll request (the message with no payload); returns frame length. */
83size_t ubx_poll(uint8_t* out, size_t cap, uint8_t cls, uint8_t id);
84
85/* MON-RF antenna supervisor values (3.14.6, p.86) */
86#define UBX_ANT_INIT 0U
87#define UBX_ANT_DONTKNOW 1U
88#define UBX_ANT_OK 2U
89#define UBX_ANT_SHORT 3U
90#define UBX_ANT_OPEN 4U
91#define UBX_ANT_POWER_OFF 0U
92#define UBX_ANT_POWER_ON 1U
93#define UBX_ANT_POWER_DONTKNOW 2U
94
95/* MON-RF, first RF block (L1, the only band on the MAX-M10S). */
96typedef struct {
97 uint8_t ant_status; /* UBX_ANT_* */
98 uint8_t ant_power; /* UBX_ANT_POWER_* */
99 uint8_t jamming; /* 0 unknown, 1 ok, 2 warning, 3 critical */
100 uint8_t cw; /* CW jamming suppression, 0 none .. 255 strong */
101 uint16_t noise; /* noisePerMS */
102 uint16_t agc; /* agcCnt, 0..8191 */
103} ubx_rf_t;
104
105/* Decode a MON-RF payload with at least one RF block. */
106bool ubx_parse_mon_rf(const uint8_t* payload, uint16_t len, ubx_rf_t* out);
107
108/* NAV-SAT condensed to counts. `len` may be a captured prefix of the
109 * payload: `listed` is the module's numSvs, the rest count only the SVs
110 * whose 12-byte blocks are within `len` (`seen` of them). */
111typedef struct {
112 uint8_t listed; /* numSvs: known visible or tracked */
113 uint8_t seen; /* blocks decoded (< listed if truncated) */
114 uint8_t with_signal; /* cno > 0 */
115 uint8_t locked; /* qualityInd >= 4: code locked, time synced */
116 uint8_t used; /* svUsed: in the navigation solution */
117 uint8_t best_cno; /* strongest C/N0, dB-Hz */
118} ubx_sats_t;
119
120bool ubx_sat_summary(const uint8_t* payload, uint16_t len, ubx_sats_t* out);
121
122#ifdef __cplusplus
123}
124#endif
125#endif
size_type count(const key_type &key) const
Definition json.hpp:19264
uint32_t value
Definition ubx.h:53
uint32_t key
Definition ubx.h:51
uint8_t size
Definition ubx.h:52
int32_t lon_e7
Definition ubx.h:71
uint8_t min
Definition ubx.h:67
uint16_t pdop_e2
Definition ubx.h:76
uint8_t valid
Definition ubx.h:67
uint32_t sacc_mms
Definition ubx.h:75
int32_t lat_e7
Definition ubx.h:71
uint8_t fix_type
Definition ubx.h:68
int32_t vel_n_mms
Definition ubx.h:74
uint8_t sec
Definition ubx.h:67
uint8_t day
Definition ubx.h:67
int32_t vel_d_mms
Definition ubx.h:74
uint32_t hacc_mm
Definition ubx.h:73
int32_t hmsl_mm
Definition ubx.h:72
uint8_t month
Definition ubx.h:67
uint8_t hour
Definition ubx.h:67
uint16_t year
Definition ubx.h:66
uint8_t num_sv
Definition ubx.h:70
int32_t height_mm
Definition ubx.h:72
uint32_t itow_ms
Definition ubx.h:65
int32_t vel_e_mms
Definition ubx.h:74
uint8_t flags
Definition ubx.h:69
uint32_t vacc_mm
Definition ubx.h:73
Definition ubx.h:96
uint8_t jamming
Definition ubx.h:99
uint8_t ant_power
Definition ubx.h:98
uint8_t ant_status
Definition ubx.h:97
uint16_t agc
Definition ubx.h:102
uint8_t cw
Definition ubx.h:100
uint16_t noise
Definition ubx.h:101
uint8_t used
Definition ubx.h:116
uint8_t best_cno
Definition ubx.h:117
uint8_t locked
Definition ubx.h:115
uint8_t with_signal
Definition ubx.h:114
uint8_t listed
Definition ubx.h:112
uint8_t seen
Definition ubx.h:113
bool ubx_parse_nav_pvt(const uint8_t *payload, uint16_t len, ubx_pvt_t *out)
Definition ubx.c:66
size_t ubx_valset(uint8_t *out, size_t cap, const ubx_item_t *items, size_t count)
Definition ubx.c:30
size_t ubx_frame(uint8_t *out, size_t cap, uint8_t cls, uint8_t id, const uint8_t *payload, uint16_t len)
Definition ubx.c:5
size_t ubx_poll(uint8_t *out, size_t cap, uint8_t cls, uint8_t id)
Definition ubx.c:96
bool ubx_parse_mon_rf(const uint8_t *payload, uint16_t len, ubx_rf_t *out)
Definition ubx.c:104
bool ubx_sat_summary(const uint8_t *payload, uint16_t len, ubx_sats_t *out)
Definition ubx.c:119