Skip to content

Commit 0434edd

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 0313650 commit 0434edd

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

app/src/modules/app/app.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,9 @@ static void app_callback(const struct zbus_channel *chan)
381381
app_state.interval_sec = config->update_interval;
382382
}
383383
} else if (&CLOUD_CHAN == chan) {
384-
const enum cloud_msg_type *status = zbus_chan_const_msg(chan);
384+
const struct cloud_msg *cloud_msg = zbus_chan_const_msg(chan)
385385

386-
app_state.status = *status;
386+
app_state.status = cloud_msg->type;
387387
} else if (&BUTTON_CHAN == chan) {
388388
const int *button_number = zbus_chan_const_msg(chan);
389389

app/src/modules/cloud/cloud_module.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ ZBUS_CHAN_DEFINE(PAYLOAD_CHAN,
7272
);
7373

7474
ZBUS_CHAN_DEFINE(CLOUD_CHAN,
75-
enum cloud_msg_type,
75+
struct cloud_msg,
7676
NULL,
7777
NULL,
7878
ZBUS_OBSERVERS_EMPTY,
@@ -332,13 +332,15 @@ static void state_running_run(void *o)
332332
static void state_disconnected_entry(void *o)
333333
{
334334
int err;
335-
enum cloud_msg_type cloud_status = CLOUD_DISCONNECTED;
335+
struct cloud_msg cloud_msg = {
336+
.type = CLOUD_DISCONNECTED,
337+
};
336338

337339
ARG_UNUSED(o);
338340

339341
LOG_DBG("%s", __func__);
340342

341-
err = zbus_chan_pub(&CLOUD_CHAN, &cloud_status, K_SECONDS(1));
343+
err = zbus_chan_pub(&CLOUD_CHAN, &cloud_msg, K_SECONDS(1));
342344
if (err) {
343345
LOG_ERR("zbus_chan_pub, error: %d", err);
344346
SEND_FATAL_ERROR();
@@ -486,13 +488,15 @@ static void shadow_get(bool delta_only)
486488
static void state_connected_ready_entry(void *o)
487489
{
488490
int err;
489-
enum cloud_msg_type cloud_status = CLOUD_CONNECTED_READY_TO_SEND;
491+
struct cloud_msg cloud_msg = {
492+
.type = CLOUD_CONNECTED_READY_TO_SEND,
493+
};
490494

491495
ARG_UNUSED(o);
492496

493497
LOG_DBG("%s", __func__);
494498

495-
err = zbus_chan_pub(&CLOUD_CHAN, &cloud_status, K_SECONDS(1));
499+
err = zbus_chan_pub(&CLOUD_CHAN, &cloud_msg, K_SECONDS(1));
496500
if (err) {
497501
LOG_ERR("zbus_chan_pub, error: %d", err);
498502
SEND_FATAL_ERROR();
@@ -624,13 +628,15 @@ static void state_connected_ready_run(void *o)
624628
static void state_connected_paused_entry(void *o)
625629
{
626630
int err;
627-
enum cloud_msg_type cloud_status = CLOUD_CONNECTED_PAUSED;
631+
struct cloud_msg cloud_msg = {
632+
.type = CLOUD_CONNECTED_PAUSED,
633+
};
628634

629635
ARG_UNUSED(o);
630636

631637
LOG_DBG("%s", __func__);
632638

633-
err = zbus_chan_pub(&CLOUD_CHAN, &cloud_status, K_SECONDS(1));
639+
err = zbus_chan_pub(&CLOUD_CHAN, &cloud_msg, K_SECONDS(1));
634640
if (err) {
635641
LOG_ERR("zbus_chan_pub, error: %d", err);
636642
SEND_FATAL_ERROR();

app/src/modules/location/location.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ 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), \
5251
(MAX(sizeof(struct configuration), \
5352
sizeof(struct network_msg)))))))
5453

tests/module/app/src/main.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ 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,
@@ -122,8 +122,11 @@ static void button_handler(uint32_t button_states, uint32_t has_changed)
122122

123123
static void send_cloud_connected_ready_to_send(void)
124124
{
125-
enum cloud_msg_type status = CLOUD_CONNECTED_READY_TO_SEND;
126-
int err = zbus_chan_pub(&CLOUD_CHAN, &status, K_SECONDS(1));
125+
struct cloud_msg cloud_msg = {
126+
.type = CLOUD_CONNECTED_READY_TO_SEND,
127+
};
128+
129+
int err = zbus_chan_pub(&CLOUD_CHAN, &cloud_msg, K_SECONDS(1));
127130

128131
TEST_ASSERT_EQUAL(0, err);
129132
}
@@ -142,8 +145,11 @@ static void send_config(uint64_t interval)
142145

143146
static void send_cloud_disconnected(void)
144147
{
145-
enum cloud_msg_type status = CLOUD_DISCONNECTED;
146-
int err = zbus_chan_pub(&CLOUD_CHAN, &status, K_SECONDS(1));
148+
struct cloud_msg cloud_msg = {
149+
.type = CLOUD_DISCONNECTED,
150+
};
151+
152+
int err = zbus_chan_pub(&CLOUD_CHAN, &cloud_msg, K_SECONDS(1));
147153

148154
TEST_ASSERT_EQUAL(0, err);
149155
}

tests/module/cloud/src/cloud_module_test.c

Lines changed: 2 additions & 1 deletion
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)