Skip to content

Commit f31ff7b

Browse files
modules: cloud: fix struct cloud_msg
cloud_msg should be used instead of could_msg_type. Signed-off-by: Giacomo Dematteis <giacomo.dematteis@nordicsemi.no>
1 parent 368a1d5 commit f31ff7b

File tree

5 files changed

+31
-18
lines changed

5 files changed

+31
-18
lines changed

app/src/modules/app/app.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,9 @@ static void app_callback(const struct zbus_channel *chan)
507507
app_state.interval_sec = config->update_interval;
508508
}
509509
} else if (&CLOUD_CHAN == chan) {
510-
const enum cloud_msg_type *status = zbus_chan_const_msg(chan);
510+
const struct cloud_msg *cloud_msg = zbus_chan_const_msg(chan);
511511

512-
app_state.status = *status;
512+
app_state.status = cloud_msg->type;
513513
} else if (&FOTA_CHAN == chan) {
514514
const enum fota_msg_type *fota_status = zbus_chan_const_msg(chan);
515515

app/src/modules/cloud/cloud_module.c

+14-8
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ ZBUS_CHAN_DEFINE(PAYLOAD_CHAN,
8383
);
8484

8585
ZBUS_CHAN_DEFINE(CLOUD_CHAN,
86-
enum cloud_msg_type,
86+
struct cloud_msg,
8787
NULL,
8888
NULL,
8989
ZBUS_OBSERVERS_EMPTY,
90-
CLOUD_DISCONNECTED
90+
ZBUS_MSG_INIT(.type = CLOUD_DISCONNECTED)
9191
);
9292

9393
/* Enumerator to be used in privat cloud channel */
@@ -346,13 +346,15 @@ static void state_running_run(void *o)
346346
static void state_disconnected_entry(void *o)
347347
{
348348
int err;
349-
enum cloud_msg_type cloud_status = CLOUD_DISCONNECTED;
349+
struct cloud_msg cloud_msg = {
350+
.type = CLOUD_DISCONNECTED,
351+
};
350352

351353
ARG_UNUSED(o);
352354

353355
LOG_DBG("%s", __func__);
354356

355-
err = zbus_chan_pub(&CLOUD_CHAN, &cloud_status, K_SECONDS(1));
357+
err = zbus_chan_pub(&CLOUD_CHAN, &cloud_msg, K_SECONDS(1));
356358
if (err) {
357359
LOG_ERR("zbus_chan_pub, error: %d", err);
358360
SEND_FATAL_ERROR();
@@ -491,13 +493,15 @@ static void shadow_get(bool delta_only)
491493
static void state_connected_ready_entry(void *o)
492494
{
493495
int err;
494-
enum cloud_msg_type cloud_status = CLOUD_CONNECTED_READY_TO_SEND;
496+
struct cloud_msg cloud_msg = {
497+
.type = CLOUD_CONNECTED_READY_TO_SEND,
498+
};
495499

496500
ARG_UNUSED(o);
497501

498502
LOG_DBG("%s", __func__);
499503

500-
err = zbus_chan_pub(&CLOUD_CHAN, &cloud_status, K_SECONDS(1));
504+
err = zbus_chan_pub(&CLOUD_CHAN, &cloud_msg, K_SECONDS(1));
501505
if (err) {
502506
LOG_ERR("zbus_chan_pub, error: %d", err);
503507
SEND_FATAL_ERROR();
@@ -629,13 +633,15 @@ static void state_connected_ready_run(void *o)
629633
static void state_connected_paused_entry(void *o)
630634
{
631635
int err;
632-
enum cloud_msg_type cloud_status = CLOUD_CONNECTED_PAUSED;
636+
struct cloud_msg cloud_msg = {
637+
.type = CLOUD_CONNECTED_PAUSED,
638+
};
633639

634640
ARG_UNUSED(o);
635641

636642
LOG_DBG("%s", __func__);
637643

638-
err = zbus_chan_pub(&CLOUD_CHAN, &cloud_status, K_SECONDS(1));
644+
err = zbus_chan_pub(&CLOUD_CHAN, &cloud_msg, K_SECONDS(1));
639645
if (err) {
640646
LOG_ERR("zbus_chan_pub, error: %d", err);
641647
SEND_FATAL_ERROR();

app/src/modules/location/location.c

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

4949
#define MAX_MSG_SIZE \
5050
(MAX(sizeof(enum location_msg_type), \
51-
(MAX(sizeof(enum cloud_msg_type), \
51+
(MAX(sizeof(struct cloud_msg), \
5252
(MAX(sizeof(struct configuration), \
5353
sizeof(struct network_msg)))))))
5454

tests/module/app/src/main.c

+12-6
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ ZBUS_CHAN_DEFINE(NETWORK_CHAN,
4646
ZBUS_MSG_INIT(.type = NETWORK_DISCONNECTED)
4747
);
4848
ZBUS_CHAN_DEFINE(CLOUD_CHAN,
49-
enum cloud_msg_type,
49+
struct cloud_msg,
5050
NULL,
5151
NULL,
5252
ZBUS_OBSERVERS_EMPTY,
53-
ZBUS_MSG_INIT(CLOUD_DISCONNECTED)
53+
ZBUS_MSG_INIT(.type = CLOUD_DISCONNECTED)
5454
);
5555
ZBUS_CHAN_DEFINE(ENVIRONMENTAL_CHAN,
5656
struct environmental_msg,
@@ -125,8 +125,11 @@ static void button_handler(uint32_t button_states, uint32_t has_changed)
125125

126126
static void send_cloud_connected_ready_to_send(void)
127127
{
128-
enum cloud_msg_type status = CLOUD_CONNECTED_READY_TO_SEND;
129-
int err = zbus_chan_pub(&CLOUD_CHAN, &status, K_SECONDS(1));
128+
struct cloud_msg cloud_msg = {
129+
.type = CLOUD_CONNECTED_READY_TO_SEND,
130+
};
131+
132+
int err = zbus_chan_pub(&CLOUD_CHAN, &cloud_msg, K_SECONDS(1));
130133

131134
TEST_ASSERT_EQUAL(0, err);
132135
}
@@ -145,8 +148,11 @@ static void send_config(uint64_t interval)
145148

146149
static void send_cloud_disconnected(void)
147150
{
148-
enum cloud_msg_type status = CLOUD_DISCONNECTED;
149-
int err = zbus_chan_pub(&CLOUD_CHAN, &status, K_SECONDS(1));
151+
struct cloud_msg cloud_msg = {
152+
.type = CLOUD_DISCONNECTED,
153+
};
154+
155+
int err = zbus_chan_pub(&CLOUD_CHAN, &cloud_msg, K_SECONDS(1));
150156

151157
TEST_ASSERT_EQUAL(0, err);
152158
}

tests/module/cloud/src/cloud_module_test.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ static void dummy_cb(const struct zbus_channel *chan)
9090
static void cloud_chan_cb(const struct zbus_channel *chan)
9191
{
9292
if (chan == &CLOUD_CHAN) {
93-
enum cloud_msg_type status = *(enum cloud_msg_type *)chan->message;
93+
const struct cloud_msg *cloud_msg = zbus_chan_const_msg(chan);
94+
enum cloud_msg_type status = cloud_msg->type;
9495

9596
if (status == CLOUD_DISCONNECTED) {
9697
k_sem_give(&cloud_disconnected);

0 commit comments

Comments
 (0)