Strip tabs and trailing white spaces, and fix end of files (#748)

* format: Strip trailing whitespaces

We want to get rid of trailing whitespaces completly as they make just git
noice. Much better to start using automated tools to get rid of them once and
not getting them back again. This way git history will be cleaner and review
easier.

Commit was generated with:

    pre-commit run --all-files trailing-whitespace

* format: Files should have exactly one new line end of them

It is good practice that every file has one new line. It is not now days so
mandatory but it also is not nice if file has lot of newlines end of it. We will
use pre-commit which takes automatically care about this so let's fix all.

Commit was generated with:

    pre-commit run --all-files end-of-file-fixer

* format: Convert tabs to spaces

Project mostly use spaces over tabs. When mixing tabs and spaces this usually
makes formatting issues and also when changing those in commits it will make lot
of git noise. We will force spaces most of the time and use pre-commit to fix.

Commit was generated with:

    pre-commit run --all-files remove-tabs

---------

Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
This commit is contained in:
Kari Argillander
2024-08-25 22:13:57 +03:00
committed by GitHub
parent 9e0657424e
commit 369da70f2a
455 changed files with 7147 additions and 7249 deletions
+11 -11
View File
@@ -5,8 +5,8 @@
# @copyright SPDX-License-Identifier: MIT
menuconfig BACNETSTACK_BACNET_SETTINGS
bool "BACNETSTACK_BACNET_SETTINGS"
default y if BACNETSTACK && SETTINGS
help
default y if BACNETSTACK && SETTINGS
help
This option enables BACnet Settings services
if BACNETSTACK_BACNET_SETTINGS
@@ -14,15 +14,15 @@ if BACNETSTACK_BACNET_SETTINGS
module = BACNETSTACK_BACNET_SETTINGS
module-str = bac_settings
config BACNET_SETTINGS_BASE_NAME
string "BACnet object path base name for every setting"
default ".bacnet"
help
BACnet object path base name for every setting"
config BACNET_SETTINGS_BASE_NAME
string "BACnet object path base name for every setting"
default ".bacnet"
help
BACnet object path base name for every setting"
config BACNET_SETTINGS_SHELL
bool "BACnet settings subsystem shell"
depends on BACNETSTACK
default y if SHELL && SETTINGS
config BACNET_SETTINGS_SHELL
bool "BACnet settings subsystem shell"
depends on BACNETSTACK
default y if SHELL && SETTINGS
endif # BACNETSTACK_BACNET_SETTINGS
+182 -182
View File
@@ -27,26 +27,26 @@
* @return stored data length on success 0..N, negative on failure.
*/
int bacnet_settings_value_get(uint16_t object_type, uint32_t object_instance,
uint32_t property_id, uint32_t array_index,
BACNET_APPLICATION_DATA_VALUE *value)
uint32_t property_id, uint32_t array_index,
BACNET_APPLICATION_DATA_VALUE *value)
{
uint8_t name[BACNET_STORAGE_VALUE_SIZE_MAX + 1] = { 0 };
BACNET_STORAGE_KEY key = { 0 };
int stored_len, len;
uint8_t name[BACNET_STORAGE_VALUE_SIZE_MAX + 1] = { 0 };
BACNET_STORAGE_KEY key = { 0 };
int stored_len, len;
bacnet_storage_key_init(&key, object_type, object_instance, property_id,
array_index);
stored_len = bacnet_storage_get(&key, name, sizeof(name));
if (stored_len > 0) {
len = bacapp_decode_application_data(name, stored_len, value);
if (len <= 0) {
if (value) {
value->tag = MAX_BACNET_APPLICATION_TAG;
}
}
}
bacnet_storage_key_init(&key, object_type, object_instance, property_id,
array_index);
stored_len = bacnet_storage_get(&key, name, sizeof(name));
if (stored_len > 0) {
len = bacapp_decode_application_data(name, stored_len, value);
if (len <= 0) {
if (value) {
value->tag = MAX_BACNET_APPLICATION_TAG;
}
}
}
return stored_len;
return stored_len;
}
/**
@@ -59,25 +59,25 @@ int bacnet_settings_value_get(uint16_t object_type, uint32_t object_instance,
* @return true on success, false on failure.
*/
bool bacnet_settings_value_set(uint16_t object_type, uint32_t object_instance,
uint32_t property_id, uint32_t array_index,
BACNET_APPLICATION_DATA_VALUE *value)
uint32_t property_id, uint32_t array_index,
BACNET_APPLICATION_DATA_VALUE *value)
{
uint8_t name[BACNET_STORAGE_VALUE_SIZE_MAX] = { 0 };
BACNET_STORAGE_KEY key = { 0 };
int rc, len;
uint8_t name[BACNET_STORAGE_VALUE_SIZE_MAX] = { 0 };
BACNET_STORAGE_KEY key = { 0 };
int rc, len;
bacnet_storage_key_init(&key, object_type, object_instance, property_id,
array_index);
len = bacapp_encode_application_data(NULL, value);
if (len <= 0) {
return false;
} else if (len > sizeof(name)) {
return false;
}
len = bacapp_encode_application_data(name, value);
rc = bacnet_storage_set(&key, name, len);
bacnet_storage_key_init(&key, object_type, object_instance, property_id,
array_index);
len = bacapp_encode_application_data(NULL, value);
if (len <= 0) {
return false;
} else if (len > sizeof(name)) {
return false;
}
len = bacapp_encode_application_data(name, value);
rc = bacnet_storage_set(&key, name, len);
return rc == 0;
return rc == 0;
}
/**
@@ -90,26 +90,26 @@ bool bacnet_settings_value_set(uint16_t object_type, uint32_t object_instance,
* @return stored data length on success 0..N, negative on failure.
*/
int bacnet_settings_real_get(uint16_t object_type, uint32_t object_instance,
uint32_t property_id, uint32_t array_index,
float default_value, float *value)
uint32_t property_id, uint32_t array_index,
float default_value, float *value)
{
int stored_len;
BACNET_APPLICATION_DATA_VALUE bvalue = { 0 };
int stored_len;
BACNET_APPLICATION_DATA_VALUE bvalue = { 0 };
stored_len =
bacnet_settings_value_get(object_type, object_instance,
property_id, array_index, &bvalue);
if ((stored_len >= 0) && (bvalue.tag == BACNET_APPLICATION_TAG_REAL)) {
if (value) {
*value = bvalue.type.Real;
}
} else {
if (value) {
*value = default_value;
}
}
stored_len =
bacnet_settings_value_get(object_type, object_instance,
property_id, array_index, &bvalue);
if ((stored_len >= 0) && (bvalue.tag == BACNET_APPLICATION_TAG_REAL)) {
if (value) {
*value = bvalue.type.Real;
}
} else {
if (value) {
*value = default_value;
}
}
return stored_len;
return stored_len;
}
/**
@@ -122,17 +122,17 @@ int bacnet_settings_real_get(uint16_t object_type, uint32_t object_instance,
* @return true on success, false on failure.
*/
bool bacnet_settings_real_set(uint16_t object_type, uint32_t object_instance,
uint32_t property_id, uint32_t array_index,
float value)
uint32_t property_id, uint32_t array_index,
float value)
{
BACNET_APPLICATION_DATA_VALUE bvalue = { 0 };
BACNET_APPLICATION_DATA_VALUE bvalue = { 0 };
bvalue.context_specific = false;
bvalue.tag = BACNET_APPLICATION_TAG_REAL;
bvalue.type.Real = value;
bvalue.context_specific = false;
bvalue.tag = BACNET_APPLICATION_TAG_REAL;
bvalue.type.Real = value;
return bacnet_settings_value_set(object_type, object_instance,
property_id, array_index, &bvalue);
return bacnet_settings_value_set(object_type, object_instance,
property_id, array_index, &bvalue);
}
/**
@@ -144,32 +144,32 @@ bool bacnet_settings_real_set(uint16_t object_type, uint32_t object_instance,
* @return stored data length on success 0..N, negative on failure.
*/
int bacnet_settings_unsigned_get(uint16_t object_type, uint32_t object_instance,
uint32_t property_id, uint32_t array_index,
BACNET_UNSIGNED_INTEGER default_value,
BACNET_UNSIGNED_INTEGER *value)
uint32_t property_id, uint32_t array_index,
BACNET_UNSIGNED_INTEGER default_value,
BACNET_UNSIGNED_INTEGER *value)
{
uint8_t name[BACNET_STORAGE_VALUE_SIZE_MAX + 1] = { 0 };
BACNET_STORAGE_KEY key = { 0 };
int stored_len, len;
uint8_t name[BACNET_STORAGE_VALUE_SIZE_MAX + 1] = { 0 };
BACNET_STORAGE_KEY key = { 0 };
int stored_len, len;
bacnet_storage_key_init(&key, object_type, object_instance, property_id,
array_index);
stored_len = bacnet_storage_get(&key, name, sizeof(name));
if (stored_len > 0) {
len = bacnet_unsigned_application_decode(name, stored_len,
value);
if (len <= 0) {
if (value) {
*value = default_value;
}
}
} else {
if (value) {
*value = default_value;
}
}
bacnet_storage_key_init(&key, object_type, object_instance, property_id,
array_index);
stored_len = bacnet_storage_get(&key, name, sizeof(name));
if (stored_len > 0) {
len = bacnet_unsigned_application_decode(name, stored_len,
value);
if (len <= 0) {
if (value) {
*value = default_value;
}
}
} else {
if (value) {
*value = default_value;
}
}
return stored_len;
return stored_len;
}
/**
@@ -181,18 +181,18 @@ int bacnet_settings_unsigned_get(uint16_t object_type, uint32_t object_instance,
* @return true on success, false on failure.
*/
bool bacnet_settings_unsigned_set(uint16_t object_type,
uint32_t object_instance,
uint32_t property_id, uint32_t array_index,
BACNET_UNSIGNED_INTEGER value)
uint32_t object_instance,
uint32_t property_id, uint32_t array_index,
BACNET_UNSIGNED_INTEGER value)
{
BACNET_APPLICATION_DATA_VALUE bvalue = { 0 };
BACNET_APPLICATION_DATA_VALUE bvalue = { 0 };
bvalue.context_specific = false;
bvalue.tag = BACNET_APPLICATION_TAG_UNSIGNED_INT;
bvalue.type.Unsigned_Int = value;
bvalue.context_specific = false;
bvalue.tag = BACNET_APPLICATION_TAG_UNSIGNED_INT;
bvalue.type.Unsigned_Int = value;
return bacnet_settings_value_set(object_type, object_instance,
property_id, array_index, &bvalue);
return bacnet_settings_value_set(object_type, object_instance,
property_id, array_index, &bvalue);
}
/**
@@ -205,30 +205,30 @@ bool bacnet_settings_unsigned_set(uint16_t object_type,
* @return stored data length on success 0..N, negative on failure.
*/
int bacnet_settings_signed_get(uint16_t object_type, uint32_t object_instance,
uint32_t property_id, uint32_t array_index,
int32_t default_value, int32_t *value)
uint32_t property_id, uint32_t array_index,
int32_t default_value, int32_t *value)
{
uint8_t name[BACNET_STORAGE_VALUE_SIZE_MAX + 1] = { 0 };
BACNET_STORAGE_KEY key = { 0 };
int stored_len, len;
uint8_t name[BACNET_STORAGE_VALUE_SIZE_MAX + 1] = { 0 };
BACNET_STORAGE_KEY key = { 0 };
int stored_len, len;
bacnet_storage_key_init(&key, object_type, object_instance, property_id,
array_index);
stored_len = bacnet_storage_get(&key, name, sizeof(name));
if (stored_len > 0) {
len = bacnet_signed_application_decode(name, stored_len, value);
if (len <= 0) {
if (value) {
*value = default_value;
}
}
} else {
if (value) {
*value = default_value;
}
}
bacnet_storage_key_init(&key, object_type, object_instance, property_id,
array_index);
stored_len = bacnet_storage_get(&key, name, sizeof(name));
if (stored_len > 0) {
len = bacnet_signed_application_decode(name, stored_len, value);
if (len <= 0) {
if (value) {
*value = default_value;
}
}
} else {
if (value) {
*value = default_value;
}
}
return stored_len;
return stored_len;
}
/**
@@ -241,17 +241,17 @@ int bacnet_settings_signed_get(uint16_t object_type, uint32_t object_instance,
* @return true on success, false on failure.
*/
bool bacnet_settings_signed_set(uint16_t object_type, uint32_t object_instance,
uint32_t property_id, uint32_t array_index,
int32_t value)
uint32_t property_id, uint32_t array_index,
int32_t value)
{
BACNET_APPLICATION_DATA_VALUE bvalue = { 0 };
BACNET_APPLICATION_DATA_VALUE bvalue = { 0 };
bvalue.context_specific = false;
bvalue.tag = BACNET_APPLICATION_TAG_SIGNED_INT;
bvalue.type.Signed_Int = value;
bvalue.context_specific = false;
bvalue.tag = BACNET_APPLICATION_TAG_SIGNED_INT;
bvalue.type.Signed_Int = value;
return bacnet_settings_value_set(object_type, object_instance,
property_id, array_index, &bvalue);
return bacnet_settings_value_set(object_type, object_instance,
property_id, array_index, &bvalue);
}
/**
@@ -264,30 +264,30 @@ bool bacnet_settings_signed_set(uint16_t object_type, uint32_t object_instance,
* @return stored data length on success 0..N, negative on failure.
*/
int bacnet_settings_characterstring_get(uint16_t object_type,
uint32_t object_instance,
uint32_t property_id,
uint32_t array_index,
const char *default_value,
BACNET_CHARACTER_STRING *value)
uint32_t object_instance,
uint32_t property_id,
uint32_t array_index,
const char *default_value,
BACNET_CHARACTER_STRING *value)
{
uint8_t name[BACNET_STORAGE_VALUE_SIZE_MAX + 1] = { 0 };
BACNET_STORAGE_KEY key = { 0 };
int stored_len, len;
uint8_t name[BACNET_STORAGE_VALUE_SIZE_MAX + 1] = { 0 };
BACNET_STORAGE_KEY key = { 0 };
int stored_len, len;
bacnet_storage_key_init(&key, object_type, object_instance, property_id,
array_index);
stored_len = bacnet_storage_get(&key, name, sizeof(name));
if (stored_len > 0) {
len = bacnet_character_string_application_decode(
name, stored_len, value);
if (len <= 0) {
characterstring_init_ansi(value, default_value);
}
} else {
characterstring_init_ansi(value, default_value);
}
bacnet_storage_key_init(&key, object_type, object_instance, property_id,
array_index);
stored_len = bacnet_storage_get(&key, name, sizeof(name));
if (stored_len > 0) {
len = bacnet_character_string_application_decode(
name, stored_len, value);
if (len <= 0) {
characterstring_init_ansi(value, default_value);
}
} else {
characterstring_init_ansi(value, default_value);
}
return stored_len;
return stored_len;
}
/**
@@ -300,25 +300,25 @@ int bacnet_settings_characterstring_get(uint16_t object_type,
* @return true on success, false on failure.
*/
bool bacnet_settings_characterstring_ansi_set(uint16_t object_type,
uint32_t object_instance,
uint32_t property_id,
uint32_t array_index,
const char *cstring)
uint32_t object_instance,
uint32_t property_id,
uint32_t array_index,
const char *cstring)
{
BACNET_APPLICATION_DATA_VALUE bvalue = { 0 };
bool status;
BACNET_APPLICATION_DATA_VALUE bvalue = { 0 };
bool status;
bvalue.context_specific = false;
bvalue.tag = BACNET_APPLICATION_TAG_CHARACTER_STRING;
status = characterstring_init_ansi(&bvalue.type.Character_String,
cstring);
if (!status) {
status = bacnet_settings_value_set(object_type, object_instance,
property_id, array_index,
&bvalue);
}
bvalue.context_specific = false;
bvalue.tag = BACNET_APPLICATION_TAG_CHARACTER_STRING;
status = characterstring_init_ansi(&bvalue.type.Character_String,
cstring);
if (!status) {
status = bacnet_settings_value_set(object_type, object_instance,
property_id, array_index,
&bvalue);
}
return status;
return status;
}
/**
@@ -332,24 +332,24 @@ bool bacnet_settings_characterstring_ansi_set(uint16_t object_type,
* @return stored data length on success 0..N, negative on failure.
*/
int bacnet_settings_string_get(uint16_t object_type, uint32_t object_instance,
uint32_t property_id, uint32_t array_index,
const char *default_value, char *value,
size_t value_size)
uint32_t property_id, uint32_t array_index,
const char *default_value, char *value,
size_t value_size)
{
BACNET_STORAGE_KEY key = { 0 };
int rc;
BACNET_STORAGE_KEY key = { 0 };
int rc;
bacnet_storage_key_init(&key, object_type, object_instance, property_id,
array_index);
rc = bacnet_storage_get(&key, value, value_size);
if (rc <= 0) {
if (default_value) {
strncpy(value, default_value, value_size);
rc = strlen(default_value);
}
}
bacnet_storage_key_init(&key, object_type, object_instance, property_id,
array_index);
rc = bacnet_storage_get(&key, value, value_size);
if (rc <= 0) {
if (default_value) {
strncpy(value, default_value, value_size);
rc = strlen(default_value);
}
}
return rc;
return rc;
}
/**
@@ -362,18 +362,18 @@ int bacnet_settings_string_get(uint16_t object_type, uint32_t object_instance,
* @return true on success, false on failure.
*/
bool bacnet_settings_string_set(uint16_t object_type, uint32_t object_instance,
uint32_t property_id, uint32_t array_index,
const char *value)
uint32_t property_id, uint32_t array_index,
const char *value)
{
BACNET_STORAGE_KEY key = { 0 };
int rc;
BACNET_STORAGE_KEY key = { 0 };
int rc;
if (!value) {
return false;
}
bacnet_storage_key_init(&key, object_type, object_instance, property_id,
array_index);
rc = bacnet_storage_set(&key, (const char *)value, strlen(value) + 1);
if (!value) {
return false;
}
bacnet_storage_key_init(&key, object_type, object_instance, property_id,
array_index);
rc = bacnet_storage_set(&key, (const char *)value, strlen(value) + 1);
return rc == 0;
return rc == 0;
}
+74 -74
View File
@@ -19,48 +19,48 @@
* @return 0 on success, negative on failure
*/
static int cmd_key(BACNET_STORAGE_KEY *key, const struct shell *sh, size_t argc,
char **argv)
char **argv)
{
uint16_t object_type;
uint32_t object_instance;
uint32_t property_id = 77;
uint32_t array_index = BACNET_STORAGE_ARRAY_INDEX_NONE;
long value = 0;
uint16_t object_type;
uint32_t object_instance;
uint32_t property_id = 77;
uint32_t array_index = BACNET_STORAGE_ARRAY_INDEX_NONE;
long value = 0;
if (argc < 3) {
shell_error(
sh,
"Usage: %s <object-type> <instance> <property> [value]",
argv[0]);
return -EINVAL;
}
value = strtoul(argv[1], NULL, 0);
if ((value < 0) || (value >= UINT16_MAX)) {
shell_error(sh, "Invalid object-type: %s. Must be 0-65535.",
argv[1]);
return -EINVAL;
}
object_type = (uint16_t)value;
value = strtoul(argv[2], NULL, 0);
if (value > 4194303) {
shell_error(sh,
"Invalid object-instance: %s. Must be 0-4194303.",
argv[2]);
return -EINVAL;
}
object_instance = (uint32_t)value;
value = strtoul(argv[3], NULL, 0);
if (value > UINT32_MAX) {
shell_error(sh, "Invalid property: %s. Must be 0-4294967295.",
argv[3]);
return -EINVAL;
}
property_id = (uint32_t)value;
/* setup the storage key */
bacnet_storage_key_init(key, object_type, object_instance, property_id,
array_index);
if (argc < 3) {
shell_error(
sh,
"Usage: %s <object-type> <instance> <property> [value]",
argv[0]);
return -EINVAL;
}
value = strtoul(argv[1], NULL, 0);
if ((value < 0) || (value >= UINT16_MAX)) {
shell_error(sh, "Invalid object-type: %s. Must be 0-65535.",
argv[1]);
return -EINVAL;
}
object_type = (uint16_t)value;
value = strtoul(argv[2], NULL, 0);
if (value > 4194303) {
shell_error(sh,
"Invalid object-instance: %s. Must be 0-4194303.",
argv[2]);
return -EINVAL;
}
object_instance = (uint32_t)value;
value = strtoul(argv[3], NULL, 0);
if (value > UINT32_MAX) {
shell_error(sh, "Invalid property: %s. Must be 0-4294967295.",
argv[3]);
return -EINVAL;
}
property_id = (uint32_t)value;
/* setup the storage key */
bacnet_storage_key_init(key, object_type, object_instance, property_id,
array_index);
return 0;
return 0;
}
/**
@@ -72,45 +72,45 @@ static int cmd_key(BACNET_STORAGE_KEY *key, const struct shell *sh, size_t argc,
*/
static int cmd_string(const struct shell *sh, size_t argc, char **argv)
{
char key_name[BACNET_STORAGE_KEY_SIZE_MAX + 1] = { 0 };
uint8_t data[BACNET_STORAGE_VALUE_SIZE_MAX + 1] = { 0 };
BACNET_STORAGE_KEY key = { 0 };
size_t arg_len = 0;
int rc;
char key_name[BACNET_STORAGE_KEY_SIZE_MAX + 1] = { 0 };
uint8_t data[BACNET_STORAGE_VALUE_SIZE_MAX + 1] = { 0 };
BACNET_STORAGE_KEY key = { 0 };
size_t arg_len = 0;
int rc;
rc = cmd_key(&key, sh, argc, argv);
if (rc < 0) {
return rc;
}
/* convert the key to a string for the shell */
(void)bacnet_storage_key_encode(key_name, sizeof(key_name), &key);
if (argc > 4) {
arg_len = strlen(argv[4]);
rc = bacnet_storage_set(&key, argv[4], arg_len);
if (rc == 0) {
shell_print(sh, "Set %s = %s", key_name, argv[4]);
} else {
shell_error(sh, "Unable to set %s = %s", key_name,
argv[4]);
return -EINVAL;
}
} else {
rc = bacnet_storage_get(&key, data, sizeof(data));
if (rc < 0) {
shell_error(sh, "Unable to get %s", key_name);
return -EINVAL;
}
shell_print(sh, "Get %s = %s", key_name, data);
}
rc = cmd_key(&key, sh, argc, argv);
if (rc < 0) {
return rc;
}
/* convert the key to a string for the shell */
(void)bacnet_storage_key_encode(key_name, sizeof(key_name), &key);
if (argc > 4) {
arg_len = strlen(argv[4]);
rc = bacnet_storage_set(&key, argv[4], arg_len);
if (rc == 0) {
shell_print(sh, "Set %s = %s", key_name, argv[4]);
} else {
shell_error(sh, "Unable to set %s = %s", key_name,
argv[4]);
return -EINVAL;
}
} else {
rc = bacnet_storage_get(&key, data, sizeof(data));
if (rc < 0) {
shell_error(sh, "Unable to get %s", key_name);
return -EINVAL;
}
shell_print(sh, "Get %s = %s", key_name, data);
}
return 0;
return 0;
}
SHELL_STATIC_SUBCMD_SET_CREATE(sub_bacnet_settings_cmds,
SHELL_CMD(string, NULL,
"get or set BACnet storage string",
cmd_string),
SHELL_SUBCMD_SET_END);
SHELL_CMD(string, NULL,
"get or set BACnet storage string",
cmd_string),
SHELL_SUBCMD_SET_END);
SHELL_SUBCMD_ADD((bacnet), settings, &sub_bacnet_settings_cmds,
"BACnet settings commands", NULL, 1, 0);
"BACnet settings commands", NULL, 1, 0);
+131 -131
View File
@@ -41,38 +41,38 @@ LOG_MODULE_DECLARE(bacnet, CONFIG_BACNETSTACK_LOG_LEVEL);
*/
void bacnet_storage_init(void)
{
int rc;
int rc;
#if defined(CONFIG_SETTINGS_FILE) && defined(CONFIG_FILE_SYSTEM_LITTLEFS)
FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(cstorage);
FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(cstorage);
/* mounting info */
static struct fs_mount_t littlefs_mnt = {
.type = FS_LITTLEFS,
.fs_data = &cstorage,
.storage_dev = (void *)STORAGE_PARTITION_ID,
.mnt_point = "/ff"
};
/* mounting info */
static struct fs_mount_t littlefs_mnt = {
.type = FS_LITTLEFS,
.fs_data = &cstorage,
.storage_dev = (void *)STORAGE_PARTITION_ID,
.mnt_point = "/ff"
};
rc = fs_mount(&littlefs_mnt);
if (rc != 0) {
LOG_INF("mounting littlefs error: [%d]", rc);
} else {
rc = fs_unlink(CONFIG_SETTINGS_FILE_PATH);
if ((rc != 0) && (rc != -ENOENT)) {
H("can't delete config file%d", rc);
} else {
LOG_INF("FS initialized: OK");
}
}
rc = fs_mount(&littlefs_mnt);
if (rc != 0) {
LOG_INF("mounting littlefs error: [%d]", rc);
} else {
rc = fs_unlink(CONFIG_SETTINGS_FILE_PATH);
if ((rc != 0) && (rc != -ENOENT)) {
H("can't delete config file%d", rc);
} else {
LOG_INF("FS initialized: OK");
}
}
#endif
rc = settings_subsys_init();
if (rc) {
LOG_INF("settings subsys initialization: fail (err %d)", rc);
return;
}
rc = settings_subsys_init();
if (rc) {
LOG_INF("settings subsys initialization: fail (err %d)", rc);
return;
}
LOG_INF("settings subsys initialization: OK.");
LOG_INF("settings subsys initialization: OK.");
}
/**
@@ -84,15 +84,15 @@ void bacnet_storage_init(void)
* @param array_index BACnet array index
*/
void bacnet_storage_key_init(BACNET_STORAGE_KEY *key, uint16_t object_type,
uint32_t object_instance, uint32_t property_id,
uint32_t array_index)
uint32_t object_instance, uint32_t property_id,
uint32_t array_index)
{
if (key) {
key->object_type = object_type;
key->object_instance = object_instance;
key->property_id = property_id;
key->array_index = array_index;
}
if (key) {
key->object_type = object_type;
key->object_instance = object_instance;
key->property_id = property_id;
key->array_index = array_index;
}
}
/**
@@ -103,35 +103,35 @@ void bacnet_storage_key_init(BACNET_STORAGE_KEY *key, uint16_t object_type,
* @return length of the string
*/
int bacnet_storage_key_encode(char *buffer, size_t buffer_size,
BACNET_STORAGE_KEY *key)
BACNET_STORAGE_KEY *key)
{
int rc = 0;
const char base_name[] = CONFIG_BACNET_STORAGE_BASE_NAME;
int rc = 0;
const char base_name[] = CONFIG_BACNET_STORAGE_BASE_NAME;
if (buffer) {
memset(buffer, 0, buffer_size);
}
if (key->array_index == BACNET_STORAGE_ARRAY_INDEX_NONE) {
rc = snprintf(buffer, buffer_size, "%s%c%u%c%lu%c%lu",
base_name, SETTINGS_NAME_SEPARATOR,
(unsigned short)key->object_type,
SETTINGS_NAME_SEPARATOR,
(unsigned long)key->object_instance,
SETTINGS_NAME_SEPARATOR,
(unsigned long)key->property_id);
} else {
rc = snprintf(buffer, buffer_size, "%s%c%u%c%lu%c%lu%c%lu",
base_name, SETTINGS_NAME_SEPARATOR,
(unsigned short)key->object_type,
SETTINGS_NAME_SEPARATOR,
(unsigned long)key->object_instance,
SETTINGS_NAME_SEPARATOR,
(unsigned long)key->property_id,
SETTINGS_NAME_SEPARATOR,
(unsigned long)key->array_index);
}
if (buffer) {
memset(buffer, 0, buffer_size);
}
if (key->array_index == BACNET_STORAGE_ARRAY_INDEX_NONE) {
rc = snprintf(buffer, buffer_size, "%s%c%u%c%lu%c%lu",
base_name, SETTINGS_NAME_SEPARATOR,
(unsigned short)key->object_type,
SETTINGS_NAME_SEPARATOR,
(unsigned long)key->object_instance,
SETTINGS_NAME_SEPARATOR,
(unsigned long)key->property_id);
} else {
rc = snprintf(buffer, buffer_size, "%s%c%u%c%lu%c%lu%c%lu",
base_name, SETTINGS_NAME_SEPARATOR,
(unsigned short)key->object_type,
SETTINGS_NAME_SEPARATOR,
(unsigned long)key->object_instance,
SETTINGS_NAME_SEPARATOR,
(unsigned long)key->property_id,
SETTINGS_NAME_SEPARATOR,
(unsigned long)key->array_index);
}
return rc;
return rc;
}
/**
@@ -142,31 +142,31 @@ int bacnet_storage_key_encode(char *buffer, size_t buffer_size,
* @return 0 on success, non-zero on failure.
*/
int bacnet_storage_set(BACNET_STORAGE_KEY *key, const void *data,
size_t data_len)
size_t data_len)
{
char name[SETTINGS_MAX_NAME_LEN + 1] = { 0 };
int rc;
char name[SETTINGS_MAX_NAME_LEN + 1] = { 0 };
int rc;
rc = bacnet_storage_key_encode(name, sizeof(name), key);
LOG_INF("Set a key-value pair. Key=%s", name);
rc = settings_save_one(name, data, data_len);
if (rc) {
LOG_INF(FAIL_MSG, rc);
} else {
LOG_HEXDUMP_INF(data, data_len, "value");
}
rc = bacnet_storage_key_encode(name, sizeof(name), key);
LOG_INF("Set a key-value pair. Key=%s", name);
rc = settings_save_one(name, data, data_len);
if (rc) {
LOG_INF(FAIL_MSG, rc);
} else {
LOG_HEXDUMP_INF(data, data_len, "value");
}
return rc;
return rc;
}
/**
/**
* @brief Structure to hold immediate values
*/
struct direct_immediate_value {
size_t value_size;
size_t value_len;
void *value;
bool fetched;
size_t value_size;
size_t value_len;
void *value;
bool fetched;
};
/**
@@ -179,33 +179,33 @@ struct direct_immediate_value {
* @return 0 on success, non-zero on failure.
*/
static int direct_loader_immediate_value(const char *name, size_t len,
settings_read_cb read_cb, void *cb_arg,
void *param)
settings_read_cb read_cb, void *cb_arg,
void *param)
{
const char *next;
size_t name_len;
int rc;
struct direct_immediate_value *context =
(struct direct_immediate_value *)param;
const char *next;
size_t name_len;
int rc;
struct direct_immediate_value *context =
(struct direct_immediate_value *)param;
/* only the exact match and ignore descendants of the searched name */
name_len = settings_name_next(name, &next);
if (name_len == 0) {
rc = read_cb(cb_arg, context->value, len);
if ((rc >= 0) && (rc <= context->value_size)) {
context->fetched = true;
context->value_len = rc;
LOG_INF("immediate load: OK.");
return 0;
}
return -EINVAL;
}
/* only the exact match and ignore descendants of the searched name */
name_len = settings_name_next(name, &next);
if (name_len == 0) {
rc = read_cb(cb_arg, context->value, len);
if ((rc >= 0) && (rc <= context->value_size)) {
context->fetched = true;
context->value_len = rc;
LOG_INF("immediate load: OK.");
return 0;
}
return -EINVAL;
}
/* other keys aren't served by the callback
* Return success in order to skip them
* and keep storage processing.
*/
return 0;
/* other keys aren't served by the callback
* Return success in order to skip them
* and keep storage processing.
*/
return 0;
}
/**
@@ -216,25 +216,25 @@ static int direct_loader_immediate_value(const char *name, size_t len,
* @return value length in bytes on success 0..N, negative on failure.
*/
static int load_immediate_value(const char *name, void *value,
size_t value_size)
size_t value_size)
{
int rc;
struct direct_immediate_value context;
int rc;
struct direct_immediate_value context;
context.fetched = false;
context.value_size = value_size;
context.value_len = 0;
context.value = value;
context.fetched = false;
context.value_size = value_size;
context.value_len = 0;
context.value = value;
rc = settings_load_subtree_direct(name, direct_loader_immediate_value,
(void *)&context);
if (rc == 0) {
if (!context.fetched) {
rc = -ENOENT;
}
}
rc = settings_load_subtree_direct(name, direct_loader_immediate_value,
(void *)&context);
if (rc == 0) {
if (!context.fetched) {
rc = -ENOENT;
}
}
return context.value_len;
return context.value_len;
}
/**
@@ -246,21 +246,21 @@ static int load_immediate_value(const char *name, void *value,
*/
int bacnet_storage_get(BACNET_STORAGE_KEY *key, void *data, size_t data_size)
{
char name[SETTINGS_MAX_NAME_LEN + 1] = { 0 };
int rc;
char name[SETTINGS_MAX_NAME_LEN + 1] = { 0 };
int rc;
rc = bacnet_storage_key_encode(name, sizeof(name), key);
LOG_INF("Get a key-value pair. Key=<%s>", name);
rc = load_immediate_value(name, data, data_size);
if (rc == 0) {
LOG_INF("empty entry");
} else if (rc > 0) {
LOG_HEXDUMP_INF(data, rc, "value");
} else if (rc == -ENOENT) {
LOG_INF("no entry");
} else {
LOG_INF("unexpected" FAIL_MSG, rc);
}
rc = bacnet_storage_key_encode(name, sizeof(name), key);
LOG_INF("Get a key-value pair. Key=<%s>", name);
rc = load_immediate_value(name, data, data_size);
if (rc == 0) {
LOG_INF("empty entry");
} else if (rc > 0) {
LOG_HEXDUMP_INF(data, rc, "value");
} else if (rc == -ENOENT) {
LOG_INF("no entry");
} else {
LOG_INF("unexpected" FAIL_MSG, rc);
}
return rc;
return rc;
}