From 6056ea167ac0deeeb2a1c487b8d041d491dd4b00 Mon Sep 17 00:00:00 2001 From: lnk Date: Tue, 16 Sep 2025 10:13:47 +0800 Subject: [PATCH 1/2] add --- LFtid1056/dealMsg.cpp | 2 ++ LFtid1056/main_thread.cpp | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/LFtid1056/dealMsg.cpp b/LFtid1056/dealMsg.cpp index 78d1e20..acbe8b6 100644 --- a/LFtid1056/dealMsg.cpp +++ b/LFtid1056/dealMsg.cpp @@ -1031,6 +1031,7 @@ void process_received_message(string mac, string id,const char* data, size_t len uint8_t monitor_index = parser.RecvData[0]; std::cout << "Monitor Index: " << static_cast(monitor_index) << std::endl; send_set_value_reply(id, monitor_index, dz_list); + on_device_response_minimal(static_cast(ResponseCode::OK), id, 0, static_cast(DeviceState::READING_FIXEDVALUE)); //定值描述读取完毕,调整为空闲,处理后续工作。 ClientManager::instance().change_device_state(id, DeviceState::IDLE); @@ -1261,6 +1262,7 @@ void process_received_message(string mac, string id,const char* data, size_t len } send_internal_value_reply(id, control_words); + on_device_response_minimal(static_cast(ResponseCode::OK), id, 0, static_cast(DeviceState::READING_INTERFIXEDVALUE)); // 控制字描述读取完毕,调整为空闲,处理后续工作 ClientManager::instance().change_device_state(id, DeviceState::IDLE); diff --git a/LFtid1056/main_thread.cpp b/LFtid1056/main_thread.cpp index cf42326..9e0d208 100644 --- a/LFtid1056/main_thread.cpp +++ b/LFtid1056/main_thread.cpp @@ -154,17 +154,17 @@ void* client_manager_thread(void* arg) { printf("Started client connections\n"); // 创建测点数据 - std::vector points1 = { + /*std::vector points1 = { {"P001", "Main Voltage", "D001",1 ,1, 1, 1, 1,"0.38k",0}, {"P002", "Backup Voltage", "D001",2 ,1, 1, 1, 1,"0.38k",0} }; std::vector points2 = { {"P003", "Main Voltage", "D002",1 ,1, 1, 1, 1,"0.38k",0}, {"P004", "Backup Voltage", "D002",2 ,1, 1, 1, 1,"0.38k",0} - }; + };*/ //00B78DA800D6 00-B7-8D-01-79-06 00-B7-8D-A8-00-D6 00-B7-8D-01-71-09 00-B7-8D-01-88-7f // 创建装置列表 - std::vector devices = { + /*std::vector devices = { { "D001", "Primary Device", "Model-X", "00-B7-8D-01-88-7f", 1, points1,true @@ -173,13 +173,13 @@ void* client_manager_thread(void* arg) { "D002", "Primary Device1", "Model-X1", "00-B7-8D-01-71-09", 1, points2,true } - }; + };*/ // 生成100个测试装置 //std::vector test_devices = generate_test_devices(100); //lnk从台账读取设备 - //std::vector devices = GenerateDeviceInfoFromLedger(terminal_devlist);//lnk添加 + std::vector devices = GenerateDeviceInfoFromLedger(terminal_devlist);//lnk添加 //台账打印 PrintDevices(devices); @@ -310,7 +310,7 @@ int main(int argc ,char** argv) {// std::cerr << "process param error,exit" << std::endl; return 1; } - //init_daemon(); + init_daemon(); srand(time(NULL)); // 初始化随机数种子 // 初始化线程数组 From 0638b1dbf804664376de5657284339c6db87f550 Mon Sep 17 00:00:00 2001 From: lnk Date: Tue, 16 Sep 2025 11:07:10 +0800 Subject: [PATCH 2/2] add comments --- LFtid1056/cloudfront/code/cfg_parser.cpp | 50 ++++++++++++++++++++++-- LFtid1056/dealMsg.cpp | 2 +- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/LFtid1056/cloudfront/code/cfg_parser.cpp b/LFtid1056/cloudfront/code/cfg_parser.cpp index 7a30419..a3341a7 100644 --- a/LFtid1056/cloudfront/code/cfg_parser.cpp +++ b/LFtid1056/cloudfront/code/cfg_parser.cpp @@ -2827,6 +2827,9 @@ bool compare_qvvr_and_file(const std::string& cfg_path, const std::vector(data.QVVR_time) - trig_tm; @@ -3067,6 +3070,9 @@ 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::cout << "[update_qvvr_file_download] filename_with_mac=" << filename_with_mac + << " terminal_id=" << terminal_id << std::endl; + //鍙拌处鍔犻攣 std::lock_guard lock(ledgermtx); @@ -3093,8 +3099,31 @@ bool update_qvvr_file_download(const std::string& filename_with_mac, const std:: try { // 灏嗙洃娴嬬偣鍙拌处涓殑 logical_device_seq 杞崲涓烘暟瀛楄繘琛屽尮閰 ushort monitor_seq = static_cast(std::stoi(monitor.logical_device_seq)); - if (monitor_seq != logical_seq) continue; - } catch (...) { + if (monitor_seq != logical_seq) { + // 鈽呮柊澧烇細涓嶅尮閰嶆椂瀵规瘮鎵撳嵃 + std::cout << "[cmp-monitor-seq][NOT-MATCH]" + << " monitor_id=" << monitor.monitor_id + << " seq_in_ledger=\"" << seq_str << "\"" + << " parsed=" << monitor_seq + << " target_seq=" << logical_seq + << std::endl; + continue; + } + } catch (const std::exception& e) { + // 鈽呮柊澧烇細瑙f瀽澶辫触璇︾粏鍘熷洜 + std::cout << "[cmp-monitor-seq][PARSE-FAIL]" + << " monitor_id=" << monitor.monitor_id + << " seq_in_ledger=\"" << monitor.logical_device_seq << "\"" + << " err=" << e.what() + << std::endl; + continue; // logical_device_seq 闈炴硶锛岃烦杩 + }catch (...) { + // 鈽呮柊澧烇細鏈煡寮傚父 + std::cout << "[cmp-monitor-seq][PARSE-FAIL]" + << " monitor_id=" << monitor.monitor_id + << " seq_in_ledger=\"" << monitor.logical_device_seq << "\"" + << " err=" + << std::endl; continue; // logical_device_seq 闈炴硶锛岃烦杩 } @@ -3108,6 +3137,7 @@ bool update_qvvr_file_download(const std::string& filename_with_mac, const std:: 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()) { + std::cout << "[update_qvvr_file_download] Adding downloaded file: " << filename_with_mac << std::endl; qfile.file_download.push_back(filename_with_mac); } @@ -3120,8 +3150,16 @@ bool update_qvvr_file_download(const std::string& filename_with_mac, const std:: s_down.insert(extract_filename1(path)); // 鎻愬彇姣忎釜璺緞涓殑鏂囦欢鍚 } + //鎵撳嵃s_name鍜宻_down鍐呭 + std::cout << "[update_qvvr_file_download] Expected files (file_name): "; + for (const auto& fn : s_name) std::cout << fn << " "; + std::cout << std::endl; + std::cout << "[update_qvvr_file_download] Downloaded files (file_download): "; + for (const auto& fn : s_down) std::cout << fn << " "; + // 妫鏌 file_download 鏄惁涓 file_name 瀹屽叏涓鑷达紙闆嗗悎鐩稿悓锛 if (s_name == s_down) { + std::cout << "[update_qvvr_file_download] All files downloaded for qfile in logical_seq=" << logical_seq << std::endl; qfile.is_download = true; // 鍏ㄩ儴涓嬭浇瀹屾垚 // 鎵惧埌鍏朵腑鐨 .cfg 鏂囦欢杩涜鍖归厤 @@ -3169,7 +3207,13 @@ bool update_qvvr_file_download(const std::string& filename_with_mac, const std:: if (it != monitor.qvvrevent.qvvrdata.end()) { monitor.qvvrevent.qvvrdata.erase(it); } - } + } + else { + std::cerr << "[update_qvvr_file_download] Failed to send qvvr files for logical_seq=" << logical_seq << std::endl; + } + } + else { + std::cout << "[update_qvvr_file_download] No matching qvvr_data found for cfg file: " << fpath << std::endl; } break; // 鍙鐞嗙涓涓 cfg 鏂囦欢 } diff --git a/LFtid1056/dealMsg.cpp b/LFtid1056/dealMsg.cpp index acbe8b6..269c0c9 100644 --- a/LFtid1056/dealMsg.cpp +++ b/LFtid1056/dealMsg.cpp @@ -609,7 +609,7 @@ void process_received_message(string mac, string id,const char* data, size_t len cid, //逻辑子设备ID,0-逻辑设备本身,无填-1 0x04, //数据类型固定为电能质量数据 1, //数据属性:无“0”、实时“1”、统计“2”等 - 1, //数据集序号(以数据集方式上送),无填-1 + 2, //数据集序号(以数据集方式上送),无填-1 arr //数据数组 ); //std::cout << js << std::en