diff --git a/LFtid1056.zip b/LFtid1056.zip
new file mode 100644
index 0000000..5eb149c
Binary files /dev/null and b/LFtid1056.zip differ
diff --git a/LFtid1056/LFtid1056.vcxproj b/LFtid1056/LFtid1056.vcxproj
index 93bdaf4..206e6b8 100644
--- a/LFtid1056/LFtid1056.vcxproj
+++ b/LFtid1056/LFtid1056.vcxproj
@@ -86,6 +86,9 @@
+
+
+
@@ -267,6 +270,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -299,23 +339,263 @@
+
+
- $(RemoteRootDir)/cloudfront/code;$(RemoteRootDir)/cloudfront/code/nlohmann;$(RemoteRootDir)/cloudfront/code/curl;$(RemoteRootDir)/cloudfront/code/log4cplus;$(RemoteRootDir)/cloudfront/code/rocketmq;$(RemoteRootDir)/lib/libuv-v1.51.0/include;$(RemoteRootDir);D:\Git代码\frontlinux\LFtid1056\cloudfront\code;D:\Git代码\frontlinux\LFtid1056;D:\Git代码\frontlinux\LFtid1056\lib\libuv-v1.51.0\include;D:\Git代码\frontlinux\LFtid1056\cloudfront\code\curl;D:\Git代码\frontlinux\LFtid1056\cloudfront\code\log4cplus;D:\Git代码\frontlinux\LFtid1056\cloudfront\code\nlohmann;D:\Git代码\frontlinux\LFtid1056\cloudfront\code\rocketmq;./cloudfront/code;./cloudfront/code/nlohmann;./cloudfront/code/curl;./cloudfront/code/log4cplus;./cloudfront/code/rocketmq;./lib/libuv-v1.51.0/include;.;%(AdditionalIncludeDirectories)
+ $(RemoteRootDir);
+$(RemoteRootDir)/cloudfront/code;
+$(RemoteRootDir)/cloudfront/code/log4cplus;
+$(RemoteRootDir)/cloudfront/code/log4cplus/include;
+$(RemoteRootDir)/lib/libuv-v1.51.0/include;
+$(RemoteRootDir)/pqdif;
+$(RemoteRootDir)/pqdif/include;
+D:\Git代码\frontlinux\LFtid1056;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code\log4cplus;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code\log4cplus\include;
+D:\Git代码\frontlinux\LFtid1056\lib\libuv-v1.51.0\include;
+D:\Git代码\frontlinux\LFtid1056\pqdif;
+D:\Git代码\frontlinux\LFtid1056\pqdif\include;
+.;
+./cloudfront/code;
+./cloudfront/code/log4cplus;
+./cloudfront/code/log4cplus/include;
+./lib/libuv-v1.51.0/include;
+./pqdif;
+./pqdif/include;
+%(AdditionalIncludeDirectories)
-std=c++11 -O2 -static-libstdc++ -static-libgcc -pthread %(AdditionalOptions)
- D:\Git代码\frontlinux;D:\Git代码\frontlinux\LFtid1056\cloudfront\lib;$(RemoteRootDir)/cloudfront/lib;$(RemoteRootDir);/usr/lib64;/usr/local/lib;D:\Git代码\frontlinux\LFtid1056;./cloudfront/lib;./usr/lib64;./usr/local/lib;%(AdditionalLibraryDirectories)
+ /root/projects/LFtid1056/pqdif/lib
uv;pthread;dl;rt;stdc++fs;z;%(LibraryDependencies)
- /root/projects/LFtid1056/cloudfront/lib/librocketmq.a;/root/projects/LFtid1056/cloudfront/lib/libcurl.so;/root/projects/LFtid1056/cloudfront/lib/libssl.so;/root/projects/LFtid1056/cloudfront/lib/libcrypto.so;/root/projects/LFtid1056/cloudfront/lib/liblog4cplus.so;/root/projects/LFtid1056/libuv.a;%(AdditionalDependencies)
- -Wl,-rpath=/root/projects/LFtid1056/cloudfront/lib %(AdditionalOptions)
+ /root/projects/LFtid1056/pqdif/lib/libpqdiflib.a;/root/projects/LFtid1056/pqdif/lib/libz.a;%(AdditionalDependencies)
+ -Wl,-rpath=/root/projects/LFtid1056/cloudfront/lib -Wl,--start-group /root/projects/LFtid1056/pqdif/lib/libpqdiflib.a /root/projects/LFtid1056/pqdif/lib/libz.a -Wl,--end-group %(AdditionalOptions)
+
+
+ $(RemoteRootDir);
+$(RemoteRootDir)/cloudfront/code;
+$(RemoteRootDir)/cloudfront/code/log4cplus;
+$(RemoteRootDir)/cloudfront/code/log4cplus/include;
+$(RemoteRootDir)/lib/libuv-v1.51.0/include;
+$(RemoteRootDir)/pqdif;
+$(RemoteRootDir)/pqdif/include;
+D:\Git代码\frontlinux\LFtid1056;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code\log4cplus;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code\log4cplus\include;
+D:\Git代码\frontlinux\LFtid1056\lib\libuv-v1.51.0\include;
+D:\Git代码\frontlinux\LFtid1056\pqdif;
+D:\Git代码\frontlinux\LFtid1056\pqdif\include;
+.;
+./cloudfront/code;
+./cloudfront/code/log4cplus;
+./cloudfront/code/log4cplus/include;
+./lib/libuv-v1.51.0/include;
+./pqdif;
+./pqdif/include;
+%(AdditionalIncludeDirectories)
+
+
+ /root/projects/LFtid1056/pqdif/lib/libpqdiflib.a;/root/projects/LFtid1056/pqdif/lib/libz.a;%(AdditionalDependencies)
+ -Wl,-rpath=/root/projects/LFtid1056/cloudfront/lib -Wl,--start-group /root/projects/LFtid1056/pqdif/lib/libpqdiflib.a /root/projects/LFtid1056/pqdif/lib/libz.a -Wl,--end-group %(AdditionalOptions)
+ /root/projects/LFtid1056/pqdif/lib
+
+
+
+
+ $(RemoteRootDir);
+$(RemoteRootDir)/cloudfront/code;
+$(RemoteRootDir)/cloudfront/code/log4cplus;
+$(RemoteRootDir)/cloudfront/code/log4cplus/include;
+$(RemoteRootDir)/lib/libuv-v1.51.0/include;
+$(RemoteRootDir)/pqdif;
+$(RemoteRootDir)/pqdif/include;
+D:\Git代码\frontlinux\LFtid1056;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code\log4cplus;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code\log4cplus\include;
+D:\Git代码\frontlinux\LFtid1056\lib\libuv-v1.51.0\include;
+D:\Git代码\frontlinux\LFtid1056\pqdif;
+D:\Git代码\frontlinux\LFtid1056\pqdif\include;
+.;
+./cloudfront/code;
+./cloudfront/code/log4cplus;
+./cloudfront/code/log4cplus/include;
+./lib/libuv-v1.51.0/include;
+./pqdif;
+./pqdif/include;
+%(AdditionalIncludeDirectories)
+
+
+ /root/projects/LFtid1056/pqdif/lib/libpqdiflib.a;/root/projects/LFtid1056/pqdif/lib/libz.a;%(AdditionalDependencies)
+ -Wl,-rpath=/root/projects/LFtid1056/cloudfront/lib -Wl,--start-group /root/projects/LFtid1056/pqdif/lib/libpqdiflib.a /root/projects/LFtid1056/pqdif/lib/libz.a -Wl,--end-group %(AdditionalOptions)
+ /root/projects/LFtid1056/pqdif/lib
+
+
+
+
+ $(RemoteRootDir);
+$(RemoteRootDir)/cloudfront/code;
+$(RemoteRootDir)/cloudfront/code/log4cplus;
+$(RemoteRootDir)/cloudfront/code/log4cplus/include;
+$(RemoteRootDir)/lib/libuv-v1.51.0/include;
+$(RemoteRootDir)/pqdif;
+$(RemoteRootDir)/pqdif/include;
+D:\Git代码\frontlinux\LFtid1056;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code\log4cplus;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code\log4cplus\include;
+D:\Git代码\frontlinux\LFtid1056\lib\libuv-v1.51.0\include;
+D:\Git代码\frontlinux\LFtid1056\pqdif;
+D:\Git代码\frontlinux\LFtid1056\pqdif\include;
+.;
+./cloudfront/code;
+./cloudfront/code/log4cplus;
+./cloudfront/code/log4cplus/include;
+./lib/libuv-v1.51.0/include;
+./pqdif;
+./pqdif/include;
+%(AdditionalIncludeDirectories)
+
+
+ /root/projects/LFtid1056/pqdif/lib/libpqdiflib.a;/root/projects/LFtid1056/pqdif/lib/libz.a;%(AdditionalDependencies)
+ -Wl,-rpath=/root/projects/LFtid1056/cloudfront/lib -Wl,--start-group /root/projects/LFtid1056/pqdif/lib/libpqdiflib.a /root/projects/LFtid1056/pqdif/lib/libz.a -Wl,--end-group %(AdditionalOptions)
+ /root/projects/LFtid1056/pqdif/lib
+
+
+
+
+ $(RemoteRootDir);
+$(RemoteRootDir)/cloudfront/code;
+$(RemoteRootDir)/cloudfront/code/log4cplus;
+$(RemoteRootDir)/cloudfront/code/log4cplus/include;
+$(RemoteRootDir)/lib/libuv-v1.51.0/include;
+$(RemoteRootDir)/pqdif;
+$(RemoteRootDir)/pqdif/include;
+D:\Git代码\frontlinux\LFtid1056;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code\log4cplus;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code\log4cplus\include;
+D:\Git代码\frontlinux\LFtid1056\lib\libuv-v1.51.0\include;
+D:\Git代码\frontlinux\LFtid1056\pqdif;
+D:\Git代码\frontlinux\LFtid1056\pqdif\include;
+.;
+./cloudfront/code;
+./cloudfront/code/log4cplus;
+./cloudfront/code/log4cplus/include;
+./lib/libuv-v1.51.0/include;
+./pqdif;
+./pqdif/include;
+%(AdditionalIncludeDirectories)
+
+
+ /root/projects/LFtid1056/pqdif/lib/libpqdiflib.a;/root/projects/LFtid1056/pqdif/lib/libz.a;%(AdditionalDependencies)
+ -Wl,-rpath=/root/projects/LFtid1056/cloudfront/lib -Wl,--start-group /root/projects/LFtid1056/pqdif/lib/libpqdiflib.a /root/projects/LFtid1056/pqdif/lib/libz.a -Wl,--end-group %(AdditionalOptions)
+ /root/projects/LFtid1056/pqdif/lib
+
+
+
+
+ $(RemoteRootDir);
+$(RemoteRootDir)/cloudfront/code;
+$(RemoteRootDir)/cloudfront/code/log4cplus;
+$(RemoteRootDir)/cloudfront/code/log4cplus/include;
+$(RemoteRootDir)/lib/libuv-v1.51.0/include;
+$(RemoteRootDir)/pqdif;
+$(RemoteRootDir)/pqdif/include;
+D:\Git代码\frontlinux\LFtid1056;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code\log4cplus;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code\log4cplus\include;
+D:\Git代码\frontlinux\LFtid1056\lib\libuv-v1.51.0\include;
+D:\Git代码\frontlinux\LFtid1056\pqdif;
+D:\Git代码\frontlinux\LFtid1056\pqdif\include;
+.;
+./cloudfront/code;
+./cloudfront/code/log4cplus;
+./cloudfront/code/log4cplus/include;
+./lib/libuv-v1.51.0/include;
+./pqdif;
+./pqdif/include;
+%(AdditionalIncludeDirectories)
+
+
+ /root/projects/LFtid1056/pqdif/lib/libpqdiflib.a;/root/projects/LFtid1056/pqdif/lib/libz.a;%(AdditionalDependencies)
+ -Wl,-rpath=/root/projects/LFtid1056/cloudfront/lib -Wl,--start-group /root/projects/LFtid1056/pqdif/lib/libpqdiflib.a /root/projects/LFtid1056/pqdif/lib/libz.a -Wl,--end-group %(AdditionalOptions)
+ /root/projects/LFtid1056/pqdif/lib
+
+
+
+
+ $(RemoteRootDir);
+$(RemoteRootDir)/cloudfront/code;
+$(RemoteRootDir)/cloudfront/code/log4cplus;
+$(RemoteRootDir)/cloudfront/code/log4cplus/include;
+$(RemoteRootDir)/lib/libuv-v1.51.0/include;
+$(RemoteRootDir)/pqdif;
+$(RemoteRootDir)/pqdif/include;
+D:\Git代码\frontlinux\LFtid1056;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code\log4cplus;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code\log4cplus\include;
+D:\Git代码\frontlinux\LFtid1056\lib\libuv-v1.51.0\include;
+D:\Git代码\frontlinux\LFtid1056\pqdif;
+D:\Git代码\frontlinux\LFtid1056\pqdif\include;
+.;
+./cloudfront/code;
+./cloudfront/code/log4cplus;
+./cloudfront/code/log4cplus/include;
+./lib/libuv-v1.51.0/include;
+./pqdif;
+./pqdif/include;
+%(AdditionalIncludeDirectories)
+
+
+ /root/projects/LFtid1056/pqdif/lib/libpqdiflib.a;/root/projects/LFtid1056/pqdif/lib/libz.a;%(AdditionalDependencies)
+ -Wl,-rpath=/root/projects/LFtid1056/cloudfront/lib -Wl,--start-group /root/projects/LFtid1056/pqdif/lib/libpqdiflib.a /root/projects/LFtid1056/pqdif/lib/libz.a -Wl,--end-group %(AdditionalOptions)
+ /root/projects/LFtid1056/pqdif/lib
+
+
+
+
+ $(RemoteRootDir);
+$(RemoteRootDir)/cloudfront/code;
+$(RemoteRootDir)/cloudfront/code/log4cplus;
+$(RemoteRootDir)/cloudfront/code/log4cplus/include;
+$(RemoteRootDir)/lib/libuv-v1.51.0/include;
+$(RemoteRootDir)/pqdif;
+$(RemoteRootDir)/pqdif/include;
+D:\Git代码\frontlinux\LFtid1056;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code\log4cplus;
+D:\Git代码\frontlinux\LFtid1056\cloudfront\code\log4cplus\include;
+D:\Git代码\frontlinux\LFtid1056\lib\libuv-v1.51.0\include;
+D:\Git代码\frontlinux\LFtid1056\pqdif;
+D:\Git代码\frontlinux\LFtid1056\pqdif\include;
+.;
+./cloudfront/code;
+./cloudfront/code/log4cplus;
+./cloudfront/code/log4cplus/include;
+./lib/libuv-v1.51.0/include;
+./pqdif;
+./pqdif/include;
+%(AdditionalIncludeDirectories)
+
+
+ /root/projects/LFtid1056/pqdif/lib/libpqdiflib.a;/root/projects/LFtid1056/pqdif/lib/libz.a;%(AdditionalDependencies)
+ -Wl,-rpath=/root/projects/LFtid1056/cloudfront/lib -Wl,--start-group /root/projects/LFtid1056/pqdif/lib/libpqdiflib.a /root/projects/LFtid1056/pqdif/lib/libz.a -Wl,--end-group %(AdditionalOptions)
+ /root/projects/LFtid1056/pqdif/lib
+
+
\ No newline at end of file
diff --git a/LFtid1056/LFtid1056.vcxproj.filters b/LFtid1056/LFtid1056.vcxproj.filters
index 96eaa06..4ac9a20 100644
--- a/LFtid1056/LFtid1056.vcxproj.filters
+++ b/LFtid1056/LFtid1056.vcxproj.filters
@@ -26,6 +26,13 @@
cloudfront\code
+
+ pqdif
+
+
+ pqdif\include
+
+
@@ -559,6 +566,115 @@
cloudfront\code\log4cplus\thread\impl
+
+ pqdif
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
+ pqdif\include
+
+
@@ -633,6 +749,15 @@
{ca2cfaa3-ac76-42f8-a17f-67b4f693b719}
+
+ {d602780e-e7fa-4253-b532-afd407583f88}
+
+
+ {0e3fb7c4-4107-4518-b2ed-857f8c659fa0}
+
+
+ {721d48b7-af7b-4e48-84d2-21220c6534c3}
+
@@ -714,5 +839,11 @@
cloudfront\lib
+
+ pqdif\lib
+
+
+ pqdif\lib
+
\ No newline at end of file
diff --git a/LFtid1056/build.sh b/LFtid1056/build.sh
index 6be6c39..743a70a 100644
--- a/LFtid1056/build.sh
+++ b/LFtid1056/build.sh
@@ -19,7 +19,10 @@ $SRC_DIR/tinyxml2.cpp \
./client2.cpp \
./dealMsg.cpp \
./main_thread.cpp \
-./PQSMsg.cpp "
+./PQSMsg.cpp \
+./pqdif_thread_processor.cpp \
+./pqdif/PQDIF.cpp \
+./pqdif/include/cjson.c "
INCLUDE_DIRS="-I$SRC_DIR \
-I$SRC_DIR/nlohmann \
@@ -28,7 +31,9 @@ INCLUDE_DIRS="-I$SRC_DIR \
-I$SRC_DIR/rocketmq \
-I$SRC_DIR \
-I./lib/libuv-v1.51.0/include \
--I. "
+-I./pqdif \
+-I./pqdif/include \
+-I. "
LIB_DIRS="-L$LIB_DIR -L/usr/lib64 -L/usr/local/lib"
@@ -36,6 +41,8 @@ LIBS="./cloudfront/lib/libcurl.so \
./cloudfront/lib/libssl.so \
./cloudfront/lib/libcrypto.so \
./cloudfront/lib/liblog4cplus.so \
+./pqdif/lib/libpqdiflib.a \
+./pqdif/lib/libz.a \
-lpthread -ldl -lrt \
-lstdc++fs \
-lz \
diff --git a/LFtid1056/main_thread.cpp b/LFtid1056/main_thread.cpp
index af43e85..624a965 100644
--- a/LFtid1056/main_thread.cpp
+++ b/LFtid1056/main_thread.cpp
@@ -7,6 +7,7 @@
#include "client2.h"
#include "cloudfront/code/interface.h"
+#include "pqdif_thread_processor.h"
#include
#include
#include
@@ -35,7 +36,7 @@ typedef struct {
#endif
extern std::atomic INITFLAG;//̨˵ȳʼɱ־
-//extern void cleanup_args(ThreadArgs* args);
+//extern void cleanup_args(ThreadArgs* args);00:B7:8D:A8:00:D6 00:B7:8D:00:A9:03
void init_daemon(void)
{
@@ -66,53 +67,9 @@ void init_daemon(void)
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,
- 1,
- 0.0, // ѹֵ
- 0.0,
- 100.0,
- 80.0
- },
- {
- "P" + dev_id.substr(1) + "02", // ID P00102
- "Current " + dev_name,
- dev_id,
- 2,
- 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-D6", // MACַ
- 1, // ״̬ (1=)
- points
- });
- }
-
- return devices;
-}
+bool PQD_FLAG = false;//pqd߳־ ߳رй߳ ⲿ
+//̨˴ӡ
void PrintDevices(const std::vector& devices) {
std::cout << "==== Devices List (" << devices.size() << ") ====\n";
for (const auto& dev : devices) {
@@ -139,7 +96,7 @@ void PrintDevices(const std::vector& devices) {
}
}
-/* ̹߳ 0߳*/
+/* ̹߳ 1߳*/
/* ͻӹ̺߳*/
void* client_manager_thread(void* arg) {
int index = *(int*)arg;
@@ -171,9 +128,6 @@ void* client_manager_thread(void* arg) {
// }
//};
- // 100װ
- //std::vector test_devices = generate_test_devices(100);
-
//lnk̨˶ȡ豸
std::vector devices = GenerateDeviceInfoFromLedger(terminal_devlist);//lnk
@@ -192,7 +146,7 @@ void* client_manager_thread(void* arg) {
pthread_mutex_unlock(&thread_info[index].lock);
return NULL;
}
-/* ̹߳ 1߳*/
+/* ̹߳ 2߳*/
/* Ϣ̺߳ */
void* message_processor_thread(void* arg) {
int index = *(int*)arg;
@@ -230,6 +184,39 @@ void* message_processor_thread(void* arg) {
pthread_mutex_unlock(&thread_info[index].lock);
return NULL;
}
+/* ̹߳ 3߳*/
+/* PQDIF̺߳*/
+void* pqd_thread(void* arg)
+{
+ int index = *(int*)arg;
+ free(arg);
+
+ pthread_mutex_lock(&thread_info[index].lock);
+ printf("PQDIF Thread %d started\n", index);
+ thread_info[index].state = THREAD_RUNNING;
+ pthread_mutex_unlock(&thread_info[index].lock);
+
+ try
+ {
+ // PQDIF ɨ߳
+ RunPqdifScanLoop();
+ }
+ catch (const std::exception& ex)
+ {
+ printf("PQDIF Thread %d exception: %s\n", index, ex.what());
+ }
+ catch (...)
+ {
+ printf("PQDIF Thread %d exception: unknown\n", index);
+ }
+
+ pthread_mutex_lock(&thread_info[index].lock);
+ thread_info[index].state = THREAD_STOPPED;
+ printf("PQDIF Thread %d stopped\n", index);
+ pthread_mutex_unlock(&thread_info[index].lock);
+ return NULL;
+}
+
/* ߳ */
void restart_thread(int index) {
@@ -270,7 +257,7 @@ void restart_thread(int index) {
thread_info[index].state = THREAD_CRASHED;
pthread_mutex_unlock(&global_lock);
}
- } else if (index == 1) {
+ } else if (index == 1 && !PQD_FLAG) {
// ͻ˹߳
int* new_index = (int*)malloc(sizeof(int));
if (!new_index) {
@@ -282,15 +269,14 @@ void restart_thread(int index) {
}
*new_index = index;
- if (pthread_create(&thread_info[index].tid, NULL,
- client_manager_thread, new_index) != 0) {
+ if (pthread_create(&thread_info[index].tid, NULL,client_manager_thread, new_index) != 0) {
pthread_mutex_lock(&global_lock);
printf("Failed to restart client manager thread %d\n", index);
thread_info[index].state = THREAD_CRASHED;
pthread_mutex_unlock(&global_lock);
free(new_index); // ʧܲԼ freeɹʱ߳ free
}
- } else if (index == 2) {
+ } else if (index == 2 && !PQD_FLAG) {
// Ϣ߳
int* new_index = (int*)malloc(sizeof(int));
if (!new_index) {
@@ -302,61 +288,36 @@ void restart_thread(int index) {
}
*new_index = index;
- if (pthread_create(&thread_info[index].tid, NULL,
- message_processor_thread, new_index) != 0) {
+ if (pthread_create(&thread_info[index].tid, NULL,message_processor_thread, new_index) != 0) {
pthread_mutex_lock(&global_lock);
printf("Failed to restart message processor thread %d\n", index);
thread_info[index].state = THREAD_CRASHED;
pthread_mutex_unlock(&global_lock);
free(new_index);
}
+ } else if(index == 3 && PQD_FLAG){
+ //PQDIF߳ ̲߳
+ int* new_index = (int*)malloc(sizeof(int));
+ if (!new_index) {
+ pthread_mutex_lock(&global_lock);
+ printf("Failed to malloc for message processor thread %d\n", index);
+ thread_info[index].state = THREAD_CRASHED;
+ pthread_mutex_unlock(&global_lock);
+ return;
+ }
+ *new_index = index;
+
+ if (pthread_create(&thread_info[index].tid, NULL, pqd_thread, new_index) != 0) {
+ pthread_mutex_lock(&global_lock);
+ printf("Failed to restart message processor thread %d\n", index);
+ thread_info[index].state = THREAD_CRASHED;
+ pthread_mutex_unlock(&global_lock);
+ free(new_index);
+ }
+
} else {
// ߳ݲ
-
}
-
- /*// ߳
- int* new_index = (int*)malloc(sizeof(int));
- *new_index = index;
-
- if (index == 1) {
- // ͻ˹߳
- if (pthread_create(&thread_info[index].tid, NULL, client_manager_thread, new_index) != 0) {
- pthread_mutex_lock(&global_lock);
- printf("Failed to restart client manager thread %d\n", index);
- thread_info[index].state = THREAD_CRASHED;
- pthread_mutex_unlock(&global_lock);
- free(new_index);
- }
- }
- else if (index == 2) {
- // Ϣ߳
- if (pthread_create(&thread_info[index].tid, NULL, message_processor_thread, new_index) != 0) {
- pthread_mutex_lock(&global_lock);
- printf("Failed to restart message processor thread %d\n", index);
- thread_info[index].state = THREAD_CRASHED;
- pthread_mutex_unlock(&global_lock);
- free(new_index);
- }
- }
- else if (index == 0) {
- // ӿڣmq
- //char* argv[] = { (char*)new_index };//Ҫ̺Ų
- // ThreadArgs* args = new ThreadArgs{1, argv};
- if (pthread_create(&thread_info[index].tid, NULL, cloudfrontthread, new_index) != 0) {
- pthread_mutex_lock(&global_lock);
- printf("Failed to restart message processor thread %d\n", index);
- thread_info[index].state = THREAD_CRASHED;
- pthread_mutex_unlock(&global_lock);
- //delete args; // ߳ûɹֶͷ
- free(new_index);
- }
- }
- else {
- // ߳
- // ΪգʵӦп߳
- }*/
-
}
/* ̴߳ */
@@ -364,16 +325,6 @@ int is_thread_alive(pthread_t tid) {
return pthread_tryjoin_np(tid, NULL) == EBUSY; // EBUSYʾ߳
}
-//lnk
-/*ThreadArgs* make_thread_args_from_strs(const std::vector& args_vec) {
- char** argv = new char*[args_vec.size() + 1]; // һ nullptr β
- for (size_t i = 0; i < args_vec.size(); ++i) {
- argv[i] = strdup(args_vec[i].c_str()); // strdup malloc
- }
- argv[args_vec.size()] = nullptr;
- return new ThreadArgs{static_cast(args_vec.size()), argv};
-}*/
-
/* */
int main(int argc ,char** argv) {//Ӳ
if(!parse_param(argc,argv)){
@@ -407,29 +358,26 @@ int main(int argc ,char** argv) {//
int* index = (int*)malloc(sizeof(int));
*index = i;
- if (i == 1) {
+ if (i == 1 && !PQD_FLAG) {
// ͻ˹߳
- if (pthread_create(&thread_info[i].tid, NULL, client_manager_thread, index) != 0) {
+ if (pthread_create(&thread_info[i].tid, NULL, client_manager_thread, index) != 0 ) {
printf("Failed to create client manager thread %d\n", i);
free(index);
}
}
- else if (i == 2) {
+ else if (i == 2 && !PQD_FLAG) {
// Ϣ߳
- if (pthread_create(&thread_info[i].tid, NULL, message_processor_thread, index) != 0) {
+ if (pthread_create(&thread_info[i].tid, NULL, message_processor_thread, index) != 0 ) {
printf("Failed to create message processor thread %d\n", i);
free(index);
}
}
- else if (i == 3){
- /*//ӿںmq
- char* argv[] = { (char*)index };//Ҫ̺Ų
- ThreadArgs* args = new ThreadArgs{1, argv};
- if (pthread_create(&thread_info[i].tid, NULL, cloudfrontthread, args) != 0) {
- printf("Failed to create message processor thread %d\n", i);
- delete args; // ߳ûɹֶͷ
+ else if (i == 3 && PQD_FLAG){
+ //PQDIF߳ ʱֹ߳ͣ
+ if (pthread_create(&thread_info[i].tid, NULL, pqd_thread, index) != 0) {
+ printf("Failed to create pqd_thread %d\n", i);
free(index);
- }*/
+ }
}
else {
// ߳
@@ -465,59 +413,12 @@ int main(int argc ,char** argv) {//
}
}
- /*//
- std::vector points2 = {
- {"P101", "Generator Output", "D002",1 ,1, 1, 1, 1,"0.38k",0}
- };
- //00B78DA800D6 00-B7-8D-01-79-06 00-B7-8D-A8-00-D6
- // װб
- std::vector devices = {
- {
- "D002", "Backup Device", "Model-Y", "00-B7-8D-A8-00-D6",
- 1, points2,true
- }
- };*/
-
- //
- //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 = {
- // {
- // "D001", "Primary Device", "Model-X", "00-B7-8D-01-88-7f",
- // 1, points1,true
- // },
- // {
- // "D002", "Primary Device1", "Model-X1", "00-B7-8D-01-71-09",
- // 1, points2,true
- // }
- //};
-
// socket״̬
static int queue_monitor = 0;
static bool flag = false;
- //static int count = 3;
- if (++queue_monitor >= 60) { // һ豸
+ if (++queue_monitor >= 60) {
printf("Message queue size: %zu\n", message_queue.size());
queue_monitor = 0;
- /*if (flag) {
- flag = false;
- for (const auto& device : devices) {
- ClientManager::instance().add_device(device);
- }
- }
- else {
- flag = true;
- ClientManager::instance().remove_device("D001");
- ClientManager::instance().remove_device("D002");
- }*/
}
}
diff --git a/LFtid1056/pqdif/PQDIF.cpp b/LFtid1056/pqdif/PQDIF.cpp
new file mode 100644
index 0000000..6760d68
--- /dev/null
+++ b/LFtid1056/pqdif/PQDIF.cpp
@@ -0,0 +1,1562 @@
+#include "PQDIF.h"
+#include "pqdsupport.h"
+#include "cjson.h"
+#include
+#include
+#include
+#include
+#include
+
+CPQDIF::CPQDIF()
+{
+ // Init
+ m_percont = (CPQDIF_PC_FlatFile *)theFactory.NewPersistController(PFPC_FlatFile);
+}
+
+CPQDIF::~CPQDIF()
+{
+ // Destroy
+ delete m_percont;
+}
+
+void CPQDIF::GetTime(DATE dt, time_t* tm)
+{
+ *tm = (time_t)((double)(dt - EXCEL_DAYCOUNT_ADJUST + 1) * (double)SECONDS_PER_DAY - 8 * 60 * 60);//EXCEL_DAYCOUNT_ADJUSTΪ19701900 8*60*60ΪUTCʱ
+
+}
+
+void CPQDIF::put_FlatFileName(string strFileName)
+{
+ // // AFX_MANAGE_STATE(AfxGetStaticModuleState())
+
+ m_percont->SetFileName(strFileName.c_str());
+
+}
+
+bool CPQDIF::Read()
+{
+ // QT Ŀ ReadHeaders() int ״̬
+ // 0 ʾɹʾʧ
+ int rc = m_percont->ReadHeaders();
+
+#ifdef __linux__
+ printf("[PQDIF] ReadHeaders rc=%d\n", rc);
+#endif
+
+ return (rc == 0);
+}
+
+bool CPQDIF::Close()
+{
+ // AFX_MANAGE_STATE(AfxGetStaticModuleState())
+
+ return New();
+}
+
+bool CPQDIF::New()
+{
+ // AFX_MANAGE_STATE(AfxGetStaticModuleState())
+ bool ret = false;
+ // Destroy & re-create
+ if (m_percont)
+ delete m_percont;
+
+ m_percont = (CPQDIF_PC_FlatFile *)theFactory.NewPersistController(PFPC_FlatFile);
+
+ if (m_percont)
+ ret = true;
+ else
+ ret = false;
+
+ return ret;
+}
+
+long CPQDIF::RecordGetCount()
+{
+ // AFX_MANAGE_STATE(AfxGetStaticModuleState())
+
+ return (long)m_percont->GetRecordCount();
+
+}
+
+
+bool CPQDIF::RecordGetInfo
+(
+ long index,
+ GUID * tagRecordType,
+ string & nameRecordType
+)
+{
+ // AFX_MANAGE_STATE(AfxGetStaticModuleState())
+
+ bool status = false;
+
+ CPQDIFRecord * prec;
+ GUID tagRecord;
+ string nameTag;
+
+ try
+ {
+ prec = m_percont->GetRecord(index);
+ if (prec)
+ {
+ //ASSERT_VALID(prec);
+
+ // Get header info
+ prec->HeaderGetTag(tagRecord);
+
+ // Return the data...
+ // The GUID itself
+ *tagRecordType=tagRecord;
+
+ // The GUID name
+ nameTag = theInfo.GetNameOfTag(tagRecord);
+ nameRecordType=nameTag;
+
+
+ status = true;
+ }
+ }
+ // catch( ... )
+ catch (...)
+ {
+ // // e->Delete();
+ status = false;
+ }
+
+ return status;
+}
+
+bool CPQDIF::RecordRequestObservation(long index, long * pRecordObserv)
+{
+
+ bool status = false;
+ CPQDIFRecord * precBase;
+ CPQDIFRecord * precCurrent = NULL;
+ CPQDIFRecord * precDS = NULL;
+ CPQDIFRecord * precSett = NULL;
+ CPQDIF_R_Observation * pobs = NULL;
+
+ GUID tagRecord;
+ long idxRec;
+
+ try
+ {
+ // Find the observation and associated data source
+ precBase = m_percont->GetRecordFull(index);
+ if (precBase)
+ {
+ // Is this an observation?
+ precBase->HeaderGetTag(tagRecord);
+ if (PQDIF_IsEqualGUID(tagRecord, tagRecObservation))
+ {
+ // Find its data source...
+ // Search backward through the record list.
+ for (idxRec = index - 1; idxRec >= 0; idxRec--)
+ {
+
+ // Are we still looking for the DS?
+ if (!precDS)
+ {
+ precCurrent = m_percont->GetRecord(idxRec);
+ precCurrent->HeaderGetTag(tagRecord);
+ if (PQDIF_IsEqualGUID(tagRecord, tagRecDataSource))
+ {
+ // Found it!
+ precDS = m_percont->GetRecordFull(idxRec);
+ status = true;
+ // We're cool even if we just find this one. We should break at this point,
+ // because we won't find any valid settings records *before* it!
+ break;
+ }
+ }
+
+ // Are we still looking for the settings?
+ if (!precSett)
+ {
+ precCurrent = m_percont->GetRecord(idxRec);
+ precCurrent->HeaderGetTag(tagRecord);
+ if (PQDIF_IsEqualGUID(tagRecord, tagRecMonitorSettings))
+ {
+ // Found it!
+ precSett = m_percont->GetRecordFull(idxRec);
+ // precSett is not required, so we don't change
+ // the value of status.
+ }
+ }
+ } // for( records )
+ }
+ } // if( found obs record )
+
+ if (status && precBase && precDS)
+ {
+ pobs = theFactory.NewObservationWrapper2(precBase, precDS, precSett);
+ if (pobs)
+ {
+ *pRecordObserv = (long)pobs;
+ status = true;
+ }
+ }
+ else
+ {
+ if (precBase)
+ {
+ pobs = theFactory.NewObservationWrapper2(precBase, precDS, precSett);
+ if (pobs)
+ {
+ *pRecordObserv = (long)pobs;
+ status = true;
+ }
+ }
+ }
+ }
+ catch (...)
+ {
+ // e->Delete();
+ status = false;
+ }
+
+ return status;
+}
+
+
+bool CPQDIF::ObservationGetInfo(long pRecordObserv, DATE& timeStart, string& name, long& countChannels)
+{
+ // AFX_MANAGE_STATE(AfxGetStaticModuleState())
+
+ bool status = false;
+ CPQDIF_R_Observation * pobs;
+ TIMESTAMPPQDIF timeStartLocal;
+ TIMESTAMPPQDIF timeCreateLocal;
+ // string nameLocal;
+ string nameLocal;
+
+ countChannels = 0;
+ timeStart = -1;
+ try
+ {
+ pobs = ValidateObservation(pRecordObserv);
+ if (pobs)
+ {
+ // Get channel count
+ countChannels = pobs->GetCountChannels();
+
+ // Get time & name
+ status = pobs->GetInfo(timeStartLocal, timeCreateLocal, nameLocal);
+
+ // Transfer info over
+ if (status)
+ {
+ status = SetDateFromTimeStamp(timeStart, timeStartLocal);
+ //status = theSupport.SetDateFromTimeStamp( *timeCreate, timeCreateLocal );
+
+ name = nameLocal;
+ }
+
+ }
+
+
+ }
+ catch (...)
+ {
+ // e->Delete();
+ status = false;
+ }
+
+
+ return status;
+}
+
+bool CPQDIF::ObservationGetTriggerInfo(long pRecordObserv, long * idTriggerMethod, DATE * timeTriggered)
+{
+ // AFX_MANAGE_STATE(AfxGetStaticModuleState())
+
+ bool status = false;
+ CPQDIF_R_Observation * pobs;
+
+ UINT4 idTriggerMethodLocal;
+ CPQDIF_E_Vector * pvectTriggerChanIdx = NULL;
+ TIMESTAMPPQDIF timeTriggeredLocal;
+
+ *idTriggerMethod = -1;
+ try
+ {
+ pobs = ValidateObservation(pRecordObserv);
+ if (pobs)
+ {
+ status = pobs->GetTriggerInfo(idTriggerMethodLocal, &pvectTriggerChanIdx, timeTriggeredLocal);
+ if (status)
+ {
+ status = SetDateFromTimeStamp(*timeTriggered, timeTriggeredLocal);
+ }
+
+ // Copy this one anyway...
+ *idTriggerMethod = (long)idTriggerMethodLocal;
+ }
+
+
+ }
+ catch (...)
+ {
+ // e->Delete();
+ status = false;
+ }
+
+ return status;
+}
+
+bool CPQDIF::ObservationGetChannelInfo(long pRecordObserv, long idxChannel, string &name, long * countSeries)
+{
+ // AFX_MANAGE_STATE(AfxGetStaticModuleState())
+
+ bool status = false;
+ CPQDIF_R_Observation * pobs;
+
+ string nameLocal;
+ UINT4 idPhaseLocal;
+ GUID idQuantityTypeLocal;
+ UINT4 idQuantityMeasuredLocal;
+
+ try
+ {
+ pobs = ValidateObservation(pRecordObserv);
+ if (pobs)
+ {
+ // Make sure we're in the right range.
+ if (idxChannel >= 0 && idxChannel < pobs->GetCountChannels())
+ {
+ *countSeries = pobs->GetCountSeries(idxChannel);
+
+ // Get full channel info
+ status = pobs->GetChannelInfo(idxChannel, nameLocal, idPhaseLocal, idQuantityTypeLocal, idQuantityMeasuredLocal);
+ if (status)
+ {
+ name = nameLocal;
+ }
+ }
+ }
+
+
+ }
+ catch (...)
+ {
+ // e->Delete();
+ status = false;
+ }
+
+
+ return status;
+}
+
+bool CPQDIF::ObservationGetSeriesInfo3(long pRecordObserv, long idxChannel, long idxSeries, long * idQuantityUnits, GUID * idQuantityCharacteristic, GUID * idValueType)
+{
+ bool status = false;
+ CPQDIF_R_Observation * pobs;
+
+ UINT4 idQuantityUnitsLocal;
+ GUID idValueTypeLocal;
+ GUID idQuantityCharacteristicLocal;
+
+ try
+ {
+ pobs = ValidateObservation(pRecordObserv);
+ if (pobs)
+ {
+ status = pobs->GetSeriesInfo(idxChannel, idxSeries, idQuantityUnitsLocal, idQuantityCharacteristicLocal, idValueTypeLocal);
+ if (status)
+ {
+ // Translate information
+ *idQuantityUnits = (long)idQuantityUnitsLocal;
+ *idValueType=idValueTypeLocal;
+ *idQuantityCharacteristic=idQuantityCharacteristicLocal;
+ }
+ }
+
+
+ }
+ catch (...)
+ {
+ // e->Delete();
+ status = false;
+ }
+
+ return status;
+}
+
+//עҪdouble* Ϊڲ̬ڴ棬ʹҪͷ
+bool CPQDIF::ObservationGetSeriesData(long pRecordObserv, long idxChannel, long idxSeries, double ** values,long* varCount)
+{
+ // AFX_MANAGE_STATE(AfxGetStaticModuleState())
+
+ bool status = false;
+ CPQDIF_R_Observation * pobs;
+ double * pvalues;
+ long countPoints;
+
+ try
+ {
+ pobs = ValidateObservation(pRecordObserv);
+ if (pobs)
+ {
+ pvalues = pobs->NewResolvedSeries(idxChannel, idxSeries, countPoints);
+ if (pvalues)
+ {
+ *values= pvalues;
+ status = true;
+ *varCount = countPoints;
+ //delete[] pvalues;
+ }
+ }
+
+
+ }
+ catch (...)
+ {
+ // e->Delete();
+ status = false;
+ }
+
+ return status;
+}
+
+bool CPQDIF::ObservationGetChannelFreq(long pRecObs, long idxChannel, double * freq)
+{
+ bool status = false;
+
+ CPQDIF_R_Observation * pobs;
+
+ try
+ {
+ pobs = ValidateObservation(pRecObs);
+ if (pobs)
+ {
+ CPQDIF_E_Collection * pcol = pobs->GetOneChannel(idxChannel);
+
+ if (pcol)
+ {
+ CPQDIF_E_Scalar * psc = pobs->FindScalarInCollection(pcol, tagChannelFrequency);
+ if (psc)
+ {
+ double val;
+ psc->GetValueREAL8(val);
+ if (freq)
+ {
+ *freq = val;
+ status = true;
+ }
+ }
+ }
+ }
+ }
+ catch (...)
+ {
+ // e->Delete();
+ status = false;
+ }
+
+ return status;
+}
+
+bool CPQDIF::ObservationGetChannelGroupID(long pRecObs, long idxChannel, int *GroupID)
+{
+
+ bool status = false;
+
+ CPQDIF_R_Observation * pobs;
+
+ try
+ {
+ pobs = ValidateObservation(pRecObs);
+ if (pobs)
+ {
+ CPQDIF_E_Collection * pcol = pobs->GetOneChannel(idxChannel);
+
+ if (pcol)
+ {
+ CPQDIF_E_Scalar * psc = pobs->FindScalarInCollection(pcol, tagChannelGroupID);
+ if (psc)
+ {
+ INT2 val = 0;
+ bool bOk = psc->GetValueINT2(val);
+ if (bOk == true)
+ {
+ if (GroupID)
+ {
+ *GroupID = val;
+ status = true;
+ }
+ }
+ else
+ {
+ UINT2 val = 0;
+ psc->GetValueUINT2(val);
+ if (GroupID)
+ {
+ *GroupID = val;
+ status = true;
+ }
+ }
+ }
+ }
+ }
+ }
+ catch (...)
+ {
+ // e->Delete();
+ status = false;
+ }
+
+
+ return status;
+}
+
+
+bool CPQDIF::ObservationGetSeriesPhasicType(long pRecordObserv, long idxChannel, long idxSeries, long *valuetypes)
+{
+
+ bool status = false;
+ CPQDIF_R_Observation * pobs;
+
+ try
+ {
+ pobs = ValidateObservation(pRecordObserv);
+ if (pobs)
+ {
+ long lvalue = 0;
+ status = pobs->GetSeriesBaseType(idxChannel, idxSeries, lvalue);
+ if (status)
+ *valuetypes = lvalue;
+
+ }
+
+
+ }
+ catch (...)
+ {
+ // e->Delete();
+ status = false;
+ }
+
+ return status;
+}
+
+
+bool CPQDIF::ObservationGetSeriesScale(long pRecObs, long idxChannel, long idxSeries, double * scale, double * offset)
+{
+ // AFX_MANAGE_STATE(AfxGetStaticModuleState())
+
+ bool status = false;
+
+ CPQDIF_R_Observation * pobs;
+
+ try
+ {
+ pobs = ValidateObservation(pRecObs);
+ if (pobs)
+ {
+ status = pobs->GetSeriesScale(idxChannel, idxSeries, *scale, *offset);
+ }
+ }
+ catch (...)
+ {
+ // e->Delete();
+ status = false;
+ }
+
+
+ return status;
+}
+
+
+bool CPQDIF::RecordReleaseObservation(long pRecordObserv)
+{
+ // AFX_MANAGE_STATE(AfxGetStaticModuleState())
+
+ bool status = false;
+ CPQDIF_R_Observation * pobs;
+
+ pobs = ValidateObservation(pRecordObserv);
+ if (pobs)
+ {
+ delete pobs;
+ status = true;
+ }
+
+ return status;
+}
+//protected
+
+bool CPQDIF::SetDateFromTimeStamp(DATE& date, const TIMESTAMPPQDIF& ts)
+{
+ date = (double)ts.day
+ + ((double)ts.sec / (double)SECONDS_PER_DAY);
+
+ return true;
+}
+
+CPQDIF_Element * CPQDIF::ValidateElement(long pElement)
+{
+ // AFX_MANAGE_STATE(AfxGetStaticModuleState())
+
+ CPQDIF_Element * pel;
+
+ pel = (CPQDIF_Element *)pElement;
+ //ASSERT_VALID(pel);
+
+ return pel;
+}
+
+
+CPQDIF_E_Collection * CPQDIF::ValidateCollection(long pElement)
+{
+ // AFX_MANAGE_STATE(AfxGetStaticModuleState())
+
+ CPQDIF_Element * pel;
+ CPQDIF_E_Collection * pcoll = NULL;
+
+ pel = (CPQDIF_Element *)pElement;
+ //ASSERT_VALID(pel);
+ if (pel)
+ {
+ if (pel->GetElementType() == ID_ELEMENT_TYPE_COLLECTION)
+ {
+ pcoll = (CPQDIF_E_Collection *)pel;
+ //ASSERT_VALID(pcoll);
+ }
+ }
+
+ return pcoll;
+}
+
+
+// Validates a scalar handle and returns the object pointer.
+// For internal use.
+//
+// Returns
+// -------
+// Valid object pointer The object is valid and of the correct type
+// NULL The object is invalid or has an incorrect type
+//
+CPQDIF_E_Scalar * CPQDIF::ValidateScalar(long pElement)
+{
+ // AFX_MANAGE_STATE(AfxGetStaticModuleState())
+
+ CPQDIF_Element * pel;
+ CPQDIF_E_Scalar * pscalar = NULL;
+
+ pel = (CPQDIF_Element *)pElement;
+ //ASSERT_VALID(pel);
+ if (pel)
+ {
+ if (pel->GetElementType() == ID_ELEMENT_TYPE_SCALAR)
+ {
+ pscalar = (CPQDIF_E_Scalar *)pel;
+ //ASSERT_VALID(pscalar);
+ }
+ }
+
+ return pscalar;
+}
+
+
+// Validates a vector handle and returns the object pointer.
+// For internal use.
+//
+// Returns
+// -------
+// Valid object pointer The object is valid and of the correct type
+// NULL The object is invalid or has an incorrect type
+//
+CPQDIF_E_Vector * CPQDIF::ValidateVector(long pElement)
+{
+ // AFX_MANAGE_STATE(AfxGetStaticModuleState())
+
+ CPQDIF_Element * pel;
+ CPQDIF_E_Vector * pvector = NULL;
+
+ pel = (CPQDIF_Element *)pElement;
+ //ASSERT_VALID(pel);
+ if (pel)
+ {
+ if (pel->GetElementType() == ID_ELEMENT_TYPE_VECTOR)
+ {
+ pvector = (CPQDIF_E_Vector *)pel;
+ //ASSERT_VALID(pvector);
+ }
+ }
+
+ return pvector;
+}
+
+
+// Validates a observation record handle and returns the object pointer.
+// For internal use.
+//
+// Returns
+// -------
+// Valid object pointer The object is valid and of the correct type
+// NULL The object is invalid or has an incorrect type
+//
+CPQDIF_R_Observation * CPQDIF::ValidateObservation(long pRecObserv)
+{
+ // AFX_MANAGE_STATE(AfxGetStaticModuleState())
+
+ CPQDIFRecord * prec;
+ CPQDIF_R_Observation * pobs = NULL;
+ GUID tagThisRecord;
+
+ prec = (CPQDIFRecord *)pRecObserv;
+ //ASSERT_VALID(prec);
+ if (prec)
+ {
+ prec->HeaderGetTag(tagThisRecord);
+ if (PQDIF_IsEqualGUID(tagThisRecord, tagRecObservation))
+ {
+ pobs = (CPQDIF_R_Observation *)prec;
+ //ASSERT_VALID(pobs);
+ }
+ }
+
+ return pobs;
+}
+
+void testjson()
+{
+ //{ "emspq1":[{ "type":1,"min":"{str}" },{ "type":2,"min":"{str2}" }],"emspq2":[{ "type":3,"min":"{str3}" },{ "type":4,"min":"{str4}" }] }
+ //
+ cJSON* root = cJSON_CreateObject();
+
+ // emspq1
+ cJSON* emspq1_array = cJSON_CreateArray();
+ cJSON_AddItemToObject(root, "emspq1", emspq1_array);
+
+ // emspq1Ӷ
+ cJSON* emspq1_obj1 = cJSON_CreateObject();
+ cJSON_AddNumberToObject(emspq1_obj1, "type", 1);
+ cJSON_AddStringToObject(emspq1_obj1, "min", "{str}");
+ cJSON_AddItemToArray(emspq1_array, emspq1_obj1);
+
+ cJSON* emspq1_obj2 = cJSON_CreateObject();
+ cJSON_AddNumberToObject(emspq1_obj2, "type", 2);
+ cJSON_AddStringToObject(emspq1_obj2, "min", "{str2}");
+ cJSON_AddItemToArray(emspq1_array, emspq1_obj2);
+
+ // emspq2
+ cJSON* emspq2_array = cJSON_CreateArray();
+ cJSON_AddItemToObject(root, "emspq2", emspq2_array);
+
+ // emspq2Ӷ
+ cJSON* emspq2_obj1 = cJSON_CreateObject();
+ cJSON_AddNumberToObject(emspq2_obj1, "type", 3);
+ cJSON_AddStringToObject(emspq2_obj1, "min", "{str3}");
+ cJSON_AddItemToArray(emspq2_array, emspq2_obj1);
+
+ cJSON* emspq2_obj2 = cJSON_CreateObject();
+ cJSON_AddNumberToObject(emspq2_obj2, "type", 4);
+ cJSON_AddStringToObject(emspq2_obj2, "min", "{str4}");
+ cJSON_AddItemToArray(emspq2_array, emspq2_obj2);
+
+ // лJSONΪַ
+ char* json_string = cJSON_Print(root);
+ printf("%s\n", json_string);
+
+ // ͷڴ
+ free(json_string); // ͷ JSON ַռõڴ
+ cJSON_Delete(root); // ͷ cJSON ռõڴ
+
+ printf("testjson \n");
+
+
+}
+
+char* CDeal::AssJson(char* Id) //װjsonṹ
+{
+ //
+ cJSON* root = cJSON_CreateObject();
+
+ for (std::list::iterator tableIt = DataTableList.begin(); tableIt != DataTableList.end(); ++tableIt) {
+ CTable* table = *tableIt;
+ //printf("TableName = %s || table->DateSeqList siez = %d\n", table->TableName.c_str(), table->DateSeqList.size());
+ // emspq1
+ cJSON* emspq1_array = cJSON_CreateArray();
+ cJSON_AddItemToObject(root, table->TableName.c_str(), emspq1_array);
+
+ // б
+ for (std::list::iterator seqIt = table->DateSeqList.begin(); seqIt != table->DateSeqList.end(); ++seqIt) {
+ CSeq* seq = *seqIt;
+ //printf("telemetryType = %s || seq->DateItemList siez = %d\n", seq->telemetryType.c_str(), seq->DateItemList.size());
+
+ // emspq1Ӷ
+ cJSON* emspq1_obj1 = cJSON_CreateObject();
+ cJSON_AddStringToObject(emspq1_obj1, seq->jsonname.c_str(), seq->telemetryType.c_str());
+ // б
+ for (std::list::iterator itemIt = seq->DateItemList.begin(); itemIt != seq->DateItemList.end(); ++itemIt) {
+ CItem* item = *itemIt;
+ //printf("KeyName = %s || DateName = %s\n", item->KeyName.c_str(), item->DateName.c_str());
+
+ if (item->Type == "Avg")
+ {
+ std::map< std::string, std::list >::iterator it = AvgData.find(item->DateName);
+ if (it != AvgData.end())
+ {
+ int i = 1;
+ if (stringToTimeT(dataDate) != -1) {
+ std::map< std::string, int >::iterator it = aggCydeMinList.find(item->DateName);
+ if (it != aggCydeMinList.end())
+ {
+ i = getCurrentGroup(stringToTimeT(dataDate), it->second);
+ }
+ else
+ {
+ i = getCurrentGroup(stringToTimeT(dataDate), aggCydeMin);
+ }
+ }
+ bool isFirst = true; // ǷǵһԪ
+ std::ostringstream count;
+ count << "{";
+ for (std::list::iterator itm = it->second.begin(); itm != it->second.end(); ++itm) {
+ if (!isFirst) {
+ // ǵһԪأ
+ count << ",";
+ }
+ count << "\"P" << i++ << "\":" << *itm;
+ isFirst = false; // ѾǵһԪ
+ }
+ count << "}";
+ std::string count_str = count.str();
+ cJSON_AddStringToObject(emspq1_obj1, item->KeyName.c_str(), count_str.c_str());
+ }
+ }
+ if (item->Type == "Max")
+ {
+ std::map< std::string, std::list >::iterator it = MaxData.find(item->DateName);
+ if (it != MaxData.end())
+ {
+ int i = 1;
+ if (stringToTimeT(dataDate) != -1) {
+ std::map< std::string, int >::iterator it = aggCydeMinList.find(item->DateName);
+ if (it != aggCydeMinList.end())
+ {
+ i = getCurrentGroup(stringToTimeT(dataDate), it->second);
+ }
+ else
+ {
+ i = getCurrentGroup(stringToTimeT(dataDate), aggCydeMin);
+ }
+ }
+ bool isFirst = true; // ǷǵһԪ
+ std::ostringstream count;
+ count << "{";
+ for (std::list::iterator itm = it->second.begin(); itm != it->second.end(); ++itm) {
+ if (!isFirst) {
+ // ǵһԪأ
+ count << ",";
+ }
+ count << "\"P" << i++ << "\":" << *itm;
+ isFirst = false; // ѾǵһԪ
+ }
+ count << "}";
+ std::string count_str = count.str();
+ cJSON_AddStringToObject(emspq1_obj1, item->KeyName.c_str(), count_str.c_str());
+ }
+ }
+ if (item->Type == "Min")
+ {
+ std::map< std::string, std::list >::iterator it = MinData.find(item->DateName);
+ if (it != MinData.end())
+ {
+ int i = 1;
+ if (stringToTimeT(dataDate) != -1) {
+ std::map< std::string, int >::iterator it = aggCydeMinList.find(item->DateName);
+ if (it != aggCydeMinList.end())
+ {
+ i = getCurrentGroup(stringToTimeT(dataDate), it->second);
+ }
+ else
+ {
+ i = getCurrentGroup(stringToTimeT(dataDate), aggCydeMin);
+ }
+ }
+ bool isFirst = true; // ǷǵһԪ
+ std::ostringstream count;
+ count << "{";
+ for (std::list::iterator itm = it->second.begin(); itm != it->second.end(); ++itm) {
+ if (!isFirst) {
+ // ǵһԪأ
+ count << ",";
+ }
+ count << "\"P" << i++ << "\":" << *itm;
+ isFirst = false; // ѾǵһԪ
+ }
+ count << "}";
+ std::string count_str = count.str();
+ cJSON_AddStringToObject(emspq1_obj1, item->KeyName.c_str(), count_str.c_str());
+ }
+ }
+ if (item->Type == "CP95")
+ {
+ std::map< std::string, std::list >::iterator it = CP95Data.find(item->DateName);
+ if (it != CP95Data.end())
+ {
+ int i = 1;
+ if (stringToTimeT(dataDate) != -1) {
+ std::map< std::string, int >::iterator it = aggCydeMinList.find(item->DateName);
+ if (it != aggCydeMinList.end())
+ {
+ i = getCurrentGroup(stringToTimeT(dataDate), it->second);
+ }
+ else
+ {
+ i = getCurrentGroup(stringToTimeT(dataDate), aggCydeMin);
+ }
+ }
+ bool isFirst = true; // ǷǵһԪ
+ std::ostringstream count;
+ count << "{";
+ for (std::list::iterator itm = it->second.begin(); itm != it->second.end(); ++itm) {
+ if (!isFirst) {
+ // ǵһԪأ
+ count << ",";
+ }
+ count << "\"P" << i++ << "\":" << *itm;
+ isFirst = false; // ѾǵһԪ
+ }
+ count << "}";
+ std::string count_str = count.str();
+ cJSON_AddStringToObject(emspq1_obj1, item->KeyName.c_str(), count_str.c_str());
+ }
+ }
+ if (item->Type == "Val")
+ {
+ std::map< std::string, std::list >::iterator it = ValData.find(item->DateName);
+ if (it != ValData.end())
+ {
+ int i = 1;
+ if (stringToTimeT(dataDate) != -1) {
+ std::map< std::string, int >::iterator it = aggCydeMinList.find(item->DateName);
+ if (it != aggCydeMinList.end())
+ {
+ i = getCurrentGroup(stringToTimeT(dataDate), it->second);
+ }
+ else
+ {
+ i = getCurrentGroup(stringToTimeT(dataDate), aggCydeMin);
+ }
+ }
+ bool isFirst = true; // ǷǵһԪ
+ std::ostringstream count;
+ count << "{";
+ for (std::list::iterator itm = it->second.begin(); itm != it->second.end(); ++itm) {
+ if (!isFirst) {
+ // ǵһԪأ
+ count << ",";
+ }
+ count << "\"P" << i++ << "\":" << *itm;
+ isFirst = false; // ѾǵһԪ
+ }
+ count << "}";
+ std::string count_str = count.str();
+ cJSON_AddStringToObject(emspq1_obj1, item->KeyName.c_str(), count_str.c_str());
+ }
+ }
+ if (item->Type == "Null")
+ {
+ if (item->DateName == "monitorId") // ID
+ {
+ cJSON_AddStringToObject(emspq1_obj1, item->KeyName.c_str(), Id);
+ }
+
+ // ַԭʼַеλ
+ size_t pos = item->DateName.find("-dataDate-pt");
+ // ҵַ
+ if (pos != std::string::npos) {
+ cJSON_AddStringToObject(emspq1_obj1, item->KeyName.c_str(), convertToDateOnly(dataDatePT).c_str());
+ continue;
+ }
+ pos = item->DateName.find("-dataDate-all");
+ // ҵַ
+ if (pos != std::string::npos) {
+ cJSON_AddStringToObject(emspq1_obj1, item->KeyName.c_str(), convertToDateOnly(dataDate).c_str());
+ continue;
+ }
+ pos = item->DateName.find("-aggCydeMin-pst");
+ // ҵַ
+ if (pos != std::string::npos && ShortFlag == 1) {
+ std::ostringstream count;
+ count << aggCycleMinShort;
+ std::string count_str = count.str();
+ cJSON_AddStringToObject(emspq1_obj1, item->KeyName.c_str(), count_str.c_str());
+ continue;
+ }
+ pos = item->DateName.find("-aggCydeMin-plt");
+ // ҵַ
+ if (pos != std::string::npos && LongFlag == 1) {
+ std::ostringstream count;
+ count << aggCycleMinLong;
+ std::string count_str = count.str();
+ cJSON_AddStringToObject(emspq1_obj1, item->KeyName.c_str(), count_str.c_str());
+ continue;
+ }
+ pos = item->DateName.find("-aggCydeMin-flu");
+ // ҵַ
+ if (pos != std::string::npos && FluFlag == 1) {
+ std::ostringstream count;
+ count << fluCydeMin;
+ std::string count_str = count.str();
+ cJSON_AddStringToObject(emspq1_obj1, item->KeyName.c_str(), count_str.c_str());
+ continue;
+ }
+ pos = item->DateName.find("-aggCydeMin-all");
+ // ҵַ
+ if (pos != std::string::npos) {
+ std::ostringstream count;
+ count << aggCydeMin;
+ std::string count_str = count.str();
+ cJSON_AddStringToObject(emspq1_obj1, item->KeyName.c_str(), count_str.c_str());
+ continue;
+ }
+ }
+ }
+ cJSON_AddItemToArray(emspq1_array, emspq1_obj1);
+ }
+ }
+
+ // лJSONΪַ
+ char* json_string = cJSON_Print(root);
+ //printf("%s\n", json_string);
+
+ // ͷڴ
+ //free(json_string); // ͷ JSON ַռõڴ
+ cJSON_Delete(root); // ͷ cJSON ռõڴ
+ return json_string;
+}
+
+bool CDeal::ExtractNumbersBetweenPercent(const std::string& str, int& start, int& end) {
+ size_t pos_start = str.find('%');
+ if (pos_start == std::string::npos) {
+ // ûҵ'%'ַ
+ return false;
+ }
+
+ size_t pos_end = str.find('%', pos_start + 1);
+ if (pos_end == std::string::npos) {
+ // ûҵڶ'%'ַ
+ return false;
+ }
+
+ std::istringstream iss(str.substr(pos_start + 1, pos_end - pos_start - 1));
+ char comma;
+ if (!(iss >> start >> comma >> end)) {
+ // ַȡ
+ return false;
+ }
+
+ return true;
+}
+
+void CDeal::CheckDataTableList()
+{
+ for (std::list::iterator tableIt = DataTableList.begin(); tableIt != DataTableList.end(); ++tableIt) {
+ CTable* table = *tableIt;
+ // б
+ for (std::list::iterator seqIt = table->DateSeqList.begin(); seqIt != table->DateSeqList.end(); ++seqIt) {
+ CSeq* seq = *seqIt;
+ // б
+ for (std::list::iterator itemIt = seq->DateItemList.begin(); itemIt != seq->DateItemList.end(); ++itemIt) {
+ CItem* item = *itemIt;
+ if (item->Type == "Null")
+ {
+ {
+ std::string str = item->DateName;
+ std::string substr = "-dataDate-pt";
+
+ // ַԭʼַеλ
+ size_t pos = str.find(substr);
+
+ // ҵַ
+ if (pos != std::string::npos) {
+ // ҵλÿʼɾַȵַ
+ str.erase(pos, substr.length());
+ std::map< std::string, std::string >::iterator it = DateData.find(str);
+ if (it != DateData.end())
+ {
+ std::ostringstream count;
+ count << it->second;
+ std::string count_str = count.str();
+ dataDatePT = count_str;
+ }
+ continue;
+ }
+ }
+ {
+ std::string str = item->DateName;
+ std::string substr = "-dataDate-all";
+
+ // ַԭʼַеλ
+ size_t pos = str.find(substr);
+
+ // ҵַ
+ if (pos != std::string::npos) {
+ // ҵλÿʼɾַȵַ
+ str.erase(pos, substr.length());
+ std::map< std::string, std::string >::iterator it = DateData.find(str);
+ if (it != DateData.end())
+ {
+ std::ostringstream count;
+ count << it->second;
+ std::string count_str = count.str();
+ dataDate = count_str;
+ }
+ continue;
+ }
+ }
+ {
+ std::string str = item->DateName;
+ std::string substr = "-aggCydeMin-pst";
+
+ // ַԭʼַеλ
+ size_t pos = str.find(substr);
+
+ // ҵַ
+ if (pos != std::string::npos) {
+ // ҵλÿʼɾַȵַ
+ str.erase(pos, substr.length());
+ std::map< std::string, std::list >::iterator it = TimeData.find(str);
+ if (it != TimeData.end())
+ {
+ ShortFlag = 1;//ôڶ
+ // ȡlist
+ const std::list& list_values = it->second;
+
+ // ȡlistĸ
+ std::list::size_type list_size = list_values.size();
+
+ // listԪأȡǰֵ
+ if (list_size >= 2) {
+ // ʹõʵһԪ
+ std::list::const_iterator it_first = list_values.begin();
+ // ʹõʵڶԪ
+ std::list::const_iterator it_second = it_first;
+ ++it_second; // ָڶԪ
+
+ aggCycleMinShort = *it_second - *it_first;
+ aggCycleMinShort = aggCycleMinShort / 60;
+ }
+ aggCydeMinList[str] = aggCycleMinShort;
+ }
+ continue;
+ }
+ }
+ {
+ std::string str = item->DateName;
+ std::string substr = "-aggCydeMin-plt";
+
+ // ַԭʼַеλ
+ size_t pos = str.find(substr);
+
+ // ҵַ
+ if (pos != std::string::npos) {
+ // ҵλÿʼɾַȵַ
+ str.erase(pos, substr.length());
+ std::map< std::string, std::list >::iterator it = TimeData.find(str);
+ if (it != TimeData.end())
+ {
+ LongFlag = 1;//ôڶ
+ // ȡlist
+ const std::list& list_values = it->second;
+
+ // ȡlistĸ
+ std::list::size_type list_size = list_values.size();
+
+ // listԪأȡǰֵ
+ if (list_size >= 2) {
+ // ʹõʵһԪ
+ std::list::const_iterator it_first = list_values.begin();
+ // ʹõʵڶԪ
+ std::list::const_iterator it_second = it_first;
+ ++it_second; // ָڶԪ
+
+ aggCycleMinLong = *it_second - *it_first;
+ aggCycleMinLong = aggCycleMinLong / 60;
+ }
+ aggCydeMinList[str] = aggCycleMinLong;
+ }
+ continue;
+ }
+ }
+ {
+ std::string str = item->DateName;
+ std::string substr = "-aggCydeMin-flu";
+
+ // ַԭʼַеλ
+ size_t pos = str.find(substr);
+
+ // ҵַ
+ if (pos != std::string::npos) {
+ // ҵλÿʼɾַȵַ
+ str.erase(pos, substr.length());
+ std::map< std::string, std::list >::iterator it = TimeData.find(str);
+ if (it != TimeData.end())
+ {
+ FluFlag = 1;//ôڶ
+ // ȡlist
+ const std::list& list_values = it->second;
+
+ // ȡlistĸ
+ std::list::size_type list_size = list_values.size();
+
+ // listԪأȡǰֵ
+ if (list_size >= 2) {
+ // ʹõʵһԪ
+ std::list::const_iterator it_first = list_values.begin();
+ // ʹõʵڶԪ
+ std::list::const_iterator it_second = it_first;
+ ++it_second; // ָڶԪ
+
+ fluCydeMin = *it_second - *it_first;
+ fluCydeMin = fluCydeMin / 60;
+ }
+ aggCydeMinList[str] = fluCydeMin;
+ }
+ continue;
+ }
+ }
+ {
+ std::string str = item->DateName;
+ std::string substr = "-aggCydeMin-all";
+
+ // ַԭʼַеλ
+ size_t pos = str.find(substr);
+
+ // ҵַ
+ if (pos != std::string::npos) {
+ // ҵλÿʼɾַȵַ
+ str.erase(pos, substr.length());
+ std::map< std::string, std::list >::iterator it = TimeData.find(str);
+ if (it != TimeData.end())
+ {
+ // ȡlist
+ const std::list& list_values = it->second;
+
+ // ȡlistĸ
+ std::list::size_type list_size = list_values.size();
+
+ // listԪأȡǰֵ
+ if (list_size >= 2) {
+ // ʹõʵһԪ
+ std::list::const_iterator it_first = list_values.begin();
+ // ʹõʵڶԪ
+ std::list::const_iterator it_second = it_first;
+ ++it_second; // ָڶԪ
+
+ aggCydeMin = *it_second - *it_first;
+ aggCydeMin = aggCydeMin / 60;
+ }
+
+ }
+ continue;
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+void CDeal::ResJsonCfg(char* json)
+{
+ // ļ·
+ std::ifstream file(json);
+
+ // ļǷɹ
+ if (!file.is_open()) {
+ printf("can not open file:%s \n", json);
+ return;
+ }
+
+ // ȡļݵַ
+ std::ostringstream ss;
+ ss << file.rdbuf();
+ std::string json_string = ss.str();
+
+ //printf("%s \n", json_string.c_str());
+
+ // رļ
+ file.close();
+
+ cJSON* root = cJSON_Parse(json_string.c_str());
+
+ if (root == NULL) {
+ printf("Error before: [%s]\n", cJSON_GetErrorPtr());
+ return;
+ }
+
+ // JSONеÿ
+ int count = cJSON_GetArraySize(root);
+ for (int i = 0; i < count; i++) {
+ cJSON* item = cJSON_GetArrayItem(root, i);
+
+ // ȡ"table"ֶ
+ const char* table = cJSON_GetObjectItemCaseSensitive(item, "table")->valuestring;
+ CTable* ctable = new CTable(table);
+ DataTableList.push_back(ctable);
+ //printf("Table: %s\n", ctable->TableName.c_str());
+
+ // "cfg"ֶ
+ cJSON* cfg = cJSON_GetObjectItemCaseSensitive(item, "cfg");
+ // "TELEMETRYTYPE"
+ cJSON* telemetry_types = cJSON_GetObjectItemCaseSensitive(cfg, "TELEMETRYTYPE");
+ int telemetry_count = cJSON_GetArraySize(telemetry_types);
+ for (int i = 0; i < telemetry_count; i++) {
+ cJSON* telemetry = cJSON_GetArrayItem(telemetry_types, i);
+ const char* seq = cJSON_GetObjectItemCaseSensitive(telemetry, "seq")->valuestring;
+ const char* key_name = cJSON_GetObjectItemCaseSensitive(telemetry, "KeyName")->valuestring;
+ const char* json_name = cJSON_GetObjectItemCaseSensitive(telemetry, "JsonName")->valuestring;
+ CSeq* cseq = new CSeq(seq, key_name, json_name);
+ ctable->DateSeqList.push_back(cseq);
+ //printf(" Telemetry: Seq=%s, KeyName=%s\n", seq, key_name);
+
+ // "Item"飨ƵشֶΣ
+ cJSON* items = cJSON_GetObjectItemCaseSensitive(cfg, "Item");
+ int item_count = cJSON_GetArraySize(items);
+ for (int i = 0; i < item_count; i++) {
+ cJSON* item = cJSON_GetArrayItem(items, i);
+ const char* key_name = cJSON_GetObjectItemCaseSensitive(item, "KeyName")->valuestring;
+ const char* data_name = cJSON_GetObjectItemCaseSensitive(item, "DataName")->valuestring; //const char* data_name = "V HRMS A[%2,25%]"
+ const char* type = cJSON_GetObjectItemCaseSensitive(item, "Type")->valuestring;
+ std::string str_key_name(key_name); // const char*תΪstd::string
+ std::string str_data_name(data_name); // const char*תΪstd::string
+ size_t pos;
+ while ((pos = str_data_name.find('*')) != std::string::npos) {
+ str_data_name.replace(pos, 1, seq);
+ }
+ int start = 0, end = 0;
+ if (ExtractNumbersBetweenPercent(str_data_name,start,end))
+ {
+ //printf(" Item: start=%d, end=%d\n", start,end);
+ for (int i = start; i <= end; i++) {
+ std::string str_key_name_temp = str_key_name;
+ std::string str_data_name_temp = str_data_name;
+ std::ostringstream oss;
+ oss << "%" << start << "," << end << "%";
+ std::string result = oss.str();
+
+ std::ostringstream count;
+ count << i;
+ std::string count_str = count.str();
+
+ size_t pos = str_data_name.find(result);
+ if (pos != std::string::npos) {
+ str_data_name_temp.replace(pos, result.length(), count_str); // 滻6ַȵӴ
+ //str_key_name_temp.replace(pos, result.length(), count_str);
+ }
+ pos = str_key_name.find(result);
+ if (pos != std::string::npos) {
+ //str_data_name_temp.replace(pos, result.length(), count_str); // 滻6ַȵӴ
+ str_key_name_temp.replace(pos, result.length(), count_str);
+ }
+
+ CItem* citem = new CItem(str_key_name_temp.c_str(), str_data_name_temp.c_str(), type);
+ cseq->DateItemList.push_back(citem);
+ //printf(" Item: KeyName=%s, DataName=%s, Type=%s\n", str_key_name_temp.c_str(), str_data_name_temp.c_str(), type);
+ }
+ }
+ else
+ {
+ CItem* citem = new CItem(key_name, str_data_name.c_str(), type);
+ cseq->DateItemList.push_back(citem);
+ //printf(" Item: KeyName=%s, DataName=%s, Type=%s\n", key_name, str_data_name.c_str(), type);
+ }
+ }
+ }
+
+ }
+
+ // ͷcJSONռõڴ
+ cJSON_Delete(root);
+}
+
+cJSON* CDeal::cJSON_GetObjectItemCaseSensitive(cJSON* object, const char* string) {
+ cJSON* c = object->child;
+ while (c) {
+ if (strcmp(c->string, string) == 0) {
+ return c;
+ }
+ c = c->next;
+ }
+ return NULL;
+}
+
+std::string CDeal::convertToDateOnly(const std::string& dateTime) {
+ size_t spacePos = dateTime.find(' '); // ѰҿոλãԷָںʱ
+ if (spacePos != std::string::npos) {
+ return dateTime.substr(0, spacePos); // شַʼո֮ǰӴ
+ }
+ return dateTime; // ûҵոԭַȻв̫ܷ
+}
+
+int CDeal::getCurrentGroup(const std::time_t& currentTime,int min) {
+ // time_tתΪtmṹ
+ std::tm* localTime = std::localtime(¤tTime);
+
+ // ҹʼǰʱܷ
+ int totalMinutes = localTime->tm_hour * 60 + localTime->tm_min;
+
+ // ÿķ
+ const int groupSize = min;
+
+ //
+ // ʹܷСȻȡõ
+ // ټΪʱһ飨˵һĿʼм䣩
+ int groupNumber = totalMinutes / groupSize;
+ if (totalMinutes % groupSize != 0) {
+ groupNumber++; // һ
+ }
+ groupNumber++;//ݴ0ʼ ±1ʼ ±ֵ1
+ return groupNumber;
+}
+
+std::time_t CDeal::stringToTimeT(const std::string& dateTime) {
+ std::tm tm{};
+
+ // strptime is not standard C++ but is available on many systems (POSIX)
+ strptime(dateTime.c_str(), "%Y-%m-%d %H:%M:%S", &tm);
+
+ // Convert tm to time_t
+ std::time_t currentTime = std::mktime(&tm);
+ if (currentTime == -1) {
+ std::cerr << "Error converting string to time_t." << std::endl;
+ // Handle the error as needed
+ }
+
+ return currentTime;
+}
+
+void CDeal::clear()
+{
+ // AvgDataͬʱͷlistеڴ棨еĻͨlistҪֶͷţ
+ AvgData.clear();
+ // MaxData
+ MaxData.clear();
+ // MinData
+ MinData.clear();
+ // CP95Data
+ CP95Data.clear();
+ // ValData
+ ValData.clear();
+ // TimeData
+ TimeData.clear();
+ // DateDatavaluestd::stringҪֶͷڴ棩
+ DateData.clear();
+ // aggCydeMinList
+ aggCydeMinList.clear();
+
+ // DataTableListͷÿCTableڴ
+ for (std::list::iterator it = DataTableList.begin(); it != DataTableList.end(); ++it) {
+ delete* it; // ͷڴ
+ }
+ DataTableList.clear(); // беָ
+}
+
+bool CPQDIF::ObservationGetChannelInfoEx(long pRecordObserv, long idxChannel, PqdifChannelInfoEx* out)
+{
+ if (out == nullptr)
+ return false;
+
+ bool status = false;
+ CPQDIF_R_Observation* pobs = nullptr;
+
+ try
+ {
+ pobs = ValidateObservation(pRecordObserv);
+ if (pobs)
+ {
+ if (idxChannel >= 0 && idxChannel < pobs->GetCountChannels())
+ {
+ std::string nameLocal;
+ UINT4 idPhaseLocal = 0;
+ GUID idQuantityTypeLocal{};
+ UINT4 idQuantityMeasuredLocal = 0;
+
+ out->countSeries = pobs->GetCountSeries(idxChannel);
+
+ status = pobs->GetChannelInfo(
+ idxChannel,
+ nameLocal,
+ idPhaseLocal,
+ idQuantityTypeLocal,
+ idQuantityMeasuredLocal
+ );
+
+ if (status)
+ {
+ out->name = nameLocal;
+ out->phaseId = static_cast(idPhaseLocal);
+ out->quantityTypeId = idQuantityTypeLocal;
+ out->quantityMeasuredId = static_cast(idQuantityMeasuredLocal);
+ }
+ }
+ }
+ }
+ catch (...)
+ {
+ status = false;
+ }
+
+ return status;
+}
+
+bool CPQDIF::ObservationGetSeriesInfoEx(long pRecordObserv, long idxChannel, long idxSeries, PqdifSeriesInfoEx* out)
+{
+ if (out == nullptr)
+ return false;
+
+ bool status = false;
+ CPQDIF_R_Observation* pobs = nullptr;
+
+ try
+ {
+ pobs = ValidateObservation(pRecordObserv);
+ if (pobs)
+ {
+ UINT4 idQuantityUnitsLocal = 0;
+ GUID idQuantityCharacteristicLocal{};
+ GUID idValueTypeLocal{};
+
+ status = pobs->GetSeriesInfo(
+ idxChannel,
+ idxSeries,
+ idQuantityUnitsLocal,
+ idQuantityCharacteristicLocal,
+ idValueTypeLocal
+ );
+
+ if (status)
+ {
+ out->quantityUnitsId = static_cast(idQuantityUnitsLocal);
+ out->quantityCharacteristicId = idQuantityCharacteristicLocal;
+ out->valueTypeId = idValueTypeLocal;
+
+ long baseType = -1;
+ if (pobs->GetSeriesBaseType(idxChannel, idxSeries, baseType))
+ {
+ out->seriesBaseType = baseType;
+ }
+
+ double scale = 1.0;
+ double offset = 0.0;
+ if (pobs->GetSeriesScale(idxChannel, idxSeries, scale, offset))
+ {
+ out->scale = scale;
+ out->offset = offset;
+ }
+ }
+ }
+ }
+ catch (...)
+ {
+ status = false;
+ }
+
+ return status;
+}
\ No newline at end of file
diff --git a/LFtid1056/pqdif/PQDIF.h b/LFtid1056/pqdif/PQDIF.h
new file mode 100644
index 0000000..c0a0356
--- /dev/null
+++ b/LFtid1056/pqdif/PQDIF.h
@@ -0,0 +1,193 @@
+#pragma once
+
+#include
+#include
+#include
+#include
+#include
+#include