From e91eaa18befd14446d280311c9bd5c05f29801f0 Mon Sep 17 00:00:00 2001 From: Tobias Jahnke Date: Tue, 15 Oct 2019 15:14:30 +0200 Subject: unicens-controller: add DOA feature Introduce a new API to retrieve the current direction of audio (DOA) recognized by the microphone. Bug-AGL: SPEC-2899 Signed-off-by: Tobias Jahnke Change-Id: I387efaeaf0cffd06b3d88efbeeaf2ef7eb23c780 --- binding/wrap-unicens/wrap-unicens.c | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'binding/wrap-unicens/wrap-unicens.c') 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; -- cgit 1.2.3-korg