From 51af98fb4727811e91527e48bbe047d737e2dddd Mon Sep 17 00:00:00 2001 From: zhaohe Date: Fri, 6 Dec 2024 13:19:08 +0800 Subject: [PATCH] update --- README.md | 7 ++++++ .../iflytop/core/spdlogfactory/logger_factory.cpp | 3 +++ appsrc/appbase/appbase.hpp | 3 ++- appsrc/appbase/appbean/device_type_enum.cpp | 2 ++ appsrc/appbase/appbean/device_type_enum.hpp | 11 ++++++++ appsrc/appconfig/basic/zappversion.hpp | 2 +- appsrc/baseservice/db/device_ext_setting_dao.cpp | 4 ++- appsrc/baseservice/db/device_ext_setting_dao.hpp | 4 ++- appsrc/service/app_core.cpp | 2 ++ ...o2_liquid_weight_sensor_calibration_service.cpp | 11 +++++--- appsrc/service/device_info_mgr_service.cpp | 1 + .../disinfectant_weight_update_service.cpp | 17 ++++++++----- .../disinfectant_weight_update_service.hpp | 9 ++++--- appsrc/service/setting/ext_setting_mgr_service.cpp | 29 ++++++++++++++++++++-- appsrc/service/setting/ext_setting_mgr_service.hpp | 4 +++ 15 files changed, 89 insertions(+), 20 deletions(-) create mode 100644 appsrc/appbase/appbean/device_type_enum.cpp create mode 100644 appsrc/appbase/appbean/device_type_enum.hpp diff --git a/README.md b/README.md index 02d779f..bd37ff6 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,13 @@ VERSION 2.0.1 4. 支持液体重量传感器校准接口。 5. 支持设备类型 UI 修改。 +VERSION 2.0.2 + 1. 添加毛重,净重 + +VERSION 2.0.3 + 1. 增加设备信息配置接口 + + TODO: 1. 设备使用时间维护(UI接口已经准备好,考虑是否使用文件袋放在设备中的方案) 2. 升级方案 diff --git a/appdep/iflytop/core/spdlogfactory/logger_factory.cpp b/appdep/iflytop/core/spdlogfactory/logger_factory.cpp index 08ac66c..1770cba 100644 --- a/appdep/iflytop/core/spdlogfactory/logger_factory.cpp +++ b/appdep/iflytop/core/spdlogfactory/logger_factory.cpp @@ -145,6 +145,9 @@ static string default_config = R"( "name": "infologger", "type": "rotating_file_sink_mt", "filename": "logs/infolog.log", + "max_file_size":10485760, + "max_files":3, + "rotate_on_open":true, "level" : 2 }, { diff --git a/appsrc/appbase/appbase.hpp b/appsrc/appbase/appbase.hpp index aa91e75..5230288 100644 --- a/appsrc/appbase/appbase.hpp +++ b/appsrc/appbase/appbase.hpp @@ -15,4 +15,5 @@ #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 +#include "appbase/appbean/project_type_enum.hpp" +#include "appbase/appbean/device_type_enum.hpp" \ No newline at end of file diff --git a/appsrc/appbase/appbean/device_type_enum.cpp b/appsrc/appbase/appbean/device_type_enum.cpp new file mode 100644 index 0000000..7dc0504 --- /dev/null +++ b/appsrc/appbase/appbean/device_type_enum.cpp @@ -0,0 +1,2 @@ +#include "device_type_enum.hpp" +DeviceTypeZENUM_IMPL \ No newline at end of file diff --git a/appsrc/appbase/appbean/device_type_enum.hpp b/appsrc/appbase/appbean/device_type_enum.hpp new file mode 100644 index 0000000..4604c48 --- /dev/null +++ b/appsrc/appbase/appbean/device_type_enum.hpp @@ -0,0 +1,11 @@ +#pragma once +#include "iflytop/core/components/zenum_template/zenum_template.hpp" + +#define DeviceTypeZENUM_IMPL ZENUM_IMPL(DeviceType, DeviceTypeLIST) +#define DeviceTypeLIST(type, marco) /**/ \ + marco(type, DT_600N) /*大空间*/ \ + marco(type, DT_300N) /*小空间*/ \ + marco(type, DT_300W) /*管道式*/ \ + marco(type, DT_100N) /*拉杆箱*/ + +ZENUM_DECLAR(DeviceType, DeviceTypeLIST); diff --git a/appsrc/appconfig/basic/zappversion.hpp b/appsrc/appconfig/basic/zappversion.hpp index 1d09d6c..01266aa 100644 --- a/appsrc/appconfig/basic/zappversion.hpp +++ b/appsrc/appconfig/basic/zappversion.hpp @@ -1,3 +1,3 @@ #pragma once -#define VERSION "2.0.2" +#define VERSION "2.0.3" #define PROJECT_NAME "TRANSMIT_DM" \ No newline at end of file diff --git a/appsrc/baseservice/db/device_ext_setting_dao.cpp b/appsrc/baseservice/db/device_ext_setting_dao.cpp index 54d9008..d14eb34 100644 --- a/appsrc/baseservice/db/device_ext_setting_dao.cpp +++ b/appsrc/baseservice/db/device_ext_setting_dao.cpp @@ -42,6 +42,7 @@ DeviceExtSetting DeviceExtSettingDAO::getDeviceExtSetting() { // setting.dvalueCoefficient = get("printerBaudrate", 2); setting.projectTypes = get("projectTypes", ""); setting.h2o2SensorExpireTimeMonth = get("h2o2SensorExpireTimeMonth", 12); + setting.deviceType = get("deviceType", ""); return setting; } @@ -57,4 +58,5 @@ 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::setH2o2SensorExpireTimeMonth(int32_t h2o2SensorExpireTimeMonth) { set("h2o2SensorExpireTimeMonth", to_string(h2o2SensorExpireTimeMonth)); } \ No newline at end of file +void DeviceExtSettingDAO::setH2o2SensorExpireTimeMonth(int32_t h2o2SensorExpireTimeMonth) { set("h2o2SensorExpireTimeMonth", to_string(h2o2SensorExpireTimeMonth)); } +void DeviceExtSettingDAO::setDeviceType(string deviceType) { set("deviceType", deviceType); } diff --git a/appsrc/baseservice/db/device_ext_setting_dao.hpp b/appsrc/baseservice/db/device_ext_setting_dao.hpp index abe5391..2d546be 100644 --- a/appsrc/baseservice/db/device_ext_setting_dao.hpp +++ b/appsrc/baseservice/db/device_ext_setting_dao.hpp @@ -39,6 +39,7 @@ class DeviceExtSetting { public: string deviceId; // 设备ID string projectTypes; // 项目类型 + string deviceType; // 设备类型,只做展示用,不做业务逻辑 string canIF; // can接口 int32_t canBitrate; // can波特率 @@ -49,7 +50,7 @@ class DeviceExtSetting { int32_t h2o2SensorExpireTimeMonth; // h2o2传感器过期时间,单位月 - NLOHMANN_DEFINE_TYPE_INTRUSIVE(DeviceExtSetting, deviceId, projectTypes, canIF, canBitrate, printerUartPath, dvalueCoefficient,h2o2SensorExpireTimeMonth); + NLOHMANN_DEFINE_TYPE_INTRUSIVE(DeviceExtSetting, deviceId, projectTypes, deviceType, canIF, canBitrate, printerUartPath, dvalueCoefficient, h2o2SensorExpireTimeMonth); }; } // namespace db @@ -88,6 +89,7 @@ class DeviceExtSettingDAO : public KeyValDBV2Dao { void setPrinterUartPath(string printerUartPath); void setDvalueCoefficient(float dvalueCoefficient); void setH2o2SensorExpireTimeMonth(int32_t h2o2SensorExpireTimeMonth); + void setDeviceType(string deviceType); // void setTestMode(bool testMode); }; diff --git a/appsrc/service/app_core.cpp b/appsrc/service/app_core.cpp index 89730b5..fb4ac64 100644 --- a/appsrc/service/app_core.cpp +++ b/appsrc/service/app_core.cpp @@ -47,6 +47,8 @@ static void installEcodeInfo() { REG_ENUM_TYPE(UsrRoleType, UsrRoleType::getEnumStrList()); REG_ENUM_TYPE(AppEventType, AppEventType::getEnumStrList()); REG_ENUM_TYPE(ProjectTypeEnum, ProjectTypeEnum::getEnumStrList()); + REG_ENUM_TYPE(DeviceType, DeviceType::getEnumStrList()); + AppEcodeInfoMgr::ins().regEcodeInfo(kerr_overtime, "通信超时"); AppEcodeInfoMgr::ins().regEcodeInfo(kerr_invalid_param, "非法参数"); diff --git a/appsrc/service/calibration/h2o2_liquid_weight_sensor_calibration_service.cpp b/appsrc/service/calibration/h2o2_liquid_weight_sensor_calibration_service.cpp index 6f787e8..2b34ebc 100644 --- a/appsrc/service/calibration/h2o2_liquid_weight_sensor_calibration_service.cpp +++ b/appsrc/service/calibration/h2o2_liquid_weight_sensor_calibration_service.cpp @@ -6,16 +6,19 @@ using namespace core; void H2O2LiquidWeightSensorCalibrationService::initialize() { GET_TO_SERVICE(m_disinfectantWeightUpdateService); - REG_EXTFN_VOID(tare, void(void)); // 去皮 - REG_EXTFN_VOID(getWeight, float(void)); // 单位g + REG_EXTFN_VOID(tare, void(void)); // 去皮 + REG_EXTFN_VOID(getWeight, json(void)); // + REG_EXTFN_VOID(getBias, json(void)); // } 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; + float weight = m_disinfectantWeightUpdateService->getWeight(); + float roughWeight = m_disinfectantWeightUpdateService->getRoughWeight(); + cxt->rely["weight"] = weight; + cxt->rely["roughWeight"] = roughWeight; } void H2O2LiquidWeightSensorCalibrationService::getBias(shared_ptr cxt) { diff --git a/appsrc/service/device_info_mgr_service.cpp b/appsrc/service/device_info_mgr_service.cpp index e0184e6..3b7dd86 100644 --- a/appsrc/service/device_info_mgr_service.cpp +++ b/appsrc/service/device_info_mgr_service.cpp @@ -15,6 +15,7 @@ void DeviceInfoMgrService::getDeviceInfo(shared_ptr cxt) { / auto& content = cxt->rely; content["projectType"] = PORT.getProjTypeString(); content["appVersion"] = VERSION; + content["deviceType"] = DeviceExtSettingDAO::ins()->getDeviceExtSetting().deviceType; content["mircoVersion"] = "3.0.0"; // TODO:换成真实的版本信息 content["ip"] = "192.168.73.10"; content["deviceId"] = DeviceExtSettingDAO::ins()->getDeviceExtSetting().deviceId; diff --git a/appsrc/service/hardware/disinfectant_weight_update_service.cpp b/appsrc/service/hardware/disinfectant_weight_update_service.cpp index 2b61775..2303a8e 100644 --- a/appsrc/service/hardware/disinfectant_weight_update_service.cpp +++ b/appsrc/service/hardware/disinfectant_weight_update_service.cpp @@ -30,8 +30,14 @@ float DisinfectantWeightUpdateService::getWeight() { // throw m_e; } } - return netWeight; + return m_netWeight; } + +float DisinfectantWeightUpdateService::getRoughWeight() { + lock_guard lock(m_mutex); + return m_roughWeight; +} + void DisinfectantWeightUpdateService::updateWeightThread() { while (true) { if (PORT.isLageSpaceDM() || PORT.isSmallSpaceDM() || PORT.isPipeDM()) { @@ -70,7 +76,7 @@ void DisinfectantWeightUpdateService::updateWeight() { setNetWeight(weight_g); m_errorFlag = false; - logger->debug("updateWeightThread: pa={}, weight_g={}", pa, netWeight); + logger->debug("updateWeightThread: pa={}, weight_g={}", pa, m_netWeight); } catch (const appexception& e) { if (!m_errorFlag) { { @@ -88,11 +94,10 @@ void DisinfectantWeightUpdateService::updateWeight() { void DisinfectantWeightUpdateService::setNetWeight(float roughWeight) { float bias = CalibrationInfoDao::ins()->getH2O2LiquidWeightSensorZeroBias(); float netWeight = roughWeight - bias; - if (netWeight < 0) { - netWeight = 0; - } + if (netWeight < 0) netWeight = 0; { lock_guard lock(m_mutex); - this->netWeight = netWeight; + m_roughWeight = roughWeight; + this->m_netWeight = netWeight; } } diff --git a/appsrc/service/hardware/disinfectant_weight_update_service.hpp b/appsrc/service/hardware/disinfectant_weight_update_service.hpp index 2a27e8a..61c3d6e 100644 --- a/appsrc/service/hardware/disinfectant_weight_update_service.hpp +++ b/appsrc/service/hardware/disinfectant_weight_update_service.hpp @@ -39,8 +39,8 @@ class DisinfectantWeightUpdateService : public enable_shared_from_this deviceIoControlService; MovingAverageFilter filter = {5}; - float weightCache = 0; - float netWeight = 0; + float m_roughWeight = 0; + float m_netWeight = 0; bool m_errorFlag = false; appexception m_e; @@ -50,12 +50,13 @@ class DisinfectantWeightUpdateService : public enable_shared_from_this cxt) { void ExtSettingMgrService::getSetting(shared_ptr cxt) { // cxt->rely["extSettings"] = DeviceExtSettingDAO::ins()->getDeviceExtSettingAsJson(); } +void ExtSettingMgrService::setDeviceType(shared_ptr cxt, DeviceType deviceType) { DeviceExtSettingDAO::ins()->setDeviceType(deviceType); } void ExtSettingMgrService::setDeviceId(shared_ptr cxt, string deviceId) { DeviceExtSettingDAO::ins()->setDeviceId(deviceId); } @@ -79,3 +83,24 @@ void ExtSettingMgrService::setDvalueCoefficient(shared_ptr cx void ExtSettingMgrService::setH2o2SensorExpireTimeMonth(shared_ptr cxt, int32_t h2o2SensorExpireTimeMonth) { DeviceExtSettingDAO::ins()->setH2o2SensorExpireTimeMonth(h2o2SensorExpireTimeMonth); } void ExtSettingMgrService::rebootDevice(shared_ptr cxt) { system("reboot"); } + +void ExtSettingMgrService::setDeviceInfo(shared_ptr cxt, DeviceType type, int year, int month, int day, int index) { + string deviceIdPrefix; + if (type == DeviceType::DT_600N) { + DeviceExtSettingDAO::ins()->setProjectTypes(ProjectTypeEnum::LargeSpaceDM); + deviceIdPrefix = "DT-600N"; + } else if (type == DeviceType::DT_300N) { + DeviceExtSettingDAO::ins()->setProjectTypes(ProjectTypeEnum::SmallSpaceDM); + deviceIdPrefix = "DT-300N"; + } else if (type == DeviceType::DT_300W) { + DeviceExtSettingDAO::ins()->setProjectTypes(ProjectTypeEnum::PipeDM); + deviceIdPrefix = "DT-300W"; + } else if (type == DeviceType::DT_100N) { + DeviceExtSettingDAO::ins()->setProjectTypes(ProjectTypeEnum::DrawBarDM); + deviceIdPrefix = "DT-100N"; + } + + DeviceExtSettingDAO::ins()->setDeviceType(type); + DeviceExtSettingDAO::ins()->setDeviceId(fmt::format("{}-{:0>2d}{:0>2d}{:0>2d}{:0>3d}", deviceIdPrefix, year, month, day, index)); + cxt->rely["extSettings"] = DeviceExtSettingDAO::ins()->getDeviceExtSettingAsJson(); +} diff --git a/appsrc/service/setting/ext_setting_mgr_service.hpp b/appsrc/service/setting/ext_setting_mgr_service.hpp index 4033847..c1f2ccc 100644 --- a/appsrc/service/setting/ext_setting_mgr_service.hpp +++ b/appsrc/service/setting/ext_setting_mgr_service.hpp @@ -25,8 +25,12 @@ class ExtSettingMgrService : public enable_shared_from_this cxt); void showHelp(shared_ptr cxt); + void setDeviceInfo(shared_ptr cxt, DeviceType type, int year, int month, int day, int index); + void setDeviceId(shared_ptr cxt, string deviceId); + void setProjectTypes(shared_ptr cxt, ProjectTypeEnum projectTypes); + void setDeviceType(shared_ptr cxt, DeviceType deviceType); void setCanIF(shared_ptr cxt, string canIF); void setCanBitrate(shared_ptr cxt, int32_t canBitrate); void setPrinterUartPath(shared_ptr cxt, string printerUartPath);