diff --git a/README.md b/README.md index 20b2f76..032ec6c 100644 --- a/README.md +++ b/README.md @@ -23,4 +23,7 @@ VERSION 1.0.3 2. 添加对subdevice_overtimes的处理 VERSION 1.0.4 1. 添加相对饱和度计算 +VERSION 1.0.5 + 1. 修改测试json格式 + 2. 修改气密性测试阀门控制逻辑 ``` \ No newline at end of file diff --git a/app_protocols/transmit_disfection_protocol b/app_protocols/transmit_disfection_protocol index 6fb781e..4aef968 160000 --- a/app_protocols/transmit_disfection_protocol +++ b/app_protocols/transmit_disfection_protocol @@ -1 +1 @@ -Subproject commit 6fb781e6b5fe8f4f44c7046b30cbee47512f5bd9 +Subproject commit 4aef96865307cfad9f2386253496f696c6ed5ecf diff --git a/appdep/iflytop/core/components/zenum_template/zenum_template.hpp b/appdep/iflytop/core/components/zenum_template/zenum_template.hpp index 2da8df6..eccdcf4 100644 --- a/appdep/iflytop/core/components/zenum_template/zenum_template.hpp +++ b/appdep/iflytop/core/components/zenum_template/zenum_template.hpp @@ -44,6 +44,7 @@ enum_val_t id; \ elist(name, ZENUM_IMPL2) public : name() {} \ name(enum_val_t id) : id(id) {} \ + name(int id) : id((enum_val_t)id) {} \ name(string str) : id(toEnum(str)) {} \ enum_val_t getId() const { return id; } \ static string toString(enum_val_t enu) { \ diff --git a/appsrc/appbase/appbase.hpp b/appsrc/appbase/appbase.hpp index beabd9c..c0e1710 100644 --- a/appsrc/appbase/appbase.hpp +++ b/appsrc/appbase/appbase.hpp @@ -13,3 +13,4 @@ #include "appbase/appbean/test_page_iterm.hpp" #include "appbean/device_state.hpp" #include "appbase/appbean/h2o2_sensor_data_snapshot.hpp" +#include "appbase/appbean/air_leak_test_mode.hpp" diff --git a/appsrc/appbase/appbean/air_leak_test_mode.cpp b/appsrc/appbase/appbean/air_leak_test_mode.cpp new file mode 100644 index 0000000..49223ac --- /dev/null +++ b/appsrc/appbase/appbean/air_leak_test_mode.cpp @@ -0,0 +1,2 @@ +#include "air_leak_test_mode.hpp" +AirLeakTestMode_ZENUM_IMPL \ No newline at end of file diff --git a/appsrc/appbase/appbean/air_leak_test_mode.hpp b/appsrc/appbase/appbean/air_leak_test_mode.hpp new file mode 100644 index 0000000..743867a --- /dev/null +++ b/appsrc/appbase/appbean/air_leak_test_mode.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include "iflytop/core/components/zenum_template/zenum_template.hpp" + +#define AirLeakTestMode_ZENUM_IMPL ZENUM_IMPL(AirLeakTestMode, AirLeakTestMode_LIST) +#define AirLeakTestMode_LIST(type, marco) /**/ \ + marco(type, disinfection) /**/ \ + marco(type, inflation) /**/ \ + marco(type, leakTest) /**/ \ + marco(type, closeAll) /**/ \ + marco(type, openAll) /**/ + +ZENUM_DECLAR(AirLeakTestMode, AirLeakTestMode_LIST); \ No newline at end of file diff --git a/appsrc/appbase/appbean/test_page_iterm.hpp b/appsrc/appbase/appbean/test_page_iterm.hpp index bdf0a33..4070a25 100644 --- a/appsrc/appbase/appbean/test_page_iterm.hpp +++ b/appsrc/appbase/appbean/test_page_iterm.hpp @@ -4,9 +4,7 @@ #define TestPageItermType_ZENUM_IMPL ZENUM_IMPL(TestPageItermType, TestPageItermType_LIST) #define TestPageItermType_LIST(type, marco) /**/ \ - marco(type, button) /**/ \ marco(type, buttons) /**/ \ - marco(type, state) /**/ \ marco(type, states) /**/ \ marco(type, placeHolder) /**/ diff --git a/appsrc/appcomponents/canchannel/transmit_disinfection_can_master.hpp b/appsrc/appcomponents/canchannel/transmit_disinfection_can_master.hpp index c6a7ef7..0de64c2 100644 --- a/appsrc/appcomponents/canchannel/transmit_disinfection_can_master.hpp +++ b/appsrc/appcomponents/canchannel/transmit_disinfection_can_master.hpp @@ -125,8 +125,8 @@ class TransmitDisinfectionCanMaster { int proportionalReadPos(int boardid, int valveId) { return m_com->callcmd1(boardid, kfn_proportional_read_pos, valveId, DEFUALT_OVERTIME)->getContent(0); } int proportionalIsBusy(int boardid, int valveId) { return m_com->callcmd1(boardid, kfn_proportional_is_busy, valveId, DEFUALT_OVERTIME)->getContent(0); } - void airLeakDetectTestSetMode(int boardid, int mode) { m_com->callcmd1(boardid, kfn_air_leak_detect_test_set_mode, mode, DEFUALT_OVERTIME); } - int airLeakDetectTestGetMode(int boardid) { return m_com->callcmd0(boardid, kfn_air_tightness_test_get_mode, DEFUALT_OVERTIME)->getContent(0); } + void airLeakDetectTestSetMode(int boardid, int mode) { m_com->callcmd1(boardid, kfn_air_leak_test_set_mode, mode, DEFUALT_OVERTIME); } + int airLeakDetectTestGetMode(int boardid) { return m_com->callcmd0(boardid, kfn_air_leak_test_get_mode, DEFUALT_OVERTIME)->getContent(0); } void extChSelectorSetCh(int boardid, int ch) { m_com->callcmd1(boardid, kfn_ext_ch_selector_set_ch, ch, DEFUALT_OVERTIME); } int extChSelectorGetCh(int boardid) { return m_com->callcmd0(boardid, kfn_ext_ch_selector_get_ch, DEFUALT_OVERTIME)->getContent(0); } diff --git a/appsrc/service/app/air_leak_detect_test.cpp b/appsrc/service/app/air_leak_detect_test.cpp index ed9b9de..1025837 100644 --- a/appsrc/service/app/air_leak_detect_test.cpp +++ b/appsrc/service/app/air_leak_detect_test.cpp @@ -35,7 +35,7 @@ void AirLeakDetectTest::start() { GET_SERVICE(PipelinePressureControl)->syncPressureValueState(); try { - if (PORT.isPipeDM()) m_dics->AirLeakDetectTestModeCtrl_setMode(0); + // if (PORT.isPipeDM()) m_dics->AirLeakDetectTestModeCtrl_setMode(0); } catch (...) { } @@ -58,7 +58,6 @@ void AirLeakDetectTest::airLeakDetectTestThread() { // 初始化设备,关闭比例法 m_dics->PosiPressureProp_setValve(0); m_dics->NegaPressureProp_setValve(0); - m_dics->AirLeakDetectTestModeCtrl_setMode(1); // 等待比例法关闭 while (!ThisThread().getExitFlag()) { @@ -75,8 +74,9 @@ void AirLeakDetectTest::airLeakDetectTestThread() { logger->info("inflate....."); m_workstate = kinflating; m_dics->AC_ctrl(1); - ThisThread().sleepForMs(1000); // 充气时间 + ThisThread().sleepForMs(100); // 充气时间 m_dics->AC_ctrl(0); + // m_dics->AirLeakDetectTestModeCtrl_setMode(1); if (ThisThread().getExitFlag()) return; // 等待充气完成 diff --git a/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp b/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp index 30f3f1c..e6bd79c 100644 --- a/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp +++ b/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp @@ -492,7 +492,7 @@ void DisinfectionCtrlService::processStateDisinfection(DisinfectionEvent* event) tryLogState(true); s_isDisinfectionTakeBreak = false; if (PORT.isPipeDM()) { - dics->AirLeakDetectTestModeCtrl_setMode(0); + dics->AirLeakDetectTestModeCtrl_setMode(AirLeakTestMode::disinfection); } dics->ExtChSelector_trySelectCh(kext_ch_disinfection); dics->AC_ctrl(1); diff --git a/appsrc/service/app_core.cpp b/appsrc/service/app_core.cpp index c758cd5..ed759e2 100644 --- a/appsrc/service/app_core.cpp +++ b/appsrc/service/app_core.cpp @@ -54,6 +54,8 @@ static void installEcodeInfo() { // kerr_ProportionalValveError = 203, // 气密性测试专用空压机异常 REG_ENUM_TYPE(SettingId, SettingId::getEnumStrList()); + REG_ENUM_TYPE(AirLeakTestMode, AirLeakTestMode::getEnumStrList()); + AppEcodeInfoMgr::ins().regEcodeInfo(kerr_motor_reset_error, "电机复位错误"); AppEcodeInfoMgr::ins().regEcodeInfo(kerr_motor_subdevice_offline, "电机子设备离线"); diff --git a/appsrc/service/hardware/device_io_ctrl_service.cpp b/appsrc/service/hardware/device_io_ctrl_service.cpp index 8f38e0d..c335130 100644 --- a/appsrc/service/hardware/device_io_ctrl_service.cpp +++ b/appsrc/service/hardware/device_io_ctrl_service.cpp @@ -61,7 +61,7 @@ void DeviceIoControlService::initialize() { REG_FN(NegaPressureProp_setValve, void(int32_t), val); REG_FN_VOID(NegaPressureProp_readPos, void(void)); REG_FN_VOID(NegaPressureProp_isBusy, void(void)); - REG_FN(AirLeakDetectTestModeCtrl_setMode, void(int32_t), val); + REG_FN(AirLeakDetectTestModeCtrl_setMode, void(AirLeakTestMode), val); REG_FN_VOID(AirLeakDetectTestModeCtrl_getMode, void(void)); REG_FN(ExtChSelector_selectCh, void(int32_t), val); REG_FN(ExtChSelector_trySelectCh, void(int32_t), val); @@ -103,7 +103,7 @@ void DeviceIoControlService::initialize() { if (PORT.isPipeDM()) { PosiPressureProp_setValve(0); NegaPressureProp_setValve(0); - AirLeakDetectTestModeCtrl_setMode(0); + AirLeakDetectTestModeCtrl_setMode(AirLeakTestMode::disinfection); } } } catch (const appexception &e) { @@ -128,7 +128,7 @@ int DeviceIoControlService::forceStopDeviceWithoutExc() { if (PORT.isPipeDM()) { TRY_DO(PosiPressureProp_setValve(0)); TRY_DO(NegaPressureProp_setValve(0)); - TRY_DO(AirLeakDetectTestModeCtrl_setMode(0)); + TRY_DO(AirLeakDetectTestModeCtrl_setMode(AirLeakTestMode::disinfection)); } } return 0; @@ -350,14 +350,17 @@ bool DeviceIoControlService::NegaPressureProp_isBusy() { #define COMPONENT HardwareComponent::AirLeakDetectTestModeCtrl -int DeviceIoControlService::AirLeakDetectTestModeCtrl_setMode(int mode) { +int DeviceIoControlService::AirLeakDetectTestModeCtrl_setMode(AirLeakTestMode mode) { logger->info(" AirLeakDetectTestModeCtrl_setMode, mode={}", mode); - if (!isInTestMode()) CAN_MASTER->airLeakDetectTestSetMode(GET_BOARDID(), mode); + if (!isInTestMode()) CAN_MASTER->airLeakDetectTestSetMode(GET_BOARDID(), mode.getId()); return 0; } -int DeviceIoControlService::AirLeakDetectTestModeCtrl_getMode() { - if (!isInTestMode()) return CAN_MASTER->airLeakDetectTestGetMode(GET_BOARDID()); - return 0; +AirLeakTestMode DeviceIoControlService::AirLeakDetectTestModeCtrl_getMode() { + if (!isInTestMode()) { + int val = CAN_MASTER->airLeakDetectTestGetMode(GET_BOARDID()); + return AirLeakTestMode(val); + } + return AirLeakTestMode::disinfection; } #undef COMPONENT diff --git a/appsrc/service/hardware/device_io_ctrl_service.hpp b/appsrc/service/hardware/device_io_ctrl_service.hpp index ec528dc..4eee0d0 100644 --- a/appsrc/service/hardware/device_io_ctrl_service.hpp +++ b/appsrc/service/hardware/device_io_ctrl_service.hpp @@ -89,8 +89,8 @@ class DeviceIoControlService : public enable_shared_from_this cxt) { cxt->rely["items"] = m_testPageItemMgr.getPageCfgInfo(); } void TestPageMgrService::onButton(shared_ptr cxt, string groupName, string buttonName, json params) { m_testPageItemMgr.processOnButton(groupName, buttonName, params); } @@ -39,100 +40,109 @@ void TestPageMgrService::initialize() { REG_FN_VOID(PrinterTest_test, void()); - m_dict = make_shared(); - m_testPageItemMgr.installDict(m_dict); - - // 喷液泵1 - m_dict->insert("pumpVel", "速度"); - m_dict->insert("SprayPumpCtrl", "喷液泵控制"); - m_dict->insert("SprayPumpCtrl.forward", "正转"); - m_dict->insert("SprayPumpCtrl.backward", "反转"); - m_dict->insert("SprayPumpCtrl.stop", "停止"); - m_testPageItemMgr.installParamType("SprayPumpCtrl.pumpVel", "g/min", {"5", "10", "15"}); - m_testPageItemMgr.insertButtons("SprayPumpCtrl", {"pumpVel"}, {"forward", "backward", "stop"}, [this](string buttonName, vector param) { // - logger->info("SprayPumpCtrl on button.{} ({})", buttonName, param[0]); - if (buttonName == "forward") { - dcs->SprayPump_startInRPM(atoi(param[0].c_str())); - } else if (buttonName == "backward") { - dcs->SprayPump_startInRPM(-atoi(param[0].c_str())); - } else if (buttonName == "stop") { - dcs->SprayPump_stop(); - } - }); - - // 加液泵2 - m_dict->insert("AddDischargePumpCtrl", "加液泵控制"); - m_dict->insert("AddDischargePumpCtrl.addingLiquid", "加液"); - m_dict->insert("AddDischargePumpCtrl.drainLiquid", "排液"); - m_testPageItemMgr.insertButtons("AddDischargePumpCtrl", {}, {"addingLiquid", "drainLiquid"}, [this](string buttonName, vector param) { // - logger->info("on AddDischargePumpCtrl.{}", buttonName); - if (buttonName == "addingLiquid") { - dcs->AddLiquidPump_addLiquid(); - } else if (buttonName == "drainLiquid") { - dcs->AddLiquidPump_drainLiquid(); - } - }); - - // 空压机3 - m_dict->insert("AirCompressorCtrl", "空压机控制"); - m_dict->insert("AirCompressorCtrl.on", "打开"); - m_dict->insert("AirCompressorCtrl.off", "关闭"); - m_testPageItemMgr.insertButtons("AirCompressorCtrl", {}, {"on", "off"}, [this](string buttonName, vector param) { // - logger->info("on AirCompressorCtrl.{}", buttonName); - if (buttonName == "on") { - dcs->AC_ctrl(1); - } else if (buttonName == "off") { - dcs->AC_close(); - } - }); - - // 空压机电流4 - m_dict->insert("ACState", "空压机状态"); - m_dict->insert("ACState.current", "电流"); - m_testPageItemMgr.insertStates("ACState", {"current"}, [this](string stateName) { // + auto SprayPumpCtrl = m_testPageItemMgr.createButtons({"SprayPumpCtrl", "喷液泵控制"}, // 模组名 + { + // 参数 + {{"pumpVel", "速度"}, "g/min", {{"5"}, {"10"}, {"15"}}}, // + }, + { + // 按键 + {"forward", "正转"}, + {"backward", "反转"}, + {"stop", "停止"}, + }, + [this](string buttonName, vector param) { // + logger->info("SprayPumpCtrl on button.{} ({})", buttonName, param[0]); + if (buttonName == "forward") { + dcs->SprayPump_startInRPM(atoi(param[0].c_str())); + } else if (buttonName == "backward") { + dcs->SprayPump_startInRPM(-atoi(param[0].c_str())); + } else if (buttonName == "stop") { + dcs->SprayPump_stop(); + } + }); + + auto AddDischargePumpCtrl = m_testPageItemMgr.createButtons({"AddDischargePumpCtrl", "加液泵控制"}, // 模组名 + { + // 参数 + }, + { + // 按键 + {"addingLiquid", "加液"}, + {"drainLiquid", "排液"}, + }, + [this](string buttonName, vector param) { // + logger->info("on AddDischargePumpCtrl.{}", buttonName); + if (buttonName == "addingLiquid") { + dcs->AddLiquidPump_addLiquid(); + } else if (buttonName == "drainLiquid") { + dcs->AddLiquidPump_drainLiquid(); + } + }); + + auto AirCompressorCtrl = m_testPageItemMgr.createButtons({"AirCompressorCtrl", "空压机控制"}, // 模组名 + { + // 参数 + }, + { + // 按键 + {"on", "打开"}, + {"off", "关闭"}, + }, + [this](string buttonName, vector param) { // + logger->info("on AirCompressorCtrl.{}", buttonName); + if (buttonName == "on") { + dcs->AC_ctrl(1); + } else if (buttonName == "off") { + dcs->AC_close(); + } + }); + + auto ACState = m_testPageItemMgr.createStates({"ACState", "空压机状态"}, {{"current", "电流"}}, [this](string stateName) { // return fmt::format("{:.2f}A", dcs->AC_readEI()); }); - // 风机5 - m_dict->insert("BlowerCtrl", "风机控制"); - m_dict->insert("BlowerCtrl.on", "打开"); - m_dict->insert("BlowerCtrl.off", "关闭"); - - m_testPageItemMgr.insertButtons("BlowerCtrl", {}, {"on", "off"}, [this](string buttonName, vector param) { // - logger->info("on BlowerCtrl.{}", buttonName); - if (buttonName == "on") { - dcs->Blower_ctrl(90); - } else if (buttonName == "off") { - dcs->Blower_close(); - } - return "error"; - }); - - // 风机电流6 - m_dict->insert("Blower", "风机状态"); - m_dict->insert("Blower.current", "电流"); - m_testPageItemMgr.insertStates("Blower", {"current"}, [this](string stateName) { // + auto BlowerCtrl = m_testPageItemMgr.createButtons({"BlowerCtrl", "风机控制"}, // 模组名 + { + // 参数 + }, + { + // 按键 + {"on", "打开"}, + {"off", "关闭"}, + }, + [this](string buttonName, vector param) { // + logger->info("on BlowerCtrl.{}", buttonName); + if (buttonName == "on") { + dcs->Blower_ctrl(90); + } else if (buttonName == "off") { + dcs->Blower_close(); + } + }); + + auto Blower = m_testPageItemMgr.createStates({"Blower", "风机状态"}, {{"current", "电流"}}, [this](string stateName) { // return fmt::format("{:.2f}A", dcs->AC_readEI()); }); - // 加热片7 - m_dict->insert("HeatingCtrl", "加热片控制"); - m_dict->insert("HeatingCtrl.on", "打开"); - m_dict->insert("HeatingCtrl.off", "关闭"); - m_testPageItemMgr.insertButtons("HeatingCtrl", {}, {"on", "off"}, [this](string buttonName, vector param) { // - logger->info("on HeatingCtrl.{}", buttonName); - if (buttonName == "on") { - dcs->Heater_ctrl(1); - } else if (buttonName == "off") { - dcs->Heater_close(); - } - }); - - // 加热片状态8 - m_dict->insert("HeatingState", "加热片状态"); - m_dict->insert("HeatingState.temperature", "温度"); - m_dict->insert("HeatingState.current", "电流"); - m_testPageItemMgr.insertStates("HeatingState", {"temperature", "current"}, [this](string stateName) { // + auto HeatingCtrl = m_testPageItemMgr.createButtons({"HeatingCtrl", "加热片控制"}, // 模组名 + { + // 参数 + }, + { + // 按键 + {"on", "打开"}, + {"off", "关闭"}, + }, + [this](string buttonName, vector param) { // + logger->info("on HeatingCtrl.{}", buttonName); + if (buttonName == "on") { + dcs->Heater_ctrl(1); + } else if (buttonName == "off") { + dcs->Heater_close(); + } + }); + + auto HeatingState = m_testPageItemMgr.createStates({"HeatingState", "加热片状态"}, {{"temperature", "温度"}, {"current", "电流"}}, [this](string stateName) { // if (stateName == "temperature") { return fmt::format("{:.2f}℃", dcs->Heater_readTemperature()); } else if (stateName == "current") { @@ -142,59 +152,97 @@ void TestPageMgrService::initialize() { }); // 9 - m_dict->insert("PrinterTest", "打印机测试"); - m_dict->insert("PrinterTest.test", "测试"); - m_testPageItemMgr.insertButtons("PrinterTest", {}, {"test"}, [this](string buttonName, vector param) { PrinterTest_test(); }); + + auto PrinterTest = m_testPageItemMgr.createButtons({"PrinterTest", "打印机测试"}, // 模组名 + { + // 参数 + }, + { + // 按键 + {"test", "测试"}, + }, + [this](string buttonName, vector param) { PrinterTest_test(); }); // 10 - m_testPageItemMgr.insertPlaceHolder(); /******************************************************************************* * 正负压力控制 * *******************************************************************************/ + + auto AirLeakDetectTestModeCtrl = m_testPageItemMgr.createButtons({"AirLeakDetectTestModeCtrl", "气密性检测通道控制"}, // 模组名 + { + // 参数 + }, + { + // 按键 + {"disinfection", "正常模式"}, + {"inflation", "充气模式"}, + {"leakTest", "漏气检测模式"}, + }, + [this](string buttonName, vector param) { // + logger->info("AirLeakDetectTestModeCtrl buttonName:{} param:{}", buttonName, param); + if (buttonName == "disinfection") { + dcs->AirLeakDetectTestModeCtrl_setMode({kAirLeakTestMode_disinfection}); + } else if (buttonName == "inflation") { + dcs->AirLeakDetectTestModeCtrl_setMode({kAirLeakTestMode_inflation}); + } else if (buttonName == "leakTest") { + dcs->AirLeakDetectTestModeCtrl_setMode({kAirLeakTestMode_leakTest}); + } + }); + + auto PosiPressurePropCtrl = m_testPageItemMgr.createButtons({"PosiPressurePropCtrl", "正压比例阀控制"}, // 模组名 + { + // 参数 + {{"pumpVel", "百分比"}, "%", {{"0"}, {"10"}, {"20"}, {"30"}, {"40"}, {"50"}, {"60"}, {"70"}, {"80"}, {"90"}, {"100"}}}, // + }, + { + // 按键 + {"set", "设置"}, + {"close", "关闭"}, + }, + [this](string buttonName, vector param) { // + logger->info("PosiPressurePropCtrl buttonName:{} params:{}", buttonName, param); + if (buttonName == "set") { + dcs->PosiPressureProp_setValve(atoi(param[0].c_str())); + } else if (buttonName == "close") { + dcs->PosiPressureProp_setValve(0); + } + }); + + auto NegaPressurePropCtrl = m_testPageItemMgr.createButtons({"NegaPressurePropCtrl", "负压比例阀控制"}, // 模组名 + { + // 参数 + {{"pumpVel", "百分比"}, "%", {{"0"}, {"10"}, {"20"}, {"30"}, {"40"}, {"50"}, {"60"}, {"70"}, {"80"}, {"90"}, {"100"}}}, // + }, + { + // 按键 + {"set", "设置"}, + {"close", "关闭"}, + }, + [this](string buttonName, vector param) { // + logger->info("NegaPressurePropCtrl buttonName:{} params:{}", buttonName, param); + if (buttonName == "set") { + dcs->NegaPressureProp_setValve(atoi(param[0].c_str())); + } else if (buttonName == "close") { + dcs->NegaPressureProp_setValve(0); + } + }); + + m_testPageItemMgr.insert(SprayPumpCtrl); // 1 + m_testPageItemMgr.insert(AddDischargePumpCtrl); // 2 + m_testPageItemMgr.insert(AirCompressorCtrl); // 3 + m_testPageItemMgr.insert(ACState); // 4 + m_testPageItemMgr.insert(BlowerCtrl); // 5 + m_testPageItemMgr.insert(Blower); // 6 + m_testPageItemMgr.insert(HeatingCtrl); // 7 + m_testPageItemMgr.insert(HeatingState); // 8 + m_testPageItemMgr.insert(PrinterTest); // 9 + m_testPageItemMgr.insert(make_shared()); // 10 + if (PORT.isPipeDM()) { - // 11 - m_dict->insert("AirLeakDetectTestModeCtrl", ""); - m_dict->insert("AirLeakDetectTestModeCtrl.normal", "正常模式"); - m_dict->insert("AirLeakDetectTestModeCtrl.airTight", "密封模式"); - m_testPageItemMgr.insertButtons("AirLeakDetectTestModeCtrl", {}, {"normal", "airTight"}, [this](string buttonName, vector param) { // - logger->info("AirLeakDetectTestModeCtrl buttonName:{} param:{}", buttonName, param); - if (buttonName == "normal") { - dcs->AirLeakDetectTestModeCtrl_setMode(0); - } else if (buttonName == "airTight") { - dcs->AirLeakDetectTestModeCtrl_setMode(1); - } - }); - - // 比例阀控制 12 - m_dict->insert("PosiPressurePropCtrl", "正压比例阀控制"); - m_dict->insert("PosiPressurePropCtrl.set", "设置"); - m_dict->insert("PosiPressurePropCtrl.close", "关闭"); - m_dict->insert("NegaPressurePropCtrl", "负压比例阀控制"); - m_dict->insert("NegaPressurePropCtrl.set", "设置"); - m_dict->insert("NegaPressurePropCtrl.close", "关闭"); - m_dict->insert("PosiPressurePropCtrl.percent", "百分比"); - - m_testPageItemMgr.installParamType("PosiPressurePropCtrl.percent", "%", {"0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"}); - m_testPageItemMgr.insertButtons("PosiPressurePropCtrl", {"percent"}, {"set", "close"}, [this](string buttonName, vector param) { // - logger->info("PosiPressurePropCtrl buttonName:{} params:{}", buttonName, param); - if (buttonName == "set") { - dcs->PosiPressureProp_setValve(atoi(param[0].c_str())); - } else if (buttonName == "close") { - dcs->PosiPressureProp_setValve(0); - } - }); - - // 比例阀控制 13 - m_testPageItemMgr.installParamType("NegaPressurePropCtrl.percent", "%", {"0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"}); - m_testPageItemMgr.insertButtons("NegaPressurePropCtrl", {"percent"}, {"set", "close"}, [this](string buttonName, vector param) { // - logger->info("NegaPressurePropCtrl buttonName:{},params:{}", buttonName, param); - if (buttonName == "set") { - dcs->NegaPressureProp_setValve(atoi(param[0].c_str())); - } else if (buttonName == "close") { - dcs->NegaPressureProp_setValve(0); - } - }); + m_testPageItemMgr.insert(AirLeakDetectTestModeCtrl); // 11 + m_testPageItemMgr.insert(PosiPressurePropCtrl); // 12 + m_testPageItemMgr.insert(NegaPressurePropCtrl); // 13 } m_testPageItemMgr.onState.connect([this](json state) { // diff --git a/appsrc/service/test_page_mgr_service.hpp b/appsrc/service/test_page_mgr_service.hpp index 4ef7a07..519949f 100644 --- a/appsrc/service/test_page_mgr_service.hpp +++ b/appsrc/service/test_page_mgr_service.hpp @@ -16,6 +16,7 @@ namespace iflytop { using namespace testpage; + class TestPageMgrService : public enable_shared_from_this { THISCLASS(TestPageMgrService); @@ -25,8 +26,8 @@ class TestPageMgrService : public enable_shared_from_this { unique_ptr m_thread; - shared_ptr m_dict; - TestPageItemMgr m_testPageItemMgr; + // shared_ptr m_dict; + TestPageItemMgr m_testPageItemMgr; public: void initialize(); diff --git a/appsrc/service/testpage/test_page_item.hpp b/appsrc/service/testpage/test_page_item.hpp index 82e55fa..7cdd456 100644 --- a/appsrc/service/testpage/test_page_item.hpp +++ b/appsrc/service/testpage/test_page_item.hpp @@ -17,69 +17,64 @@ namespace testpage { typedef function)> onButton_t; typedef function readState_t; +class KeyName { + public: + string name; + string displayName; + KeyName() {} + KeyName(string name) : name(name), displayName(name) {} + KeyName(string name, string display) : name(name), displayName(display) {} + NLOHMANN_DEFINE_TYPE_INTRUSIVE(KeyName, name, displayName); +}; + class TestPageItem { public: TestPageItermType type; - string displayName; - string name; + KeyName name; TestPageItem(TestPageItermType t) : type(t) {} + TestPageItem(TestPageItermType t, KeyName n) : type(t), name(n) {} virtual ~TestPageItem() {} }; class Parameter { public: - string name; - string displayName; - string uint; - vector enums; - vector enumDisplayNames; + KeyName name; + string uint; + vector enums; - NLOHMANN_DEFINE_TYPE_INTRUSIVE(Parameter, name, displayName, uint, enums, enumDisplayNames); + Parameter() {} + Parameter(KeyName name, string uint, vector enums) : name(name), uint(uint), enums(enums) {} + NLOHMANN_DEFINE_TYPE_INTRUSIVE(Parameter, name, uint, enums); }; class Buttons : public TestPageItem { public: vector params; - - vector buttons; - vector buttonDisplayNames; + vector buttons; onButton_t onButton; Buttons() : TestPageItem(TestPageItermType::buttons) {} + Buttons(KeyName groupname, vector params, vector buttons, onButton_t onButton) // + : TestPageItem(TestPageItermType::buttons, groupname), params(params), buttons(buttons), onButton(onButton) {} - NLOHMANN_DEFINE_TYPE_INTRUSIVE(Buttons, type, displayName, name, params, buttons, buttonDisplayNames); -}; - -// class Button : public TestPageItem { -// public: -// vector params; - -// onButton_t onButton; -// Button() : TestPageItem(TestPageItermType::button) {} -// NLOHMANN_DEFINE_TYPE_INTRUSIVE(Button, type, displayName, name, params); -// }; - -class State : public TestPageItem { - public: - readState_t readState; - State() : TestPageItem(TestPageItermType::state) {} - NLOHMANN_DEFINE_TYPE_INTRUSIVE(State, type, displayName, name); + NLOHMANN_DEFINE_TYPE_INTRUSIVE(Buttons, type, name, params, buttons); }; class States : public TestPageItem { public: - vector states; - vector stateDisplayNames; - readState_t readState; + vector states; + readState_t readState; States() : TestPageItem(TestPageItermType::states) {} - NLOHMANN_DEFINE_TYPE_INTRUSIVE(States, type, displayName, name, states, stateDisplayNames); + States(KeyName groupname, vector states, readState_t readStates) // + : TestPageItem(TestPageItermType::states, groupname), states(states), readState(readStates) {} + NLOHMANN_DEFINE_TYPE_INTRUSIVE(States, type, name, states); }; // 换行 class PlaceHolder : public TestPageItem { public: - PlaceHolder() : TestPageItem(TestPageItermType::placeHolder) {} - NLOHMANN_DEFINE_TYPE_INTRUSIVE(PlaceHolder, type, displayName, name); + PlaceHolder() : TestPageItem(TestPageItermType::placeHolder) { name = KeyName("placeHolder"); } + NLOHMANN_DEFINE_TYPE_INTRUSIVE(PlaceHolder, type, name); }; } // namespace testpage diff --git a/appsrc/service/testpage/test_page_processer.cpp b/appsrc/service/testpage/test_page_processer.cpp index d76e0db..64ed4bb 100644 --- a/appsrc/service/testpage/test_page_processer.cpp +++ b/appsrc/service/testpage/test_page_processer.cpp @@ -5,72 +5,29 @@ using namespace testpage; void TestPageItemMgr::initialize() {} -void TestPageItemMgr::installDict(shared_ptr dict) { this->dict = dict; } -void TestPageItemMgr::installParamType(string paramType, string uint, vector enumItems) { - Parameter param; - param.name = paramType; - param.displayName = getDisplayVal(paramType, paramType); - param.uint = uint; - - for (uint32_t i = 0; i < enumItems.size(); i++) { - param.enums.push_back(enumItems[i]); - param.enumDisplayNames.push_back(getDisplayVal(paramType + "xx." + enumItems[i], enumItems[i])); - } - m_paramTypes[paramType] = param; -} - -void TestPageItemMgr::insertButtons(string groupName, vector params, vector buttons, onButton_t onButton) { +shared_ptr TestPageItemMgr::createButtons(KeyName groupName, vector params, vector buttons, onButton_t onButton) { shared_ptr item = make_shared(); item->name = groupName; - item->displayName = getDisplayVal(groupName, groupName); item->buttons = buttons; - for (auto& p : params) { - Parameter para = getParamType(groupName + "." + p); - item->params.push_back(para); - } - for (auto& bname : buttons) { - item->buttonDisplayNames.push_back(getDisplayVal(groupName + "." + bname, bname)); - } - item->onButton = onButton; - insert(item); + item->params = params; + item->onButton = onButton; + return item; } -void TestPageItemMgr::insertStates(string groupname, vector states, readState_t readStates) { +shared_ptr TestPageItemMgr::createStates(KeyName groupname, vector states, readState_t readStates) { shared_ptr item = make_shared(); item->name = groupname; - item->displayName = getDisplayVal(groupname, groupname); item->states = states; item->readState = readStates; - // stateDisplayNames - for (auto& s : states) { - item->stateDisplayNames.push_back(getDisplayVal(groupname + "." + s, s)); - } - insert(item); -} -void TestPageItemMgr::insertPlaceHolder() { - shared_ptr item = make_shared(); - item->name = "PlaceHolder"; - insert(item); -} - -string TestPageItemMgr::getDisplayVal(string name, string defaultVal) { - if (!dict) return defaultVal; - return dict->getChName(name, defaultVal); + return item; } -Parameter TestPageItemMgr::getParamType(string name) { - auto it = m_paramTypes.find(name); - if (it == m_paramTypes.end()) { - THROW_APP_EXCEPTION(err::kappe_missing_param, fmt::format("missing param type: {}", name)); - } - return it->second; -} - void TestPageItemMgr::insert(shared_ptr item) { m_itemList.push_back(item); } + void TestPageItemMgr::processOnButton(string groupName, string buttonName, json params) { for (auto& it : m_itemList) { shared_ptr item = it; - if (item->name != groupName) continue; + if (item->name.name != groupName) continue; // // if (item->type == TestPageItermType::button) { @@ -91,15 +48,15 @@ void TestPageItemMgr::processOnButton(string groupName, string buttonName, json vector paramstable; for (auto& p : buttons->params) { - auto it = params.find(p.name); + auto it = params.find(p.name.name); if (it == params.end()) { - THROW_APP_EXCEPTION(err::kappe_missing_param, fmt::format("missing parameter {}", p.name)); + THROW_APP_EXCEPTION(err::kappe_missing_param, fmt::format("missing parameter {}", p.name.name)); } paramstable.push_back(it->get()); } for (uint32_t i = 0; i < buttons->buttons.size(); i++) { - if (buttons->buttons[i] == buttonName) { + if (buttons->buttons[i].name == buttonName) { buttons->onButton(buttonName, params); } } @@ -125,7 +82,7 @@ void TestPageItemMgr::startReportState(int interval) { logger->info("TestPageItemMgr thread error, sleep 10s"); thisThread.sleepForMs(10 * 1000); m_errorFlag = false; - if(thisThread.getExitFlag()) break; + if (thisThread.getExitFlag()) break; } try { @@ -153,19 +110,8 @@ json TestPageItemMgr::readState() { for (auto& it : m_itemList) { shared_ptr item = it; - // process state - if (item->type == TestPageItermType::state) { - // - shared_ptr stateItem = dynamic_pointer_cast(item); - ZASSERT(stateItem); - ZASSERT(stateItem->readState); - - // read state - state[item->name][item->name] = stateItem->readState(item->name); - } - // process states - else if (item->type == TestPageItermType::states) { + if (item->type == TestPageItermType::states) { // shared_ptr states = dynamic_pointer_cast(item); ZASSERT(states); @@ -173,7 +119,7 @@ json TestPageItemMgr::readState() { // read state for (uint32_t i = 0; i < states->states.size(); i++) { - state[item->name][states->states[i]] = states->readState(states->states[i]); + state[item->name.name][states->states[i].name] = states->readState(states->states[i].name); } } } @@ -185,12 +131,8 @@ json TestPageItemMgr::getPageCfgInfo() { for (auto& it : m_itemList) { shared_ptr item = it; json itemCfg; - if (item->type == TestPageItermType::button) { - // itemCfg = TOJSON(Button, item); - } else if (item->type == TestPageItermType::buttons) { + if (item->type == TestPageItermType::buttons) { itemCfg = TOJSON(Buttons, item); - } else if (item->type == TestPageItermType::state) { - itemCfg = TOJSON(State, item); } else if (item->type == TestPageItermType::states) { itemCfg = TOJSON(States, item); } else if (item->type == TestPageItermType::placeHolder) { diff --git a/appsrc/service/testpage/test_page_processer.hpp b/appsrc/service/testpage/test_page_processer.hpp index 71f9639..6242d25 100644 --- a/appsrc/service/testpage/test_page_processer.hpp +++ b/appsrc/service/testpage/test_page_processer.hpp @@ -20,24 +20,19 @@ class TestPageItemMgr { THISCLASS(TestPageItemMgr); private: - shared_ptr dict; - map m_paramTypes; - list> m_itemList; unique_ptr m_thread; - bool m_errorFlag=false; + bool m_errorFlag = false; public: nod::signal onState; public: void initialize(); - void installDict(shared_ptr dict); - void installParamType(string name, string uint, vector enumItems); - void insertButtons(string name, vector buttons, vector params, onButton_t onButton); - void insertStates(string name, vector states, readState_t readStates); - void insertPlaceHolder(); + shared_ptr createButtons(KeyName groupName, vector params, vector buttons, onButton_t onButton); + shared_ptr createStates(KeyName name, vector states, readState_t readStates); + void insert(shared_ptr item); // ZDictionaryIterm public: @@ -48,9 +43,6 @@ class TestPageItemMgr { json readState(); private: - void insert(shared_ptr item); - string getDisplayVal(string name, string defaultVal); - Parameter getParamType(string name); }; } // namespace testpage