From 730e0f3a47098771c78f786d8cfe64e2445dc6e6 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sun, 22 Oct 2023 22:21:07 +0800 Subject: [PATCH] update --- README.md | 11 ++++++ src/db/db_service.hpp | 2 +- src/service/device_io_control_service.cpp | 59 +++++++++++++++++++++++-------- src/service/disinfection_ctl_service.cpp | 6 ++-- 4 files changed, 60 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index e05e1e6..f32e34c 100644 --- a/README.md +++ b/README.md @@ -71,4 +71,15 @@ https://www.sqlite.org/docs.html 量程:-1~4kPa 4 kPa=407.888 毫米水柱 传感器测量精度:0.407888 毫米水柱 +``` + +``` +1. 支持调速 +2. 液体容量进行滤波 +3. 打印日志去掉小数点 + +1. 加泵写死,速度不可修改,550g/min +2. 注射泵速率限制在30g/min + + ``` \ No newline at end of file diff --git a/src/db/db_service.hpp b/src/db/db_service.hpp index fc2c962..74b4da7 100644 --- a/src/db/db_service.hpp +++ b/src/db/db_service.hpp @@ -25,7 +25,7 @@ #define FORMULA_DB "formula.db" #define USER_BEHAVIOR_RECORD_DB "user_behavior_record.db" -#define USER_BEHAVIOR_RECORD_DB_MAX_RECORDS 1000 +#define USER_BEHAVIOR_RECORD_DB_MAX_RECORDS 30000 /** * @brief * diff --git a/src/service/device_io_control_service.cpp b/src/service/device_io_control_service.cpp index faa2604..1b9bf59 100644 --- a/src/service/device_io_control_service.cpp +++ b/src/service/device_io_control_service.cpp @@ -13,8 +13,8 @@ using namespace std; -通断电磁阀 3 PC7 5 #endif -#define GPM_TO_SPEED(gpm) (gpm * 3.07) -#define SPEED_TO_GPM(speed) (speed / 3.07) +#define GPM_TO_SPEED(gpm) (gpm * 10) +#define SPEED_TO_GPM(speed) (speed / 10) DeviceIoControlService::DeviceIoControlService() {} void DeviceIoControlService::initialize() { GET_TO_SERVICE(m_zcanHost); } @@ -164,9 +164,10 @@ void DeviceIoControlService::drainingPump_close() { logger->info("drainingPump_close"); m_zcanHost->pumpctrl_c1004(1, 100, 0, 1, 20); } - +#define replenishingFluidsPump_GPM2RPM(gpm) (gpm / 2) void DeviceIoControlService::replenishingFluidsPump_open() { logger->info("replenishingFluidsPump_open"); + // 600g/m 300RPM m_zcanHost->pumpctrl_c1004(1, 100, 300, 1, 20); } void DeviceIoControlService::replenishingFluidsPump_close() { @@ -176,7 +177,7 @@ void DeviceIoControlService::replenishingFluidsPump_close() { void DeviceIoControlService::replenishingFluidsPump_open_for_test(int gpm) { logger->info("replenishingFluidsPump_open_for_test {}", gpm); - int speed = GPM_TO_SPEED(gpm); + int speed = replenishingFluidsPump_GPM2RPM(gpm); if (speed > 300) { speed = 300; } else if (speed < -300) { @@ -192,10 +193,10 @@ void DeviceIoControlService::replenishingFluidsPump_close_for_test() { * sprayLiquidPump * *******************************************************************************/ void DeviceIoControlService::sprayLiquidPump_open(int gpm) { - logger->info("sprayLiquidPump_open"); + logger->info("sprayLiquidPump_open {}", gpm); int speed = GPM_TO_SPEED(gpm); - if (speed > 300) { - speed = 300; + if (speed > 400) { + speed = 400; } else if (speed < 0) { speed = 0; } @@ -207,12 +208,12 @@ void DeviceIoControlService::sprayLiquidPump_close() { } void DeviceIoControlService::sprayLiquidPump_open_for_test(int gpm) { - logger->info("sprayLiquidPump_open"); + logger->info("sprayLiquidPump_open {}", gpm); int speed = GPM_TO_SPEED(gpm); - if (speed > 300) { - speed = 300; - } else if (speed < -300) { - speed = -300; + if (speed > 400) { + speed = 400; + } else if (speed < -400) { + speed = -400; } m_zcanHost->pumpctrl_c1004(2, 100, speed, 1, 15); } @@ -232,6 +233,34 @@ int DeviceIoControlService::sprayLiquidPump_getState() { // /******************************************************************************* * SensorState * *******************************************************************************/ + +static int filter(int data) { + static list q; + q.push_back(data); + + if (q.size() > 50) { + q.pop_front(); + } + // 中值滤波 + int datacache[51]; + int ndata = 0; + for (auto& var : q) { + datacache[ndata] = var; + ndata++; + } + + for (int i = 0; i < ndata; i++) { + for (int j = i + 1; j < ndata; j++) { + if (datacache[i] > datacache[j]) { + int temp = datacache[i]; + datacache[i] = datacache[j]; + datacache[j] = temp; + } + } + } + return datacache[ndata / 2]; +} + int DeviceIoControlService::getDisinfectantVolume_g() { // kpa; lock_guard lock(lock_); @@ -243,6 +272,8 @@ int DeviceIoControlService::getDisinfectantVolume_g() { } else { g -= 450; } + g = filter(g); + // logger->info("g {}", g); return g; } int DeviceIoControlService::getPressureSensorData(int index) { @@ -275,9 +306,9 @@ DeviceIoControlService::h2o2sensor_data_t DeviceIoControlService::getH2O2SenSorD data.saturation = m_hpp272_data_1.h2o_h2o2_rs / 100; /** - * @brief + * @brief * TODO:传感器未初始化完成时,除了温度外,读取到的数据都是小于零,这里做了一个简单的处理,后续需要修改 - * + * */ if (data.h2o2 < 0) { data.h2o2 = 0; diff --git a/src/service/disinfection_ctl_service.cpp b/src/service/disinfection_ctl_service.cpp index 67516cc..cbe2c41 100644 --- a/src/service/disinfection_ctl_service.cpp +++ b/src/service/disinfection_ctl_service.cpp @@ -250,8 +250,8 @@ void DisinfectionCtrlService::dumpDisinfectionLogsToCSV(DisinfectionContext& con "{},{},{},{}," // // "{},{},{},{}," // // "{},{},{},{}," // - "{:.2f},{:.2f},{:.2f}," // - "{},{},{},{}," // + "{},{},{}," // + "{},{},{},{}," // // "{},{},{},{}," // "{}," // "{}\n" // @@ -260,7 +260,7 @@ void DisinfectionCtrlService::dumpDisinfectionLogsToCSV(DisinfectionContext& con sensors[0].h2o2, sensors[0].temp, sensors[0].humid, sensors[0].saturation, // // sensors[1].h2o2, sensors[1].temp, sensors[1].humid, sensors[1].saturation, // // sensors[2].h2o2, sensors[2].temp, sensors[2].humid, sensors[2].saturation, // - dvalue, m_context.m_nowLoglevel, m_context.m_targetLoglevel, // + (int32_t)dvalue, (int32_t)m_context.m_nowLoglevel, (int32_t)m_context.m_targetLoglevel, // ds->heatingStrip_getstate(), ds->airBlower_getstate(), ds->airCompressor_getstate(), ds->sprayLiquidPump_getGPM(), // m_deviceIoControlService->getDisinfectantVolume_g(), // formattimeS(remaintime)));