Skip to content

Commit baee75d

Browse files
authored
Merge pull request #33 from bacnet-stack/feature/bacnet-settings-restore
Feature/bacnet settings restore
2 parents 3d006da + c4c963f commit baee75d

35 files changed

+3140
-1963
lines changed

.clang-format

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
BasedOnStyle: WebKit
3+
AlignAfterOpenBracket: AlwaysBreak
4+
BinPackArguments: true
5+
BinPackParameters: false
6+
PenaltyBreakBeforeFirstCallParameter: 1
7+
AllowShortFunctionsOnASingleLine: None
8+
AllowShortIfStatementsOnASingleLine: false
9+
AllowShortLoopsOnASingleLine: false
10+
AlignEscapedNewlines: Left
11+
AlignArrayOfStructures: None
12+
PointerAlignment: Right
13+
InsertBraces: true
14+
BreakBeforeBraces: Linux
15+
BreakBeforeBinaryOperators: None
16+
KeepEmptyLinesAtTheStartOfBlocks: false
17+
IndentCaseLabels: true
18+
IndentWidth: 4
19+
UseTab: Never
20+
SortIncludes: false
21+
ColumnLimit: 80
22+
# Const always to left side.
23+
QualifierAlignment: Left
24+
---
25+
Language: JavaScript
26+
DisableFormat: true
27+
...

.pre-commit-config.yaml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,17 @@ repos:
4141
- id: remove-tabs
4242
name: Remove tabs (4 spaces)
4343
args: ["--whitespaces-count", "4"]
44-
exclude: \.(yaml|yml|html|htm|sln|atsln|layout)$|Makefile|\.(mgw|mak|MAK)$|Dockerfile$
44+
exclude: \.(c|h|yaml|yml|overlay|html|htm|sln|atsln|layout|rst)$|Makefile|\.(mgw|mak|MAK)|Dockerfile$
4545
- id: remove-tabs
4646
name: Remove tabs (2 spaces)
4747
args: ["--whitespaces-count", "2"]
48-
files: '.*\.(yaml|yml|html|htm)|Dockerfile$'
48+
files: '.*\.(yaml|yml|overlay|html|htm)|Dockerfile$'
4949

5050
- repo: https://github.com/pre-commit/mirrors-clang-format
5151
rev: v20.1.5
5252
hooks:
5353
- id: clang-format
5454

55-
# We might enable this in future.
56-
# - repo: https://github.com/pre-commit/mirrors-prettier
57-
# rev: ffb6a759a979008c0e6dff86e39f4745a2d9eac4 # v3.1.0
58-
# hooks:
59-
# - id: prettier
60-
6155
- repo: https://github.com/pre-commit/pygrep-hooks
6256
rev: v1.10.0
6357
hooks:

west.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ manifest:
4141
revision: master
4242
- name: zephyr
4343
path: zephyr
44-
revision: v3.7.0
44+
revision: v3.7.1
4545
remote: zephyrproject-rtos
4646
west-commands: scripts/west-commands.yml
4747
import:

zephyr/.clang-format

Lines changed: 0 additions & 94 deletions
This file was deleted.

zephyr/include/bacnet-config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef BACNET_PORTS_ZEPHYR_BACNET_CONFIG_H
99
#define BACNET_PORTS_ZEPHYR_BACNET_CONFIG_H
1010

11-
#if ! defined BACNET_CONFIG_H || ! BACNET_CONFIG_H
11+
#if !defined BACNET_CONFIG_H || !BACNET_CONFIG_H
1212
#error bacnet-config.h included outside of BACNET_CONFIG_H control
1313
#endif
1414

zephyr/include/bacnet_settings/bacnet_settings.h

Lines changed: 103 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,55 +17,122 @@
1717
#include "bacnet/bacint.h"
1818
#include "bacnet/wp.h"
1919

