|
|
@ -1,4 +1,5 @@ |
|
|
|
#include "device_io_control_service.hpp"
|
|
|
|
|
|
|
|
#include "iflytop/components/uart_printer/uart_printer.hpp"
|
|
|
|
#include "iflytoplinuxsdk/src/iflytop/components/ziconv.hpp"
|
|
|
|
using namespace iflytop; |
|
|
@ -14,18 +15,68 @@ using namespace std; |
|
|
|
-通断电磁阀 3 PC7 5 |
|
|
|
#endif
|
|
|
|
|
|
|
|
#define GPM_TO_SPEED(gpm) (gpm * 10)
|
|
|
|
#define SPEED_TO_GPM(speed) (speed / 10)
|
|
|
|
#define GPM_TO_SPEED(gpm) (gpm * 14.7)
|
|
|
|
#define SPEED_TO_GPM(speed) (speed / 14.7 + 0.5)
|
|
|
|
|
|
|
|
DeviceIoControlService::DeviceIoControlService() {} |
|
|
|
void DeviceIoControlService::initialize() { GET_TO_SERVICE(m_zcanHost); } |
|
|
|
void DeviceIoControlService::initialize() { |
|
|
|
GET_TO_SERVICE(m_zcanHost); |
|
|
|
GET_TO_SERVICE(m_config); |
|
|
|
} |
|
|
|
|
|
|
|
void DeviceIoControlService::updateDisinfectantVolumeSample(float _pa) { |
|
|
|
float pa = _pa - 100; // 100当容器中没有液体时的压强
|
|
|
|
if (pa < 0) pa = 0; |
|
|
|
float g = m_volumeConvertor.pressurePa2VolumeG(_pa) * m_config->get_disinfectantWeightCorrectionFactor(); |
|
|
|
m_disinfectantVolumeSample_g = m_DisinfectantWeightFilter.filter(g); |
|
|
|
// logger->info("pa:{} _pa:{}", _pa, _pa,g);
|
|
|
|
logger->info("g:{} pa:{} _pa:{}", g, pa, _pa); |
|
|
|
} |
|
|
|
|
|
|
|
void DeviceIoControlService::startScan() { |
|
|
|
m_workThread.reset(new Thread("DeviceIoControlService", [this]() { |
|
|
|
m_PressureSensorDataSampleThread.reset(new Thread("PressureSensorDataSampleThread", [this]() { |
|
|
|
ThisThread thisThread; |
|
|
|
uint32_t i = 0; |
|
|
|
|
|
|
|
int readpressuresensor_id = 1; |
|
|
|
while (!thisThread.getExitFlag()) { |
|
|
|
/* code */ |
|
|
|
ZCanHost::huacheng_pressure_sensor_read_c1005_t sdata; |
|
|
|
if (m_zcanHost->huacheng_pressure_sensor_read_c1005(1, sdata) == 0) { |
|
|
|
lock_guard<recursive_mutex> lock(lock_); |
|
|
|
m_pressure_sensor_data[1] = sdata; |
|
|
|
} |
|
|
|
|
|
|
|
thisThread.sleepForMs(100); |
|
|
|
|
|
|
|
if (m_zcanHost->huacheng_pressure_sensor_read_c1005(2, sdata) == 0) { |
|
|
|
lock_guard<recursive_mutex> lock(lock_); |
|
|
|
m_pressure_sensor_data[2] = sdata; |
|
|
|
} |
|
|
|
|
|
|
|
thisThread.sleepForMs(100); |
|
|
|
|
|
|
|
if (m_zcanHost->huacheng_pressure_sensor_read_c1005(3, sdata) == 0) { |
|
|
|
lock_guard<recursive_mutex> lock(lock_); |
|
|
|
m_pressure_sensor_data[3] = sdata; |
|
|
|
} |
|
|
|
|
|
|
|
thisThread.sleepForMs(100); |
|
|
|
|
|
|
|
if (m_zcanHost->huacheng_pressure_sensor_read_c1005(4, sdata) == 0) { |
|
|
|
lock_guard<recursive_mutex> lock(lock_); |
|
|
|
m_pressure_sensor_data[4] = sdata; |
|
|
|
} |
|
|
|
|
|
|
|
thisThread.sleepForMs(100); |
|
|
|
|
|
|
|
{ updateDisinfectantVolumeSample(m_pressure_sensor_data[1].value / 1.0 /*pa*/); } |
|
|
|
} |
|
|
|
})); |
|
|
|
|
|
|
|
m_workThread.reset(new Thread("DeviceIoControlService", [this]() { |
|
|
|
ThisThread thisThread; |
|
|
|
uint32_t i = 0; |
|
|
|
int error = 0; |
|
|
|
int readpressuresensor_id = 1; |
|
|
|
|
|
|
|
while (!thisThread.getExitFlag()) { |
|
|
|
/* code */ |
|
|
@ -47,56 +98,22 @@ void DeviceIoControlService::startScan() { |
|
|
|
lock_guard<recursive_mutex> lock(lock_); |
|
|
|
m_adc_2 = adcv; |
|
|
|
} |
|
|
|
// m_zcanHost->readadc(1, m_adc_1);
|
|
|
|
// m_zcanHost->readadc(2, m_adc_2);
|
|
|
|
// m_zcanHost->readadc(3, m_adc_3);
|
|
|
|
// m_zcanHost->readadc(4, m_adc_4);
|
|
|
|
// m_zcanHost->readadc(5, m_adc_5);
|
|
|
|
} |
|
|
|
|
|
|
|
if (i % 3000 == 0) { |
|
|
|
if (i % 3000 == 0 && error < 10) { |
|
|
|
// m_hpp272_data_1
|
|
|
|
ZCanHost::hpp272_data_t m_hpp272_data_1_cache; |
|
|
|
int suc = m_zcanHost->hpp272_read_c1000(1, m_hpp272_data_1_cache); |
|
|
|
if (suc == 0) { |
|
|
|
lock_guard<recursive_mutex> lock(lock_); |
|
|
|
m_hpp272_data_1 = m_hpp272_data_1_cache; |
|
|
|
error = 0; |
|
|
|
} else { |
|
|
|
error++; |
|
|
|
if (error == 10) { |
|
|
|
logger->error("hpp272_read_c1000 error:{}", suc); |
|
|
|
} |
|
|
|
} |
|
|
|
// hydrogen_peroxide_volume
|
|
|
|
// water_vapor_saturation_pressure_h2o_h2o2
|
|
|
|
// logger->info("---------hpp272_read_c1000---------");
|
|
|
|
// logger->info("hydrogen_peroxide_volume :{}", m_hpp272_data_1.hydrogen_peroxide_volume);
|
|
|
|
// logger->info("h2o_h2o2_rs :{}", m_hpp272_data_1.h2o_h2o2_rs);
|
|
|
|
// logger->info("temperature1 :{}", m_hpp272_data_1.temperature1);
|
|
|
|
// logger->info("relative_humidity :{}", m_hpp272_data_1.relative_humidity);
|
|
|
|
// logger->info("absolute_hydrogen_peroxide :{}", m_hpp272_data_1.absolute_hydrogen_peroxide);
|
|
|
|
// logger->info("h2o_h2o2dew_point_temperature :{}", m_hpp272_data_1.h2o_h2o2dew_point_temperature);
|
|
|
|
// logger->info("reserved1 :{}", m_hpp272_data_1.reserved1);
|
|
|
|
// logger->info("water_volume :{}", m_hpp272_data_1.water_volume);
|
|
|
|
// logger->info("water_vapor_pressure :{}", m_hpp272_data_1.water_vapor_pressure);
|
|
|
|
// logger->info("absolute_humidity :{}", m_hpp272_data_1.absolute_humidity);
|
|
|
|
// logger->info("water_vapor_saturation_pressure_h2o:{}", m_hpp272_data_1.water_vapor_saturation_pressure_h2o);
|
|
|
|
// logger->info("temperature2 :{}", m_hpp272_data_1.temperature2);
|
|
|
|
// logger->info("h2o2_vapor_pressure :{}", m_hpp272_data_1.h2o2_vapor_pressure);
|
|
|
|
// logger->info("water_vapor_saturation_pressure_h2o_h2o2:{}", m_hpp272_data_1.water_vapor_saturation_pressure_h2o_h2o2);
|
|
|
|
// logger->info("");
|
|
|
|
} |
|
|
|
|
|
|
|
if (i % 300 == 0) { |
|
|
|
if (readpressuresensor_id == 5) { |
|
|
|
readpressuresensor_id = 1; |
|
|
|
} |
|
|
|
ZCanHost::huacheng_pressure_sensor_read_c1005_t sdata; |
|
|
|
if (m_zcanHost->huacheng_pressure_sensor_read_c1005(readpressuresensor_id, sdata) == 0) { |
|
|
|
lock_guard<recursive_mutex> lock(lock_); |
|
|
|
m_pressure_sensor_data[readpressuresensor_id] = sdata; |
|
|
|
} |
|
|
|
readpressuresensor_id++; |
|
|
|
} |
|
|
|
|
|
|
|
if (i % 100 == 0) { |
|
|
|
// m_zcanHost->readio(1, m_waterImmersionSensor1);
|
|
|
|
// m_zcanHost->readio(2, m_waterImmersionSensor2);
|
|
|
|
} |
|
|
|
} |
|
|
|
})); |
|
|
@ -325,19 +342,21 @@ static int filter(int data) { |
|
|
|
} |
|
|
|
|
|
|
|
int DeviceIoControlService::getDisinfectantVolume_g() { |
|
|
|
// kpa;
|
|
|
|
lock_guard<recursive_mutex> lock(lock_); |
|
|
|
return m_disinfectantVolumeSample_g; |
|
|
|
|
|
|
|
float kpa = m_pressure_sensor_data[1].value / 1000.0; |
|
|
|
int g = 2.11 * kpa * 1000 * 1.3; |
|
|
|
if (g < 450) { /*零点*/ |
|
|
|
return 0; |
|
|
|
} else { |
|
|
|
g -= 450; |
|
|
|
} |
|
|
|
g = filter(g); |
|
|
|
// logger->info("g {}", g);
|
|
|
|
return g; |
|
|
|
// kpa;
|
|
|
|
// lock_guard<recursive_mutex> lock(lock_);
|
|
|
|
// float kpa = m_pressure_sensor_data[1].value / 1000.0;
|
|
|
|
// int g = 2.11 * kpa * 1000 * 1.3;
|
|
|
|
// if (g < 450) { /*零点*/
|
|
|
|
// return 0;
|
|
|
|
// } else {
|
|
|
|
// g -= 450;
|
|
|
|
// }
|
|
|
|
// g = filter(g);
|
|
|
|
// // logger->info("g {}", g);
|
|
|
|
// return g;
|
|
|
|
} |
|
|
|
int DeviceIoControlService::getPressureSensorData(int index) { |
|
|
|
lock_guard<recursive_mutex> lock(lock_); |
|
|
@ -458,6 +477,5 @@ bool DeviceIoControlService::getAllSensorData(DeviceIoControlService::all_h2o2se |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void DeviceIoControlService::printerTest() {} |
|
|
|
void DeviceIoControlService::printerPrintf(string str) { GET_SERVICE(UartPrinter)->print(ZIconv::utf8_to_gb2312(str)); } |