diff --git a/lib/wpc_proto/internal_modules/common.c b/lib/wpc_proto/internal_modules/common.c index b489734..358c18e 100644 --- a/lib/wpc_proto/internal_modules/common.c +++ b/lib/wpc_proto/internal_modules/common.c @@ -103,20 +103,23 @@ wp_ErrorCode Common_convert_error_code(app_res_e error) return ret; } -void Common_fill_event_header(wp_EventHeader * header_p) +void Common_fill_event_header(wp_EventHeader * header_p, bool has_sink_id) { _Static_assert(member_size(wp_EventHeader, gw_id) >= GATEWAY_ID_MAX_SIZE, "Gateway ID too long"); _Static_assert(member_size(wp_EventHeader, sink_id) >= SINK_ID_MAX_SIZE, "Sink ID too long"); *header_p = (wp_EventHeader){ - .has_sink_id = (strlen(m_sink_id) != 0), + .has_sink_id = (strlen(m_sink_id) != 0) && has_sink_id, .has_time_ms_epoch = true, .time_ms_epoch = Platform_get_timestamp_ms_epoch(), .event_id = rand() + (((uint64_t) rand()) << 32), }; strncpy(header_p->gw_id, Common_get_gateway_id(), GATEWAY_ID_MAX_SIZE); - strncpy(header_p->sink_id, Common_get_sink_id(), SINK_ID_MAX_SIZE); + if (header_p->has_sink_id) + { + strncpy(header_p->sink_id, Common_get_sink_id(), SINK_ID_MAX_SIZE); + } } void Common_Fill_response_header(wp_ResponseHeader * header_p, diff --git a/lib/wpc_proto/internal_modules/common.h b/lib/wpc_proto/internal_modules/common.h index 152ee2d..574b056 100644 --- a/lib/wpc_proto/internal_modules/common.h +++ b/lib/wpc_proto/internal_modules/common.h @@ -41,8 +41,9 @@ wp_ErrorCode Common_convert_error_code(app_res_e error); /** * \brief Fill event message header * \param header_p pointer to header to fill + * \param has_sink_id boolean indicating if sink_id should be included in header */ -void Common_fill_event_header(wp_EventHeader * header_p); +void Common_fill_event_header(wp_EventHeader * header_p, bool has_sink_id); /** * \brief Fill response header diff --git a/lib/wpc_proto/internal_modules/proto_config.c b/lib/wpc_proto/internal_modules/proto_config.c index c290b0f..c9049f2 100644 --- a/lib/wpc_proto/internal_modules/proto_config.c +++ b/lib/wpc_proto/internal_modules/proto_config.c @@ -445,7 +445,7 @@ static void fill_status_event(wp_StatusEvent * status_event_p, strncpy(status_event_p->gw_model, Common_get_gateway_model(), GATEWAY_MODEL_MAX_SIZE); strncpy(status_event_p->gw_version, Common_get_gateway_version(), GATEWAY_VERSION_MAX_SIZE); - Common_fill_event_header(&status_event_p->header); + Common_fill_event_header(&status_event_p->header, false); } static bool refresh_full_stack_state() diff --git a/lib/wpc_proto/internal_modules/proto_data.c b/lib/wpc_proto/internal_modules/proto_data.c index 845928c..d83d81b 100644 --- a/lib/wpc_proto/internal_modules/proto_data.c +++ b/lib/wpc_proto/internal_modules/proto_data.c @@ -90,7 +90,7 @@ static bool onDataReceived(const uint8_t * bytes, memcpy(message_PacketReceived_p->payload.bytes, bytes, num_bytes); message_PacketReceived_p->payload.size = num_bytes; - Common_fill_event_header(&message_PacketReceived_p->header); + Common_fill_event_header(&message_PacketReceived_p->header, true); pb_ostream_t stream = pb_ostream_from_buffer(encoded_message_p, max_encoded_size);