diff --git a/appsrc/service/app/pipeline_pressure_control.cpp b/appsrc/service/app/pipeline_pressure_control.cpp index 1387d3c..68ac3b2 100644 --- a/appsrc/service/app/pipeline_pressure_control.cpp +++ b/appsrc/service/app/pipeline_pressure_control.cpp @@ -1,9 +1,10 @@ #include "pipeline_pressure_control.hpp" using namespace iflytop; -static vector pressureEnum = {"constantPressure", "positivePressure", "negativePressure"}; static vector pressureEnumDisplay = {"恒压", "正压", "负压"}; +ZENUM_IMPL(PressureType, PressureType_LIST); + static bool isInStrings(const string& s, const vector& v) { for (auto& i : v) { if (i == s) { @@ -18,27 +19,33 @@ void PipelinePressureControl::initialize() { GET_TO_SERVICE(m_ds); GET_TO_SERVICE(m_dics); GET_TO_SERVICE(m_gConfig); + REG_ENUM_TYPE(PressureType, PressureType::getEnumStrList()); - REG_EXTFN(setType, void(string), type); - REG_EXTFN(setIntensity, void(string), intensity); + REG_EXTFN(setType, void(PressureType), type); + REG_EXTFN(setIntensity, void(int), intensity); REG_EXTFN_VOID(getState, void(void)); REG_EXTFN_VOID(getConfig, void(void)); - m_type = "constantPressure"; + + m_type = PressureType::constantPressure; m_intensity = 0; - syncPressureValueState(); + try { + syncPressureValueState(); + } catch (const appexception& e) { + logger->error("syncPressureValueState error:{}", e.what()); + } } void PipelinePressureControl::syncPressureValueState() { if (PORT.isPipeDM()) { logger->info("syncPressureValueState m_type:{} m_intensity:{}", m_type, m_intensity); - if (m_type == "constantPressure") { + if (m_type == PressureType::constantPressure) { m_dics->PosiPressureProp_setValve(0); m_dics->NegaPressureProp_setValve(0); - } else if (m_type == "positivePressure") { + } else if (m_type == PressureType::positivePressure) { m_dics->PosiPressureProp_setValve(m_intensity); m_dics->NegaPressureProp_setValve(0); - } else if (m_type == "negativePressure") { + } else if (m_type == PressureType::negativePressure) { m_dics->PosiPressureProp_setValve(0); m_dics->NegaPressureProp_setValve(m_intensity); } @@ -48,48 +55,41 @@ void PipelinePressureControl::syncPressureValueState() { void PipelinePressureControl::getConfig(shared_ptr cxt) { json cfg; - cfg["types"] = pressureEnum; + cfg["types"] = PressureType::getEnumStrList(); cfg["typeDisplayNames"] = pressureEnumDisplay; cfg["intensitys"]["constantPressure"] = {}; - cfg["intensitys"]["positivePressure"] = {"10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%"}; - cfg["intensitys"]["negativePressure"] = {"10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%"}; - cxt->rely = cfg; + cfg["intensitys"]["positivePressure"] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100}; + cfg["intensitys"]["negativePressure"] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100}; + cxt->rely = cfg; } -void PipelinePressureControl::setType(shared_ptr cxt, string type) { +void PipelinePressureControl::setType(shared_ptr cxt, PressureType type) { m_type = cxt->params["type"]; - if (!isInStrings(m_type, pressureEnum)) { + if (!isInStrings(m_type, PressureType::getEnumStrList())) { cxt->ackcode = err::kappe_param_value_err; return; } - if (m_type == "constantPressure") { + if (m_type == PressureType::constantPressure) { m_intensity = 0; - } - if (m_type == "positivePressure") { + + } else if (m_type == PressureType::positivePressure) { m_intensity = 10; - } - if (m_type == "negativePressure") { + } else if (m_type == PressureType::negativePressure) { m_intensity = 10; } syncPressureValueState(); cxt->rely["type"] = m_type; - cxt->rely["intensity"] = fmt::format("{}%", m_intensity); + cxt->rely["intensity"] = m_intensity; } -void PipelinePressureControl::setIntensity(shared_ptr cxt, string intensity) { +void PipelinePressureControl::setIntensity(shared_ptr cxt, int intensity) { // 解析字符串 10% -> 10 - auto pos = intensity.find("%"); - if (pos == string::npos) { - cxt->ackcode = err::kappe_param_value_err; - return; - } - intensity = intensity.substr(0, pos); - m_intensity = atoi(intensity.c_str()); + + m_intensity = intensity; syncPressureValueState(); } void PipelinePressureControl::getState(shared_ptr cxt) { cxt->rely["type"] = m_type; - cxt->rely["intensity"] = fmt::format("{}%", m_intensity); - ; + cxt->rely["intensity"] = m_intensity; } diff --git a/appsrc/service/app/pipeline_pressure_control.hpp b/appsrc/service/app/pipeline_pressure_control.hpp index 72c2027..74e06f3 100644 --- a/appsrc/service/app/pipeline_pressure_control.hpp +++ b/appsrc/service/app/pipeline_pressure_control.hpp @@ -11,6 +11,15 @@ // #include "baseservice/baseservice.hpp" #include "service/hardware/device_io_ctrl_service.hpp" + +// +#define PressureType_LIST(type, marco) /**/ \ + marco(type, constantPressure) /**/ \ + marco(type, positivePressure) /**/ \ + marco(type, negativePressure) /**/ + +ZENUM_DECLAR(PressureType, PressureType_LIST); + namespace iflytop { class PipelinePressureControl : public enable_shared_from_this { THISCLASS(PipelinePressureControl); @@ -48,8 +57,8 @@ class PipelinePressureControl : public enable_shared_from_this m_dics; shared_ptr m_gConfig; - string m_type; - int m_intensity = 0; + PressureType m_type; + int m_intensity = 0; public: void initialize(); @@ -58,8 +67,8 @@ class PipelinePressureControl : public enable_shared_from_this cxt,string type); - void setIntensity(shared_ptr cxt,string intensity); + void setType(shared_ptr cxt, PressureType type); + void setIntensity(shared_ptr cxt, int intensity); void getState(shared_ptr cxt); void getConfig(shared_ptr cxt); diff --git a/appsrc/service/test_page_mgr_service.cpp b/appsrc/service/test_page_mgr_service.cpp index 5024bfc..5a8f2e1 100644 --- a/appsrc/service/test_page_mgr_service.cpp +++ b/appsrc/service/test_page_mgr_service.cpp @@ -173,11 +173,10 @@ void TestPageMgrService::initialize() { m_dict->insert("NegaPressurePropCtrl", "负压比例阀控制"); m_dict->insert("NegaPressurePropCtrl.set", "设置"); m_dict->insert("NegaPressurePropCtrl.close", "关闭"); - m_dict->insert("proportionalOpenPercent", "数值"); + m_dict->insert("PosiPressurePropCtrl.percent", "百分比"); - m_testPageItemMgr.installParamType("proportionalOpenPercent", "%", {"0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"}); - - m_testPageItemMgr.insertButtons("PosiPressurePropCtrl", {"proportionalOpenPercent"}, {"set", "close"}, [this](string buttonName, vector param) { // + 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())); @@ -187,7 +186,8 @@ void TestPageMgrService::initialize() { }); // 比例阀控制 13 - m_testPageItemMgr.insertButtons("NegaPressurePropCtrl", {"proportionalOpenPercent"}, {"set", "close"}, [this](string buttonName, vector param) { // + 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()));