aboutsummaryrefslogtreecommitdiffstats
path: root/binding/wrap-unicens/wrap-unicens.c
diff options
context:
space:
mode:
Diffstat (limited to 'binding/wrap-unicens/wrap-unicens.c')
-rw-r--r--binding/wrap-unicens/wrap-unicens.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/binding/wrap-unicens/wrap-unicens.c b/binding/wrap-unicens/wrap-unicens.c
index e5d4570..84b94cd 100644
--- a/binding/wrap-unicens/wrap-unicens.c
+++ b/binding/wrap-unicens/wrap-unicens.c
@@ -66,6 +66,56 @@ extern int wrap_ucs_subscribe_sync(void) {
return 0;
}
+/*
+ * Subscribes to unicens2-binding RX message events.
+ * \return Returns 0 if successful, otherwise != 0".
+ */
+extern int wrap_ucs_subscriberx_sync(void) {
+ int err;
+
+ json_object *j_response, *j_query = NULL;
+ char *error, *info;
+
+ /* Build an empty JSON object */
+ if((err = wrap_json_pack(&j_query, "{}"))) {
+ AFB_API_ERROR(api_handle_, "Failed to create subscribe RX json object");
+ return err;
+ }
+
+ if((err = afb_api_call_sync(api_handle_, "UNICENS", "subscriberx", j_query, &j_response, &error, &info))) {
+ AFB_API_ERROR(api_handle_, "Fail subscribing to UNICENS RX events");
+ return err;
+ }
+ else {
+ AFB_API_NOTICE(api_handle_, "Subscribed to UNICENS RX events, res=%s", json_object_to_json_string(j_response));
+ json_object_put(j_response);
+ }
+
+ return 0;
+}
+
+extern int wrap_ucs_interpretrx_event(const char *event, struct json_object *object, wrap_ucs_rx_message_cb_t callback) {
+ int node_id = 0;
+ int msg_id = 0;
+ uint8_t *data_ptr = NULL;
+ size_t data_sz = 0;
+
+ if (strcmp(event, "UNICENS/rx-message") != 0) {
+ return -1; // unhandled event
+ }
+
+ if (wrap_json_unpack(object, "{s:i, s:i, s?Y}", "node", &node_id, "msgid", &msg_id, "data", &data_ptr, &data_sz) != 0) {
+ AFB_API_NOTICE(api_handle_, "Parsing rx-message failed.");
+ return -2;
+ }
+
+ if (callback != NULL) {
+ callback((uint16_t)node_id, (uint16_t)msg_id, (uint16_t)data_sz, data_ptr);
+ }
+
+ return 0;
+}
+
extern int wrap_ucs_interpret_event(const char *event, struct json_object *object, wrap_ucs_availability_cb_t callback) {
int node_id = 0;
int available = false;