新增暂态事件补招功能
This commit is contained in:
@@ -283,6 +283,37 @@ void ClientContext::clear_stat_cache() {
|
||||
stat_packets_cache_.clear();
|
||||
expected_total_packets_ = 0;
|
||||
}
|
||||
|
||||
bool ClientContext::event_add_stat_packet(const std::vector<unsigned char>& packet, int current_packet, int total_packets) {
|
||||
std::lock_guard<std::mutex> lock(event_stat_cache_mutex_);
|
||||
|
||||
// 如果是第一帧,初始化缓存
|
||||
if (current_packet == 1) {
|
||||
event_stat_packets_cache_.clear();
|
||||
event_expected_total_packets_ = total_packets;
|
||||
}
|
||||
|
||||
// 添加到缓存
|
||||
event_stat_packets_cache_.push_back({ current_packet, packet });
|
||||
|
||||
// 检查是否收齐所有帧
|
||||
return (event_stat_packets_cache_.size() >= event_expected_total_packets_);
|
||||
}
|
||||
|
||||
std::vector<ClientContext::StatPacket> ClientContext::event_get_and_clear_stat_packets() {
|
||||
std::lock_guard<std::mutex> lock(event_stat_cache_mutex_);
|
||||
auto packets = std::move(event_stat_packets_cache_);
|
||||
event_stat_packets_cache_.clear();
|
||||
event_expected_total_packets_ = 0;
|
||||
return packets;
|
||||
}
|
||||
|
||||
void ClientContext::event_clear_stat_cache() {
|
||||
std::lock_guard<std::mutex> lock(event_stat_cache_mutex_);
|
||||
event_stat_packets_cache_.clear();
|
||||
event_expected_total_packets_ = 0;
|
||||
}
|
||||
|
||||
// 添加浮点数据到缓存
|
||||
bool ClientContext::add_float_data(ushort point_id, int data_type, const tagPqData_Float& float_data) {
|
||||
if (data_type < 0 || data_type > 3) return false;
|
||||
@@ -548,6 +579,7 @@ void on_close(uv_handle_t* handle) {
|
||||
ctx->stop_timers();
|
||||
// 清空缓存
|
||||
ctx->clear_stat_cache();
|
||||
ctx->event_clear_stat_cache();
|
||||
// 清除浮点数据缓存
|
||||
ctx->clear_float_cache();
|
||||
// 装置登录状态调整为离线
|
||||
@@ -1055,6 +1087,52 @@ bool ClientManager::clear_stat_cache(const std::string& identifier) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//保存多帧事件日志报文至缓存区等待收全
|
||||
bool ClientManager::add_eventlog_packet_to_device(const std::string& identifier,
|
||||
const std::vector<unsigned char>& packet,
|
||||
int current_packet,
|
||||
int total_packets) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
for (auto& pair : clients_) {
|
||||
auto& ctx = pair.second;
|
||||
if (ctx->device_info.device_id == identifier ||
|
||||
ctx->device_info.mac == identifier) {
|
||||
return ctx->event_add_stat_packet(packet, current_packet, total_packets);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//获取缓存区内所有多帧事件日志报文并清空缓存
|
||||
std::vector<ClientContext::StatPacket> ClientManager::get_and_clear_event_packets(const std::string& identifier) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
for (auto& pair : clients_) {
|
||||
auto& ctx = pair.second;
|
||||
if (ctx->device_info.device_id == identifier ||
|
||||
ctx->device_info.mac == identifier) {
|
||||
return ctx->event_get_and_clear_stat_packets();
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
//清空所有事件日志缓存区
|
||||
bool ClientManager::clear_event_cache(const std::string& identifier) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
for (auto& pair : clients_) {
|
||||
auto& ctx = pair.second;
|
||||
if (ctx->device_info.device_id == identifier ||
|
||||
ctx->device_info.mac == identifier) {
|
||||
ctx->event_clear_stat_cache();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取pt和CT变比
|
||||
bool ClientManager::get_pt_ct_ratio(const std::string& identifier,
|
||||
int16_t nCpuNo,
|
||||
@@ -1093,6 +1171,25 @@ bool ClientManager::get_pt_ct_ratio(const std::string& identifier,
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取待补招测点序号
|
||||
bool ClientManager::get_event_lineid(const std::string& identifier,int& nCpuNo) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
for (auto& pair : clients_) {
|
||||
auto& ctx = pair.second;
|
||||
// 匹配装置ID或MAC地址
|
||||
if (ctx->device_info.device_id == identifier ||
|
||||
ctx->device_info.mac == identifier) {
|
||||
|
||||
nCpuNo = ctx->event_lineNo;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "[get_pt_ct_ratio] Device not found: " << identifier << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// 添加浮点数据到指定设备的缓存
|
||||
bool ClientManager::add_float_data_to_device(const std::string& identifier,
|
||||
ushort point_id,
|
||||
@@ -1451,6 +1548,43 @@ bool ClientManager::read_devversion_action_to_device(const std::string& identifi
|
||||
}
|
||||
return false; // 设备未找到
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 补招事件日志动作
|
||||
* @param Time1 起始时间
|
||||
* @param Time2 结束时间
|
||||
* @param eventType 事件类型,默认2-暂态事件 4-告警时间
|
||||
* @param monitorPoint 监测点,默认1-监测点1 1-6 对应测点
|
||||
* @return 调用成功或失败的结果
|
||||
*/
|
||||
bool ClientManager::read_eventlog_action_to_device(const std::string& identifier, const std::tm& Time1, const std::tm& Time2,
|
||||
uint8_t eventType, uint8_t monitorPoint) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
// 查找匹配的设备
|
||||
for (auto& pair : clients_) {
|
||||
auto& ctx = pair.second;
|
||||
if (ctx->device_info.device_id == identifier ||
|
||||
ctx->device_info.mac == identifier)
|
||||
{
|
||||
ctx->event_lineNo = monitorPoint;
|
||||
// 生成定值描述报文
|
||||
auto packet = generate_recallevent_message(Time1, Time2, eventType, monitorPoint);
|
||||
|
||||
// 添加动作到队列 (状态: 读取文件目录)
|
||||
ctx->add_action(DeviceState::READING_EVENTLOG, packet);
|
||||
|
||||
// 如果当前空闲则立即执行
|
||||
if (ctx->current_state_ == DeviceState::IDLE) {
|
||||
ctx->process_next_action();
|
||||
}
|
||||
|
||||
return true; // 成功添加
|
||||
}
|
||||
}
|
||||
return false; // 设备未找到
|
||||
}
|
||||
|
||||
//获取指定装置测点的电压等级与接线方式
|
||||
bool ClientManager::get_point_scale_and_pttype(const std::string& identifier,
|
||||
ushort nCpuNo,
|
||||
|
||||
Reference in New Issue
Block a user