diff --git a/CMakeLists.txt b/CMakeLists.txt index 0dad4c3..82eefd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,9 @@ set(C_CPP_FLAGS "${C_CPP_FLAGS} -Wno-deprecated-declarations") set(C_CPP_FLAGS "${C_CPP_FLAGS} -Werror=return-type") set(C_CPP_FLAGS "${C_CPP_FLAGS} -Werror=parentheses") set(C_CPP_FLAGS "${C_CPP_FLAGS} -Wfatal-errors") +set(C_CPP_FLAGS "${C_CPP_FLAGS} -Wno-unused-result") set(C_CPP_FLAGS "${C_CPP_FLAGS} -Wno-comment") + set(C_CPP_FLAGS "${C_CPP_FLAGS} -O3") set(C_CPP_FLAGS "${C_CPP_FLAGS} -g3") set(C_CPP_FLAGS "${C_CPP_FLAGS} -fPIC") diff --git a/env/app.sh b/env/app.sh new file mode 100644 index 0000000..8a542e5 --- /dev/null +++ b/env/app.sh @@ -0,0 +1,4 @@ +#!/bin/bash +cd /app +source /etc/device_info.env +./app.out --device_id ${DEVICE_ID} --aiui_auth_id ${AIUI_AUTH_ID} \ No newline at end of file diff --git a/env/app_monitor.sh b/env/app_monitor.sh new file mode 100755 index 0000000..cdb6ea1 --- /dev/null +++ b/env/app_monitor.sh @@ -0,0 +1,15 @@ +# +# 1. 监听app.out,如果app.out退出,则重启app.out +# + +# 1. 监听app.out,如果app.out退出,则重启app.out +while true; do + ps -ef | grep app.out | grep -v grep + if [ $? -ne 0 ]; then + echo "app.out is not running, restart it" + cd /app + ./app.sh + fi + sleep 1 +done + diff --git a/env/rootfs/var/spool/cron/crontabs/root b/env/rootfs/var/spool/cron/crontabs/root new file mode 100644 index 0000000..cb10650 --- /dev/null +++ b/env/rootfs/var/spool/cron/crontabs/root @@ -0,0 +1,4 @@ +# +# 定时任务,每天晚上12点,自动杀死应用程序 +# +0 0 * * * killall app.out \ No newline at end of file diff --git a/env/speaker_control.sh b/env/speaker_control.sh old mode 100644 new mode 100755 diff --git a/env/startup.sh b/env/startup.sh index 3b72449..c1df478 100755 --- a/env/startup.sh +++ b/env/startup.sh @@ -1,3 +1,5 @@ #!/bin/bash cd /app -./app.out & \ No newline at end of file +firefox --kiosk www.baidu.com +./app.sh +./app_monitor.sh & diff --git a/sh/boardinit.sh b/sh/boardinit.sh index ac04076..62d04bc 100755 --- a/sh/boardinit.sh +++ b/sh/boardinit.sh @@ -44,6 +44,7 @@ function generate_device_info() { echo "DEVICE_ID=${DEVICE_ID}" >/etc/device_info.env echo "FRP_SERVER_ADDR=${FTP_SERVER_ADDR}" >>/etc/device_info.env + echo "AIUI_AUTH_ID=${AIUI_AUTH_ID}" >>/etc/device_info.env echo "+++++++++ create /etc/device_info.env +++++++++" cat /etc/device_info.env @@ -70,7 +71,6 @@ function update_frpc_config() { # local_port = 22 # remote_port = 0 - echo "[common]" >/etc/frpc.ini echo "server_addr = ${FTP_SERVER_ADDR}" >>/etc/frpc.ini echo "server_port = 7000" >>/etc/frpc.ini @@ -98,6 +98,7 @@ function update_frpc_config() { set -e DEVICE_ID="" FTP_SERVER_ADDR="" +AIUI_AUTH_ID="" FIX_MAC="" PARAMETERS=$@ EXEC_IN_BOARD=false @@ -119,6 +120,12 @@ for i in "$@"; do FIX_MAC=$1 shift ;; + + --aiui_auth_id) + shift + AIUI_AUTH_ID=$1 + shift + ;; --exec_in_board) shift EXEC_IN_BOARD=$1 @@ -156,4 +163,4 @@ generate_device_info # 翻转屏幕 ff_rotate right -update_frpc_config \ No newline at end of file +update_frpc_config diff --git a/src/configs/gconfig.hpp b/src/configs/gconfig.hpp index 1a9158f..3672cac 100644 --- a/src/configs/gconfig.hpp +++ b/src/configs/gconfig.hpp @@ -26,11 +26,12 @@ marco(int /* */, wakeup_source, 0.9) /*唤醒词配置*/ \ marco(bool /* */, voice_logger_enable, true) /*是否记录语音配置*/ \ marco(string /* */, aiui_appid, "5938b7c7") /*aiui*/ \ - marco(string /* */, aiui_appkey, "") /*aiui*/ \ - marco(string /* */, aiui_auth_id, "ac30105366ea460f9ff08ddac0c4f71e") /*aiui:产品未量产前使用次ID*/ \ + marco(string /* */, aiui_appkey, "") /*aiui*/ \ + marco(string /* */, aiui_auth_id, "") /*aiui:产品未量产前使用次ID*/ \ marco(string /* */, aiui_scene, "main_box") /*aiui*/ \ marco(string /* */, device_io_uart_path, "/dev/ttyUSB1") /*唤醒词配置,对应50ms*/ \ marco(int /* */, device_io_uart_baundrate, 115200) /*唤醒词配置,对应50ms*/ \ + marco(int /* */, speaker_driver_ic_ctrl_pin, 60) /**/ \ marco(string /* */, lightControlMode, "auto") /*照明灯控制模式 auto/manual*/ \ marco(int /* */, lightAutoOpenHour, 18) /**/ \ marco(int /* */, lightAutoOpenMin, 0) /**/ \ diff --git a/src/main.cpp b/src/main.cpp index f16160f..c401e77 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,6 +56,13 @@ class Main { void buildDeviceIOService(); void buildVoiceProcessService(); void onSIGINT(); + + void dosystem(string order, bool dump) { + if (dump) { + logger->info("{}", order); + } + system(order.c_str()); + } }; Main *g_main; @@ -74,10 +81,11 @@ void Main::onSIGINT() { exit(0); } void Main::appSetup(int argc, char *argv[]) { string g_host_server_ip; - string g_device_id; -#if 0 - auto cli = ( // - (required("-device_id") & value("device_id", g_device_id)).doc("device_id") // + string device_id; + string aiui_auth_id; +#if 1 + auto cli = ((required("-device_id") & value("device_id", device_id)).doc("device_id"), + (required("-aiui_auth_id") & value("aiui_auth_id", aiui_auth_id)).doc("aiui_auth_id") // ); if (!parse(argc, argv, cli)) { cout << make_man_page(cli, argv[0]); @@ -97,7 +105,8 @@ void Main::appSetup(int argc, char *argv[]) { logger->info("build {}.....", "Config"); BUILD_AND_REG_SERRVICE(GConfig); GET_SERVICE(GConfig)->initialize(); - if (!g_device_id.empty()) GET_SERVICE(GConfig)->set_deviceId(g_device_id); + if (!device_id.empty()) GET_SERVICE(GConfig)->set_deviceId(device_id); + if (!aiui_auth_id.empty()) GET_SERVICE(GConfig)->set_aiui_auth_id(aiui_auth_id); } void Main::updateRootfs() { @@ -124,6 +133,16 @@ void Main::buildDeviceIOService() { */ auto config = GET_SERVICE(GConfig); + /** + * @brief 喇叭初始化 + */ + + logger->info("enable speaker ctrl ic"); + + dosystem(fmt::format("echo {} >/sys/class/gpio/export", config->get_speaker_driver_ic_ctrl_pin()), true); + dosystem(fmt::format("echo out >/sys/class/gpio/gpio{}/direction", config->get_speaker_driver_ic_ctrl_pin()), true); + dosystem(fmt::format("echo 1 >/sys/class/gpio/gpio{}/value", config->get_speaker_driver_ic_ctrl_pin()), true); + #if 1 BUILD_AND_REG_SERRVICE(DeviceIOService); #else diff --git a/src/service/main_control_service.cpp b/src/service/main_control_service.cpp index 6fed447..b13f01d 100644 --- a/src/service/main_control_service.cpp +++ b/src/service/main_control_service.cpp @@ -170,6 +170,14 @@ void MainControlService::constructSession() { */ lock_guard lock(m_voiceprocessmutex); + /** + * @brief + * TODO: + * 不知道什么原因喇叭有时候会失效,此处相当于重新使能了一下喇叭。 + */ + system(fmt::format("echo 0 >/sys/class/gpio/gpio{}/value", m_zconfig->get_speaker_driver_ic_ctrl_pin()).c_str()); + ThisThread().sleepForMs(33); + system(fmt::format("echo 1 >/sys/class/gpio/gpio{}/value", m_zconfig->get_speaker_driver_ic_ctrl_pin()).c_str()); m_smartSoundboxPlayer->triggerWakeup(); if (m_conversationSession) { @@ -354,5 +362,8 @@ void MainControlService::processReceiveMessage(fromwhere_t fromwhere, const json // int id = in["id"]; receipt["power"][0] = m_deviceIOService->fanGetState(0); receipt["power"][1] = m_deviceIOService->fanGetState(0); + } else if (in["command"] == "triggerWakeup") { + logger->info("triggerWakeup from web"); + constructSession(); } } diff --git a/src/service/main_control_service.hpp b/src/service/main_control_service.hpp index 953a3b6..5c62c11 100644 --- a/src/service/main_control_service.hpp +++ b/src/service/main_control_service.hpp @@ -102,6 +102,13 @@ class MainControlService : public enable_shared_from_this { void processasrResult_nlp(json& rxjson); void processasrResult_tts(json& rxjson); + void dosystem(string order, bool dump) { + if (dump) { + logger->info("do:{}", order); + } + system(order.c_str()); + } + /** * @brief 处理本次对话,一般接收完全部的ASR结果后,调用此函数 */ diff --git a/webapp/debug/device_test.html b/webapp/debug/device_test.html index 3b95995..d337ca6 100644 --- a/webapp/debug/device_test.html +++ b/webapp/debug/device_test.html @@ -242,6 +242,14 @@ onclick='zcmd.send_message({"command": "getDeviceState"},2000).then((data) => {alert(JSON.stringify(data,null,2))})'>Trigger + + + triggerWakeup + - + + + diff --git a/webapp/debug/wakeup_control.html b/webapp/debug/wakeup_control.html new file mode 100644 index 0000000..0ea8e6c --- /dev/null +++ b/webapp/debug/wakeup_control.html @@ -0,0 +1,51 @@ + + + + + + + + + 唤醒测试 + + + + + + + +
+

唤醒测试

+ + + + + + +
triggerWakeup- +
+
+ + + + + + + + \ No newline at end of file