Skip to content

Commit d577240

Browse files
committed
app: Fix build errors
* Fix build errors in all modules * Align use of SMF macros Signed-off-by: Jan Tore Guggedal <jantore.guggedal@nordicsemi.no>
1 parent 4c7aec5 commit d577240

20 files changed

+149
-497
lines changed

app/src/common/message_channel.h

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ struct payload {
5555
enum network_status {
5656
NETWORK_DISCONNECTED = 0x1,
5757
NETWORK_CONNECTED,
58+
NETWORK_UICC_FAILURE,
59+
NETWORK_DISCONNECT,
60+
NETWORK_CONNECT,
61+
NETWORK_QUALITY_SAMPLE,
5862
};
5963

6064
#define MSG_TO_NETWORK_STATUS(_msg) (*(const enum network_status *)_msg)

app/src/common/modules_common.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern "C" {
1818
*
1919
* @return see smf_set_initial().
2020
*/
21-
#define STATE_SET_INITIAL(_state) smf_set_initial(SMF_CTX(&_state_obj), &states[_state])
21+
#define STATE_SET_INITIAL(_state_obj, _state) smf_set_initial(SMF_CTX(&_state_obj), &states[_state])
2222

2323
/** @brief Set the state for a module.
2424
*
@@ -27,15 +27,15 @@ extern "C" {
2727
*
2828
* @return see smf_set_state().
2929
*/
30-
#define STATE_SET(_state) smf_set_state(SMF_CTX(&_state_obj), &states[_state])
30+
#define STATE_SET(_state_obj, _state) smf_set_state(SMF_CTX(&_state_obj), &states[_state])
3131

3232
/** @brief Set the state for a module and handle the event.
3333
*
3434
* @param _state_obj State machine object.
3535
*
3636
* @return see smf_set_handled().
3737
*/
38-
#define STATE_EVENT_HANDLED(_state_obj) smf_set_handled(SMF_CTX(&_state_obj))
38+
#define STATE_EVENT_HANDLED(_state_obj) smf_set_handled(SMF_CTX(&_state_obj))
3939

4040
/** @brief Run the state machine for a module.
4141
*

app/src/modules/app/CMakeLists.txt

-29
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,3 @@
55
#
66

77
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/app.c)
8-
9-
# generate encoder code using zcbor
10-
set(zcbor_command
11-
zcbor code # Invoke code generation
12-
--cddl ${ZEPHYR_BASE}/subsys/net/lib/lwm2m/lwm2m_senml_cbor.cddl
13-
--cddl ${CMAKE_CURRENT_SOURCE_DIR}/app_object.cddl
14-
--decode # Generate decoding functions
15-
--short-names # Attempt to make generated symbol names shorter (at the risk of collision)
16-
-t app-object # Create a public API for decoding the "app_object" type from the cddl file
17-
--output-cmake app_object.cmake # The generated cmake file will be placed here
18-
)
19-
execute_process(COMMAND ${zcbor_command}
20-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
21-
COMMAND_ERROR_IS_FATAL ANY)
22-
23-
# Include the cmake file generated by zcbor. It adds the
24-
# generated code and the necessary zcbor C code files.
25-
include(${CMAKE_CURRENT_BINARY_DIR}/app_object.cmake)
26-
27-
# Ensure that the cmake reconfiguration is triggerred everytime the cddl file changes.
28-
# This ensures that the codec generation is triggered.
29-
set_property(
30-
DIRECTORY
31-
PROPERTY
32-
CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/app_object.cddl
33-
)
34-
35-
zephyr_link_libraries(app_object)
36-
target_link_libraries(app_object PRIVATE zephyr_interface)

app/src/modules/app/Kconfig.app

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
module = APP
2-
module-str = APP
3-
source "subsys/logging/Kconfig.template.log_config"
4-
1+
#
2+
# Copyright (c) 2023 Nordic Semiconductor
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
56
menu "App"
67

78
config APP_MODULE_THREAD_STACK_SIZE
@@ -22,4 +23,9 @@ config APP_MODULE_RECV_BUFFER_SIZE
2223
int "Receive buffer size"
2324
default 1024
2425

26+
27+
module = APP
28+
module-str = APP
29+
source "subsys/logging/Kconfig.template.log_config"
30+
2531
endmenu

app/src/modules/app/app.c

+6-114
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#endif /* CONFIG_MEMFAULT */
1818

1919
#include "message_channel.h"
20-
#include "app_object_decode.h"
2120

2221
/* Register log module */
2322
LOG_MODULE_REGISTER(app, CONFIG_APP_LOG_LEVEL);
@@ -37,16 +36,13 @@ BUILD_ASSERT(CONFIG_APP_MODULE_WATCHDOG_TIMEOUT_SECONDS > CONFIG_APP_MODULE_EXEC
3736
static void shadow_get(bool delta_only)
3837
{
3938
int err;
40-
struct app_object app_object = { 0 };
41-
struct configuration configuration = { 0 };
42-
uint8_t buf_cbor[CONFIG_APP_MODULE_RECV_BUFFER_SIZE] = { 0 };
43-
size_t buf_cbor_len = sizeof(buf_cbor);
44-
size_t not_used;
39+
uint8_t recv_buf[CONFIG_APP_MODULE_RECV_BUFFER_SIZE] = { 0 };
40+
size_t recv_buf_len = sizeof(recv_buf);
4541

46-
LOG_DBG("Requesting device configuration from the device shadow");
42+
LOG_DBG("Requesting device shadow from the device");
4743

48-
err = nrf_cloud_coap_shadow_get(buf_cbor, &buf_cbor_len, delta_only,
49-
COAP_CONTENT_FORMAT_APP_CBOR);
44+
err = nrf_cloud_coap_shadow_get(recv_buf, &recv_buf_len, delta_only,
45+
COAP_CONTENT_FORMAT_APP_JSON);
5046
if (err == -EACCES) {
5147
LOG_WRN("Not connected, error: %d", err);
5248
return;
@@ -65,111 +61,7 @@ static void shadow_get(bool delta_only)
6561
return;
6662
}
6763

68-
if (buf_cbor_len == 0) {
69-
LOG_DBG("No shadow delta changes available");
70-
return;
71-
}
72-
73-
/* Workaroud: Sometimes nrf_cloud_coap_shadow_get() returns 0 even though obtaining
74-
* the shadow failed. Ignore the payload if the first 10 bytes are zero.
75-
*/
76-
if (!memcmp(buf_cbor, "\0\0\0\0\0\0\0\0\0\0", 10)) {
77-
LOG_WRN("Returned buffer is empty, ignore");
78-
return;
79-
}
80-
81-
err = cbor_decode_app_object(buf_cbor, buf_cbor_len, &app_object, &not_used);
82-
if (err) {
83-
/* Do not throw an error if decoding fails. This might occur if the shadow
84-
* structure or content changes. In such cases, we need to ensure the possibility
85-
* of performing a Firmware Over-The-Air (FOTA) update to address the issue.
86-
* Hardfaulting would prevent FOTA, hence it should be avoided.
87-
*/
88-
LOG_ERR("Ignoring incoming configuration change due to decoding error: %d", err);
89-
LOG_HEXDUMP_ERR(buf_cbor, buf_cbor_len, "CBOR data");
90-
91-
IF_ENABLED(CONFIG_MEMFAULT,
92-
(MEMFAULT_TRACE_EVENT_WITH_STATUS(cbor_decode_app_object, err)));
93-
94-
return;
95-
}
96-
97-
if (!app_object.lwm2m_present) {
98-
LOG_DBG("No LwM2M object present in shadow, ignoring");
99-
return;
100-
}
101-
102-
if (app_object.lwm2m.lwm2m._1424010_present) {
103-
configuration.led_present = true;
104-
105-
configuration.led_red = app_object.lwm2m.lwm2m._1424010._1424010._0._0._0;
106-
configuration.led_red_present =
107-
app_object.lwm2m.lwm2m._1424010._1424010._0._0_present;
108-
109-
configuration.led_green = app_object.lwm2m.lwm2m._1424010._1424010._0._1._1;
110-
configuration.led_green_present =
111-
app_object.lwm2m.lwm2m._1424010._1424010._0._1_present;
112-
113-
configuration.led_blue = app_object.lwm2m.lwm2m._1424010._1424010._0._2._2;
114-
configuration.led_blue_present =
115-
app_object.lwm2m.lwm2m._1424010._1424010._0._2_present;
116-
117-
LOG_DBG("LED object (1424010) values received from cloud:");
118-
119-
if (configuration.led_red_present) {
120-
LOG_DBG("New RED value: %d", configuration.led_red);
121-
}
122-
123-
if (configuration.led_green_present) {
124-
LOG_DBG("New GREEN value: %d", configuration.led_green);
125-
}
126-
127-
if (configuration.led_blue_present) {
128-
LOG_DBG("New BLUE value: %d", configuration.led_blue);
129-
}
130-
131-
LOG_DBG("Timestamp: %lld", app_object.lwm2m.lwm2m._1424010._1424010._0._99);
132-
}
133-
134-
if (app_object.lwm2m.lwm2m._1430110_present) {
135-
configuration.config_present = true;
136-
137-
configuration.update_interval = app_object.lwm2m.lwm2m._1430110._1430110._0._0._0;
138-
configuration.update_interval_present =
139-
app_object.lwm2m.lwm2m._1430110._1430110._0._0_present;
140-
141-
configuration.gnss = app_object.lwm2m.lwm2m._1430110._1430110._0._1._1;
142-
configuration.gnss_present = app_object.lwm2m.lwm2m._1430110._1430110._0._1_present;
143-
144-
LOG_DBG("Application configuration object (1430110) values received from cloud:");
145-
146-
if (configuration.update_interval_present) {
147-
LOG_DBG("New update interval: %lld", configuration.update_interval);
148-
}
149-
150-
if (configuration.gnss_present) {
151-
LOG_DBG("New GNSS setting: %d", configuration.gnss);
152-
}
153-
154-
LOG_DBG("Timestamp: %lld", app_object.lwm2m.lwm2m._1430110._1430110._0._99);
155-
}
156-
157-
/* Distribute configuration */
158-
err = zbus_chan_pub(&CONFIG_CHAN, &configuration, K_SECONDS(1));
159-
if (err) {
160-
LOG_ERR("zbus_chan_pub, error: %d", err);
161-
SEND_FATAL_ERROR();
162-
return;
163-
}
164-
165-
/* Send the received configuration back to the reported shadow section. */
166-
err = nrf_cloud_coap_patch("state/reported", NULL, (uint8_t *)buf_cbor,
167-
buf_cbor_len, COAP_CONTENT_FORMAT_APP_CBOR, true, NULL, NULL);
168-
if (err < 0) {
169-
LOG_ERR("Failed to send PATCH request: %d", err);
170-
} else if (err > 0) {
171-
LOG_ERR("Error from server: %d", err);
172-
}
64+
/* No further processing of shadow is implemented */
17365
}
17466

17567
static void task_wdt_callback(int channel_id, void *user_data)

app/src/modules/battery/CMakeLists.txt

-21
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,3 @@
55
#
66

77
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/battery.c)
8-
9-
# generate encoder code using zcbor
10-
set(zcbor_command
11-
zcbor code # Invoke code generation
12-
--cddl ${ZEPHYR_BASE}/subsys/net/lib/lwm2m/lwm2m_senml_cbor.cddl
13-
--cddl ${CMAKE_CURRENT_SOURCE_DIR}/bat_object.cddl
14-
--encode # Generate encoding functions
15-
--short-names # Attempt to make generated symbol names shorter (at the risk of collision)
16-
-t bat-object # Create a public API for decoding/encoding the "bat-object" type from the cddl file
17-
--output-cmake bat_object.cmake # The generated cmake file will be placed here
18-
)
19-
execute_process(COMMAND ${zcbor_command}
20-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
21-
COMMAND_ERROR_IS_FATAL ANY)
22-
23-
# Include the cmake file generated by zcbor. It adds the
24-
# generated code and the necessary zcbor C code files.
25-
include(${CMAKE_CURRENT_BINARY_DIR}/bat_object.cmake)
26-
27-
zephyr_link_libraries(bat_object)
28-
target_link_libraries(bat_object PRIVATE zephyr_interface)

app/src/modules/battery/Kconfig.battery

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#
2-
# Copyright (c) 2023 Nordic Semiconductor
2+
# Copyright (c) 2024 Nordic Semiconductor
33
#
44
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
#
66

7-
menu "Sampler"
7+
menu "Battery"
88

99
config APP_BATTERY_THREAD_STACK_SIZE
1010
int "Thread stack size"
@@ -24,4 +24,4 @@ module = APP_BATTERY
2424
module-str = Battery
2525
source "subsys/logging/Kconfig.template.log_config"
2626

27-
endmenu # Sampler
27+
endmenu # Battery

app/src/modules/battery/battery.c

+5-26
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "lp803448_model.h"
1919
#include "message_channel.h"
2020
#include "modules_common.h"
21-
#include "bat_object_encode.h"
2221

2322
/* Register log module */
2423
LOG_MODULE_REGISTER(battery, CONFIG_APP_BATTERY_LOG_LEVEL);
@@ -89,7 +88,7 @@ static void state_init_entry(void *o);
8988
static void state_init_run(void *o);
9089
static void state_sampling_run(void *o);
9190

92-
static struct s_object s_obj;
91+
static struct s_object battery_state_object;
9392
static const struct smf_state states[] = {
9493
[STATE_INIT] =
9594
SMF_CREATE_STATE(state_init_entry, state_init_run, NULL,
@@ -153,7 +152,7 @@ static void state_init_run(void *o)
153152
if (time_status == TIME_AVAILABLE) {
154153
LOG_DBG("Time available, sampling can start");
155154

156-
STATE_SET(STATE_SAMPLING);
155+
STATE_SET(battery_state_object, STATE_SAMPLING);
157156
}
158157
}
159158
}
@@ -210,8 +209,6 @@ static void sample(int64_t *ref_time)
210209
float temp;
211210
float state_of_charge;
212211
float delta;
213-
struct bat_object bat_object = { 0 };
214-
struct payload payload = { 0 };
215212
int64_t system_time;
216213

217214
err = date_time_now(&system_time);
@@ -238,25 +235,7 @@ static void sample(int64_t *ref_time)
238235
LOG_DBG("State of charge: %f", (double)roundf(state_of_charge));
239236
LOG_DBG("The battery is %s", charging ? "charging" : "not charging");
240237

241-
bat_object.state_of_charge_m.bt = (int32_t)(system_time / 1000);
242-
bat_object.state_of_charge_m.vi = (int32_t)(state_of_charge + 0.5f);
243-
bat_object.voltage_m.vf = voltage;
244-
bat_object.temperature_m.vf = temp;
245-
246-
err = cbor_encode_bat_object(payload.buffer, sizeof(payload.buffer),
247-
&bat_object, &payload.buffer_len);
248-
if (err) {
249-
LOG_ERR("Failed to encode env object, error: %d", err);
250-
SEND_FATAL_ERROR();
251-
return;
252-
}
253-
254-
err = zbus_chan_pub(&PAYLOAD_CHAN, &payload, K_SECONDS(1));
255-
if (err) {
256-
LOG_ERR("zbus_chan_pub, error: %d", err);
257-
SEND_FATAL_ERROR();
258-
return;
259-
}
238+
/* No further use of the battery data is implemented */
260239
}
261240

262241
static void task_wdt_callback(int channel_id, void *user_data)
@@ -279,7 +258,7 @@ static void battery_task(void)
279258

280259
task_wdt_id = task_wdt_add(wdt_timeout_ms, task_wdt_callback, (void *)k_current_get());
281260

282-
STATE_SET_INITIAL(STATE_INIT);
261+
STATE_SET_INITIAL(battery_state_object, STATE_INIT);
283262

284263
while (true) {
285264
err = task_wdt_feed(task_wdt_id);
@@ -298,7 +277,7 @@ static void battery_task(void)
298277
return;
299278
}
300279

301-
err = STATE_RUN();
280+
err = STATE_RUN(battery_state_object);
302281
if (err) {
303282
LOG_ERR("handle_message, error: %d", err);
304283
SEND_FATAL_ERROR();

app/src/modules/button/CMakeLists.txt

-21
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,3 @@
55
#
66

77
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/button.c)
8-
9-
# generate encoder code using zcbor
10-
set(zcbor_command
11-
zcbor code # Invoke code generation
12-
--cddl ${ZEPHYR_BASE}/subsys/net/lib/lwm2m/lwm2m_senml_cbor.cddl
13-
--cddl ${CMAKE_CURRENT_SOURCE_DIR}/button_object.cddl
14-
--encode # Generate encoding functions
15-
--short-names # Attempt to make generated symbol names shorter (at the risk of collision)
16-
-t button-object # Create a public API for decoding/encoding the "button-object" type from the cddl file
17-
--output-cmake button_object.cmake # The generated cmake file will be placed here
18-
)
19-
execute_process(COMMAND ${zcbor_command}
20-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
21-
COMMAND_ERROR_IS_FATAL ANY)
22-
23-
# Include the cmake file generated by zcbor. It adds the
24-
# generated code and the necessary zcbor C code files.
25-
include(${CMAKE_CURRENT_BINARY_DIR}/button_object.cmake)
26-
27-
zephyr_link_libraries(button_object)
28-
target_link_libraries(button_object PRIVATE zephyr_interface)

0 commit comments

Comments
 (0)