20+
/**
21+
* @brief Callback data for WriteProperty restore iterator
22+
* @param write_function The WriteProperty function to call
23+
* @param context The context to pass to the WriteProperty function
24+
* @return true if the WriteProperty succeeded
25+
*/
26+
typedef bool (*bacnet_settings_restore_callback)(
27+
BACNET_WRITE_PROPERTY_DATA *wp_data, void *context);
28+
2029
#ifdef __cplusplus
2130
extern "C" {
2231
#endif /* __cplusplus */
2332

24-
void bacnet_settings_basic_store(BACNET_OBJECT_TYPE object_type, uint32_t object_instance,
25-
BACNET_PROPERTY_ID object_property, BACNET_ARRAY_INDEX array_index,
26-
uint8_t *application_data, int application_data_len);
33+
void bacnet_settings_basic_store(
34+
BACNET_OBJECT_TYPE object_type,
35+
uint32_t object_instance,
36+
BACNET_PROPERTY_ID object_property,
37+
BACNET_ARRAY_INDEX array_index,
38+
uint8_t *application_data,
39+
int application_data_len);
2740
bool bacnet_settings_write_property_store(BACNET_WRITE_PROPERTY_DATA *wp_data);
28-
bool bacnet_settings_write_property_restore(uint16_t object_type, uint32_t object_instance,
29-
uint32_t property_id, uint32_t array_index,
30-
write_property_function write_function);
41+
bool bacnet_settings_write_property_restore(
42+
bacnet_settings_restore_callback cb, void *context);
43+
44+
int bacnet_settings_value_get(
45+
uint16_t object_type,
46+
uint32_t object_instance,
47+
uint32_t property_id,
48+
uint32_t array_index,
49+
BACNET_APPLICATION_DATA_VALUE *value);
50+
bool bacnet_settings_value_set(
51+
uint16_t object_type,
52+
uint32_t object_instance,
53+
uint32_t property_id,
54+
uint32_t array_index,
55+
BACNET_APPLICATION_DATA_VALUE *value);
56+
bool bacnet_settings_value_parse(
57+
const char *value_string,
58+
uint16_t object_type,
59+
uint32_t property_id,
60+
BACNET_APPLICATION_DATA_VALUE *value);
3161

32-
int bacnet_settings_value_get(uint16_t object_type, uint32_t object_instance, uint32_t property_id,
33-
uint32_t array_index, BACNET_APPLICATION_DATA_VALUE *value);
34-
bool bacnet_settings_value_set(uint16_t object_type, uint32_t object_instance, uint32_t property_id,
35-
uint32_t array_index, BACNET_APPLICATION_DATA_VALUE *value);
62+
int bacnet_settings_real_get(
63+
uint16_t object_type,
64+
uint32_t object_instance,
65+
uint32_t property_id,
66+
uint32_t array_index,
67+
float default_value,
68+
float *value);
69+
bool bacnet_settings_real_set(
70+
uint16_t object_type,
71+
uint32_t object_instance,
72+
uint32_t property_id,
73+
uint32_t array_index,
74+
float value);
3675

37-
int bacnet_settings_real_get(uint16_t object_type, uint32_t object_instance, uint32_t property_id,
38-
uint32_t array_index, float default_value, float *value);
39-
bool bacnet_settings_real_set(uint16_t object_type, uint32_t object_instance, uint32_t property_id,
40-
uint32_t array_index, float value);
76+
int bacnet_settings_unsigned_get(
77+
uint16_t object_type,
78+
uint32_t object_instance,
79+
uint32_t property_id,
80+
uint32_t array_index,
81+
BACNET_UNSIGNED_INTEGER default_value,
82+
BACNET_UNSIGNED_INTEGER *value);
83+
bool bacnet_settings_unsigned_set(
84+
uint16_t object_type,
85+
uint32_t object_instance,
86+
uint32_t property_id,
87+
uint32_t array_index,
88+
BACNET_UNSIGNED_INTEGER value);
4189

42-
int bacnet_settings_unsigned_get(uint16_t object_type, uint32_t object_instance,
43-
uint32_t property_id, uint32_t array_index,
44-
BACNET_UNSIGNED_INTEGER default_value,
45-
BACNET_UNSIGNED_INTEGER *value);
46-
bool bacnet_settings_unsigned_set(uint16_t object_type, uint32_t object_instance,
47-
uint32_t property_id, uint32_t array_index,
48-
BACNET_UNSIGNED_INTEGER value);
90+
int bacnet_settings_signed_get(
91+
uint16_t object_type,
92+
uint32_t object_instance,
93+
uint32_t property_id,
94+
uint32_t array_index,
95+
int32_t default_value,
96+
int32_t *value);
97+
bool bacnet_settings_signed_set(
98+
uint16_t object_type,
99+
uint32_t object_instance,
100+
uint32_t property_id,
101+
uint32_t array_index,
102+
int32_t value);
49103

50-
int bacnet_settings_signed_get(uint16_t object_type, uint32_t object_instance, uint32_t property_id,
51-
uint32_t array_index, int32_t default_value, int32_t *value);
52-
bool bacnet_settings_signed_set(uint16_t object_type, uint32_t object_instance,
53-
uint32_t property_id, uint32_t array_index, int32_t value);
104+
int bacnet_settings_characterstring_get(
105+
uint16_t object_type,
106+
uint32_t object_instance,
107+
uint32_t property_id,
108+
uint32_t array_index,
109+
const char *default_value,
110+
BACNET_CHARACTER_STRING *value);
54111

55-
int bacnet_settings_characterstring_get(uint16_t object_type, uint32_t object_instance,
56-
uint32_t property_id, uint32_t array_index,
57-
const char *default_value, BACNET_CHARACTER_STRING *value);
112+
bool bacnet_settings_characterstring_ansi_set(
113+
uint16_t object_type,
114+
uint32_t object_instance,
115+
uint32_t property_id,
116+
uint32_t array_index,
117+
const char *cstring);
58118

59-
bool bacnet_settings_characterstring_ansi_set(uint16_t object_type, uint32_t object_instance,
60-
uint32_t property_id, uint32_t array_index,
61-
const char *cstring);
119+
int bacnet_settings_string_get(
120+
uint16_t object_type,
121+
uint32_t object_instance,
122+
uint32_t property_id,
123+
uint32_t array_index,
124+
const char *default_value,
125+
char *value,
126+
size_t value_size);
62127

63-
int bacnet_settings_string_get(uint16_t object_type, uint32_t object_instance, uint32_t property_id,
64-
uint32_t array_index, const char *default_value, char *value,
65-
size_t value_size);
128+
bool bacnet_settings_string_set(
129+
uint16_t object_type,
130+
uint32_t object_instance,
131+
uint32_t property_id,
132+
uint32_t array_index,
133+
const char *value);
66134

67-
bool bacnet_settings_string_set(uint16_t object_type, uint32_t object_instance,
68-
uint32_t property_id, uint32_t array_index, const char *value);
135+
bool bacnet_settings_init(void);
69136

70137
#ifdef __cplusplus
71138
}

