summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2018-12-10 17:22:34 +0100
committerTobias Jahnke <tobias.jahnke@microchip.com>2018-12-19 10:27:57 +0100
commit362c23509cca3101b4abcb47f76c57baa69c8d08 (patch)
tree4e22d79b2915ab90b93a804144c6491561940c2f /plugin
parent5770713075119f42d3486fa8db616efa8231a336 (diff)
Add unicens input plugin for md microphone
Add unicens input plugin for multi-directionnal microphone. Update the unciens hal to load this plugin. Change-Id: I933ed6ff3a709d0c11bf86e64c83559a38386e98 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to 'plugin')
-rw-r--r--plugin/unicens-input/CMakeLists.txt44
-rw-r--r--plugin/unicens-input/unicens-md-mic-cb.c247
-rw-r--r--plugin/unicens-input/unicens-md-mic-cb.h61
-rw-r--r--plugin/unicens-input/unicens-md-mic.c109
-rw-r--r--plugin/unicens-input/unicens-md-mic.h56
5 files changed, 517 insertions, 0 deletions
diff --git a/plugin/unicens-input/CMakeLists.txt b/plugin/unicens-input/CMakeLists.txt
new file mode 100644
index 0000000..57ed7af
--- /dev/null
+++ b/plugin/unicens-input/CMakeLists.txt
@@ -0,0 +1,44 @@
+###########################################################################
+# Copyright 2015, 2016, 2017, 2018 IoT.bzh
+#
+# author: Jonathan Aillet <jonathan.aillet@iot.bzh>
+#
+# 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.
+###########################################################################
+
+PROJECT_TARGET_ADD(hal-unicens-md-input)
+
+ # Define targets
+ ADD_LIBRARY(${TARGET_NAME} MODULE
+ unicens-md-mic.c
+ unicens-md-mic-cb.c
+ )
+
+ # Alsa Plugin properties
+ SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
+ LABELS "PLUGIN"
+ PREFIX ""
+ SUFFIX ".ctlso"
+ OUTPUT_NAME ${TARGET_NAME}
+ )
+
+ # Library dependencies (include updates automatically)
+ TARGET_LINK_LIBRARIES(${TARGET_NAME}
+ afb-helpers
+ ctl-utilities
+ ${link_libraries}
+ )
+
+ target_include_directories(${TARGET_NAME}
+ PRIVATE "${CMAKE_SOURCE_DIR}/app-controller/ctl-lib"
+ )
diff --git a/plugin/unicens-input/unicens-md-mic-cb.c b/plugin/unicens-input/unicens-md-mic-cb.c
new file mode 100644
index 0000000..c7bc836
--- /dev/null
+++ b/plugin/unicens-input/unicens-md-mic-cb.c
@@ -0,0 +1,247 @@
+/*
+ * Copyright (C) 2018, "IoT.bzh".
+ * Author Jonathan Aillet
+ *
+ * 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.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <wrap-json.h>
+
+#include <afb/afb-binding.h>
+
+#include "unicens-md-mic.h"
+#include "unicens-md-mic-cb.h"
+
+/*******************************************************************************
+ * Unicens multi-directional microphone plugin verbs functions *
+ ******************************************************************************/
+
+void UnicensMdMicSetColorScheme(afb_req_t request)
+{
+ int32_t darkRed, darkBlue, darkGreen, lightRed, lightBlue, lightGreen, errorRed, errorBlue, errorGreen;
+
+ uint8_t setColorSchemeData[UNICENS_MD_MIC_SET_COLOR_SCHEME_DATA_LENGTH];
+
+ char *error, *info;
+
+ json_object *receivedRequestJson, *unicensServiceRequestJson, *unicensServiceReturnedJson;
+
+ afb_api_t apiHandle;
+
+ if(! (receivedRequestJson = afb_req_json(request))) {
+ afb_req_fail(request, "request_json", "Can't get request json");
+ return;
+ }
+
+ if(! (apiHandle = (afb_api_t ) afb_req_get_api(request))) {
+ afb_req_fail(request, "api_handle", "Can't get current hal controller api handle");
+ return;
+ }
+
+ if(wrap_json_unpack(receivedRequestJson, "{s:{s:i, s:i, s:i}, s:{s:i, s:i, s:i}, s:{s:i, s:i, s:i}}",
+ "dark",
+ "red", &darkRed,
+ "green", &darkGreen,
+ "blue", &darkBlue,
+ "light",
+ "red", &lightRed,
+ "green", &lightGreen,
+ "blue", &lightBlue,
+ "error",
+ "red", &errorRed,
+ "green", &errorGreen,
+ "blue", &errorBlue)) {
+ afb_req_fail_f(request, "requested_colors", "Can't get requested colors, might be a syntax error (json format should be : '%s')", UNICENS_MD_MIC_SET_COLOR_SCHEME_JSON);
+ return;
+ }
+
+ if(darkRed < 0 || darkRed > 255 || darkGreen < 0 || darkGreen > 255 || darkBlue < 0 || darkBlue > 255 ||
+ lightRed < 0 || lightRed > 255 || lightGreen < 0 || lightGreen > 255 || lightBlue < 0 || lightBlue > 255 ||
+ errorRed < 0 || errorRed > 255 || errorGreen < 0 || errorGreen > 255 || errorBlue < 0 || errorBlue > 255) {
+ afb_req_fail(request, "requested_colors", "Invalid requested colors, colors should be between 0 and 255");
+ return;
+ }
+
+ setColorSchemeData[0] = (uint8_t) UNICENS_MD_MIC_SET_COLOR_SCHEME_CMD;
+ setColorSchemeData[1] = (uint8_t) darkRed;
+ setColorSchemeData[2] = (uint8_t) darkGreen;
+ setColorSchemeData[3] = (uint8_t) darkBlue;
+ setColorSchemeData[4] = (uint8_t) lightRed;
+ setColorSchemeData[5] = (uint8_t) lightGreen;
+ setColorSchemeData[6] = (uint8_t) lightBlue;
+ setColorSchemeData[7] = (uint8_t) errorRed;
+ setColorSchemeData[8] = (uint8_t) errorGreen;
+ setColorSchemeData[9] = (uint8_t) errorBlue;
+
+ wrap_json_pack(&unicensServiceRequestJson, "{s:i, s:i, s:y}",
+ "node", UNICENS_MD_MIC_NODE,
+ "msgid", UNICENS_MD_MIC_SET_COLOR_SCHEME_MSG_ID,
+ "data", setColorSchemeData, (size_t) UNICENS_MD_MIC_SET_COLOR_SCHEME_DATA_LENGTH);
+
+ if(afb_api_call_sync(apiHandle,
+ UNICENS_API,
+ UNICENS_SEND_MSG_VERB,
+ unicensServiceRequestJson,
+ &unicensServiceReturnedJson,
+ &error,
+ &info)) {
+ afb_req_fail_f(request,
+ "unicens_service_call",
+ "Error '%s' during call to '%s' verb of '%s' api (info: '%s')",
+ error, UNICENS_SEND_MSG_VERB, UNICENS_API, info);
+ return;
+ }
+
+ afb_req_success_f(request, NULL, "Set color scheme correctly send on MOST network, multi-directional microphone colors should be set according to your request");
+}
+
+void UnicensMdMicSetMode(afb_req_t request)
+{
+ uint8_t setModeData[UNICENS_MD_MIC_SET_MODE_DATA_LENGTH];
+
+ char *mode, *error, *info;
+
+ json_object *receivedRequestJson, *unicensServiceRequestJson, *unicensServiceReturnedJson;
+
+ afb_api_t apiHandle;
+
+ if(! (receivedRequestJson = afb_req_json(request))) {
+ afb_req_fail(request, "request_json", "Can't get request json");
+ return;
+ }
+
+ if(! (apiHandle = (afb_api_t ) afb_req_get_api(request))) {
+ afb_req_fail(request, "api_handle", "Can't get current hal controller api handle");
+ return;
+ }
+
+ if(wrap_json_unpack(receivedRequestJson, "{s:s}", "mode", &mode)) {
+ afb_req_fail(request, "requested_mode", "Can't get requested mode, might be a syntax error (mode should be a string)");
+ return;
+ }
+
+ setModeData[0] = (uint8_t) UNICENS_MD_MIC_SET_COLOR_SCHEME_CMD;
+
+ if(! strcasecmp(mode, "off")) {
+ setModeData[1] = (uint8_t) UNICENS_MD_MIC_SET_MODE_OFF;
+ }
+ else if(! strcasecmp(mode, "idle")) {
+ setModeData[1] = (uint8_t) UNICENS_MD_MIC_SET_MODE_IDLE;
+ }
+ else if(! strcasecmp(mode, "listening")) {
+ setModeData[1] = (uint8_t) UNICENS_MD_MIC_SET_MODE_LISTENING;
+ }
+ else if(! strcasecmp(mode, "processing")) {
+ setModeData[1] = (uint8_t) UNICENS_MD_MIC_SET_MODE_PROCESSING;
+ }
+ else if(! strcasecmp(mode, "error")) {
+ setModeData[1] = (uint8_t) UNICENS_MD_MIC_SET_MODE_ERROR;
+ }
+ else if(! strcasecmp(mode, "doa")) {
+ setModeData[1] = (uint8_t) UNICENS_MD_MIC_SET_MODE_DOA;
+ }
+ else {
+ afb_req_fail(request, "requested_mode", "Invalid requested mode, should be : 'off', 'idle', 'listening', 'processing', 'error', or 'doa'");
+ return;
+ }
+
+ wrap_json_pack(&unicensServiceRequestJson, "{s:i, s:i, s:y}",
+ "node", UNICENS_MD_MIC_NODE,
+ "msgid", UNICENS_MD_MIC_SET_MODE_MSG_ID,
+ "data", setModeData, (size_t) UNICENS_MD_MIC_SET_MODE_DATA_LENGTH);
+
+ if(afb_api_call_sync(apiHandle,
+ UNICENS_API,
+ UNICENS_SEND_MSG_VERB,
+ unicensServiceRequestJson,
+ &unicensServiceReturnedJson,
+ &error,
+ &info)) {
+ afb_req_fail_f(request,
+ "unicens_service_call",
+ "Error '%s' during call to '%s' verb of '%s' api (info: '%s')",
+ error, UNICENS_SEND_MSG_VERB, UNICENS_API, info);
+ return;
+ }
+
+ afb_req_success_f(request, NULL, "Set mode correctly send on MOST network, multi-directional microphone mode should be set according to your request");
+}
+
+void UnicensMdMicSetDoa(afb_req_t request)
+{
+ uint8_t setDoaData[UNICENS_MD_MIC_SET_DOA_DATA_LENGTH];
+
+ int32_t doa;
+
+ char *error, *info;
+
+ json_object *receivedRequestJson, *unicensServiceRequestJson, *unicensServiceReturnedJson;
+
+ afb_api_t apiHandle;
+
+ if(! (receivedRequestJson = afb_req_json(request))) {
+ afb_req_fail(request, "request_json", "Can't get request json");
+ return;
+ }
+
+ if(! (apiHandle = (afb_api_t ) afb_req_get_api(request))) {
+ afb_req_fail(request, "api_handle", "Can't get current hal controller api handle");
+ return;
+ }
+
+ if(wrap_json_unpack(receivedRequestJson, "{s:i}", "doa", &doa)) {
+ afb_req_fail(request, "requested_doa", "Can't get requested doa (doa should be an integer)");
+ return;
+ }
+
+ if(doa < 0 || doa > 359) {
+ afb_req_fail(request, "requested_doa", "Invalid doa, should be expressed in degree between 0 and 359");
+ return;
+ }
+
+ setDoaData[0] = (uint8_t) UNICENS_MD_MIC_SET_DOA_CMD;
+ setDoaData[1] = (uint8_t) ((doa & 0xFF00) >> 8);
+ setDoaData[2] = (uint8_t) (doa & 0xFF);
+
+ wrap_json_pack(&unicensServiceRequestJson, "{s:i, s:i, s:y}",
+ "node", UNICENS_MD_MIC_NODE,
+ "msgid", UNICENS_MD_MIC_SET_DOA_MSG_ID,
+ "data", setDoaData, (size_t) UNICENS_MD_MIC_SET_DOA_DATA_LENGTH);
+
+ if(afb_api_call_sync(apiHandle,
+ UNICENS_API,
+ UNICENS_SEND_MSG_VERB,
+ unicensServiceRequestJson,
+ &unicensServiceReturnedJson,
+ &error,
+ &info)) {
+ afb_req_fail_f(request,
+ "unicens_service_call",
+ "Error '%s' during call to '%s' verb of '%s' api (info: '%s')",
+ error, UNICENS_SEND_MSG_VERB, UNICENS_API, info);
+ return;
+ }
+
+ afb_req_success_f(request, NULL, "Set doa correctly send on MOST network, multi-directional microphone doa should be set according to your request");
+}
+
+void UnicensMdMicGetDoa(afb_req_t request)
+{
+ AFB_REQ_WARNING(request, "Not implemented because %s api does not include the doa with its response", UNICENS_API);
+
+ afb_req_success_f(request, NULL, "Not implemented because %s api does not include the doa with its response", UNICENS_API);
+} \ No newline at end of file
diff --git a/plugin/unicens-input/unicens-md-mic-cb.h b/plugin/unicens-input/unicens-md-mic-cb.h
new file mode 100644
index 0000000..40ca910
--- /dev/null
+++ b/plugin/unicens-input/unicens-md-mic-cb.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2018, "IoT.bzh".
+ * Author Jonathan Aillet
+ *
+ * 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.
+ *
+ */
+
+#ifndef _UNICENS_MD_MIC_CB_INCLUDE_
+#define _UNICENS_MD_MIC_CB_INCLUDE_
+
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+
+#include <afb/afb-binding.h>
+
+#define UNICENS_MD_MIC_SET_COLOR_SCHEME_VERB "set_md_mic_color_scheme"
+#define UNICENS_MD_MIC_SET_MODE_VERB "set_md_mic_mode"
+#define UNICENS_MD_MIC_SET_DOA_VERB "set_md_mic_doa"
+#define UNICENS_MD_MIC_GET_DOA_VERB "get_md_mic_doa"
+
+#define UNICENS_MD_MIC_SET_COLOR_SCHEME_JSON "\
+\"light\" : \
+{ \
+\"red\" : integer, \
+\"green\" : integer, \
+\"blue\" : integer \
+}, \
+\"dark\" : \
+{ \
+\"red\" : integer, \
+\"green\" : integer, \
+\"blue\" : integer \
+}, \
+\"error\" : \
+{ \
+\"red\" : integer, \
+\"green\" : integer, \
+\"blue\" : integer \
+} \
+}\
+"
+
+// Unicens multi-directional microphone plugin verbs functions
+void UnicensMdMicSetColorScheme(afb_req_t request);
+void UnicensMdMicSetMode(afb_req_t request);
+void UnicensMdMicSetDoa(afb_req_t request);
+void UnicensMdMicGetDoa(afb_req_t request);
+
+#endif /*_UNICENS_MD_MIC_CB_INCLUDE_ */ \ No newline at end of file
diff --git a/plugin/unicens-input/unicens-md-mic.c b/plugin/unicens-input/unicens-md-mic.c
new file mode 100644
index 0000000..b35743b
--- /dev/null
+++ b/plugin/unicens-input/unicens-md-mic.c
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2018, "IoT.bzh".
+ * Author Jonathan Aillet
+ *
+ * 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.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <wrap-json.h>
+
+#include <ctl-config.h>
+
+#include "unicens-md-mic.h"
+#include "unicens-md-mic-cb.h"
+
+CTLP_CAPI_REGISTER(UNICENS_MD_MIC_PLUGIN_NAME)
+
+// Call at pre-initialisation time
+CTLP_ONLOAD(plugin, callbacks)
+{
+ AFB_API_NOTICE(plugin->api, "%s Plugin Registered correctly: uid='%s' 'info='%s'", UNICENS_MD_MIC_PLUGIN_NAME, plugin->uid, plugin->info);
+
+ return 0;
+}
+
+// Call at initialisation time
+CTLP_INIT(plugin, callbacks)
+{
+ AFB_API_INFO(plugin->api, "Initialization of %s plugin", UNICENS_MD_MIC_PLUGIN_NAME);
+
+ if(afb_api_require_api(plugin->api, UNICENS_API, 1)) {
+ AFB_API_WARNING(plugin->api, "Didn't succeed to require %s api, won't be able to send command to unicens multi-directional microphone", UNICENS_API);
+ return 0;
+ }
+
+ // Loading Unicens multi-directional microphone specific verbs
+ if(afb_api_add_verb(plugin->api,
+ UNICENS_MD_MIC_SET_COLOR_SCHEME_VERB,
+ "Set Unicens multi-directional microphone color scheme",
+ UnicensMdMicSetColorScheme,
+ NULL,
+ NULL,
+ 0,
+ 0)) {
+ AFB_API_ERROR(plugin->api,
+ "Error while creating verb for unicens multi-directional microphone plugin : '%s'",
+ UNICENS_MD_MIC_SET_COLOR_SCHEME_VERB);
+ return -1;
+ }
+
+ if(afb_api_add_verb(plugin->api,
+ UNICENS_MD_MIC_SET_MODE_VERB,
+ "Set Unicens multi-directional microphone mode",
+ UnicensMdMicSetMode,
+ NULL,
+ NULL,
+ 0,
+ 0)) {
+ AFB_API_ERROR(plugin->api,
+ "Error while creating verb for unicens multi-directional microphone plugin : '%s'",
+ UNICENS_MD_MIC_SET_MODE_VERB);
+ return -2;
+ }
+
+ if(afb_api_add_verb(plugin->api,
+ UNICENS_MD_MIC_SET_DOA_VERB,
+ "Set Unicens multi-directional microphone DOA",
+ UnicensMdMicSetDoa,
+ NULL,
+ NULL,
+ 0,
+ 0)) {
+ AFB_API_ERROR(plugin->api,
+ "Error while creating verb for unicens multi-directional microphone plugin : '%s'",
+ UNICENS_MD_MIC_SET_DOA_VERB);
+ return -3;
+ }
+
+ if(afb_api_add_verb(plugin->api,
+ UNICENS_MD_MIC_GET_DOA_VERB,
+ "Get Unicens multi-directional microphone DOA",
+ UnicensMdMicGetDoa,
+ NULL,
+ NULL,
+ 0,
+ 0)) {
+ AFB_API_ERROR(plugin->api,
+ "Error while creating verb for unicens multi-directional microphone plugin : '%s'",
+ UNICENS_MD_MIC_GET_DOA_VERB);
+ return -4;
+ }
+
+ AFB_API_NOTICE(plugin->api, "Initialization of %s plugin correctly done", UNICENS_MD_MIC_PLUGIN_NAME);
+
+ return 0;
+} \ No newline at end of file
diff --git a/plugin/unicens-input/unicens-md-mic.h b/plugin/unicens-input/unicens-md-mic.h
new file mode 100644
index 0000000..3a9a12b
--- /dev/null
+++ b/plugin/unicens-input/unicens-md-mic.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2018, "IoT.bzh".
+ * Author Jonathan Aillet
+ *
+ * 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.
+ *
+ */
+
+#ifndef _UNICENS_MD_MIC_INCLUDE_
+#define _UNICENS_MD_MIC_INCLUDE_
+
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+
+#define UNICENS_MD_MIC_PLUGIN_NAME "unicens-md-input"
+
+#define UNICENS_API "UNICENS"
+#define UNICENS_SEND_MSG_VERB "sendmessage"
+
+#define UNICENS_MD_MIC_NODE 0x520
+
+#define UNICENS_MD_MIC_SET_COLOR_SCHEME_MSG_ID 0x1000
+#define UNICENS_MD_MIC_SET_MODE_MSG_ID 0x1001
+#define UNICENS_MD_MIC_SET_DOA_MSG_ID 0x1002
+#define UNICENS_MD_MIC_GET_DOA_MSG_ID 0x1003
+
+#define UNICENS_MD_MIC_SET_COLOR_SCHEME_CMD 0x00
+#define UNICENS_MD_MIC_SET_COLOR_SCHEME_DATA_LENGTH 10
+
+#define UNICENS_MD_MIC_SET_MODE_CMD 0x00
+#define UNICENS_MD_MIC_SET_MODE_OFF 0x00
+#define UNICENS_MD_MIC_SET_MODE_IDLE 0x01
+#define UNICENS_MD_MIC_SET_MODE_LISTENING 0x02
+#define UNICENS_MD_MIC_SET_MODE_PROCESSING 0x03
+#define UNICENS_MD_MIC_SET_MODE_ERROR 0x04
+#define UNICENS_MD_MIC_SET_MODE_DOA 0x06
+#define UNICENS_MD_MIC_SET_MODE_DATA_LENGTH 2
+
+#define UNICENS_MD_MIC_SET_DOA_CMD 0x00
+#define UNICENS_MD_MIC_SET_DOA_DATA_LENGTH 3
+
+#define UNICENS_MD_MIC_GET_DOA_DATA 0x01
+#define UNICENS_MD_MIC_GET_DOA_DATA_LENGTH 1
+
+#endif /*_UNICENS_MD_MIC_INCLUDE_ */ \ No newline at end of file