Skip to content

Commit 2bdf778

Browse files
committed
modules: cloud: Use pointer instead of message copy
Use a pointer instead of a complete message copy in the cloud message convenience macro. This saves memory. Signed-off-by: Jan Tore Guggedal <jantore.guggedal@nordicsemi.no>
1 parent f676691 commit 2bdf778

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

app/src/main.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,9 @@ static void idle_run(void *o)
398398
struct main_state *state_object = o;
399399

400400
if (state_object->chan == &CLOUD_CHAN) {
401-
struct cloud_msg msg = MSG_TO_CLOUD_MSG(state_object->msg_buf);
401+
const struct cloud_msg *msg = MSG_TO_CLOUD_MSG_PTR(state_object->msg_buf);
402402

403-
if (msg.type == CLOUD_CONNECTED) {
403+
if (msg->type == CLOUD_CONNECTED) {
404404
state_object->connected = true;
405405
smf_set_state(SMF_CTX(state_object), &states[STATE_TRIGGERING]);
406406
return;
@@ -452,17 +452,17 @@ static void triggering_run(void *o)
452452
struct main_state *state_object = o;
453453

454454
if (state_object->chan == &CLOUD_CHAN) {
455-
struct cloud_msg msg = MSG_TO_CLOUD_MSG(state_object->msg_buf);
455+
const struct cloud_msg *msg = MSG_TO_CLOUD_MSG_PTR(state_object->msg_buf);
456456

457-
if (msg.type == CLOUD_DISCONNECTED) {
457+
if (msg->type == CLOUD_DISCONNECTED) {
458458
state_object->connected = false;
459459
smf_set_state(SMF_CTX(state_object), &states[STATE_IDLE]);
460460
return;
461461
}
462462

463-
if (msg.type == CLOUD_SHADOW_RESPONSE) {
464-
err = get_update_interval_from_cbor_response(msg.response.buffer,
465-
msg.response.buffer_data_len,
463+
if (msg->type == CLOUD_SHADOW_RESPONSE) {
464+
err = get_update_interval_from_cbor_response(msg->response.buffer,
465+
msg->response.buffer_data_len,
466466
&state_object->interval_sec);
467467
if (err) {
468468
LOG_ERR("get_update_interval_from_cbor_response, error: %d", err);

app/src/modules/cloud/cloud_module.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,10 +669,10 @@ static void state_connected_ready_run(void *o)
669669
#endif /* CONFIG_APP_ENVIRONMENTAL */
670670

671671
if (state_object->chan == &CLOUD_CHAN) {
672-
const struct cloud_msg msg = MSG_TO_CLOUD_MSG(state_object->msg_buf);
672+
const struct cloud_msg *msg = MSG_TO_CLOUD_MSG_PTR(state_object->msg_buf);
673673

674-
if (msg.type == CLOUD_PAYLOAD_JSON) {
675-
err = nrf_cloud_coap_json_message_send(msg.payload.buffer,
674+
if (msg->type == CLOUD_PAYLOAD_JSON) {
675+
err = nrf_cloud_coap_json_message_send(msg->payload.buffer,
676676
false, confirmable);
677677
if (err == -ENETUNREACH) {
678678
LOG_WRN("Network is unreachable, error: %d", err);
@@ -682,7 +682,7 @@ static void state_connected_ready_run(void *o)
682682
SEND_FATAL_ERROR();
683683
return;
684684
}
685-
} else if (msg.type == CLOUD_POLL_SHADOW) {
685+
} else if (msg->type == CLOUD_POLL_SHADOW) {
686686
LOG_DBG("Poll shadow trigger received");
687687

688688
shadow_get(true);

app/src/modules/cloud/cloud_module.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ struct cloud_msg {
4848
};
4949
};
5050

51-
#define MSG_TO_CLOUD_MSG(_msg) (*(const struct cloud_msg *)_msg)
51+
/* Cast a pointer to a message to a pointer to a cloud message */
52+
#define MSG_TO_CLOUD_MSG_PTR(_msg) ((const struct cloud_msg *)_msg)
5253

5354
#ifdef __cplusplus
5455
}

0 commit comments

Comments
 (0)