Browse Source

添加加液逻辑

storage-in-realtime
zhaohe 12 months ago
parent
commit
e678026900
  1. 2
      app_protocols/apperrorcode/apperrorcode.hpp
  2. 3
      appsrc/appbase/appbase.hpp
  3. 3
      appsrc/appbase/appbean/device_state.cpp
  4. 13
      appsrc/appbase/appbean/device_state.hpp
  5. 9
      appsrc/appsetting/project_port/basic/project_constant.hpp
  6. 20
      appsrc/appsetting/project_port/project_port.cpp
  7. 8
      appsrc/appsetting/project_port/project_port.hpp
  8. 11
      appsrc/baseservice/devicestate/device_state_service.hpp
  9. 90
      appsrc/service/app/add_liquid_service.cpp
  10. 14
      appsrc/service/app/add_liquid_service.hpp
  11. 2
      appsrc/service/app/air_leak_detect_test.cpp
  12. 0
      appsrc/service/app/air_leak_detect_test.hpp
  13. 11
      appsrc/service/hardware/device_ctrl_service.cpp
  14. 1
      appsrc/service/hardware/device_ctrl_service.hpp
  15. 2
      appsrc/service/main_control_service.cpp

2
app_protocols/apperrorcode/apperrorcode.hpp

@ -62,6 +62,8 @@ typedef enum {
kappe_missing_param = 10016,
kappe_param_num_err = 10017,
kappe_is_busy = 10018,
} apperror_t;
}

3
appsrc/appbase/appbase.hpp

@ -11,4 +11,5 @@
#include "appbase/appbean/hardware_component.hpp"
#include "appbase/appbean/setting_id.hpp"
#include "appbase/appbean/pumpid.hpp"
#include "appbase/appbean/test_page_iterm.hpp"
#include "appbase/appbean/test_page_iterm.hpp"
#include "appbean/device_state.hpp"

3
appsrc/appbase/appbean/device_state.cpp

@ -0,0 +1,3 @@
#include "device_state.hpp"
DeviceState_ZENUM_IMPL;

13
appsrc/appbase/appbean/device_state.hpp

@ -0,0 +1,13 @@
#pragma once
#include "iflytop/core/components/zenum_template/zenum_template.hpp"
#define DeviceState_ZENUM_IMPL ZENUM_IMPL(DeviceState, DeviceState_LIST)
#define DeviceState_LIST(type, marco) /**/ \
marco(type, Idle) /**/ \
marco(type, Disinfection) /**/ \
marco(type, AddingLiquid) /**/ \
marco(type, DrainingLiquid) /**/ \
marco(type, AirLeakDetectTesting) /**/
ZENUM_DECLAR(DeviceState, DeviceState_LIST);

9
appsrc/appsetting/project_port/basic/project_constant.hpp

@ -19,8 +19,8 @@
#define MAX_SUPPORT_SENSOR 3
// GPM_TO_SPEED_RADIO
#define LARGE_SPACE_DM_GPM_TO_SPEED_RADIO (11.0250)
#define SMALL_SPACE_DM_GPM_TO_SPEED_RADIO (11.0250)
#define LARGE_SPACE_DM__GPM_TO_SPEED_RADIO (11.0250)
#define SMALL_SPACE_DM__GPM_TO_SPEED_RADIO (11.0250)
#define PIPE_DM_GPM_TO_SPEED_RADIO (11.0250)
#define DRAW_BAR_DM_GPM_TO_SPEED_RADIO (41.97)
@ -32,3 +32,8 @@
#define POSITIVE_PRESSURE_PROPORTIONAL_ID 0x01
#define NEGATIVE_PRESSURE_PROPORTIONAL_ID 0x02
#define LARGE_SPACE_DM__DISINFECTANT_BUCKET_CAPACITY 5000
#define SMALL_SPACE_DM__DISINFECTANT_BUCKET_CAPACITY 2800
#define PIPE_DM__DISINFECTANT_BUCKET_CAPACITY 2500
#define DRAW_BAR_DM__DISINFECTANT_BUCKET_CAPACITY 0

