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
UBLOXCFG_SIZE_FOUR
@ UBLOXCFG_SIZE_FOUR
Four bytes.
Definition: ubloxcfg.h:49
UBLOXCFG_CONST_s::value
const char * value
Value as string.
Definition: ubloxcfg.h:104
UBLOXCFG_MSGRATE_s::msgName
const char * msgName
Message name.
Definition: ubloxcfg.h:131
UBLOXCFG_TYPE_L
@ UBLOXCFG_TYPE_L
One bit logical (0 = false, 1 = true)
Definition: ubloxcfg.h:96
UBLOXCFG_VALUE_u::I4
int32_t I4
UBLOXCFG_TYPE_I4 type value
Definition: ubloxcfg.h:218
UBLOXCFG_TYPE_X4
@ UBLOXCFG_TYPE_X4
Four bytes unsigned, little-endian (uint32_t)
Definition: ubloxcfg.h:89
UBLOXCFG_SIZE_TWO
@ UBLOXCFG_SIZE_TWO
Two bytes.
Definition: ubloxcfg.h:48
UBLOXCFG_VALUE_u::X2
uint16_t X2
UBLOXCFG_TYPE_X2 type value
Definition: ubloxcfg.h:221
UBLOXCFG_LAYER_FLASH
@ UBLOXCFG_LAYER_FLASH
Flash layer.
Definition: ubloxcfg.h:185
UBLOXCFG_ITEM_s::scalefact
double scalefact
Scale factor as number.
Definition: ubloxcfg.h:124
UBLOXCFG_CONST_s::E
int32_t E
E type value as number.
Definition: ubloxcfg.h:107
UBLOXCFG_ITEM_s::scale
const char * scale
Scale factor as string (or NULL)
Definition: ubloxcfg.h:121
UBLOXCFG_SIZE_t
enum UBLOXCFG_SIZE_e UBLOXCFG_SIZE_t
Configuration item size.
ubloxcfg_splitValueStr
bool ubloxcfg_splitValueStr(char *str, char **valueStr, char **prettyStr)
Split stringified value string.
Definition: ubloxcfg.c:549
UBLOXCFG_TYPE_t
enum UBLOXCFG_TYPE_e UBLOXCFG_TYPE_t
Configuration item storage type (s.a. UBLOXCFG_VALUE_t)
UBLOXCFG_TYPE_I4
@ UBLOXCFG_TYPE_I4
Four bytes signed, little-endian (int32_t)
Definition: ubloxcfg.h:85
ubloxcfg_getMsgRateCfg
const UBLOXCFG_MSGRATE_t * ubloxcfg_getMsgRateCfg(const char *msgName)
Get configuration items for output message rate configuration.
Definition: ubloxcfg.c:95
UBLOXCFG_TYPE_U4
@ UBLOXCFG_TYPE_U4
Four bytes unsigned, little-endian (uint32_t)
Definition: ubloxcfg.h:81
UBLOXCFG_LAYER_t
enum UBLOXCFG_LAYER_e UBLOXCFG_LAYER_t
Configuration layers.
UBLOXCFG_VALUE_u::U8
uint64_t U8
UBLOXCFG_TYPE_U8 type value
Definition: ubloxcfg.h:215
UBLOXCFG_VALUE_u::R8
double R8
UBLOXCFG_TYPE_R8 type value
Definition: ubloxcfg.h:225
UBLOXCFG_TYPE_I2
@ UBLOXCFG_TYPE_I2
Two bytes signed, little-endian (int16_t)
Definition: ubloxcfg.h:84
UBLOXCFG_TYPE_E1
@ UBLOXCFG_TYPE_E1
One byte unsigned, little-endian (int8_t)
Definition: ubloxcfg.h:93
UBLOXCFG_VALUE_u::E4
int32_t E4
UBLOXCFG_TYPE_E4 type value
Definition: ubloxcfg.h:228
UBLOXCFG_TYPE_U8
@ UBLOXCFG_TYPE_U8
Eight bytes unsigned, little-endian (uint64_t)
Definition: ubloxcfg.h:82
UBLOXCFG_VALUE_u::I8
int64_t I8
UBLOXCFG_TYPE_I8 type value
Definition: ubloxcfg.h:219
UBLOXCFG_VALUE_u::X8
uint64_t X8
UBLOXCFG_TYPE_X8 type value
Definition: ubloxcfg.h:223
UBLOXCFG_VALUE_u::X1
uint8_t X1
UBLOXCFG_TYPE_X1 type value
Definition: ubloxcfg.h:220
UBLOXCFG_MSGRATE_s::itemI2c
const UBLOXCFG_ITEM_t * itemI2c
Item for output rate on I2C port (or NULL)
Definition: ubloxcfg.h:135
UBLOXCFG_TYPE_X8
@ UBLOXCFG_TYPE_X8
Eight bytes unsigned, little-endian (uint64_t)
Definition: ubloxcfg.h:90
UBLOXCFG_CONST_s::title
const char * title
Title.
Definition: ubloxcfg.h:103
UBLOXCFG_VALUE_u::_bytes
uint8_t _bytes[8]
raw bytes, unused bytes shall be 0x00
Definition: ubloxcfg.h:230
UBLOXCFG_TYPE_E2
@ UBLOXCFG_TYPE_E2
Two bytes unsigned, little-endian (int16_t)
Definition: ubloxcfg.h:94
UBLOXCFG_ITEM_s::name
const char * name
Item name.
Definition: ubloxcfg.h:118
UBLOXCFG_CONST_s::name
const char * name
Name of the constant.
Definition: ubloxcfg.h:102
UBLOXCFG_LAYER_DEFAULT
@ UBLOXCFG_LAYER_DEFAULT
Default layer.
Definition: ubloxcfg.h:186
UBLOXCFG_ITEM_s::order
int order
Ordering.
Definition: ubloxcfg.h:125
UBLOXCFG_VALUE_u::L
bool L
UBLOXCFG_TYPE_L type value
Definition: ubloxcfg.h:229
UBLOXCFG_VALUE_u::_raw
uint64_t _raw
raw value, unused bytes shall be 0x00
Definition: ubloxcfg.h:231
UBLOXCFG_ITEM_t
struct UBLOXCFG_ITEM_s UBLOXCFG_ITEM_t
Configuration item.
UBLOXCFG_VALUE_u::R4
float R4
UBLOXCFG_TYPE_R4 type value
Definition: ubloxcfg.h:224
UBLOXCFG_KEYVAL_s
Key-value pair.
Definition: ubloxcfg.h:235
ubloxcfg_getAllMsgRateCfgs
const UBLOXCFG_MSGRATE_t ** ubloxcfg_getAllMsgRateCfgs(int *num)
Get list of all output message rate configurations.
Definition: ubloxcfg.c:114
UBLOXCFG_MSGRATE_s
Configuration items for output message rate configuration.
Definition: ubloxcfg.h:129
UBLOXCFG_MSGRATE_s::itemUsb
const UBLOXCFG_ITEM_t * itemUsb
Item for output rate on USB port (or NULL)
Definition: ubloxcfg.h:136
ubloxcfg_getAllItems
const UBLOXCFG_ITEM_t ** ubloxcfg_getAllItems(int *num)
Get list of all items.
Definition: ubloxcfg.c:89
UBLOXCFG_VALUE_u::U2
uint16_t U2
UBLOXCFG_TYPE_U2 type value
Definition: ubloxcfg.h:213
UBLOXCFG_ITEM_s::nConsts
int nConsts
Number of constants (or 0 if none)
Definition: ubloxcfg.h:123
UBLOXCFG_SIZE_BIT
@ UBLOXCFG_SIZE_BIT
One bit.
Definition: ubloxcfg.h:46
UBLOXCFG_VALUE_u::I1
int8_t I1
UBLOXCFG_TYPE_I1 type value
Definition: ubloxcfg.h:216
UBLOXCFG_TYPE_I8
@ UBLOXCFG_TYPE_I8
Eight byte signed, little-endian (int64_t)
Definition: ubloxcfg.h:86
UBLOXCFG_MSGRATE_s::itemSpi
const UBLOXCFG_ITEM_t * itemSpi
Item for output rate on SPI port (or NULL)
Definition: ubloxcfg.h:134
UBLOXCFG_ITEM_s::unit
const char * unit
Unit (or NULL)
Definition: ubloxcfg.h:120
UBLOXCFG_TYPE_U1
@ UBLOXCFG_TYPE_U1
One byte unsigned, little-endian (uint8_t)
Definition: ubloxcfg.h:79
ubloxcfg_typeStr
const char * ubloxcfg_typeStr(UBLOXCFG_TYPE_t type)
Stringify item type.
Definition: ubloxcfg.c:336
UBLOXCFG_TYPE_E4
@ UBLOXCFG_TYPE_E4
Four bytes unsigned, little-endian (int32_t)
Definition: ubloxcfg.h:95
UBLOXCFG_VALUE_u
Configuration value storage (s.a. UBLOXCFG_TYPE_t)
Definition: ubloxcfg.h:210
UBLOXCFG_KEYVAL_t
struct UBLOXCFG_KEYVAL_s UBLOXCFG_KEYVAL_t
Key-value pair.
UBLOXCFG_VALUE_t
union UBLOXCFG_VALUE_u UBLOXCFG_VALUE_t
Configuration value storage (s.a. UBLOXCFG_TYPE_t)
UBLOXCFG_CONST_s::X
uint64_t X
X type value as number.
Definition: ubloxcfg.h:108
UBLOXCFG_LAYER_BBR
@ UBLOXCFG_LAYER_BBR
BBR layer.
Definition: ubloxcfg.h:184
UBLOXCFG_CONST_s
Constants for type E1/E2/E4 configuration items.
Definition: ubloxcfg.h:100
ubloxcfg_layerFromName
bool ubloxcfg_layerFromName(const char *name, UBLOXCFG_LAYER_t *layer)
Get layer from name.
Definition: ubloxcfg.c:1138
UBLOXCFG_ITEM_s::id
uint32_t id
Item ID.
Definition: ubloxcfg.h:115
ubloxcfg_getSources
const char ** ubloxcfg_getSources(int *numSources)
Get strings describing the data sources.
Definition: ubloxcfg.c:1184
ubloxcfg_stringifyKeyVal
bool ubloxcfg_stringifyKeyVal(char *str, const int size, const UBLOXCFG_KEYVAL_t *keyVal)
Stringify key-value pair (for debugging)
Definition: ubloxcfg.c:575
ubloxcfg_makeData
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:120
UBLOXCFG_SIZE_EIGHT
@ UBLOXCFG_SIZE_EIGHT
Eight bytes.
Definition: ubloxcfg.h:50
UBLOXCFG_KEYVAL_s::id
uint32_t id
Configuration item ID.
Definition: ubloxcfg.h:237
ubloxcfg_stringifyValue
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:362
UBLOXCFG_VALUE_u::E1
int8_t E1
UBLOXCFG_TYPE_E1 type value
Definition: ubloxcfg.h:226
UBLOXCFG_VALUE_u::X4
uint32_t X4
UBLOXCFG_TYPE_X4 type value
Definition: ubloxcfg.h:222
UBLOXCFG_TYPE_X2
@ UBLOXCFG_TYPE_X2
Two bytes unsigned, little-endian (uint16_t)
Definition: ubloxcfg.h:88
ubloxcfg_getItemById
const UBLOXCFG_ITEM_t * ubloxcfg_getItemById(const uint32_t id)
Get configuration item info by key ID.
Definition: ubloxcfg.c:74
UBLOXCFG_SIZE_ONE
@ UBLOXCFG_SIZE_ONE
One byte.
Definition: ubloxcfg.h:47
UBLOXCFG_LAYER_e
UBLOXCFG_LAYER_e
Configuration layers.
Definition: ubloxcfg.h:181
UBLOXCFG_ITEM_s::type
UBLOXCFG_TYPE_t type
Storage type.
Definition: ubloxcfg.h:116
UBLOXCFG_VALUE_u::I2
int16_t I2
UBLOXCFG_TYPE_I2 type value
Definition: ubloxcfg.h:217
UBLOXCFG_ITEM_s::consts
const UBLOXCFG_CONST_t * consts
Constants (or NULL if none)
Definition: ubloxcfg.h:122
UBLOXCFG_CONST_t
struct UBLOXCFG_CONST_s UBLOXCFG_CONST_t
Constants for type E1/E2/E4 configuration items.
UBLOXCFG_MSGRATE_t
struct UBLOXCFG_MSGRATE_s UBLOXCFG_MSGRATE_t
Configuration items for output message rate configuration.
UBLOXCFG_TYPE_I1
@ UBLOXCFG_TYPE_I1
One byte signed, little-endian (int8_t)
Definition: ubloxcfg.h:83
UBLOXCFG_VALUE_u::U4
uint32_t U4
UBLOXCFG_TYPE_U4 type value
Definition: ubloxcfg.h:214
UBLOXCFG_VALUE_u::U1
uint8_t U1
UBLOXCFG_TYPE_U1 type value
Definition: ubloxcfg.h:212
UBLOXCFG_TYPE_R4
@ UBLOXCFG_TYPE_R4
Four bytes IEEE754 single precision (float)
Definition: ubloxcfg.h:91
UBLOXCFG_SIZE_e
UBLOXCFG_SIZE_e
Configuration item size.
Definition: ubloxcfg.h:44
UBLOXCFG_KEYVAL_s::val
UBLOXCFG_VALUE_t val
Configuration item value.
Definition: ubloxcfg.h:238
ubloxcfg_valueFromString
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:675
UBLOXCFG_ITEM_s::size
UBLOXCFG_SIZE_t size
Item size.
Definition: ubloxcfg.h:117
UBLOXCFG_TYPE_e
UBLOXCFG_TYPE_e
Configuration item storage type (s.a. UBLOXCFG_VALUE_t)
Definition: ubloxcfg.h:77
UBLOXCFG_MSGRATE_s::itemUart2
const UBLOXCFG_ITEM_t * itemUart2
Item for output rate on UART2 port (or NULL)
Definition: ubloxcfg.h:133
UBLOXCFG_TYPE_U2
@ UBLOXCFG_TYPE_U2
Two bytes unsigned, little-endian (uint16_t)
Definition: ubloxcfg.h:80
UBLOXCFG_TYPE_X1
@ UBLOXCFG_TYPE_X1
One byte unsigned, little-endian (uint8_t)
Definition: ubloxcfg.h:87
UBLOXCFG_VALUE_u::E2
int16_t E2
UBLOXCFG_TYPE_E2 type value
Definition: ubloxcfg.h:227
UBLOXCFG_ITEM_s::title
const char * title
Title.
Definition: ubloxcfg.h:119
ubloxcfg_getVersion
uint16_t ubloxcfg_getVersion(void)
Get library version.
Definition: ubloxcfg.c:1179
UBLOXCFG_CONST_s::val
union UBLOXCFG_CONST_s::@0 val
Value.
UBLOXCFG_LAYER_RAM
@ UBLOXCFG_LAYER_RAM
RAM layer (a.k.a. current configuration)
Definition: ubloxcfg.h:183
UBLOXCFG_MSGRATE_s::itemUart1
const UBLOXCFG_ITEM_t * itemUart1
Item for output rate on UART1 port (or NULL)
Definition: ubloxcfg.h:132
ubloxcfg_parseData
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:214
ubloxcfg_getItemByName
const UBLOXCFG_ITEM_t * ubloxcfg_getItemByName(const char *name)
Get configuration item info by name.
Definition: ubloxcfg.c:41
ubloxcfg_layerName
const char * ubloxcfg_layerName(const UBLOXCFG_LAYER_t layer)
Get name for layer.
Definition: ubloxcfg.c:1126
UBLOXCFG_TYPE_R8
@ UBLOXCFG_TYPE_R8
Eight bytes IEEE754 double precision (double)
Definition: ubloxcfg.h:92
UBLOXCFG_ITEM_s
Configuration item.
Definition: ubloxcfg.h:113