From 94b12008a85d693b6ac603f1fabc04c50c6b086f Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sat, 1 Jun 2024 14:22:28 +0800 Subject: [PATCH] update --- iflytoplinuxsdk | 2 +- src/configs/gconfig.hpp | 10 +- src/configs/project_setting.hpp | 9 - src/configs/version.hpp | 2 + src/extapi_service.cpp | 374 +------------------------- src/extapi_service.hpp | 77 +----- src/main.cpp | 67 +---- src/main.hpp | 51 ---- src/main_control_service.cpp | 36 ++- src/main_control_service.hpp | 7 +- src/services.hpp | 0 src/version.hpp | 2 - src/zservice_container/zservice_container.hpp | 3 - 13 files changed, 58 insertions(+), 582 deletions(-) create mode 100644 src/configs/version.hpp delete mode 100644 src/main.hpp delete mode 100644 src/services.hpp delete mode 100644 src/version.hpp delete mode 100644 src/zservice_container/zservice_container.hpp diff --git a/iflytoplinuxsdk b/iflytoplinuxsdk index bfbd902..350e652 160000 --- a/iflytoplinuxsdk +++ b/iflytoplinuxsdk @@ -1 +1 @@ -Subproject commit bfbd9026128cafcb5d33faff829757f36a2156be +Subproject commit 350e65242ec5ce5afe60210254af303f95a31b74 diff --git a/src/configs/gconfig.hpp b/src/configs/gconfig.hpp index f5c3ae6..1b749e7 100644 --- a/src/configs/gconfig.hpp +++ b/src/configs/gconfig.hpp @@ -14,12 +14,10 @@ #include "iflytop/core/components/config_template/config_template.hpp" -#define ConfigELEMENT_LIST(marco) \ - marco(string /* */, deviceId, "") /*设备ID*/ \ - marco(string /* */, iflytopSubDeviceCanIFName, "can0") /*子设备Can设备名称*/ \ - marco(int32_t /* */, iflytopSubDeviceCanBitrate, 500000) /*子设备Can设备波特率*/ \ - marco(string /* */, pipettingRobotCanIFName, "can1") /*移液臂Can设备名称*/ \ - marco(int32_t /* */, pipettingRobotCanBitrate, 500000) /*移液臂Can设备波特率*/ +#define ConfigELEMENT_LIST(marco) \ + marco(string /* */, deviceId, "") /*设备ID*/ \ + marco(string /* */, canName, "can0") /*子设备Can设备名称*/ \ + marco(int32_t /* */, canBaudRate, 500000) /*Can波特率*/ configTemplateDEFILE_CONFIG_SERVICE2( // GConfig, // diff --git a/src/configs/project_setting.hpp b/src/configs/project_setting.hpp index fac8c71..6f70f09 100644 --- a/src/configs/project_setting.hpp +++ b/src/configs/project_setting.hpp @@ -1,10 +1 @@ #pragma once -#define LINUX_HARDWARE_ID (0x02) - -/******************************************************************************* - * LINUX_HARDWARE_REG * - *******************************************************************************/ - -#define REG_REBOOT_FLAG 0x0000 // 重启标识 -#define REG_DEVICE_ID 0x0001 // 重启标识 -#define REG_EXCEPTION_FLAG 0x0100 // 异常标志位 \ No newline at end of file diff --git a/src/configs/version.hpp b/src/configs/version.hpp new file mode 100644 index 0000000..025956d --- /dev/null +++ b/src/configs/version.hpp @@ -0,0 +1,2 @@ +#pragma once +#define VERSION "0.1" \ No newline at end of file diff --git a/src/extapi_service.cpp b/src/extapi_service.cpp index f9f307a..4727aa0 100644 --- a/src/extapi_service.cpp +++ b/src/extapi_service.cpp @@ -1,10 +1,10 @@ #include "extapi_service.hpp" #include "configs/project_setting.hpp" +#include "configs/version.hpp" #include "iflytop/components/zcanreceiver/zcanreceiverhost.hpp" #include "iflytop/core/components/stringutils.hpp" #include "iflytop/core/core.hpp" -#include "version.hpp" using namespace iflytop; using namespace core; using namespace std; @@ -12,96 +12,16 @@ using namespace nlohmann; #define BIND namespace iflytop {}; - -/******************************************************************************* - * TOOLS * - *******************************************************************************/ -static void getJsonValFromJson(json j, int &val) { - if (j.is_string()) { - string valstr = j; - val = atoi(valstr.c_str()); - } else if (j.is_number()) { - val = j; - } else { - throw std::runtime_error("getJsonValFromJson(int) error"); - } -} - -template -static T jsonGet(json j) { - T val; - getJsonValFromJson(j, val); - return val; -} - -void ExtAPIService::dosystem(string order) { - logger->info("do:{}", order); - system(order.c_str()); -} - void ExtAPIService::initialize(string can_if_name, int baudrate, bool enablLoopback) { GET_TO_SERVICE(m_zconfig); - m_zcan_receiver_master.reset(new ZcanReceiverMaster()); - m_zcan_receiver_master->initialize(can_if_name, baudrate, enablLoopback); - - m_zmodule_device_manager.reset(new ZModuleDeviceManager()); - m_zmodule_device_manager->initialize(m_zcan_receiver_master.get()); - - // m_zmodule_device_manager->registerModule(); - for (size_t i = 1; i < 1000; i++) { - m_proxys[i].initialize(i, m_zcan_receiver_master.get()); - m_zmodule_device_manager->registerModule(&m_proxys[i]); - } - - /** - * @brief CAN通用指令解析器 - */ - m_zmodule_device_script_cmder_paser.reset(new ZModuleDeviceScriptCmderPaser()); - m_zmodule_device_script_cmder_paser->initialize(this, m_zmodule_device_manager.get()); - -#if 0 - m_restfulServer.reset(new RestfulServer()); - m_restfulServer->start(20000, 20001, "0.0.0.0"); - m_restfulServer->regAPI( // - "/doscript", // - [this](HttpRequestPtr request, shared_ptr context, std::shared_ptr) { - string script = request->body; - // callcmd(script) - return std::make_shared(200, "OK", HttpErrorCode::Ok, WebSocketHttpHeaders(), "hello_world"); - }); - m_iflytopwsService.reset(new IflytopFrontEndService()); - m_iflytopwsService->initialize("0.0.0.0"); - m_iflytopwsService->startListen(); -#endif - - /******************************************************************************* - * 脚本服务 * - *******************************************************************************/ - /** - * - * protocol: websocket - * port : 19004 - * descript: 命令行脚本服务支持,回执以日志的形式返回 - */ - m_script_server.reset(new WebSocketServer(19004, "0.0.0.0")); - m_script_server->setOnConnectionCallback([this](weak_ptr webSocket, shared_ptr connectionState) { - // on new client connected - logger->info("remote ip: {} connect to 19004", connectionState->getRemoteIp()); - auto ws = webSocket.lock(); - if (!ws) return; - ws->setOnMessageCallback([this, webSocket](const ix::WebSocketMessagePtr &msg) { - if (msg->type == ix::WebSocketMessageType::Message) { - script_server_on_message(webSocket, msg); - } - }); - }); + m_zcanreceiverhost.reset(new ZCanReceiverHost()); + m_zcanreceiverhost->initialize(can_if_name, baudrate, enablLoopback); - m_script_server->listenAndStart(); + initCanPassthroughServer(); +}; - /******************************************************************************* - * CAN透传服务 * - *******************************************************************************/ +void ExtAPIService::initCanPassthroughServer() { /** * * protocol: websocket @@ -109,9 +29,9 @@ void ExtAPIService::initialize(string can_if_name, int baudrate, bool enablLoopb * descript: 直接透传CAN数据,不做任何处理 * */ - m_can_passthrough_server.reset(new WebSocketServer(19005, "0.0.0.0")); - m_can_passthrough_server->setOnConnectionCallback([this](weak_ptr webSocket, shared_ptr connectionState) { - logger->info("m_can_passthrough_server on connect remote ip: {}", connectionState->getRemoteIp()); + m_canPassthroughServer.reset(new WebSocketServer(19005, "0.0.0.0")); + m_canPassthroughServer->setOnConnectionCallback([this](weak_ptr webSocket, shared_ptr connectionState) { + logger->info("m_canPassthroughServer on connect remote ip: {}", connectionState->getRemoteIp()); auto ws = webSocket.lock(); if (!ws) return; @@ -120,281 +40,9 @@ void ExtAPIService::initialize(string can_if_name, int baudrate, bool enablLoopb logger->info("down can bin -> {}({})", msg->str, msg->wireSize); vector rxbyte; StringUtils().hexStringToBytes(msg->str, "", rxbyte); - m_zcan_receiver_master->sendraw(rxbyte.data(), rxbyte.size()); + m_zcanreceiverhost->sendPacket(rxbyte.data(), rxbyte.size()); } }); }); - m_can_passthrough_server->listenAndStart(); - - m_zcan_receiver_master->regPacketListener([this](int32_t fromboard, zcr_cmd_header_t *packet, int32_t datalen) { - auto clients = m_can_passthrough_server->getClients(); - string rx = StringUtils().bytesToString((uint8_t *)packet, datalen); - logger->info("report can bin -< {}({})", rx, datalen); - for (auto &each : clients) { - if (each) each->sendText(rx); - } - }); - - /******************************************************************************* - * 事件监听器 * - *******************************************************************************/ - /** - * @brief 监听事件,并打印 - */ - m_zmodule_device_manager->regOnRegValChangeEvent([this](int32_t moduleid, int32_t regindex, int32_t oldval, int32_t toval) { // - logger->info("on reg change: moduleid:{} REG({}) {} to {}", moduleid, regindex, oldval, toval); - - // m_script_server 上报事件 - { - auto clients = m_script_server->getClients(); - for (auto &each : clients) { - if (each) each->sendText(fmt::format("on reg change: moduleid:{} REG({}) {} to {}", moduleid, regindex, oldval, toval)); - } - } - - }); -}; - -/******************************************************************************* - * m_script_server * - *******************************************************************************/ - -void ExtAPIService::script_server_on_message(weak_ptr webSocket, const ix::WebSocketMessagePtr &msg) { - logger->info("script_server_on_message:\n{}", msg->str); - script_processer_processcmds( - msg->str, - /******************************************************************************* - * PRIVATE_FN_PROCESSER * - *******************************************************************************/ - [this, webSocket](string cmd, int32_t paramN, const char **paraV, ICmdParserACK *ack) { - auto ws = webSocket.lock(); - if (!ws) return; - - /******************************************************************************* - * HELP * - *******************************************************************************/ - if (cmd == "help") { - ack->ecode = 0; - string helpinfo; - helpinfo += fmt::format("cmdlist:\n"); - for (auto it = m_cmdmap.begin(); it != m_cmdmap.end(); it++) { - // ws->sendText(fmt::format("\t{} {}", it->first, it->second.helpinfo)); - helpinfo += fmt::format("\t{} {}\n", it->first, it->second.helpinfo); - } - ws->sendText(helpinfo); - return; - } - - if (cmd == "app_scan_moudle") { - ack->ecode = 0; - string helpinfo; - helpinfo += fmt::format("cmdlist:\n"); - for (auto it = m_cmdmap.begin(); it != m_cmdmap.end(); it++) { - // ws->sendText(fmt::format("\t{} {}", it->first, it->second.helpinfo)); - helpinfo += fmt::format("\t{} {}\n", it->first, it->second.helpinfo); - } - ws->sendText(helpinfo); - return; - } - }, - /******************************************************************************* - * ACK_PROCESSER * - *******************************************************************************/ - [this, webSocket](string cmd, ICmdParserACK *ack) { // - logger->info("do {},{}({})", cmd, ack->ecode, err::error2str(ack->ecode)); - string ackstr; - if (ack->acktype == ICmdParserACK::kAckType_none) { - ackstr += fmt::format("{} -> ecode:{}({})\n", cmd, err::error2str(ack->ecode), ack->ecode); - } else if (ack->acktype == ICmdParserACK::kAckType_int32) { - ackstr += fmt::format("{} -> ecode:{}({})\n", cmd, err::error2str(ack->ecode), ack->ecode); - for (int32_t i = 0; i < ack->getAckInt32Num(); i++) { - ackstr += fmt::format(" ack[{}]{}\n", i, ack->getAckInt32Val(i)); - } - } else if (ack->acktype == ICmdParserACK::kAckType_buf) { - ackstr += fmt::format("{} -> ecode:{}({})\n", cmd, err::error2str(ack->ecode), ack->ecode); - ackstr += tools_dumpbuffer(ack->rawdata, ack->rawlen); - } else if (ack->acktype == ICmdParserACK::kAckType_str) { - ackstr += fmt::format("{} -> ecode:{}({})\n", cmd, err::error2str(ack->ecode), ack->ecode); - ackstr = fmt::format(" ackbufstr:{}", string((const char *)ack->rawdata)); - } - auto ws = webSocket.lock(); - if (ws) ws->sendText(ackstr); - }); -} - -void ExtAPIService::regfns() { - this->regCMD("", "", 2, [](int32_t paramN, const char **paraV, ICmdParserACK *ack) { - /** - * @brief who call me? - */ - }); + m_canPassthroughServer->listenAndStart(); } -/******************************************************************************* - * 脚本处理方法 * - *******************************************************************************/ -void ExtAPIService::regCMD(const char *cmdname, const char *helpinfo, int paraNum, ICmdFunction_t cmdimpl) { - cmd_container_t cmd_container; - cmd_container.cmdname = cmdname; - cmd_container.helpinfo = helpinfo; - cmd_container.paraNum = paraNum; - cmd_container.cmdimpl = cmdimpl; - m_cmdmap[cmdname] = cmd_container; -} - -void ExtAPIService::script_processer_processcmds(string script, private_fn_processer_t private_fn_processer, ackprocesser_t ackprocesser) { - /** - * @brief - * script: - * cmd val1 val2 val3 - * cmd val1 val2 val3 - */ - - vector cmdlines; - char *strcache = (char *)malloc(script.size() + 1); - strncpy(strcache, script.c_str(), script.size()); - int32_t stringlen = script.size(); - for (int32_t i = 0; i < stringlen; i++) { - if (strcache[i] == '\n' || strcache[i] == '\r') { - strcache[i] = '\0'; - } - } - - char *currentstr = nullptr; - for (int32_t i = 0; i < stringlen; i++) { - if (currentstr == nullptr) { - if (strcache[i] != '\0') { - // logger->info("new cmd:{}", &strcache[i]); - currentstr = &strcache[i]; - cmdlines.push_back(currentstr); - } - } else { - if (strcache[i] == '\0') { - currentstr = nullptr; - } - } - } - - for (auto &cmdline : cmdlines) { - // bool isnote = false; - FnProcessContext cxt; - cxt.private_fn_processer = private_fn_processer; - cxt.ackprocesser = ackprocesser; - - // logger->info("do {}", cmdline); - script_processer_callcmd(cmdline, cxt); - - if (cxt.breakflag) break; - } - free(strcache); -} - -void ExtAPIService::script_processer_callcmd(string cmd, FnProcessContext &cxt) { - char *argv[30] = {0}; - int32_t argc = 0; - - char cmdcache[1024] = {0}; - strncpy(cmdcache, cmd.c_str(), 1023); - - // remove note - for (size_t i = 0; i < cmd.length(); i++) { - if (cmdcache[i] == '#') { - cmdcache[i] = '\0'; - if (i == 0) { - // is note return; - return; - } - break; - } - } - - // logger->info("cmdcache:{}", cmdcache); - - for (int32_t i = 0; i < cmd.length(); i++) { - if (cmdcache[i] == '\n' || cmdcache[i] == '\r' || cmdcache[i] == ' ' || cmdcache[i] == 127) { - cmdcache[i] = '\0'; - } - } - - int j = 0; - for (int i = 0; cmdcache[i] == 0 || i < cmd.length(); i++) { - if (cmdcache[i] != 0 && j == 0) { - argv[argc++] = &cmdcache[i]; - j = 1; - continue; - } - - if (cmdcache[i] == 0 && j == 1) { - j = 0; - continue; - } - } - - logger->info("argc:{}", argc); - for (int i = 0; i < argc; i++) { - logger->info("argv[{}]:{}", i, argv[i]); - } - - if (argc == 0) { - return; - } - - script_processer_callcmd(cxt, argv[0], argc - 1, (const char **)(argv + 1)); -} -void ExtAPIService::script_processer_callcmd(FnProcessContext &cxt, string cmdname, int32_t paramN, const char **paraV) { - std::lock_guard lock(m_cmdmaplock_); - auto it = m_cmdmap.find(cmdname); - - logger->info("call cmd:{} paramN:{}", cmdname, paramN); - ICmdParserACK ack = {0}; - if (it != m_cmdmap.end()) { - cmd_container_t cmd_container = it->second; - if (cmd_container.paraNum != paramN) { - ack.ecode = err::kcmd_param_num_error; - return; - } - if (cmd_container.cmdimpl) { - cmd_container.cmdimpl(paramN, paraV, &ack); - } else { - logger->info("cmd:{} not impl", cmdname); - } - } else { - ack.ecode = err::kcmd_not_found; - if (cxt.private_fn_processer) cxt.private_fn_processer(cmdname, paramN, paraV, &ack); - } - - if (cxt.ackprocesser) cxt.ackprocesser(cmdname, &ack); - if (ack.ecode != err::ksucc) cxt.breakflag = true; -} -/******************************************************************************* - * TOOLS * - *******************************************************************************/ -string ExtAPIService::tools_dumpbuffer(uint8_t *data, int32_t len) { - int32_t align = 32; - string ret; - - for (int32_t i = 0; i < len;) { - for (int32_t j = 0; j < align; j++) { - if (i + j < len) { - ret += fmt::format("{:02X} ", data[i + j]); - } else { - ret += " "; - } - } - - ret += "|"; - - for (int32_t j = 0; j < align; j++) { - if (i + j < len) { - if (isprint(data[i + j])) { - ret += fmt::format("{}", data[i + j]); - } else { - ret += "."; - } - } else { - ret += " "; - } - } - ret += "\n"; - } - return ret; -} \ No newline at end of file diff --git a/src/extapi_service.hpp b/src/extapi_service.hpp index 0e816a4..dd4491a 100644 --- a/src/extapi_service.hpp +++ b/src/extapi_service.hpp @@ -24,13 +24,13 @@ #include "iflytop/components/iflytop_front_end_service/iflytop_front_end_service.hpp" #include "iflytop/zprotocols/zmodule_device_manager.hpp" #include "iflytop/zprotocols/zmodule_device_script_cmder_paser.hpp" -#include "zservice_container/zservice_container.hpp" +#include "iflytoplinuxsdk/src/iflytop/core/components/zservice_container/zservice_container.hpp" // // #include -#include "iflytop/components/zcanreceiver/zcanreceiver_master.hpp" +#include "iflytop/components/zcanreceiver/zcanreceiverhost.hpp" #include "iflytoplinuxsdk/src/iflytop/zprotocols/protocol_proxy.hpp" /** * @brief @@ -43,81 +43,18 @@ namespace iflytop { using namespace std; using namespace core; -class ExtAPIService : public ICmdParser { +class ExtAPIService { ENABLE_LOGGER(ExtAPIService); - shared_ptr m_zconfig; - shared_ptr m_restfulServer; // 20000,20001 - shared_ptr m_iflytopwsService; // 19001,19002 - shared_ptr m_can_passthrough_server; // 19003 - shared_ptr m_script_server; // 19004 - - shared_ptr m_zcan_receiver_master; - shared_ptr m_zmodule_device_manager; - shared_ptr m_zmodule_device_script_cmder_paser; - - ZIProtocolProxy m_proxys[1000]; - - // cmd - - typedef function private_fn_processer_t; - typedef function ackprocesser_t; - - typedef struct { - string cmdname; - string helpinfo; - int paraNum; - ICmdFunction_t cmdimpl; - } cmd_container_t; - - class FnProcessContext { - public: - private_fn_processer_t private_fn_processer = nullptr; - ackprocesser_t ackprocesser = nullptr; - bool breakflag = false; - }; - - map m_cmdmap; - std::recursive_mutex m_cmdmaplock_; + shared_ptr m_zconfig; + shared_ptr m_canPassthroughServer; // 19003 + shared_ptr m_zcanreceiverhost; public: ExtAPIService(){}; void initialize(string can_if_name, int baudrate, bool enablLoopback); - virtual void regCMD(const char *cmdname, const char *helpinfo, int paraNum, ICmdFunction_t cmdimpl); - private: - void dosystem(string order, bool dump) { - if (dump) logger->info("do:{}", order); - system(order.c_str()); - } - - private: - void dosystem(string order); - - void removenote(char *buf); - - /******************************************************************************* - * TOOLS * - *******************************************************************************/ - string tools_dumpbuffer(uint8_t *data, int32_t len); - - /******************************************************************************* - * m_script_server * - *******************************************************************************/ - - void script_server_on_message(weak_ptr webSocket, const ix::WebSocketMessagePtr &msg); - - /******************************************************************************* - * 脚本处理方法 * - *******************************************************************************/ - void script_processer_processcmds(string script, private_fn_processer_t private_fn_processer, ackprocesser_t ackprocesser); - void script_processer_callcmd(string cmd, FnProcessContext &cxt); - void script_processer_callcmd(FnProcessContext &cxt, string cmdname, int32_t paramN, const char **paraV); - - /******************************************************************************* - * 脚本方法 * - *******************************************************************************/ - void regfns(); + void initCanPassthroughServer(); }; } // namespace iflytop \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index ffcaa10..d168b28 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,73 +1,20 @@ -#include "main.hpp" #include #include +#include "main_control_service.hpp" + using namespace iflytop; using namespace core; using namespace std; -namespace iflytop { -bool g_in_test = false; -}; - /******************************************************************************* * MAIN => MAIN * *******************************************************************************/ -Main *Main::g_main; -int main(int argc, char *argv[]) { - Main main; - Main::g_main = &main; - main.run(argc, argv); -} -void Main::onsignal(int signo) { exit(0); } -void Main::run(int argc, char *argv[]) { - // ::signal(SIGINT, Main::_onsignal); - thread.reset(new Thread("main", [&]() { exit(main(argc, argv)); })); - while (true) sleep(1000); -} -int Main::main(int argc, char *argv[]) { - /** - * @brief 解析命令行参数 - */ - string test_mode = "false"; - auto cli = ((required("--test_mode") & value("test_mode", test_mode)).doc("test_mode")); - if (!parse(argc, argv, cli)) { - test_mode = "false"; - // cout << make_man_page(cli, argv[0]); - // exit(-1); - } - if (test_mode == "false") { - g_in_test = false; - } else { - g_in_test = true; +int main(int argc, char *argv[]) { + shared_ptr main = make_shared(); + main->initialize(argc, argv); + while (true) { + sleep(1); } - logger->info("test_mode:{}:{}", test_mode, g_in_test); - - /** - * @brief 系统初始化 - */ - logger->info("system setup start."); - spdlog::flush_on(spdlog::level::debug); - logger->info("#"); - logger->info("# company:{}", "ifytop"); - logger->info("# version:{}", VERSION); - logger->info("#"); - logger->info("build {}.....", "Config"); - // 构造GConfig - BUILD_AND_REG_SERRVICE(GConfig); - GET_SERVICE(GConfig)->initialize(); - - /** - * @brief - */ - // if (!device_id.empty()) GET_SERVICE(GConfig)->set_deviceId(device_id); - - auto config = GET_SERVICE(GConfig); - - // 构造MainControlService - BUILD_AND_REG_SERRVICE(MainControlService); - GET_SERVICE(MainControlService)->initialize(); - logger->info("system setup end."); - while (true) sleep(1000); } diff --git a/src/main.hpp b/src/main.hpp deleted file mode 100644 index 80eeae6..0000000 --- a/src/main.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// #include -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -// -#include "configs/gconfig.hpp" -#include "iflytop/core/spdlogfactory/logger.hpp" -#include "iflytop/core/thread/thread.hpp" -#include "version.hpp" -#include "zservice_container/zservice_container.hpp" -#include "iflytop/components/zclicpp/clipp.h" -// -#include "main_control_service.hpp" - -namespace iflytop { -using namespace iflytop; -using namespace core; -using namespace std; -using namespace clipp; -class Main { - ENABLE_LOGGER(Main); - - private: - unique_ptr thread; - - private: - int main(int argc, char *argv[]); - - public: - static Main *g_main; - static void _onsignal(int signo) { g_main->onsignal(signo); } - void onsignal(int signo); - - public: - Main(/* args */) {} - ~Main() {} - void run(int argc, char *argv[]); - void dosystem(string order, bool dump) { - if (dump) logger->info("{}", order); - system(order.c_str()); - } -}; -} // namespace iflytop diff --git a/src/main_control_service.cpp b/src/main_control_service.cpp index 64f541c..1d4fee5 100644 --- a/src/main_control_service.cpp +++ b/src/main_control_service.cpp @@ -1,28 +1,38 @@ #include "main_control_service.hpp" #include "configs/project_setting.hpp" +#include "configs/version.hpp" #include "iflytop/components/zcanreceiver/zcanreceiverhost.hpp" #include "iflytop/core/components/stringutils.hpp" #include "iflytop/core/core.hpp" -#include "version.hpp" + using namespace iflytop; using namespace core; using namespace std; using namespace nlohmann; -#define BIND + +#define OBJECT GET_SERVICE namespace iflytop {}; -void MainControlService::initialize() { - GET_TO_SERVICE(m_zconfig); +void MainControlService::initialize(int argc, char *argv[]) { + /** + * @brief 系统初始化 + */ + logger->info("system setup start."); + spdlog::flush_on(spdlog::level::debug); + logger->info("#"); + logger->info("# company:{}", "ifytop"); + logger->info("# version:{}", VERSION); + logger->info("#"); + logger->info("build {}.....", "Config"); -#if 0 - BUILD_AND_REG_SERRVICE(DeviceIoControlService); - REG_SERRVICE(DeviceIoControlService, new DeviceIoControlServiceTest()); + initializeService(); +}; - GET_SERVICE(DeviceIoControlService)->initialize(); - GET_TO_SERVICE(m_deviceIoControlService); - m_deviceIoControlService->startScan(); -#endif +void MainControlService::initializeService() { + BUILD_AND_REG_SERRVICE(GConfig); + OBJECT(GConfig)->initialize(); - m_extAPIService.initialize(m_zconfig->get_iflytopSubDeviceCanIFName(), m_zconfig->get_iflytopSubDeviceCanBitrate(), false); -}; + m_extAPIService.initialize(OBJECT(GConfig)->get_canName(), // + OBJECT(GConfig)->get_canBaudRate(), false); +} diff --git a/src/main_control_service.hpp b/src/main_control_service.hpp index 8cae68d..f8dda9b 100644 --- a/src/main_control_service.hpp +++ b/src/main_control_service.hpp @@ -22,7 +22,7 @@ // #include "configs/gconfig.hpp" #include "iflytop/components/iflytop_front_end_service/iflytop_front_end_service.hpp" -#include "zservice_container/zservice_container.hpp" +#include "iflytoplinuxsdk/src/iflytop/core/components/zservice_container/zservice_container.hpp" // // @@ -46,14 +46,13 @@ using namespace core; class MainControlService : public enable_shared_from_this { ENABLE_LOGGER(MainControlService); - shared_ptr m_zconfig; - ExtAPIService m_extAPIService; public: MainControlService(){}; - void initialize(); + void initialize(int argc, char *argv[]); private: + void initializeService(); }; } // namespace iflytop \ No newline at end of file diff --git a/src/services.hpp b/src/services.hpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/version.hpp b/src/version.hpp deleted file mode 100644 index 025956d..0000000 --- a/src/version.hpp +++ /dev/null @@ -1,2 +0,0 @@ -#pragma once -#define VERSION "0.1" \ No newline at end of file diff --git a/src/zservice_container/zservice_container.hpp b/src/zservice_container/zservice_container.hpp deleted file mode 100644 index aa3fd93..0000000 --- a/src/zservice_container/zservice_container.hpp +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "iflytoplinuxsdk/src/iflytop/core/components/zservice_container/zservice_container.hpp" \ No newline at end of file