From 13ddd122f0d2360bb283e616cd322577e134fa3a Mon Sep 17 00:00:00 2001 From: zhaohe Date: Tue, 20 Aug 2024 14:58:50 +0800 Subject: [PATCH] update --- .../front_msg_processer/front_msg_processer.cpp | 3 +- .../front_msg_processer/front_msg_processer.hpp | 82 +++++----------------- appsrc/service/app/pipeline_pressure_control.cpp | 8 +-- appsrc/service/app/pipeline_pressure_control.hpp | 2 +- appsrc/service/app_core.cpp | 2 + appsrc/service/hardware/device_io_ctrl_service.cpp | 75 ++++++++++---------- 6 files changed, 63 insertions(+), 109 deletions(-) diff --git a/appsrc/baseservice/front_msg_processer/front_msg_processer.cpp b/appsrc/baseservice/front_msg_processer/front_msg_processer.cpp index c9996ff..3758539 100644 --- a/appsrc/baseservice/front_msg_processer/front_msg_processer.cpp +++ b/appsrc/baseservice/front_msg_processer/front_msg_processer.cpp @@ -58,7 +58,8 @@ void FrontMsgProcesser::processMsg(shared_ptr cxt) { logger->info("call: {}->({})", fn, param); if (fn == "FNScheduler.geFnList") { - cxt->content = geFnList(); + cxt->receipt["ackcode"] = 0; + cxt->receipt["content"] = geFnList(); return; } diff --git a/appsrc/baseservice/front_msg_processer/front_msg_processer.hpp b/appsrc/baseservice/front_msg_processer/front_msg_processer.hpp index befb44b..55ff2bf 100644 --- a/appsrc/baseservice/front_msg_processer/front_msg_processer.hpp +++ b/appsrc/baseservice/front_msg_processer/front_msg_processer.hpp @@ -98,48 +98,32 @@ class FrontMsgProcesser { }; template - string getTypeName(const T& val) { + string getTypeName(const string& className, const string fnName) { if (typeInfoMap.find(type_index(typeid(T))) != typeInfoMap.end()) { return typeInfoMap[type_index(typeid(T))].typeName; } - throw std::runtime_error(fmt::format("getTypeName error:{}", typeid(T).name())); - }; - - template - string getTypeName(const shared_ptr& val) { - if (typeInfoMap.find(type_index(typeid(T))) != typeInfoMap.end()) { - return typeInfoMap[type_index(typeid(T))].typeName; - } - throw std::runtime_error(fmt::format("getTypeName error:{}", typeid(T).name())); - } - - template - string getTypeName() { - if (typeInfoMap.find(type_index(typeid(T))) != typeInfoMap.end()) { - return typeInfoMap[type_index(typeid(T))].typeName; - } - throw std::runtime_error(fmt::format("getTypeName error:{}", typeid(T).name())); + return typeid(T).name(); + // throw std::runtime_error(fmt::format("reg {}:{} fail,getTypeName error:{}", className, fnName, typeid(T).name())); }; + // + // ref https://blog.csdn.net/Veritaz/article/details/113820764 + // template void regProcesser(const string& className, const string fnName, vector params, MsgProcesserFn_t fn) { vector paramsTypeInfo; - string ret = getTypeName(); - (paramsTypeInfo.push_back(getTypeName()), ...); + string ret = getTypeName(className, fnName); + (paramsTypeInfo.push_back(getTypeName(className, fnName)), ...); string key = className + "." + fnName; - shared_ptr processer = nullptr; - if (m_msgProcesserMap.find(key) != m_msgProcesserMap.end()) { - processer = m_msgProcesserMap[key]; - } - ZASSERT(processer); - processer->className = className; - processer->fnName = fnName; - processer->paramsTypeInfo = paramsTypeInfo; - processer->params = params; - processer->retTypeInfo = ret; - processer->fn = fn; - m_msgProcesserMap[key] = processer; + shared_ptr processer = make_shared(); + processer->className = className; + processer->fnName = fnName; + processer->paramsTypeInfo = paramsTypeInfo; + processer->params = params; + processer->retTypeInfo = ret; + processer->fn = fn; + m_msgProcesserMap[key] = processer; m_msgProcesserList.push_back(processer); } }; @@ -183,37 +167,3 @@ static inline T jsonGet(json j) { fn(cxt, MARCO_LIST(REGFNV_EACH_EXPTR1, _1, _2, _3, _4, _5, __VA_ARGS__)); \ }); #define REG_EXTFN_VOID(fn, type) FrontMsgProcesser::ins().regProcesser(thisClass.className, #fn, {}, [this](shared_ptr cxt) { fn(cxt); }); - -#if 0 -#define REG_FN(fn, type, ...) \ - { \ - type __fn_type; \ - FrontMsgProcesser::ins().regProcesser(thisClass.className, #fn, /**/ \ - {MARCO_LIST(REGFNV_EACH_EXPTR2, _1, _2, _3, _4, _5, __VA_ARGS__)}, /**/ \ - __fn_type, /**/ \ - [this](shared_ptr cxt) { \ - json& params = cxt->params; \ - cxt->content = fn(MARCO_LIST(REGFNV_EACH_EXPTR1, _1, _2, _3, _4, _5, __VA_ARGS__)); \ - }); \ - } - -#define REG_FN_VOID(fn, type) \ - { \ - type __fn_type; \ - FrontMsgProcesser::ins().regProcesser(thisClass.className, #fn, {}, __fn_type, [this](shared_ptr cxt) { cxt->content = fn(); }); \ - } - -#define REG_EXTFN(fn, type, ...) \ - { \ - type __fn_type; \ - FrontMsgProcesser::ins().regProcesser(thisClass.className, #fn, {MARCO_LIST(REGFNV_EACH_EXPTR2, _1, _2, _3, _4, _5, __VA_ARGS__)}, __fn_type, [this](shared_ptr cxt) { \ - json& params = cxt->params; \ - fn(cxt, MARCO_LIST(REGFNV_EACH_EXPTR1, _1, _2, _3, _4, _5, __VA_ARGS__)); \ - }); \ - } -#define REG_EXTFN_VOID(fn, type) \ - { \ - type __fn_type; \ - FrontMsgProcesser::ins().regProcesser(thisClass.className, #fn, {}, __fn_type, [this](shared_ptr cxt) { fn(cxt); }); \ - } -#endif \ No newline at end of file diff --git a/appsrc/service/app/pipeline_pressure_control.cpp b/appsrc/service/app/pipeline_pressure_control.cpp index 577a8b6..f7ec2b2 100644 --- a/appsrc/service/app/pipeline_pressure_control.cpp +++ b/appsrc/service/app/pipeline_pressure_control.cpp @@ -19,10 +19,10 @@ void PipelinePressureControl::initialize() { GET_TO_SERVICE(m_dics); GET_TO_SERVICE(m_gConfig); - REG_EXTFN_VOID(setType, void()); - REG_EXTFN_VOID(setIntensity, void()); - REG_EXTFN_VOID(getState, void()); - REG_EXTFN_VOID(getConfig, void()); + REG_EXTFN_VOID(setType, void(void)); + REG_EXTFN_VOID(setIntensity, void(void)); + REG_EXTFN_VOID(getState, void(void)); + REG_EXTFN_VOID(getConfig, void(void)); diff --git a/appsrc/service/app/pipeline_pressure_control.hpp b/appsrc/service/app/pipeline_pressure_control.hpp index 0084cf6..f1969f4 100644 --- a/appsrc/service/app/pipeline_pressure_control.hpp +++ b/appsrc/service/app/pipeline_pressure_control.hpp @@ -13,7 +13,7 @@ #include "service/hardware/device_io_ctrl_service.hpp" namespace iflytop { class PipelinePressureControl : public enable_shared_from_this { - THISCLASS(AddLiquidService); + THISCLASS(PipelinePressureControl); typedef enum { kpositivePressure, // 正压 knegativePressure, // 负压 diff --git a/appsrc/service/app_core.cpp b/appsrc/service/app_core.cpp index e6e7540..e48fc3f 100644 --- a/appsrc/service/app_core.cpp +++ b/appsrc/service/app_core.cpp @@ -32,7 +32,9 @@ void AppCore::dosystem(string order, bool dump) { void AppCore::initialize() { REG_TYPE(string); + REG_TYPE(void(void)); REG_TYPE(int); + REG_TYPE(int32_t); REG_TYPE(float); REG_TYPE(double); REG_TYPE(void); diff --git a/appsrc/service/hardware/device_io_ctrl_service.cpp b/appsrc/service/hardware/device_io_ctrl_service.cpp index 886974f..a3f2cfb 100644 --- a/appsrc/service/hardware/device_io_ctrl_service.cpp +++ b/appsrc/service/hardware/device_io_ctrl_service.cpp @@ -36,42 +36,6 @@ static bool isInTestMode() { void DeviceIoControlService::initialize() { GET_TO_SERVICE(m_config); - if (isInTestMode()) { - logger->warn("run in pc, skip initialize device io control service"); - return; - } else { - } - - TransmitDisinfectionCanMaster::ins()->initialize(m_config->get_canIF().c_str(), m_config->get_canBitrate(), false); - TransmitDisinfectionCanMaster::ins()->getCanProtocolCom()->regOnRawData( // - [this](packet_type_t type, uint8_t from, uint8_t to, uint8_t *hex, uint32_t hexlen) { - if (type == kreport) { - processReportMsg(from, hex, hexlen); - } - }); - // REGFNV2(DeviceIoControlService, test); - - /** - * @brief 初始化所有硬件状态 - */ - try { - if (PORT.isLageSpaceDM() || PORT.isSmallSpaceDM() || PORT.isPipeDM()) { - AddLiquidPump_stop(); - SprayPump_stop(); - Blower_close(); - AC_close(); - Heater_close(); - WarningLight_setState(0, 0, 0, 0); - if (PORT.isPipeDM()) { - PosiPressureProp_setValve(0); - NegaPressureProp_setValve(0); - AirLeakDetectTestModeCtrl_setMode(0); - } - } - } catch (const appexception &e) { - logger->error("initialize hardware error:{}", e.what()); - DS->setAppExceptionFlag(e); - } REG_FN_VOID(AddLiquidPump_addLiquid, void()); REG_FN(AddLiquidPump_run, void(int), rpm); @@ -90,7 +54,7 @@ void DeviceIoControlService::initialize() { REG_FN_VOID(Heater_close, void()); REG_FN_VOID(Heater_readEI, void()); REG_FN_VOID(Heater_readTemperature, void()); - REG_FN(WarningLight_setState,void(int, int, int, int), r, g, b, warning); + REG_FN(WarningLight_setState, void(int, int, int, int), r, g, b, warning); REG_FN(PosiPressureProp_setValve, void(int), val); REG_FN_VOID(PosiPressureProp_readPos, void()); REG_FN_VOID(PosiPressureProp_isBusy, void()); @@ -109,6 +73,43 @@ void DeviceIoControlService::initialize() { REG_FN_VOID(LiquidWeightPS_readPa, void()); REG_FN_VOID(SprayPumpPostPS_readPa, void()); REG_FN_VOID(AddLiquidPumpPostPS_readPa, void()); + + if (isInTestMode()) { + logger->warn("run in pc, skip initialize device io control service"); + return; + } else { + } + + TransmitDisinfectionCanMaster::ins()->initialize(m_config->get_canIF().c_str(), m_config->get_canBitrate(), false); + TransmitDisinfectionCanMaster::ins()->getCanProtocolCom()->regOnRawData( // + [this](packet_type_t type, uint8_t from, uint8_t to, uint8_t *hex, uint32_t hexlen) { + if (type == kreport) { + processReportMsg(from, hex, hexlen); + } + }); + // REGFNV2(DeviceIoControlService, test); + + /** + * @brief 初始化所有硬件状态 + */ + try { + if (PORT.isLageSpaceDM() || PORT.isSmallSpaceDM() || PORT.isPipeDM()) { + AddLiquidPump_stop(); + SprayPump_stop(); + Blower_close(); + AC_close(); + Heater_close(); + WarningLight_setState(0, 0, 0, 0); + if (PORT.isPipeDM()) { + PosiPressureProp_setValve(0); + NegaPressureProp_setValve(0); + AirLeakDetectTestModeCtrl_setMode(0); + } + } + } catch (const appexception &e) { + logger->error("initialize hardware error:{}", e.what()); + DS->setAppExceptionFlag(e); + } } #define TRY_DO(func) \