523调试

This commit is contained in:
zjk
2025-05-23 15:38:23 +08:00
parent 3a14a3cff8
commit ee050bb58b
13 changed files with 1209 additions and 939 deletions
@@ -10,6 +10,7 @@
#include "logpage.h"
#include "testpage.h"
#include "degubpage.h"
#include "batteryoperation.h"
using json = Json::Value;
@@ -90,6 +91,55 @@ void HttpServer::handleWebSocketEvent(struct mg_connection* c, int ev, void* ev_
} else if (mg_match(hm->uri, mg_str("/debug"), NULL)) {
// 返回调试页面HTML
mg_http_reply(c, 200, "Content-Type: text/html; charset=utf-8\r\n", DEBUGPAGE_HTML.c_str());
} else if (mg_match(hm->uri, mg_str("/battery"), NULL)) {
// 返回电池操作页面HTML
mg_http_reply(c, 200, "Content-Type: text/html; charset=utf-8\r\n", BATTERY_OPERATION_HTML.c_str());
} else if (mg_match(hm->uri, mg_str("/battery/control"), NULL)) {
// 处理电池控制POST请求
if (mg_strcmp(hm->method, mg_str("POST")) == 0) {
// 解析表单数据
struct mg_str body = hm->body;
unsigned char fuelCellMode = 0;
unsigned char fuelCellCommand = 0;
unsigned short fuelCellPower = 0;
unsigned char instrumentBattery = 0;
unsigned char powerBattery = 0;
unsigned short powerBatteryPower = 0;
char tmp[16] = {0};
mg_http_get_var(&body, "fuelCellMode", tmp, sizeof(tmp));
fuelCellMode = (unsigned char)strtoul(tmp, NULL, 16);
mg_http_get_var(&body, "fuelCellCommand", tmp, sizeof(tmp));
fuelCellCommand = (unsigned char)strtoul(tmp, NULL, 16);
mg_http_get_var(&body, "fuelCellPower", tmp, sizeof(tmp));
fuelCellPower = (unsigned short)atoi(tmp);
mg_http_get_var(&body, "instrumentBattery", tmp, sizeof(tmp));
instrumentBattery = (unsigned char)strtoul(tmp, NULL, 16);
mg_http_get_var(&body, "powerBattery", tmp, sizeof(tmp));
powerBattery = (unsigned char)strtoul(tmp, NULL, 16);
mg_http_get_var(&body, "powerBatteryPower", tmp, sizeof(tmp));
powerBatteryPower = (unsigned short)atoi(tmp);
// 记录接收到的配置
LOG_F(INFO, "Received battery control config: "
"fuelCellMode=%02XH, fuelCellCommand=%02XH, fuelCellPower=%d, "
"instrumentBattery=%02XH, powerBattery=%02XH, powerBatteryPower=%d",
fuelCellMode, fuelCellCommand, fuelCellPower,
instrumentBattery, powerBattery, powerBatteryPower);
m_powerManger->m_CcuColCmd.fcmode = fuelCellMode;
m_powerManger->m_CcuColCmd.fcuCmd = fuelCellCommand;
m_powerManger->m_CcuColCmd.fcuPowerEfficiency = fuelCellPower;
m_powerManger->m_CcuColCmd.insBatCmd = instrumentBattery;
m_powerManger->m_CcuColCmd.powerBatCmd = powerBattery;
m_powerManger->m_CcuColCmd.powerBatEfficiency = powerBatteryPower;
mg_http_reply(c, 200, "Content-Type: application/json\r\n",
"{\"success\": true, \"message\": \"电池配置提交成功\"}");
} else {
mg_http_reply(c, 405, "Content-Type: text/plain\r\n", "Method Not Allowed");
}
} else if (mg_match(hm->uri, mg_str("/ws/debug"), NULL)) {
// 升级到调试WebSocket连接
LOG_F(INFO, "Upgrading to Debug WebSocket: id=%lu fd=%d", c->id, c->fd);