|
|
@ -1,6 +1,8 @@ |
|
|
|
#include "h2o2_sensor_mgr.hpp"
|
|
|
|
|
|
|
|
#include "service/hardware/device_io_ctrl_service.hpp"
|
|
|
|
//
|
|
|
|
#include "service/app/disinfection_ctrl/disinfection_ctrl_service.hpp"
|
|
|
|
|
|
|
|
using namespace iflytop; |
|
|
|
|
|
|
@ -39,6 +41,7 @@ void H2O2SensorMgr::initialize() { |
|
|
|
})); |
|
|
|
|
|
|
|
REG_EXTFN(getH2O2DataRecordList, void(H2O2SensorType, int, int64_t, int64_t, int64_t), type, id, since, interval, before); |
|
|
|
REG_EXTFN(getDisinfectionH2O2DataRecordList, void(H2O2SensorType, int, int64_t), type, id, interval); |
|
|
|
REG_EXTFN_VOID(getH2O2SensorList, void()); |
|
|
|
} |
|
|
|
|
|
|
@ -121,7 +124,8 @@ void H2O2SensorMgr::getH2O2DataRecordList(shared_ptr<MsgProcessContext> cxt, H2O |
|
|
|
return; |
|
|
|
} |
|
|
|
json dataList = json::array(); |
|
|
|
int32_t nextdataTimestamp = since; |
|
|
|
int64_t nextdataTimestamp = since; |
|
|
|
|
|
|
|
for (auto& data : recordList->datas) { |
|
|
|
if (data.timestamp < (nextdataTimestamp - RECORD_PERIOD / 2)) { |
|
|
|
continue; |
|
|
@ -134,10 +138,37 @@ void H2O2SensorMgr::getH2O2DataRecordList(shared_ptr<MsgProcessContext> cxt, H2O |
|
|
|
|
|
|
|
dataList.push_back(data); |
|
|
|
nextdataTimestamp = data.timestamp + interval; |
|
|
|
// logger->info("nextdataTimestamp: {}, data.timestamp: {}, interval: {}", nextdataTimestamp, data.timestamp, interval);
|
|
|
|
} |
|
|
|
cxt->rely = dataList; |
|
|
|
} |
|
|
|
|
|
|
|
void H2O2SensorMgr::getDisinfectionH2O2DataRecordList(shared_ptr<MsgProcessContext> cxt, H2O2SensorType type, int id, int64_t interval) { //
|
|
|
|
auto disinfectionCtrlService = GET_SERVICE(DisinfectionCtrlService); |
|
|
|
|
|
|
|
DisinfectionState disinfectionState; |
|
|
|
int64_t startTime = 0; |
|
|
|
int64_t endTime = 0; |
|
|
|
|
|
|
|
disinfectionCtrlService->getStateSafeBlock([&]() { |
|
|
|
disinfectionState = disinfectionCtrlService->getState(); |
|
|
|
startTime = disinfectionCtrlService->getStartTP(); |
|
|
|
endTime = disinfectionCtrlService->getCompleteTP(); |
|
|
|
}); |
|
|
|
|
|
|
|
if (disinfectionState.eq(DisinfectionState::kidle)) { |
|
|
|
if (endTime == 0) { |
|
|
|
cxt->rely = json::array(); // No disinfection in progress, return empty array
|
|
|
|
} else { |
|
|
|
getH2O2DataRecordList(cxt, type, id, startTime, interval, endTime); |
|
|
|
return; |
|
|
|
} |
|
|
|
} else { |
|
|
|
getH2O2DataRecordList(cxt, type, id, startTime, interval, 0); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
shared_ptr<H2O2DataRecordList> H2O2SensorMgr::findRecordList(H2O2SensorType type, int id) { |
|
|
|
std::lock_guard<std::recursive_mutex> lock(lock_); |
|
|
|
for (auto& recordList : h2o2DataRecords) { |
|
|
|