Skip to content

Commit 71c202d

Browse files
committed
modules: transport: Update state machine and adde message types
Update the state machine and add new message types to the existing implementation. Signed-off-by: Jan Tore Guggedal <jantore.guggedal@nordicsemi.no>
1 parent 41f9cf3 commit 71c202d

File tree

12 files changed

+250
-118
lines changed

12 files changed

+250
-118
lines changed

app/src/common/message_channel.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ ZBUS_CHAN_DEFINE(CONFIG_CHAN,
7575
);
7676

7777
ZBUS_CHAN_DEFINE(CLOUD_CHAN,
78-
enum cloud_status,
78+
enum cloud_msg_type,
7979
NULL,
8080
NULL,
8181
ZBUS_OBSERVERS_EMPTY,

app/src/common/message_channel.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,20 @@ struct battery_msg {
207207

208208
#define MSG_TO_BATTERY_MSG(_msg) (*(const struct battery_msg *)_msg)
209209

210-
enum cloud_status {
210+
enum cloud_msg_type {
211211
CLOUD_DISCONNECTED = 0x1,
212212
CLOUD_CONNECTED_READY_TO_SEND,
213213
CLOUD_CONNECTED_PAUSED,
214+
CLOUD_CONNECTION_ATTEMPT_COUNT_REACHED,
215+
CLOUD_PAYLOAD_JSON,
214216
};
215217

216-
#define MSG_TO_CLOUD_STATUS(_msg) (*(const enum cloud_status *)_msg)
218+
struct cloud_msg {
219+
enum cloud_msg_type type;
220+
struct payload payload;
221+
};
222+
223+
#define MSG_TO_CLOUD_MSG(_msg) (*(const struct cloud_msg *)_msg)
217224

218225
enum trigger_type {
219226
TRIGGER_POLL = 0x1,

app/src/modules/app/app.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ ZBUS_MSG_SUBSCRIBER_DEFINE(app);
2828
ZBUS_CHAN_ADD_OBS(TRIGGER_CHAN, app, 0);
2929
ZBUS_CHAN_ADD_OBS(CLOUD_CHAN, app, 0);
3030

31-
#define MAX_MSG_SIZE (MAX(sizeof(enum trigger_type), sizeof(enum cloud_status)))
31+
#define MAX_MSG_SIZE (MAX(sizeof(enum trigger_type), sizeof(enum cloud_msg_type)))
3232

3333
BUILD_ASSERT(CONFIG_APP_MODULE_WATCHDOG_TIMEOUT_SECONDS > CONFIG_APP_MODULE_EXEC_TIME_SECONDS_MAX,
3434
"Watchdog timeout must be greater than maximum execution time");
@@ -122,7 +122,7 @@ static void app_task(void)
122122
if (&CLOUD_CHAN == chan) {
123123
LOG_DBG("Cloud connection status received");
124124

125-
const enum cloud_status *status = (const enum cloud_status *)msg_buf;
125+
const enum cloud_msg_type *status = (const enum cloud_msg_type *)msg_buf;
126126

127127
if (*status == CLOUD_CONNECTED_READY_TO_SEND) {
128128
LOG_DBG("Cloud ready to send");

app/src/modules/fota/fota.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ZBUS_MSG_SUBSCRIBER_DEFINE(fota);
3434
ZBUS_CHAN_ADD_OBS(TRIGGER_CHAN, fota, 0);
3535
ZBUS_CHAN_ADD_OBS(CLOUD_CHAN, fota, 0);
3636

37-
#define MAX_MSG_SIZE MAX(sizeof(enum trigger_type), sizeof(enum cloud_status))
37+
#define MAX_MSG_SIZE MAX(sizeof(enum trigger_type), sizeof(enum cloud_msg_type))
3838

3939
/* FOTA support context */
4040
static void fota_reboot(enum nrf_cloud_fota_reboot_status status);
@@ -157,7 +157,7 @@ static void state_wait_for_cloud_run(void *o)
157157
struct state_object *state_object = o;
158158

159159
if (&CLOUD_CHAN == state_object->chan) {
160-
const enum cloud_status status = MSG_TO_CLOUD_STATUS(state_object->msg_buf);
160+
const enum cloud_msg_type status = MSG_TO_CLOUD_MSG(state_object->msg_buf).type;
161161

162162
if (status == CLOUD_CONNECTED_READY_TO_SEND) {
163163
STATE_SET(fota_state, STATE_WAIT_FOR_TRIGGER);
@@ -178,7 +178,7 @@ static void state_wait_for_trigger_run(void *o)
178178
}
179179

180180
if (&CLOUD_CHAN == state_object->chan) {
181-
const enum cloud_status status = MSG_TO_CLOUD_STATUS(state_object->msg_buf);
181+
const enum cloud_msg_type status = MSG_TO_CLOUD_MSG(state_object->msg_buf).type;
182182

183183
if (status == CLOUD_CONNECTED_PAUSED) {
184184
STATE_SET(fota_state, STATE_WAIT_FOR_CLOUD);

app/src/modules/location/location.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ ZBUS_CHAN_ADD_OBS(NETWORK_CHAN, location, 0);
3636

3737
#define MAX_MSG_SIZE \
3838
(MAX(sizeof(enum trigger_type), \
39-
(MAX(sizeof(enum cloud_status), \
39+
(MAX(sizeof(enum cloud_msg_type), \
4040
(MAX(sizeof(struct configuration), \
4141
sizeof(struct network_msg)))))))
4242

app/src/modules/memfault/memfault.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ ZBUS_MSG_SUBSCRIBER_DEFINE(memfault);
2727
/* Observe channels */
2828
ZBUS_CHAN_ADD_OBS(CLOUD_CHAN, memfault, 0);
2929

30-
#define MAX_MSG_SIZE sizeof(enum cloud_status)
30+
#define MAX_MSG_SIZE sizeof(enum cloud_msg_type)
3131

3232
static void task_wdt_callback(int channel_id, void *user_data)
3333
{
@@ -196,7 +196,8 @@ static void on_connected(void)
196196
#endif /* CONFIG_NRF_MODEM_LIB_TRACE && CONFIG_NRF_MODEM_LIB_TRACE_BACKEND_FLASH */
197197
}
198198

199-
void handle_cloud_chan(enum cloud_status status) {
199+
void handle_cloud_chan(enum cloud_msg_type status)
200+
{
200201
if (status == CLOUD_CONNECTED_READY_TO_SEND) {
201202
on_connected();
202203
}
@@ -239,7 +240,7 @@ void memfault_task(void)
239240

240241
if (&CLOUD_CHAN == chan) {
241242
LOG_DBG("Cloud status received");
242-
handle_cloud_chan(MSG_TO_CLOUD_STATUS(&msg_buf));
243+
handle_cloud_chan(MSG_TO_CLOUD_MSG(&msg_buf).type);
243244
}
244245
}
245246
}

app/src/modules/transport/Kconfig.transport

+42-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,50 @@
77
menu "Transport"
88
depends on NRF_CLOUD_COAP
99

10-
config APP_TRANSPORT_RECONNECTION_TIMEOUT_SECONDS
11-
int "Reconnection timeout in seconds"
10+
config APP_TRANSPORT_BACKOFF_INITIAL_SECONDS
11+
int "Reconnection backoff time in seconds"
1212
default 60
1313
help
14-
Time in between reconnection attempts to the MQTT broker.
14+
Time in between reconnection attempts to the CoAP server.
15+
The timer starts after the last failed attempt.
16+
17+
choice APP_TRANSPORT_BACKOFF_BACKOFF_TYPE
18+
prompt "Reconnection backoff type"
19+
default APP_TRANSPORT_BACKOFF_BACKOFF_TYPE_LINEAR
20+
21+
config APP_TRANSPORT_BACKOFF_BACKOFF_TYPE_EXPONENTIAL
22+
bool "Exponential backoff"
23+
help
24+
Exponential backoff doubles the reconnection timeout after each failed attempt.
25+
The maximum reconnection timeout is defined by APP_TRANSPORT_BACKOFF_MAX_SECONDS.
26+
27+
config APP_TRANSPORT_BACKOFF_BACKOFF_TYPE_LINEAR
28+
bool "Linear backoff"
29+
help
30+
Linear backoff adds a fixed amount of time to the reconnection timeout after each failed attempt,
31+
as defined by APP_TRANSPORT_BACKOFF_LINEAR_INCREMENT_SECONDS.
32+
33+
config APP_TRANSPORT_BACKOFF_BACKOFF_TYPE_NONE
34+
bool "No backoff"
35+
help
36+
No backoff means that the reconnection timeout is constant at the value defined by
37+
APP_TRANSPORT_BACKOFF_INITIAL_SECONDS.
38+
39+
endchoice
40+
41+
config APP_TRANSPORT_BACKOFF_LINEAR_INCREMENT_SECONDS
42+
int "Reconnection backoff time increment"
43+
default 60
44+
depends on APP_TRANSPORT_BACKOFF_BACKOFF_TYPE_LINEAR
45+
help
46+
Time added to the reconnection timeout after each failed attempt in seconds.
47+
The maximum reconnection timeout is defined by APP_TRANSPORT_BACKOFF_MAX_SECONDS.
48+
49+
config APP_TRANSPORT_BACKOFF_MAX_SECONDS
50+
int "Maximum reconnection timeout"
51+
default 3600
52+
help
53+
Maximum reconnection backoff value in seconds.
1554

1655
config APP_TRANSPORT_THREAD_STACK_SIZE
1756
int "Thread stack size"

0 commit comments

Comments
 (0)