32 #if (defined(__STDC__) && (__STDC_VERSION__ < 199901L))
33 # error This needs C99 or later!
38 if ( (name == NULL) || (strlen(name) < 2) )
44 if ( (name[0] ==
'0') && (name[1] ==
'x') )
48 if ( (sscanf(name,
"%"SCNx32
"%n", &
id, &numChar) == 1) && (numChar == (
int)strlen(name)) )
57 for (
int ix = 0; ix < _UBLOXCFG_NUM_ITEMS; ix++)
59 if (strcmp(allItems[ix]->name, name) == 0)
73 for (
int ix = 0; ix < _UBLOXCFG_NUM_ITEMS; ix++)
75 if (allItems[ix]->
id ==
id)
86 *num = _UBLOXCFG_NUM_ITEMS;
98 for (
int ix = 0; ix < _UBLOXCFG_NUM_RATES; ix++)
100 if (strcmp(allRates[ix]->msgName, msgName) == 0)
102 rates = allRates[ix];
111 *num = _UBLOXCFG_NUM_RATES;
117 if ( (data == NULL) || (size <= 0) || (keyVal == NULL) || (nKeyVal < 1) || (dataSize == NULL) )
124 memset(data, 0, size);
126 for (
int kvIx = 0; res && (kvIx < nKeyVal); kvIx++)
129 if ( (size - dataIx) < 4 )
137 const uint32_t key = kv->
id;
138 data[dataIx++] = (key >> 0) & 0xff;
139 data[dataIx++] = (key >> 8) & 0xff;
140 data[dataIx++] = (key >> 16) & 0xff;
141 data[dataIx++] = (key >> 24) & 0xff;
149 if ( (size - dataIx) < 1 )
154 data[dataIx++] = val.
_bytes[0];
157 if ( (size - dataIx) < 1 )
162 data[dataIx++] = val.
_bytes[0];
165 if ( (size - dataIx) < 2 )
170 data[dataIx++] = val.
_bytes[0];
171 data[dataIx++] = val.
_bytes[1];
174 if ( (size - dataIx) < 4 )
179 data[dataIx++] = val.
_bytes[0];
180 data[dataIx++] = val.
_bytes[1];
181 data[dataIx++] = val.
_bytes[2];
182 data[dataIx++] = val.
_bytes[3];
185 if ( (size - dataIx) < 8 )
190 data[dataIx++] = val.
_bytes[0];
191 data[dataIx++] = val.
_bytes[1];
192 data[dataIx++] = val.
_bytes[2];
193 data[dataIx++] = val.
_bytes[3];
194 data[dataIx++] = val.
_bytes[4];
195 data[dataIx++] = val.
_bytes[5];
196 data[dataIx++] = val.
_bytes[6];
197 data[dataIx++] = val.
_bytes[7];
211 if ( (data == NULL) || (size <= 0) || (keyVal == NULL) || (maxKeyVal < 1) || (nKeyVal == NULL) )
219 memset(keyVal, 0, maxKeyVal *
sizeof(*keyVal));
224 if ( dataIx > (size - 4) )
228 const uint8_t k0 = data[dataIx++];
229 const uint8_t k1 = data[dataIx++];
230 const uint8_t k2 = data[dataIx++];
231 const uint8_t k3 = data[dataIx++];
232 const uint32_t
id = k0 | (k1 << 8) | (k2 << 16) | (k3 << 24);
239 if ( dataIx > (size - 1) )
246 val.
_bytes[0] = data[dataIx++];
250 if ( dataIx > (size - 1) )
257 val.
_bytes[0] = data[dataIx++];
261 if ( dataIx > (size - 1) )
268 val.
_bytes[0] = data[dataIx++];
269 val.
_bytes[1] = data[dataIx++];
273 if ( dataIx > (size - 1) )
280 val.
_bytes[0] = data[dataIx++];
281 val.
_bytes[1] = data[dataIx++];
282 val.
_bytes[2] = data[dataIx++];
283 val.
_bytes[3] = data[dataIx++];
287 if ( dataIx > (size - 1) )
294 val.
_bytes[0] = data[dataIx++];
295 val.
_bytes[1] = data[dataIx++];
296 val.
_bytes[2] = data[dataIx++];
297 val.
_bytes[3] = data[dataIx++];
298 val.
_bytes[4] = data[dataIx++];
299 val.
_bytes[5] = data[dataIx++];
300 val.
_bytes[6] = data[dataIx++];
301 val.
_bytes[7] = data[dataIx++];
312 if (kvIx < maxKeyVal)
314 keyVal[kvIx].
id = id;
315 keyVal[kvIx].
val = val;
359 if ( (str == NULL) || (size <= 0) || ((item != NULL) && (item->
type != type)) )
372 snprintf(str, size,
"%" PRIu8, val->
U1);
379 snprintf(str, size,
"%" PRIu16, val->
U2);
386 snprintf(str, size,
"%" PRIu32, val->
U4);
393 snprintf(str, size,
"%" PRIu64, val->
U8);
400 snprintf(str, size,
"%" PRIi8, val->
I1);
407 snprintf(str, size,
"%" PRIi16, val->
I2);
414 snprintf(str, size,
"%" PRIi32, val->
I4);
421 snprintf(str, size,
"%" PRIi64, val->
I8);
429 if (size >= (19 + 20))
431 const char *fmt1 = NULL;
432 const char *fmt2 = NULL;
436 case UBLOXCFG_TYPE_X1: fmt1 =
"0x%02" PRIx64
" "; fmt2 =
"|0x%02" PRIx64; valX = val->
X1;
break;
437 case UBLOXCFG_TYPE_X2: fmt1 =
"0x%04" PRIx64
" "; fmt2 =
"|0x%04" PRIx64; valX = val->
X2;
break;
438 case UBLOXCFG_TYPE_X4: fmt1 =
"0x%08" PRIx64
" "; fmt2 =
"|0x%08" PRIx64; valX = val->
X4;
break;
439 case UBLOXCFG_TYPE_X8: fmt1 =
"0x%016" PRIx64
" "; fmt2 =
"|0x%016" PRIx64; valX = val->
X8;
break;
443 int len = snprintf(str, size, fmt1, valX);
444 const int ixBracket = len;
446 uint64_t usedBits = 0;
449 for (
int ix = 0; ix < item->
nConsts; ix++)
453 len += snprintf(&str[len], size - len,
"|%s", item->
consts[ix].
name);
455 if ((size - len - 1) <= 0)
463 if ((size - len - 1) > 0)
465 const uint64_t unusedBits = valX & (~usedBits);
466 if (unusedBits == valX)
468 strncat(&str[len],
"|n/a", size - len);
471 else if (unusedBits != 0)
473 len += snprintf(&str[len], size - len, fmt2, unusedBits);
477 str[ixBracket] =
'(';
478 if ((size - len - 1) > 0)
489 if (size > (15 + 30))
501 for (
int ix = 0; ix < item->
nConsts; ix++)
513 snprintf(str, size,
"%" PRIi8
" (n/a)", valE);
521 snprintf(str, size,
"%.24g", val->
R4);
528 snprintf(str, size,
"%.54g", val->
R8);
535 snprintf(str, size, val->
L ?
"1 (true)" :
"0 (false)");
546 if ( (str == NULL) || (valueStr == NULL) || (prettyStr == NULL) )
552 char *space = strchr(str,
' ');
555 *prettyStr = &space[2];
556 char *bracket = strchr(space,
')');
562 if (strcmp(*prettyStr,
"n/a") == 0)
572 if ( (str == NULL) || (size <= 0) || (keyVal == NULL) )
586 len = snprintf(str, size,
"CFG-?-? (0x%02" PRIx32
", ?0) = 0x%"PRIx8,
590 len = snprintf(str, size,
"CFG-?-? (0x%02" PRIx32
", ?1) = 0x%02"PRIx8,
594 len = snprintf(str, size,
"CFG-?-? (0x%02" PRIx32
", ?2) = 0x%04"PRIx16,
598 len = snprintf(str, size,
"CFG-?-? (0x%02" PRIx32
", ?4) = 0x%08"PRIx32,
602 len = snprintf(str, size,
"CFG-?-? (0x%08" PRIx32
", ?8) = 0x%016"PRIx64,
611 int len = snprintf(str, size,
"%s (0x%08" PRIx32
", %s) = ", item->
name, item->
id, type != NULL ? type :
"?");
612 if ((size - 1) <= len)
627 if ((size - 1 - 3) <= len)
634 if ( (item->
scale != NULL) || (item->
unit != NULL) )
640 if (item->
scale != NULL)
642 len += snprintf(&str[len], size - len,
"%s", item->
scale);
644 if ((size - 1 - 2) <= len)
649 if (item->
unit != NULL)
651 len += snprintf(&str[len], size - len,
"%s", item->
unit);
653 if ((size - 1 - 1) <= len)
665 static bool strToValUnsigned(
const char *str,
const UBLOXCFG_TYPE_t type, uint64_t *val);
666 static bool strToValSigned(
const char *str,
const UBLOXCFG_TYPE_t type, int64_t *val);
667 static bool findEnumValue(
const char *str,
const UBLOXCFG_ITEM_t *item, int64_t *val);
668 static bool findConstValue(
const char *str,
const UBLOXCFG_ITEM_t *item, uint64_t *val);
672 if ( (str == NULL) || (value == NULL) || ((item != NULL) && (item->
type != type)) )
679 uint64_t valUnsigned;
684 const int len = strlen(str);
688 if (strcmp(str,
"false") == 0)
693 else if (strcmp(str,
"true") == 0)
700 if (valUnsigned == 0)
705 else if (valUnsigned == 1)
713 if (strToValUnsigned(str, type, &valUnsigned))
715 value->
U1 = (uint8_t)valUnsigned;
720 if (strToValUnsigned(str, type, &valUnsigned))
722 value->
U2 = (uint16_t)valUnsigned;
727 if (strToValUnsigned(str, type, &valUnsigned))
729 value->
U4 = (uint32_t)valUnsigned;
734 if (strToValUnsigned(str, type, &valUnsigned))
736 value->
U8 = valUnsigned;
741 if (findConstValue(str, item, &valUnsigned))
743 value->
X1 = (uint8_t)valUnsigned;
746 else if (strToValUnsigned(str, type, &valUnsigned))
748 value->
U1 = (uint8_t)valUnsigned;
753 if (findConstValue(str, item, &valUnsigned))
755 value->
X2 = (uint16_t)valUnsigned;
758 else if (strToValUnsigned(str, type, &valUnsigned))
760 value->
X2 = (uint16_t)valUnsigned;
765 if (findConstValue(str, item, &valUnsigned))
767 value->
X4 = (uint32_t)valUnsigned;
770 else if (strToValUnsigned(str, type, &valUnsigned))
772 value->
X4 = (uint32_t)valUnsigned;
777 if (findConstValue(str, item, &valUnsigned))
779 value->
X8 = valUnsigned;
782 else if (strToValUnsigned(str, type, &valUnsigned))
784 value->
X8 = valUnsigned;
789 if (strToValSigned(str, type, &valSigned))
791 value->
I1 = (int8_t)valSigned;
796 if (strToValSigned(str, type, &valSigned))
798 value->
I2 = (int16_t)valSigned;
803 if (strToValSigned(str, type, &valSigned))
805 value->
I4 = (int32_t)valSigned;
810 if (strToValSigned(str, type, &valSigned))
812 value->
I8 = valSigned;
817 if ( (sscanf(str,
"%f%n", &valFloat, &numChar) == 1) && (numChar == len) )
819 value->
R4 = valFloat;
824 if ( (sscanf(str,
"%lf%n", &valDouble, &numChar) == 1) && (numChar == len) )
826 value->
R8 = valDouble;
831 if (findEnumValue(str, item, &valSigned))
833 value->
E1 = (int8_t)valSigned;
836 else if (strToValSigned(str, type, &valSigned))
838 value->
I1 = (int8_t)valSigned;
843 if (findEnumValue(str, item, &valSigned))
845 value->
E2 = (int16_t)valSigned;
848 else if (strToValSigned(str, type, &valSigned))
850 value->
I2 = (int16_t)valSigned;
855 if (findEnumValue(str, item, &valSigned))
857 value->
E4 = (int32_t)valSigned;
860 else if (strToValSigned(str, type, &valSigned))
862 value->
I4= (int32_t)valSigned;
870 static bool strToValUnsigned(
const char *str,
const UBLOXCFG_TYPE_t type, uint64_t *val)
872 if ( (str == NULL) || (val == NULL) )
876 const int len = strlen(str);
877 if ( (len < 1) || (isspace((
int)str[0]) != 0) )
910 else if ( (len > 1) && (str[0] ==
'0') && (str[1] ==
'x') )
913 if ( (len > 2) && (sscanf(str,
"%" SCNx64
"%n", &value, &numChar) == 1) && (numChar == len) )
919 else if (str[0] ==
'0')
922 if ( (sscanf(str,
"%" SCNo64
"%n", &value, &numChar) == 1) && (numChar == len) )
931 if ( (sscanf(str,
"%" SCNu64
"%n", &value, &numChar) == 1) && (numChar == len) )
941 return res && (value <= max);
945 static bool strToValSigned(
const char *str,
UBLOXCFG_TYPE_t type, int64_t *val)
947 if ( (str == NULL) || (val == NULL) )
951 const int len = strlen(str);
952 if ( (len < 1) || (isspace((
int)str[0]) != 0) )
985 if ( (len > 1) && (str[0] ==
'0') && (str[1] ==
'x') )
987 uint64_t valUnsigned;
989 if ( (len > 2) && ( sscanf(str,
"%" SCNx64
"%n", &valUnsigned, &numChar) == 1) && (numChar ==len) )
996 value = (int64_t)(int8_t)valUnsigned;
1000 value = (int64_t)(int16_t)valUnsigned;
1004 value = (int64_t)(int32_t)valUnsigned;
1007 value = (int64_t)valUnsigned;
1019 if ( (sscanf(str,
"%" SCNi64
"%n", &value, &numChar) == 1) && (numChar == len) )
1029 return res && (value >= min) && (value <= max);
1033 static bool findConstValue(
const char *str,
const UBLOXCFG_ITEM_t *item, uint64_t *val)
1035 if ( (item == NULL) || (val == NULL) || (str == NULL) || (strlen(str) < 1) )
1041 uint64_t valRes = 0;
1044 const char sep =
'|';
1045 const char *pStr = str;
1046 const char *pSep = strchr(pStr, sep);
1047 while (*pStr !=
'\0')
1050 const int cmpLen = strlen(pStr) - ( (pSep != NULL) ? strlen(pSep) : 0 );
1053 if ( (cmpLen > 2) && (pStr[0] ==
'0') && (pStr[1] ==
'x') )
1057 if ( (cmpLen < 3) || (sscanf(pStr,
"%" SCNx64
"%n", &v, &numChar) != 1) || (numChar != cmpLen) )
1067 for (
int ix = 0; (ix < item->
nConsts) && !found; ix++)
1069 const int nameLen = strlen(item->
consts[ix].
name);
1070 if ( (nameLen == cmpLen) && (strncmp(item->
consts[ix].
name, pStr, cmpLen) == 0) )
1087 pSep = strchr(pStr, sep);
1102 static bool findEnumValue(
const char *str,
const UBLOXCFG_ITEM_t *item, int64_t *val)
1107 for (
int ix = 0; ix < item->
nConsts; ix++)
1134 if ( (name == NULL) || (name[0] ==
'\0') )
1139 int len = strlen(name);
1140 if (len > ((
int)
sizeof(str) - 1))
1148 str[len] = tolower(name[len]);
1150 if (strcmp(str,
"ram") == 0)
1154 else if (strcmp(str,
"bbr") == 0)
1158 else if (strcmp(str,
"flash") == 0)
1162 else if (strcmp(str,
"default") == 0)
1175 #if defined(CONFIG_VERSION_MAJOR) && defined(CONFIG_VERSION_MINOR)
1176 return (CONFIG_VERSION_MAJOR << 8 | CONFIG_VERSION_MINOR);
1184 *numSources = _UBLOXCFG_NUM_SOURCES;
1185 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.
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.
const char * ubloxcfg_typeStr(UBLOXCFG_TYPE_t type)
Stringify item type.
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)
const UBLOXCFG_ITEM_t * ubloxcfg_getItemById(const uint32_t id)
Get configuration item info by key ID.
enum UBLOXCFG_SIZE_e UBLOXCFG_SIZE_t
Configuration item size.
const UBLOXCFG_MSGRATE_t * ubloxcfg_getMsgRateCfg(const char *msgName)
Get configuration items for output message rate configuration.
const UBLOXCFG_ITEM_t * ubloxcfg_getItemByName(const char *name)
Get configuration item info by name.
#define UBLOXCFG_ID2SIZE(id)
Get item size from item ID.
const char * ubloxcfg_layerName(const UBLOXCFG_LAYER_t layer)
Get name for layer.
enum UBLOXCFG_LAYER_e UBLOXCFG_LAYER_t
Configuration layers.
bool ubloxcfg_layerFromName(const char *name, UBLOXCFG_LAYER_t *layer)
Get layer from name.
const UBLOXCFG_ITEM_t ** ubloxcfg_getAllItems(int *num)
Get list of all items.
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
uint16_t X2
UBLOXCFG_TYPE_X2 type value
int32_t I4
UBLOXCFG_TYPE_I4 type value
int16_t E2
UBLOXCFG_TYPE_E2 type value