Skip to content

Commit 0912c14

Browse files
Allows start even if sink init failed
Generate event status with Gw online, Sink down.
1 parent a157ad5 commit 0912c14

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

example/linux/gw-example/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ static bool reconnect(uint32_t timeout_s)
281281

282282
// Setup last will
283283
proto_size = WPC_PROTO_MAX_EVENTSTATUS_SIZE;
284-
if (WPC_Proto_get_current_event_status(false, event_status_p, &proto_size) == APP_RES_PROTO_OK)
284+
if (WPC_Proto_get_current_event_status(false, false, event_status_p, &proto_size) == APP_RES_PROTO_OK)
285285
{
286286
will_options.topicName = topic_status;
287287
will_options.qos = 1;
@@ -319,7 +319,7 @@ static bool reconnect(uint32_t timeout_s)
319319

320320
// Set our current status
321321
proto_size = WPC_PROTO_MAX_EVENTSTATUS_SIZE;
322-
if (WPC_Proto_get_current_event_status(true, event_status_p, &proto_size) == APP_RES_PROTO_OK)
322+
if (WPC_Proto_get_current_event_status(true, true, event_status_p, &proto_size) == APP_RES_PROTO_OK)
323323
{
324324
MQTT_publish(topic_status, event_status_p, proto_size, true);
325325
}

lib/api/wpc_proto.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,11 @@ app_proto_res_e WPC_Proto_register_for_event_status(onEventStatus_cb_f onEventSt
157157
/**
158158
* \brief Get current event Status. It is mainly required at boot time of gateway
159159
* to publish Gateway status (and no event status are generated yet)
160-
* \param[in] online
160+
* \param[in] gw_online
161161
* If true, get the "ONLINE" current status. If false, get the "OFFLINE" status
162162
* to be published as last will topic
163+
* \param[in] sink_online
164+
* If true, one sink config is attached, if false, none.
163165
* \param[out] event_status_p
164166
* Pointer to buffer to store the event status
165167
* Not updated in case return code is different from APP_RES_PROTO_OK
@@ -170,7 +172,8 @@ app_proto_res_e WPC_Proto_register_for_event_status(onEventStatus_cb_f onEventSt
170172
* Set to 0 in case return code is different from APP_RES_PROTO_OK
171173
* \note Buffer size should higher or equal to @WPC_PROTO_MAX_EVENTSTATUS_SIZE
172174
*/
173-
app_proto_res_e WPC_Proto_get_current_event_status(bool online,
175+
app_proto_res_e WPC_Proto_get_current_event_status(bool gw_online,
176+
bool sink_online,
174177
uint8_t * event_status_p,
175178
size_t * event_status_size_p);
176179

lib/wpc_proto/internal_modules/proto_config.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,8 @@ app_proto_res_e Proto_config_handle_set_scratchpad_target_and_action_request(
10761076
return APP_RES_PROTO_OK;
10771077
}
10781078

1079-
app_proto_res_e Proto_config_get_current_event_status(bool online,
1079+
app_proto_res_e Proto_config_get_current_event_status(bool gw_online,
1080+
bool sink_online,
10801081
uint8_t * event_status_p,
10811082
size_t * event_status_size_p)
10821083
{
@@ -1096,8 +1097,8 @@ app_proto_res_e Proto_config_get_current_event_status(bool online,
10961097
message_wirepas.status_event = message_StatusEvent_p;
10971098

10981099
fill_status_event(message_StatusEvent_p,
1099-
online ? wp_OnOffState_ON : wp_OnOffState_OFF,
1100-
online ? 1 : 0);
1100+
gw_online ? wp_OnOffState_ON : wp_OnOffState_OFF,
1101+
sink_online ? 1 : 0);
11011102

11021103
// Using the module static buffer
11031104
pb_ostream_t stream = pb_ostream_from_buffer(event_status_p, *event_status_size_p);

lib/wpc_proto/internal_modules/proto_config.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ app_proto_res_e Proto_config_handle_set_scratchpad_target_and_action_request(
8484
wp_SetScratchpadTargetAndActionReq *req,
8585
wp_SetScratchpadTargetAndActionResp *resp);
8686

87-
88-
app_proto_res_e Proto_config_get_current_event_status(bool online,
87+
app_proto_res_e Proto_config_get_current_event_status(bool gw_online,
88+
bool sink_online,
8989
uint8_t * event_status_p,
9090
size_t * event_status_size_p);
9191

lib/wpc_proto/wpc_proto.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ app_proto_res_e WPC_Proto_initialize(const char * port_name,
7979
_Static_assert(WPC_PROTO_MAX_EVENTSTATUS_SIZE >= (wp_StatusEvent_size + WPC_PROTO_GENERIC_MESSAGE_OVERHEAD),
8080
"Max proto size too low");
8181

82+
Common_init(gateway_id, gateway_model, gateway_version, sink_id);
83+
8284
if (open_and_check_connection(bitrate, port_name) != 0)
8385
{
8486
return APP_RES_PROTO_WPC_NOT_INITIALIZED;
@@ -95,7 +97,6 @@ app_proto_res_e WPC_Proto_initialize(const char * port_name,
9597
return APP_RES_PROTO_WRONG_PARAMETER;
9698
}
9799

98-
Common_init(gateway_id, gateway_model, gateway_version, sink_id);
99100
Proto_data_init();
100101
Proto_config_init();
101102
Proto_otap_init();
@@ -352,11 +353,13 @@ app_proto_res_e WPC_Proto_handle_request(const uint8_t * request_p,
352353

353354
}
354355

355-
app_proto_res_e WPC_Proto_get_current_event_status(bool online,
356+
app_proto_res_e WPC_Proto_get_current_event_status(bool gw_online,
357+
bool sink_online,
356358
uint8_t * event_status_p,
357359
size_t * event_status_size_p)
358360
{
359-
return Proto_config_get_current_event_status(online,
361+
return Proto_config_get_current_event_status(gw_online,
362+
sink_online,
360363
event_status_p,
361364
event_status_size_p);
362365
}

0 commit comments

Comments
 (0)