aboutsummaryrefslogtreecommitdiffstats
path: root/HAL-afb
diff options
context:
space:
mode:
authorTobias Jahnke <tjahnk@users.noreply.github.com>2017-08-10 10:35:39 +0200
committerTobias Jahnke <tjahnk@users.noreply.github.com>2017-08-16 16:00:50 +0200
commitcf590ad67211ee634d4cb24ca97c9e65891240b9 (patch)
treeba8117a88db9c08a3e0d19ad541b3679d53c10b0 /HAL-afb
parente94c8800c515dc64a7d7ae275e607e23591b8498 (diff)
implements wrapper for unicens functions
Diffstat (limited to 'HAL-afb')
-rw-r--r--HAL-afb/hal-most-unicens/CMakeLists.txt2
-rw-r--r--HAL-afb/hal-most-unicens/hal_most_unicens.c91
-rw-r--r--HAL-afb/hal-most-unicens/wrap_unicens.c227
-rw-r--r--HAL-afb/hal-most-unicens/wrap_unicens.h27
4 files changed, 275 insertions, 72 deletions
diff --git a/HAL-afb/hal-most-unicens/CMakeLists.txt b/HAL-afb/hal-most-unicens/CMakeLists.txt
index c87ca4d..828614f 100644
--- a/HAL-afb/hal-most-unicens/CMakeLists.txt
+++ b/HAL-afb/hal-most-unicens/CMakeLists.txt
@@ -21,7 +21,7 @@
PROJECT_TARGET_ADD(hal-most-unicens)
# Define project Targets
- ADD_LIBRARY(hal-most-unicens MODULE hal_most_unicens.c wrap-json.c)
+ ADD_LIBRARY(hal-most-unicens MODULE hal_most_unicens.c wrap-json.c wrap_unicens.c)
# Binder exposes a unique public entry point
SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
diff --git a/HAL-afb/hal-most-unicens/hal_most_unicens.c b/HAL-afb/hal-most-unicens/hal_most_unicens.c
index a1a1e66..394e502 100644
--- a/HAL-afb/hal-most-unicens/hal_most_unicens.c
+++ b/HAL-afb/hal-most-unicens/hal_most_unicens.c
@@ -20,17 +20,23 @@
#include "audio-interface.h"
#include "wrap-json.h"
#include "string.h"
+#include "wrap_unicens.h"
static int master_volume;
static json_bool master_switch;
static int pcm_volume[6];
+static uint8_t test[3] = {0x07,0x03,0xFF};
+
void unicens_master_vol_cb(halCtlsEnumT tag, alsaHalCtlMapT *control, void* handle, json_object *j_obj) {
const char *j_str = json_object_to_json_string(j_obj);
if (wrap_json_unpack(j_obj, "[i!]", &master_volume) == 0) {
AFB_NOTICE("master_volume: %s, value=%d", j_str, master_volume);
+ /*wrap_ucs_i2cwrite(0x270, test, 3);
+ wrap_ucs_i2cwrite(0x271, test, 3);
+ wrap_ucs_i2cwrite(0x272, test, 3);*/
}
else {
AFB_NOTICE("master_volume: INVALID STRING %s", j_str);
@@ -84,92 +90,35 @@ STATIC alsaHalSndCardT alsaHalSndCard = {
.volumeCB = NULL, /* use default volume normalization function */
};
-STATIC int unicens_start_binding() {
-
- json_object *j_response, *j_query = NULL;
- int err;
-
- /* Build an empty JSON object */
- err = wrap_json_pack(&j_query, "{}");
- if (err) {
- AFB_ERROR("Failed to create subscribe json object");
- goto OnErrorExit;
- }
+/* initializes ALSA sound card, UNICENS API */
+STATIC int unicens_service_init() {
+ int err = 0;
+ AFB_NOTICE("Initializing HAL-MOST-UNICENS-BINDING");
- err = afb_service_call_sync("UNICENS", "subscribe", j_query, &j_response);
+ err = halServiceInit(afbBindingV2.api, &alsaHalSndCard);
if (err) {
- AFB_ERROR("Fail subscribing to UNICENS events");
+ AFB_ERROR("Cannot initialize ALSA soundcard.");
goto OnErrorExit;
- }
- else {
- AFB_NOTICE("Subscribed to UNICENS events, res=%s", json_object_to_json_string(j_response));
- json_object_put(j_response);
- }
- json_object_put(j_query);
-#if 0
- /* Build JSON object to retrieve UNICENS configuration */
- err = wrap_json_pack(&j_query, "{}");
- if (err) {
- AFB_ERROR("Failed to create listconfig json object");
- goto OnErrorExit;
- }
+ }
- err = afb_service_call_sync("UNICENS", "listconfig", j_query, &j_response);
+ err= afb_daemon_require_api("UNICENS", 1);
if (err) {
- AFB_ERROR("Failed to call listconfig");
+ AFB_ERROR("Failed to access UNICENS API");
goto OnErrorExit;
}
- else {
- AFB_NOTICE("UNICENS listconfig result, res=%s", json_object_to_json_string(j_response));
- json_object_put(j_response);
- }
- json_object_put(j_query);
-#endif
- /* Build JSON object to initialize UNICENS */
- err = wrap_json_pack(&j_query, "{s:s}", "filename", "/home/agluser/DEVELOPMENT/AGL/BINDING/unicens2-binding/data/config_multichannel_audio_kit.xml");
+ err = wrap_ucs_subscribe_sync();
if (err) {
- AFB_ERROR("Failed to create initialize json object");
- goto OnErrorExit;
- }
- err = afb_service_call_sync("UNICENS", "initialise", j_query, &j_response);
- if (err) {
- AFB_ERROR("Failed to initialize UNICENS");
+ AFB_ERROR("Failed to subscribe to unicensv2-binding");
goto OnErrorExit;
}
- else {
- AFB_NOTICE("Initialized UNICENS, res=%s", json_object_to_json_string(j_response));
- json_object_put(j_response);
- }
- json_object_put(j_query);
-
-
- j_query = NULL;
- OnErrorExit:
- if (j_query)
- json_object_put(j_query);
- return NULL;
-}
-
-STATIC int unicens_service_init() {
- int err;
- AFB_NOTICE("Initializing HAL-MOST-UNICENS-BINDING");
- err = halServiceInit(afbBindingV2.api, &alsaHalSndCard);
- if (err) {
- AFB_ERROR("Cannot initialize hal-most-unicens binding.");
- goto OnErrorExit;
- }
-
- err= afb_daemon_require_api("UNICENS", 1);
+ err = wrap_ucs_initialize_sync("/home/agluser/DEVELOPMENT/AGL/BINDING/unicens2-binding/data/config_multichannel_audio_kit.xml");
if (err) {
- AFB_ERROR("UNICENS is missing or not initialized");
- goto OnErrorExit;
+ AFB_ERROR("Failed to initialize unicens-v2 binding");
+ goto OnErrorExit;
}
- unicens_start_binding();
-
-
OnErrorExit:
AFB_NOTICE("Initializing HAL-MOST-UNICENS-BINDING done..");
return err;
diff --git a/HAL-afb/hal-most-unicens/wrap_unicens.c b/HAL-afb/hal-most-unicens/wrap_unicens.c
new file mode 100644
index 0000000..15f94a1
--- /dev/null
+++ b/HAL-afb/hal-most-unicens/wrap_unicens.c
@@ -0,0 +1,227 @@
+/*
+ * Copyright (C) 2017, Microchip Technology Inc. and its subsidiaries.
+ * Author Tobias Jahnke
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#define _GNU_SOURCE
+#define AFB_BINDING_VERSION 2
+
+#include <string.h>
+#include <json-c/json.h>
+#include <afb/afb-binding.h>
+
+#include "wrap_unicens.h"
+#include "wrap-json.h"
+
+/* Subscribes to unicens2-binding events.
+ * \return Returns 0 if successful, otherwise != 0".
+ */
+extern int wrap_ucs_subscribe_sync() {
+
+ json_object *j_response, *j_query = NULL;
+ int err;
+
+ /* Build an empty JSON object */
+ err = wrap_json_pack(&j_query, "{}");
+ if (err) {
+ AFB_ERROR("Failed to create subscribe json object");
+ goto OnErrorExit;
+ }
+
+ err = afb_service_call_sync("UNICENS", "subscribe", j_query, &j_response);
+ if (err) {
+ AFB_ERROR("Fail subscribing to UNICENS events");
+ goto OnErrorExit;
+ }
+ else {
+ AFB_NOTICE("Subscribed to UNICENS events, res=%s", json_object_to_json_string(j_response));
+ json_object_put(j_response);
+ }
+ json_object_put(j_query);
+ j_query = NULL;
+
+OnErrorExit:
+ if (j_query)
+ json_object_put(j_query);
+ return err;
+}
+
+/* Retrieves XML configuration path to initialize unicens2-binding.
+ * \param config_path Directory containing XML configuration file(s).
+ * \return Returns 0 if successful, otherwise != 0".
+ */
+extern int wrap_ucs_getconfig_sync(const char *config_path) {
+ json_object *j_response, *j_query = NULL;
+ int err;
+
+ /* Build JSON object to retrieve UNICENS configuration */
+ if (config_path != NULL)
+ err = wrap_json_pack(&j_query, "{s:s}", "cfgpath", config_path);
+ else
+ err = wrap_json_pack(&j_query, "{}");
+
+ if (err) {
+ AFB_ERROR("Failed to create listconfig json object");
+ goto OnErrorExit;
+ }
+
+ err = afb_service_call_sync("UNICENS", "listconfig", j_query, &j_response);
+ if (err) {
+ AFB_ERROR("Failed to call listconfig");
+ goto OnErrorExit;
+ }
+ else {
+ AFB_NOTICE("UNICENS listconfig result, res=%s", json_object_to_json_string(j_response));
+ json_object_put(j_response);
+ }
+ json_object_put(j_query);
+ j_query = NULL;
+
+OnErrorExit:
+ if (j_query)
+ json_object_put(j_query);
+ return err;
+}
+
+
+/* Initializes the unicens2-binding.
+ * \param file_name Path to XML configuration file or \c NULL for
+ * first found file in default path.
+ * \return Returns 0 if successful, otherwise != 0".
+ */
+extern int wrap_ucs_initialize_sync(const char *file_name) {
+ json_object *j_response, *j_query = NULL;
+ int err;
+
+ /* Build JSON object to initialize UNICENS */
+ if (file_name != NULL)
+ err = wrap_json_pack(&j_query, "{s:s}", "filename", file_name);
+ else
+ err = wrap_json_pack(&j_query, "{}");
+
+ if (err) {
+ AFB_ERROR("Failed to create initialize json object");
+ goto OnErrorExit;
+ }
+ err = afb_service_call_sync("UNICENS", "initialise", j_query, &j_response);
+ if (err) {
+ AFB_ERROR("Failed to initialize UNICENS");
+ goto OnErrorExit;
+ }
+ else {
+ AFB_NOTICE("Initialized UNICENS, res=%s", json_object_to_json_string(j_response));
+ json_object_put(j_response);
+ }
+
+ json_object_put(j_query);
+ j_query = NULL;
+
+OnErrorExit:
+ if (j_query)
+ json_object_put(j_query);
+ return err;
+}
+
+
+static void wrap_ucs_i2cwrite_cb(void *closure __attribute__((unused)), int status, struct json_object *j_result) {
+
+ AFB_NOTICE("wrap_ucs_i2cwrite_cb: status=%d, res=%s", status, json_object_to_json_string(j_result));
+}
+
+/* Write I2C command to a network node.
+ * \param node Node address
+ * \param data_ptr Reference to command data
+ * \param data_sz Size of the command data. Valid values: 1..32.
+ * \return Returns 0 if successful, otherwise != 0".
+ */
+extern int wrap_ucs_i2cwrite_sync(uint16_t node, uint8_t *data_ptr, uint8_t data_sz) {
+
+ json_object *j_response, *j_query, *j_array = NULL;
+ int err;
+ uint8_t cnt;
+
+ j_query = json_object_new_object();
+ j_array = json_object_new_array();
+
+ if (!j_query || !j_array) {
+ err = -1;
+ AFB_ERROR("Failed to create writei2c json objects");
+ goto OnErrorExit;
+ }
+
+ 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_query, "node", json_object_new_int(node));
+ json_object_object_add(j_query, "data", j_array);
+
+ err = afb_service_call_sync("UNICENS", "writei2c", j_query, &j_response);
+
+ if (err) {
+ AFB_ERROR("Failed to call writei2c");
+ goto OnErrorExit;
+ }
+ else {
+ AFB_NOTICE("Called writei2c, res=%s", "async"/*json_object_to_json_string(j_response)*/);
+ json_object_put(j_response);
+ }
+
+ json_object_put(j_query);
+ j_query = NULL;
+
+OnErrorExit:
+ if (j_query)
+ json_object_put(j_query);
+ return err;
+}
+
+/* Write I2C command to a network node.
+ * \param node Node address
+ * \param data_ptr Reference to command data
+ * \param data_sz Size of the command data. Valid values: 1..32.
+ * \return Returns 0 if successful, otherwise != 0".
+ */
+extern int wrap_ucs_i2cwrite(uint16_t node, uint8_t *data_ptr, uint8_t data_sz) {
+
+ json_object *j_query, *j_array = NULL;
+ int err;
+ uint8_t cnt;
+
+ j_query = json_object_new_object();
+ j_array = json_object_new_array();
+
+ if (!j_query || !j_array) {
+ err = -1;
+ AFB_ERROR("Failed to create writei2c json objects");
+ goto OnErrorExit;
+ }
+
+ 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_query, "node", json_object_new_int(node));
+ json_object_object_add(j_query, "data", j_array);
+
+ afb_service_call("UNICENS", "writei2c", j_query, wrap_ucs_i2cwrite_cb, NULL);
+ err = 0;
+ j_query = NULL;
+
+OnErrorExit:
+ if (j_query)
+ json_object_put(j_query);
+ return err;
+}
diff --git a/HAL-afb/hal-most-unicens/wrap_unicens.h b/HAL-afb/hal-most-unicens/wrap_unicens.h
new file mode 100644
index 0000000..27071c7
--- /dev/null
+++ b/HAL-afb/hal-most-unicens/wrap_unicens.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2017, Microchip Technology Inc. and its subsidiaries.
+ * Author Tobias Jahnke
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#pragma once
+
+#include <stdint.h>
+
+extern int wrap_ucs_subscribe_sync();
+extern int wrap_ucs_getconfig_sync(const char *config_path);
+extern int wrap_ucs_initialize_sync(const char* file_name);
+extern int wrap_ucs_i2cwrite_sync(uint16_t node, uint8_t *data_ptr, uint8_t data_sz);
+extern int wrap_ucs_i2cwrite(uint16_t node, uint8_t *data_ptr, uint8_t data_sz);