add qvvr interface
This commit is contained in:
@@ -2703,7 +2703,7 @@ bool extract_timestamp_from_cfg_file(const std::string& cfg_path, long long& sta
|
||||
return start_tm > 0 && trig_tm > 0;
|
||||
}
|
||||
|
||||
bool compare_qvvr_and_file(const std::string& cfg_path, const std::vector<qvvr_data>& data_list) {
|
||||
bool compare_qvvr_and_file(const std::string& cfg_path, const std::vector<qvvr_data>& data_list,qvvr_data& matched_data) {
|
||||
long long start_tm = 0;
|
||||
long long trig_tm = 0;
|
||||
|
||||
@@ -2717,6 +2717,7 @@ bool compare_qvvr_and_file(const std::string& cfg_path, const std::vector<qvvr_d
|
||||
for (const auto& data : data_list) {
|
||||
long long diff = static_cast<long long>(data.QVVR_time) - trig_tm;
|
||||
if (std::abs(diff) <= 1) {
|
||||
matched_data = data; // 返回匹配到的事件
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -2940,6 +2941,10 @@ bool SendAllQvvrFiles(qvvr_file& qfile, std::string& out_wavepath) {
|
||||
|
||||
//文件下载结束接口
|
||||
bool update_qvvr_file_download(const std::string& filename_with_mac, const std::string& terminal_id) {
|
||||
|
||||
//台账加锁
|
||||
std::lock_guard<std::mutex> lock(ledgermtx);
|
||||
|
||||
// 去除 mac 路径前缀,仅保留文件名
|
||||
std::string filename = extract_filename(filename_with_mac);
|
||||
|
||||
@@ -2954,9 +2959,11 @@ bool update_qvvr_file_download(const std::string& filename_with_mac, const std::
|
||||
std::string seq_str = type_part.substr(num_start + 1);
|
||||
ushort logical_seq = static_cast<ushort>(std::stoi(seq_str)); // 逻辑序号
|
||||
|
||||
//找终端
|
||||
for (auto& dev : terminal_devlist) {
|
||||
if (dev.terminal_id != terminal_id) continue;
|
||||
|
||||
//找监测点
|
||||
for (auto& monitor : dev.line) {
|
||||
try {
|
||||
// 将监测点台账中的 logical_device_seq 转换为数字进行匹配
|
||||
@@ -2967,16 +2974,19 @@ bool update_qvvr_file_download(const std::string& filename_with_mac, const std::
|
||||
}
|
||||
|
||||
// 匹配监测点下 qvvrfile 中的 file_name
|
||||
for (auto& qfile : monitor.qvvrevent.qvvrfile) {
|
||||
for (size_t i = 0; i < monitor.qvvrevent.qvvrfile.size(); ++i) {
|
||||
auto& qfile = monitor.qvvrevent.qvvrfile[i];
|
||||
// file_name 中是文件名,需与提取的 filename 比较
|
||||
auto it = std::find(qfile.file_name.begin(), qfile.file_name.end(), filename);
|
||||
|
||||
//找到匹配文件名
|
||||
if (it != qfile.file_name.end()) {
|
||||
// 添加到 file_download(记录完整路径,避免重复)
|
||||
if (std::find(qfile.file_download.begin(), qfile.file_download.end(), filename_with_mac) == qfile.file_download.end()) {
|
||||
qfile.file_download.push_back(filename_with_mac);
|
||||
}
|
||||
|
||||
qfile.file_time_count = 0; // 文件下载开始后,计时归零
|
||||
qfile.file_time_count = 0; // 任一录波文件下载后,计时归零
|
||||
|
||||
// file_download 中是完整路径,需提取文件名后与 file_name 做集合比较
|
||||
std::set<std::string> s_name(qfile.file_name.begin(), qfile.file_name.end());
|
||||
@@ -2994,7 +3004,8 @@ bool update_qvvr_file_download(const std::string& filename_with_mac, const std::
|
||||
std::string fname = extract_filename(fpath);
|
||||
if (fname.size() >= 4 && fname.substr(fname.size() - 4) == ".cfg") {
|
||||
// 提取文件时标和监测点事件的时标匹配
|
||||
if (compare_qvvr_and_file(fpath, monitor.qvvrevent.qvvrdata)) {
|
||||
qvvr_data matched;
|
||||
if (compare_qvvr_and_file(fpath, monitor.qvvrevent.qvvrdata,matched)) {
|
||||
qfile.is_pair = true; // 文件与事件匹配成功
|
||||
|
||||
// 发送所有文件(已下载完成)
|
||||
@@ -3003,16 +3014,12 @@ bool update_qvvr_file_download(const std::string& filename_with_mac, const std::
|
||||
//文件发送成功后更新事件
|
||||
transfer_json_qvvr_data(terminal_id,
|
||||
logical_seq,
|
||||
monitor.qvvrevent.qvvrdata.QVVR_Amg,
|
||||
monitor.qvvrevent.qvvrdata.QVVR_PerTime,
|
||||
monitor.qvvrevent.qvvrdata.QVVR_time,
|
||||
monitor.qvvrevent.qvvrdata.QVVR_type,
|
||||
monitor.qvvrevent.qvvrdata.phase,
|
||||
matched.QVVR_Amg,
|
||||
matched.QVVR_PerTime,
|
||||
matched.QVVR_time,
|
||||
matched.QVVR_type,
|
||||
matched.phase,
|
||||
wavepath);
|
||||
|
||||
// 清除暂态数据
|
||||
monitor.qvvrevent.qvvrfile.clear();
|
||||
monitor.qvvrevent.qvvrdata.clear();
|
||||
|
||||
// 删除上传成功的文件
|
||||
for (const auto& uploaded_file : qfile.file_download) {
|
||||
@@ -3022,15 +3029,37 @@ bool update_qvvr_file_download(const std::string& filename_with_mac, const std::
|
||||
std::cout << "[Cleanup] Deleted uploaded file: " << uploaded_file << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// 清除已发送的暂态文件
|
||||
monitor.qvvrevent.qvvrfile.erase(monitor.qvvrevent.qvvrfile.begin() + i);
|
||||
|
||||
//清除暂态事件
|
||||
auto it = std::find_if(
|
||||
monitor.qvvrevent.qvvrdata.begin(),
|
||||
monitor.qvvrevent.qvvrdata.end(),
|
||||
[&](const qvvr_data& d) {
|
||||
return d.QVVR_time == matched.QVVR_time;
|
||||
});
|
||||
|
||||
if (it != monitor.qvvrevent.qvvrdata.end()) {
|
||||
monitor.qvvrevent.qvvrdata.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
break; // 只处理第一个 cfg 文件
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
std::cout << "qvvr file still imcomplete!!!" << std::endl;
|
||||
}
|
||||
|
||||
return true; // 当前文件处理成功
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "file name doesnt match any file in this monitor!!!" << std::endl;
|
||||
|
||||
}
|
||||
}
|
||||
return false; // 未匹配到终端ID或逻辑序号对应的监测点
|
||||
|
||||
Reference in New Issue
Block a user