修改了socket通讯框架,添加了统计数据时间获取,统计数据数据读取
This commit is contained in:
@@ -4,9 +4,7 @@
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
#include "PQSMsg.h"
|
||||
#include "client2.h"
|
||||
#include "dealMsg.h"
|
||||
|
||||
#include "cloudfront/code/interface.h"
|
||||
|
||||
@@ -52,6 +50,7 @@ std::vector<DeviceInfo> generate_test_devices(int count) {
|
||||
"P" + dev_id.substr(1) + "01", // <20><><EFBFBD><EFBFBD>ID<49><44> P00101
|
||||
"Voltage " + dev_name,
|
||||
dev_id,
|
||||
1,
|
||||
0.0, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹֵ
|
||||
0.0,
|
||||
100.0,
|
||||
@@ -61,6 +60,7 @@ std::vector<DeviceInfo> generate_test_devices(int count) {
|
||||
"P" + dev_id.substr(1) + "02", // <20><><EFBFBD><EFBFBD>ID<49><44> P00102
|
||||
"Current " + dev_name,
|
||||
dev_id,
|
||||
2,
|
||||
0.0, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
0.0,
|
||||
20.0,
|
||||
@@ -82,37 +82,6 @@ std::vector<DeviceInfo> generate_test_devices(int count) {
|
||||
return devices;
|
||||
}
|
||||
|
||||
/* <20>̹߳<DFB3><CCB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳߳<DFB3>*/
|
||||
void* work_thread(void* arg) {
|
||||
int index = *(int*)arg; // <20><>ȡ<EFBFBD>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD>
|
||||
free(arg); // <20>ͷŶ<CDB7>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>״̬Ϊ<CCAC><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
pthread_mutex_lock(&thread_info[index].lock);
|
||||
printf("Thread %d started\n", index);
|
||||
thread_info[index].state = THREAD_RUNNING;
|
||||
pthread_mutex_unlock(&thread_info[index].lock);
|
||||
|
||||
// ģ<><EFBFBD><E2B9A4>ѭ<EFBFBD><D1AD>(5<><35><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
||||
while (1) {
|
||||
sleep(5);
|
||||
|
||||
// 10%<25><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD>̹߳<DFB3><CCB9><EFBFBD>
|
||||
if (rand() % 10 == 0) {
|
||||
pthread_mutex_lock(&thread_info[index].lock);
|
||||
printf("Thread %d simulated failure\n", index);
|
||||
pthread_mutex_unlock(&thread_info[index].lock);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// <20>߳<EFBFBD><DFB3><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
|
||||
pthread_mutex_lock(&thread_info[index].lock);
|
||||
thread_info[index].state = THREAD_STOPPED;
|
||||
printf("Thread %d stopped\n", index);
|
||||
pthread_mutex_unlock(&thread_info[index].lock);
|
||||
return NULL;
|
||||
}
|
||||
/* <20>̹߳<DFB3><CCB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0<><30><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>*/
|
||||
/* <20>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӹ<EFBFBD><D3B9><EFBFBD><EFBFBD>̺߳<DFB3><CCBA><EFBFBD>*/
|
||||
void* client_manager_thread(void* arg) {
|
||||
@@ -129,14 +98,14 @@ void* client_manager_thread(void* arg) {
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
std::vector<PointInfo> points1 = {
|
||||
{"P001", "Main Voltage", "D001", 10.0, 0.0, 100.0, 0.0},
|
||||
{"P002", "Backup Voltage", "D001", 5.0, 0.0, 50.0, 0.0}
|
||||
{"P001", "Main Voltage", "D001",1 ,1, 1, 1, 1},
|
||||
{"P002", "Backup Voltage", "D001",2 ,1, 1, 1, 1}
|
||||
};
|
||||
|
||||
std::vector<PointInfo> points2 = {
|
||||
{"P101", "Generator Output", "D002", 20.0, 0.0, 200.0, 0.0}
|
||||
{"P101", "Generator Output", "D002",1 ,1, 1, 1, 1}
|
||||
};
|
||||
|
||||
//00-B7-8D-A8-00-D6
|
||||
// <20><><EFBFBD><EFBFBD>װ<EFBFBD><D7B0><EFBFBD>б<EFBFBD>
|
||||
std::vector<DeviceInfo> devices = {
|
||||
{
|
||||
@@ -144,7 +113,7 @@ void* client_manager_thread(void* arg) {
|
||||
1, points1
|
||||
},
|
||||
{
|
||||
"D002", "Backup Device", "Model-Y", "00-B7-8D-A8-00-D6",
|
||||
"D002", "Backup Device", "Model-Y", "00-B7-8D-01-79-06",
|
||||
1, points2
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user