29#if !defined(CONFIG_VERSION_MAJOR) || !defined(CONFIG_VERSION_MINOR)
37#if (defined(__STDC__) && (__STDC_VERSION__ < 199901L))
38# error This needs C99 or later!
43 if ( (name == NULL) || (strlen(name) < 2) )
49 if ( (name[0] ==
'0') && (name[1] ==
'x') )
53 if ( (sscanf(name,
"%"SCNx32
"%n", &
id, &numChar) == 1) && (numChar == (
int)strlen(name)) )
62 for (
int ix = 0; ix < _UBLOXCFG_NUM_ITEMS; ix++)
64 if (strcmp(allItems[ix]->name, name) == 0)
78 for (
int ix = 0; ix < _UBLOXCFG_NUM_ITEMS; ix++)
80 if (allItems[ix]->
id ==
id)
91 *num = _UBLOXCFG_NUM_ITEMS;
103 for (
int ix = 0; ix < _UBLOXCFG_NUM_RATES; ix++)
105 if (strcmp(allRates[ix]->msgName, msgName) == 0)
107 rates = allRates[ix];
116 *num = _UBLOXCFG_NUM_RATES;
122 if ( (data == NULL) || (size <= 0) || (keyVal == NULL) || (nKeyVal < 1) || (dataSize == NULL) )
129 memset(data, 0, size);
131 for (
int kvIx = 0; res && (kvIx < nKeyVal); kvIx++)
134 if ( (size - dataIx) < 4 )
142 const uint32_t key = kv->
id;
143 data[dataIx++] = (key >> 0) & 0xff;
144 data[dataIx++] = (key >> 8) & 0xff;
145 data[dataIx++] = (key >> 16) & 0xff;
146 data[dataIx++] = (key >> 24) & 0xff;
154 if ( (size - dataIx) < 1 )
159 data[dataIx++] = val.
_bytes[0];
162 if ( (size - dataIx) < 1 )
167 data[dataIx++] = val.
_bytes[0];
170 if ( (size - dataIx) < 2 )
175 data[dataIx++] = val.
_bytes[0];
176 data[dataIx++] = val.
_bytes[1];
179 if ( (size - dataIx) < 4 )
184 data[dataIx++] = val.
_bytes[0];
185 data[dataIx++] = val.
_bytes[1];
186 data[dataIx++] = val.
_bytes[2];
187 data[dataIx++] = val.
_bytes[3];
190 if ( (size - dataIx) < 8 )
195 data[dataIx++] = val.
_bytes[0];
196 data[dataIx++] = val.
_bytes[1];
197 data[dataIx++] = val.
_bytes[2];
198 data[dataIx++] = val.
_bytes[3];
199 data[dataIx++] = val.
_bytes[4];
200 data[dataIx++] = val.
_bytes[5];
201 data[dataIx++] = val.
_bytes[6];
202 data[dataIx++] = val.
_bytes[7];
216 if ( (data == NULL) || (size <= 0) || (keyVal == NULL) || (maxKeyVal < 1) || (nKeyVal == NULL) )
224 memset(keyVal, 0, maxKeyVal *
sizeof(*keyVal));
229 if ( dataIx > (size - 4) )
233 const uint8_t k0 = data[dataIx++];
234 const uint8_t k1 = data[dataIx++];
235 const uint8_t k2 = data[dataIx++];
236 const uint8_t k3 = data[dataIx++];
237 const uint32_t
id = k0 | (k1 << 8) | (k2 << 16) | (k3 << 24);
244 if ( dataIx > (size - 1) )
251 val.
_bytes[0] = data[dataIx++];
255 if ( dataIx > (size - 1) )
262 val.
_bytes[0] = data[dataIx++];
266 if ( dataIx > (size - 1) )
273 val.
_bytes[0] = data[dataIx++];
274 val.
_bytes[1] = data[dataIx++];
278 if ( dataIx > (size - 1) )
285 val.
_bytes[0] = data[dataIx++];
286 val.
_bytes[1] = data[dataIx++];
287 val.
_bytes[2] = data[dataIx++];
288 val.
_bytes[3] = data[dataIx++];
292 if ( dataIx > (size - 1) )
299 val.
_bytes[0] = data[dataIx++];
300 val.
_bytes[1] = data[dataIx++];
301 val.
_bytes[2] = data[dataIx++];
302 val.
_bytes[3] = data[dataIx++];
303 val.
_bytes[4] = data[dataIx++];
304 val.
_bytes[5] = data[dataIx++];
305 val.
_bytes[6] = data[dataIx++];
306 val.
_bytes[7] = data[dataIx++];
317 if (kvIx < maxKeyVal)
319 keyVal[kvIx].
id = id;
320 keyVal[kvIx].
val = val;
364 if ( (str == NULL) || (size <= 0) || ((item != NULL) && (item->
type != type)) )
377 snprintf(str, size,
"%" PRIu8, val->
U1);
384 snprintf(str, size,
"%" PRIu16, val->
U2);
391 snprintf(str, size,
"%" PRIu32, val->
U4);
398 snprintf(str, size,
"%" PRIu64, val->
U8);
405 snprintf(str, size,
"%" PRIi8, val->
I1);
412 snprintf(str, size,
"%" PRIi16, val->
I2);
419 snprintf(str, size,
"%" PRIi32, val->
I4);
426 snprintf(str, size,
"%" PRIi64, val->
I8);
434 if (size >= (19 + 20))
436 const char *fmt1 = NULL;
437 const char *fmt2 = NULL;
441 case UBLOXCFG_TYPE_X1: fmt1 =
"0x%02" PRIx64
" "; fmt2 =
"|0x%02" PRIx64; valX = val->
X1;
break;
442 case UBLOXCFG_TYPE_X2: fmt1 =
"0x%04" PRIx64
" "; fmt2 =
"|0x%04" PRIx64; valX = val->
X2;
break;
443 case UBLOXCFG_TYPE_X4: fmt1 =
"0x%08" PRIx64
" "; fmt2 =
"|0x%08" PRIx64; valX = val->
X4;
break;
444 case UBLOXCFG_TYPE_X8: fmt1 =
"0x%016" PRIx64
" "; fmt2 =
"|0x%016" PRIx64; valX = val->
X8;
break;
448 int len = snprintf(str, size, fmt1, valX);
449 const int ixBracket = len;
451 uint64_t usedBits = 0;
454 for (
int ix = 0; ix < item->
nConsts; ix++)
458 len += snprintf(&str[len], size - len,
"|%s", item->
consts[ix].
name);
460 if ((size - len - 1) <= 0)
468 if ((size - len - 1) > 0)
470 const uint64_t unusedBits = valX & (~usedBits);
471 if (unusedBits == valX)
473 strncat(&str[len],
"|n/a", size - len);
476 else if (unusedBits != 0)
478 len += snprintf(&str[len], size - len, fmt2, unusedBits);
482 str[ixBracket] =
'(';
483 if ((size - len - 1) > 0)
494 if (size > (15 + 30))
506 for (
int ix = 0; ix < item->
nConsts; ix++)
518 snprintf(str, size,
"%" PRIi8
" (n/a)", valE);
526 snprintf(str, size,
"%.24g", val->
R4);
533 snprintf(str, size,
"%.54g", val->
R8);
540 snprintf(str, size, val->
L ?
"1 (true)" :
"0 (false)");
551 if ( (str == NULL) || (valueStr == NULL) || (prettyStr == NULL) )
557 char *space = strchr(str,
' ');
560 *prettyStr = &space[2];
561 char *bracket = strchr(space,
')');
567 if (strcmp(*prettyStr,
"n/a") == 0)
577 if ( (str == NULL) || (size <= 0) || (keyVal == NULL) )
591 len = snprintf(str, size,
"CFG-?-? (0x%02" PRIx32
", ?0) = 0x%"PRIx8,
595 len = snprintf(str, size,
"CFG-?-? (0x%02" PRIx32
", ?1) = 0x%02"PRIx8,
599 len = snprintf(str, size,
"CFG-?-? (0x%02" PRIx32
", ?2) = 0x%04"PRIx16,
603 len = snprintf(str, size,
"CFG-?-? (0x%02" PRIx32
", ?4) = 0x%08"PRIx32,
607 len = snprintf(str, size,
"CFG-?-? (0x%08" PRIx32
", ?8) = 0x%016"PRIx64,
616 int len = snprintf(str, size,
"%s (0x%08" PRIx32
", %s) = ", item->
name, item->
id, type != NULL ? type :
"?");
617 if ((size - 1) <= len)
632 if ((size - 1 - 3) <= len)
639 if ( (item->
scale != NULL) || (item->
unit != NULL) )
645 if (item->
scale != NULL)
647 len += snprintf(&str[len], size - len,
"%s", item->
scale);
649 if ((size - 1 - 2) <= len)
654 if (item->
unit != NULL)
656 len += snprintf(&str[len], size - len,
"%s", item->
unit);
658 if ((size - 1 - 1) <= len)
670static bool strToValUnsigned(
const char *str,
const UBLOXCFG_TYPE_t type, uint64_t *val);
671static bool strToValSigned(
const char *str,
const UBLOXCFG_TYPE_t type, int64_t *val);
672static bool findEnumValue(
const char *str,
const UBLOXCFG_ITEM_t *item, int64_t *val);
673static bool findConstValue(
const char *str,
const UBLOXCFG_ITEM_t *item, uint64_t *val);
677 if ( (str == NULL) || (value == NULL) || ((item != NULL) && (item->
type != type)) )
684 uint64_t valUnsigned;
689 const int len = strlen(str);
690 memset(value, 0,
sizeof(*value));
694 if (strcmp(str,
"false") == 0)
699 else if (strcmp(str,
"true") == 0)
706 if (valUnsigned == 0)
711 else if (valUnsigned == 1)
719 if (strToValUnsigned(str, type, &valUnsigned))
721 value->
U1 = (uint8_t)valUnsigned;
726 if (strToValUnsigned(str, type, &valUnsigned))
728 value->
U2 = (uint16_t)valUnsigned;
733 if (strToValUnsigned(str, type, &valUnsigned))
735 value->
U4 = (uint32_t)valUnsigned;
740 if (strToValUnsigned(str, type, &valUnsigned))
742 value->
U8 = valUnsigned;
747 if (findConstValue(str, item, &valUnsigned))
749 value->
X1 = (uint8_t)valUnsigned;
752 else if (strToValUnsigned(str, type, &valUnsigned))
754 value->
U1 = (uint8_t)valUnsigned;
759 if (findConstValue(str, item, &valUnsigned))
761 value->
X2 = (uint16_t)valUnsigned;
764 else if (strToValUnsigned(str, type, &valUnsigned))
766 value->
X2 = (uint16_t)valUnsigned;
771 if (findConstValue(str, item, &valUnsigned))
773 value->
X4 = (uint32_t)valUnsigned;
776 else if (strToValUnsigned(str, type, &valUnsigned))
778 value->
X4 = (uint32_t)valUnsigned;
783 if (findConstValue(str, item, &valUnsigned))
785 value->
X8 = valUnsigned;
788 else if (strToValUnsigned(str, type, &valUnsigned))
790 value->
X8 = valUnsigned;
795 if (strToValSigned(str, type, &valSigned))
797 value->
I1 = (int8_t)valSigned;
802 if (strToValSigned(str, type, &valSigned))
804 value->
I2 = (int16_t)valSigned;
809 if (strToValSigned(str, type, &valSigned))
811 value->
I4 = (int32_t)valSigned;
816 if (strToValSigned(str, type, &valSigned))
818 value->
I8 = valSigned;
823 if ( (sscanf(str,
"%f%n", &valFloat, &numChar) == 1) && (numChar == len) )
825 value->
R4 = valFloat;
830 if ( (sscanf(str,
"%lf%n", &valDouble, &numChar) == 1) && (numChar == len) )
832 value->
R8 = valDouble;
837 if (findEnumValue(str, item, &valSigned))
839 value->
E1 = (int8_t)valSigned;
842 else if (strToValSigned(str, type, &valSigned))
844 value->
I1 = (int8_t)valSigned;
849 if (findEnumValue(str, item, &valSigned))
851 value->
E2 = (int16_t)valSigned;
854 else if (strToValSigned(str, type, &valSigned))
856 value->
I2 = (int16_t)valSigned;
861 if (findEnumValue(str, item, &valSigned))
863 value->
E4 = (int32_t)valSigned;
866 else if (strToValSigned(str, type, &valSigned))
868 value->
I4= (int32_t)valSigned;
876static bool strToValUnsigned(
const char *str,
const UBLOXCFG_TYPE_t type, uint64_t *val)
878 if ( (str == NULL) || (val == NULL) )
882 const int len = strlen(str);
883 if ( (len < 1) || (isspace((
int)str[0]) != 0) )
916 else if ( (len > 1) && (str[0] ==
'0') && (str[1] ==
'x') )
919 if ( (len > 2) && (sscanf(str,
"%" SCNx64
"%n", &value, &numChar) == 1) && (numChar == len) )
925 else if (str[0] ==
'0')
928 if ( (sscanf(str,
"%" SCNo64
"%n", &value, &numChar) == 1) && (numChar == len) )
937 if ( (sscanf(str,
"%" SCNu64
"%n", &value, &numChar) == 1) && (numChar == len) )
947 return res && (value <= max);
951static bool strToValSigned(
const char *str,
UBLOXCFG_TYPE_t type, int64_t *val)
953 if ( (str == NULL) || (val == NULL) )
957 const int len = strlen(str);
958 if ( (len < 1) || (isspace((
int)str[0]) != 0) )
991 if ( (len > 1) && (str[0] ==
'0') && (str[1] ==
'x') )
993 uint64_t valUnsigned;
995 if ( (len > 2) && ( sscanf(str,
"%" SCNx64
"%n", &valUnsigned, &numChar) == 1) && (numChar ==len) )
1002 value = (int64_t)(int8_t)valUnsigned;
1006 value = (int64_t)(int16_t)valUnsigned;
1010 value = (int64_t)(int32_t)valUnsigned;
1013 value = (int64_t)valUnsigned;
1025 if ( (sscanf(str,
"%" SCNi64
"%n", &value, &numChar) == 1) && (numChar == len) )
1035 return res && (value >= min) && (value <= max);
1039static bool findConstValue(
const char *str,
const UBLOXCFG_ITEM_t *item, uint64_t *val)
1041 if ( (item == NULL) || (val == NULL) || (str == NULL) || (strlen(str) < 1) )
1047 uint64_t valRes = 0;
1050 const char sep =
'|';
1051 const char *pStr = str;
1052 const char *pSep = strchr(pStr, sep);
1053 while (*pStr !=
'\0')
1056 const int cmpLen = strlen(pStr) - ( (pSep != NULL) ? strlen(pSep) : 0 );
1059 if ( (cmpLen > 2) && (pStr[0] ==
'0') && (pStr[1] ==
'x') )
1063 if ( (cmpLen < 3) || (sscanf(pStr,
"%" SCNx64
"%n", &v, &numChar) != 1) || (numChar != cmpLen) )
1073 for (
int ix = 0; (ix < item->
nConsts) && !found; ix++)
1075 const int nameLen = strlen(item->
consts[ix].
name);
1076 if ( (nameLen == cmpLen) && (strncmp(item->
consts[ix].
name, pStr, cmpLen) == 0) )
1093 pSep = strchr(pStr, sep);
1108static bool findEnumValue(
const char *str,
const UBLOXCFG_ITEM_t *item, int64_t *val)
1113 for (
int ix = 0; ix < item->
nConsts; ix++)
1140 if ( (name == NULL) || (name[0] ==
'\0') )
1145 int len = strlen(name);
1146 if (len > ((
int)
sizeof(str) - 1))
1154 str[len] = tolower(name[len]);
1156 if (strcmp(str,
"ram") == 0)
1160 else if (strcmp(str,
"bbr") == 0)
1164 else if (strcmp(str,
"flash") == 0)
1168 else if (strcmp(str,
"default") == 0)
1181 return ((uint16_t)CONFIG_VERSION_MAJOR << 8 | ((uint16_t)CONFIG_VERSION_MINOR & 0xff));
1186 *numSources = _UBLOXCFG_NUM_SOURCES;
1187 return _ubloxcfg_allSources();
bool ubloxcfg_valueFromString(const char *str, UBLOXCFG_TYPE_t type, const UBLOXCFG_ITEM_t *item, UBLOXCFG_VALUE_t *value)
Convert string to value.
const char * ubloxcfg_typeStr(UBLOXCFG_TYPE_t type)
Stringify item type.
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.
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.
bool ubloxcfg_splitValueStr(char *str, char **valueStr, char **prettyStr)
Split stringified value string.
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.
bool ubloxcfg_stringifyKeyVal(char *str, const int size, const UBLOXCFG_KEYVAL_t *keyVal)
Stringify key-value pair (for debugging)
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.
const UBLOXCFG_MSGRATE_t * ubloxcfg_getMsgRateCfg(const char *msgName)
Get configuration items for output message rate configuration.
#define UBLOXCFG_ID2SIZE(id)
Get item size from item ID.
const UBLOXCFG_ITEM_t ** ubloxcfg_getAllItems(int *num)
Get list of all items.
enum UBLOXCFG_LAYER_e UBLOXCFG_LAYER_t
Configuration layers.
bool ubloxcfg_layerFromName(const char *name, UBLOXCFG_LAYER_t *layer)
Get layer from name.
const char * ubloxcfg_layerName(const UBLOXCFG_LAYER_t layer)
Get name for layer.
const UBLOXCFG_ITEM_t * ubloxcfg_getItemById(const uint32_t id)
Get configuration item info by key ID.
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.
@ UBLOXCFG_SIZE_EIGHT
Eight bytes.
@ UBLOXCFG_SIZE_ONE
One byte.
@ UBLOXCFG_SIZE_FOUR
Four bytes.
@ UBLOXCFG_SIZE_BIT
One bit.
@ UBLOXCFG_SIZE_TWO
Two bytes.
@ UBLOXCFG_LAYER_DEFAULT
Default layer.
@ UBLOXCFG_LAYER_FLASH
Flash layer.
@ UBLOXCFG_LAYER_RAM
RAM layer (a.k.a. current configuration)
@ UBLOXCFG_LAYER_BBR
BBR layer.
@ UBLOXCFG_TYPE_I1
One byte signed, little-endian (int8_t)
@ UBLOXCFG_TYPE_U8
Eight bytes unsigned, little-endian (uint64_t)
@ UBLOXCFG_TYPE_X8
Eight bytes unsigned, little-endian (uint64_t)
@ UBLOXCFG_TYPE_U2
Two bytes unsigned, little-endian (uint16_t)
@ UBLOXCFG_TYPE_X4
Four bytes unsigned, little-endian (uint32_t)
@ UBLOXCFG_TYPE_I8
Eight byte signed, little-endian (int64_t)
@ UBLOXCFG_TYPE_L
One bit logical (0 = false, 1 = true)
@ UBLOXCFG_TYPE_E2
Two bytes unsigned, little-endian (int16_t)
@ UBLOXCFG_TYPE_E4
Four bytes unsigned, little-endian (int32_t)
@ UBLOXCFG_TYPE_I4
Four bytes signed, little-endian (int32_t)
@ UBLOXCFG_TYPE_I2
Two bytes signed, little-endian (int16_t)
@ UBLOXCFG_TYPE_X2
Two bytes unsigned, little-endian (uint16_t)
@ UBLOXCFG_TYPE_R8
Eight bytes IEEE754 double precision (double)
@ UBLOXCFG_TYPE_R4
Four bytes IEEE754 single precision (float)
@ UBLOXCFG_TYPE_U1
One byte unsigned, little-endian (uint8_t)
@ UBLOXCFG_TYPE_X1
One byte unsigned, little-endian (uint8_t)
@ UBLOXCFG_TYPE_E1
One byte unsigned, little-endian (int8_t)
@ UBLOXCFG_TYPE_U4
Four bytes unsigned, little-endian (uint32_t)
uint16_t ubloxcfg_getVersion(void)
Get library version.
const char ** ubloxcfg_getSources(int *numSources)
Get strings describing the data sources.
union UBLOXCFG_CONST_s::@0 val
Value.
int32_t E
E type value as number.
const char * name
Name of the constant.
uint64_t X
X type value as number.
const char * value
Value as string.
const char * unit
Unit (or NULL)
const char * scale
Scale factor as string (or NULL)
UBLOXCFG_TYPE_t type
Storage type.
int nConsts
Number of constants (or 0 if none)
const char * name
Item name.
const UBLOXCFG_CONST_t * consts
Constants (or NULL if none)
UBLOXCFG_VALUE_t val
Configuration item value.
uint32_t id
Configuration item ID.
Configuration items for output message rate configuration.
u-blox 9 positioning receivers configuration library
Configuration value storage (s.a. UBLOXCFG_TYPE_t)
uint16_t U2
UBLOXCFG_TYPE_U2 type value
int16_t I2
UBLOXCFG_TYPE_I2 type value
uint32_t X4
UBLOXCFG_TYPE_X4 type value
double R8
UBLOXCFG_TYPE_R8 type value
int32_t E4
UBLOXCFG_TYPE_E4 type value
int8_t E1
UBLOXCFG_TYPE_E1 type value
uint64_t U8
UBLOXCFG_TYPE_U8 type value
int8_t I1
UBLOXCFG_TYPE_I1 type value
uint32_t U4
UBLOXCFG_TYPE_U4 type value
uint8_t X1
UBLOXCFG_TYPE_X1 type value
float R4
UBLOXCFG_TYPE_R4 type value
bool L
UBLOXCFG_TYPE_L type value
int64_t I8
UBLOXCFG_TYPE_I8 type value
uint64_t X8
UBLOXCFG_TYPE_X8 type value
uint8_t U1
UBLOXCFG_TYPE_U1 type value
uint8_t _bytes[8]
raw bytes, unused bytes shall be 0x00
uint16_t X2
UBLOXCFG_TYPE_X2 type value
int32_t I4
UBLOXCFG_TYPE_I4 type value
int16_t E2
UBLOXCFG_TYPE_E2 type value