From 16c2f55e7406c5e0a080966727e2d8cc9380ff7a Mon Sep 17 00:00:00 2001 From: zhaohe Date: Thu, 29 Feb 2024 17:20:48 +0800 Subject: [PATCH] =?UTF-8?q?Dvalue=E7=B3=BB=E6=95=B0=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/configs/gconfig.hpp | 3 +- src/service/disinfection_ctl_service.cpp | 33 ++----------------- src/service/disinfection_ctl_service.hpp | 38 ++++++++++++---------- src/utils/dvalue_computer.cpp | 54 ++++++++++++++++++++++++++++++++ src/utils/dvalue_computer.hpp | 16 ++++++++++ 5 files changed, 96 insertions(+), 48 deletions(-) create mode 100644 src/utils/dvalue_computer.cpp create mode 100644 src/utils/dvalue_computer.hpp diff --git a/src/configs/gconfig.hpp b/src/configs/gconfig.hpp index f5c3ae6..fa98bbe 100644 --- a/src/configs/gconfig.hpp +++ b/src/configs/gconfig.hpp @@ -19,7 +19,8 @@ marco(string /* */, iflytopSubDeviceCanIFName, "can0") /*子设备Can设备名称*/ \ marco(int32_t /* */, iflytopSubDeviceCanBitrate, 500000) /*子设备Can设备波特率*/ \ marco(string /* */, pipettingRobotCanIFName, "can1") /*移液臂Can设备名称*/ \ - marco(int32_t /* */, pipettingRobotCanBitrate, 500000) /*移液臂Can设备波特率*/ + marco(int32_t /* */, pipettingRobotCanBitrate, 500000) /*移液臂Can设备波特率*/ \ + marco(float /* */, dvalueCoefficient, 1) /*数值越小,相对消毒时间越长*/ configTemplateDEFILE_CONFIG_SERVICE2( // GConfig, // diff --git a/src/service/disinfection_ctl_service.cpp b/src/service/disinfection_ctl_service.cpp index cbe2c41..3443fc1 100644 --- a/src/service/disinfection_ctl_service.cpp +++ b/src/service/disinfection_ctl_service.cpp @@ -47,6 +47,7 @@ void DisinfectionCtrlService::initialize() { m_deviceIoControlService->heartingPlate_setPower(false); m_deviceIoControlService->airBlower_setState(false); m_deviceIoControlService->airCompressor_setState(false); + m_dvalueComputer.initialize(); } static string getTime() { @@ -88,36 +89,8 @@ static bool zfeq(float a, float b, float eps = 0.01) { } return false; } -float DisinfectionCtrlService::getDisinfectionDValue(float ppm) { - /** - * @brief - * - * D值的计算公式是根据美国竞品的数据记录计算得来的 - * - * 浓度小于150时,y=-0.5269X+97.868 - * 浓度大于150时,y=-0.1405X+40.369 - */ - - if (zfeq(ppm, 0)) { - return -1; - } - - float dvalue = 0; - - if (ppm < 150) { - dvalue = -0.5251 * ppm + 98.154; - } else if (ppm >= 150 && ppm < 240) { - dvalue = -0.125 * ppm + 38.913; - } else if (ppm >= 240) { - // 240 -> 8.913 - // 1400 -> 2 - // y = -0.00603x + 10.4472 - dvalue = -0.00596 * ppm + 10.3434; - } - if (dvalue < 2) { - dvalue = 2; - } - return dvalue; +float DisinfectionCtrlService::getDisinfectionDValue(float ppm) { // + return m_dvalueComputer.computeDValue(ppm); } float DisinfectionCtrlService::computeNowLogLevel(DisinfectionContext& context) { float dvalue = context.dvalue; diff --git a/src/service/disinfection_ctl_service.hpp b/src/service/disinfection_ctl_service.hpp index 4066b58..28980c4 100644 --- a/src/service/disinfection_ctl_service.hpp +++ b/src/service/disinfection_ctl_service.hpp @@ -19,6 +19,7 @@ #include "iflytop/components/zcanreceiver/zcanhost.hpp" #include "iflytop/core/core.hpp" #include "service/device_io_control_service.hpp" +#include "utils/dvalue_computer.hpp" #include "zservice_container/zservice_container.hpp" /** * @brief @@ -54,6 +55,8 @@ class DisinfectionCtrlService : public enable_shared_from_this m_dbService; shared_ptr m_disinfectionLogsManager; + DValueComputer m_dvalueComputer; + recursive_mutex lock_; int m_disinfectionWorkState = 0; @@ -96,7 +99,8 @@ class DisinfectionCtrlService : public enable_shared_from_this csvlogger; }; -public: + + public: DisinfectionContext m_context; public: @@ -159,23 +163,23 @@ public: private: float getDisinfectionDValue(float ppm); - void initContext(DisinfectionContext& context, // - int loglevel, // - float injection_pump_speed, // - float stoped_gs, // - float continued_gs, // - float stoped_satur, // - float continued_satur, // - float stoped_humi, // - float continued_humi // - ); - void computeRemainTime(DisinfectionContext& context); + void initContext(DisinfectionContext& context, // + int loglevel, // + float injection_pump_speed, // + float stoped_gs, // + float continued_gs, // + float stoped_satur, // + float continued_satur, // + float stoped_humi, // + float continued_humi // + ); + void computeRemainTime(DisinfectionContext& context); float computeNowLogLevel(DisinfectionContext& context); - void processPreheatState(DisinfectionContext& context); - void processDisinfectionState(DisinfectionContext& context); - void dumpDisinfectionLogs(DisinfectionContext& context); - void dumpDisinfectionLogsToCSV(DisinfectionContext& context); - void finishDisinfection(DisinfectionContext& context); + void processPreheatState(DisinfectionContext& context); + void processDisinfectionState(DisinfectionContext& context); + void dumpDisinfectionLogs(DisinfectionContext& context); + void dumpDisinfectionLogsToCSV(DisinfectionContext& context); + void finishDisinfection(DisinfectionContext& context); void disinfectionLoop(bool& breakflag); }; diff --git a/src/utils/dvalue_computer.cpp b/src/utils/dvalue_computer.cpp new file mode 100644 index 0000000..3952a11 --- /dev/null +++ b/src/utils/dvalue_computer.cpp @@ -0,0 +1,54 @@ +#include "dvalue_computer.hpp" + +#include + +#include "zservice_container/zservice_container.hpp" +using namespace iflytop; +using namespace std; + +static bool zfeq(float a, float b, float eps = 0.01) { + if (fabs(a - b) < eps) { + return true; + } + return false; +} + +void DValueComputer::initialize() { + /** + * @brief + */ + + m_config = GET_SERVICE(GConfig); +} + +float DValueComputer::computeDValue(float h2o2ppm) { + /** + * @brief + * + * D值的计算公式是根据美国竞品的数据记录计算得来的 + * + * 浓度小于150时,y=-0.5269X+97.868 + * 浓度大于150时,y=-0.1405X+40.369 + */ + + if (zfeq(h2o2ppm, 0)) { + return -1; + } + + float dvalue = 0; + + if (h2o2ppm < 150) { + // + dvalue = -0.5251 * h2o2ppm * m_config->get_dvalueCoefficient() + 98.154; + } else if (h2o2ppm >= 150 && h2o2ppm < 240) { + // + dvalue = -0.125 * h2o2ppm * m_config->get_dvalueCoefficient() + 38.913; + } else if (h2o2ppm >= 240) { + // + dvalue = -0.00596 * h2o2ppm * m_config->get_dvalueCoefficient() + 10.3434; + } + if (dvalue < 2) { + dvalue = 2; + } + return dvalue; +} diff --git a/src/utils/dvalue_computer.hpp b/src/utils/dvalue_computer.hpp new file mode 100644 index 0000000..e2c5418 --- /dev/null +++ b/src/utils/dvalue_computer.hpp @@ -0,0 +1,16 @@ + +#pragma once +#include + +#include "configs/gconfig.hpp" +namespace iflytop { + +class DValueComputer { + ENABLE_LOGGER(DValueComputer); + shared_ptr m_config; + + public: + void initialize(); + float computeDValue(float h2o2ppm); +}; +} // namespace iflytop \ No newline at end of file