From 51e058369addaada0a5920598d85aee26979e250 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Thu, 5 Dec 2024 21:25:02 +0800 Subject: [PATCH] update --- README.md | 15 ++-- appsrc/appbase/appbase.hpp | 1 + appsrc/appbase/appbean/project_type_enum.cpp | 2 + appsrc/appbase/appbean/project_type_enum.hpp | 13 ++++ appsrc/baseservice/baseservice.hpp | 9 +++ appsrc/baseservice/db/base/keyvaldbv2.cpp | 54 +++++++++++++ appsrc/baseservice/db/base/keyvaldbv2.hpp | 91 ++++++++++++++++++++++ appsrc/baseservice/db/calibrate_info_dao.cpp | 49 ++++++++++++ appsrc/baseservice/db/calibrate_info_dao.hpp | 75 ++++++++++++++++++ appsrc/baseservice/db/device_ext_setting_dao.cpp | 62 +++------------ appsrc/baseservice/db/device_ext_setting_dao.hpp | 55 ++++--------- appsrc/baseservice/db/equipment_usage_info_dao.cpp | 58 ++++++++++++++ appsrc/baseservice/db/equipment_usage_info_dao.hpp | 82 +++++++++++++++++++ .../front_msg_processer/front_msg_processer.cpp | 2 +- appsrc/baseservice/port/project_port.hpp | 8 ++ appsrc/service/app/add_liquid_service.cpp | 3 +- appsrc/service/app_core.cpp | 21 +++-- ...o2_liquid_weight_sensor_calibration_service.cpp | 24 ++++++ ...o2_liquid_weight_sensor_calibration_service.hpp | 30 +++++++ appsrc/service/device_info_mgr_service.cpp | 3 +- .../service/equipment_usage_info_mgr_service.cpp | 59 ++++++++++++++ .../service/equipment_usage_info_mgr_service.hpp | 29 +++++++ .../disinfectant_weight_update_service.cpp | 91 ++++++++++++++-------- .../disinfectant_weight_update_service.hpp | 5 +- appsrc/service/os_mgr_service.cpp | 2 +- appsrc/service/setting/ext_setting_mgr_service.cpp | 81 +++++++++++++++++++ appsrc/service/setting/ext_setting_mgr_service.hpp | 40 ++++++++++ 27 files changed, 820 insertions(+), 144 deletions(-) create mode 100644 appsrc/appbase/appbean/project_type_enum.cpp create mode 100644 appsrc/appbase/appbean/project_type_enum.hpp create mode 100644 appsrc/baseservice/db/base/keyvaldbv2.cpp create mode 100644 appsrc/baseservice/db/base/keyvaldbv2.hpp create mode 100644 appsrc/baseservice/db/calibrate_info_dao.cpp create mode 100644 appsrc/baseservice/db/calibrate_info_dao.hpp create mode 100644 appsrc/baseservice/db/equipment_usage_info_dao.cpp create mode 100644 appsrc/baseservice/db/equipment_usage_info_dao.hpp create mode 100644 appsrc/service/calibration/h2o2_liquid_weight_sensor_calibration_service.cpp create mode 100644 appsrc/service/calibration/h2o2_liquid_weight_sensor_calibration_service.hpp create mode 100644 appsrc/service/equipment_usage_info_mgr_service.cpp create mode 100644 appsrc/service/equipment_usage_info_mgr_service.hpp create mode 100644 appsrc/service/setting/ext_setting_mgr_service.cpp create mode 100644 appsrc/service/setting/ext_setting_mgr_service.hpp diff --git a/README.md b/README.md index 0804b1a..7ea1b95 100644 --- a/README.md +++ b/README.md @@ -108,14 +108,17 @@ VERSION 2.0.0 VERSION 2.0.1 1. 修改当db文件损坏的时候,删除db文件 - 2. 增加DeviceExtSettingDB (存储一些设备高级配置信息),例如can设备地址,打印机串口地址,设备ID,frpc地址,frpc端口号,frpc设备名 + 2. 增加DeviceExtSettingDB (存储一些设备高级配置信息),例如can设备地址,打印机串口地址,设备ID OK 3. 增加EquipmentUsageInfoDB (存储设备的使用情况,出厂时间,设备使用时间) - 4. Calibrate校准信息存储数据库 - 5. 增加校准服务-重量校准服务 - 5. 增加校准业务逻辑 + 4. Calibrate校准信息存储数据库 OK + 5. 增加校准服务-重量校准服务(OK).... + 5. 增加校准业务逻辑(OK).... + + 4. 增加关机逻辑 OK + 5. 增加信息查看,增加信息删除 + + - 4. 增加关机逻辑 - 5. 增加信息查看,增加信息删除 命名规范(已命名,但不符合命名规范的服务名暂时不做修改) XXXXMgrService -> 直接操作DAO diff --git a/appsrc/appbase/appbase.hpp b/appsrc/appbase/appbase.hpp index 84f6837..aa91e75 100644 --- a/appsrc/appbase/appbase.hpp +++ b/appsrc/appbase/appbase.hpp @@ -15,3 +15,4 @@ #include "appbean/device_state.hpp" #include "appbase/appbean/h2o2_sensor_data_snapshot.hpp" #include "appbase/appbean/air_leak_test_mode.hpp" +#include "appbase/appbean/project_type_enum.hpp" \ No newline at end of file diff --git a/appsrc/appbase/appbean/project_type_enum.cpp b/appsrc/appbase/appbean/project_type_enum.cpp new file mode 100644 index 0000000..46cfd83 --- /dev/null +++ b/appsrc/appbase/appbean/project_type_enum.cpp @@ -0,0 +1,2 @@ +#include "project_type_enum.hpp" +ProjectTypeEnumZENUM_IMPL \ No newline at end of file diff --git a/appsrc/appbase/appbean/project_type_enum.hpp b/appsrc/appbase/appbean/project_type_enum.hpp new file mode 100644 index 0000000..cdeac03 --- /dev/null +++ b/appsrc/appbase/appbean/project_type_enum.hpp @@ -0,0 +1,13 @@ +#pragma once +#include "iflytop/core/components/zenum_template/zenum_template.hpp" + + + +#define ProjectTypeEnumZENUM_IMPL ZENUM_IMPL(ProjectTypeEnum, ProjectTypeEnumLIST) +#define ProjectTypeEnumLIST(type, marco) /**/ \ + marco(type, LargeSpaceDM) /**/ \ + marco(type, SmallSpaceDM) /**/ \ + marco(type, PipeDM) /**/ \ + marco(type, DrawBarDM) /**/ + +ZENUM_DECLAR(ProjectTypeEnum, ProjectTypeEnumLIST); diff --git a/appsrc/baseservice/baseservice.hpp b/appsrc/baseservice/baseservice.hpp index 36a4654..1c857ab 100644 --- a/appsrc/baseservice/baseservice.hpp +++ b/appsrc/baseservice/baseservice.hpp @@ -13,4 +13,13 @@ #include "udisk_mgr_service.hpp" // +#include "db/calibrate_info_dao.hpp" +#include "db/db_service.hpp" +#include "db/device_ext_setting_dao.hpp" +#include "db/equipment_usage_info_dao.hpp" +#include "db/formula_db_dao.hpp" +#include "db/setting_db_dao.hpp" +#include "db/user_behavior_des.hpp" +#include "db/user_behavior_record_dao.hpp" +#include "db/user_dao.hpp" #include "db/device_ext_setting_dao.hpp" \ No newline at end of file diff --git a/appsrc/baseservice/db/base/keyvaldbv2.cpp b/appsrc/baseservice/db/base/keyvaldbv2.cpp new file mode 100644 index 0000000..93174b9 --- /dev/null +++ b/appsrc/baseservice/db/base/keyvaldbv2.cpp @@ -0,0 +1,54 @@ +#include + +// +#include +#include + +#include "keyvaldbv2.hpp" + +// + +using namespace std; +using namespace iflytop; +using namespace iflytop::db; +using namespace sqlite_orm; +using namespace nlohmann; + +bool KeyValDBV2Dao::set(string key, string val) { + lock_guard lock(lock_); + + try { + auto all = storage.get_all(where(c(&KeyValDBV2::key) == key)); + if (all.size() == 0) { + storage.insert(KeyValDBV2{0, key, val}); + } else { + all[0].val = val; + storage.update(all[0]); + } + return true; + } catch (const std::exception& e) { + return false; + } +} +string KeyValDBV2Dao::get(string key, string defaultVal) { + lock_guard lock(lock_); + + + try { + auto all = storage.get_all(where(c(&KeyValDBV2::key) == key)); + if (all.size() == 0) { + return defaultVal; + } + return all[0].val; + } catch (const std::exception& e) { + return defaultVal; + } +} + +int KeyValDBV2Dao::get(string key, int defaultVal) { return atoi(get(key, to_string(defaultVal)).c_str()); } +double KeyValDBV2Dao::get(string key, double defaultVal) { return atof(get(key, to_string(defaultVal)).c_str()); } +bool KeyValDBV2Dao::get(string key, bool defaultVal) { return get(key, defaultVal ? string("true") : string("false")) == "true"; } + +bool KeyValDBV2Dao::set(string key, int val) { return set(key, to_string(val)); } +bool KeyValDBV2Dao::set(string key, double val) { return set(key, to_string(val)); } +bool KeyValDBV2Dao::set(string key, bool val) { return set(key, val ? string("true") : string("false")); } diff --git a/appsrc/baseservice/db/base/keyvaldbv2.hpp b/appsrc/baseservice/db/base/keyvaldbv2.hpp new file mode 100644 index 0000000..3fb4048 --- /dev/null +++ b/appsrc/baseservice/db/base/keyvaldbv2.hpp @@ -0,0 +1,91 @@ +#pragma once + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "appbase/appbasedep.hpp" + +/** + * @brief + * + */ + +namespace iflytop { +using namespace std; +using namespace std; +using namespace core; +using namespace nlohmann; + +/******************************************************************************* + * DB STRUCT * + *******************************************************************************/ + +namespace db { + +struct KeyValDBV2 { + int id; + string key; + string val; +}; + +#define ZDB_TABLE(dbname) \ + sqlite_orm::make_table(dbname, /**/ \ + sqlite_orm::make_column("id", &KeyValDBV2::id, sqlite_orm::primary_key().autoincrement()), /**/ \ + sqlite_orm::make_column("key", &KeyValDBV2::key), /**/ \ + sqlite_orm::make_column("val", &KeyValDBV2::val) /**/ /**/ \ + ) + +#define ZDB_MAKE_TABLE(dbpath, dbname) sqlite_orm::make_storage(dbpath, ZDB_TABLE(dbname)) + +} // namespace db +using namespace db; + +/******************************************************************************* + * DAO_IMPL * + *******************************************************************************/ + +class KeyValDBV2Dao { + THISCLASS(KeyValDBV2Dao); + + public: + recursive_mutex lock_; + bool inited = false; + + decltype(ZDB_MAKE_TABLE("", "")) storage; + + public: + KeyValDBV2Dao(string dbpath, string dbname) : storage(ZDB_MAKE_TABLE(dbpath, dbname)) {} + + public: + bool set(string key, string val); + bool set(string key, const char* val) { return set(key, string(val)); } + string get(string key, string defaultVal); + string get(string key, const char* defaultVal) { return get(key, string(defaultVal)).c_str(); } + + bool set(string key, int val); + bool set(string key, double val); + bool set(string key, bool val); + bool set(string key, float val) { return set(key, (double)val); } + + int get(string key, int defaultVal); + bool get(string key, bool defaultVal); + double get(string key, double defaultVal); + float get(string key, float defaultVal) { return get(key, (double)defaultVal); } +}; + +}; // namespace iflytop + +#undef ZDB_TABLE +#undef ZDB_MAKE_TABLE diff --git a/appsrc/baseservice/db/calibrate_info_dao.cpp b/appsrc/baseservice/db/calibrate_info_dao.cpp new file mode 100644 index 0000000..5847eaf --- /dev/null +++ b/appsrc/baseservice/db/calibrate_info_dao.cpp @@ -0,0 +1,49 @@ +#include + +// +#include +#include + +#include "appconfig/appconfig.hpp" +#include "calibrate_info_dao.hpp" +// + +using namespace std; +using namespace iflytop; +using namespace iflytop::db; +using namespace sqlite_orm; +using namespace nlohmann; + +CalibrationInfoDao::CalibrationInfoDao() : KeyValDBV2Dao("db/calibration_info", "calibration_info") {} + +void CalibrationInfoDao::initialize() { + mkdir("db", 0755); + + while (true) { + try { + logger->info("init {}", storage.filename()); + storage.sync_schema(); + break; + } catch (const std::exception& e) { + // 删除文件 + logger->error("init {} failed: {}", storage.filename(), e.what()); + system(fmt::format("rm -rf {}", storage.filename()).c_str()); + sleep(1); + } + } +} + +CalibrationInfo CalibrationInfoDao::getCalibrationInfo() { + CalibrationInfo info = {0}; + info.h2O2LiquidWeightSensorZeroBias = get("h2O2LiquidWeightSensorZeroBias", 0.0); + return info; +} +json CalibrationInfoDao::getCalibrationInfoJson() { + CalibrationInfo info = getCalibrationInfo(); + json j; + j["h2O2LiquidWeightSensorZeroBias"] = info.h2O2LiquidWeightSensorZeroBias; + return j; +} + +void CalibrationInfoDao::setH2O2LiquidWeightSensorZeroBias(float bias) { set("h2O2LiquidWeightSensorZeroBias", bias); } +float CalibrationInfoDao::getH2O2LiquidWeightSensorZeroBias() { return get("h2O2LiquidWeightSensorZeroBias", 0.0); } diff --git a/appsrc/baseservice/db/calibrate_info_dao.hpp b/appsrc/baseservice/db/calibrate_info_dao.hpp new file mode 100644 index 0000000..6a8e160 --- /dev/null +++ b/appsrc/baseservice/db/calibrate_info_dao.hpp @@ -0,0 +1,75 @@ +#pragma once + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "appbase/appbasedep.hpp" +#include "base/keyvaldbv2.hpp" + +/** + * @brief + * + */ + +namespace iflytop { +using namespace std; +using namespace std; +using namespace core; +using namespace nlohmann; + +/******************************************************************************* + * DB STRUCT * + *******************************************************************************/ + +namespace db { +typedef struct { + int id; + float h2O2LiquidWeightSensorZeroBias; // H2O2液体重量传感器零点偏差 +} CalibrationInfo; +} // namespace db +using namespace db; +/******************************************************************************* + * DAO_IMPL * + *******************************************************************************/ + +class CalibrationInfoDao : public KeyValDBV2Dao { + THISCLASS(CalibrationInfoDao); + + public: + CalibrationInfoDao(); + + static CalibrationInfoDao* ins() { + static CalibrationInfoDao instance; + if (!instance.inited) instance.initialize(); + instance.inited = true; + return &instance; + } + static void daoInit() { ins(); } + + public: + CalibrationInfo getCalibrationInfo(); + json getCalibrationInfoJson(); + + void setH2O2LiquidWeightSensorZeroBias(float bias); + float getH2O2LiquidWeightSensorZeroBias(); + + private: + void initialize(); +}; + +}; // namespace iflytop + +#undef ZDB_MAKE_TABLE +#undef TABLE_NAME diff --git a/appsrc/baseservice/db/device_ext_setting_dao.cpp b/appsrc/baseservice/db/device_ext_setting_dao.cpp index d17d7a7..54d9008 100644 --- a/appsrc/baseservice/db/device_ext_setting_dao.cpp +++ b/appsrc/baseservice/db/device_ext_setting_dao.cpp @@ -14,7 +14,8 @@ using namespace iflytop::db; using namespace sqlite_orm; using namespace nlohmann; -DeviceExtSettingDAO::DeviceExtSettingDAO(/* args */) {} +DeviceExtSettingDAO::DeviceExtSettingDAO(/* args */) : KeyValDBV2Dao("db/device_ext_setting.db", "device_ext_setting") {} + void DeviceExtSettingDAO::initialize() { mkdir("db", 0755); @@ -34,24 +35,19 @@ void DeviceExtSettingDAO::initialize() { DeviceExtSetting DeviceExtSettingDAO::getDeviceExtSetting() { // DeviceExtSetting setting; - setting.canBitrate = getAsInt("canBitrate", 500000); - setting.canIF = getAsString("canIF", "can0"); - setting.deviceId = getAsString("deviceId", ""); - setting.printerUartPath = getAsString("printerUartPath", "/dev/ttyS1"); - setting.dvalueCoefficient = getAsDouble("printerBaudrate", 2); - setting.testMode = getAsBool("testMode", false); + setting.canBitrate = get("canBitrate", 500000); + setting.canIF = get("canIF", "can0"); + setting.deviceId = get("deviceId", ""); + setting.printerUartPath = get("printerUartPath", "/dev/ttyS1"); + setting.dvalueCoefficient = get("printerBaudrate", 2); + setting.projectTypes = get("projectTypes", ""); + setting.h2o2SensorExpireTimeMonth = get("h2o2SensorExpireTimeMonth", 12); return setting; } json DeviceExtSettingDAO::getDeviceExtSettingAsJson() { DeviceExtSetting setting = getDeviceExtSetting(); - json j; - j["canBitrate"] = setting.canBitrate; - j["canIF"] = setting.canIF; - j["deviceId"] = setting.deviceId; - j["printerUartPath"] = setting.printerUartPath; - j["dvalueCoefficient"] = setting.dvalueCoefficient; - j["testMode"] = setting.testMode; + json j = setting; return j; } @@ -61,40 +57,4 @@ void DeviceExtSettingDAO::setCanIF(string canIF) { set("canIF", canIF); } void DeviceExtSettingDAO::setCanBitrate(int32_t canBitrate) { set("canBitrate", to_string(canBitrate)); } void DeviceExtSettingDAO::setPrinterUartPath(string printerUartPath) { set("printerUartPath", printerUartPath); } void DeviceExtSettingDAO::setDvalueCoefficient(float dvalueCoefficient) { set("dvalueCoefficient", to_string(dvalueCoefficient)); } -void DeviceExtSettingDAO::setTestMode(bool testMode) { set("testMode", testMode ? "true" : "false"); } - - - - -int DeviceExtSettingDAO::getAsInt(string key, int defaultVal) { return atoi(get(key, to_string(defaultVal)).c_str()); } -string DeviceExtSettingDAO::getAsString(string key, string defaultVal) { return get(key, defaultVal); } -bool DeviceExtSettingDAO::getAsBool(string key, bool defaultVal) { return get(key, defaultVal ? "true" : "false") == "true"; } -double DeviceExtSettingDAO::getAsDouble(string key, double defaultVal) { return atof(get(key, to_string(defaultVal)).c_str()); } - -bool DeviceExtSettingDAO::set(string key, string val) { - try { - auto all = storage.get_all(where(c(&DeviceExtSettingIerm::key) == key)); - if (all.size() == 0) { - storage.insert(DeviceExtSettingIerm{0, key, val}); - } else { - all[0].val = val; - storage.update(all[0]); - } - return true; - } catch (const std::exception& e) { - logger->error("set setting failed: {}", e.what()); - return false; - } -} -string DeviceExtSettingDAO::get(string key, string defaultVal) { - try { - auto all = storage.get_all(where(c(&DeviceExtSettingIerm::key) == key)); - if (all.size() == 0) { - return defaultVal; - } - return all[0].val; - } catch (const std::exception& e) { - logger->error("get setting failed: {}", e.what()); - return ""; - } -} +void DeviceExtSettingDAO::setH2o2SensorExpireTimeMonth(int32_t h2o2SensorExpireTimeMonth) { set("h2o2SensorExpireTimeMonth", to_string(h2o2SensorExpireTimeMonth)); } \ No newline at end of file diff --git a/appsrc/baseservice/db/device_ext_setting_dao.hpp b/appsrc/baseservice/db/device_ext_setting_dao.hpp index 5218a49..7085316 100644 --- a/appsrc/baseservice/db/device_ext_setting_dao.hpp +++ b/appsrc/baseservice/db/device_ext_setting_dao.hpp @@ -16,6 +16,7 @@ #include #include "appbase/appbasedep.hpp" +#include "base/keyvaldbv2.hpp" #include "user_behavior_des.hpp" /** @@ -35,35 +36,22 @@ using namespace nlohmann; namespace db { -struct DeviceExtSettingIerm { - int id; - string key; - string val; -}; - -typedef struct { - string deviceId; - string projectTypes; - - string canIF; - int32_t canBitrate; +class DeviceExtSetting { + public: + string deviceId; // 设备ID + string projectTypes; // 项目类型 - string printerUartPath; + string canIF; // can接口 + int32_t canBitrate; // can波特率 - float dvalueCoefficient; // 数值越小,相对消毒时间越长 + string printerUartPath; // 打印机串口路径 - bool testMode; -}DeviceExtSetting; + float dvalueCoefficient; // 消毒系数,数值越小,相对消毒时间越长 -#define ZTABLE_NAME "device_ext_setting" -#define ZDB_TABLE \ - sqlite_orm::make_table(ZTABLE_NAME, /**/ \ - sqlite_orm::make_column("id", &DeviceExtSettingIerm::id, sqlite_orm::primary_key().autoincrement()), /**/ \ - sqlite_orm::make_column("key", &DeviceExtSettingIerm::key), /**/ \ - sqlite_orm::make_column("val", &DeviceExtSettingIerm::val) /**/ /**/ \ - ) + int32_t h2o2SensorExpireTimeMonth; // h2o2传感器过期时间,单位月 -#define ZDB_MAKE_TABLE() sqlite_orm::make_storage("db/" ZTABLE_NAME ".db", ZDB_TABLE) + NLOHMANN_DEFINE_TYPE_INTRUSIVE(DeviceExtSetting, deviceId, projectTypes, canIF, canBitrate, printerUartPath, dvalueCoefficient,h2o2SensorExpireTimeMonth); +}; } // namespace db using namespace db; @@ -72,12 +60,8 @@ using namespace db; * DAO_IMPL * *******************************************************************************/ -class DeviceExtSettingDAO : public enable_shared_from_this { +class DeviceExtSettingDAO : public KeyValDBV2Dao { THISCLASS(DeviceExtSettingDAO); - recursive_mutex lock_; - bool inited = false; - - decltype(ZDB_MAKE_TABLE()) storage = ZDB_MAKE_TABLE(); public: DeviceExtSettingDAO(); @@ -104,17 +88,8 @@ class DeviceExtSettingDAO : public enable_shared_from_this void setCanBitrate(int32_t canBitrate); void setPrinterUartPath(string printerUartPath); void setDvalueCoefficient(float dvalueCoefficient); - void setTestMode(bool testMode); - - private: - bool set(string key, string val); - string get(string key, string defaultVal); - - private: - int getAsInt(string key, int defaultVal); - string getAsString(string key, string defaultVal); - bool getAsBool(string key, bool defaultVal); - double getAsDouble(string key, double defaultVal); + void setH2o2SensorExpireTimeMonth(int32_t h2o2SensorExpireTimeMonth); + // void setTestMode(bool testMode); }; }; // namespace iflytop diff --git a/appsrc/baseservice/db/equipment_usage_info_dao.cpp b/appsrc/baseservice/db/equipment_usage_info_dao.cpp new file mode 100644 index 0000000..6099105 --- /dev/null +++ b/appsrc/baseservice/db/equipment_usage_info_dao.cpp @@ -0,0 +1,58 @@ +#include + +// +#include +#include + +#include "appconfig/appconfig.hpp" +#include "equipment_usage_info_dao.hpp" +// + +using namespace std; +using namespace iflytop; +using namespace iflytop::db; +using namespace sqlite_orm; +using namespace nlohmann; + +EquipmentUsageInfoDao::EquipmentUsageInfoDao(/* args */) : KeyValDBV2Dao("db/equipment_usage_info", "equipment_usage_info") {} +void EquipmentUsageInfoDao::initialize() { + mkdir("db", 0755); + + while (true) { + try { + logger->info("init {}", storage.filename()); + storage.sync_schema(); + break; + } catch (const std::exception& e) { + // 删除文件 + logger->error("init {} failed: {}", storage.filename(), e.what()); + system(fmt::format("rm -rf {}", storage.filename()).c_str()); + sleep(1); + } + } +} + +EquipmentUsageInfo EquipmentUsageInfoDao::getEquipmentUsageInfo() { + EquipmentUsageInfo info = {0}; + info.deviceUsageTimeSumaryS = get("deviceUsageTimeSumaryS", 0); + info.deviceFactoryTime = get("deviceFactoryTime", ""); + info.h2o2SensorUsageTimeSumaryS = get("h2o2SensorUsageTimeSumaryS", 0); + info.timeSinceLastDeviceMaintenanceS = get("timeSinceLastDeviceMaintenanceS", 0); + return info; +} + +void EquipmentUsageInfoDao::setCurrentTimeAsFactoryTime() { + string factoryTime = tu_sys::fmt(zsystem_clock().now(), "%Y-%m-%d"); + logger->info("setCurrentTimeAsFactoryTime {}", factoryTime); + set("deviceFactoryTime", factoryTime); +} + +void EquipmentUsageInfoDao::resetHO2SensorUsageTimeSumaryS() { + logger->info("resetHO2SensorUsageTimeSumaryS"); + set("h2o2SensorUsageTimeSumaryS", 0); +} + +void EquipmentUsageInfoDao::resetTimeSinceLastDeviceMaintenanceS() { + logger->info("resetTimeSinceLastDeviceMaintenanceS"); + set("timeSinceLastDeviceMaintenanceS", 0); +} diff --git a/appsrc/baseservice/db/equipment_usage_info_dao.hpp b/appsrc/baseservice/db/equipment_usage_info_dao.hpp new file mode 100644 index 0000000..124c512 --- /dev/null +++ b/appsrc/baseservice/db/equipment_usage_info_dao.hpp @@ -0,0 +1,82 @@ +#pragma once + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "appbase/appbasedep.hpp" +#include "base/keyvaldbv2.hpp" +#include "user_behavior_des.hpp" + +/** + * @brief + * + */ + +namespace iflytop { +using namespace std; +using namespace std; +using namespace core; +using namespace nlohmann; + +/******************************************************************************* + * DB STRUCT * + *******************************************************************************/ + +namespace db { + +class EquipmentUsageInfo { + public: + // 设备使用时间汇总(秒) + uint32_t deviceUsageTimeSumaryS; + // 设备出厂时间 + string deviceFactoryTime; + // + uint32_t h2o2SensorUsageTimeSumaryS; + // + uint32_t timeSinceLastDeviceMaintenanceS; +}; + +} // namespace db +using namespace db; +/******************************************************************************* + * DAO_IMPL * + *******************************************************************************/ + +class EquipmentUsageInfoDao : public KeyValDBV2Dao { + THISCLASS(EquipmentUsageInfoDao); + + public: + EquipmentUsageInfoDao(); + + static EquipmentUsageInfoDao* ins() { + static EquipmentUsageInfoDao instance; + if (!instance.inited) instance.initialize(); + instance.inited = true; + return &instance; + } + static void daoInit() { ins(); } + + private: + void initialize(); + + public: + EquipmentUsageInfo getEquipmentUsageInfo(); + + void setCurrentTimeAsFactoryTime(); + void resetHO2SensorUsageTimeSumaryS(); + void resetTimeSinceLastDeviceMaintenanceS(); +}; + +}; // namespace iflytop diff --git a/appsrc/baseservice/front_msg_processer/front_msg_processer.cpp b/appsrc/baseservice/front_msg_processer/front_msg_processer.cpp index 99d3d8b..4b77262 100644 --- a/appsrc/baseservice/front_msg_processer/front_msg_processer.cpp +++ b/appsrc/baseservice/front_msg_processer/front_msg_processer.cpp @@ -72,7 +72,7 @@ void FrontMsgProcesser::processMsg(shared_ptr cxt) { string fn = className + "." + fnName; string param = cxt->cmd["params"].dump(); - logger->info("call: {}->({})", fn, param); + // logger->info("call: {}->({})", fn, param); if (fn == "FNScheduler.geFnList") { cxt->receipt["ackcode"] = 0; diff --git a/appsrc/baseservice/port/project_port.hpp b/appsrc/baseservice/port/project_port.hpp index b34adfa..a7bf3a9 100644 --- a/appsrc/baseservice/port/project_port.hpp +++ b/appsrc/baseservice/port/project_port.hpp @@ -55,6 +55,14 @@ class ProjectPort { bool isDrawBarDM() { return projectTypeInt == kdraw_bar_disinfection_box; } bool isDeviceTypeInited() { return deviceTypeInited; } + bool isBuildInPC() { +#ifdef BUILD_IN_PC + return true; +#else + return false; +#endif + } + bool isProjectType(int id) { return id == projectTypeInt; } bool isProjectType(int id0, int id1) { return id0 == projectTypeInt || id1 == projectTypeInt; } bool isProjectType(int id0, int id1, int id2) { return id0 == projectTypeInt || id1 == projectTypeInt || id2 == projectTypeInt; } diff --git a/appsrc/service/app/add_liquid_service.cpp b/appsrc/service/app/add_liquid_service.cpp index 1d58525..45518dc 100644 --- a/appsrc/service/app/add_liquid_service.cpp +++ b/appsrc/service/app/add_liquid_service.cpp @@ -4,7 +4,7 @@ using namespace iflytop; * @brief * */ -#define EMTPTY_LINE_WHEN_ADDING_DISINFECTANT_TIMES 200 // 30s +#define EMTPTY_LINE_WHEN_ADDING_DISINFECTANT_TIMES 150 // 15s void AddLiquidService::initialize() { logger->info("AddLiquidService initialize"); @@ -117,6 +117,7 @@ void AddLiquidService::addLiquidWork(int stopatg, bool& errorflag) { } m_dics->AddLiquidPump_stop(); + thisThread.sleepForMs(1500); // 等待泵停止 /** * @brief 选择排空管路通道 */ diff --git a/appsrc/service/app_core.cpp b/appsrc/service/app_core.cpp index a1268b2..89730b5 100644 --- a/appsrc/service/app_core.cpp +++ b/appsrc/service/app_core.cpp @@ -24,6 +24,10 @@ #include "hardware/warning_light_controler.hpp" // #include "baseservice/db/device_ext_setting_dao.hpp" +#include "calibration/h2o2_liquid_weight_sensor_calibration_service.hpp" +#include "setting/ext_setting_mgr_service.hpp" +#include "equipment_usage_info_mgr_service.hpp" + // DeviceExtSettingDAO using namespace iflytop; @@ -42,6 +46,7 @@ static void installEcodeInfo() { REG_ENUM_TYPE(AirLeakTestMode, AirLeakTestMode::getEnumStrList()); REG_ENUM_TYPE(UsrRoleType, UsrRoleType::getEnumStrList()); REG_ENUM_TYPE(AppEventType, AppEventType::getEnumStrList()); + REG_ENUM_TYPE(ProjectTypeEnum, ProjectTypeEnum::getEnumStrList()); AppEcodeInfoMgr::ins().regEcodeInfo(kerr_overtime, "通信超时"); AppEcodeInfoMgr::ins().regEcodeInfo(kerr_invalid_param, "非法参数"); @@ -103,12 +108,6 @@ static void installEcodeInfo() { AppEcodeInfoMgr::ins().regEcodeInfo(kappe_disinfection_state_is_wrong, "消毒状态错误"); AppEcodeInfoMgr::ins().regEcodeInfo(kappe_liquid_ctrl_reboot, "液路板复位"); AppEcodeInfoMgr::ins().regEcodeInfo(kappe_power_control_reboot, "功率板复位"); - - // AppEcodeInfoMgr::ins().regEcodeInfo(kerr_motor_reset_error, "电机复位错误"); - // AppEcodeInfoMgr::ins().regEcodeInfo(kerr_motor_subdevice_offline, "电机子设备离线"); - // AppEcodeInfoMgr::ins().regEcodeInfo(kerr_motor_driver_error, "电机驱动器错误"); - // AppEcodeInfoMgr::ins().regEcodeInfo(kerr_motor_undervoltage_error, "电机欠压错误"); - // AppEcodeInfoMgr::ins().regEcodeInfo(kerr_motor_unkown_error, "电机未知错误"); } void AppCore::initialize() { @@ -116,6 +115,8 @@ void AppCore::initialize() { // DBService DeviceExtSettingDAO::daoInit(); + CalibrationInfoDao::daoInit(); + EquipmentUsageInfoDao::daoInit(); UserDao::daoInit(); UserBehaviorRecordDao::daoInit(); FormulaDBDao::daoInit(); @@ -123,6 +124,9 @@ void AppCore::initialize() { // 设备兼容 ProjectPort::ins().initialize(); + if (ProjectPort::ins().isDrawBarDM()) { + // 在这里可以修改一些数据的默认值 + } // BUILD_AND_REG_SERRVICE(IflytopFrontEndService); @@ -143,7 +147,7 @@ void AppCore::initialize() { BUILD_AND_REG_SERRVICE(FrontEndRealtimeDisplayContentMgr); // 前端实时信息显示服务 // Device BUILD_AND_REG_SERRVICE(UartPrinter); - + GET_SERVICE(UartPrinter)->initialize(DeviceExtSettingDAO::ins()->getDeviceExtSetting().printerUartPath, "9600"); // ExtApi BUILD_AND_REG_SERRVICE(UserMgrService); @@ -159,6 +163,9 @@ void AppCore::initialize() { BUILD_AND_REG_SERRVICE(DrainLiquidService); BUILD_AND_REG_SERRVICE(DebugPageTestService); BUILD_AND_REG_SERRVICE(DeviceCheckPointCheckService); + BUILD_AND_REG_SERRVICE(H2O2LiquidWeightSensorCalibrationService); // H2O2液体重量传感器校准 + BUILD_AND_REG_SERRVICE(ExtSettingMgrService); + BUILD_AND_REG_SERRVICE(EquipmentUsageInfoMgrService); // GET_SERVICE(IflytopFrontEndService)->startListen(); diff --git a/appsrc/service/calibration/h2o2_liquid_weight_sensor_calibration_service.cpp b/appsrc/service/calibration/h2o2_liquid_weight_sensor_calibration_service.cpp new file mode 100644 index 0000000..6f787e8 --- /dev/null +++ b/appsrc/service/calibration/h2o2_liquid_weight_sensor_calibration_service.cpp @@ -0,0 +1,24 @@ +#include "h2o2_liquid_weight_sensor_calibration_service.hpp" + +using namespace iflytop; +using namespace std; +using namespace core; + +void H2O2LiquidWeightSensorCalibrationService::initialize() { + GET_TO_SERVICE(m_disinfectantWeightUpdateService); + REG_EXTFN_VOID(tare, void(void)); // 去皮 + REG_EXTFN_VOID(getWeight, float(void)); // 单位g +} +void H2O2LiquidWeightSensorCalibrationService::tare(shared_ptr cxt) { // + float weight = m_disinfectantWeightUpdateService->getWeight(); + CalibrationInfoDao::ins()->setH2O2LiquidWeightSensorZeroBias(weight); +} +void H2O2LiquidWeightSensorCalibrationService::getWeight(shared_ptr cxt) { + float weight = m_disinfectantWeightUpdateService->getWeight(); + cxt->rely["weight"] = weight; +} + +void H2O2LiquidWeightSensorCalibrationService::getBias(shared_ptr cxt) { + float bias = CalibrationInfoDao::ins()->getH2O2LiquidWeightSensorZeroBias(); + cxt->rely["bias"] = bias; +} diff --git a/appsrc/service/calibration/h2o2_liquid_weight_sensor_calibration_service.hpp b/appsrc/service/calibration/h2o2_liquid_weight_sensor_calibration_service.hpp new file mode 100644 index 0000000..30d8a97 --- /dev/null +++ b/appsrc/service/calibration/h2o2_liquid_weight_sensor_calibration_service.hpp @@ -0,0 +1,30 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +// +#include "baseservice/baseservice.hpp" +#include "service/hardware/disinfectant_weight_update_service.hpp" +namespace iflytop { +class H2O2LiquidWeightSensorCalibrationService : public enable_shared_from_this { + THISCLASS(H2O2LiquidWeightSensorCalibrationService); + + shared_ptr m_udiskMgr; + shared_ptr m_disinfectantWeightUpdateService; + + public: + void initialize(); + + private: + void tare(shared_ptr cxt); + void getWeight(shared_ptr cxt); + void getBias(shared_ptr cxt); +}; + +} // namespace iflytop diff --git a/appsrc/service/device_info_mgr_service.cpp b/appsrc/service/device_info_mgr_service.cpp index 9da0266..e0184e6 100644 --- a/appsrc/service/device_info_mgr_service.cpp +++ b/appsrc/service/device_info_mgr_service.cpp @@ -8,15 +8,14 @@ DeviceInfoMgrService::DeviceInfoMgrService() {} void DeviceInfoMgrService::initialize() { GET_TO_SERVICE(m_ds); - REG_EXTFN_VOID(getDeviceInfo, void()); } void DeviceInfoMgrService::getDeviceInfo(shared_ptr cxt) { // - auto& content = cxt->rely; content["projectType"] = PORT.getProjTypeString(); content["appVersion"] = VERSION; content["mircoVersion"] = "3.0.0"; // TODO:换成真实的版本信息 content["ip"] = "192.168.73.10"; + content["deviceId"] = DeviceExtSettingDAO::ins()->getDeviceExtSetting().deviceId; } diff --git a/appsrc/service/equipment_usage_info_mgr_service.cpp b/appsrc/service/equipment_usage_info_mgr_service.cpp new file mode 100644 index 0000000..2283f95 --- /dev/null +++ b/appsrc/service/equipment_usage_info_mgr_service.cpp @@ -0,0 +1,59 @@ +#include "equipment_usage_info_mgr_service.hpp" + +using namespace iflytop; +using namespace std; +using namespace core; + +void EquipmentUsageInfoMgrService::initialize() { + REG_EXTFN_VOID(showHelp, json(void)); // + REG_EXTFN_VOID(setCurTimeAsFactoryTime, void(void)); // + REG_EXTFN_VOID(resetHO2SensorUsageTimeSumaryS, float(void)); // + REG_EXTFN_VOID(resetTimeSinceLastDeviceMaintenanceS, void(void)); +} + +void EquipmentUsageInfoMgrService::getEquipmentUsageInfo(shared_ptr cxt) { // + auto var = EquipmentUsageInfoDao::ins()->getEquipmentUsageInfo(); + auto exsetting = DeviceExtSettingDAO::ins()->getDeviceExtSetting(); + + cxt->rely["equipmentUsageInfo"]["deviceUsageTimeSumaryS"] = var.deviceUsageTimeSumaryS; + cxt->rely["equipmentUsageInfo"]["deviceFactoryTime"] = var.deviceFactoryTime; + cxt->rely["equipmentUsageInfo"]["h2o2SensorUsageTimeSumaryS"] = var.h2o2SensorUsageTimeSumaryS; + cxt->rely["equipmentUsageInfo"]["h2o2SensorExpired"] = var.h2o2SensorUsageTimeSumaryS > (exsetting.h2o2SensorExpireTimeMonth * 30 * 24 * 60 * 60); +} + +void EquipmentUsageInfoMgrService::showHelp(shared_ptr cxt) { + json helpiterm; + helpiterm["name"] = "deviceUsageTimeSumaryS"; + helpiterm["chname"] = "设备使用时间(S)"; + helpiterm["desc"] = "设备使用时间(S)"; + cxt->rely["help"].push_back(helpiterm); + + helpiterm["name"] = "deviceFactoryTime"; + helpiterm["chname"] = "设备出厂时间"; + helpiterm["desc"] = "设备出厂时间"; + cxt->rely["help"].push_back(helpiterm); + + helpiterm["name"] = "h2o2SensorUsageTimeSumaryS"; + helpiterm["chname"] = "H2O2传感器使用时间(S)"; + helpiterm["desc"] = "H2O2传感器使用时间(S)"; + cxt->rely["help"].push_back(helpiterm); + + helpiterm["name"] = "h2o2SensorExpired"; + helpiterm["chname"] = "H2O2传感器是否过期"; + helpiterm["desc"] = "H2O2传感器是否过期"; + cxt->rely["help"].push_back(helpiterm); + + helpiterm["name"] = "setCurTimeAsFactoryTime"; + helpiterm["chname"] = "设置当前时间为出厂时间"; + helpiterm["desc"] = "设置当前时间为出厂时间"; + cxt->rely["help"].push_back(helpiterm); + + helpiterm["name"] = "resetHO2SensorUsageTimeSumaryS"; + helpiterm["chname"] = "重置H2O2传感器使用时间"; + helpiterm["desc"] = "重置H2O2传感器使用时间"; + cxt->rely["help"].push_back(helpiterm); +} + +void EquipmentUsageInfoMgrService::setCurTimeAsFactoryTime(shared_ptr cxt) { EquipmentUsageInfoDao::ins()->setCurrentTimeAsFactoryTime(); } +void EquipmentUsageInfoMgrService::resetHO2SensorUsageTimeSumaryS(shared_ptr cxt) { EquipmentUsageInfoDao::ins()->resetHO2SensorUsageTimeSumaryS(); } +void EquipmentUsageInfoMgrService::resetTimeSinceLastDeviceMaintenanceS(shared_ptr cxt) { EquipmentUsageInfoDao::ins()->resetTimeSinceLastDeviceMaintenanceS(); } diff --git a/appsrc/service/equipment_usage_info_mgr_service.hpp b/appsrc/service/equipment_usage_info_mgr_service.hpp new file mode 100644 index 0000000..8087917 --- /dev/null +++ b/appsrc/service/equipment_usage_info_mgr_service.hpp @@ -0,0 +1,29 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +// +#include "baseservice/baseservice.hpp" +#include "service/hardware/disinfectant_weight_update_service.hpp" +namespace iflytop { +class EquipmentUsageInfoMgrService : public enable_shared_from_this { + THISCLASS(EquipmentUsageInfoMgrService); + + public: + void initialize(); + + private: + void showHelp(shared_ptr cxt); + void getEquipmentUsageInfo(shared_ptr cxt); + void setCurTimeAsFactoryTime(shared_ptr cxt); + void resetHO2SensorUsageTimeSumaryS(shared_ptr cxt); + void resetTimeSinceLastDeviceMaintenanceS(shared_ptr cxt); +}; + +} // namespace iflytop diff --git a/appsrc/service/hardware/disinfectant_weight_update_service.cpp b/appsrc/service/hardware/disinfectant_weight_update_service.cpp index 0ef7980..2b61775 100644 --- a/appsrc/service/hardware/disinfectant_weight_update_service.cpp +++ b/appsrc/service/hardware/disinfectant_weight_update_service.cpp @@ -1,5 +1,7 @@ #include "disinfectant_weight_update_service.hpp" +#include "baseservice/baseservice.hpp" + using namespace iflytop; using namespace core; using namespace std; @@ -22,54 +24,75 @@ float DisinfectantWeightUpdateService::getWeightNoExpection() { } float DisinfectantWeightUpdateService::getWeight() { // - if (DS->isTestMode()) { - return 1000; - } - - if (PORT.isLageSpaceDM() || PORT.isSmallSpaceDM() || PORT.isPipeDM()) { - { - lock_guard lock(m_mutex); - if (m_errorFlag) { - throw m_e; - } + { + lock_guard lock(m_mutex); + if (m_errorFlag) { + throw m_e; } - return weightCache; - } else { - return 0; } + return netWeight; } void DisinfectantWeightUpdateService::updateWeightThread() { while (true) { - if (m_errorFlag) { - sleep(10); - { - lock_guard lock(m_mutex); - m_errorFlag = false; + if (PORT.isLageSpaceDM() || PORT.isSmallSpaceDM() || PORT.isPipeDM()) { + if (!DS->isTestMode()) { + setNetWeight(1000); } - continue; - } - // 读取压力传感器数据 - try { - float pa = deviceIoControlService->LiquidWeightPS_readPa(); - pa = filter.filter(pa); - pa = pa; + else if (PORT.isBuildInPC()) { + setNetWeight(1000); + } + + else if (!PORT.isDeviceTypeInited()) { + setNetWeight(0); + } - if (pa < 0) { - pa = 0; + else { + updateWeight(); } - float weight_g = ProjectPort::ins().pressurePa2VolumeG(pa); - weightCache = weight_g; - logger->debug("updateWeightThread: pa={}, weight_g={}", pa, weight_g); - } catch (const appexception& e) { + } else { + setNetWeight(0); + } + usleep(300 * 1000); + } +} +void DisinfectantWeightUpdateService::updateWeight() { + try { + float pa = deviceIoControlService->LiquidWeightPS_readPa(); + pa = filter.filter(pa); + + if (pa < 0) { + pa = 0; + } + + float weight_g = ProjectPort::ins().pressurePa2VolumeG(pa); + setNetWeight(weight_g); + m_errorFlag = false; + + logger->debug("updateWeightThread: pa={}, weight_g={}", pa, netWeight); + } catch (const appexception& e) { + if (!m_errorFlag) { { lock_guard lock(m_mutex); m_e = e; m_errorFlag = true; - AppEventBus::ins()->pushWarningPromptEvent(e); } + logger->error("updateWeight fail, {}", e.what()); + AppEventBus::ins()->pushWarningPromptEvent(e); } - usleep(1000 * 1000); + usleep(3000 * 1000); + } +} + +void DisinfectantWeightUpdateService::setNetWeight(float roughWeight) { + float bias = CalibrationInfoDao::ins()->getH2O2LiquidWeightSensorZeroBias(); + float netWeight = roughWeight - bias; + if (netWeight < 0) { + netWeight = 0; + } + { + lock_guard lock(m_mutex); + this->netWeight = netWeight; } -} \ No newline at end of file +} diff --git a/appsrc/service/hardware/disinfectant_weight_update_service.hpp b/appsrc/service/hardware/disinfectant_weight_update_service.hpp index 7a5fd5d..2a27e8a 100644 --- a/appsrc/service/hardware/disinfectant_weight_update_service.hpp +++ b/appsrc/service/hardware/disinfectant_weight_update_service.hpp @@ -40,6 +40,7 @@ class DisinfectantWeightUpdateService : public enable_shared_from_this cxt) { logger->info("shutdown"); - // sleep + system("sync"); this_thread::sleep_for(chrono::seconds(3)); return; } diff --git a/appsrc/service/setting/ext_setting_mgr_service.cpp b/appsrc/service/setting/ext_setting_mgr_service.cpp new file mode 100644 index 0000000..906453b --- /dev/null +++ b/appsrc/service/setting/ext_setting_mgr_service.cpp @@ -0,0 +1,81 @@ +#include "ext_setting_mgr_service.hpp" + +using namespace iflytop; +using namespace std; +using namespace core; + +void ExtSettingMgrService::initialize() { + GET_TO_SERVICE(m_disinfectantWeightUpdateService); + + REG_EXTFN_VOID(showHelp, json(void)); // 单位g + REG_EXTFN_VOID(getSetting, json(void)); // 单位g + REG_EXTFN(setDeviceId, void(string)); + REG_EXTFN(setProjectTypes, void(ProjectTypeEnum)); + REG_EXTFN(setCanIF, void(string)); + REG_EXTFN(setCanBitrate, void(int32_t)); + REG_EXTFN(setPrinterUartPath, void(string)); + REG_EXTFN(setDvalueCoefficient, void(float)); + REG_EXTFN_VOID(rebootDevice, void(void)); // + REG_EXTFN(setH2o2SensorExpireTimeMonth, void(int32_t)); + + // REG_EXTFN(setTestMode, void(bool)); +} + +void ExtSettingMgrService::showHelp(shared_ptr cxt) { + json helpinfo; + + helpinfo["name"] = "DeviceId"; + helpinfo["chname"] = "设备ID"; + helpinfo["desc"] = "设备ID,需要重启生效"; + cxt->rely["help"].push_back(helpinfo); + + helpinfo["name"] = "ProjectTypes"; + helpinfo["chname"] = "项目类型"; + helpinfo["desc"] = "项目类型,需要重启生效"; + cxt->rely["help"].push_back(helpinfo); + + helpinfo["name"] = "CanIF"; + helpinfo["chname"] = "CAN接口"; + helpinfo["desc"] = "CAN接口,需要重启生效"; + cxt->rely["help"].push_back(helpinfo); + + helpinfo["name"] = "CanBitrate"; + helpinfo["chname"] = "CAN波特率"; + helpinfo["desc"] = "CAN波特率,需要重启生效"; + cxt->rely["help"].push_back(helpinfo); + + helpinfo["name"] = "PrinterUartPath"; + helpinfo["chname"] = "打印机串口地址"; + helpinfo["desc"] = "打印机串口地址,需要重启生效"; + cxt->rely["help"].push_back(helpinfo); + + helpinfo["name"] = "DvalueCoefficient"; + helpinfo["chname"] = "D值系数"; + helpinfo["desc"] = "D值系数,需要重启生效"; + cxt->rely["help"].push_back(helpinfo); + + helpinfo["name"] = "H2o2SensorExpireTimeMonth"; + helpinfo["chname"] = "H2O2传感器有效期(月)"; + helpinfo["desc"] = "H2O2传感器有效期,需要重启生效"; + cxt->rely["help"].push_back(helpinfo); +} + +void ExtSettingMgrService::getSetting(shared_ptr cxt) { // + cxt->rely["extSettings"] = DeviceExtSettingDAO::ins()->getDeviceExtSettingAsJson(); +} + +void ExtSettingMgrService::setDeviceId(shared_ptr cxt, string deviceId) { DeviceExtSettingDAO::ins()->setDeviceId(deviceId); } + +void ExtSettingMgrService::setProjectTypes(shared_ptr cxt, ProjectTypeEnum projectTypes) { DeviceExtSettingDAO::ins()->setProjectTypes(projectTypes); } + +void ExtSettingMgrService::setCanIF(shared_ptr cxt, string canIF) { DeviceExtSettingDAO::ins()->setCanIF(canIF); } + +void ExtSettingMgrService::setCanBitrate(shared_ptr cxt, int32_t canBitrate) { DeviceExtSettingDAO::ins()->setCanBitrate(canBitrate); } + +void ExtSettingMgrService::setPrinterUartPath(shared_ptr cxt, string printerUartPath) { DeviceExtSettingDAO::ins()->setPrinterUartPath(printerUartPath); } + +void ExtSettingMgrService::setDvalueCoefficient(shared_ptr cxt, float dvalueCoefficient) { DeviceExtSettingDAO::ins()->setDvalueCoefficient(dvalueCoefficient); } + +void ExtSettingMgrService::setH2o2SensorExpireTimeMonth(shared_ptr cxt, int32_t h2o2SensorExpireTimeMonth) { DeviceExtSettingDAO::ins()->setH2o2SensorExpireTimeMonth(h2o2SensorExpireTimeMonth); } + +void ExtSettingMgrService::rebootDevice(shared_ptr cxt) { system("reboot"); } diff --git a/appsrc/service/setting/ext_setting_mgr_service.hpp b/appsrc/service/setting/ext_setting_mgr_service.hpp new file mode 100644 index 0000000..4033847 --- /dev/null +++ b/appsrc/service/setting/ext_setting_mgr_service.hpp @@ -0,0 +1,40 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +// +#include "baseservice/baseservice.hpp" +#include "service/hardware/disinfectant_weight_update_service.hpp" +namespace iflytop { +class ExtSettingMgrService : public enable_shared_from_this { + THISCLASS(ExtSettingMgrService); + + shared_ptr m_udiskMgr; + shared_ptr m_disinfectantWeightUpdateService; + + public: + void initialize(); + + private: + void getSetting(shared_ptr cxt); + void showHelp(shared_ptr cxt); + + void setDeviceId(shared_ptr cxt, string deviceId); + void setProjectTypes(shared_ptr cxt, ProjectTypeEnum projectTypes); + void setCanIF(shared_ptr cxt, string canIF); + void setCanBitrate(shared_ptr cxt, int32_t canBitrate); + void setPrinterUartPath(shared_ptr cxt, string printerUartPath); + void setDvalueCoefficient(shared_ptr cxt, float dvalueCoefficient); + void setH2o2SensorExpireTimeMonth(shared_ptr cxt, int32_t h2o2SensorExpireTimeMonth); + // void setTestMode(shared_ptr cxt, bool testMode); + + void rebootDevice(shared_ptr cxt); +}; + +} // namespace iflytop