20
appsrc/appsetting/project_port/project_port.cpp

@ -43,17 +43,21 @@ void ProjectPort::initProjectSetting(int projectTypeInt) {
projectType = projectType2Str(projectTypeInt);
if (projectTypeInt == klarge_space_disinfection_machine) {
extSensorNum = LARGE_SPACE_DM_EXT_SENSOR_NUM;
gpmToSpeedRadio = LARGE_SPACE_DM_GPM_TO_SPEED_RADIO;
extSensorNum = LARGE_SPACE_DM_EXT_SENSOR_NUM;
gpmToSpeedRadio = LARGE_SPACE_DM__GPM_TO_SPEED_RADIO;
disinfectantBucketCapacity = LARGE_SPACE_DM__DISINFECTANT_BUCKET_CAPACITY;
} else if (projectTypeInt == ksmall_space_disinfection_machine) {
extSensorNum = SMALL_SPACE_DM_EXT_SENSOR_NUM;
gpmToSpeedRadio = SMALL_SPACE_DM_GPM_TO_SPEED_RADIO;
extSensorNum = SMALL_SPACE_DM_EXT_SENSOR_NUM;
gpmToSpeedRadio = SMALL_SPACE_DM__GPM_TO_SPEED_RADIO;
disinfectantBucketCapacity = SMALL_SPACE_DM__DISINFECTANT_BUCKET_CAPACITY;
} else if (projectTypeInt == kpipe_disinfection_machine) {
extSensorNum = PIPE_DM_EXT_SENSOR_NUM;
gpmToSpeedRadio = PIPE_DM_GPM_TO_SPEED_RADIO;
extSensorNum = PIPE_DM_EXT_SENSOR_NUM;
gpmToSpeedRadio = PIPE_DM_GPM_TO_SPEED_RADIO;
disinfectantBucketCapacity = PIPE_DM__DISINFECTANT_BUCKET_CAPACITY;
} else if (projectTypeInt == kdraw_bar_disinfection_box) {
extSensorNum = DRAW_BAR_DM_EXT_SENSOR_NUM;
gpmToSpeedRadio = DRAW_BAR_DM_GPM_TO_SPEED_RADIO;
extSensorNum = DRAW_BAR_DM_EXT_SENSOR_NUM;
gpmToSpeedRadio = DRAW_BAR_DM_GPM_TO_SPEED_RADIO;
disinfectantBucketCapacity = DRAW_BAR_DM__DISINFECTANT_BUCKET_CAPACITY;
} else {
ZCHECK(false, "projectTypeInt not support: " + to_string(projectTypeInt));
}

8
appsrc/appsetting/project_port/project_port.hpp

@ -39,9 +39,10 @@ class ProjectPort {
//
// some properties
//
int extSensorNum = 0;
double gpmToSpeedRadio = 0;
bool isInited = false;
int extSensorNum = 0;
double gpmToSpeedRadio = 0;
bool isInited = false;
int disinfectantBucketCapacity = 0;
public:
static ProjectPort &ins() {
@ -94,4 +95,5 @@ class ProjectPort {
};
#define PROJECT_TYPE (GET_SERVICE(ProjectSettingMgr)->getProjType())
#define PROJECT_SETTING (GET_SERVICE(ProjectSettingMgr))
#define PORT (ProjectPort::ins())
} // namespace iflytop

11
appsrc/baseservice/devicestate/device_state_service.hpp

@ -34,16 +34,18 @@ using namespace core;
class DeviceStateService : public enable_shared_from_this<DeviceStateService> {
THISCLASS(DeviceStateService);
bool loginFlag = false;
bool loginFlag = false;
bool m_isLoginAdmin = false;
string loginUid;
DeviceState state = DeviceState::Idle;
public:
DeviceStateService() {};
void setLoginState(string uid, bool isadmin) {
loginFlag = true;
loginUid = uid;
loginFlag = true;
loginUid = uid;
m_isLoginAdmin = isadmin;
}
@ -55,6 +57,9 @@ class DeviceStateService : public enable_shared_from_this<DeviceStateService> {
string getLoginUid() { return loginUid; }
bool isLoginAdmin() { return m_isLoginAdmin; }
DeviceState getDeviceState() { return state; }
void setDeviceState(DeviceState s) { state = s; }
void initialize() {};
};
} // namespace iflytop

90
appsrc/service/app/add_liquid_service.cpp

@ -8,8 +8,93 @@ void AddLiquidService::initialize() {
REGFNV2(AddLiquidService, getServiceConfig);
}
void AddLiquidService::start(int stopatg) { m_workstate = kaddingLiquid; }
void AddLiquidService::stop() { m_workstate = kidle; }
void AddLiquidService::start(int stopatg) {
lock_guard<recursive_mutex> lock(lock_);
if (m_ds->getDeviceState() != DeviceState::Idle) {
logger->warn("start add liquid fail, device state is not idle");
THROW_APP_EXCEPTION(err::kappe_is_busy, "device state is not idle");
}
if (m_thread) {
m_thread->join();
m_thread = nullptr;
m_workstate = kidle;
}
int32_t nowvolume = m_dwus->getWeight();
int maxg = PORT.disinfectantBucketCapacity;
stopatg += 0; // 由于加液过程中,测量到的液体要比真实的小,所以这里要比预设值大100
if (stopatg > maxg) {
logger->warn("start add liquid fail, stopatg {} > maxg {}", stopatg, maxg);
stopatg = maxg;
}
if (nowvolume > stopatg) {
logger->warn("start add liquid fail, nowvolume {} > stopatg {}", nowvolume, stopatg);
return;
}
m_workstate = kaddingLiquid;
m_thread.reset(new Thread("addLiquid", [this, stopatg]() { addLiquidWork(stopatg); }));
//
logger->info("start add liquid success");
}
void AddLiquidService::addLiquidWork(int stopatg) {
ThisThread thisThread;
/**
* @brief
*/
logger->info("start add liquid");
m_dcs->AddLiquidPump_addLiquid();
while (!thisThread.getExitFlag()) {
int32_t nowvolume = m_dwus->getWeight();
logger->info("replenishingFluids {}g", nowvolume);
if (nowvolume > stopatg) {
break;
}
thisThread.sleepForMs(300);
}
m_dcs->AddLiquidPump_stop();
/**
* @brief
*/
m_workstate = kemptyLineLiquid;
logger->info("start drain the liquid from the line");
m_dcs->SprayPump_startInRPM(-800); // 40gpm 约等于450RPM
thisThread.sleepForMs(1000);
m_dcs->AddLiquidPump_run(-23); // @TODO:提取常数到系统配置中
#define EMTPTY_LINE_WHEN_ADDING_DISINFECTANT_TIMES 1000
for (size_t i = 0; i < EMTPTY_LINE_WHEN_ADDING_DISINFECTANT_TIMES; i++) {
if (thisThread.getExitFlag()) break;
thisThread.sleepForMs(100);
}
m_dcs->AddLiquidPump_stop();
m_dcs->SprayPump_stop();
/**
* @brief
*/
logger->info("empty line liquid done");
m_workstate = kidle;
}
void AddLiquidService::stop() {
lock_guard<recursive_mutex> lock(lock_);
if (m_workstate == kidle) {
return;
}
m_workstate = kidle;
if (m_thread) {
m_thread->join();
m_thread = nullptr;
}
logger->info("stoped add liquid");
}
AddLiquidService::state_t AddLiquidService::getWorkstate() { return m_workstate; }
void AddLiquidService::fn_start(shared_ptr<MsgProcessContext> cxt) { //
@ -22,7 +107,6 @@ void AddLiquidService::fn_getState(shared_ptr<MsgProcessContext> cxt) { //
cxt->content["workStateDisplay"] = state2chstr(getWorkstate());
cxt->content["nowLiquid"] = 1000;
}
void AddLiquidService::fn_getServiceConfig(shared_ptr<MsgProcessContext> cxt) {
json cfg;
cfg["maxLiquid"] = 4950;

14
appsrc/service/app/add_liquid_service.hpp

@ -4,12 +4,17 @@
#include <list>
#include <map>
#include <memory>
#include <mutex>
#include <set>
#include <sstream>
#include <string>
#include <vector>
//
#include "baseservice/baseservice.hpp"
#include "service/hardware/device_ctrl_service.hpp"
#include "service/hardware/disinfectant_weight_update_service.hpp"
//
namespace iflytop {
class AddLiquidService : public enable_shared_from_this<AddLiquidService> {
THISCLASS(AddLiquidService);
@ -52,8 +57,15 @@ class AddLiquidService : public enable_shared_from_this<AddLiquidService> {
shared_ptr<DeviceStateService> m_ds;
shared_ptr<GConfig> m_gConfig;
shared_ptr<DeviceIoControlService> m_dcs;
shared_ptr<DisinfectantWeightUpdateService> m_dwus;
unique_ptr<Thread> m_thread;
state_t m_workstate = kidle;
recursive_mutex lock_;
public:
void initialize();
@ -67,6 +79,8 @@ class AddLiquidService : public enable_shared_from_this<AddLiquidService> {
void fn_getServiceConfig(shared_ptr<MsgProcessContext> cxt);
private:
void addLiquidWork(int stopatg);
};
} // namespace iflytop

2
appsrc/service/app/air_tightness_test.cpp → appsrc/service/app/air_leak_detect_test.cpp

@ -1,4 +1,4 @@
#include "air_tightness_test.hpp"
#include "air_leak_detect_test.hpp"
using namespace iflytop;
void AirLeakDetectTest::initialize() {
logger->info("AirLeakDetectTest initialize");

0
appsrc/service/app/air_tightness_test.hpp → appsrc/service/app/air_leak_detect_test.hpp

11
appsrc/service/hardware/device_ctrl_service.cpp

@ -67,6 +67,8 @@ void DeviceIoControlService::AddLiquidPump_drainLiquid() {
int pumpspeed = GET_SETTING(int, SettingId::drainage_pump_speed);
CAN_MASTER->pumpRotate(GET_BOARDID(), GET_SUBID(), -pumpspeed);
}
void DeviceIoControlService::AddLiquidPump_run(int rpm) { CAN_MASTER->pumpRotate(GET_BOARDID(), GET_SUBID(), rpm); }
void DeviceIoControlService::AddLiquidPump_stop() { CAN_MASTER->pumpStop(GET_BOARDID(), GET_SUBID()); }
#undef COMPONENT
@ -190,9 +192,8 @@ int DeviceIoControlService::AddLiquidPumpPostPS_readPa() { //
#undef COMPONENT
int DeviceIoControlService::DisinfectantVolume_readVal() {
int pa = LiquidWeightPS_readPa();
int pa = LiquidWeightPS_readPa();
return ProjectPort::ins().pressurePa2VolumeG(pa);
return 0; } // g
return 0;
} // g

1
appsrc/service/hardware/device_ctrl_service.hpp

@ -47,6 +47,7 @@ class DeviceIoControlService : public enable_shared_from_this<DeviceIoControlSer
public:
// 加液泵控制
void AddLiquidPump_addLiquid();
void AddLiquidPump_run(int rpm);
void AddLiquidPump_drainLiquid();
void AddLiquidPump_stop();

2
appsrc/service/main_control_service.cpp

@ -11,7 +11,7 @@
#include "service/user_mgr_service.hpp"
//
#include "service/app/add_liquid_service.hpp"
#include "service/app/air_tightness_test.hpp"
#include "service/app/air_leak_detect_test.hpp"
#include "service/app/disinfection_ctrl_service.hpp"
#include "service/app/drain_liquid_service.hpp"
#include "service/app/pipeline_pressure_control.hpp"

Loading…
Cancel
Save