From e56f8176665344dffeb54a4fdb7b08f18024826d Mon Sep 17 00:00:00 2001 From: zhaohe Date: Thu, 23 May 2024 22:59:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E5=87=BA=E5=9C=BA=E8=AE=BE=E7=BD=AE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++ src/api/cmds/setting_page_cmd_impl.cpp | 11 +++++++ src/api/cmds/setting_page_cmd_impl.hpp | 24 +++++++------- src/db/db_service.cpp | 54 +++++++++++++++++++++++-------- src/db/db_service.hpp | 10 +++--- src/service/device_io_control_service.cpp | 12 +++---- src/version.hpp | 2 +- 7 files changed, 79 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index cedc410..6ba034d 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ 1.添加传感器预热检查 V5.1 1.排液最后的默认排空管道时间修改成8秒 + V5.2 + 1.添加配置恢复出场设置接口 ``` @@ -15,6 +17,7 @@ TODO: 1. 如果CAN总线意外断开,程序无法自恢复通信。 + 2. 消毒前如果湿度过大,不开始消毒 ``` diff --git a/src/api/cmds/setting_page_cmd_impl.cpp b/src/api/cmds/setting_page_cmd_impl.cpp index b6959e3..4e5bfa1 100644 --- a/src/api/cmds/setting_page_cmd_impl.cpp +++ b/src/api/cmds/setting_page_cmd_impl.cpp @@ -6,6 +6,14 @@ void SettingPageCmdImpl::getAllSetting(json& cmd, json& receipt) { receipt["dbval"] = dbval; 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) { string settingName = cmd["settingName"]; int settingVal = jsonGet(cmd["settingVal"]); @@ -118,4 +126,7 @@ void SettingPageCmdImpl::initialize() { m_msgProcesser->registerMsgProcesser("delFormula", BIND(SettingPageCmdImpl::delFormula)); m_msgProcesser->registerMsgProcesser("updateFormula", BIND(SettingPageCmdImpl::updateFormula)); m_msgProcesser->registerMsgProcesser("updateFormula2", BIND(SettingPageCmdImpl::updateFormula2)); + m_msgProcesser->registerMsgProcesser("factoryResetSettings", BIND(SettingPageCmdImpl::factoryResetSettings)); + + } diff --git a/src/api/cmds/setting_page_cmd_impl.hpp b/src/api/cmds/setting_page_cmd_impl.hpp index 65d4cb5..4f25d42 100644 --- a/src/api/cmds/setting_page_cmd_impl.hpp +++ b/src/api/cmds/setting_page_cmd_impl.hpp @@ -33,17 +33,17 @@ using namespace core; class SettingPageCmdImpl : public enable_shared_from_this { ENABLE_LOGGER(SettingPageCmdImpl); - shared_ptr m_msgProcesser; - shared_ptr m_zconfig; - shared_ptr m_iflytopwsService; - shared_ptr m_dbService; - shared_ptr m_deviceStateService; - shared_ptr m_disinfectionCtrlService; - shared_ptr m_deviceIoControlService; - shared_ptr m_disinfectionLogsManager; - shared_ptr m_zcanhost; - shared_ptr m_dataExportService; - shared_ptr m_frontMsgProcesser; + shared_ptr m_msgProcesser; + shared_ptr m_zconfig; + shared_ptr m_iflytopwsService; + shared_ptr m_dbService; + shared_ptr m_deviceStateService; + shared_ptr m_disinfectionCtrlService; + shared_ptr m_deviceIoControlService; + shared_ptr m_disinfectionLogsManager; + shared_ptr m_zcanhost; + shared_ptr m_dataExportService; + shared_ptr m_frontMsgProcesser; public: SettingPageCmdImpl(){}; @@ -57,6 +57,8 @@ class SettingPageCmdImpl : public enable_shared_from_this { void updateFormula(json& cmd, json& receipt); void updateFormula2(json& cmd, json& receipt); + void factoryResetSettings(json& cmd, json& receipt); + private: }; } // namespace iflytop \ No newline at end of file diff --git a/src/db/db_service.cpp b/src/db/db_service.cpp index 67532f7..d641111 100644 --- a/src/db/db_service.cpp +++ b/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[] = { - {.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])) DBService::DBService(/* args */) {} @@ -321,11 +336,23 @@ json DBService::getAllSettingJson() { j_setting["val_upper_limit"] = s.val_upper_limit; j_setting["permission_level"] = s.permission_level; j_setting["val"] = s.val; + j_setting["default_val"] = s.default_val; j_settings.push_back(j_setting); } return j_settings; } +void DBService::settingfactoryReset() { + lock_guard lock(lock_); + auto settingtable = make_storage(SETTING_DB, SETTING_DB_STRUCT); + settingtable.sync_schema(); + auto all = settingtable.get_all(); + for (auto& s : all) { + s.val = s.default_val; + settingtable.update(s); + } +} + bool DBService::isUserExist(string uid) { lock_guard lock(lock_); @@ -454,8 +481,7 @@ json DBService::getAllFormulaJson() { 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 lock(lock_); auto formulatable = make_storage(FORMULA_DB, FORMULA_DB_STRUCT); diff --git a/src/db/db_service.hpp b/src/db/db_service.hpp index 6c2c2f0..9b272a5 100644 --- a/src/db/db_service.hpp +++ b/src/db/db_service.hpp @@ -15,10 +15,10 @@ #include #include +#include "configs/project_setting.hpp" #include "iflytop/core/spdlogfactory/logger.hpp" #include "iflytop/core/thread/thread.hpp" #include "user_behavior_des.hpp" -#include "configs/project_setting.hpp" #define USER_DB "user.db" #define SETTING_DB "setting.db" @@ -74,6 +74,7 @@ struct Setting { int val_upper_limit; int permission_level; int val; + int default_val; }; struct Formula { @@ -141,6 +142,7 @@ class DBService : public enable_shared_from_this { bool setSettingVal(int id, int val); bool setSettingVal(string name, int val); int getSettingVal(string name); + void settingfactoryReset(); public: /******************************************************************************* @@ -149,10 +151,8 @@ class DBService : public enable_shared_from_this { list> getAllFormula(); 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 delFormula(int id); shared_ptr updateFormula(int id, string column, string val); shared_ptr updateFormula(shared_ptr formula); diff --git a/src/service/device_io_control_service.cpp b/src/service/device_io_control_service.cpp index 4ab7484..16dc164 100644 --- a/src/service/device_io_control_service.cpp +++ b/src/service/device_io_control_service.cpp @@ -452,8 +452,8 @@ void DeviceIoControlService::sprayLiquidPump_open(int gpm) { SprayLiquidPump__gpm = gpm; int speed = GPM_TO_SPEED(gpm); - if (speed > 400) { - speed = 400; + if (speed > 450) { + speed = 450; } else if (speed < 0) { speed = 0; } @@ -468,10 +468,10 @@ void DeviceIoControlService::sprayLiquidPump_close() { void DeviceIoControlService::sprayLiquidPump_open_for_test(int gpm) { logger->info("sprayLiquidPump_open {}", 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; m_zcanHost->pumpctrl_c1004(2, 100, speed, 1, 15); diff --git a/src/version.hpp b/src/version.hpp index d67d9b6..f169230 100644 --- a/src/version.hpp +++ b/src/version.hpp @@ -1,2 +1,2 @@ #pragma once -#define VERSION "5.1" \ No newline at end of file +#define VERSION "5.2" \ No newline at end of file