Browse Source

添加气密性测试api

storage-in-realtime
zhaohe 12 months ago
parent
commit
06a10a766f
  1. 7
      app_protocols/apperrorcode/apperrorcode.hpp
  2. 13
      appdep/iflytop/core/components/zenum_template/zenum_template.hpp
  3. 8
      appsrc/appbase/utils/zdictionary.hpp
  4. 96
      appsrc/service/app/air_leak_detect_test.cpp
  5. 23
      appsrc/service/app/air_leak_detect_test.hpp
  6. 3
      appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp
  7. 87
      appsrc/service/app/pipeline_pressure_control.cpp
  8. 15
      appsrc/service/app/pipeline_pressure_control.hpp
  9. 11
      doc/后端测试.md

7
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;
}

13
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<string> getEnumStrList() { \
vector<string> ret; \
elist(name, ZENUM_IMPL4) return ret; \
} \
static vector<name> getEnumList() { \
vector<name> 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)); } \

8
appsrc/appbase/utils/zdictionary.hpp

@ -39,6 +39,14 @@ class ZDictionary {
return defaultval;
}
}
vector<string> getChNames(vector<string>& keys) {
vector<string> res;
for (auto& key : keys) {
res.push_back(getChName(key));
}
return res;
}
};
} // namespace iflytop

96
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<AppWarningPromoptEvent>(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<MsgProcessContext> cxt) { //
@ -17,15 +50,56 @@ void AirLeakDetectTest::fn_start(shared_ptr<MsgProcessContext> cxt) { //
}
void AirLeakDetectTest::fn_stop(shared_ptr<MsgProcessContext> cxt) { stop(); }
void AirLeakDetectTest::fn_getState(shared_ptr<MsgProcessContext> 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<MsgProcessContext> 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);
}
}
}

23
appsrc/service/app/air_leak_detect_test.hpp

@ -10,6 +10,7 @@
#include <vector>
//
#include "baseservice/baseservice.hpp"
#include "service/hardware/device_io_ctrl_service.hpp"
namespace iflytop {
class AirLeakDetectTest : public enable_shared_from_this<AirLeakDetectTest> {
THISCLASS(AddLiquidService);
@ -17,15 +18,18 @@ class AirLeakDetectTest : public enable_shared_from_this<AirLeakDetectTest> {
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<AirLeakDetectTest> {
switch (state) {
case kidle:
return "空闲";
case kinitDevice:
return "初始化设备";
case kinflating:
return "打压中";
case kleakTesting:
@ -53,11 +59,15 @@ class AirLeakDetectTest : public enable_shared_from_this<AirLeakDetectTest> {
}
private:
shared_ptr<DBService> m_db;
shared_ptr<DeviceStateService> m_ds;
shared_ptr<GConfig> m_gConfig;
shared_ptr<DBService> m_db;
shared_ptr<DeviceStateService> m_ds;
shared_ptr<GConfig> m_gConfig;
shared_ptr<DeviceIoControlService> m_dics;
unique_ptr<Thread> m_thread;
state_t m_workstate = kidle;
float pressurePa = 0;
public:
void initialize();
@ -72,6 +82,7 @@ class AirLeakDetectTest : public enable_shared_from_this<AirLeakDetectTest> {
void fn_getServiceConfig(shared_ptr<MsgProcessContext> cxt);
private:
void airLeakDetectTestThread();
};
} // namespace iflytop

3
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<AppDisinfectionStartEvent>(s_sessionId));
GET_SERVICE(WarningLightControler)->setworkFlag(true);
changeToNextState();
logger->info("start disinfection {}", s_sessionId);
}

87
appsrc/service/app/pipeline_pressure_control.cpp

@ -1,33 +1,96 @@
#include "pipeline_pressure_control.hpp"
using namespace iflytop;
static vector<string> pressureEnum = {"constantPressure", "positivePressure", "negativePressure"};
static vector<string> pressureEnumDisplay = {"恒压", "正压", "负压"};
static bool isInStrings(const string& s, const vector<string>& 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<MsgProcessContext> cxt) { m_type = cxt->params["type"]; }
void PipelinePressureControl::fn_getConfig(shared_ptr<MsgProcessContext> 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<MsgProcessContext> 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<MsgProcessContext> 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<MsgProcessContext> 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);
;
}

15
appsrc/service/app/pipeline_pressure_control.hpp

@ -10,6 +10,7 @@
#include <vector>
//
#include "baseservice/baseservice.hpp"
#include "service/hardware/device_io_ctrl_service.hpp"
namespace iflytop {
class PipelinePressureControl : public enable_shared_from_this<PipelinePressureControl> {
THISCLASS(AddLiquidService);
@ -41,17 +42,21 @@ class PipelinePressureControl : public enable_shared_from_this<PipelinePressureC
}
}
public:
shared_ptr<DBService> m_db;
shared_ptr<DeviceStateService> m_ds;
shared_ptr<GConfig> m_gConfig;
private:
shared_ptr<DBService> m_db;
shared_ptr<DeviceStateService> m_ds;
shared_ptr<DeviceIoControlService> m_dics;
shared_ptr<GConfig> m_gConfig;
string m_type;
string m_intensity;
int m_intensity = 0;
public:
void initialize();
public:
void syncPressureValueState();
private:
void fn_setType(shared_ptr<MsgProcessContext> cxt);
void fn_setIntensity(shared_ptr<MsgProcessContext> cxt);

11
doc/后端测试.md

@ -0,0 +1,11 @@
# 后端测试
```
加液
排液
消毒
```
Loading…
Cancel
Save