zephyr/include/bacnet_settings/bacnet_storage.h

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,59 @@
1111

1212
#include <stddef.h>
1313
#include <stdint.h>
14+
#include <stdbool.h>
15+
#include <errno.h>
1416
#include <zephyr/settings/settings.h>
1517

1618
#define BACNET_STORAGE_VALUE_SIZE_MAX SETTINGS_MAX_VAL_LEN
1719
#define BACNET_STORAGE_KEY_SIZE_MAX SETTINGS_MAX_NAME_LEN
1820
#define BACNET_STORAGE_ARRAY_INDEX_NONE UINT32_MAX
1921

2022
typedef struct bacnet_storage_key_t {
21-
uint16_t object_type;
22-
uint32_t object_instance;
23-
uint32_t property_id;
24-
uint32_t array_index;
23+
uint16_t object_type;
24+
uint32_t object_instance;
25+
uint32_t property_id;
26+
uint32_t array_index;
2527
} BACNET_STORAGE_KEY;
2628

29+
typedef int (*bacnet_storage_restore_callback)(
30+
BACNET_STORAGE_KEY *key, const void *data, size_t data_size, void *context);
31+
2732
#ifdef __cplusplus
2833
extern "C" {
2934
#endif /* __cplusplus */
3035

31-
void bacnet_storage_init(void);
36+
int bacnet_storage_init(void);
37+
38+
int bacnet_storage_load_callback_set(
39+
bacnet_storage_restore_callback cb, void *context);
40+
int bacnet_storage_load(void);
41+
42+
int bacnet_storage_handler_set(
43+
const char *name, size_t len, settings_read_cb read_cb, void *cb_arg);
44+
int bacnet_storage_handler_commit(void);
45+
int bacnet_storage_handler_export(
46+
int (*cb)(const char *name, const void *value, size_t val_len));
47+
48+
bool bacnet_storage_strtoul(const char *search_name, unsigned long *long_value);
49+
bool bacnet_storage_strtol(const char *search_name, long *long_value);
50+
bool bacnet_storage_strtof(const char *search_name, float *float_value);
51+
52+
void bacnet_storage_key_init(
53+
BACNET_STORAGE_KEY *key,
54+
uint16_t object_type,
55+
uint32_t object_instance,
56+
uint32_t property_id,
57+
uint32_t array_index);
58+
int bacnet_storage_key_parse(BACNET_STORAGE_KEY *key, size_t argc, char **argv);
59+
int bacnet_storage_key_decode(const char *path, BACNET_STORAGE_KEY *key);
60+
int bacnet_storage_key_encode(
61+
char *buffer, size_t buffer_size, BACNET_STORAGE_KEY *key);
3262

33-
void bacnet_storage_key_init(BACNET_STORAGE_KEY *key, uint16_t object_type,
34-
uint32_t object_instance, uint32_t property_id,
35-
uint32_t array_index);
36-
int bacnet_storage_key_encode(char *buffer, size_t buffer_size,
37-
BACNET_STORAGE_KEY *key);
38-
int bacnet_storage_set(BACNET_STORAGE_KEY *key, const void *data,
39-
size_t data_size);
63+
int bacnet_storage_set(
64+
BACNET_STORAGE_KEY *key, const void *data, size_t data_size);
4065
int bacnet_storage_get(BACNET_STORAGE_KEY *key, void *data, size_t data_size);
66+
int bacnet_storage_delete(BACNET_STORAGE_KEY *key);
4167

4268
#ifdef __cplusplus
4369
}

0 commit comments

Comments
 (0)