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
33extern "C" {
34#endif
35
36/* ****************************************************************************************************************** */
37
44typedef 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
77typedef enum UBLOXCFG_TYPE_e
78{
98
100typedef 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
113typedef 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;
124 double scalefact;
125 int order;
127
129typedef struct UBLOXCFG_MSGRATE_s
130{
131 const char *msgName;
138
140
146const UBLOXCFG_ITEM_t *ubloxcfg_getItemByName(const char *name);
147
149
154const UBLOXCFG_ITEM_t *ubloxcfg_getItemById(const uint32_t id);
155
157
162const UBLOXCFG_ITEM_t **ubloxcfg_getAllItems(int *num);
163
165
170const UBLOXCFG_MSGRATE_t *ubloxcfg_getMsgRateCfg(const char *msgName);
171
173
179
182{
188
190const char *ubloxcfg_layerName(const UBLOXCFG_LAYER_t layer);
191
193
198bool ubloxcfg_layerFromName(const char *name, UBLOXCFG_LAYER_t *layer);
199
201
202/* ****************************************************************************************************************** */
203
210typedef 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
235typedef 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
342bool ubloxcfg_makeData(uint8_t *data, const int size, const UBLOXCFG_KEYVAL_t *keyVal, const int nKeyVal, int *dataSize);
343
345
386bool ubloxcfg_parseData(const uint8_t *data, const int size, UBLOXCFG_KEYVAL_t *keyVal, const int maxKeyVal, int *nKeyVal);
387
389
394const char *ubloxcfg_typeStr(UBLOXCFG_TYPE_t type);
395
397
426bool ubloxcfg_stringifyValue(char *str, const int size, const UBLOXCFG_TYPE_t type, const UBLOXCFG_ITEM_t *item, const UBLOXCFG_VALUE_t *val);
427
429
439bool ubloxcfg_splitValueStr(char *str, char **valueStr, char **prettyStr);
440
442
486bool 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
535bool ubloxcfg_valueFromString(const char *str, const UBLOXCFG_TYPE_t type, const UBLOXCFG_ITEM_t *item, UBLOXCFG_VALUE_t *value);
536
538
539/* ****************************************************************************************************************** */
540
547
551uint16_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*/
559const char **ubloxcfg_getSources(int *numSources);
560
562
563/* ****************************************************************************************************************** */
564#ifdef __cplusplus
565}
566#endif
567#endif // __UBLOXCFG_H__
569// eof
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
const char * ubloxcfg_typeStr(UBLOXCFG_TYPE_t type)
Stringify item type.
Definition: ubloxcfg.c:336
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
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
struct UBLOXCFG_KEYVAL_s UBLOXCFG_KEYVAL_t
Key-value pair.
bool ubloxcfg_splitValueStr(char *str, char **valueStr, char **prettyStr)
Split stringified value string.
Definition: ubloxcfg.c:549
union UBLOXCFG_VALUE_u UBLOXCFG_VALUE_t
Configuration value storage (s.a. UBLOXCFG_TYPE_t)
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
bool ubloxcfg_stringifyKeyVal(char *str, const int size, const UBLOXCFG_KEYVAL_t *keyVal)
Stringify key-value pair (for debugging)
Definition: ubloxcfg.c:575
enum UBLOXCFG_SIZE_e UBLOXCFG_SIZE_t
Configuration item size.
const UBLOXCFG_ITEM_t * ubloxcfg_getItemByName(const char *name)
Get configuration item info by name.
Definition: ubloxcfg.c:41
struct UBLOXCFG_ITEM_s UBLOXCFG_ITEM_t
Configuration item.
const UBLOXCFG_MSGRATE_t * ubloxcfg_getMsgRateCfg(const char *msgName)
Get configuration items for output message rate configuration.
Definition: ubloxcfg.c:95
struct UBLOXCFG_MSGRATE_s UBLOXCFG_MSGRATE_t
Configuration items for output message rate configuration.
struct UBLOXCFG_CONST_s UBLOXCFG_CONST_t
Constants for type E1/E2/E4 configuration items.
const UBLOXCFG_ITEM_t ** ubloxcfg_getAllItems(int *num)
Get list of all items.
Definition: ubloxcfg.c:89
enum UBLOXCFG_LAYER_e UBLOXCFG_LAYER_t
Configuration layers.
bool ubloxcfg_layerFromName(const char *name, UBLOXCFG_LAYER_t *layer)
Get layer from name.
Definition: ubloxcfg.c:1138
const char * ubloxcfg_layerName(const UBLOXCFG_LAYER_t layer)
Get name for layer.
Definition: ubloxcfg.c:1126
const UBLOXCFG_ITEM_t * ubloxcfg_getItemById(const uint32_t id)
Get configuration item info by key ID.
Definition: ubloxcfg.c:74
UBLOXCFG_SIZE_e
Configuration item size.
Definition: ubloxcfg.h:45
UBLOXCFG_LAYER_e
Configuration layers.
Definition: ubloxcfg.h:182
enum UBLOXCFG_TYPE_e UBLOXCFG_TYPE_t
Configuration item storage type (s.a. UBLOXCFG_VALUE_t)
const UBLOXCFG_MSGRATE_t ** ubloxcfg_getAllMsgRateCfgs(int *num)
Get list of all output message rate configurations.
Definition: ubloxcfg.c:114
UBLOXCFG_TYPE_e
Configuration item storage type (s.a. UBLOXCFG_VALUE_t)
Definition: ubloxcfg.h:78
@ UBLOXCFG_SIZE_EIGHT
Eight bytes.
Definition: ubloxcfg.h:50
@ UBLOXCFG_SIZE_ONE
One byte.
Definition: ubloxcfg.h:47
@ UBLOXCFG_SIZE_FOUR
Four bytes.
Definition: ubloxcfg.h:49
@ UBLOXCFG_SIZE_BIT
One bit.
Definition: ubloxcfg.h:46
@ UBLOXCFG_SIZE_TWO
Two bytes.
Definition: ubloxcfg.h:48
@ UBLOXCFG_LAYER_DEFAULT
Default layer.
Definition: ubloxcfg.h:186
@ UBLOXCFG_LAYER_FLASH
Flash layer.
Definition: ubloxcfg.h:185
@ UBLOXCFG_LAYER_RAM
RAM layer (a.k.a. current configuration)
Definition: ubloxcfg.h:183
@ UBLOXCFG_LAYER_BBR
BBR layer.
Definition: ubloxcfg.h:184
@ UBLOXCFG_TYPE_I1
One byte signed, little-endian (int8_t)
Definition: ubloxcfg.h:83
@ UBLOXCFG_TYPE_U8
Eight bytes unsigned, little-endian (uint64_t)
Definition: ubloxcfg.h:82
@ UBLOXCFG_TYPE_X8
Eight bytes unsigned, little-endian (uint64_t)
Definition: ubloxcfg.h:90
@ UBLOXCFG_TYPE_U2
Two bytes unsigned, little-endian (uint16_t)
Definition: ubloxcfg.h:80
@ UBLOXCFG_TYPE_X4
Four bytes unsigned, little-endian (uint32_t)
Definition: ubloxcfg.h:89
@ UBLOXCFG_TYPE_I8
Eight byte signed, little-endian (int64_t)
Definition: ubloxcfg.h:86
@ UBLOXCFG_TYPE_L
One bit logical (0 = false, 1 = true)
Definition: ubloxcfg.h:96
@ UBLOXCFG_TYPE_E2
Two bytes unsigned, little-endian (int16_t)
Definition: ubloxcfg.h:94
@ UBLOXCFG_TYPE_E4
Four bytes unsigned, little-endian (int32_t)
Definition: ubloxcfg.h:95
@ UBLOXCFG_TYPE_I4
Four bytes signed, little-endian (int32_t)
Definition: ubloxcfg.h:85
@ UBLOXCFG_TYPE_I2
Two bytes signed, little-endian (int16_t)
Definition: ubloxcfg.h:84
@ UBLOXCFG_TYPE_X2
Two bytes unsigned, little-endian (uint16_t)
Definition: ubloxcfg.h:88
@ UBLOXCFG_TYPE_R8
Eight bytes IEEE754 double precision (double)
Definition: ubloxcfg.h:92
@ UBLOXCFG_TYPE_R4
Four bytes IEEE754 single precision (float)
Definition: ubloxcfg.h:91
@ UBLOXCFG_TYPE_U1
One byte unsigned, little-endian (uint8_t)
Definition: ubloxcfg.h:79
@ UBLOXCFG_TYPE_X1
One byte unsigned, little-endian (uint8_t)
Definition: ubloxcfg.h:87
@ UBLOXCFG_TYPE_E1
One byte unsigned, little-endian (int8_t)
Definition: ubloxcfg.h:93
@ UBLOXCFG_TYPE_U4
Four bytes unsigned, little-endian (uint32_t)
Definition: ubloxcfg.h:81
uint16_t ubloxcfg_getVersion(void)
Get library version.
Definition: ubloxcfg.c:1179
const char ** ubloxcfg_getSources(int *numSources)
Get strings describing the data sources.
Definition: ubloxcfg.c:1184
Constants for type E1/E2/E4 configuration items.
Definition: ubloxcfg.h:101
union UBLOXCFG_CONST_s::@0 val
Value.
int32_t E
E type value as number.
Definition: ubloxcfg.h:107
const char * name
Name of the constant.
Definition: ubloxcfg.h:102
const char * title
Title.
Definition: ubloxcfg.h:103
uint64_t X
X type value as number.
Definition: ubloxcfg.h:108
const char * value
Value as string.
Definition: ubloxcfg.h:104
Configuration item.
Definition: ubloxcfg.h:114
const char * unit
Unit (or NULL)
Definition: ubloxcfg.h:120
int order
Ordering.
Definition: ubloxcfg.h:125
const char * scale
Scale factor as string (or NULL)
Definition: ubloxcfg.h:121
UBLOXCFG_TYPE_t type
Storage type.
Definition: ubloxcfg.h:116
UBLOXCFG_SIZE_t size
Item size.
Definition: ubloxcfg.h:117
double scalefact
Scale factor as number.
Definition: ubloxcfg.h:124
uint32_t id
Item ID.
Definition: ubloxcfg.h:115
const char * title
Title.
Definition: ubloxcfg.h:119
int nConsts
Number of constants (or 0 if none)
Definition: ubloxcfg.h:123
const char * name
Item name.
Definition: ubloxcfg.h:118
const UBLOXCFG_CONST_t * consts
Constants (or NULL if none)
Definition: ubloxcfg.h:122
Key-value pair.
Definition: ubloxcfg.h:236
UBLOXCFG_VALUE_t val
Configuration item value.
Definition: ubloxcfg.h:238
uint32_t id
Configuration item ID.
Definition: ubloxcfg.h:237
Configuration items for output message rate configuration.
Definition: ubloxcfg.h:130
const UBLOXCFG_ITEM_t * itemSpi
Item for output rate on SPI port (or NULL)
Definition: ubloxcfg.h:134
const UBLOXCFG_ITEM_t * itemUart2
Item for output rate on UART2 port (or NULL)
Definition: ubloxcfg.h:133
const char * msgName
Message name.
Definition: ubloxcfg.h:131
const UBLOXCFG_ITEM_t * itemUsb
Item for output rate on USB port (or NULL)
Definition: ubloxcfg.h:136
const UBLOXCFG_ITEM_t * itemUart1
Item for output rate on UART1 port (or NULL)
Definition: ubloxcfg.h:132
const UBLOXCFG_ITEM_t * itemI2c
Item for output rate on I2C port (or NULL)
Definition: ubloxcfg.h:135
Configuration value storage (s.a. UBLOXCFG_TYPE_t)
Definition: ubloxcfg.h:211
uint16_t U2
UBLOXCFG_TYPE_U2 type value
Definition: ubloxcfg.h:213
int16_t I2
UBLOXCFG_TYPE_I2 type value
Definition: ubloxcfg.h:217
uint32_t X4
UBLOXCFG_TYPE_X4 type value
Definition: ubloxcfg.h:222
double R8
UBLOXCFG_TYPE_R8 type value
Definition: ubloxcfg.h:225
int32_t E4
UBLOXCFG_TYPE_E4 type value
Definition: ubloxcfg.h:228
int8_t E1
UBLOXCFG_TYPE_E1 type value
Definition: ubloxcfg.h:226
uint64_t U8
UBLOXCFG_TYPE_U8 type value
Definition: ubloxcfg.h:215
int8_t I1
UBLOXCFG_TYPE_I1 type value
Definition: ubloxcfg.h:216
uint32_t U4
UBLOXCFG_TYPE_U4 type value
Definition: ubloxcfg.h:214
uint8_t X1
UBLOXCFG_TYPE_X1 type value
Definition: ubloxcfg.h:220
uint64_t _raw
raw value, unused bytes shall be 0x00
Definition: ubloxcfg.h:231
float R4
UBLOXCFG_TYPE_R4 type value
Definition: ubloxcfg.h:224
bool L
UBLOXCFG_TYPE_L type value
Definition: ubloxcfg.h:229
int64_t I8
UBLOXCFG_TYPE_I8 type value
Definition: ubloxcfg.h:219
uint64_t X8
UBLOXCFG_TYPE_X8 type value
Definition: ubloxcfg.h:223
uint8_t U1
UBLOXCFG_TYPE_U1 type value
Definition: ubloxcfg.h:212
uint8_t _bytes[8]
raw bytes, unused bytes shall be 0x00
Definition: ubloxcfg.h:230
uint16_t X2
UBLOXCFG_TYPE_X2 type value
Definition: ubloxcfg.h:221
int32_t I4
UBLOXCFG_TYPE_I4 type value
Definition: ubloxcfg.h:218
int16_t E2
UBLOXCFG_TYPE_E2 type value
Definition: ubloxcfg.h:227