summaryrefslogtreecommitdiffstats
path: root/MOST_UNICENS/wrap_unicens.c
diff options
context:
space:
mode:
Diffstat (limited to 'MOST_UNICENS/wrap_unicens.c')
-rw-r--r--MOST_UNICENS/wrap_unicens.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/MOST_UNICENS/wrap_unicens.c b/MOST_UNICENS/wrap_unicens.c
index 095a2fe..4b75780 100644
--- a/MOST_UNICENS/wrap_unicens.c
+++ b/MOST_UNICENS/wrap_unicens.c
@@ -334,3 +334,35 @@ OnErrorExit:
json_object_put(j_query);
return err;
}
+
+extern int wrap_ucs_sendmessage(uint16_t src_addr, uint16_t msg_id, uint8_t *data_ptr, uint8_t data_sz) {
+
+ json_object *j_query, *j_response = NULL;
+ int err;
+ int node = (int)src_addr;
+ int msgid = (int)msg_id;
+ size_t data_size = (size_t)data_sz;
+
+ /* skip data attribute if possible, wrap_json_unpack may fail to deal with
+ * an empty Base64 string */
+ if (data_size > 0)
+ wrap_json_pack(&j_query, "{s:i, s:i, s:Y}", "node", node, "msgid", msgid, "data", data_ptr, data_size);
+ else
+ wrap_json_pack(&j_query, "{s:i, s:i}", "node", node, "msgid", msgid);
+
+ err = afb_service_call_sync("UNICENS", "sendmessage", j_query, &j_response);
+
+ if (err) {
+ AFB_ERROR("Failed to call wrap_ucs_sendmessage");
+ goto OnErrorExit;
+ }
+ else {
+ AFB_INFO("Called wrap_ucs_sendmessage, res=%s", json_object_to_json_string(j_response));
+ json_object_put(j_response);
+ }
+
+ j_query = NULL;
+
+OnErrorExit:
+ return err;
+}