diff --git a/src/db/db_service.cpp b/src/db/db_service.cpp index 63af958..a2e3b90 100644 --- a/src/db/db_service.cpp +++ b/src/db/db_service.cpp @@ -141,10 +141,10 @@ id setting_name setting_name_ch val_upper_limit val_lower_limi storage.insert(Setting{5, "max_humidity", "允许消毒最大湿度", 0, 100, 0, 90}); if (storage.get_all(where(c(&Setting::id) == 6)).size() == 0) - storage.insert(Setting{6, "drainage_pump_speed", "排液蠕动泵转速", 0, 350, 0, 300}); + storage.insert(Setting{6, "drainage_pump_speed", "排液蠕动泵转速", 0, 40, 0, 40});//g/min if (storage.get_all(where(c(&Setting::id) == 7)).size() == 0) - storage.insert(Setting{7, "injection_pump_speed", "喷射蠕动泵转速", 0, 350, 0, 300}); + storage.insert(Setting{7, "injection_pump_speed", "喷射蠕动泵转速", 0, 40, 0, 40}); //g/min if (storage.get_all(where(c(&Setting::id) == 8)).size() == 0) // storage.insert(Setting{8, "pre_heat_time_s", "预热时间", 0, 600, 0, 120}); diff --git a/src/main_control_service.cpp b/src/main_control_service.cpp index a30c6e1..5718333 100644 --- a/src/main_control_service.cpp +++ b/src/main_control_service.cpp @@ -140,8 +140,8 @@ json MainControlService::createSensorDataJson() { report["heatingStrip"]["io2"] = m_deviceIoControlService->heatingStrip_getio2(); report["heatingStrip"]["currentVal"] = m_deviceIoControlService->heatingStrip_getcurrentValue(); - report["sprinklerPump"] = m_deviceIoControlService->sprayLiquidPump_getRPM(); - report["chargingPump"] = m_deviceIoControlService->getChargingPump_PumpRPM(); + report["sprinklerPumpRPM"] = m_deviceIoControlService->sprayLiquidPump_getRPM(); + report["chargingPumpRPM"] = m_deviceIoControlService->getChargingPump_PumpRPM(); report["waterImmersionSensor1"] = m_deviceIoControlService->getWaterImmersionSensor1(); report["waterImmersionSensor2"] = m_deviceIoControlService->getWaterImmersionSensor2(); @@ -228,6 +228,17 @@ void MainControlService::processFrontEndMessage(weak_ptr webSocket, j return; } + if (cmdstr == "shutdown") { + int delayms = jsonGet(cmd["delayms"]); + logger->info("shutdown {} ms", delayms); + m_autoshutdownThread.reset(new Thread("autoShutdown", [delayms]() { + ThisThread thisThread; + thisThread.sleepForMs(delayms); + system("shutdown -h now"); + })); + return; + } + if (cmdstr == "updateDate") { #if 0 { @@ -278,15 +289,15 @@ void MainControlService::processFrontEndMessage(weak_ptr webSocket, j } if (cmdstr == "startDisinfection") { - int loglevel = jsonGet(cmd["loglevel"]); + int loglevel = jsonGet(cmd["loglevel"]); - int injection_pump_speed = m_dbService->getSettingVal("injection_pump_speed"); - int stoped_gs = m_dbService->getSettingVal("stoped_gs"); - int continued_gs = m_dbService->getSettingVal("continued_gs"); - int stoped_satur = m_dbService->getSettingVal("stoped_satur"); - int continued_satur = m_dbService->getSettingVal("continued_satur"); - int stoped_humi = m_dbService->getSettingVal("stoped_humi"); - int continued_humi = m_dbService->getSettingVal("continued_humi"); + int injection_pump_speed = m_dbService->getSettingVal("injection_pump_speed"); + int stoped_gs = m_dbService->getSettingVal("stoped_gs"); + int continued_gs = m_dbService->getSettingVal("continued_gs"); + int stoped_satur = m_dbService->getSettingVal("stoped_satur"); + int continued_satur = m_dbService->getSettingVal("continued_satur"); + int stoped_humi = m_dbService->getSettingVal("stoped_humi"); + int continued_humi = m_dbService->getSettingVal("continued_humi"); m_disinfectionCtrlService->startDisinfection(loglevel, // injection_pump_speed, // @@ -394,6 +405,46 @@ void MainControlService::processFrontEndMessage(weak_ptr webSocket, j return; } +// // 排液泵 +// void drainingPump_open(); +// void drainingPump_close(); +// // 充液泵 +// void replenishingFluidsPump_open(); +// void replenishingFluidsPump_close(); +// // 喷液泵 +// void sprayLiquidPump_open(int gpm); +// void sprayLiquidPump_close(); +// int sprayLiquidPump_getState(); +// int sprayLiquidPump_getRPM(); +// int sprayLiquidPump_getGPM(); +#if 1 + if (cmdstr == "test_sprayLiquidPumpCtrl") { + int ctrl = jsonGet(cmd["ctrl"]); + int speed = jsonGet(cmd["speed"]); + if (ctrl == 1) { + m_deviceIoControlService->sprayLiquidPump_open_for_test(speed); + } else if (ctrl == -1) { + m_deviceIoControlService->sprayLiquidPump_open_for_test(-speed); + } else { + m_deviceIoControlService->sprayLiquidPump_close(); + } + return; + } + + if (cmdstr == "test_replenishingFluidsPumpCtrl") { + int ctrl = jsonGet(cmd["ctrl"]); + int speed = jsonGet(cmd["speed"]); + if (ctrl == 1) { + m_deviceIoControlService->replenishingFluidsPump_open_for_test(speed); + } else if (ctrl == -1) { + m_deviceIoControlService->replenishingFluidsPump_open_for_test(-speed); + } else { + m_deviceIoControlService->replenishingFluidsPump_close_for_test(); + } + return; + } +#endif + /******************************************************************************* * 执行测试指令 * *******************************************************************************/ diff --git a/src/service/device_io_control_service.cpp b/src/service/device_io_control_service.cpp index d31cd76..0401d8a 100644 --- a/src/service/device_io_control_service.cpp +++ b/src/service/device_io_control_service.cpp @@ -170,6 +170,21 @@ void DeviceIoControlService::replenishingFluidsPump_close() { logger->info("replenishingFluidsPump_close"); m_zcanHost->pumpctrl_c1004(1, 100, 0, 1, 20); } + +void DeviceIoControlService::replenishingFluidsPump_open_for_test(int gpm) { + logger->info("replenishingFluidsPump_open_for_test {}", gpm); + int speed = gpm * 7.5; + if (speed > 300) { + speed = 300; + } else if (speed < -300) { + speed = -300; + } + m_zcanHost->pumpctrl_c1004(1, 100, speed, 1, 20); +} +void DeviceIoControlService::replenishingFluidsPump_close_for_test() { + logger->info("replenishingFluidsPump_close_for_test"); + m_zcanHost->pumpctrl_c1004(1, 100, 0, 1, 20); +} /******************************************************************************* * sprayLiquidPump * *******************************************************************************/ @@ -178,6 +193,8 @@ void DeviceIoControlService::sprayLiquidPump_open(int gpm) { int speed = gpm * 7.5; if (speed > 300) { speed = 300; + } else if (speed < 0) { + speed = 0; } m_zcanHost->pumpctrl_c1004(2, 100, speed, 1, 15); } @@ -185,6 +202,22 @@ void DeviceIoControlService::sprayLiquidPump_close() { logger->info("sprayLiquidPump_close"); m_zcanHost->pumpctrl_c1004(2, 100, 0, 1, 15); } + +void DeviceIoControlService::sprayLiquidPump_open_for_test(int gpm) { + logger->info("sprayLiquidPump_open"); + int speed = gpm * 7.5; + if (speed > 300) { + speed = 300; + } else if (speed < -300) { + speed = -300; + } + m_zcanHost->pumpctrl_c1004(2, 100, speed, 1, 15); +} +void DeviceIoControlService::sprayLiquidPump_close_for_test() { + logger->info("sprayLiquidPump_close"); + m_zcanHost->pumpctrl_c1004(2, 100, 0, 1, 15); +} + int DeviceIoControlService::sprayLiquidPump_getRPM() { return m_zcanHost->pumpctrl_c1004_get_speed_cache(2); } int DeviceIoControlService::sprayLiquidPump_getGPM() { return sprayLiquidPump_getRPM() / 7.5; } diff --git a/src/service/device_io_control_service.hpp b/src/service/device_io_control_service.hpp index 98dca59..23917e6 100644 --- a/src/service/device_io_control_service.hpp +++ b/src/service/device_io_control_service.hpp @@ -104,6 +104,10 @@ class DeviceIoControlService : public enable_shared_from_thisheatingStrip_getstate(), ds->airBlower_getstate(), ds->airCompressor_getstate(), ds->sprayLiquidPump_getGPM(), // - m_deviceIoControlService->getDisinfectantVolume_g(), // + // m_deviceIoControlService->getDisinfectantVolume_g(), // m_context.m_remaintime)); } @@ -366,6 +366,7 @@ void DisinfectionCtrlService::processDisinfectionState(DisinfectionContext& cont void DisinfectionCtrlService::disinfectionLoop(bool& breakflag) { // logger->info("disinfection running {} {}s preheatFlag:{}", m_context.m_disinfectionID, m_context.m_remaintime, m_context.m_preheatFlag); m_context.m_remaintime--; + bool forcelog = false; if (m_context.m_remaintime < 0) { m_context.m_remaintime = 0; } @@ -392,6 +393,7 @@ void DisinfectionCtrlService::disinfectionLoop(bool& breakflag) { // if (m_context.m_remaintime <= 0) { m_context.m_remaintime = 0; + m_context.m_loglevel = m_context.m_targetLoglevel; logger->info("disinfection finished {},but waitting for h2o2 to safe", m_context.m_disinfectionID); m_deviceIoControlService->sprayLiquidPump_close(); usleep(1000 * 1000); @@ -399,6 +401,7 @@ void DisinfectionCtrlService::disinfectionLoop(bool& breakflag) { usleep(1000 * 1000); m_deviceIoControlService->heartingPlate_setPower(false); m_context.m_state = kwait_for_h2o2_down; + forcelog = true; } } else if (m_context.m_state == kwait_for_h2o2_down) { @@ -409,13 +412,14 @@ void DisinfectionCtrlService::disinfectionLoop(bool& breakflag) { if (m_context.h2o2data.min_h2o2 < 1) { logger->info("h2o2 concentration to safe value"); breakflag = true; + forcelog = true; m_context.m_state = kfinished; } } else { ZCHECK(false, "state error"); } - if (breakflag || zsteady_clock().elapsedTimeS(m_context.m_lastlogTp) > DVALUE_COMPUTEPERIOD_TIME_S) { + if (forcelog || zsteady_clock().elapsedTimeS(m_context.m_lastlogTp) > DVALUE_COMPUTEPERIOD_TIME_S) { m_context.m_lastlogTp = zsteady_clock().now(); dumpDisinfectionLogs(m_context); dumpDisinfectionLogsToCSV(m_context); @@ -445,7 +449,7 @@ void DisinfectionCtrlService::changeDisinfectionParameter(int injection_pump_spe continued_humi); } -void DisinfectionCtrlService::startDisinfection(int loglevel, // +void DisinfectionCtrlService::startDisinfection(int loglevel, // int injection_pump_speed, // int stoped_gs, // int continued_gs, // @@ -483,7 +487,7 @@ void DisinfectionCtrlService::startDisinfection(int loglevel, // // } -int DisinfectionCtrlService::getDisinfectionWorkState() { return m_disinfectionWorkState; } +int DisinfectionCtrlService::getDisinfectionWorkState() { return m_context.m_state; } void DisinfectionCtrlService::stopDisinfection() { lock_guard lock(lock_); @@ -491,12 +495,19 @@ void DisinfectionCtrlService::stopDisinfection() { m_disinfectionThread->join(); m_disinfectionThread = nullptr; } + m_context.m_state = kfinished; m_disinfectionWorkState = 0; } int32_t DisinfectionCtrlService::getEstimatedRemainingTimeS() { lock_guard lock(lock_); - return m_context.m_remaintime; + if (m_context.m_state == kpreheat) { + return getPreHeatRaminTimeS(); + } else if (m_context.m_state == kdisinfection || m_context.m_state == kdisinfection_take_a_break) { + return m_context.m_remaintime; + } else { + return 0; + } } int32_t DisinfectionCtrlService::getPreHeatRaminTimeS() { lock_guard lock(lock_); diff --git a/src/service/disinfection_ctl_service.hpp b/src/service/disinfection_ctl_service.hpp index 7cf7b4b..09e6c7a 100644 --- a/src/service/disinfection_ctl_service.hpp +++ b/src/service/disinfection_ctl_service.hpp @@ -40,12 +40,12 @@ class DisinfectionCtrlService : public enable_shared_from_this