diff --git a/README.md b/README.md index 893192b..a604f54 100644 --- a/README.md +++ b/README.md @@ -68,4 +68,34 @@ https://www.sqlite.org/docs.html 1. 开始消毒后 +``` + + +``` + + + +液位测量压力传感器: +设备地址:01 +量程:-1~4kPa +4 kPa=407.888 毫米水柱 +传感器测量精度:0.407888 毫米水柱 + + + +1. 需求 + +加液 液位变换 + +排液 1.控制蠕动泵 + 2.液位变换 + +消毒 1. 上报时间,计算剩余时间. + 2. 上报所有传感器信息. + 3. 根据当前浓度估算D数值. + + 开始消毒 + 停止消毒 + +超时后设备自动杀死自己 ``` \ No newline at end of file diff --git a/iflytoplinuxsdk b/iflytoplinuxsdk index 49be222..ef70ce3 160000 --- a/iflytoplinuxsdk +++ b/iflytoplinuxsdk @@ -1 +1 @@ -Subproject commit 49be222386739d320e2dcfe3f1a79cd8dd71c5b2 +Subproject commit ef70ce36d2577b0f5ce3ec1d9cd2de3f7d2ec922 diff --git a/src/service/sensor_data_scan.cpp b/src/service/sensor_data_scan.cpp new file mode 100644 index 0000000..405a645 --- /dev/null +++ b/src/service/sensor_data_scan.cpp @@ -0,0 +1,94 @@ +#include "sensor_data_scan.hpp" + +using namespace iflytop; +using namespace std; + +SensorDataScan::SensorDataScan() {} +void SensorDataScan::initialize() { GET_TO_SERVICE(m_zcanHost); } +#if 0 +模块 板子 硬件ID ID +空压机-安全电磁阀 3 PC2 0 +空压机-通断电磁阀 3 PC3 1 +鼓风机-安全电磁阀 3 PC4 2 +-通断电磁阀 3 PC5 3 +加热片-安全电磁阀 3 PC6 4 +-通断电磁阀 3 PC7 5 +#endif +void SensorDataScan::startScan() { + m_workThread.reset(new Thread("SensorDataScan", [this]() { + ThisThread thisThread; + uint32_t i = 0; + + int readpressuresensor_id = 1; + + while (!thisThread.getExitFlag()) { + /* code */ + thisThread.sleepForMs(1); + i++; + + if (i % 1000 == 0) { + 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 % 1000 * 3) { + // m_hpp272_data_1 + m_zcanHost->hpp272_read_c1000(1, m_hpp272_data_1); + } + + if (i % 300 * 1) { + if (readpressuresensor_id == 5) { + readpressuresensor_id = 1; + } + m_zcanHost->huacheng_pressure_sensor_read_c1005(readpressuresensor_id, m_pressure_sensor_data[readpressuresensor_id]); + readpressuresensor_id++; + } + + if (i % 100 * 1) { + m_zcanHost->readio(1, m_waterImmersionSensor1); + m_zcanHost->readio(2, m_waterImmersionSensor2); + } + } + })); +} + +int SensorDataScan::getAirCompressor_io1() { return m_zcanHost->read_writeio_state_cache(1); } +int SensorDataScan::getAirCompressor_io2() { return m_zcanHost->read_writeio_state_cache(2); } +int SensorDataScan::getAirCompressor_currentValue() { return m_adc_1; } + +int SensorDataScan::getAirBlower_io1() { return m_zcanHost->read_writeio_state_cache(3); } +int SensorDataScan::getAirBlower_io2() { return m_zcanHost->read_writeio_state_cache(4); } +int SensorDataScan::getAirBlower_currentValue() { return m_adc_2; } + +// heatingStrip +int SensorDataScan::getHeatingStrip_io1() { return m_zcanHost->read_writeio_state_cache(5); } +int SensorDataScan::getHeatingStrip_io2() { return m_zcanHost->read_writeio_state_cache(6); } +int SensorDataScan::getHeatingStrip_currentValue() { return m_adc_3; } + +int SensorDataScan::getSprinkler_PumpRPM() { return m_zcanHost->pumpctrl_c1004_get_speed_cache(2); } +int SensorDataScan::getChargingPump_PumpRPM() { return m_zcanHost->pumpctrl_c1004_get_speed_cache(1); } + +int SensorDataScan::getDisinfectantVolume() { + // kpa; + int pa = m_zcanHost->huacheng_pressure_sensor_get_pa(&m_pressure_sensor_data[0]); + return pa; +} + +int SensorDataScan::getWaterImmersionSensor1() { return m_waterImmersionSensor1 ? 1 : 0; } +int SensorDataScan::getWaterImmersionSensor2() { return m_waterImmersionSensor2 ? 1 : 0; } + +SensorDataScan::h2o2sensor_data_t SensorDataScan::getH2O2SenSorData(int id) { + SensorDataScan::h2o2sensor_data_t data; + // int16_t hydrogen_peroxide_volume; // ppm 0x0100 过氧化氢浓度 + // int16_t h2o_h2o2_rs; // %RS * 100 0x0101 过氧化氢相对饱和度 + // int16_t temperature1; // °C * 100 0x0102 温度 + // int16_t relative_humidity; // %RH * 100 0x0103 相对湿度 + data.h2o2 = m_hpp272_data_1.hydrogen_peroxide_volume; + data.humid = m_hpp272_data_1.relative_humidity; + data.temp = m_hpp272_data_1.temperature1; + data.saturation = m_hpp272_data_1.h2o_h2o2_rs; + return data; +} diff --git a/src/service/sensor_data_scan.hpp b/src/service/sensor_data_scan.hpp new file mode 100644 index 0000000..8df5bfc --- /dev/null +++ b/src/service/sensor_data_scan.hpp @@ -0,0 +1,93 @@ +// +// Created by zwsd +// + +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "iflytop/components/zcanreceiver/zcanhost.hpp" +#include "iflytop/core/core.hpp" +#include "zservice_container/zservice_container.hpp" + +/** + * @brief + * + * service: SensorDataScan + * + * 监听事件: + * 依赖状态: + * 依赖服务: + * 作用: + * + */ + +namespace iflytop { +using namespace std; +using namespace core; + +class SensorDataScan : public enable_shared_from_this { + ENABLE_LOGGER(SensorDataScan); + + unique_ptr m_workThread; + shared_ptr m_zcanHost; + + // + ZCanHost::hpp272_data_t m_hpp272_data_1; + ZCanHost::huacheng_pressure_sensor_read_c1005_t m_pressure_sensor_data[4]; + + // + bool m_waterImmersionSensor1 = false; // 漏液检测 + bool m_waterImmersionSensor2 = false; // 仓内液体检测 + + int m_adc_1 = 0; // + int m_adc_2 = 0; + int m_adc_3 = 0; + int m_adc_4 = 0; + int m_adc_5 = 0; + + public: + SensorDataScan(); + void initialize(); + void startScan(); + + public: + int getAirCompressor_io1(); + int getAirCompressor_io2(); + int getAirCompressor_currentValue(); + + int getAirBlower_io1(); + int getAirBlower_io2(); + int getAirBlower_currentValue(); + + // heatingStrip + int getHeatingStrip_io1(); + int getHeatingStrip_io2(); + int getHeatingStrip_currentValue(); + + int getSprinkler_PumpRPM(); + int getChargingPump_PumpRPM(); + + int getDisinfectantVolume(); + + int getWaterImmersionSensor1(); + int getWaterImmersionSensor2(); + + typedef struct { + int h2o2; // ppm + int temp; // 温度 + int humid; // 湿度 %RS + int saturation; // 相对饱和度 %RS + } h2o2sensor_data_t; + + h2o2sensor_data_t getH2O2SenSorData(int id); +}; +} // namespace iflytop \ No newline at end of file