+ AFB_NOTICE ("UNICENS stopped");
+ /* push an asynchronous request for loopback to call UcsXml_FreeVal */
+ sd_event_add_time(afb_daemon_get_event_loop(), NULL, CLOCK_MONOTONIC, 0, 0, OnStopCB, pTag);
+}
+
+/* helper function: wraps Rx message in json and triggers notification */
+STATIC void NotifyEventRxMsg(uint16_t src_addr, uint16_t msg_id, uint8_t *data_ptr, uint32_t data_sz) {
+
+ if (!eventDataRx)
+ return;
+
+ if (data_sz > CTRL_MAX_DATA_SZ) {
+ AFB_NOTICE("RX-MSG: discarded, payload exceeds %d bytes", CTRL_MAX_DATA_SZ);
+ return;
+ }
+
+ json_object *j_event_info = json_object_new_object();
+ json_object *j_array = json_object_new_array();
+
+ if (!j_event_info || !j_array) {
+ if (j_event_info) {
+ json_object_put(j_event_info);
+ }
+ if (j_array) {
+ json_object_put(j_array);
+ }
+ AFB_ERROR("Failed to create json objects");
+ return;
+ }
+
+ uint32_t cnt = 0U;
+ for (cnt = 0U; cnt < data_sz; cnt++) {
+ json_object_array_add(j_array, json_object_new_int(data_ptr[cnt]));
+ }
+
+ json_object_object_add(j_event_info, "node", json_object_new_int(src_addr));
+ json_object_object_add(j_event_info, "msgid", json_object_new_int(msg_id));
+ json_object_object_add(j_event_info, "data", j_array);