diff --git a/app_protocols/apperrorcode/apperrorcode.hpp b/app_protocols/apperrorcode/apperrorcode.hpp index b87f263..6c9792f 100644 --- a/app_protocols/apperrorcode/apperrorcode.hpp +++ b/app_protocols/apperrorcode/apperrorcode.hpp @@ -59,8 +59,9 @@ typedef enum { // kappe_file_operate_error = 10015, - kappe_missing_param = 10016, - kappe_param_num_err = 10017, + kappe_missing_param = 10016, + kappe_param_num_err = 10017, + kappe_param_value_err = 10018, // 液体已加到位 kappe_adding_liquid_is_already_in_place = 10100, @@ -79,8 +80,6 @@ typedef enum { kappe_sensor_is_pre_hearting = 10027, // 传感器正在预热 kappe_disinfection_state_is_wrong = 10028, // 消毒状态错误 - - } apperror_t; } diff --git a/appdep/iflytop/core/components/zenum_template/zenum_template.hpp b/appdep/iflytop/core/components/zenum_template/zenum_template.hpp index 8821b14..2da8df6 100644 --- a/appdep/iflytop/core/components/zenum_template/zenum_template.hpp +++ b/appdep/iflytop/core/components/zenum_template/zenum_template.hpp @@ -31,6 +31,9 @@ return k##enumname; \ } +#define ZENUM_IMPL4(type, enumname) ret.push_back(#enumname); +#define ZENUM_IMPL5(type, enumname) ret.push_back(enumname); + #define ZENUM_DECLAR(name, elist) \ namespace iflytop { \ using namespace std; \ @@ -49,7 +52,15 @@ static enum_val_t toEnum(string str) { elist(name, ZENUM_TO_ENUM_IMPL) return kunkown; } \ operator string() const { return toString(id); } \ operator int() const { return int(id); } \ - bool operator==(const name& setid) const { return id == setid.id; } \ + bool operator==(const name& setid) const { return id == setid.id; } \ + static vector getEnumStrList() { \ + vector ret; \ + elist(name, ZENUM_IMPL4) return ret; \ + } \ + static vector getEnumList() { \ + vector ret; \ + elist(name, ZENUM_IMPL5) return ret; \ + } \ }; \ static inline void to_json(json& j, const name& setid) { j = setid.toString(setid.getId()); } \ static inline void from_json(const json& j, name& setid) { setid = name(string(j)); } \ diff --git a/appsrc/appbase/utils/zdictionary.hpp b/appsrc/appbase/utils/zdictionary.hpp index 8e635b0..2587620 100644 --- a/appsrc/appbase/utils/zdictionary.hpp +++ b/appsrc/appbase/utils/zdictionary.hpp @@ -39,6 +39,14 @@ class ZDictionary { return defaultval; } } + + vector getChNames(vector& keys) { + vector res; + for (auto& key : keys) { + res.push_back(getChName(key)); + } + return res; + } }; } // namespace iflytop \ No newline at end of file diff --git a/appsrc/service/app/air_leak_detect_test.cpp b/appsrc/service/app/air_leak_detect_test.cpp index 2e66f49..6c40ee1 100644 --- a/appsrc/service/app/air_leak_detect_test.cpp +++ b/appsrc/service/app/air_leak_detect_test.cpp @@ -1,15 +1,48 @@ #include "air_leak_detect_test.hpp" + +#include "pipeline_pressure_control.hpp" using namespace iflytop; void AirLeakDetectTest::initialize() { logger->info("AirLeakDetectTest initialize"); + + GET_TO_SERVICE(m_db) + GET_TO_SERVICE(m_ds) + GET_TO_SERVICE(m_gConfig) + GET_TO_SERVICE(m_dics) + REGFNV2(AirLeakDetectTest, start); REGFNV2(AirLeakDetectTest, stop); REGFNV2(AirLeakDetectTest, getState); REGFNV2(AirLeakDetectTest, getServiceConfig); } -void AirLeakDetectTest::start() { m_workstate = kleakTesting; } -void AirLeakDetectTest::stop() { m_workstate = kidle; } +void AirLeakDetectTest::start() { + logger->info("AirLeakDetectTest start"); + m_workstate = kinitDevice; + m_thread.reset(new Thread("AirLeakDetectTestThread", [this]() { + try { + airLeakDetectTestThread(); + } catch (const appexception& e) { + logger->error("AirLeakDetectTest error: {}", e.what()); + AppEventBus::ins()->push(make_shared(e.ecode())); + } + GET_SERVICE(PipelinePressureControl)->syncPressureValueState(); + + try { + if (PORT.isPipeDM()) m_dics->AirLeakDetectTestModeCtrl_setMode(0); + } catch (...) { + } + + m_workstate = kidle; + })); +} +void AirLeakDetectTest::stop() { + logger->info("AirLeakDetectTest stop"); + if (m_thread) { + m_thread->join(); + m_thread = nullptr; + } +} AirLeakDetectTest::state_t AirLeakDetectTest::getWorkstate() { return m_workstate; } void AirLeakDetectTest::fn_start(shared_ptr cxt) { // @@ -17,15 +50,56 @@ void AirLeakDetectTest::fn_start(shared_ptr cxt) { // } void AirLeakDetectTest::fn_stop(shared_ptr cxt) { stop(); } void AirLeakDetectTest::fn_getState(shared_ptr cxt) { // - cxt->content["workState"] = state2str(getWorkstate()); - cxt->content["workStateDisplay"] = state2chstr(getWorkstate()); - cxt->content["pressure"] = 3.1; + + if (PORT.isPipeDM()) { + cxt->content["workState"] = state2str(getWorkstate()); + cxt->content["workStateDisplay"] = state2chstr(getWorkstate()); + cxt->content["pressure"] = pressurePa / 1000.0; + } } void AirLeakDetectTest::fn_getServiceConfig(shared_ptr cxt) { - json cfg; - cfg["pressureUint"] = "kPa"; - cfg["pressureMax"] = 5.0; - cfg["show"] = true; - cfg["updatePeriod"] = 300; - cxt->content = cfg; + if (PORT.isPipeDM()) { + json cfg; + cfg["pressureUint"] = "kPa"; + cfg["pressureMax"] = 8.0; + cfg["show"] = true; + cfg["updatePeriod"] = 300; + cxt->content = cfg; + } +} +void AirLeakDetectTest::airLeakDetectTestThread() { + if (PORT.isPipeDM()) { + m_workstate = kinitDevice; + // 初始化设备,关闭比例法 + m_dics->PosiPressureProp_setValve(0); + m_dics->NegaPressureProp_setValve(0); + m_dics->AirLeakDetectTestModeCtrl_setMode(1); + + // 等待比例法关闭 + while (!ThisThread().getExitFlag()) { + if (m_dics->PosiPressureProp_isBusy() || m_dics->NegaPressureProp_isBusy()) { + ThisThread().sleepForMs(1000); + logger->info("AirLeakDetectTest wait for valve to close , posi:{} nega:{}", m_dics->PosiPressureProp_isBusy(), m_dics->NegaPressureProp_isBusy()); + } else { + break; + } + } + if (ThisThread().getExitFlag()) return; + + // 开始充气 + logger->info("inflate....."); + m_workstate = kinflating; + m_dics->AC_ctrl(1); + ThisThread().sleepForMs(1000); // 充气时间 + m_dics->AC_ctrl(0); + + if (ThisThread().getExitFlag()) return; + // 等待充气完成 + m_workstate = kleakTesting; + ThisThread().sleepForMs(5000); + while (!ThisThread().getExitFlag()) { + pressurePa = m_dics->ACPostPS_readPa(); + ThisThread().sleepForMs(1000); + } + } } diff --git a/appsrc/service/app/air_leak_detect_test.hpp b/appsrc/service/app/air_leak_detect_test.hpp index 6983c02..aa2c87e 100644 --- a/appsrc/service/app/air_leak_detect_test.hpp +++ b/appsrc/service/app/air_leak_detect_test.hpp @@ -10,6 +10,7 @@ #include // #include "baseservice/baseservice.hpp" +#include "service/hardware/device_io_ctrl_service.hpp" namespace iflytop { class AirLeakDetectTest : public enable_shared_from_this { THISCLASS(AddLiquidService); @@ -17,15 +18,18 @@ class AirLeakDetectTest : public enable_shared_from_this { public: typedef enum { kidle = 0, // 空闲 - kinflating = 1, // 打压中 - kleakTesting = 2, // 检漏中 - kstopping = 3, // 停止中 + kinitDevice = 1, // 初始化设备 + kinflating = 2, // 打压中 + kleakTesting = 3, // 检漏中 + kstopping = 4, // 停止中 } state_t; static const char* state2str(state_t state) { switch (state) { case kidle: return "idle"; + case kinitDevice: + return "initDevice"; case kinflating: return "inflating"; case kleakTesting: @@ -41,6 +45,8 @@ class AirLeakDetectTest : public enable_shared_from_this { switch (state) { case kidle: return "空闲"; + case kinitDevice: + return "初始化设备"; case kinflating: return "打压中"; case kleakTesting: @@ -53,11 +59,15 @@ class AirLeakDetectTest : public enable_shared_from_this { } private: - shared_ptr m_db; - shared_ptr m_ds; - shared_ptr m_gConfig; + shared_ptr m_db; + shared_ptr m_ds; + shared_ptr m_gConfig; + shared_ptr m_dics; + + unique_ptr m_thread; state_t m_workstate = kidle; + float pressurePa = 0; public: void initialize(); @@ -72,6 +82,7 @@ class AirLeakDetectTest : public enable_shared_from_this { void fn_getServiceConfig(shared_ptr cxt); private: + void airLeakDetectTestThread(); }; } // namespace iflytop diff --git a/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp b/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp index e2de9db..fb9666e 100644 --- a/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp +++ b/appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp @@ -2,6 +2,7 @@ #include "appcomponents/algo/dvalue_computer.hpp" #include "service/hardware/warning_light_controler.hpp" +#include "service/app/pipeline_pressure_control.hpp" using namespace iflytop; using namespace disinfection; @@ -396,6 +397,8 @@ void DisinfectionCtrlService::processStateInit(DisinfectionEvent* event) { AppEventBus::ins()->push(make_shared(s_sessionId)); GET_SERVICE(WarningLightControler)->setworkFlag(true); + + changeToNextState(); logger->info("start disinfection {}", s_sessionId); } diff --git a/appsrc/service/app/pipeline_pressure_control.cpp b/appsrc/service/app/pipeline_pressure_control.cpp index 09b6a48..5117b25 100644 --- a/appsrc/service/app/pipeline_pressure_control.cpp +++ b/appsrc/service/app/pipeline_pressure_control.cpp @@ -1,33 +1,96 @@ #include "pipeline_pressure_control.hpp" using namespace iflytop; + +static vector pressureEnum = {"constantPressure", "positivePressure", "negativePressure"}; +static vector pressureEnumDisplay = {"恒压", "正压", "负压"}; + +static bool isInStrings(const string& s, const vector& v) { + for (auto& i : v) { + if (i == s) { + return true; + } + } + return false; +} + void PipelinePressureControl::initialize() { + GET_TO_SERVICE(m_db); + GET_TO_SERVICE(m_ds); + GET_TO_SERVICE(m_dics); + GET_TO_SERVICE(m_gConfig); + REGFNV2(PipelinePressureControl, setType); REGFNV2(PipelinePressureControl, setIntensity); REGFNV2(PipelinePressureControl, getState); REGFNV2(PipelinePressureControl, getConfig); - m_type = "positivePressure"; - m_intensity = "10%"; + m_type = "constantPressure"; + m_intensity = 0; + syncPressureValueState(); +} + +void PipelinePressureControl::syncPressureValueState() { + if (PORT.isPipeDM()) { + logger->info("syncPressureValueState m_type:{} m_intensity:{}", m_type, m_intensity); + if (m_type == "constantPressure") { + m_dics->PosiPressureProp_setValve(0); + m_dics->NegaPressureProp_setValve(0); + } else if (m_type == "positivePressure") { + m_dics->PosiPressureProp_setValve(m_intensity); + m_dics->NegaPressureProp_setValve(0); + } else if (m_type == "negativePressure") { + m_dics->PosiPressureProp_setValve(0); + m_dics->NegaPressureProp_setValve(m_intensity); + } + } } -void PipelinePressureControl::fn_setType(shared_ptr cxt) { m_type = cxt->params["type"]; } void PipelinePressureControl::fn_getConfig(shared_ptr cxt) { json cfg; - cfg["types"] = {"constantPressure", "positivePressure", "negativePressure"}; - cfg["typeDisplayNames"] = {"恒压", "正压", "负压"}; + cfg["types"] = pressureEnum; + cfg["typeDisplayNames"] = pressureEnumDisplay; cfg["intensitys"]["constantPressure"] = {}; - cfg["intensitys"]["positivePressure"] = {"0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%"}; - cfg["intensitys"]["negativePressure"] = {"0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%"}; + 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->content = cfg; } +void PipelinePressureControl::fn_setType(shared_ptr cxt) { + m_type = cxt->params["type"]; + if (!isInStrings(m_type, pressureEnum)) { + cxt->ackcode = err::kappe_param_value_err; + return; + } + + if (m_type == "constantPressure") { + m_intensity = 0; + } + if (m_type == "positivePressure") { + m_intensity = 10; + } + if (m_type == "negativePressure") { + m_intensity = 10; + } + + syncPressureValueState(); + cxt->content["type"] = m_type; + cxt->content["intensity"] = fmt::format("{}%", m_intensity); +} + void PipelinePressureControl::fn_setIntensity(shared_ptr cxt) { string intensity = cxt->params["intensity"]; - m_intensity = intensity; + // 解析字符串 10% -> 10 + int 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()); + syncPressureValueState(); } void PipelinePressureControl::fn_getState(shared_ptr cxt) { - json state; - state["type"] = m_type; - state["intensity"] = m_intensity; - cxt->content = state; + cxt->content["type"] = m_type; + cxt->content["intensity"] = fmt::format("{}%", m_intensity); + ; } diff --git a/appsrc/service/app/pipeline_pressure_control.hpp b/appsrc/service/app/pipeline_pressure_control.hpp index 19c5b42..0051af5 100644 --- a/appsrc/service/app/pipeline_pressure_control.hpp +++ b/appsrc/service/app/pipeline_pressure_control.hpp @@ -10,6 +10,7 @@ #include // #include "baseservice/baseservice.hpp" +#include "service/hardware/device_io_ctrl_service.hpp" namespace iflytop { class PipelinePressureControl : public enable_shared_from_this { THISCLASS(AddLiquidService); @@ -41,17 +42,21 @@ class PipelinePressureControl : public enable_shared_from_this m_db; - shared_ptr m_ds; - shared_ptr m_gConfig; + private: + shared_ptr m_db; + shared_ptr m_ds; + shared_ptr m_dics; + shared_ptr m_gConfig; string m_type; - string m_intensity; + int m_intensity = 0; public: void initialize(); + public: + void syncPressureValueState(); + private: void fn_setType(shared_ptr cxt); void fn_setIntensity(shared_ptr cxt); diff --git a/doc/后端测试.md b/doc/后端测试.md new file mode 100644 index 0000000..4096e8d --- /dev/null +++ b/doc/后端测试.md @@ -0,0 +1,11 @@ +# 后端测试 + +``` +加液 +排液 +消毒 + + + + +``` \ No newline at end of file