ubloxcfg
u-blox 9 configuration helpers
ubloxcfg.h
Go to the documentation of this file.
1 /* ************************************************************************************************/ // clang-format off
24 #ifndef __UBLOXCFG_H__
25 #define __UBLOXCFG_H__
26 
27 #include <stdint.h>
28 #include <stdbool.h>
29 
30 #include "ubloxcfg_gen.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /* ****************************************************************************************************************** */
37 
43 typedef enum UBLOXCFG_SIZE_e
45 {
52 
54 
60 #define UBLOXCFG_ID2SIZE(id) (UBLOXCFG_SIZE_t)(((id) >> 28) & 0x0f)
61 
63 
67 #define UBLOXCFG_ID2GROUP(id) ((id) & 0x0fff0000)
68 
70 
74 #define UBLOXCFG_ID2IDGRP(id) ((id) & 0x0000ffff)
75 
77 typedef enum UBLOXCFG_TYPE_e
78 {
98 
100 typedef struct UBLOXCFG_CONST_s
101 {
102  const char *name;
103  const char *title;
104  const char *value;
105  union
106  {
107  int32_t E;
108  uint64_t X;
109  } val;
111 
113 typedef struct UBLOXCFG_ITEM_s
114 {
115  uint32_t id;
118  const char *name;
119  const char *title;
120  const char *unit;
121  const char *scale;
123  int nConsts;
124  double scalefact;
125  int order;
127 
129 typedef struct UBLOXCFG_MSGRATE_s
130 {
131  const char *msgName;
138 
140 
146 const UBLOXCFG_ITEM_t *ubloxcfg_getItemByName(const char *name);
147 
149 
154 const UBLOXCFG_ITEM_t *ubloxcfg_getItemById(const uint32_t id);
155 
157 
162 const UBLOXCFG_ITEM_t **ubloxcfg_getAllItems(int *num);
163 
165 
170 const UBLOXCFG_MSGRATE_t *ubloxcfg_getMsgRateCfg(const char *msgName);
171 
173 
179 
181 typedef enum UBLOXCFG_LAYER_e
182 {
188 
190 const char *ubloxcfg_layerName(const UBLOXCFG_LAYER_t layer);
191 
193 
198 bool ubloxcfg_layerFromName(const char *name, UBLOXCFG_LAYER_t *layer);
199 
201 
202 /* ****************************************************************************************************************** */
203 
209 typedef union UBLOXCFG_VALUE_u
211 {
212  uint8_t U1;
213  uint16_t U2;
214  uint32_t U4;
215  uint64_t U8;
216  int8_t I1;
217  int16_t I2;
218  int32_t I4;
219  int64_t I8;
220  uint8_t X1;
221  uint16_t X2;
222  uint32_t X4;
223  uint64_t X8;
224  float R4;
225  double R8;
226  int8_t E1;
227  int16_t E2;
228  int32_t E4;
229  bool L;
230  uint8_t _bytes[8];
231  uint64_t _raw;
233 
235 typedef struct UBLOXCFG_KEYVAL_s
236 {
237  uint32_t id;
240 
242 
257 #define UBLOXCFG_KEYVAL_ANY(name, value) { .id = UBLOXCFG_ ## name ## _ID, .val = { .UBLOXCFG_ ## name ## _TYPE = (value) } }
258 
260 
275 #define UBLOXCFG_KEYVAL_ENU(name, value) { .id = UBLOXCFG_ ## name ## _ID, .val = { .UBLOXCFG_ ## name ## _TYPE = (UBLOXCFG_ ## name ## _ ## value) } }
276 
278 
298 #define UBLOXCFG_KEYVAL_MSG(msg, port, rate) UBLOXCFG_KEYVAL_ANY(msg ## _ ## port, rate)
299 
301 
342 bool ubloxcfg_makeData(uint8_t *data, const int size, const UBLOXCFG_KEYVAL_t *keyVal, const int nKeyVal, int *dataSize);
343 
345 
386 bool ubloxcfg_parseData(const uint8_t *data, const int size, UBLOXCFG_KEYVAL_t *keyVal, const int maxKeyVal, int *nKeyVal);
387 
389 
394 const char *ubloxcfg_typeStr(UBLOXCFG_TYPE_t type);
395 
397 
426 bool ubloxcfg_stringifyValue(char *str, const int size, const UBLOXCFG_TYPE_t type, const UBLOXCFG_ITEM_t *item, const UBLOXCFG_VALUE_t *val);
427 
429 
439 bool ubloxcfg_splitValueStr(char *str, char **valueStr, char **prettyStr);
440 
442 
486 bool ubloxcfg_stringifyKeyVal(char *str, const int size, const UBLOXCFG_KEYVAL_t *keyVal);
487 
489 #define UBLOXCFG_MAX_KEYVAL_STR_SIZE (_UBLOXCFG_MAX_ITEM_LEN + /* "CFG-LOOOOONG-NAME" (item name) */ \
490  20 + /* " (0x........, XX) = " (item Id and type) */ \
491  21 + /* "0x................ ()" (X8) */ \
492  _UBLOXCFG_MAX_CONSTS_LEN + /* "FIRST|LAST|BLA" (all defined constants) */ \
493  19 + /* "|0x................" (remaining bits X8) */ \
494  10)
495 
497 
535 bool ubloxcfg_valueFromString(const char *str, const UBLOXCFG_TYPE_t type, const UBLOXCFG_ITEM_t *item, UBLOXCFG_VALUE_t *value);
536 
538 
539 /* ****************************************************************************************************************** */
540 
546 
551 uint16_t ubloxcfg_getVersion(void);
552 
553 
555 /*
556  \param[out] numSources Number of sources strings returned
557  \returns a list of strings that each name a source of the data
558 */
559 const char **ubloxcfg_getSources(int *numSources);
560 
562 
563 /* ****************************************************************************************************************** */
564 #ifdef __cplusplus
565 }
566 #endif
567 #endif // __UBLOXCFG_H__
568 // eof
const char * unit
Unit (or NULL)
Definition: ubloxcfg.h:120
Four bytes.
Definition: ubloxcfg.h:49
const UBLOXCFG_ITEM_t * ubloxcfg_getItemByName(const char *name)
Get configuration item info by name.
Definition: ubloxcfg.c:36
UBLOXCFG_TYPE_t type
Storage type.
Definition: ubloxcfg.h:116
int16_t I2
UBLOXCFG_TYPE_I2 type value
Definition: ubloxcfg.h:217
int16_t E2
UBLOXCFG_TYPE_E2 type value
Definition: ubloxcfg.h:227
Two bytes signed, little-endian (int16_t)
Definition: ubloxcfg.h:84
const UBLOXCFG_CONST_t * consts
Constants (or NULL if none)
Definition: ubloxcfg.h:122
Four bytes unsigned, little-endian (int32_t)
Definition: ubloxcfg.h:95
One bit logical (0 = false, 1 = true)
Definition: ubloxcfg.h:96
Two bytes unsigned, little-endian (uint16_t)
Definition: ubloxcfg.h:80
bool ubloxcfg_splitValueStr(char *str, char **valueStr, char **prettyStr)
Split stringified value string.
Definition: ubloxcfg.c:544
Configuration value storage (s.a. UBLOXCFG_TYPE_t)
Definition: ubloxcfg.h:210
UBLOXCFG_SIZE_t size
Item size.
Definition: ubloxcfg.h:117
const UBLOXCFG_MSGRATE_t * ubloxcfg_getMsgRateCfg(const char *msgName)
Get configuration items for output message rate configuration.
Definition: ubloxcfg.c:90
RAM layer (a.k.a. current configuration)
Definition: ubloxcfg.h:183
BBR layer.
Definition: ubloxcfg.h:184
Eight bytes unsigned, little-endian (uint64_t)
Definition: ubloxcfg.h:90
uint32_t X4
UBLOXCFG_TYPE_X4 type value
Definition: ubloxcfg.h:222
const UBLOXCFG_ITEM_t * itemUsb
Item for output rate on USB port (or NULL)
Definition: ubloxcfg.h:136
Four bytes unsigned, little-endian (uint32_t)
Definition: ubloxcfg.h:81
bool L
UBLOXCFG_TYPE_L type value
Definition: ubloxcfg.h:229
union UBLOXCFG_VALUE_u UBLOXCFG_VALUE_t
Configuration value storage (s.a. UBLOXCFG_TYPE_t)
Four bytes signed, little-endian (int32_t)
Definition: ubloxcfg.h:85
const char * value
Value as string.
Definition: ubloxcfg.h:104
const char * msgName
Message name.
Definition: ubloxcfg.h:131
enum UBLOXCFG_SIZE_e UBLOXCFG_SIZE_t
Configuration item size.
One bit.
Definition: ubloxcfg.h:46
struct UBLOXCFG_ITEM_s UBLOXCFG_ITEM_t
Configuration item.
Eight bytes unsigned, little-endian (uint64_t)
Definition: ubloxcfg.h:82
uint16_t X2
UBLOXCFG_TYPE_X2 type value
Definition: ubloxcfg.h:221
const char ** ubloxcfg_getSources(int *numSources)
Get strings describing the data sources.
Definition: ubloxcfg.c:1182
const UBLOXCFG_ITEM_t * itemI2c
Item for output rate on I2C port (or NULL)
Definition: ubloxcfg.h:135
const UBLOXCFG_ITEM_t * itemUart1
Item for output rate on UART1 port (or NULL)
Definition: ubloxcfg.h:132
int64_t I8
UBLOXCFG_TYPE_I8 type value
Definition: ubloxcfg.h:219
uint32_t id
Item ID.
Definition: ubloxcfg.h:115
Default layer.
Definition: ubloxcfg.h:186
int8_t E1
UBLOXCFG_TYPE_E1 type value
Definition: ubloxcfg.h:226
const char * name
Name of the constant.
Definition: ubloxcfg.h:102
Eight byte signed, little-endian (int64_t)
Definition: ubloxcfg.h:86
const UBLOXCFG_MSGRATE_t ** ubloxcfg_getAllMsgRateCfgs(int *num)
Get list of all output message rate configurations.
Definition: ubloxcfg.c:109
uint8_t X1
UBLOXCFG_TYPE_X1 type value
Definition: ubloxcfg.h:220
uint8_t U1
UBLOXCFG_TYPE_U1 type value
Definition: ubloxcfg.h:212
One byte unsigned, little-endian (uint8_t)
Definition: ubloxcfg.h:87
struct UBLOXCFG_KEYVAL_s UBLOXCFG_KEYVAL_t
Key-value pair.
uint16_t U2
UBLOXCFG_TYPE_U2 type value
Definition: ubloxcfg.h:213
const UBLOXCFG_ITEM_t ** ubloxcfg_getAllItems(int *num)
Get list of all items.
Definition: ubloxcfg.c:84
Configuration item.
Definition: ubloxcfg.h:113
Configuration items for output message rate configuration.
Definition: ubloxcfg.h:129
const UBLOXCFG_ITEM_t * itemUart2
Item for output rate on UART2 port (or NULL)
Definition: ubloxcfg.h:133
const char * ubloxcfg_typeStr(UBLOXCFG_TYPE_t type)
Stringify item type.
Definition: ubloxcfg.c:331
Eight bytes IEEE754 double precision (double)
Definition: ubloxcfg.h:92
double scalefact
Scale factor as number.
Definition: ubloxcfg.h:124
Eight bytes.
Definition: ubloxcfg.h:50
Flash layer.
Definition: ubloxcfg.h:185
uint32_t U4
UBLOXCFG_TYPE_U4 type value
Definition: ubloxcfg.h:214
Constants for type E1/E2/E4 configuration items.
Definition: ubloxcfg.h:100
const char * title
Title.
Definition: ubloxcfg.h:119
enum UBLOXCFG_TYPE_e UBLOXCFG_TYPE_t
Configuration item storage type (s.a. UBLOXCFG_VALUE_t)
Key-value pair.
Definition: ubloxcfg.h:235
bool ubloxcfg_makeData(uint8_t *data, const int size, const UBLOXCFG_KEYVAL_t *keyVal, const int nKeyVal, int *dataSize)
Configuration data from key-value list.
Definition: ubloxcfg.c:115
int8_t I1
UBLOXCFG_TYPE_I1 type value
Definition: ubloxcfg.h:216
int nConsts
Number of constants (or 0 if none)
Definition: ubloxcfg.h:123
One byte unsigned, little-endian (int8_t)
Definition: ubloxcfg.h:93
Four bytes IEEE754 single precision (float)
Definition: ubloxcfg.h:91
bool ubloxcfg_stringifyValue(char *str, const int size, const UBLOXCFG_TYPE_t type, const UBLOXCFG_ITEM_t *item, const UBLOXCFG_VALUE_t *val)
Stringify item value.
Definition: ubloxcfg.c:357
uint32_t id
Configuration item ID.
Definition: ubloxcfg.h:237
float R4
UBLOXCFG_TYPE_R4 type value
Definition: ubloxcfg.h:224
bool ubloxcfg_layerFromName(const char *name, UBLOXCFG_LAYER_t *layer)
Get layer from name.
Definition: ubloxcfg.c:1132
uint16_t ubloxcfg_getVersion(void)
Get library version.
Definition: ubloxcfg.c:1173
union UBLOXCFG_CONST_s::@0 val
Value.
const UBLOXCFG_ITEM_t * ubloxcfg_getItemById(const uint32_t id)
Get configuration item info by key ID.
Definition: ubloxcfg.c:69
const char * title
Title.
Definition: ubloxcfg.h:103
bool ubloxcfg_stringifyKeyVal(char *str, const int size, const UBLOXCFG_KEYVAL_t *keyVal)
Stringify key-value pair (for debugging)
Definition: ubloxcfg.c:570
UBLOXCFG_VALUE_t val
Configuration item value.
Definition: ubloxcfg.h:238
struct UBLOXCFG_MSGRATE_s UBLOXCFG_MSGRATE_t
Configuration items for output message rate configuration.
One byte unsigned, little-endian (uint8_t)
Definition: ubloxcfg.h:79
One byte.
Definition: ubloxcfg.h:47
int32_t E4
UBLOXCFG_TYPE_E4 type value
Definition: ubloxcfg.h:228
int32_t E
E type value as number.
Definition: ubloxcfg.h:107
Four bytes unsigned, little-endian (uint32_t)
Definition: ubloxcfg.h:89
int32_t I4
UBLOXCFG_TYPE_I4 type value
Definition: ubloxcfg.h:218
const UBLOXCFG_ITEM_t * itemSpi
Item for output rate on SPI port (or NULL)
Definition: ubloxcfg.h:134
One byte signed, little-endian (int8_t)
Definition: ubloxcfg.h:83
uint64_t _raw
raw value
Definition: ubloxcfg.h:231
enum UBLOXCFG_LAYER_e UBLOXCFG_LAYER_t
Configuration layers.
UBLOXCFG_LAYER_e
Configuration layers.
Definition: ubloxcfg.h:181
const char * scale
Scale factor as string (or NULL)
Definition: ubloxcfg.h:121
double R8
UBLOXCFG_TYPE_R8 type value
Definition: ubloxcfg.h:225
UBLOXCFG_TYPE_e
Configuration item storage type (s.a. UBLOXCFG_VALUE_t)
Definition: ubloxcfg.h:77
uint64_t X
X type value as number.
Definition: ubloxcfg.h:108
const char * name
Item name.
Definition: ubloxcfg.h:118
Two bytes unsigned, little-endian (int16_t)
Definition: ubloxcfg.h:94
bool ubloxcfg_parseData(const uint8_t *data, const int size, UBLOXCFG_KEYVAL_t *keyVal, const int maxKeyVal, int *nKeyVal)
Key-value list from configuration data.
Definition: ubloxcfg.c:209
UBLOXCFG_SIZE_e
Configuration item size.
Definition: ubloxcfg.h:44
Two bytes.
Definition: ubloxcfg.h:48
const char * ubloxcfg_layerName(const UBLOXCFG_LAYER_t layer)
Get name for layer.
Definition: ubloxcfg.c:1120
bool ubloxcfg_valueFromString(const char *str, const UBLOXCFG_TYPE_t type, const UBLOXCFG_ITEM_t *item, UBLOXCFG_VALUE_t *value)
Convert string to value.
Definition: ubloxcfg.c:670
uint8_t _bytes[8]
raw bytes
Definition: ubloxcfg.h:230
Two bytes unsigned, little-endian (uint16_t)
Definition: ubloxcfg.h:88
uint64_t X8
UBLOXCFG_TYPE_X8 type value
Definition: ubloxcfg.h:223
uint64_t U8
UBLOXCFG_TYPE_U8 type value
Definition: ubloxcfg.h:215
struct UBLOXCFG_CONST_s UBLOXCFG_CONST_t
Constants for type E1/E2/E4 configuration items.
int order
Ordering.
Definition: ubloxcfg.h:125