You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

218 lines
6.8 KiB

2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
  1. #include <curl/curl.h>
  2. #include <iostream>
  3. #include <string>
  4. #include "zlinuxcomponents/aiui_ws/aiui_service.hpp"
  5. #include "zlinuxcomponents/alsaplayer/AudioPlayerAlsaImpl.hpp"
  6. #include "zlinuxcomponents/alsaplayer/smart_soundbox_player.hpp"
  7. #include "zlinuxcomponents/zmainhelper.hpp"
  8. //
  9. #include "configs/zconfig.hpp"
  10. #include "iflytopcpp/core/spdlogfactory/logger.hpp"
  11. #include "iflytopcpp/core/thread/thread.hpp"
  12. #include "version.hpp"
  13. #include "zlinuxcomponents/rootfs_auto_update/rootfs_auto_update.hpp"
  14. #include "zservice_container/zservice_container.hpp"
  15. #include "zwebservice/zwebservice.hpp"
  16. //
  17. #include "service/device_io_service.hpp"
  18. #include "service/device_io_service_mock.hpp"
  19. #include "service/light_control_service.hpp"
  20. #include "service/main_control_service.hpp"
  21. #include "service/report_service.hpp"
  22. #include "service/voiceprocess/audio_logging_service.hpp"
  23. #include "service/voiceprocess/audio_recoder_service.hpp"
  24. #include "service/voiceprocess/beforeasr_voiceprocesser.hpp"
  25. #include "service/voiceprocess/beforewakeup_voiceprocesser.hpp"
  26. #include "service/voiceprocess/wakeup_processer.hpp"
  27. //
  28. using namespace iflytop;
  29. using namespace core;
  30. using namespace std;
  31. using namespace clipp;
  32. class Main {
  33. ENABLE_LOGGER(Main);
  34. private:
  35. unique_ptr<Thread> thread;
  36. private:
  37. int main(int argc, char *argv[]);
  38. public:
  39. Main(/* args */) {}
  40. ~Main() {}
  41. void run(int argc, char *argv[]) {
  42. thread.reset(new Thread("main", [&]() { exit(main(argc, argv)); }));
  43. while (true) sleep(1000);
  44. }
  45. void appSetup(int argc, char *argv[]);
  46. void updateRootfs();
  47. void buildDeviceIOService();
  48. void buildVoiceProcessService();
  49. void onSIGINT();
  50. };
  51. Main *g_main;
  52. void onsignal(int signo) { g_main->onSIGINT(); }
  53. int main(int argc, char *argv[]) {
  54. Main main;
  55. g_main = &main;
  56. ::signal(SIGINT, onsignal);
  57. main.run(argc, argv);
  58. }
  59. /***********************************************************************************************************************
  60. * =======================================================Main======================================================== *
  61. ***********************************************************************************************************************/
  62. void Main::onSIGINT() { exit(0); }
  63. void Main::appSetup(int argc, char *argv[]) {
  64. string g_host_server_ip;
  65. string g_device_id;
  66. #if 0
  67. auto cli = ( //
  68. (required("-device_id") & value("device_id", g_device_id)).doc("device_id") //
  69. );
  70. if (!parse(argc, argv, cli)) {
  71. cout << make_man_page(cli, argv[0]);
  72. exit(-1);
  73. }
  74. #endif
  75. logger->info("system setup start.");
  76. spdlog::flush_on(spdlog::level::debug);
  77. logger->info("#");
  78. logger->info("# company:{}", "ifytop");
  79. logger->info("# version:{}", VERSION);
  80. logger->info("#");
  81. // BUILD_AND_REG_SERRVICE(Config);
  82. logger->info("build {}.....", "Config");
  83. BUILD_AND_REG_SERRVICE(ZConfig);
  84. GET_SERVICE(ZConfig)->initialize();
  85. if (!g_device_id.empty()) GET_SERVICE(ZConfig)->set_deviceId(g_device_id);
  86. }
  87. void Main::updateRootfs() {
  88. /**
  89. * @brief rootfs目录中的文件和系统中对应路径的文件是否一致
  90. *
  91. *
  92. * ./rootfs/etc/asound.conf /etc/asound.conf
  93. *
  94. */
  95. auto rootfsAutoUpdate = make_shared<RootfsAutoUpdate>();
  96. rootfsAutoUpdate->compareAndReplace();
  97. logger->info("rootfs changed:{}", rootfsAutoUpdate->isChanged() ? "yes" : "no");
  98. if (rootfsAutoUpdate->isChanged()) {
  99. logger->info("reboot system.");
  100. logger->warn("not auto reboot, please reboot manually.");
  101. // system("reboot");
  102. }
  103. }
  104. void Main::buildDeviceIOService() {
  105. /**
  106. * @brief DeviceIOService初始化
  107. */
  108. auto config = GET_SERVICE(ZConfig);
  109. #if 1
  110. BUILD_AND_REG_SERRVICE(DeviceIOService);
  111. #else
  112. BUILD_AND_REG_MOCK_SERRVICE(DeviceIOService, DeviceIOServiceMock);
  113. #endif
  114. GET_SERVICE(DeviceIOService)->initialize(config->get_device_io_uart_path(), config->get_device_io_uart_baundrate());
  115. }
  116. void Main::buildVoiceProcessService() {
  117. /**
  118. * @brief
  119. */
  120. auto config = GET_SERVICE(ZConfig);
  121. // AudioLoggingService
  122. BUILD_AND_REG_SERRVICE(AudioLoggingService);
  123. GET_SERVICE(AudioLoggingService)->initialize(config->get_voice_logger_enable());
  124. // 音频采集
  125. BUILD_AND_REG_SERRVICE(AudioRecoderService);
  126. GET_SERVICE(AudioRecoderService)
  127. ->initialize(config->get_recoder_device_name().c_str(), //
  128. config->get_recoder_ch_number(), //
  129. config->get_recoder_sample_rate(), //
  130. SND_PCM_FORMAT_S16_LE, //
  131. config->get_recoder_period_time_ms());
  132. // BfWakeupVProcesser
  133. BUILD_AND_REG_SERRVICE(BfWakeupVProcesser);
  134. GET_SERVICE(BfWakeupVProcesser)->initialize();
  135. // BeforeAsrVoiceProcesser
  136. BUILD_AND_REG_SERRVICE(BfAsrVProcesser);
  137. GET_SERVICE(BfAsrVProcesser)->initialize();
  138. // WakeupProcesser
  139. BUILD_AND_REG_SERRVICE(WakeupProcesser);
  140. GET_SERVICE(WakeupProcesser)
  141. ->initialize(config->get_wakeup_lib_module(), //
  142. config->get_wakeup_module_path(), //
  143. config->get_wakeup_chunk_length());
  144. // AsrProcesser
  145. const char *appid = config->get_aiui_appid().c_str();
  146. const char *appkey = config->get_aiui_appkey().c_str();
  147. json paramj;
  148. paramj["result_level"] = "plain";
  149. paramj["auth_id"] = config->get_aiui_auth_id();
  150. paramj["data_type"] = "audio";
  151. paramj["aue"] = "raw";
  152. paramj["vad_info"] = "end";
  153. paramj["cloud_vad_eos"] = "700";
  154. paramj["close_delay"] = "200";
  155. paramj["scene"] = config->get_aiui_scene();
  156. paramj["sample_rate"] = "16000";
  157. paramj["context"] = R"({"sdk_support":["nlp","tts","vad","iat"]})";
  158. BUILD_AND_REG_SERRVICE(AiuiService);
  159. logger->info("appid {}", appid);
  160. logger->info("param {}", paramj.dump(0));
  161. GET_SERVICE(AiuiService)->initialize(appid, appkey, paramj.dump());
  162. }
  163. int Main::main(int argc, char *argv[]) {
  164. appSetup(argc, argv);
  165. updateRootfs();
  166. buildDeviceIOService();
  167. buildVoiceProcessService();
  168. // while (true) sleep(1000);
  169. // 播放器-SmartSoundBoxPlayer
  170. BUILD_AND_REG_SERRVICE(SmartSoundBoxPlayer);
  171. GET_SERVICE(SmartSoundBoxPlayer)->initialize(100, 30);
  172. /**
  173. * @brief
  174. */
  175. BUILD_AND_REG_SERRVICE(ZWebService);
  176. GET_SERVICE(ZWebService)->initialize();
  177. BUILD_AND_REG_SERRVICE(LightControlService);
  178. GET_SERVICE(LightControlService)->initialize();
  179. GET_SERVICE(LightControlService)->start();
  180. BUILD_AND_REG_SERRVICE(ReportService);
  181. GET_SERVICE(ReportService)->initialize();
  182. GET_SERVICE(ReportService)->start();
  183. BUILD_AND_REG_SERRVICE(MainControlService);
  184. GET_SERVICE(MainControlService)->initialize();
  185. logger->info("system setup end.");
  186. while (true) sleep(1000);
  187. }