aboutsummaryrefslogtreecommitdiffstats
path: root/binding/wrap-unicens/wrap-unicens.c
diff options
context:
space:
mode:
authorTobias Jahnke <tobias.jahnke@microchip.com>2019-10-15 15:14:30 +0200
committerTobias Jahnke <tobias.jahnke@microchip.com>2019-10-16 06:11:37 +0000
commite91eaa18befd14446d280311c9bd5c05f29801f0 (patch)
treec8921df433cacd724a7ade71f74be2aa962adff0 /binding/wrap-unicens/wrap-unicens.c
parent6854f72cb81b10e1add164e754aba1952df5b269 (diff)
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 <tobias.jahnke@microchip.com> Change-Id: I387efaeaf0cffd06b3d88efbeeaf2ef7eb23c780
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;