345 lines
9.5 KiB
C
345 lines
9.5 KiB
C
|
|
/**
|
|||
|
|
* @file: $RCSfile: save2json.h,v $
|
|||
|
|
* @brief: $IEC 61850 Protocol
|
|||
|
|
*
|
|||
|
|
* @version: $Revision: 1.5 $
|
|||
|
|
* @date: $Date: 2018/12/23 12:39:52 $
|
|||
|
|
* @author: $Author: lizhongming $
|
|||
|
|
* @state: $State: Exp $
|
|||
|
|
*
|
|||
|
|
* @latest: $Id: save2json.h,v 1.5 2018/12/23 12:39:52 lizhongming Exp $
|
|||
|
|
*
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
#ifndef SAVE2DB_8ue3hy0923r_H
|
|||
|
|
#define SAVE2DB_8ue3hy0923r_H
|
|||
|
|
#ifdef __cplusplus
|
|||
|
|
extern "C" {
|
|||
|
|
#endif
|
|||
|
|
extern int g_front_seg_index;
|
|||
|
|
#ifdef __cplusplus
|
|||
|
|
}
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
#ifdef __cplusplus
|
|||
|
|
|
|||
|
|
#include <string>
|
|||
|
|
#include <vector>
|
|||
|
|
#include <map>
|
|||
|
|
#include <list>
|
|||
|
|
|
|||
|
|
#include <QThread>
|
|||
|
|
|
|||
|
|
//lnk20250106
|
|||
|
|
#include "../include/rocketmq/SimpleProducer.h"
|
|||
|
|
#include <QTcpServer>
|
|||
|
|
#include <QTcpSocket>
|
|||
|
|
#include <QMutex>
|
|||
|
|
#include <QMutexLocker>
|
|||
|
|
#include <QDebug>
|
|||
|
|
#include <QTimer>
|
|||
|
|
#include <QCoreApplication>
|
|||
|
|
#include <QStringList>
|
|||
|
|
|
|||
|
|
#include <iostream>
|
|||
|
|
extern int G_TEST_NUM;
|
|||
|
|
extern void ledger(const char* terminal_id = NULL,QIODevice* outputDevice = NULL);
|
|||
|
|
extern int TEST_PORT;
|
|||
|
|
|
|||
|
|
//////////////////////////////////////////////////////////////////////////////
|
|||
|
|
//struct json_pair_info
|
|||
|
|
//{
|
|||
|
|
// string topic; //<Topic name="HISDATA" desc="<22><>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD>"> "RTDATA" ʵʱ<CAB5><CAB1><EFBFBD><EFBFBD> "RTDATASOE"ʵʱSOE<4F>¼<EFBFBD> <20><>
|
|||
|
|
// string data_type; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>01/04:<3A><>̬/<2F>ٲ<EFBFBD><D9B2><EFBFBD>̬<EFBFBD><CCAC>02/05:<3A><><EFBFBD><EFBFBD>/<2F>ٲ<EFBFBD><D9B2><EFBFBD><EFBFBD>䣬03/06:<3A><>̬/<2F>ٲ<EFBFBD><D9B2><EFBFBD>̬
|
|||
|
|
// string item; //<Item name="V" desc="<22><>ѹ" type="4" > <20><>"I" "PQ" <20><>
|
|||
|
|
// string sequence; //"A" <20><> "B" <20><> "C" <20><> "T"
|
|||
|
|
// string name; //json<6F><6E>key
|
|||
|
|
// int type; //6-ֵ<><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>9-ʵʱSOE<4F>¼<EFBFBD>
|
|||
|
|
// string mms_ref; //mms<6D><73>ַ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
|
// float coeff; //Coefficient:<3A><><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5>
|
|||
|
|
// unsigned short PltFlag; //0xffff
|
|||
|
|
//};
|
|||
|
|
|
|||
|
|
/////////////////////////////////////////////////////////////////////////////
|
|||
|
|
|
|||
|
|
class KafkaSendThread : public QThread
|
|||
|
|
{
|
|||
|
|
// Q_OBJECT
|
|||
|
|
//public:
|
|||
|
|
|
|||
|
|
protected:
|
|||
|
|
void run();
|
|||
|
|
};
|
|||
|
|
//WW 2023-08-22 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF>̺߳<DFB3>WebSocket<65>߳<EFBFBD>
|
|||
|
|
class SQLExcuteThread : public QThread
|
|||
|
|
{
|
|||
|
|
protected:
|
|||
|
|
void run();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
class WebSocketThread : public QThread
|
|||
|
|
{
|
|||
|
|
protected:
|
|||
|
|
void run();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
//lnk20241029
|
|||
|
|
class WebhttpThread : public QThread
|
|||
|
|
{
|
|||
|
|
protected:
|
|||
|
|
void run();
|
|||
|
|
};
|
|||
|
|
class httpThread : public QThread
|
|||
|
|
{
|
|||
|
|
protected:
|
|||
|
|
void run();
|
|||
|
|
};
|
|||
|
|
//lnk20241202
|
|||
|
|
/*class mqtestThread : public QThread
|
|||
|
|
{
|
|||
|
|
protected:
|
|||
|
|
void run();
|
|||
|
|
};*/
|
|||
|
|
//lnk20250106
|
|||
|
|
//ʹ<><CAB9>telnet 127.0.0.1 12345<34><35><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
class Worker : public QObject
|
|||
|
|
{
|
|||
|
|
Q_OBJECT
|
|||
|
|
|
|||
|
|
public:
|
|||
|
|
Worker(QObject *parent = NULL) : QObject(parent), server(NULL), TEST_NUM(G_TEST_NUM) {}
|
|||
|
|
~Worker() {
|
|||
|
|
if (server) {
|
|||
|
|
server->close();
|
|||
|
|
delete server;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public slots:
|
|||
|
|
void startServer() {
|
|||
|
|
server = new QTcpServer();
|
|||
|
|
connect(server, SIGNAL(newConnection()), this, SLOT(onNewConnection()));
|
|||
|
|
|
|||
|
|
if (!server->listen(QHostAddress::Any, TEST_PORT)) {
|
|||
|
|
std::cout << "Server failed to start!" << std::endl;
|
|||
|
|
qDebug() << "Server failed to start!";
|
|||
|
|
delete server;
|
|||
|
|
server = NULL;
|
|||
|
|
emit serverError();
|
|||
|
|
return;
|
|||
|
|
} else {
|
|||
|
|
std::cout << "Server is running on port " << TEST_PORT << std::endl;
|
|||
|
|
qDebug() << QString("Server is running on port %1").arg(TEST_PORT);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
timer = new QTimer(this);
|
|||
|
|
connect(timer, SIGNAL(timeout()), this, SLOT(doPeriodicTask()));
|
|||
|
|
timer->start(60000); // ÿ60<36>봥<EFBFBD><EBB4A5>һ<EFBFBD><D2BB>
|
|||
|
|
|
|||
|
|
std::cout << "Timer started, event loop running in thread: " << QThread::currentThreadId() << std::endl;
|
|||
|
|
qDebug() << "Timer started, event loop running in thread:" << QThread::currentThreadId();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void setTestNum(int num) {
|
|||
|
|
QMutexLocker locker(&mutex);
|
|||
|
|
TEST_NUM = num;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private slots:
|
|||
|
|
void doPeriodicTask() {
|
|||
|
|
QMutexLocker locker(&mutex);
|
|||
|
|
std::cout << "Executing TEST_NUM is " << TEST_NUM << std::endl;
|
|||
|
|
qDebug() << "doPeriodicTask() called. TEST_NUM = " << TEST_NUM;
|
|||
|
|
|
|||
|
|
if (TEST_NUM != 0) {
|
|||
|
|
qDebug() << "Executing rocketmq_test_300()";
|
|||
|
|
std::cout << "Executing rocketmq_test_300()\n";
|
|||
|
|
rocketmq_test_300(TEST_NUM, g_front_seg_index);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void onNewConnection() {
|
|||
|
|
if (!server) return;
|
|||
|
|
|
|||
|
|
QTcpSocket *clientSocket = server->nextPendingConnection();
|
|||
|
|
qDebug() << "New connection established!";
|
|||
|
|
std::cout << "New connection established!\n";
|
|||
|
|
|
|||
|
|
connect(clientSocket, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>ͻ<EFBFBD><CDBB>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>
|
|||
|
|
if (clientSocket) {
|
|||
|
|
std::cout << "clientSocket OK\n";
|
|||
|
|
clientSocket->write("Welcome to the test shell. Type 'help' for available commands.\n> ");
|
|||
|
|
clientSocket->flush(); // ȷ<><C8B7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void onReadyRead() {
|
|||
|
|
QTcpSocket *clientSocket = qobject_cast<QTcpSocket *>(sender());
|
|||
|
|
std::cout << "onReadyRead\n";
|
|||
|
|
if (!clientSocket) {
|
|||
|
|
std::cout << "Invalid socket\n";
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
std::cout << "read all\n";
|
|||
|
|
|
|||
|
|
QByteArray data = clientSocket->readAll();
|
|||
|
|
QString command = QString::fromUtf8(data).trimmed(); // <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ<EEB2A2><C8A5>ǰ<EFBFBD><C7B0><EFBFBD>ո<EFBFBD>
|
|||
|
|
|
|||
|
|
qDebug() << "Received command:" << command;
|
|||
|
|
std::cout << "Received command: " << command.toStdString() << "\n";
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>ͻ<EFBFBD><CDBB>˷<EFBFBD><CBB7>͡<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>롱<EFBFBD><EBA1B1><EFBFBD><EFBFBD>
|
|||
|
|
clientSocket->write("Received command\n> ");
|
|||
|
|
clientSocket->flush();
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ʾ<EFBFBD><CABE>
|
|||
|
|
clientSocket->write("test_shell> ");
|
|||
|
|
clientSocket->flush(); // ȷ<><C8B7><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD> TEST_NUM
|
|||
|
|
if (command.startsWith("TEST_NUM=")) {
|
|||
|
|
bool ok;
|
|||
|
|
int num = command.mid(9).toInt(&ok); // <20><>ȡ<EFBFBD>Ⱥź<C8BA><C5BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD>
|
|||
|
|
if (ok) {
|
|||
|
|
setTestNum(num); // <20><><EFBFBD><EFBFBD> TEST_NUM
|
|||
|
|
clientSocket->write("TEST_NUM updated\n> ");
|
|||
|
|
std::cout << "TEST_NUM updated\n";
|
|||
|
|
} else {
|
|||
|
|
clientSocket->write("Invalid number\n> ");
|
|||
|
|
std::cout << "Invalid number\n";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// <20><><EFBFBD><EFBFBD> rc <20><><EFBFBD><EFBFBD>
|
|||
|
|
else if (command.startsWith("rc")) {
|
|||
|
|
qDebug() << "Executing rocketmq_test_rc()";
|
|||
|
|
std::cout << "Executing rocketmq_test_rc()\n";
|
|||
|
|
rocketmq_test_rc(); // <20><><EFBFBD><EFBFBD> rc <20><><EFBFBD><EFBFBD>
|
|||
|
|
clientSocket->write("Executed rocketmq_test_rc\n> ");
|
|||
|
|
}
|
|||
|
|
// <20><><EFBFBD><EFBFBD> rt <20><><EFBFBD><EFBFBD>
|
|||
|
|
else if (command.startsWith("rt")) {
|
|||
|
|
qDebug() << "Executing rocketmq_test_rt()";
|
|||
|
|
std::cout << "Executing rocketmq_test_rt()\n";
|
|||
|
|
rocketmq_test_rt(); // <20><><EFBFBD><EFBFBD> rt <20><><EFBFBD><EFBFBD>
|
|||
|
|
clientSocket->write("Executed rocketmq_test_rt\n> ");
|
|||
|
|
}
|
|||
|
|
// <20><><EFBFBD><EFBFBD> ud <20><><EFBFBD><EFBFBD>
|
|||
|
|
else if (command.startsWith("ud")) {
|
|||
|
|
qDebug() << "Executing rocketmq_test_ud()";
|
|||
|
|
std::cout << "Executing rocketmq_test_ud()\n";
|
|||
|
|
rocketmq_test_ud(); // <20><><EFBFBD><EFBFBD> ud <20><><EFBFBD><EFBFBD>
|
|||
|
|
clientSocket->write("Executed rocketmq_test_ud\n> ");
|
|||
|
|
}
|
|||
|
|
else if (command.startsWith("set")) {
|
|||
|
|
qDebug() << "Executing rocketmq_test_set()";
|
|||
|
|
std::cout << "Executing rocketmq_test_set()\n";
|
|||
|
|
rocketmq_test_set(); // <20><><EFBFBD><EFBFBD> set <20><><EFBFBD><EFBFBD>
|
|||
|
|
clientSocket->write("Executed rocketmq_test_set\n> ");
|
|||
|
|
}
|
|||
|
|
else if (command.startsWith("ledger")) {
|
|||
|
|
qDebug() << "Executing ledger()";
|
|||
|
|
std::cout << "Executing ledger()\n";
|
|||
|
|
|
|||
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|||
|
|
QStringList parts = command.split(" "); // <20><><EFBFBD>ݿո<DDBF><D5B8>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (parts.size() > 1) { // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>а<EFBFBD><D0B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> id<69>ţ<EFBFBD>
|
|||
|
|
QString terminalId = parts[1];
|
|||
|
|
std::cout << "Calling ledger with terminal_id: " << terminalId.toStdString() << std::endl;
|
|||
|
|
|
|||
|
|
// <20>ģ<DEB8><C4A3><EFBFBD><EFBFBD><EFBFBD> ledger ʱ<><CAB1><EFBFBD><EFBFBD> clientSocket <20><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>豸
|
|||
|
|
ledger(terminalId.toStdString().c_str(), clientSocket); // <20><><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ledger<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD> clientSocket
|
|||
|
|
|
|||
|
|
clientSocket->write("Executed ledger with terminal_id\n> ");
|
|||
|
|
} else {
|
|||
|
|
std::cout << "Calling ledger without parameters\n";
|
|||
|
|
|
|||
|
|
// <20>ģ<DEB8><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DEB2><EFBFBD><EFBFBD><EFBFBD> ledger<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD> clientSocket
|
|||
|
|
ledger(NULL, clientSocket); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DEB2><EFBFBD><EFBFBD><EFBFBD> ledger<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD> clientSocket
|
|||
|
|
|
|||
|
|
clientSocket->write("Executed ledger without parameters\n> ");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>δ֪<CEB4><D6AA><EFBFBD><EFBFBD>
|
|||
|
|
else {
|
|||
|
|
clientSocket->write("Unknown command\n> ");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
clientSocket->flush();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
signals:
|
|||
|
|
void serverError();
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
QTcpServer *server;
|
|||
|
|
QTimer *timer;
|
|||
|
|
int TEST_NUM;
|
|||
|
|
QMutex mutex;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
//lnk20241213
|
|||
|
|
class mqconsumerThread : public QThread
|
|||
|
|
{
|
|||
|
|
protected:
|
|||
|
|
void run();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
|
|||
|
|
class OnTimerThread : public QThread//<2F><>ʱ<EFBFBD>߳<EFBFBD>
|
|||
|
|
{
|
|||
|
|
protected:
|
|||
|
|
void run();
|
|||
|
|
};
|
|||
|
|
//WW 2023-08-22 end
|
|||
|
|
|
|||
|
|
/////////////////////////////////////////////////////////////////////////
|
|||
|
|
|
|||
|
|
|
|||
|
|
extern "C" {
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
|
|||
|
|
//lnk20250106<30><36><EFBFBD><EFBFBD>̨<EFBFBD>˽ṹ
|
|||
|
|
typedef struct terminal terminal;
|
|||
|
|
typedef struct monitor monitor;
|
|||
|
|
struct monitor // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̨<EFBFBD><CCA8>
|
|||
|
|
{
|
|||
|
|
char monitor_id[64];
|
|||
|
|
char terminal_code[64];
|
|||
|
|
char monitor_name[64];
|
|||
|
|
char logical_device_seq[64];
|
|||
|
|
char voltage_level[64];
|
|||
|
|
char terminal_connect[64];
|
|||
|
|
char timestamp[64];
|
|||
|
|
char status[255];
|
|||
|
|
|
|||
|
|
};
|
|||
|
|
struct terminal // <20>ն<EFBFBD>̨<EFBFBD><CCA8>
|
|||
|
|
{
|
|||
|
|
char terminal_id[64];
|
|||
|
|
char terminal_code[64];
|
|||
|
|
char org_name[64];
|
|||
|
|
char maint_name[64];
|
|||
|
|
char station_name[64];
|
|||
|
|
char tmnl_factory[64];
|
|||
|
|
char tmnl_status[64];
|
|||
|
|
char dev_type[64];
|
|||
|
|
char dev_key[255];
|
|||
|
|
char dev_series[255];
|
|||
|
|
char addr_str[64];
|
|||
|
|
char port[64];
|
|||
|
|
char timestamp[64];
|
|||
|
|
monitor line[10]; // <20><><EFBFBD><EFBFBD> 10 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
#ifdef __cplusplus
|
|||
|
|
}
|
|||
|
|
#endif
|
|||
|
|
/////////////////////////////////////////////////////////////////////////////
|
|||
|
|
|
|||
|
|
#endif //SAVE2DB_8ue3hy0923r_H
|