Browse Source

添加配置恢复出场设置接口

master
zhaohe 1 year ago
parent
commit
e56f817666
  1. 3
      README.md
  2. 11
      src/api/cmds/setting_page_cmd_impl.cpp
  3. 24
      src/api/cmds/setting_page_cmd_impl.hpp
  4. 54
      src/db/db_service.cpp
  5. 10
      src/db/db_service.hpp
  6. 12
      src/service/device_io_control_service.cpp
  7. 2
      src/version.hpp

3
README.md

@ -8,6 +8,8 @@
1.添加传感器预热检查 1.添加传感器预热检查
V5.1 V5.1
1.排液最后的默认排空管道时间修改成8秒 1.排液最后的默认排空管道时间修改成8秒
V5.2
1.添加配置恢复出场设置接口
``` ```
@ -15,6 +17,7 @@
TODO: TODO:
1. 如果CAN总线意外断开,程序无法自恢复通信。 1. 如果CAN总线意外断开,程序无法自恢复通信。
2. 消毒前如果湿度过大,不开始消毒
``` ```

11
src/api/cmds/setting_page_cmd_impl.cpp

@ -6,6 +6,14 @@ void SettingPageCmdImpl::getAllSetting(json& cmd, json& receipt) {
receipt["dbval"] = dbval; receipt["dbval"] = dbval;
return; return;
} }
void SettingPageCmdImpl::factoryResetSettings(json& cmd, json& receipt) {
m_dbService->settingfactoryReset();
auto dbval = m_dbService->getAllSettingJson();
receipt["dbval"] = dbval;
return;
}
void SettingPageCmdImpl::setSettingVal(json& cmd, json& receipt) { void SettingPageCmdImpl::setSettingVal(json& cmd, json& receipt) {
string settingName = cmd["settingName"]; string settingName = cmd["settingName"];
int settingVal = jsonGet<int>(cmd["settingVal"]); int settingVal = jsonGet<int>(cmd["settingVal"]);
@ -118,4 +126,7 @@ void SettingPageCmdImpl::initialize() {
m_msgProcesser->registerMsgProcesser("delFormula", BIND(SettingPageCmdImpl::delFormula)); m_msgProcesser->registerMsgProcesser("delFormula", BIND(SettingPageCmdImpl::delFormula));
m_msgProcesser->registerMsgProcesser("updateFormula", BIND(SettingPageCmdImpl::updateFormula)); m_msgProcesser->registerMsgProcesser("updateFormula", BIND(SettingPageCmdImpl::updateFormula));
m_msgProcesser->registerMsgProcesser("updateFormula2", BIND(SettingPageCmdImpl::updateFormula2)); m_msgProcesser->registerMsgProcesser("updateFormula2", BIND(SettingPageCmdImpl::updateFormula2));
m_msgProcesser->registerMsgProcesser("factoryResetSettings", BIND(SettingPageCmdImpl::factoryResetSettings));
} }

24
src/api/cmds/setting_page_cmd_impl.hpp

@ -33,17 +33,17 @@ using namespace core;
class SettingPageCmdImpl : public enable_shared_from_this<SettingPageCmdImpl> { class SettingPageCmdImpl : public enable_shared_from_this<SettingPageCmdImpl> {
ENABLE_LOGGER(SettingPageCmdImpl); ENABLE_LOGGER(SettingPageCmdImpl);
shared_ptr<FrontMsgProcesser> m_msgProcesser;
shared_ptr<GConfig> m_zconfig;
shared_ptr<IflytopFrontEndService> m_iflytopwsService;
shared_ptr<DBService> m_dbService;
shared_ptr<DeviceStateService> m_deviceStateService;
shared_ptr<DisinfectionCtrlService> m_disinfectionCtrlService;
shared_ptr<IF_DeviceIoContrlService> m_deviceIoControlService;
shared_ptr<DisinfectionLogsManager> m_disinfectionLogsManager;
shared_ptr<ZCanHost> m_zcanhost;
shared_ptr<DataExportService> m_dataExportService;
shared_ptr<FrontMsgProcesser> m_frontMsgProcesser;
shared_ptr<FrontMsgProcesser> m_msgProcesser;
shared_ptr<GConfig> m_zconfig;
shared_ptr<IflytopFrontEndService> m_iflytopwsService;
shared_ptr<DBService> m_dbService;
shared_ptr<DeviceStateService> m_deviceStateService;
shared_ptr<DisinfectionCtrlService> m_disinfectionCtrlService;
shared_ptr<IF_DeviceIoContrlService> m_deviceIoControlService;
shared_ptr<DisinfectionLogsManager> m_disinfectionLogsManager;
shared_ptr<ZCanHost> m_zcanhost;
shared_ptr<DataExportService> m_dataExportService;
shared_ptr<FrontMsgProcesser> m_frontMsgProcesser;
public: public:
SettingPageCmdImpl(){}; SettingPageCmdImpl(){};
@ -57,6 +57,8 @@ class SettingPageCmdImpl : public enable_shared_from_this<SettingPageCmdImpl> {
void updateFormula(json& cmd, json& receipt); void updateFormula(json& cmd, json& receipt);
void updateFormula2(json& cmd, json& receipt); void updateFormula2(json& cmd, json& receipt);
void factoryResetSettings(json& cmd, json& receipt);
private: private:
}; };
} // namespace iflytop } // namespace iflytop

54
src/db/db_service.cpp

@ -61,21 +61,36 @@ using namespace nlohmann;
/******************************************************************************* /*******************************************************************************
* * * *
*******************************************************************************/ *******************************************************************************/
#define SETTING_ITEM(_id, _name, _name_ch, _val_lower_limit, _val_upper_limit, _val) \
{ .id = _id, .name = _name, .name_ch = _name_ch, .val_lower_limit = _val_lower_limit, .val_upper_limit = _val_upper_limit, .permission_level = 0, .val = _val, .default_val = _val }
// static Setting config_settings_table[] = {
// {.id = 1, .name = "stoped_gs", .name_ch = "消毒停止过氧化氢溶度", .val_lower_limit = 0, .val_upper_limit = 2000, .permission_level = 0, .val = 300},
// {.id = 2, .name = "continued_gs", .name_ch = "消毒继续过氧化氢溶度", .val_lower_limit = 0, .val_upper_limit = 2000, .permission_level = 0, .val = 200},
// {.id = 3, .name = "stoped_satur", .name_ch = "消毒停止过氧化氢相对饱和度", .val_lower_limit = 0, .val_upper_limit = 100, .permission_level = 0, .val = 85},
// {.id = 4, .name = "continued_satur", .name_ch = "消毒继续过氧化氢相对饱和度", .val_lower_limit = 0, .val_upper_limit = 100, .permission_level = 0, .val = 70},
// {.id = 5, .name = "max_humidity", .name_ch = "允许消毒最大湿度", .val_lower_limit = 0, .val_upper_limit = 100, .permission_level = 0, .val = 90},
// {.id = 6, .name = "placeHolder0", .name_ch = "placeHolder0", .val_lower_limit = 0, .val_upper_limit = 0, .permission_level = 0, .val = 0},
// {.id = 7, .name = "injection_pump_speed", .name_ch = "喷射蠕动泵转速", .val_lower_limit = 0, .val_upper_limit = 50, .permission_level = 0, .val = 50},
// {.id = 8, .name = "pre_heat_time_s", .name_ch = "预热时间", .val_lower_limit = 0, .val_upper_limit = 600, .permission_level = 0, .val = 120},
// {.id = 9, .name = "stoped_humi", .name_ch = "消毒停止相对湿度", .val_lower_limit = 0, .val_upper_limit = 100, .permission_level = 0, .val = 85},
// {.id = 10, .name = "continued_humi", .name_ch = "消毒继续相对湿度", .val_lower_limit = 0, .val_upper_limit = 100, .permission_level = 0, .val = 70},
// };
static Setting config_settings_table[] = { static Setting config_settings_table[] = {
{.id = 1, .name = "stoped_gs", .name_ch = "消毒停止过氧化氢溶度", .val_lower_limit = 0, .val_upper_limit = 2000, .permission_level = 0, .val = 1800},
{.id = 2, .name = "continued_gs", .name_ch = "消毒继续过氧化氢溶度", .val_lower_limit = 0, .val_upper_limit = 2000, .permission_level = 0, .val = 1500},
{.id = 3, .name = "stoped_satur", .name_ch = "消毒停止过氧化氢相对饱和度", .val_lower_limit = 0, .val_upper_limit = 100, .permission_level = 0, .val = 85},
{.id = 4, .name = "continued_satur", .name_ch = "消毒继续过氧化氢相对饱和度", .val_lower_limit = 0, .val_upper_limit = 100, .permission_level = 0, .val = 70},
{.id = 5, .name = "max_humidity", .name_ch = "允许消毒最大湿度", .val_lower_limit = 0, .val_upper_limit = 100, .permission_level = 0, .val = 90},
{.id = 6, .name = "drainage_pump_speed", .name_ch = "排液蠕动泵转速", .val_lower_limit = 0, .val_upper_limit = 90, .permission_level = 0, .val = 90},
{.id = 7, .name = "injection_pump_speed", .name_ch = "喷射蠕动泵转速", .val_lower_limit = 0, .val_upper_limit = 50, .permission_level = 0, .val = 50},
{.id = 8, .name = "pre_heat_time_s", .name_ch = "预热时间", .val_lower_limit = 0, .val_upper_limit = 600, .permission_level = 0, .val = 120},
{.id = 9, .name = "stoped_humi", .name_ch = "消毒停止相对湿度", .val_lower_limit = 0, .val_upper_limit = 100, .permission_level = 0, .val = 85},
{.id = 10, .name = "continued_humi", .name_ch = "消毒继续相对湿度", .val_lower_limit = 0, .val_upper_limit = 100, .permission_level = 0, .val = 70},
{.id = 11, .name = "proportional_valve_default_value", .name_ch = "正负压默认开合比例", .val_lower_limit = 0, .val_upper_limit = 100, .permission_level = 0, .val = 10},
SETTING_ITEM(1, "stoped_gs", /*************/ "消毒停止过氧化氢溶度", /**********/ 0, 2000, 300), //
SETTING_ITEM(2, "continued_gs", /**********/ "消毒继续过氧化氢溶度", /**********/ 0, 2000, 200), //
SETTING_ITEM(3, "stoped_satur", /**********/ "消毒停止过氧化氢相对饱和度", /*****/ 0, 100, 85), //
SETTING_ITEM(4, "continued_satur", /*******/ "消毒继续过氧化氢相对饱和度", /*****/ 0, 100, 60), //
SETTING_ITEM(5, "max_humidity", /**********/ "允许消毒最大湿度", /*************/ 0, 100, 90), //
SETTING_ITEM(6, "placeHolder0", /**********/ "placeHolder0", /***************/ 0, 0, 0), //
SETTING_ITEM(7, "injection_pump_speed", /**/ "喷射蠕动泵转速", /***************/ 0, 30, 30), //
SETTING_ITEM(8, "pre_heat_time_s", /*******/ "预热时间", /*******************/ 0, 1200, 120), //
SETTING_ITEM(9, "stoped_humi", /***********/ "消毒停止相对湿度", /************/ 0, 100, 85), //
SETTING_ITEM(10, "continued_humi", /*******/ "消毒继续相对湿度", /************/ 0, 100, 60), //
}; };
#define ZARRARY_SIZE(val) (sizeof(val) / sizeof(val[0])) #define ZARRARY_SIZE(val) (sizeof(val) / sizeof(val[0]))
DBService::DBService(/* args */) {} DBService::DBService(/* args */) {}
@ -321,11 +336,23 @@ json DBService::getAllSettingJson() {
j_setting["val_upper_limit"] = s.val_upper_limit; j_setting["val_upper_limit"] = s.val_upper_limit;
j_setting["permission_level"] = s.permission_level; j_setting["permission_level"] = s.permission_level;
j_setting["val"] = s.val; j_setting["val"] = s.val;
j_setting["default_val"] = s.default_val;
j_settings.push_back(j_setting); j_settings.push_back(j_setting);
} }
return j_settings; return j_settings;
} }
void DBService::settingfactoryReset() {
lock_guard<recursive_mutex> lock(lock_);
auto settingtable = make_storage(SETTING_DB, SETTING_DB_STRUCT);
settingtable.sync_schema();
auto all = settingtable.get_all<Setting>();
for (auto& s : all) {
s.val = s.default_val;
settingtable.update(s);
}
}
bool DBService::isUserExist(string uid) { bool DBService::isUserExist(string uid) {
lock_guard<recursive_mutex> lock(lock_); lock_guard<recursive_mutex> lock(lock_);
@ -454,8 +481,7 @@ json DBService::getAllFormulaJson() {
return jret; return jret;
} }
void DBService::addFormula(string formula_id, string loglevel, string stoped_gs, string continued_gs, string stoped_satur, string continued_satur, string stoped_humi, string continued_humi,
string injection_pump_speed) {
void DBService::addFormula(string formula_id, string loglevel, string stoped_gs, string continued_gs, string stoped_satur, string continued_satur, string stoped_humi, string continued_humi, string injection_pump_speed) {
lock_guard<recursive_mutex> lock(lock_); lock_guard<recursive_mutex> lock(lock_);
auto formulatable = make_storage(FORMULA_DB, FORMULA_DB_STRUCT); auto formulatable = make_storage(FORMULA_DB, FORMULA_DB_STRUCT);

10
src/db/db_service.hpp

@ -15,10 +15,10 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "configs/project_setting.hpp"
#include "iflytop/core/spdlogfactory/logger.hpp" #include "iflytop/core/spdlogfactory/logger.hpp"
#include "iflytop/core/thread/thread.hpp" #include "iflytop/core/thread/thread.hpp"
#include "user_behavior_des.hpp" #include "user_behavior_des.hpp"
#include "configs/project_setting.hpp"
#define USER_DB "user.db" #define USER_DB "user.db"
#define SETTING_DB "setting.db" #define SETTING_DB "setting.db"
@ -74,6 +74,7 @@ struct Setting {
int val_upper_limit; int val_upper_limit;
int permission_level; int permission_level;
int val; int val;
int default_val;
}; };
struct Formula { struct Formula {
@ -141,6 +142,7 @@ class DBService : public enable_shared_from_this<DBService> {
bool setSettingVal(int id, int val); bool setSettingVal(int id, int val);
bool setSettingVal(string name, int val); bool setSettingVal(string name, int val);
int getSettingVal(string name); int getSettingVal(string name);
void settingfactoryReset();
public: public:
/******************************************************************************* /*******************************************************************************
@ -149,10 +151,8 @@ class DBService : public enable_shared_from_this<DBService> {
list<shared_ptr<db::Formula>> getAllFormula(); list<shared_ptr<db::Formula>> getAllFormula();
json getAllFormulaJson(); json getAllFormulaJson();
void addFormula(string formula_id, string loglevel, string stoped_gs, string continued_gs, string stoped_satur, string continued_satur, string stoped_humi,
string continued_humi, string injection_pump_speed);
void addFormula(string formula_id, int loglevel, int stoped_gs, int continued_gs, int stoped_satur, int continued_satur, int stoped_humi, int continued_humi,
int injection_pump_speed);
void addFormula(string formula_id, string loglevel, string stoped_gs, string continued_gs, string stoped_satur, string continued_satur, string stoped_humi, string continued_humi, string injection_pump_speed);
void addFormula(string formula_id, int loglevel, int stoped_gs, int continued_gs, int stoped_satur, int continued_satur, int stoped_humi, int continued_humi, int injection_pump_speed);
shared_ptr<db::Formula> delFormula(int id); shared_ptr<db::Formula> delFormula(int id);
shared_ptr<db::Formula> updateFormula(int id, string column, string val); shared_ptr<db::Formula> updateFormula(int id, string column, string val);
shared_ptr<db::Formula> updateFormula(shared_ptr<db::Formula> formula); shared_ptr<db::Formula> updateFormula(shared_ptr<db::Formula> formula);

12
src/service/device_io_control_service.cpp

@ -452,8 +452,8 @@ void DeviceIoControlService::sprayLiquidPump_open(int gpm) {
SprayLiquidPump__gpm = gpm; SprayLiquidPump__gpm = gpm;
int speed = GPM_TO_SPEED(gpm); int speed = GPM_TO_SPEED(gpm);
if (speed > 400) {
speed = 400;
if (speed > 450) {
speed = 450;
} else if (speed < 0) { } else if (speed < 0) {
speed = 0; speed = 0;
} }
@ -468,10 +468,10 @@ void DeviceIoControlService::sprayLiquidPump_close() {
void DeviceIoControlService::sprayLiquidPump_open_for_test(int gpm) { void DeviceIoControlService::sprayLiquidPump_open_for_test(int gpm) {
logger->info("sprayLiquidPump_open {}", gpm); logger->info("sprayLiquidPump_open {}", gpm);
int speed = GPM_TO_SPEED(gpm); int speed = GPM_TO_SPEED(gpm);
if (speed > 400) {
speed = 400;
} else if (speed < -400) {
speed = -400;
if (speed > 450) {
speed = 450;
} else if (speed < -450) {
speed = -450;
} }
SprayLiquidPump__gpm = gpm; SprayLiquidPump__gpm = gpm;
m_zcanHost->pumpctrl_c1004(2, 100, speed, 1, 15); m_zcanHost->pumpctrl_c1004(2, 100, speed, 1, 15);

2
src/version.hpp

@ -1,2 +1,2 @@
#pragma once #pragma once
#define VERSION "5.1"
#define VERSION "5.2"
Loading…
Cancel
Save