diff --git a/LFtid1056/main_thread.cpp b/LFtid1056/main_thread.cpp index 19dc836..3a564bd 100644 --- a/LFtid1056/main_thread.cpp +++ b/LFtid1056/main_thread.cpp @@ -7,7 +7,7 @@ #include "PQSMsg.h" #include "client2.h" #include "dealMsg.h" - +using namespace std; /* 常量定义 */ #define THREAD_CONNECTIONS 10 // 最大线程数 #define MONITOR_INTERVAL 1 // 监控间隔(秒) @@ -33,6 +33,51 @@ thread_info_t thread_info[THREAD_CONNECTIONS]; // pthread_mutex_t global_lock = PTHREAD_MUTEX_INITIALIZER; // 全局互斥锁 extern SafeMessageQueue message_queue; +// 生成测试装置 +std::vector generate_test_devices(int count) { + std::vector devices; + + for (int i = 1; i <= count; ++i) { + // 生成装置ID和名称 + std::string dev_id = "D" + std::to_string(1000 + i).substr(1); // D001, D002, ..., D100 + std::string dev_name = "Device " + std::to_string(i); + + // 生成测点 + std::vector points = { + { + "P" + dev_id.substr(1) + "01", // 测点ID如 P00101 + "Voltage " + dev_name, + dev_id, + 0.0, // 随机电压值 + 0.0, + 100.0, + 80.0 + }, + { + "P" + dev_id.substr(1) + "02", // 测点ID如 P00102 + "Current " + dev_name, + dev_id, + 0.0, // 随机电流值 + 0.0, + 20.0, + 15.0 + } + }; + + // 添加装置 + devices.push_back({ + dev_id, + dev_name, + (i % 2 == 0) ? "Model-X" : "Model-Y", // 交替使用两种型号 + "00-B7-8D-A8-00-D1", // 随机MAC地址 + 1, // 状态 (1=在线) + points + }); + } + + return devices; +} + /* 线程工作函数 待分配线程池*/ void* work_thread(void* arg) { int index = *(int*)arg; // 获取线程索引 @@ -100,6 +145,10 @@ void* client_manager_thread(void* arg) { } }; + // 生成100个测试装置 + std::vector test_devices = generate_test_devices(100); + + // 启动客户端连接 start_client_connect(devices); printf("Stopped all client connections\n");