增加mooos信息
This commit is contained in:
@@ -64,6 +64,7 @@ PowerManger::PowerManger()
|
|||||||
|
|
||||||
//初始化http服务器
|
//初始化http服务器
|
||||||
m_httpServer = new HttpServer(8090);
|
m_httpServer = new HttpServer(8090);
|
||||||
|
m_httpServer->setPowerManger(this);
|
||||||
m_httpServer->setLowerCommManager(m_lowerCommManager);
|
m_httpServer->setLowerCommManager(m_lowerCommManager);
|
||||||
m_httpServer->setSystemData(m_systemData);
|
m_httpServer->setSystemData(m_systemData);
|
||||||
m_httpServer->start();
|
m_httpServer->start();
|
||||||
|
|||||||
@@ -131,6 +131,13 @@ class PowerManger : public AppCastingMOOSApp
|
|||||||
bool sendNotification(const std::string& key, const std::string& value) {
|
bool sendNotification(const std::string& key, const std::string& value) {
|
||||||
return Notify(key, value);
|
return Notify(key, value);
|
||||||
}
|
}
|
||||||
|
public:
|
||||||
|
double GetPublicAppFreq() { return GetAppFreq(); }
|
||||||
|
unsigned int GetPublicCommsFreq() { return GetCommsFreq(); }
|
||||||
|
double GetPublicAppStartTime() { return GetAppStartTime(); }
|
||||||
|
double GetPublicCPULoad() { return GetCPULoad(); }
|
||||||
|
double GetPublicTimeSinceIterate() { return GetTimeSinceIterate(); }
|
||||||
|
double GetPublicLastIterateTime() { return GetLastIterateTime(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -6,6 +6,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "json/json.h"
|
#include "json/json.h"
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
|
#include "data.h"
|
||||||
|
|
||||||
using json = Json::Value;
|
using json = Json::Value;
|
||||||
|
|
||||||
@@ -63,6 +64,9 @@ void HttpServer::handleWebSocketEvent(struct mg_connection* c, int ev, void* ev_
|
|||||||
} else if (mg_match(hm->uri, mg_str("/dashboard"), NULL)) {
|
} else if (mg_match(hm->uri, mg_str("/dashboard"), NULL)) {
|
||||||
// 返回仪表盘HTML
|
// 返回仪表盘HTML
|
||||||
mg_http_reply(c, 200, "Content-Type: text/html; charset=utf-8\r\n", DASHBOARD_HTML.c_str());
|
mg_http_reply(c, 200, "Content-Type: text/html; charset=utf-8\r\n", DASHBOARD_HTML.c_str());
|
||||||
|
} else if (mg_match(hm->uri, mg_str("/data"), NULL)) {
|
||||||
|
// 返回数据页面HTML
|
||||||
|
mg_http_reply(c, 200, "Content-Type: text/html; charset=utf-8\r\n", DATA_HTML.c_str());
|
||||||
} else if (mg_match(hm->uri, mg_str("/control"), NULL)) {
|
} else if (mg_match(hm->uri, mg_str("/control"), NULL)) {
|
||||||
// 处理断路器控制请求
|
// 处理断路器控制请求
|
||||||
if (mg_strcmp(hm->method, mg_str("POST")) == 0) {
|
if (mg_strcmp(hm->method, mg_str("POST")) == 0) {
|
||||||
@@ -485,6 +489,14 @@ void HttpServer::pushSystemData() {
|
|||||||
j["instrument_bus_status"]["emergencyLithiumBatteryGroup1Current"] = Json::Value(m_systemData->instrument_bus_status.emergencyLithiumBatteryGroup1Current); // 应急锂电池组1电流
|
j["instrument_bus_status"]["emergencyLithiumBatteryGroup1Current"] = Json::Value(m_systemData->instrument_bus_status.emergencyLithiumBatteryGroup1Current); // 应急锂电池组1电流
|
||||||
j["instrument_bus_status"]["emergency1BusbarVoltage"] = Json::Value(m_systemData->instrument_bus_status.emergency1BusbarVoltage); // 应急1汇流排电压
|
j["instrument_bus_status"]["emergency1BusbarVoltage"] = Json::Value(m_systemData->instrument_bus_status.emergency1BusbarVoltage); // 应急1汇流排电压
|
||||||
|
|
||||||
|
|
||||||
|
//MOOSDB数据
|
||||||
|
j["moosdb"]["appFreq"] = Json::Value(m_powerManger->GetPublicAppFreq());
|
||||||
|
j["moosdb"]["commFreq"] = Json::Value(m_powerManger->GetPublicCommsFreq());
|
||||||
|
j["moosdb"]["startTime"] = Json::Value(m_powerManger->GetPublicAppStartTime());
|
||||||
|
j["moosdb"]["cpuLoad"] = Json::Value(m_powerManger->GetPublicCPULoad());
|
||||||
|
j["moosdb"]["timeSinceIterate"] = Json::Value(m_powerManger->GetPublicTimeSinceIterate());
|
||||||
|
j["moosdb"]["lastIterateTime"] = Json::Value(m_powerManger->GetPublicLastIterateTime());
|
||||||
// 时间戳
|
// 时间戳
|
||||||
j["timestamp"] = Json::Value((Json::UInt64)(std::chrono::duration_cast<std::chrono::milliseconds>(
|
j["timestamp"] = Json::Value((Json::UInt64)(std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
std::chrono::system_clock::now().time_since_epoch()).count()));
|
std::chrono::system_clock::now().time_since_epoch()).count()));
|
||||||
|
|||||||
@@ -7,13 +7,18 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <fstream>
|
||||||
|
#include <deque>
|
||||||
#include "../LowerCommManager.h"
|
#include "../LowerCommManager.h"
|
||||||
class PowerManger; // 前向声明
|
#include "../PowerManger.h"
|
||||||
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
class HttpServer {
|
class HttpServer {
|
||||||
public:
|
public:
|
||||||
// 构造函数,传入PowerManger指针和端口号
|
// 构造函数,传入PowerManger指针和端口号
|
||||||
explicit HttpServer(int port = 8000);
|
HttpServer(int port = 8000);
|
||||||
|
|
||||||
// 析构函数
|
// 析构函数
|
||||||
~HttpServer();
|
~HttpServer();
|
||||||
@@ -34,10 +39,19 @@ public:
|
|||||||
void setLowerCommManager(LowerCommManager* lowerCommManager){
|
void setLowerCommManager(LowerCommManager* lowerCommManager){
|
||||||
m_lowerCommManager = lowerCommManager;
|
m_lowerCommManager = lowerCommManager;
|
||||||
}
|
}
|
||||||
|
void setPowerManger(PowerManger* powerManger){
|
||||||
|
m_powerManger = powerManger;
|
||||||
|
}
|
||||||
|
|
||||||
// 推送系统数据到所有WebSocket客户端
|
// 推送系统数据到所有WebSocket客户端
|
||||||
void pushSystemData();
|
void pushSystemData();
|
||||||
|
|
||||||
|
// 推送日志数据到指定客户端
|
||||||
|
void pushLogData(struct mg_connection* c, int page, int pageSize, const std::string& level, const std::string& search);
|
||||||
|
|
||||||
|
// 监控日志文件变化并推送新内容
|
||||||
|
void monitorLogFile();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// WebSocket事件处理函数
|
// WebSocket事件处理函数
|
||||||
void handleWebSocketEvent(struct mg_connection* c, int ev, void* ev_data, void* fn_data);
|
void handleWebSocketEvent(struct mg_connection* c, int ev, void* ev_data, void* fn_data);
|
||||||
@@ -49,6 +63,7 @@ private:
|
|||||||
// 后台系统数据
|
// 后台系统数据
|
||||||
SystemData *m_systemData = nullptr;
|
SystemData *m_systemData = nullptr;
|
||||||
LowerCommManager *m_lowerCommManager = nullptr;
|
LowerCommManager *m_lowerCommManager = nullptr;
|
||||||
|
PowerManger *m_powerManger = nullptr;
|
||||||
|
|
||||||
struct mg_mgr mgr_; // Mongoose管理器
|
struct mg_mgr mgr_; // Mongoose管理器
|
||||||
int port_; // 监听端口
|
int port_; // 监听端口
|
||||||
@@ -57,6 +72,27 @@ private:
|
|||||||
std::mutex ws_connections_mutex_; // WebSocket连接锁
|
std::mutex ws_connections_mutex_; // WebSocket连接锁
|
||||||
std::vector<mg_connection*> ws_connections_; // WebSocket连接列表
|
std::vector<mg_connection*> ws_connections_; // WebSocket连接列表
|
||||||
std::unordered_map<mg_connection*, uint64_t> ws_last_io_time_; // 连接最后活动时间
|
std::unordered_map<mg_connection*, uint64_t> ws_last_io_time_; // 连接最后活动时间
|
||||||
|
|
||||||
|
// 读取日志文件
|
||||||
|
std::vector<std::string> readLogFile(int page, int pageSize, const std::string& level, const std::string& search);
|
||||||
|
|
||||||
|
// 处理WebSocket消息
|
||||||
|
void handleWebSocketMessage(struct mg_connection* c, const std::string& msg);
|
||||||
|
|
||||||
|
// 日志文件相关
|
||||||
|
std::string m_logFilePath = "pPowerManger.log";
|
||||||
|
std::ifstream m_logFile;
|
||||||
|
std::streampos m_lastLogPosition = 0;
|
||||||
|
std::deque<std::string> m_logCache; // 缓存最近的日志
|
||||||
|
static const size_t MAX_CACHE_SIZE = 1000; // 最大缓存条数
|
||||||
|
|
||||||
|
// Log monitoring
|
||||||
|
std::string m_logPath;
|
||||||
|
std::deque<std::string> m_logCache;
|
||||||
|
std::mutex m_logMutex;
|
||||||
|
std::vector<struct mg_connection*> m_logSubscribers;
|
||||||
|
std::mutex m_subscriberMutex;
|
||||||
|
std::atomic<off_t> m_lastLogSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // HTTP_SERVER_H
|
#endif // HTTP_SERVER_H
|
||||||
+219
-1563
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,573 @@
|
|||||||
|
#ifndef HTTP_SERVER_LOGPAGE_H
|
||||||
|
#define HTTP_SERVER_LOGPAGE_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
const std::string LOG_PAGE_HTML = R"(
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>系统日志 - Power Manager</title>
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--primary-color: #2563eb;
|
||||||
|
--primary-hover: #1d4ed8;
|
||||||
|
--bg-color: #f8fafc;
|
||||||
|
--sidebar-width: 60px;
|
||||||
|
--sidebar-expanded: 220px;
|
||||||
|
--header-height: 36px;
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||||
|
background-color: var(--bg-color);
|
||||||
|
color: #1a1a1a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
display: grid;
|
||||||
|
grid-template-areas: "sidebar main-content";
|
||||||
|
grid-template-columns: var(--sidebar-width) 1fr;
|
||||||
|
grid-template-rows: 1fr;
|
||||||
|
min-height: 100vh;
|
||||||
|
gap: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header {
|
||||||
|
grid-area: unset;
|
||||||
|
background: white;
|
||||||
|
padding: 0 0.5rem;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
left: var(--sidebar-width);
|
||||||
|
height: var(--header-height);
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header h1 {
|
||||||
|
font-size: 1.25rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #1a1a1a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar {
|
||||||
|
grid-area: sidebar;
|
||||||
|
background: white;
|
||||||
|
width: var(--sidebar-width);
|
||||||
|
height: 100vh;
|
||||||
|
position: fixed;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
padding: 0.5rem 0.25rem;
|
||||||
|
transition: width 0.3s ease;
|
||||||
|
box-shadow: 1px 0 3px rgba(0, 0, 0, 0.1);
|
||||||
|
z-index: 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar:hover {
|
||||||
|
width: var(--sidebar-expanded);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-menu {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-button {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
border-radius: 0.375rem;
|
||||||
|
color: #4b5563;
|
||||||
|
text-decoration: none;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-button:hover {
|
||||||
|
background: var(--bg-color);
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-button.active {
|
||||||
|
background: var(--primary-color);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-icon {
|
||||||
|
min-width: 1.5rem;
|
||||||
|
margin-right: 1rem;
|
||||||
|
font-size: 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content {
|
||||||
|
grid-area: main-content;
|
||||||
|
padding: 1px;
|
||||||
|
margin-top: var(--header-height);
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-panel {
|
||||||
|
background: white;
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 6px;
|
||||||
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||||
|
height: calc(100vh - var(--header-height));
|
||||||
|
overflow: hidden;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-controls {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 4px;
|
||||||
|
border-bottom: 1px solid #e5e7eb;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-button {
|
||||||
|
padding: 4px 12px;
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: white;
|
||||||
|
color: #4b5563;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-button:hover {
|
||||||
|
background: var(--bg-color);
|
||||||
|
border-color: var(--primary-color);
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-filter {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
align-items: center;
|
||||||
|
margin-left: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-filter select, .log-filter input {
|
||||||
|
padding: 4px 8px;
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
color: #4b5563;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-filter input {
|
||||||
|
width: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-pagination {
|
||||||
|
display: flex;
|
||||||
|
gap: 4px;
|
||||||
|
align-items: center;
|
||||||
|
padding: 4px;
|
||||||
|
border-top: 1px solid #e5e7eb;
|
||||||
|
justify-content: space-between;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
color: #4b5563;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-info {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-size {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-size select {
|
||||||
|
padding: 2px 4px;
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-nav {
|
||||||
|
display: flex;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-nav button {
|
||||||
|
padding: 2px 8px;
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: white;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-nav button:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-content {
|
||||||
|
flex: 1;
|
||||||
|
overflow: auto;
|
||||||
|
padding: 8px;
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
background: #1a1a1a;
|
||||||
|
color: #f8fafc;
|
||||||
|
margin: 4px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-entry {
|
||||||
|
margin: 2px 0;
|
||||||
|
padding: 2px 4px;
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-entry:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-entry.error {
|
||||||
|
color: #f87171;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-entry.warning {
|
||||||
|
color: #fbbf24;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-entry.info {
|
||||||
|
color: #60a5fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-bar {
|
||||||
|
position: fixed;
|
||||||
|
top: 4px;
|
||||||
|
right: 8px;
|
||||||
|
background: white;
|
||||||
|
padding: 4px 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
z-index: 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-info {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
color: #4b5563;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<div class="sidebar">
|
||||||
|
<div class="sidebar-menu">
|
||||||
|
<a href="/data" class="sidebar-button">
|
||||||
|
<span class="sidebar-icon">📊</span>
|
||||||
|
<span>系统数据</span>
|
||||||
|
</a>
|
||||||
|
<a href="/dashboard" class="sidebar-button">
|
||||||
|
<span class="sidebar-icon">⚡</span>
|
||||||
|
<span>配电操作</span>
|
||||||
|
</a>
|
||||||
|
<a href="/logs" class="sidebar-button active">
|
||||||
|
<span class="sidebar-icon">📝</span>
|
||||||
|
<span>系统日志</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="header">
|
||||||
|
<h1>系统日志</h1>
|
||||||
|
<div class="status-bar">
|
||||||
|
<div class="status-info">
|
||||||
|
<span>🟢 系统状态: 运行中</span>
|
||||||
|
<span>🕒 更新时间: <time id="updateTime">2025-05-18 15:52</time></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="main-content">
|
||||||
|
<div class="log-panel">
|
||||||
|
<div class="log-controls">
|
||||||
|
<button class="log-button" id="clearBtn">清空显示</button>
|
||||||
|
<button class="log-button" id="scrollLockBtn">自动滚动</button>
|
||||||
|
<button class="log-button" id="downloadBtn">下载日志</button>
|
||||||
|
<div class="log-filter">
|
||||||
|
<select id="logLevel">
|
||||||
|
<option value="ALL">所有级别</option>
|
||||||
|
<option value="ERROR">错误</option>
|
||||||
|
<option value="WARNING">警告</option>
|
||||||
|
<option value="INFO">信息</option>
|
||||||
|
</select>
|
||||||
|
<input type="text" id="searchInput" placeholder="搜索日志...">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="log-content" id="logContent"></div>
|
||||||
|
<div class="log-pagination">
|
||||||
|
<div class="page-size">
|
||||||
|
每页显示:
|
||||||
|
<select id="pageSize">
|
||||||
|
<option value="100">100</option>
|
||||||
|
<option value="200">200</option>
|
||||||
|
<option value="500">500</option>
|
||||||
|
<option value="1000">1000</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="page-info">
|
||||||
|
<span id="pageInfo">第 0/0 页</span>
|
||||||
|
<div class="page-nav">
|
||||||
|
<button id="firstPage">首页</button>
|
||||||
|
<button id="prevPage">上一页</button>
|
||||||
|
<button id="nextPage">下一页</button>
|
||||||
|
<button id="lastPage">末页</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
let ws = null;
|
||||||
|
let autoScroll = true;
|
||||||
|
let logContent = document.getElementById('logContent');
|
||||||
|
let currentPage = 1;
|
||||||
|
let totalPages = 1;
|
||||||
|
let pageSize = 100;
|
||||||
|
let allLogs = [];
|
||||||
|
let filteredLogs = [];
|
||||||
|
let searchTimer = null;
|
||||||
|
|
||||||
|
function initWebSocket() {
|
||||||
|
ws = new WebSocket('ws://' + window.location.host + '/ws');
|
||||||
|
|
||||||
|
ws.onopen = () => {
|
||||||
|
console.log('WebSocket连接已建立');
|
||||||
|
updateStatus('运行中', true);
|
||||||
|
requestLogs();
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.onmessage = (event) => {
|
||||||
|
const data = JSON.parse(event.data);
|
||||||
|
if (data.type === 'log') {
|
||||||
|
if (Array.isArray(data.content)) {
|
||||||
|
// 初始加载的日志数据
|
||||||
|
allLogs = data.content;
|
||||||
|
filterAndDisplayLogs();
|
||||||
|
} else {
|
||||||
|
// 新的日志条目
|
||||||
|
allLogs.push(data.content);
|
||||||
|
if (shouldShowLog(data.content)) {
|
||||||
|
appendLogEntry(data.content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateTime();
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.onclose = () => {
|
||||||
|
console.log('WebSocket连接已关闭');
|
||||||
|
updateStatus('已断开', false);
|
||||||
|
setTimeout(initWebSocket, 5000);
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.onerror = (error) => {
|
||||||
|
console.error('WebSocket错误:', error);
|
||||||
|
updateStatus('错误', false);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestLogs() {
|
||||||
|
ws.send(JSON.stringify({
|
||||||
|
type: 'get_logs',
|
||||||
|
page: currentPage,
|
||||||
|
pageSize: pageSize,
|
||||||
|
filter: {
|
||||||
|
level: document.getElementById('logLevel').value,
|
||||||
|
search: document.getElementById('searchInput').value
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
function shouldShowLog(logEntry) {
|
||||||
|
const level = document.getElementById('logLevel').value;
|
||||||
|
const search = document.getElementById('searchInput').value.toLowerCase();
|
||||||
|
|
||||||
|
if (level !== 'ALL') {
|
||||||
|
if (!logEntry.includes(level)) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (search && !logEntry.toLowerCase().includes(search)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterAndDisplayLogs() {
|
||||||
|
filteredLogs = allLogs.filter(shouldShowLog);
|
||||||
|
totalPages = Math.ceil(filteredLogs.length / pageSize);
|
||||||
|
displayCurrentPage();
|
||||||
|
updatePagination();
|
||||||
|
}
|
||||||
|
|
||||||
|
function displayCurrentPage() {
|
||||||
|
logContent.innerHTML = '';
|
||||||
|
const start = (currentPage - 1) * pageSize;
|
||||||
|
const end = Math.min(start + pageSize, filteredLogs.length);
|
||||||
|
|
||||||
|
for (let i = start; i < end; i++) {
|
||||||
|
appendLogEntry(filteredLogs[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updatePagination() {
|
||||||
|
document.getElementById('pageInfo').textContent = `第 ${currentPage}/${totalPages} 页`;
|
||||||
|
document.getElementById('firstPage').disabled = currentPage === 1;
|
||||||
|
document.getElementById('prevPage').disabled = currentPage === 1;
|
||||||
|
document.getElementById('nextPage').disabled = currentPage === totalPages;
|
||||||
|
document.getElementById('lastPage').disabled = currentPage === totalPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 事件监听器
|
||||||
|
document.getElementById('logLevel').addEventListener('change', () => {
|
||||||
|
currentPage = 1;
|
||||||
|
filterAndDisplayLogs();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('searchInput').addEventListener('input', (e) => {
|
||||||
|
clearTimeout(searchTimer);
|
||||||
|
searchTimer = setTimeout(() => {
|
||||||
|
currentPage = 1;
|
||||||
|
filterAndDisplayLogs();
|
||||||
|
}, 300);
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('pageSize').addEventListener('change', (e) => {
|
||||||
|
pageSize = parseInt(e.target.value);
|
||||||
|
currentPage = 1;
|
||||||
|
filterAndDisplayLogs();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('firstPage').addEventListener('click', () => {
|
||||||
|
currentPage = 1;
|
||||||
|
displayCurrentPage();
|
||||||
|
updatePagination();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('prevPage').addEventListener('click', () => {
|
||||||
|
if (currentPage > 1) {
|
||||||
|
currentPage--;
|
||||||
|
displayCurrentPage();
|
||||||
|
updatePagination();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('nextPage').addEventListener('click', () => {
|
||||||
|
if (currentPage < totalPages) {
|
||||||
|
currentPage++;
|
||||||
|
displayCurrentPage();
|
||||||
|
updatePagination();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('lastPage').addEventListener('click', () => {
|
||||||
|
currentPage = totalPages;
|
||||||
|
displayCurrentPage();
|
||||||
|
updatePagination();
|
||||||
|
});
|
||||||
|
|
||||||
|
function appendLogEntry(content) {
|
||||||
|
const entry = document.createElement('div');
|
||||||
|
entry.className = 'log-entry';
|
||||||
|
|
||||||
|
// 根据日志内容设置不同的样式
|
||||||
|
if (content.includes('ERROR')) {
|
||||||
|
entry.classList.add('error');
|
||||||
|
} else if (content.includes('WARNING')) {
|
||||||
|
entry.classList.add('warning');
|
||||||
|
} else if (content.includes('INFO')) {
|
||||||
|
entry.classList.add('info');
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.textContent = content;
|
||||||
|
logContent.appendChild(entry);
|
||||||
|
|
||||||
|
if (autoScroll) {
|
||||||
|
logContent.scrollTop = logContent.scrollHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateStatus(status, isConnected) {
|
||||||
|
const statusElement = document.querySelector('.status-info span:first-child');
|
||||||
|
statusElement.innerHTML = `${isConnected ? '🟢' : '🔴'} 系统状态: ${status}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateTime() {
|
||||||
|
const now = new Date();
|
||||||
|
const timeStr = now.toLocaleString('zh-CN', {
|
||||||
|
year: 'numeric',
|
||||||
|
month: '2-digit',
|
||||||
|
day: '2-digit',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
second: '2-digit',
|
||||||
|
hour12: false
|
||||||
|
});
|
||||||
|
document.getElementById('updateTime').textContent = timeStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按钮事件处理
|
||||||
|
document.getElementById('clearBtn').onclick = () => {
|
||||||
|
logContent.innerHTML = '';
|
||||||
|
};
|
||||||
|
|
||||||
|
document.getElementById('scrollLockBtn').onclick = function() {
|
||||||
|
autoScroll = !autoScroll;
|
||||||
|
this.textContent = autoScroll ? '自动滚动' : '已锁定';
|
||||||
|
this.style.backgroundColor = autoScroll ? 'white' : '#e5e7eb';
|
||||||
|
};
|
||||||
|
|
||||||
|
document.getElementById('downloadBtn').onclick = () => {
|
||||||
|
const text = logContent.innerText;
|
||||||
|
const blob = new Blob([text], { type: 'text/plain' });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = `system_log_${new Date().toISOString().slice(0,19).replace(/[:-]/g, '')}.txt`;
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
document.body.removeChild(a);
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('load', initWebSocket);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
)";
|
||||||
|
|
||||||
|
#endif // HTTP_SERVER_LOGPAGE_H
|
||||||
@@ -135,6 +135,9 @@ public:
|
|||||||
uint32_t reserved4; // 保留字段
|
uint32_t reserved4; // 保留字段
|
||||||
uint32_t heartbeat; // 主机心跳计数器
|
uint32_t heartbeat; // 主机心跳计数器
|
||||||
|
|
||||||
|
|
||||||
|
// MOOSD 状态
|
||||||
|
bool moosd_status;
|
||||||
//配电系统状态
|
//配电系统状态
|
||||||
//动力母线状态
|
//动力母线状态
|
||||||
struct POWER_BUS_STATUS
|
struct POWER_BUS_STATUS
|
||||||
@@ -397,6 +400,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void updateSystemData(ccuState data){
|
void updateSystemData(ccuState data){
|
||||||
|
|
||||||
fc_mode = data.fc_mode;
|
fc_mode = data.fc_mode;
|
||||||
fc_status = data.fc_status;
|
fc_status = data.fc_status;
|
||||||
fc_fault_level = data.fc_fault_level;
|
fc_fault_level = data.fc_fault_level;
|
||||||
|
|||||||
Reference in New Issue
Block a user