From c843247d68990f93ede69d18c2a1245c5ddf9626 Mon Sep 17 00:00:00 2001 From: lnk Date: Thu, 27 Feb 2025 16:28:04 +0800 Subject: [PATCH] finish log realdata send funtion --- cfg_parse/SimpleProducer.cpp | 4 +- cfg_parse/cfg_parser.cpp | 319 +++++++++++++++++++++++------------ json/create_json.cpp | 6 +- json/save2json.cpp | 21 ++- json/save2json.h | 267 +++++++++++++++++++---------- mms/mms_process.c | 46 ++--- mms/rdb_client.c | 6 +- 7 files changed, 439 insertions(+), 230 deletions(-) diff --git a/cfg_parse/SimpleProducer.cpp b/cfg_parse/SimpleProducer.cpp index 9920c13..e2cac2b 100644 --- a/cfg_parse/SimpleProducer.cpp +++ b/cfg_parse/SimpleProducer.cpp @@ -434,11 +434,13 @@ public: &queueNum // 传递给选择器的额外参数(队列数量) ); + //调试用 + /* if (sendResult == 0) { // 假设返回 0 表示成功 std::cout << "Message sent successfully.topic:" << topic <>>json %s\n", url); + //printf(">>>json %s\n", url);//ٲҪĴӡ // URL curl_easy_setopt(curl, CURLOPT_URL, url); @@ -11454,7 +11454,7 @@ void SendJsonAPI_web(const std::string& strUrl, const char* code, const std::str if (curl) { char url[256]; snprintf(url, sizeof(url), "%s?%s", strUrl.c_str(), code); - printf(">>>json %s\n", url); + //printf(">>>json %s\n", url);//ٲҪĴӡ curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, req_reply_http); @@ -14357,7 +14357,7 @@ int update_one_terminal_ledger(terminal* update, int i,ied_t* ied,int terminal_i rptinfo_t **rptinfo = NULL; // - printf("check error111 !!!!!!!!!!!!!!\n"); + //printf("check error111 !!!!!!!!!!!!!!\n"); @@ -14376,14 +14376,14 @@ int update_one_terminal_ledger(terminal* update, int i,ied_t* ied,int terminal_i } // - printf("check error112 !!!!!!!!!!!!!!\n"); + //printf("check error112 !!!!!!!!!!!!!!\n"); //////// //¼ԭеı־ loginfo = ied_usr->LD_info[cpuno - 1].loginfo?ied_usr->LD_info[cpuno - 1].loginfo:NULL; rptinfo = ied_usr->LD_info[cpuno - 1].rptinfo?ied_usr->LD_info[cpuno - 1].rptinfo:NULL; // - printf("check error113 !!!!!!!!!!!!!!\n"); + //printf("check error113 !!!!!!!!!!!!!!\n"); //ظڴ棬ʹѴڵiedô֮ǰʼͷ˹ϣɾ̨ʱûҪԭ if (ied_usr->LD_info[cpuno - 1].ht_fcd != NULL) { @@ -14394,7 +14394,7 @@ int update_one_terminal_ledger(terminal* update, int i,ied_t* ied,int terminal_i } // - printf("check error116 !!!!!!!!!!!!!!\n"); + //printf("check error116 !!!!!!!!!!!!!!\n"); //Щеڴ棬Ҫ̨ɾʱӦ apr_snprintf(str, sizeof(str), "PQMonitorPQM%d", cpuno); @@ -14424,23 +14424,23 @@ int update_one_terminal_ledger(terminal* update, int i,ied_t* ied,int terminal_i // ڴ棬ֹ memset(ied_usr->LD_info[cpuno - 1].LD_name, 0, 256); - printf("check error333 !!!!!!!!!!!!!!\n"); + //printf("check error333 !!!!!!!!!!!!!!\n"); apr_cpystrn(ied_usr->LD_info[cpuno - 1].LD_name, str, 256); //ԭпռ串 - printf("check error222 !!!!!!!!!!!!!!\n"); + //printf("check error222 !!!!!!!!!!!!!!\n"); } ldname = ied_usr->LD_info[cpuno - 1].LD_name; // - printf("check error114 !!!!!!!!!!!!!!\n"); + //printf("check error114 !!!!!!!!!!!!!!\n"); ied_usr->LD_info[cpuno - 1] = line_info;//ں棬ΪҪжԭеָ ied_usr->LD_info[cpuno - 1].ied = ied; //ں棬ΪҪжԭеָ // - printf("check error115 !!!!!!!!!!!!!!\n"); + //printf("check error115 !!!!!!!!!!!!!!\n"); @@ -15166,127 +15166,232 @@ void rocketmq_test_300(int mpnum,int front_index) { } ///////////////////////////////////////////////////////////////////////////////lnkʵʱ־20250205 -// ȫбͿ +// ------------------ ȫ־б ------------------ std::list errorList; std::list warnList; std::list normalList; -// ȫֻ -pthread_mutex_t errorListMutex = PTHREAD_MUTEX_INITIALIZER; -pthread_mutex_t warnListMutex = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t errorListMutex = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t warnListMutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t normalListMutex = PTHREAD_MUTEX_INITIALIZER; - -bool errorOutputEnabled = false; -bool warnOutputEnabled = false; -bool normalOutputEnabled = false; -// Զ -class RedirectStreamBuf : public std::streambuf { - public: - RedirectStreamBuf(std::list& targetList, pthread_mutex_t& targetMutex) - : targetList(targetList), targetMutex(targetMutex) {} - - protected: - virtual int_type overflow(int_type ch) override { - if (ch != EOF) { - char c = static_cast(ch); - - // targetList - pthread_mutex_lock(&targetMutex); - targetList.push_back(std::string(1, c)); - pthread_mutex_unlock(&targetMutex); - } - return ch; - } - - private: - std::list& targetList; - pthread_mutex_t& targetMutex; +// ------------------ ------------------ +bool errorOutputEnabled = false; // Ƿ error д errorList +bool warnOutputEnabled = false; // Ƿ warn д warnList +bool normalOutputEnabled = false; // Ƿ normal д normalList + +// ------------------ ڻָԭʼ ------------------ +static std::streambuf* g_originalCoutBuf = NULL; +static std::streambuf* g_originalClogBuf = NULL; +static std::streambuf* g_originalCerrBuf = NULL; + +// ------------------ ־ö٣C++98 ------------------ +enum LogLevel { + LOG_ERROR, + LOG_WARN, + LOG_NORMAL }; - -// Զ -void redirectErrorOutput(bool enabled) { - errorOutputEnabled = enabled; - if (enabled) { - static RedirectStreamBuf errorBuf(errorList, errorListMutex); - std::cerr.rdbuf(&errorBuf); - } else { - std::cerr.rdbuf(nullptr); // ָ׼ - } + +// ------------------------------------------------------------------ +// TeeStreamBuf: дԭʼbuf(ն)ٿlist +// ------------------------------------------------------------------ +class TeeStreamBuf : public std::streambuf +{ +public: + // ĬϹ죺ȰָΪNULL + TeeStreamBuf() + : m_originalBuf(NULL), m_level(LOG_NORMAL) + { + } + + // ι죺ֱӳʼ + TeeStreamBuf(std::streambuf* originalBuf, LogLevel level) + : m_originalBuf(originalBuf), m_level(level) + { + } + + // Զ init(...) ͬһ + void init(std::streambuf* originalBuf, LogLevel level) + { + m_originalBuf = originalBuf; + m_level = level; + m_buffer.clear(); + } + +protected: + // flush std::endl ʱ sync() + virtual int sync() + { + // ԭʼִͬ + if (m_originalBuf) { + m_originalBuf->pubsync(); + } + // ٽĻ flush + flushBuffer(); + return 0; // ɹ + } + + // дһַʱoverflow() + virtual int_type overflow(int_type ch) + { + if (ch == traits_type::eof()) { + return ch; + } + // 1) дԭʼ ն + if (m_originalBuf) { + if (m_originalBuf->sputc(static_cast(ch)) == traits_type::eof()) { + return traits_type::eof(); + } + } + // 2) 浽ǵʱ + m_buffer.push_back((char)ch); + // 3) о flushBuffer() + if (ch == '\n') { + flushBuffer(); + } + return ch; + } + +private: + // m_buffer һдӦ list + void flushBuffer() + { + if (m_buffer.empty()) { + return; + } + + // ݵȼ + Ӧ дļlist + switch (m_level) { + + case LOG_ERROR: + if (errorOutputEnabled) { + pthread_mutex_lock(&errorListMutex); + errorList.push_back(m_buffer); + pthread_mutex_unlock(&errorListMutex); + } + if (warnOutputEnabled) { + pthread_mutex_lock(&warnListMutex); + warnList.push_back(m_buffer); + pthread_mutex_unlock(&warnListMutex); + } + if (normalOutputEnabled) { + pthread_mutex_lock(&normalListMutex); + normalList.push_back(m_buffer); + pthread_mutex_unlock(&normalListMutex); + } + break; + + case LOG_WARN: + if (warnOutputEnabled) { + pthread_mutex_lock(&warnListMutex); + warnList.push_back(m_buffer); + pthread_mutex_unlock(&warnListMutex); + } + if (normalOutputEnabled) { + pthread_mutex_lock(&normalListMutex); + normalList.push_back(m_buffer); + pthread_mutex_unlock(&normalListMutex); + } + break; + + case LOG_NORMAL: + if (normalOutputEnabled) { + pthread_mutex_lock(&normalListMutex); + normalList.push_back(m_buffer); + pthread_mutex_unlock(&normalListMutex); + } + break; + } + + m_buffer.clear(); + } + +private: + // ֹԶɵĸֵ (C++98) + TeeStreamBuf& operator=(const TeeStreamBuf&); // ʵ + +private: + std::streambuf* m_originalBuf; + LogLevel m_level; + std::string m_buffer; +}; + +// ------------------ ȫTee󣨱ظֵ ------------------ +static TeeStreamBuf g_errorTeeBuf; +static TeeStreamBuf g_warnTeeBuf; +static TeeStreamBuf g_normalTeeBuf; + +// ------------------ ض ------------------ +// ֻڵһʱ init(...) ʼ TeeStreamBuf +// ֮ʱ new ֱֵ֮ǰõĶ +void redirectErrorOutput(bool enabled) +{ + errorOutputEnabled = enabled; + if (enabled) { + if (g_originalCerrBuf == NULL) { + g_originalCerrBuf = std::cerr.rdbuf(); + g_errorTeeBuf.init(g_originalCerrBuf, LOG_ERROR); + } + std::cerr.rdbuf(&g_errorTeeBuf); + } else { + if (g_originalCerrBuf) { + std::cerr.rdbuf(g_originalCerrBuf); + } + } } -// Զ澯 -void redirectWarnOutput(bool enabled) { - warnOutputEnabled = enabled; - if (enabled) { - static RedirectStreamBuf warnBuf(warnList, warnListMutex); - std::clog.rdbuf(&warnBuf); - std::cerr.rdbuf(&warnBuf); - } else { - std::clog.rdbuf(nullptr); // ָ׼澯 - std::cerr.rdbuf(nullptr); // ָ׼ - } +void redirectWarnOutput(bool enabled) +{ + warnOutputEnabled = enabled; + if (enabled) { + if (g_originalClogBuf == NULL) { + g_originalClogBuf = std::clog.rdbuf(); + g_warnTeeBuf.init(g_originalClogBuf, LOG_WARN); + } + std::clog.rdbuf(&g_warnTeeBuf); + } else { + if (g_originalClogBuf) { + std::clog.rdbuf(g_originalClogBuf); + } + } } -// Զͨ -void redirectNormalOutput(bool enabled) { - normalOutputEnabled = enabled; - if (enabled) { - static RedirectStreamBuf normalBuf(normalList, normalListMutex); - std::cout.rdbuf(&normalBuf); - std::clog.rdbuf(&normalBuf); - std::cerr.rdbuf(&normalBuf); - } else { - std::cout.rdbuf(nullptr); // ָ׼ - std::clog.rdbuf(nullptr); // ָ׼澯 - std::cerr.rdbuf(nullptr); // ָ׼ - } +void redirectNormalOutput(bool enabled) +{ + normalOutputEnabled = enabled; + if (enabled) { + if (g_originalCoutBuf == NULL) { + g_originalCoutBuf = std::cout.rdbuf(); + g_normalTeeBuf.init(g_originalCoutBuf, LOG_NORMAL); + } + std::cout.rdbuf(&g_normalTeeBuf); + } else { + if (g_originalCoutBuf) { + std::cout.rdbuf(g_originalCoutBuf); + } + } } - -// Զ printf -int customPrintf(const char* format, ...) { +// ------------------ Զ printf ------------------ +// ʾ normal => ջnormalList(ؿ) +int customPrintf(const char* format, ...) +{ va_list args; va_start(args, format); + char buffer[1024]; - - // ȸʽַ buffer int written = vsnprintf(buffer, sizeof(buffer), format, args); - // ԭʼ va_list va_end(args); - // ʽʧܣش if (written < 0) { return -1; } - // õĿؽӵӦб - if (errorOutputEnabled) { - pthread_mutex_lock(&errorListMutex); - errorList.push_back(buffer); - pthread_mutex_unlock(&errorListMutex); - } + // ֱstd::coutӶTeeStreamBufԲ + std::cout << buffer << std::endl; - if (warnOutputEnabled) { - pthread_mutex_lock(&warnListMutex); - warnList.push_back(buffer); - pthread_mutex_unlock(&warnListMutex); - } - - if (normalOutputEnabled) { - pthread_mutex_lock(&normalListMutex); - normalList.push_back(buffer); - pthread_mutex_unlock(&normalListMutex); - } - - // пضûʹԭ printf - if (!errorOutputEnabled && !warnOutputEnabled && !normalOutputEnabled) { - // ֱն - std::cout << buffer << std::endl; // ʹ std::cout printf ijͻ - } - - return written; // Ѵӡַ + return written; } /////////////////////////////////////////////////////////////////////////////// diff --git a/json/create_json.cpp b/json/create_json.cpp index 13bdbda..6a4e242 100644 --- a/json/create_json.cpp +++ b/json/create_json.cpp @@ -1216,7 +1216,7 @@ bool ParseXMLConfig2(int xml_flag, XmlConfig *cfg, list *ctopiclist,QSt if (strDAName.indexOf("l_phs*") >= 0){ //DA"l_phs*"//lnk20250221νҲԽPPV strDAName = strDAName.replace("l_phs", "phs"); strDAName = strDAName.replace("*", strLine[n]); - qDebug() << "strDAName:" << strDAName << endl;// + //qDebug() << "strDAName:" << strDAName << endl;// } //DA*滻Ϊ(ABBCCA) phsAB$cVal$mag$f else if (strDAName.indexOf("phs*") >= 0) {//DA"phs*" @@ -3986,7 +3986,7 @@ void connectlog_pgsql(char* id,char* datetime,int status) return; } - std::cout << "jsonString" << jsonString << std::endl; + //std::cout << "jsonString: " << jsonString << std::endl;////ٶĴӡ //ݵԶ SendJsonAPI_web(WEB_COMFLAG, "", jsonString,&ptr); @@ -3994,7 +3994,7 @@ void connectlog_pgsql(char* id,char* datetime,int status) //ص // ptr ǷΪ NULL std::string ʼʧ if (ptr != NULL) { - handleCommentResponse(std::string(ptr)); + //handleCommentResponse(std::string(ptr));//ٶĴӡ free(ptr); // SendJsonAPI_web ڴ棬ǵͷ } else { // ptr Ϊ NULL ־¼ diff --git a/json/save2json.cpp b/json/save2json.cpp index 4204a91..bed2c89 100644 --- a/json/save2json.cpp +++ b/json/save2json.cpp @@ -344,6 +344,7 @@ void my_rocketmq_send(Ckafka_data_t& data) else { topic = data.strTopic.toStdString(); + } if (g_onlyIP[0] != 0) { @@ -598,12 +599,17 @@ void KafkaSendThread::run() bool log_gotten; log_gotten = false; + + if (normalOutputEnabled) { // normalOutputEnabled Ϊ 1ȴ normalList ȡ // normalList pthread_mutex_lock(&normalListMutex); if (!normalList.empty()) { - data_gotten = true; + + //qDebug() << "flag of list:" << normalOutputEnabled << " " << warnOutputEnabled << " " << errorOutputEnabled << " " << "warnList size: " << warnList.size() << "normalList size: " << normalList.size() << "errorList size: " << errorList.size()<>>>>>>>>>>> %s \n", count, - QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz").toAscii().data()); + //printf("BEGIN current log send no.%i -------->>>>>>>>>>>> %s \n", count,QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz").toAscii().data()); my_rocketmq_send(log_send); } @@ -1520,7 +1526,10 @@ void parse_log(const std::string& json_str) { redirectNormalOutput(false); } else{ - std::cout << "level error" <stop(); @@ -190,8 +195,10 @@ private slots: qDebug() << "New connection established!"; std::cout << "New connection established!\n"; + // ݿɶʱ onReadyRead() connect(clientSocket, SIGNAL(readyRead()), this, SLOT(onReadyRead())); - connect(clientSocket, SIGNAL(disconnected()), clientSocket, SLOT(deleteLater())); // Զ + // ͻ˶ϿʱԶ socket + connect(clientSocket, SIGNAL(disconnected()), clientSocket, SLOT(deleteLater())); // ͻ˷ʾ if (clientSocket) { @@ -201,6 +208,10 @@ private slots: } } + /** + * @brief ֽڴTelnet룬ʶ()˸񡢻س + * »سʱǰΪһ processCommand + */ void onReadyRead() { QTcpSocket *clientSocket = qobject_cast(sender()); if (!clientSocket) { @@ -209,29 +220,91 @@ private slots: } QByteArray data = clientSocket->readAll(); - QString command = QString::fromUtf8(data).trimmed(); // ȡȥǰո + + // ֽڴ + for (int i = 0; i < data.size(); ++i) { + char c = data[i]; + switch (c) { + case '\r': + case '\n': + // ⵽سУΪûһ + if (!currentCommand.isEmpty()) { + // ʷ¼ͬظ¼ + if (commandHistory.isEmpty() || commandHistory.last() != currentCommand) { + commandHistory.append(currentCommand); + } + historyIndex = commandHistory.size(); // ָһ֮ + + // + processCommand(currentCommand, clientSocket); + currentCommand.clear(); + } else { + // ֻǿУǸʾ + clientSocket->write("\n> "); + clientSocket->flush(); + } + break; + + case '\x1b': + // Ƿ ESC + // ϼͷ: \x1b[A + // ¼ͷ: \x1b[B + if (i + 2 < data.size() && data[i+1] == '[') { + char arrow = data[i+2]; + if (arrow == 'A') { + // ϼͷ + handleUpArrow(clientSocket); + } else if (arrow == 'B') { + // ¼ͷ + handleDownArrow(clientSocket); + } + // Ѿ3ֽ: \x1b [ X + i += 2; + } + break; + + case '\x7f': + case '\x08': + // ˸DelBackspace + if (!currentCommand.isEmpty()) { + currentCommand.chop(1); // ɾһַ + // ԣ + + ٻ + // "\b \b"ھնʵ˸ + clientSocket->write("\b \b"); + clientSocket->flush(); + } + break; + + default: + // ַͨ׷ӵ currentCommand + currentCommand.append(c); + // Եͻ + clientSocket->write(&c, 1); + clientSocket->flush(); + break; + } + } + } + +signals: + void serverError(); + +private: + // -------------------- + // Ϊĸ + // -------------------- + + /** + * @brief (һ)ԭ onReadyRead() if-else ߼ + */ + void processCommand(const QString &command, QTcpSocket *clientSocket) { + // ӡ־ qDebug() << "Received command:" << command; std::cout << "Received command: " << command.toStdString() << "\n"; - // 洢ʷ - if (!command.isEmpty() && (commandHistory.isEmpty() || command != commandHistory.last())) { - commandHistory.append(command); - historyIndex = commandHistory.size(); // - } - - // 洢ǰ - if (!currentCommand.isEmpty() && command != "up" && command != "down" && command != "\x7f") { - currentCommand.append(command); - } - - // ͻ˷ָ͡롱 - clientSocket->write("Received command\n> "); - clientSocket->flush(); - clientSocket->write("test_shell> "); - clientSocket->flush(); // ȷʾʾ - - // help + // Ϊԭ onReadyRead() е if / else if ߼ + // ------------------------------------------------------ if (command == "help") { QString helpText = "Available commands:\n"; helpText += "TEST_NUM= - Set the TEST_NUM\n"; @@ -239,12 +312,13 @@ private slots: helpText += "rt - Execute rocketmq_test_rt\n"; helpText += "ud - Execute rocketmq_test_ud\n"; helpText += "set - Execute rocketmq_test_set\n"; + helpText += "only - Execute rocketmq_test_only\n"; + helpText += "log - Execute rocketmq_test_log\n"; helpText += "ledger - Execute ledger with optional terminal_id\n"; - helpText += "value - Execute value print with valuename : iedcount frontfun frontindex remtable\n"; + helpText += "value - Execute value print with valuename : iedcount frontfun frontindex remtable\n"; helpText += "exit - Exit the shell\n"; helpText += "help - Show this help message\n"; clientSocket->write(helpText.toUtf8()); - } // öģĸ else if (command.startsWith("TEST_NUM=")) { @@ -252,10 +326,10 @@ private slots: int num = command.mid(9).toInt(&ok); // ȡȺźֲ if (ok) { setTestNum(num); // TEST_NUM - clientSocket->write("TEST_NUM updated\n> "); + clientSocket->write("TEST_NUM updated\n"); std::cout << "TEST_NUM updated\n"; } else { - clientSocket->write("Invalid number\n> "); + clientSocket->write("Invalid number\n"); std::cout << "Invalid number\n"; } } @@ -264,35 +338,42 @@ private slots: qDebug() << "Executing rocketmq_test_rc()"; std::cout << "Executing rocketmq_test_rc()\n"; rocketmq_test_rc(); // rc - clientSocket->write("Executed rocketmq_test_rc\n> "); + clientSocket->write("Executed rocketmq_test_rc\n"); } // ʵʱݲı else if (command.startsWith("rt")) { qDebug() << "Executing rocketmq_test_rt()"; std::cout << "Executing rocketmq_test_rt()\n"; rocketmq_test_rt(); // rt - clientSocket->write("Executed rocketmq_test_rt\n> "); + clientSocket->write("Executed rocketmq_test_rt\n"); } // ̨˸²ı else if (command.startsWith("ud")) { qDebug() << "Executing rocketmq_test_ud()"; std::cout << "Executing rocketmq_test_ud()\n"; rocketmq_test_ud(); // ud - clientSocket->write("Executed rocketmq_test_ud\n> "); + 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(); // set - clientSocket->write("Executed rocketmq_test_set\n> "); + clientSocket->write("Executed rocketmq_test_set\n"); } // ͵̲ı else if (command.startsWith("only")) { qDebug() << "Executing rocketmq_test_only()"; std::cout << "Executing rocketmq_test_only()\n"; - rocketmq_test_only(); // set - clientSocket->write("Executed rocketmq_test_only\n> "); + rocketmq_test_only(); // rocketmq_test_only + clientSocket->write("Executed rocketmq_test_only\n"); + } + // ʵʱ־ı + else if (command.startsWith("log")) { + qDebug() << "Executing rocketmq_test_log()"; + std::cout << "Executing rocketmq_test_log()\n"; + rocketmq_test_log(); // log + clientSocket->write("Executed rocketmq_test_log\n"); } // 鿴ǰ̵̨ else if (command.startsWith("ledger")) { @@ -305,64 +386,30 @@ private slots: QString terminalId = parts[1]; std::cout << "Calling ledger with terminal_id: " << terminalId.toStdString() << std::endl; - // ޸ģ ledger ʱ clientSocket Ϊ豸 - ledger(terminalId.toStdString().c_str(), clientSocket); // ô ledger clientSocket - - clientSocket->write("Executed ledger with terminal_id\n> "); + ledger(terminalId.toStdString().c_str(), clientSocket); // ledger + clientSocket->write("Executed ledger with terminal_id\n"); } else { std::cout << "Calling ledger without parameters\n"; - - // ޸ģ޲ ledger clientSocket - ledger(NULL, clientSocket); // ޲ ledger clientSocket - - clientSocket->write("Executed ledger without parameters\n> "); + ledger(NULL, clientSocket); // ޲ ledger + clientSocket->write("Executed ledger without parameters\n"); } } // 鿴ǰ̵ֵָ else if (command.startsWith("value")) { std::cout << "Executing value()" << std::endl; - + // ȡеIJȡ - QStringList parts = command.split(" "); // ݿոָ - if (parts.size() > 1) { // а + QStringList parts = command.split(" "); + if (parts.size() > 1) { QString variableName = parts[1]; - std::cout << "Calling value() with variable name: " << variableName.toStdString() << std::endl; - - // value() ֵ - value_print(variableName.toStdString().c_str(), clientSocket); // value() Ըݱֵ - - clientSocket->write("Executed value with variable name: " + variableName.toUtf8() + "\n> "); + + // value_print() ֵ + value_print(variableName.toStdString().c_str(), clientSocket); + clientSocket->write("Executed value with variable name: " + variableName.toUtf8() + "\n"); } else { std::cout << "Calling value without parameters" << std::endl; - - // ʾûҪṩ - clientSocket->write("Please provide a variable name\n> "); - } - } - // ʷ - // ¼ʷ - if (command == "up") { - if (historyIndex > 0) { - historyIndex--; - clientSocket->write(commandHistory[historyIndex].toUtf8()); - } else { - clientSocket->write("No previous command\n> "); - } - } else if (command == "down") { - if (historyIndex < commandHistory.size() - 1) { - historyIndex++; - clientSocket->write(commandHistory[historyIndex].toUtf8()); - } else { - clientSocket->write("No next command\n> "); - } - } - - // backspace - else if (command == "\x7f") { - if (!currentCommand.isEmpty()) { - currentCommand.chop(1); // ɾһַ - clientSocket->write(currentCommand.toUtf8()); + clientSocket->write("Please provide a variable name\n"); } } // exit @@ -372,26 +419,72 @@ private slots: clientSocket->flush(); clientSocket->disconnectFromHost(); // ر clientSocket->waitForDisconnected(); // ȷӶϿ + return; } - // δ֪ + // δ֪ else { - clientSocket->write("Unknown command\n> "); + clientSocket->write("Unknown command\n"); } + // 󣬻һкʾ + clientSocket->write("> "); clientSocket->flush(); } -signals: - void serverError(); + /** + * @brief ϼͷʷ¼еһ + */ + void handleUpArrow(QTcpSocket *clientSocket) { + if (!commandHistory.isEmpty() && historyIndex > 0) { + historyIndex--; + currentCommand = commandHistory[historyIndex]; + + // Ƶףյǰ (: سÿո񸲸) + clientSocket->write("\r"); + clientSocket->write(" "); + clientSocket->write("\r> "); + // ʷ + clientSocket->write(currentCommand.toUtf8()); + clientSocket->flush(); + } + } + + /** + * @brief ¼ͷʷ¼еһ + */ + void handleDownArrow(QTcpSocket *clientSocket) { + if (!commandHistory.isEmpty() && historyIndex < commandHistory.size() - 1) { + historyIndex++; + currentCommand = commandHistory[historyIndex]; + + clientSocket->write("\r"); + clientSocket->write(" "); + clientSocket->write("\r> "); + clientSocket->write(currentCommand.toUtf8()); + clientSocket->flush(); + } + else if (historyIndex == commandHistory.size() - 1) { + // Ѿһٰ¼ͷ + historyIndex = commandHistory.size(); + currentCommand.clear(); + + clientSocket->write("\r"); + clientSocket->write(" "); + clientSocket->write("\r> "); + clientSocket->flush(); + } + } private: - QList commandHistory; // 洢ʷ - int historyIndex = -1; // ǰʷ - QString currentCommand; // ǰ QTcpServer *server; QTimer *timer; int TEST_NUM; QMutex mutex; + + // ʷ + QList commandHistory; // 洢ʷ + int historyIndex; // ǰʷ + QString currentCommand; // ǰ }; diff --git a/mms/mms_process.c b/mms/mms_process.c index d49e795..b70833a 100644 --- a/mms/mms_process.c +++ b/mms/mms_process.c @@ -368,7 +368,7 @@ void ChannelCheckIECReports(chnl_usr_t *chnl_usr) ied_usr = GET_IEDEXT_ADDR(ied); channel = chnl_usr->chnl; - printf("check error %s !!!!!!!!!!!!!!cpucount:%d\n",((ied_usr_t*)chnl_usr->chnl->ied->usr_ext)->terminal_id,(int)ied->cpucount); + //printf("check error %s !!!!!!!!!!!!!!cpucount:%d\n",((ied_usr_t*)chnl_usr->chnl->ied->usr_ext)->terminal_id,(int)ied->cpucount); //printf("1 chnl_usr->ip_str = %s \n",chnl_usr->ip_str); for(cpuno=0 ; cpunocpucount; cpuno++) @@ -1260,7 +1260,7 @@ void check_ledger_update()//lnk20250113 - printf("check ledger update...trigger_ledger_update_xml:%d\n",trigger_ledger_update_xml->modify_update_num); + //printf("check ledger update...trigger_ledger_update_xml:%d\n",trigger_ledger_update_xml->modify_update_num);//ٲҪĴӡ last_check_3s_config_time = now; //¼ʱ @@ -1546,7 +1546,7 @@ void CheckNextNotConnectedChannel() chnl_total_no = (chnl_total_no+1) % g_pt61850app->chnl_counts; } while ( (g_onlyIP[0]!=0) && (strcmp(g_onlyIP,chnl_usr->ip_str)!=0) ); - printf("check error chnl_total_no !!!!!!!!!!!!!! %d\n",chnl_total_no); + //printf("check error chnl_total_no !!!!!!!!!!!!!! %d\n",chnl_total_no); //10-11-01 22:03 beijing if( ( (chnl_total_no+1)==g_pt61850app->chnl_counts) || (g_onlyIP[0]!=0) ){ @@ -1571,19 +1571,19 @@ void CheckNextNotConnectedChannel() //} } - printf("check error %s !!!!!!!!!!!!!!\n",((ied_usr_t*)chnl_usr->chnl->ied->usr_ext)->terminal_id); + //printf("check error %s !!!!!!!!!!!!!!\n",((ied_usr_t*)chnl_usr->chnl->ied->usr_ext)->terminal_id); if(chnl_usr->m_state == CHANNEL_CONNECTING)// { - printf("check error93 !!!!!!!!!!!!!!\n"); + //printf("check error93 !!!!!!!!!!!!!!\n"); MVL_REQ_PEND* reqCtrl= chnl_usr->m_reqCtrl ; - printf("check error60 !!!!!!!!!!!!!!\n"); + //printf("check error60 !!!!!!!!!!!!!!\n"); if( reqCtrl->done == SD_TRUE) { - printf("check error92 !!!!!!!!!!!!!!\n"); + //printf("check error92 !!!!!!!!!!!!!!\n"); if(reqCtrl->result == SD_SUCCESS) { - printf("check error91 !!!!!!!!!!!!!!\n"); + //printf("check error91 !!!!!!!!!!!!!!\n"); ALL_RCB_INFO *all_rcb_info; // cout<GetIP()<<" CHANNEL_CONNECTED netInfo "<net_info<m_StartConnectingTime)/1000 ; //cout<<"reqCtrl->result == FAIL, Since StartConnecting "<GetIP()<<" !!! "<chnl->ied->usr_ext; if (g_node_id == STAT_DATA_BASE_NODE_ID || g_node_id == NEW_HIS_DATA_BASE_NODE_ID) { //lnk202411-4 //connectlog_pgsql(ied_usr->terminal_code);//ʧ - printf("check error89 !!!!!!!!!!!!!!\n"); + //printf("check error89 !!!!!!!!!!!!!!\n"); connectlog_pgsql(ied_usr->terminal_code,convertMsToDateTimeString((int)sGetMsTime()),0);//0ʧ - printf("check error88 !!!!!!!!!!!!!!\n"); + //printf("check error88 !!!!!!!!!!!!!!\n"); } printf( "reqCtrl->result == FAIL, Since StartConnecting %i ,channel IP %s:%d \n",secsSince,chnl_usr->ip_str,chnl_usr->chnl->port); mvl_free_req_ctrl(chnl_usr->m_reqCtrl); @@ -1642,7 +1642,7 @@ void CheckNextNotConnectedChannel() } else {// - printf("check error61 !!!!!!!!!!!!!!\n"); + //printf("check error61 !!!!!!!!!!!!!!\n"); if ( (sGetMsTime() - chnl_usr->m_StartConnectingTime) > 300*1000 ) //300*1000 ) //wait 300 secs ????? { ied_usr_t* ied_usr = (ied_usr_t*)chnl_usr->chnl->ied->usr_ext; @@ -1677,13 +1677,13 @@ void CheckNextNotConnectedChannel() else if(chnl_usr->m_state == CHANNEL_DISCONNECTED) { // - printf("check error99 !!!!!!!!!!!!!!\n"); + //printf("check error99 !!!!!!!!!!!!!!\n"); if ( (sGetMsTime() - chnl_usr->m_ClosedMsTime) > NEXT_CONNECT_TIME ) //wait 10 secs { // - printf("check error98 !!!!!!!!!!!!!!\n"); + //printf("check error98 !!!!!!!!!!!!!!\n"); ST_RET ret; ST_CHAR serverARName[32]; @@ -1691,10 +1691,10 @@ void CheckNextNotConnectedChannel() apr_snprintf(serverARName,sizeof(serverARName),"%s:%d",chnl_usr->ip_str,chnl_usr->chnl->port); if (chnl_usr->chnl->ied->cpucount != NULL && chnl_usr->chnl->ied->cpucount > 0 && ied_usr->dev_flag == ENABLE) {//2023-09-26 czy line count<0 Ҫ//lnk20250121նЧ ret = mms_connectToServer(ied_usr->dev_key, ied_usr->dev_series, serverARName, &(chnl_usr->net_info), &(chnl_usr->m_reqCtrl)); - printf("check error73 !!!!!!!!!!!!!!\n"); + //printf("check error73 !!!!!!!!!!!!!!\n"); if (ret == SD_SUCCESS) { - printf("check error74 !!!!!!!!!!!!!!\n"); + //printf("check error74 !!!!!!!!!!!!!!\n"); //if(chnl_usr->chnl->ied->id==virtual_ied){ // chnl_usr->m_state = CHANNEL_CONNECTED; // chnl_usr->chnl->ied->status = STATUS_NORMAL; @@ -1717,15 +1717,15 @@ void CheckNextNotConnectedChannel() else { // - printf("check error97 !!!!!!!!!!!!!!\n"); + //printf("check error97 !!!!!!!!!!!!!!\n"); chnl_usr->m_ClosedMsTime = sGetMsTime(); if (g_node_id == STAT_DATA_BASE_NODE_ID || g_node_id == NEW_HIS_DATA_BASE_NODE_ID) { //lnk202411-4 //connectlog_pgsql(ied_usr->terminal_code);//ʧ // - printf("check error96 !!!!!!!!!!!!!!\n"); + //printf("check error96 !!!!!!!!!!!!!!\n"); connectlog_pgsql(ied_usr->terminal_code,convertMsToDateTimeString((int)sGetMsTime()),0);//0ʧ - printf("check error95 !!!!!!!!!!!!!!\n"); + //printf("check error95 !!!!!!!!!!!!!!\n"); } echo_warn3("FAILED: mms_connectToServer IP %s:%d ,NetInfo= %x \n", chnl_usr->ip_str, chnl_usr->chnl->port, chnl_usr->net_info); } @@ -1735,11 +1735,11 @@ void CheckNextNotConnectedChannel() }//if(pChannel->m_state == CHANNEL_DISCONNECTED) else if(chnl_usr->m_state == CHANNEL_DISCONNECTING) //need check timeout?᲻Զͣ??? { - printf("check error92 !!!!!!!!!!!!!!\n"); + //printf("check error92 !!!!!!!!!!!!!!\n"); MVL_REQ_PEND* reqCtrl= chnl_usr->m_reqCtrl ; if( reqCtrl->done == SD_TRUE) { - printf("check error72 !!!!!!!!!!!!!!\n"); + //printf("check error72 !!!!!!!!!!!!!!\n"); //cout<GetIP()<<" CHANNEL_DISCONNECTING done"<ip_str,chnl_usr->chnl->port,chnl_usr->net_info); mvl_free_req_ctrl(chnl_usr->m_reqCtrl); @@ -1754,7 +1754,7 @@ void CheckNextNotConnectedChannel() } else {// - printf("check error70 !!!!!!!!!!!!!!\n"); + //printf("check error70 !!!!!!!!!!!!!!\n"); // cout<GetIP()<<" CHANNEL_DISCONNECTING waiting ..."<ip_str,chnl_usr->net_info); @@ -1775,7 +1775,7 @@ void CheckNextNotConnectedChannel() } }//if(pChannel->m_state == CHANNEL_DISCONNECTING) ////////////////// - printf("check error77 !!!!!!!!!!!!!!\n"); + //printf("check error77 !!!!!!!!!!!!!!\n"); } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/mms/rdb_client.c b/mms/rdb_client.c index 0e062c5..5f6eec7 100644 --- a/mms/rdb_client.c +++ b/mms/rdb_client.c @@ -404,7 +404,7 @@ static void* APR_THREAD_FUNC rtdb_worker(apr_thread_t* thd, void* data) //pthread_mutex_lock(&mtx); printf("work hold lock !!!!!!!!!!!"); // - printf("check error4 !!!!!!!!!!!!!!\n"); + //printf("check error4 !!!!!!!!!!!!!!\n"); doCommService();//61850Ϣ @@ -421,11 +421,11 @@ static void* APR_THREAD_FUNC rtdb_worker(apr_thread_t* thd, void* data) //check_recall_config();//ٽ̶ȡϢ create_recall_xml();//ɴxmlļ - pthread_mutex_lock(&mtx); printf("work hold lock !!!!!!!!!!!"); + pthread_mutex_lock(&mtx); //printf("work hold lock !!!!!!!!!!!"); check_ledger_update();//lnk20250113ȡ̨˸£̨˸ - pthread_mutex_unlock(&mtx); printf("work free lock !!!!!!!!!!!"); + pthread_mutex_unlock(&mtx); //printf("work free lock !!!!!!!!!!!"); //Check_Recall_Config(); /*if ((g_protect_file) && (g_pt61850app->initNum>=MIN_INIT_NUM) ) {