15 changed files with 351 additions and 103 deletions
-
1appsrc/appbase/appbean/hardware_component.hpp
-
2appsrc/appconfig/basic/zappversion.hpp
-
4appsrc/baseservice/db/device_ext_setting_dao.cpp
-
8appsrc/baseservice/db/device_ext_setting_dao.hpp
-
3appsrc/baseservice/port/project_port.cpp
-
1appsrc/baseservice/port/project_port.hpp
-
101appsrc/service/app/air_leak_detect_test.cpp
-
16appsrc/service/app/air_leak_detect_test.hpp
-
100appsrc/service/h2o2_data_record_service.cpp
-
75appsrc/service/h2o2_data_record_service.hpp
-
28appsrc/service/hardware/h2o2_sensor_state_sync.hpp
-
2appsrc/service/hardware/sensor_state_sync_service.hpp
-
98appsrc/service/setting/ext_setting_mgr_service.cpp
-
5appsrc/service/setting/ext_setting_mgr_service.hpp
-
10html/debug/index.html
@ -1,3 +1,3 @@ |
|||
#pragma once
|
|||
#define VERSION "2.4.4"
|
|||
#define VERSION "2.4.5"
|
|||
#define PROJECT_NAME "TRANSMIT_DM"
|
@ -0,0 +1,100 @@ |
|||
#include "h2o2_data_record_service.hpp"
|
|||
|
|||
#include "service/hardware/device_io_ctrl_service.hpp"
|
|||
|
|||
using namespace iflytop; |
|||
|
|||
#define RECORD_PERIOD (10 * 1000) // 10 seconds
|
|||
#define MAX_RECORD_NUM (8 * 60 * 60 * 1000 / RECORD_PERIOD) //
|
|||
|
|||
|
|||
|
|||
void H2O2DataRecordService::initialize() { |
|||
if (PORT.getExtH2O2SensorNum() == 0) { |
|||
newH2O2DataRecordList(H2O2SensorType::Internal, 1); |
|||
} else if (PORT.getExtH2O2SensorNum() == 1) { |
|||
newH2O2DataRecordList(H2O2SensorType::Internal, 1); |
|||
newH2O2DataRecordList(H2O2SensorType::WiredExtSensor, 1); |
|||
} else if (PORT.getExtH2O2SensorNum() == 2) { |
|||
newH2O2DataRecordList(H2O2SensorType::Internal, 1); |
|||
newH2O2DataRecordList(H2O2SensorType::WiredExtSensor, 1); |
|||
newH2O2DataRecordList(H2O2SensorType::WiredExtSensor, 2); |
|||
} |
|||
|
|||
//
|
|||
stateUpdateThread.reset(new Thread("FERDC-stateUpdateThread", [this]() { |
|||
while (!ThisThread().getExitFlag()) { |
|||
try { |
|||
} catch (const std::exception& e) { |
|||
logger->error("stateUpdateThread error:{}", e.what()); |
|||
} |
|||
ThisThread().sleepForMs(1000); |
|||
} |
|||
})); |
|||
} |
|||
|
|||
void H2O2DataRecordService::stateUpdateThreadFunc() {} |
|||
void H2O2DataRecordService::captureThreadFunc() { |
|||
ThisThread thisThread; |
|||
while (true) { |
|||
{ |
|||
std::lock_guard<std::recursive_mutex> lock(lock_); |
|||
|
|||
for (auto& recordList : h2o2DataRecords) { |
|||
auto data = h2o2SensorStateSyncService->getCacheDataCpy(recordList->sensorDataInfo.type, recordList->sensorDataInfo.id); |
|||
|
|||
recordList->sensorDataInfo.isOnline = data->isOnline; |
|||
shared_ptr<H2O2SensorData> sensorData = //
|
|||
make_shared<H2O2SensorData>(data->h2o2, //
|
|||
data->rh, //
|
|||
data->temp, //
|
|||
data->rs, //
|
|||
zsys_get_ticket()); |
|||
|
|||
recordList->sensorDataList.push_back(sensorData); |
|||
if (recordList->sensorDataList.size() > MAX_RECORD_NUM) { |
|||
recordList->sensorDataList.pop_front(); // Remove the oldest record if it exceeds the max limit
|
|||
} |
|||
} |
|||
} |
|||
thisThread.sleepForMs(RECORD_PERIOD); |
|||
} |
|||
} |
|||
|
|||
void H2O2DataRecordService::getH2O2DataRecordList(shared_ptr<MsgProcessContext> cxt, H2O2SensorType type, int id, int64_t since, int64_t Interval) {} |
|||
|
|||
shared_ptr<H2O2DataRecordList> H2O2DataRecordService::findRecordList(H2O2SensorType type, int id) { |
|||
std::lock_guard<std::recursive_mutex> lock(lock_); |
|||
for (auto& recordList : h2o2DataRecords) { |
|||
if (recordList->sensorDataInfo.type == type && recordList->sensorDataInfo.id == id) { |
|||
return recordList; |
|||
} |
|||
} |
|||
return nullptr; // Not found
|
|||
} |
|||
void H2O2DataRecordService::getH2O2SensorDataInfoList(shared_ptr<MsgProcessContext> cxt) { |
|||
std::lock_guard<std::recursive_mutex> lock(lock_); |
|||
list<shared_ptr<H2O2SensorDataInfo>> sensorDataInfoList; |
|||
|
|||
for (auto& recordList : h2o2DataRecords) { |
|||
auto sensorDataInfo = make_shared<H2O2SensorDataInfo>(); |
|||
sensorDataInfo->type = recordList->sensorDataInfo.type; |
|||
sensorDataInfo->id = recordList->sensorDataInfo.id; |
|||
sensorDataInfo->isOnline = recordList->sensorDataInfo.isOnline; |
|||
|
|||
sensorDataInfoList.push_back(sensorDataInfo); |
|||
} |
|||
|
|||
// cxt->rely = sensorDataInfoList;
|
|||
} |
|||
|
|||
void H2O2DataRecordService::newH2O2DataRecordList(H2O2SensorType type, int id) { |
|||
std::lock_guard<std::recursive_mutex> lock(lock_); |
|||
auto recordList = findRecordList(type, id); |
|||
if (!recordList) { |
|||
recordList = make_shared<H2O2DataRecordList>(); |
|||
recordList->sensorDataInfo.type = type; |
|||
recordList->sensorDataInfo.id = id; |
|||
h2o2DataRecords.push_back(recordList); |
|||
} |
|||
} |
@ -0,0 +1,75 @@ |
|||
#pragma once
|
|||
#include <fstream>
|
|||
#include <iostream>
|
|||
#include <list>
|
|||
#include <map>
|
|||
#include <memory>
|
|||
#include <set>
|
|||
#include <sstream>
|
|||
#include <string>
|
|||
#include <vector>
|
|||
//
|
|||
#include "baseservice/baseservice.hpp"
|
|||
#include "service/hardware/h2o2_sensor_state_sync.hpp"
|
|||
|
|||
namespace iflytop { |
|||
class H2O2SensorData { |
|||
public: |
|||
float h2o2 = -1; // ppm
|
|||
float rh = -1; // %RH
|
|||
float temp = -1; // °C
|
|||
float rs = -1; // %RS
|
|||
int64_t timestamp = 0; // Timestamp in milliseconds since epoch
|
|||
|
|||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(H2O2SensorData, h2o2, rh, temp, rs, timestamp); |
|||
H2O2SensorData(float h2o2, float rh, float temp, float rs, int64_t timestamp) : h2o2(h2o2), rh(rh), temp(temp), rs(rs), timestamp(timestamp) {} |
|||
}; |
|||
|
|||
class H2O2SensorDataInfo { |
|||
public: |
|||
H2O2SensorType type; |
|||
int id; |
|||
bool isOnline; |
|||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(H2O2SensorDataInfo, type, id, isOnline); |
|||
}; |
|||
|
|||
class H2O2DataRecordList { |
|||
public: |
|||
H2O2SensorDataInfo sensorDataInfo; |
|||
list<shared_ptr<H2O2SensorData>> sensorDataList; |
|||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(H2O2DataRecordList, sensorDataInfo, sensorDataList); |
|||
}; |
|||
|
|||
class H2O2DataRecordService : public enable_shared_from_this<H2O2DataRecordService> { |
|||
THISCLASS(H2O2DataRecordService); |
|||
|
|||
// Service
|
|||
SERVICE(H2O2SensorStateSyncService, h2o2SensorStateSyncService); |
|||
|
|||
// Fields
|
|||
unique_ptr<Thread> stateUpdateThread; |
|||
unique_ptr<Thread> captureThread; |
|||
|
|||
// Data
|
|||
list<shared_ptr<H2O2DataRecordList>> h2o2DataRecords; |
|||
|
|||
// Lock
|
|||
std::recursive_mutex lock_; |
|||
|
|||
public: |
|||
void initialize(); |
|||
|
|||
private: |
|||
void getH2O2DataRecordList(shared_ptr<MsgProcessContext> cxt, H2O2SensorType type, int id, int64_t since, int64_t Interval); |
|||
void getH2O2SensorDataInfoList(shared_ptr<MsgProcessContext> cxt); |
|||
|
|||
private: |
|||
void stateUpdateThreadFunc(); |
|||
void captureThreadFunc(); |
|||
|
|||
shared_ptr<H2O2DataRecordList> findRecordList(H2O2SensorType type, int id); |
|||
|
|||
void newH2O2DataRecordList(H2O2SensorType type, int id); |
|||
}; |
|||
|
|||
} // namespace iflytop
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue