21
21
#include "message_channel.h"
22
22
23
23
/* Register log module */
24
- LOG_MODULE_REGISTER (transport , CONFIG_APP_TRANSPORT_LOG_LEVEL );
24
+ LOG_MODULE_REGISTER (cloud , CONFIG_APP_CLOUD_LOG_LEVEL );
25
25
26
26
#define CUSTOM_JSON_APPID_VAL_CONEVAL "CONEVAL"
27
27
#define CUSTOM_JSON_APPID_VAL_BATTERY "BATTERY"
28
- #define MAX_MSG_SIZE (MAX(sizeof(struct cloud_payload), \
28
+ #define MAX_MSG_SIZE (MAX(sizeof(struct cloud_payload), \
29
29
MAX(sizeof(struct network_msg), sizeof(struct battery_msg))))
30
30
31
- BUILD_ASSERT (CONFIG_APP_TRANSPORT_WATCHDOG_TIMEOUT_SECONDS >
32
- CONFIG_APP_TRANSPORT_EXEC_TIME_SECONDS_MAX ,
31
+ BUILD_ASSERT (CONFIG_APP_CLOUD_WATCHDOG_TIMEOUT_SECONDS >
32
+ CONFIG_APP_CLOUD_EXEC_TIME_SECONDS_MAX ,
33
33
"Watchdog timeout must be greater than maximum execution time" );
34
34
35
35
/* Register subscriber */
36
- ZBUS_MSG_SUBSCRIBER_DEFINE (transport );
36
+ ZBUS_MSG_SUBSCRIBER_DEFINE (cloud );
37
37
38
38
/* Observe channels */
39
- ZBUS_CHAN_ADD_OBS (PAYLOAD_CHAN , transport , 0 );
40
- ZBUS_CHAN_ADD_OBS (NETWORK_CHAN , transport , 0 );
41
- ZBUS_CHAN_ADD_OBS (BATTERY_CHAN , transport , 0 );
42
- ZBUS_CHAN_ADD_OBS (TRIGGER_CHAN , transport , 0 );
39
+ ZBUS_CHAN_ADD_OBS (PAYLOAD_CHAN , cloud , 0 );
40
+ ZBUS_CHAN_ADD_OBS (NETWORK_CHAN , cloud , 0 );
41
+ ZBUS_CHAN_ADD_OBS (BATTERY_CHAN , cloud , 0 );
42
+ ZBUS_CHAN_ADD_OBS (TRIGGER_CHAN , cloud , 0 );
43
43
44
44
/* Define channels provided by this module */
45
45
@@ -59,21 +59,21 @@ ZBUS_CHAN_DEFINE(CLOUD_CHAN,
59
59
CLOUD_DISCONNECTED
60
60
);
61
61
62
- /* Enumerator to be used in privat transport channel */
63
- enum priv_transport_msg {
62
+ /* Enumerator to be used in privat cloud channel */
63
+ enum priv_cloud_msg {
64
64
CLOUD_BACKOFF_EXPIRED ,
65
65
};
66
66
67
- /* Create private transport channel for internal messaging that is not intended for external use.
67
+ /* Create private cloud channel for internal messaging that is not intended for external use.
68
68
* The channel is needed to communicate from asynchronous callbacks to the state machine and
69
- * ensure state transitions only happen from the transport module thread where the state machine
69
+ * ensure state transitions only happen from the cloud module thread where the state machine
70
70
* is running.
71
71
*/
72
- ZBUS_CHAN_DEFINE (PRIV_TRANSPORT_CHAN ,
73
- enum priv_transport_msg ,
72
+ ZBUS_CHAN_DEFINE (PRIV_CLOUD_CHAN ,
73
+ enum priv_cloud_msg ,
74
74
NULL ,
75
75
NULL ,
76
- ZBUS_OBSERVERS (transport ),
76
+ ZBUS_OBSERVERS (cloud ),
77
77
CLOUD_BACKOFF_EXPIRED
78
78
);
79
79
@@ -108,9 +108,9 @@ static void state_connected_ready_run(void *o);
108
108
static void state_connected_paused_entry (void * o );
109
109
static void state_connected_paused_run (void * o );
110
110
111
- /* Defining the hierarchical transport module states:
111
+ /* Defining the hierarchical cloud module states:
112
112
*
113
- * STATE_RUNNING: The transport module has started and is running
113
+ * STATE_RUNNING: The cloud module has started and is running
114
114
* - STATE_DISCONNECTED: Cloud connection is not established
115
115
* - STATE_CONNECTING: The module is connecting to cloud
116
116
* - STATE_CONNECTING_ATTEMPT: The module is trying to connect to cloud
@@ -197,7 +197,7 @@ static struct state_object {
197
197
198
198
/* Connection backoff time */
199
199
uint32_t backoff_time ;
200
- } transport_state ;
200
+ } cloud_state ;
201
201
202
202
/* Static helper function */
203
203
static void task_wdt_callback (int channel_id , void * user_data )
@@ -225,32 +225,32 @@ static void connect_to_cloud(void)
225
225
226
226
err = nrf_cloud_coap_connect (APP_VERSION_STRING );
227
227
if (err == 0 ) {
228
- STATE_SET (transport_state , STATE_CONNECTED );
228
+ STATE_SET (cloud_state , STATE_CONNECTED );
229
229
230
230
return ;
231
231
}
232
232
233
233
/* Connection failed, retry */
234
234
LOG_ERR ("nrf_cloud_coap_connect, error: %d" , err );
235
235
236
- STATE_SET (transport_state , STATE_CONNECTING_BACKOFF );
236
+ STATE_SET (cloud_state , STATE_CONNECTING_BACKOFF );
237
237
}
238
238
239
239
static uint32_t calculate_backoff_time (uint32_t attempts )
240
240
{
241
- uint32_t backoff_time = CONFIG_APP_TRANSPORT_BACKOFF_INITIAL_SECONDS ;
241
+ uint32_t backoff_time = CONFIG_APP_CLOUD_BACKOFF_INITIAL_SECONDS ;
242
242
243
243
/* Calculate backoff time */
244
- if (IS_ENABLED (CONFIG_APP_TRANSPORT_BACKOFF_TYPE_EXPONENTIAL )) {
245
- backoff_time = CONFIG_APP_TRANSPORT_BACKOFF_INITIAL_SECONDS << (attempts - 1 );
246
- } else if (IS_ENABLED (CONFIG_APP_TRANSPORT_BACKOFF_TYPE_LINEAR )) {
247
- backoff_time = CONFIG_APP_TRANSPORT_BACKOFF_INITIAL_SECONDS +
248
- ((attempts - 1 ) * CONFIG_APP_TRANSPORT_BACKOFF_LINEAR_INCREMENT_SECONDS );
244
+ if (IS_ENABLED (CONFIG_APP_CLOUD_BACKOFF_TYPE_EXPONENTIAL )) {
245
+ backoff_time = CONFIG_APP_CLOUD_BACKOFF_INITIAL_SECONDS << (attempts - 1 );
246
+ } else if (IS_ENABLED (CONFIG_APP_CLOUD_BACKOFF_TYPE_LINEAR )) {
247
+ backoff_time = CONFIG_APP_CLOUD_BACKOFF_INITIAL_SECONDS +
248
+ ((attempts - 1 ) * CONFIG_APP_CLOUD_BACKOFF_LINEAR_INCREMENT_SECONDS );
249
249
}
250
250
251
251
/* Limit backoff time */
252
- if (backoff_time > CONFIG_APP_TRANSPORT_BACKOFF_MAX_SECONDS ) {
253
- backoff_time = CONFIG_APP_TRANSPORT_BACKOFF_MAX_SECONDS ;
252
+ if (backoff_time > CONFIG_APP_CLOUD_BACKOFF_MAX_SECONDS ) {
253
+ backoff_time = CONFIG_APP_CLOUD_BACKOFF_MAX_SECONDS ;
254
254
}
255
255
256
256
LOG_DBG ("Backoff time: %u seconds" , backoff_time );
@@ -261,9 +261,9 @@ static uint32_t calculate_backoff_time(uint32_t attempts)
261
261
static void backoff_timer_work_fn (struct k_work * work )
262
262
{
263
263
int err ;
264
- enum priv_transport_msg msg = CLOUD_BACKOFF_EXPIRED ;
264
+ enum priv_cloud_msg msg = CLOUD_BACKOFF_EXPIRED ;
265
265
266
- err = zbus_chan_pub (& PRIV_TRANSPORT_CHAN , & msg , K_SECONDS (1 ));
266
+ err = zbus_chan_pub (& PRIV_CLOUD_CHAN , & msg , K_SECONDS (1 ));
267
267
if (err ) {
268
268
LOG_ERR ("zbus_chan_pub, error: %d" , err );
269
269
SEND_FATAL_ERROR ();
@@ -301,7 +301,7 @@ static void state_running_run(void *o)
301
301
struct network_msg msg = MSG_TO_NETWORK_MSG (state_object -> msg_buf );
302
302
303
303
if (msg .type == NETWORK_DISCONNECTED ) {
304
- STATE_SET (transport_state , STATE_DISCONNECTED );
304
+ STATE_SET (cloud_state , STATE_DISCONNECTED );
305
305
306
306
return ;
307
307
}
@@ -336,7 +336,7 @@ static void state_disconnected_run(void *o)
336
336
struct network_msg msg = MSG_TO_NETWORK_MSG (state_object -> msg_buf );
337
337
338
338
if ((state_object -> chan == & NETWORK_CHAN ) && (msg .type == NETWORK_CONNECTED )) {
339
- STATE_SET (transport_state , STATE_CONNECTING );
339
+ STATE_SET (cloud_state , STATE_CONNECTING );
340
340
341
341
return ;
342
342
}
@@ -386,11 +386,11 @@ static void state_connecting_backoff_run(void *o)
386
386
387
387
LOG_DBG ("%s" , __func__ );
388
388
389
- if (state_object -> chan == & PRIV_TRANSPORT_CHAN ) {
390
- enum priv_transport_msg msg = * (enum priv_transport_msg * )state_object -> msg_buf ;
389
+ if (state_object -> chan == & PRIV_CLOUD_CHAN ) {
390
+ enum priv_cloud_msg msg = * (enum priv_cloud_msg * )state_object -> msg_buf ;
391
391
392
392
if (msg == CLOUD_BACKOFF_EXPIRED ) {
393
- STATE_SET (transport_state , STATE_CONNECTING_ATTEMPT );
393
+ STATE_SET (cloud_state , STATE_CONNECTING_ATTEMPT );
394
394
395
395
return ;
396
396
}
@@ -495,11 +495,11 @@ static void state_connected_ready_run(void *o)
495
495
496
496
switch (msg .type ) {
497
497
case NETWORK_DISCONNECTED :
498
- STATE_SET (transport_state , STATE_CONNECTED_PAUSED );
498
+ STATE_SET (cloud_state , STATE_CONNECTED_PAUSED );
499
499
break ;
500
500
501
501
case NETWORK_CONNECTED :
502
- STATE_EVENT_HANDLED (transport_state );
502
+ STATE_EVENT_HANDLED (cloud_state );
503
503
break ;
504
504
505
505
case NETWORK_QUALITY_SAMPLE_RESPONSE :
@@ -593,28 +593,28 @@ static void state_connected_paused_run(void *o)
593
593
LOG_DBG ("%s" , __func__ );
594
594
595
595
if ((state_object -> chan == & NETWORK_CHAN ) && (msg .type == NETWORK_CONNECTED )) {
596
- STATE_SET (transport_state , STATE_CONNECTED_READY );
596
+ STATE_SET (cloud_state , STATE_CONNECTED_READY );
597
597
598
598
return ;
599
599
}
600
600
}
601
601
602
602
/* End of state handlers */
603
603
604
- static void transport_module_thread (void )
604
+ static void cloud_module_thread (void )
605
605
{
606
606
int err ;
607
607
int task_wdt_id ;
608
- const uint32_t wdt_timeout_ms = (CONFIG_APP_TRANSPORT_WATCHDOG_TIMEOUT_SECONDS * MSEC_PER_SEC );
609
- const uint32_t execution_time_ms = (CONFIG_APP_TRANSPORT_EXEC_TIME_SECONDS_MAX * MSEC_PER_SEC );
608
+ const uint32_t wdt_timeout_ms = (CONFIG_APP_CLOUD_WATCHDOG_TIMEOUT_SECONDS * MSEC_PER_SEC );
609
+ const uint32_t execution_time_ms = (CONFIG_APP_CLOUD_EXEC_TIME_SECONDS_MAX * MSEC_PER_SEC );
610
610
const k_timeout_t zbus_wait_ms = K_MSEC (wdt_timeout_ms - execution_time_ms );
611
611
612
- LOG_DBG ("Transport module task started" );
612
+ LOG_DBG ("cloud module task started" );
613
613
614
614
task_wdt_id = task_wdt_add (wdt_timeout_ms , task_wdt_callback , (void * )k_current_get ());
615
615
616
616
/* Initialize the state machine to STATE_RUNNING, which will also run its entry function */
617
- STATE_SET_INITIAL (transport_state , STATE_RUNNING );
617
+ STATE_SET_INITIAL (cloud_state , STATE_RUNNING );
618
618
619
619
while (true) {
620
620
err = task_wdt_feed (task_wdt_id );
@@ -625,7 +625,7 @@ static void transport_module_thread(void)
625
625
return ;
626
626
}
627
627
628
- err = zbus_sub_wait_msg (& transport , & transport_state .chan , transport_state .msg_buf ,
628
+ err = zbus_sub_wait_msg (& cloud , & cloud_state .chan , cloud_state .msg_buf ,
629
629
zbus_wait_ms );
630
630
if (err == - ENOMSG ) {
631
631
continue ;
@@ -636,7 +636,7 @@ static void transport_module_thread(void)
636
636
return ;
637
637
}
638
638
639
- err = STATE_RUN (transport_state );
639
+ err = STATE_RUN (cloud_state );
640
640
if (err ) {
641
641
LOG_ERR ("STATE_RUN(), error: %d" , err );
642
642
SEND_FATAL_ERROR ();
@@ -646,6 +646,6 @@ static void transport_module_thread(void)
646
646
}
647
647
}
648
648
649
- K_THREAD_DEFINE (transport_module_thread_id ,
650
- CONFIG_APP_TRANSPORT_THREAD_STACK_SIZE ,
651
- transport_module_thread , NULL , NULL , NULL , K_LOWEST_APPLICATION_THREAD_PRIO , 0 , 0 );
649
+ K_THREAD_DEFINE (cloud_module_thread_id ,
650
+ CONFIG_APP_CLOUD_THREAD_STACK_SIZE ,
651
+ cloud_module_thread , NULL , NULL , NULL , K_LOWEST_APPLICATION_THREAD_PRIO , 0 , 0 );
0 commit comments