完成了网页控制断路器

This commit is contained in:
zjk
2025-05-17 22:39:08 +08:00
parent fb23554408
commit ab803d8d7e
8 changed files with 640 additions and 41 deletions
+330 -8
View File
@@ -76,7 +76,7 @@ bool LowerCommManager::initUdpComm(){
return true;
}
void LowerCommManager::processPeriodicTasks() {
sendCcuCommand(m_pm->m_CcuColCmd);
// sendCcuCommand(m_pm->m_CcuColCmd);
//延时5ms
usleep(5000);
// sendDisSysCommand(m_pm->m_targetDisBreakerState);
@@ -352,12 +352,6 @@ char LowerCommManager::getBreakerOption(char cmd)
return 0x00;
}
//TODO:根据心跳检查连接状态
bool LowerCommManager::checkConnection()
{
m_pm->connectState =5;
}
void LowerCommManager::coutMsg(const msg_CcuStateFbMsg& p, std::ostream& os){
os << std::hex << std::setfill('0') << std::uppercase;
@@ -476,4 +470,332 @@ void LowerCommManager::coutMsg(const msg_CcuStateFbMsg& p, std::ostream& os){
os << "校验和 (checksum): 0x" << p.checkCode << "\n";
os << std::dec;
}
}
//================================================================================================================
// 高电压母线断路器操作函数
bool LowerCommManager::operate_HV_fuelCellCircuit_Breaker(char opt){
return operateBreakerGeneric<disHighVolBusCmd, char>(
"HV_fuelCellCircuit_Breaker",
opt,
[&](disHighVolBusCmd& c){ c.fuelCellCircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus1State.fuelCellCircuitBreaker; }
);
}
bool LowerCommManager::operate_HV_powerLithiumBattery_Breaker(char opt){
return operateBreakerGeneric<disHighVolBusCmd, char>(
"HV_powerLithiumBattery_Breaker",
opt,
[&](disHighVolBusCmd& c){ c.powerLithiumBatteryCircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus1State.powerLithiumBatteryCircuitBreaker; }
);
}
bool LowerCommManager::operate_HV_propulsionMotor_Breaker(char opt){
return operateBreakerGeneric<disHighVolBusCmd, char>(
"HV_propulsionMotor_Breaker",
opt,
[&](disHighVolBusCmd& c){ c.propulsionMotorCircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus1State.propulsionMotorCircuitBreaker; }
);
}
bool LowerCommManager::operate_HV_lithiumBatteryMeter_Breaker(char opt){
return operateBreakerGeneric<disHighVolBusCmd, char>(
"HV_lithiumBatteryMeter_Breaker",
opt,
[&](disHighVolBusCmd& c){ c.lithiumBatteryGroupInstrumentCircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus1State.lithiumBatteryGroupInstrumentCircuitBreaker; }
);
}
bool LowerCommManager::operate_HV_dcDc5Module_Breaker(char opt){
return operateBreakerGeneric<disHighVolBusCmd, char>(
"HV_dcDc5Module_Breaker",
opt,
[&](disHighVolBusCmd& c){ c.dcDc5ModuleCircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus1State.dcDc5ModuleCircuitBreaker; }
);
}
bool LowerCommManager::operate_HV_bowHighVoltageBox_Breaker(char opt){
return operateBreakerGeneric<disHighVolBusCmd, char>(
"HV_bowHighVoltageBox_Breaker",
opt,
[&](disHighVolBusCmd& c){ c.bowHighVoltageDistributionBoxCircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus1State.bowHighVoltageDistributionBoxCircuitBreaker; }
);
}
bool LowerCommManager::operate_HV_sternFt45_Breaker(char opt){
return operateBreakerGeneric<disHighVolBusCmd, char>(
"HV_sternFt45_Breaker",
opt,
[&](disHighVolBusCmd& c){ c.sternFTDevice45CircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus1State.sternFTDevice45CircuitBreaker; }
);
}
bool LowerCommManager::operate_HV_sternRudder1_Breaker(char opt){
return operateBreakerGeneric<disHighVolBusCmd, char>(
"HV_sternRudder1_Breaker",
opt,
[&](disHighVolBusCmd& c){ c.sternRudderSwitch1CircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus1State.sternRudderSwitch1CircuitBreaker; }
);
}
bool LowerCommManager::operate_HV_sternRudder2_Breaker(char opt){
return operateBreakerGeneric<disHighVolBusCmd, char>(
"HV_sternRudder2_Breaker",
opt,
[&](disHighVolBusCmd& c){ c.sternRudderSwitch2CircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus1State.sternRudderSwitch2CircuitBreaker; }
);
}
bool LowerCommManager::operate_HV_fbReserved_Breaker(char opt){
return operateBreakerGeneric<disHighVolBusCmd, char>(
"HV_fbReserved_Breaker",
opt,
[&](disHighVolBusCmd& c){ c.fbReservedCircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus1State.fbReservedCircuitBreaker; }
);
}
bool LowerCommManager::operate_HV_tyzReserved_Breaker(char opt){
return operateBreakerGeneric<disHighVolBusCmd, char>(
"HV_tyzReserved_Breaker",
opt,
[&](disHighVolBusCmd& c){ c.tyzReservedCircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus1State.tyzReservedCircuitBreaker; }
);
}
bool LowerCommManager::operate_HV_reserved_Breaker(char opt){
return operateBreakerGeneric<disHighVolBusCmd, char>(
"HV_reserved_Breaker",
opt,
[&](disHighVolBusCmd& c){ c.reservedCircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus1State.reservedCircuitBreaker; }
);
}
bool LowerCommManager::operate_HV_dcDc5_Breaker(char opt){
return operateBreakerGeneric<disHighVolBusCmd, char>(
"HV_dcDc5_Breaker",
opt,
[&](disHighVolBusCmd& c){ c.dcdc5Module = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus1State.dcDcFaultWord1&(0x02); }
);
}
bool LowerCommManager::operate_HV_coolingSystem_Breaker(char opt){
return operateBreakerGeneric<disHighVolBusCmd, char>(
"HV_coolingSystem_Breaker",
opt,
[&](disHighVolBusCmd& c){ c.coolingSystem = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus1State.dcDcFaultWord1&(0x20); }
);
}
// 高压汇流排断路器操作函数
bool LowerCommManager::operate_HVA_bowFTDevice123Circuit_Breaker(char opt){
return operateBreakerGeneric<disHighAVolBusCmd, char>(
"HVA_bowFTDevice123Circuit_Breaker",
opt,
[&](disHighAVolBusCmd& c){ c.bowFTDevice123CircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus2State.bowFTDevice123CircuitBreaker; }
);
}
bool LowerCommManager::operate_HVA_actuatorCircuit_Breaker(char opt){
return operateBreakerGeneric<disHighAVolBusCmd, char>(
"HVA_actuatorCircuit_Breaker",
opt,
[&](disHighAVolBusCmd& c){ c.actuatorCircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus2State.actuatorCircuitBreaker; }
);
}
bool LowerCommManager::operate_HVA_mastSteeringGearControlBoxCircuit_Breaker(char opt){
return operateBreakerGeneric<disHighAVolBusCmd, char>(
"HVA_mastSteeringGearControlBoxCircuit_Breaker",
opt,
[&](disHighAVolBusCmd& c){ c.mastSteeringGearControlBoxCircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus2State.mastSteeringGearControlBoxCircuitBreaker; }
);
}
bool LowerCommManager::operate_HVA_xczCircuit_Breaker(char opt){
return operateBreakerGeneric<disHighAVolBusCmd, char>(
"HVA_xczCircuit_Breaker",
opt,
[&](disHighAVolBusCmd& c){ c.xczCircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus2State.xczCircuitBreaker; }
);
}
bool LowerCommManager::operate_HVA_bowRudderControlBoxCircuit_Breaker(char opt){
return operateBreakerGeneric<disHighAVolBusCmd, char>(
"HVA_bowRudderControlBoxCircuit_Breaker",
opt,
[&](disHighAVolBusCmd& c){ c.bowRudderControlBoxCircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus2State.bowRudderControlBoxCircuitBreaker; }
);
}
bool LowerCommManager::operate_HVA_openWaterCoverStartCylinderCircuit_Breaker(char opt){
return operateBreakerGeneric<disHighAVolBusCmd, char>(
"HVA_openWaterCoverStartCylinderCircuit_Breaker",
opt,
[&](disHighAVolBusCmd& c){ c.openWaterCoverStartCylinderCircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus2State.openWaterCoverStartCylinderCircuitBreaker; }
);
}
// 仪表汇流排断路器操作函数
bool LowerCommManager::operate_LVA_unit1Circuit_Breaker(char opt){
return operateBreakerGeneric<disLowBusCmd, char>(
"LVA_unit1Circuit_Breaker",
opt,
[&](disLowBusCmd& c){ c.unit1CircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus4State.unit1CircuitBreaker; }
);
}
bool LowerCommManager::operate_LVA_unit2Circuit_Breaker(char opt){
return operateBreakerGeneric<disLowBusCmd, char>(
"LVA_unit2Circuit_Breaker",
opt,
[&](disLowBusCmd& c){ c.unit2CircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus4State.unit2CircuitBreaker; }
);
}
bool LowerCommManager::operate_LVA_unit3Circuit_Breaker(char opt){
return operateBreakerGeneric<disLowBusCmd, char>(
"LVA_unit3Circuit_Breaker",
opt,
[&](disLowBusCmd& c){ c.unit3CircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus4State.unit3CircuitBreaker; }
);
}
bool LowerCommManager::operate_LVA_unit5Circuit_Breaker(char opt){
return operateBreakerGeneric<disLowBusCmd, char>(
"LVA_unit5Circuit_Breaker",
opt,
[&](disLowBusCmd& c){ c.unit5CircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus4State.unit5CircuitBreaker; }
);
}
bool LowerCommManager::operate_LVA_bowPZDeviceCircuit_Breaker(char opt){
return operateBreakerGeneric<disLowBusCmd, char>(
"LVA_bowPZDeviceCircuit_Breaker",
opt,
[&](disLowBusCmd& c){ c.bowPZDeviceCircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus4State.bowPZDeviceCircuitBreaker; }
);
}
bool LowerCommManager::operate_LVA_reservedCircuit1_Breaker(char opt){
return operateBreakerGeneric<disLowBusCmd, char>(
"LVA_reservedCircuit1_Breaker",
opt,
[&](disLowBusCmd& c){ c.reservedCircuitBreaker1 = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus4State.reservedCircuitBreaker1; }
);
}
bool LowerCommManager::operate_LVA_reservedCircuit2_Breaker(char opt){
return operateBreakerGeneric<disLowBusCmd, char>(
"LVA_reservedCircuit2_Breaker",
opt,
[&](disLowBusCmd& c){ c.reservedCircuitBreaker2 = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus4State.reservedCircuitBreaker2; }
);
}
bool LowerCommManager::operate_LVA_mergencyLithiumBatteryGroup1Circuit_Breaker(char opt){
return operateBreakerGeneric<disLowBusCmd, char>(
"LVA_mergencyLithiumBatteryGroup1Circuit_Breaker",
opt,
[&](disLowBusCmd& c){ c.emergencyLithiumBatteryGroup1CircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus4State.emergencyLithiumBatteryGroup1CircuitBreaker; }
);
}
// 仪表母线断路器操作函数
bool LowerCommManager::operate_LV_lithiumBatteryGroupInstrumentCircuit_Breaker(char opt){
return operateBreakerGeneric<disLowMainBusCmd, char>(
"HV_fuelCellCircuit_Breaker",
opt,
[&](disLowMainBusCmd& c){ c.lithiumBatteryGroupInstrumentCircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus3State.lithiumBatteryGroupInstrumentCircuitBreaker; }
);
}
bool LowerCommManager::operate_LV_bowLowVoltageDistributionBoxCircuit_Breaker(char opt){
return operateBreakerGeneric<disLowMainBusCmd, char>(
"HV_fuelCellCircuit_Breaker",
opt,
[&](disLowMainBusCmd& c){ c.bowLowVoltageDistributionBoxCircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus3State.bowLowVoltageDistributionBoxCircuitBreaker; }
);
}
bool LowerCommManager::operate_LV_unit4Dc48V_Breaker(char opt){
return operateBreakerGeneric<disLowMainBusCmd, char>(
"HV_fuelCellCircuit_Breaker",
opt,
[&](disLowMainBusCmd& c){ c.unit4InstrumentDC48VCircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus3State.unit4InstrumentDC48VCircuitBreaker; }
);
}
bool LowerCommManager::operate_LV_dcC1Panel_Breaker(char opt){
return operateBreakerGeneric<disLowMainBusCmd, char>(
"HV_fuelCellCircuit_Breaker",
opt,
[&](disLowMainBusCmd& c){ c.dcC1DCDistributionPanelCircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus3State.dcC1DCDistributionPanelCircuitBreaker; }
);
}
bool LowerCommManager::operate_LV_reservedCircuit1_Breaker(char opt){
return operateBreakerGeneric<disLowMainBusCmd, char>(
"HV_fuelCellCircuit_Breaker",
opt,
[&](disLowMainBusCmd& c){ c.reservedCircuitBreaker1 = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus3State.reservedCircuitBreaker1; }
);
}
bool LowerCommManager::operate_LV_reservedCircuit2_Breaker(char opt){
return operateBreakerGeneric<disLowMainBusCmd, char>(
"HV_fuelCellCircuit_Breaker",
opt,
[&](disLowMainBusCmd& c){ c.reservedCircuitBreaker2 = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus3State.reservedCircuitBreaker2; }
);
}
bool LowerCommManager::operate_LV_mergencyLithiumBatteryGroup2Circuit_Breaker(char opt){
return operateBreakerGeneric<disLowMainBusCmd, char>(
"HV_fuelCellCircuit_Breaker",
opt,
[&](disLowMainBusCmd& c){ c.emergencyLithiumBatteryGroup2CircuitBreaker = getBreakerOption(opt); },
[&](){ return m_pm->m_pmCurrentState.bus3State.emergencyLithiumBatteryGroup2CircuitBreaker; }
);
}
// 通用模板
template<typename CmdT, typename StateT>
bool LowerCommManager::operateBreakerGeneric(
char const* name,
char opt,
std::function<void(CmdT&)> fillCmd, // 填 cmd 对应字段
std::function<StateT()> readState // 读 pmCurrentState 对应字段
) {
CmdT cmd{}; // 默认全零
double t0 = MOOSTime();
LOG_F(INFO, "operate %s: opt=%d", name, opt);
// 第一次发包
fillCmd(cmd);
m_udpComm->sendDisSysCmd(cmd);
MOOSPause(100);
// 等待状态变更
while ( readState() != getBreakerOption(opt) ) {
if (!m_udpComm->sendDisSysCmd(cmd)) {
LOG_F(ERROR, "operate %s: sendDisSysCmd failed", name);
return false;
}
if (MOOSTime() > t0 + 5) {
LOG_F(ERROR, "operate %s: timeout", name);
return false;
}
MOOSPause(1000);
}
// 清零再发三次
CmdT clr{};
for (int i = 0; i < 3; ++i)
{
m_udpComm->sendDisSysCmd(clr);
MOOSPause(100);
}
return true;
}
+51 -9
View File
@@ -13,6 +13,7 @@
#include <atomic>
#include <vector>
#include "udpComm.h"
#include <functional>
class PowerManger; // 前向声明
@@ -30,19 +31,60 @@ public:
// 初始化UDP通信
bool initUdpComm();
// TODO:实现连接检查功能
bool checkConnection();
// 更新设备状态
bool updatePoweSystemStates();
//================================断路器操作函数=======================================
template<typename CmdT, typename StateT>
bool operateBreakerGeneric(
char const* name,
char opt,
std::function<void(CmdT&)> fillCmd, // 填 cmd 对应字段
std::function<StateT()> readState // 读 pmCurrentState 对应字段
);
// 高电压母线
bool operate_HV_fuelCellCircuit_Breaker(char opt);
bool operate_HV_powerLithiumBattery_Breaker(char opt);
bool operate_HV_propulsionMotor_Breaker(char opt);
bool operate_HV_lithiumBatteryMeter_Breaker(char opt);
bool operate_HV_dcDc5Module_Breaker(char opt);
bool operate_HV_bowHighVoltageBox_Breaker(char opt);
bool operate_HV_sternFt45_Breaker(char opt);
bool operate_HV_sternRudder1_Breaker(char opt);
bool operate_HV_sternRudder2_Breaker(char opt);
bool operate_HV_fbReserved_Breaker(char opt);
bool operate_HV_tyzReserved_Breaker(char opt);
bool operate_HV_reserved_Breaker(char opt);
bool operate_HV_dcDc5_Breaker(char opt);
bool operate_HV_coolingSystem_Breaker(char opt);
// 高压汇流排
bool operate_HVA_bowFTDevice123Circuit_Breaker(char opt);
bool operate_HVA_actuatorCircuit_Breaker(char opt);
bool operate_HVA_mastSteeringGearControlBoxCircuit_Breaker(char opt);
bool operate_HVA_xczCircuit_Breaker(char opt);
bool operate_HVA_bowRudderControlBoxCircuit_Breaker(char opt);
bool operate_HVA_openWaterCoverStartCylinderCircuit_Breaker(char opt);
// 仪表母线
bool operate_LV_lithiumBatteryGroupInstrumentCircuit_Breaker(char opt);
bool operate_LV_bowLowVoltageDistributionBoxCircuit_Breaker(char opt);
bool operate_LV_unit4Dc48V_Breaker(char opt);
bool operate_LV_dcC1Panel_Breaker(char opt);
bool operate_LV_reservedCircuit1_Breaker(char opt);
bool operate_LV_reservedCircuit2_Breaker(char opt);
bool operate_LV_mergencyLithiumBatteryGroup2Circuit_Breaker(char opt);
// 仪表汇流排
bool operate_LVA_unit1Circuit_Breaker(char opt);
bool operate_LVA_unit2Circuit_Breaker(char opt);
bool operate_LVA_unit3Circuit_Breaker(char opt);
bool operate_LVA_unit5Circuit_Breaker(char opt);
bool operate_LVA_bowPZDeviceCircuit_Breaker(char opt);
bool operate_LVA_reservedCircuit1_Breaker(char opt);
bool operate_LVA_reservedCircuit2_Breaker(char opt);
bool operate_LVA_mergencyLithiumBatteryGroup1Circuit_Breaker(char opt);
//========================================================================================
// 发送CCU控制命令
bool sendCcuCommand(const ccuColCmd cmd);
bool sendDisSysCommand(const disSysBreakerList& cmd);
// 获取通信状态
int getConnectionState() const { return m_connectState; }
bool sendDisSysCommand(const disSysBreakerList& cmd); //已废弃,不同时操作多个继电器设备
// 启动/停止监听线程
void startListenThread();
void stopListenThread();
+6 -4
View File
@@ -59,12 +59,15 @@ PowerManger::PowerManger()
m_db = new SQLite("power_data.db");
m_db->createTable();
//初始化http服务器
m_httpServer = new HttpServer(8090);
//初始化系统数据
m_systemData = new SystemData();
//初始化http服务器
m_httpServer = new HttpServer(8090);
m_httpServer->setLowerCommManager(m_lowerCommManager);
m_httpServer->setSystemData(m_systemData);
m_httpServer->start();
}
//---------------------------------------------------------
@@ -135,7 +138,6 @@ bool PowerManger::Iterate()
CycleTriggeredEvent cycleEvent;
PowerManagerFsm::dispatch(cycleEvent);
faultLevel = getFaultLevel();
// 更新系统数据
m_systemData->updateSystemData(m_pmCurrentState.ccustate);
m_systemData->updateSystemData(m_pmCurrentState.bus1State);
@@ -148,7 +150,7 @@ bool PowerManger::Iterate()
m_systemData->device_common_status.dis_lv_c1.lastUpdateTime = m_lowerCommManager->msg_disHighBVolBusFbMsg_Update_time;
m_systemData->device_common_status.dis_lv_c2.lastUpdateTime = m_lowerCommManager->msg_disLowBusFbMsg_Update_time;
m_systemData->updateCommonStatus();
if (m_ticker++ % 5 == 0)
{
m_CcuColCmd.heartbeat++;
+3 -2
View File
@@ -40,7 +40,8 @@
#define IPORT 5001
#define CCUPORT 7000
#define CCUHOST "192.168.0.140"
// #define CCUHOST "192.168.0.140"
#define CCUHOST "127.0.0.0"
#define MAX_UDP_PKT_SIZE 65535
#define SKEW_TOLERANCE 5
@@ -84,7 +85,7 @@ class PowerManger : public AppCastingMOOSApp
ccuColCmd m_CcuColCmd;
disSysBreakerList m_targetDisBreakerState;
//===========================FEEDBACK======================================
pmState m_pmCurrentState; //能源系统的当前状态
pmState m_pmCurrentState; //能源系统的当前状态(由下位机线程修改)
disSysBreakerList m_currentDisBreakerState; //配电断路器状态
DriverTable m_currentDriverState;
DriverTable m_subDisSysState;
+103 -13
View File
@@ -71,13 +71,103 @@ void HttpServer::handleWebSocketEvent(struct mg_connection* c, int ev, void* ev_
char *device_id = mg_json_get_str(hm->body, "$.device_id");
char *action = mg_json_get_str(hm->body, "$.action");
bool success = true;
std::string device_type_str = device_type? std::string(device_type) : "";
std::string device_id_str = device_id ? std::string(device_id) : "";
std::string action_str = action ? std::string(action) : "";
if (device_type && device_id && action) {
//TODO: 处理断路器控制逻辑
LOG_F(INFO, "Received control request: device_type=%s, device_id=%s, action=%s ,from Net DashBoard id=%lu fd=%d",
device_type, device_id, action, c->id, c->fd);
device_type, device_id, action, c->id, c->fd);
char opt = (action_str == "open") ? 0 : 1;
if(device_type_str == "meter_bus")
{
if (device_id_str == "battery_meter")
{
success = m_lowerCommManager->operate_LV_lithiumBatteryGroupInstrumentCircuit_Breaker(opt);
} else if (device_id_str == "bow_low_dist")
{
success = m_lowerCommManager->operate_LV_bowLowVoltageDistributionBoxCircuit_Breaker(opt);
} else if (device_id_str == "unit4_dc48v"){
success = m_lowerCommManager->operate_LV_unit4Dc48V_Breaker(opt);
} else if (device_id_str == "dc_c1"){
success = m_lowerCommManager->operate_LV_dcC1Panel_Breaker(opt);
} else if(device_id_str == "reserve1"){
success = m_lowerCommManager->operate_LV_reservedCircuit1_Breaker(opt);
} else if(device_id_str == "reserve2"){
success = m_lowerCommManager->operate_LV_reservedCircuit2_Breaker(opt);
} else if(device_id_str == "emergency_battery2"){
success = m_lowerCommManager->operate_LV_mergencyLithiumBatteryGroup2Circuit_Breaker(opt);
}
}
else if (device_type_str == "bow_high_vol")
{
if (device_id_str == "bow_ft1_3") {
success = m_lowerCommManager->operate_HVA_bowFTDevice123Circuit_Breaker(opt);
} else if (device_id_str == "opening_mechanism") {
success = m_lowerCommManager->operate_HVA_actuatorCircuit_Breaker(opt);
} else if (device_id_str == "mast_steering") {
success = m_lowerCommManager->operate_HVA_mastSteeringGearControlBoxCircuit_Breaker(opt);
} else if (device_id_str == "xcz") {
success = m_lowerCommManager->operate_HVA_xczCircuit_Breaker(opt);
} else if (device_id_str == "bow_rudder") {
success = m_lowerCommManager->operate_HVA_bowRudderControlBoxCircuit_Breaker(opt);
} else if (device_id_str == "water_cover") {
success = m_lowerCommManager->operate_HVA_openWaterCoverStartCylinderCircuit_Breaker(opt);
}
} else if (device_type_str == "high_vol_bus")
{
if (device_id_str == "fuel_cell") {
success = m_lowerCommManager->operate_HV_fuelCellCircuit_Breaker(opt);
} else if (device_id_str == "power_battery") {
success = m_lowerCommManager->operate_HV_powerLithiumBattery_Breaker(opt);
} else if (device_id_str == "propulsion_motor") {
success = m_lowerCommManager->operate_HV_propulsionMotor_Breaker(opt);
} else if (device_id_str == "battery_meter") {
success = m_lowerCommManager->operate_HV_lithiumBatteryMeter_Breaker(opt);
} else if (device_id_str == "dcdc5") {
success = m_lowerCommManager->operate_HV_dcDc5Module_Breaker(opt);
} else if (device_id_str == "bow_distribution") {
success = m_lowerCommManager->operate_HV_bowHighVoltageBox_Breaker(opt);
} else if (device_id_str == "stern_ft45") {
success = m_lowerCommManager->operate_HV_sternFt45_Breaker(opt);
} else if (device_id_str == "stern_rudder1") {
success = m_lowerCommManager->operate_HV_sternRudder1_Breaker(opt);
} else if (device_id_str == "stern_rudder2") {
success = m_lowerCommManager->operate_HV_sternRudder2_Breaker(opt);
} else if (device_id_str == "fb_reserve") {
success = m_lowerCommManager->operate_HV_fbReserved_Breaker(opt);
} else if (device_id_str == "tyz_reserve") {
success = m_lowerCommManager->operate_HV_tyzReserved_Breaker(opt);
} else if (device_id_str == "reserve") {
success = m_lowerCommManager->operate_HV_reserved_Breaker(opt);
} else if (device_id_str == "dcdc5_start") {
success = m_lowerCommManager->operate_HV_dcDc5_Breaker(opt);
} else if (device_id_str == "cooling_system") {
success = m_lowerCommManager->operate_HV_coolingSystem_Breaker(opt);
}
} else if (device_type_str == "bow_low_vol")
{
if (device_id_str == "unit1") {
success = m_lowerCommManager->operate_LVA_unit1Circuit_Breaker(opt);
} else if (device_id_str == "unit2") {
success = m_lowerCommManager->operate_LVA_unit2Circuit_Breaker(opt);
} else if (device_id_str == "unit3") {
success = m_lowerCommManager->operate_LVA_unit3Circuit_Breaker(opt);
} else if (device_id_str == "unit5") {
success = m_lowerCommManager->operate_LVA_unit5Circuit_Breaker(opt);
} else if (device_id_str == "bow_pz") {
success = m_lowerCommManager->operate_LVA_bowPZDeviceCircuit_Breaker(opt);
} else if (device_id_str == "reserve1") {
success = m_lowerCommManager->operate_LVA_reservedCircuit1_Breaker(opt);
} else if (device_id_str == "reserve2") {
success = m_lowerCommManager->operate_LVA_reservedCircuit2_Breaker(opt);
} else if (device_id_str == "emergency_battery1") {
success = m_lowerCommManager->operate_LVA_mergencyLithiumBatteryGroup1Circuit_Breaker(opt);
}
}
// 模拟随机成功或失败 (70%成功率)
bool success = (rand() % 10) < 7;
const char *message = success ? "操作成功" : "操作失败";
// 返回JSON响应
@@ -260,17 +350,17 @@ void HttpServer::pushSystemData() {
j["dyn_power_limit2"] = Json::Value(m_systemData->dyn_power_limit2); // 动力电池2功率限制值
//设备在线状态
j["device_onile"]["device_online_flag1"] = Json::Value(m_systemData->device_online_flag1);
j["device_onile"]["device_online_flag2"] = Json::Value(m_systemData->device_online_flag2);
j["device_online"]["device_online_flag1"] = Json::Value(m_systemData->device_online_flag1);
j["device_online"]["device_online_flag2"] = Json::Value(m_systemData->device_online_flag2);
j["device_onile"]["ins_online_state"] = Json::Value(m_systemData->device_online_status.ins_online_state); // 仪表锂电在线标志位
j["device_onile"]["dyn_online_state"] = Json::Value(m_systemData->device_online_status.dyn_online_state); // 动力锂电在线标志位
j["device_onile"]["fuel_online_state"] = Json::Value(m_systemData->device_online_status.fuel_online_state); // 燃电锂电在线标志位
j["device_onile"]["high_voltage_online_state"] = Json::Value(m_systemData->device_online_status.high_voltage_online_state); // 高压配电板在线标志位
j["device_onile"]["low_voltage_online_state"] = Json::Value(m_systemData->device_online_status.low_voltage_online_state); // 低压配电板在线标志位
j["device_onile"]["composite_online_state"] = Json::Value(m_systemData->device_online_status.composite_online_state); // 复合管控主机在线标志位
j["device_onile"]["composite_backup_online_state"] = Json::Value(m_systemData->device_online_status.composite_backup_online_state); // 复合管控备机在线标志位
j["device_online_status"]["ins_online_state"] = Json::Value(m_systemData->device_online_status.ins_online_state); // 仪表锂电在线标志位
j["device_online_status"]["dyn_online_state"] = Json::Value(m_systemData->device_online_status.dyn_online_state); // 动力锂电在线标志位
j["device_online_status"]["fuel_online_state"] = Json::Value(m_systemData->device_online_status.fuel_online_state); // 燃电锂电在线标志位
j["device_online_status"]["high_voltage_online_state"] = Json::Value(m_systemData->device_online_status.high_voltage_online_state); // 高压配电板在线标志位
j["device_online_status"]["low_voltage_online_state"] = Json::Value(m_systemData->device_online_status.low_voltage_online_state); // 低压配电板在线标志位
j["device_online_status"]["composite_online_state"] = Json::Value(m_systemData->device_online_status.composite_online_state); // 复合管控主机在线标志位
j["device_online_status"]["composite_backup_online_state"] = Json::Value(m_systemData->device_online_status.composite_backup_online_state); // 复合管控备机在线标志位
// cout << j << endl;
//通信状态
//ccu状态
j["comm_state"]["ccu_status"]["isTimeout"] = Json::Value(m_systemData->device_common_status.ccu_status.isTimeout);
+6 -1
View File
@@ -7,6 +7,7 @@
#include <vector>
#include <mutex>
#include <unordered_map>
#include "../LowerCommManager.h"
class PowerManger; // 前向声明
class HttpServer {
@@ -30,13 +31,16 @@ public:
void setSystemData(SystemData* systemData){
m_systemData = systemData;
}
void setLowerCommManager(LowerCommManager* lowerCommManager){
m_lowerCommManager = lowerCommManager;
}
// 推送系统数据到所有WebSocket客户端
void pushSystemData();
private:
// WebSocket事件处理函数
static 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);
// 线程回调函数
static bool serverThreadCB(void* pParam);
@@ -44,6 +48,7 @@ private:
// 后台系统数据
SystemData *m_systemData = nullptr;
LowerCommManager *m_lowerCommManager = nullptr;
struct mg_mgr mgr_; // Mongoose管理器
int port_; // 监听端口
+132 -4
View File
@@ -311,6 +311,94 @@ const std::string INDEX_HTML = R"(
</div>
</div>
<button class="collapsible">设备在线状态</button>
<div class="content">
<div class="system-data-grid">
<div class="data-item">
<span class="data-label">设备在线标志1:</span>
<span class="data-value" id="device-online-flag1">正在加载...</span>
</div>
<div class="data-item">
<span class="data-label">设备在线标志2:</span>
<span class="data-value" id="device-online-flag2">正在加载...</span>
</div>
<div class="data-item">
<span class="data-label">仪表锂电在线状态:</span>
<span class="data-value" id="ins-online-state">正在加载...</span>
</div>
<div class="data-item">
<span class="data-label">动力锂电在线状态:</span>
<span class="data-value" id="dyn-online-state">正在加载...</span>
</div>
<div class="data-item">
<span class="data-label">燃电锂电在线状态:</span>
<span class="data-value" id="fuel-online-state">正在加载...</span>
</div>
<div class="data-item">
<span class="data-label">高压配电板在线状态:</span>
<span class="data-value" id="high-voltage-online-state">正在加载...</span>
</div>
<div class="data-item">
<span class="data-label">低压配电板在线状态:</span>
<span class="data-value" id="low-voltage-online-state">正在加载...</span>
</div>
<div class="data-item">
<span class="data-label">复合管控主机在线状态:</span>
<span class="data-value" id="composite-online-state">正在加载...</span>
</div>
<div class="data-item">
<span class="data-label">复合管控备机在线状态:</span>
<span class="data-value" id="composite-backup-online-state">正在加载...</span>
</div>
</div>
</div>
<button class="collapsible">通信状态</button>
<div class="content">
<div class="system-data-grid">
<div class="data-item">
<span class="data-label">CCU状态-超时:</span>
<span class="data-value" id="ccu-status-timeout">正在加载...</span>
</div>
<div class="data-item">
<span class="data-label">CCU状态-最后更新时间:</span>
<span class="data-value" id="ccu-status-last-update">正在加载...</span>
</div>
<div class="data-item">
<span class="data-label">高压配电1-超时:</span>
<span class="data-value" id="dis-hv-c1-timeout">正在加载...</span>
</div>
<div class="data-item">
<span class="data-label">高压配电1-最后更新时间:</span>
<span class="data-value" id="dis-hv-c1-last-update">正在加载...</span>
</div>
<div class="data-item">
<span class="data-label">高压配电2-超时:</span>
<span class="data-value" id="dis-hv-c2-timeout">正在加载...</span>
</div>
<div class="data-item">
<span class="data-label">高压配电2-最后更新时间:</span>
<span class="data-value" id="dis-hv-c2-last-update">正在加载...</span>
</div>
<div class="data-item">
<span class="data-label">低压配电1-超时:</span>
<span class="data-value" id="dis-lv-c1-timeout">正在加载...</span>
</div>
<div class="data-item">
<span class="data-label">低压配电1-最后更新时间:</span>
<span class="data-value" id="dis-lv-c1-last-update">正在加载...</span>
</div>
<div class="data-item">
<span class="data-label">低压配电2-超时:</span>
<span class="data-value" id="dis-lv-c2-timeout">正在加载...</span>
</div>
<div class="data-item">
<span class="data-label">低压配电2-最后更新时间:</span>
<span class="data-value" id="dis-lv-c2-last-update">正在加载...</span>
</div>
</div>
</div>
<button class="collapsible">动力母线状态</button>
<div class="content">
<div class="system-data-grid">
@@ -1407,11 +1495,36 @@ if (data.power_a_bus_status) {
}
// 其他系统参数
if (data.device_online_flag1 !== undefined) {
document.getElementById('device-online-flag1').textContent = data.device_online_flag1;
// 设备在线状态
if (data.device_online && data.device_online.device_online_flag1 !== undefined) {
document.getElementById('device-online-flag1').textContent = data.device_online.device_online_flag1;
}
if (data.device_online_flag2 !== undefined) {
document.getElementById('device-online-flag2').textContent = data.device_online_flag2;
if (data.device_online && data.device_online.device_online_flag2 !== undefined) {
document.getElementById('device-online-flag2').textContent = data.device_online.device_online_flag2;
}
if (data.device_online_status) {
const status = data.device_online_status;
document.getElementById('ins-online-state').textContent = getOnlineStateText(status.ins_online_state);
document.getElementById('dyn-online-state').textContent = getOnlineStateText(status.dyn_online_state);
document.getElementById('fuel-online-state').textContent = getOnlineStateText(status.fuel_online_state);
document.getElementById('high-voltage-online-state').textContent = getOnlineStateText(status.high_voltage_online_state);
document.getElementById('low-voltage-online-state').textContent = getOnlineStateText(status.low_voltage_online_state);
document.getElementById('composite-online-state').textContent = getOnlineStateText(status.composite_online_state);
document.getElementById('composite-backup-online-state').textContent = getOnlineStateText(status.composite_backup_online_state);
}
// 通信状态
if (data.comm_state) {
const comm = data.comm_state;
document.getElementById('ccu-status-timeout').textContent = getTimeoutText(comm.ccu_status.isTimeout);
document.getElementById('ccu-status-last-update').textContent = new Date(comm.ccu_status.lastUpdateTime * 1000).toLocaleString();
document.getElementById('dis-hv-c1-timeout').textContent = getTimeoutText(comm.dis_hv_c1.isTimeout);
document.getElementById('dis-hv-c1-last-update').textContent = new Date(comm.dis_hv_c1.lastUpdateTime * 1000).toLocaleString();
document.getElementById('dis-hv-c2-timeout').textContent = getTimeoutText(comm.dis_hv_c2.isTimeout);
document.getElementById('dis-hv-c2-last-update').textContent = new Date(comm.dis_hv_c2.lastUpdateTime * 1000).toLocaleString();
document.getElementById('dis-lv-c1-timeout').textContent = getTimeoutText(comm.dis_lv_c1.isTimeout);
document.getElementById('dis-lv-c1-last-update').textContent = new Date(comm.dis_lv_c1.lastUpdateTime * 1000).toLocaleString();
document.getElementById('dis-lv-c2-timeout').textContent = getTimeoutText(comm.dis_lv_c2.isTimeout);
document.getElementById('dis-lv-c2-last-update').textContent = new Date(comm.dis_lv_c2.lastUpdateTime * 1000).toLocaleString();
}
if (data.heartbeat !== undefined) {
document.getElementById('heartbeat').textContent = data.heartbeat;
@@ -1421,6 +1534,21 @@ if (data.power_a_bus_status) {
}
}
// 在线状态文本转换
function getOnlineStateText(state) {
const states = {
"0": "未上线",
"1": "在线",
"2": "上线后掉线"
};
return states[state] || "未知状态";
}
// 超时状态文本转换
function getTimeoutText(isTimeout) {
return isTimeout ? "已超时" : "正常";
}
// FC模式文本转换
function getFCModeText(mode) {
const modes = {
+9
View File
@@ -534,6 +534,15 @@ public:
device_online_status.low_voltage_online_state = (data.device_online_flag2 >> 0) & 0xFF; // byte0:低压配电板在线标志位
device_online_status.composite_online_state = (data.device_online_flag2 >> 8) & 0xFF; // byte1:复合管控主机在线标志位
device_online_status.composite_backup_online_state = (data.device_online_flag2 >> 16) & 0xFF; // byte2:复合管控备机在线标志位
// std::cout << "device_online_status.ins_online_state: " << (int)device_online_status.ins_online_state << std::endl;
// std::cout << "device_online_status.dyn_online_state: " << (int)device_online_status.dyn_online_state << std::endl;
// std::cout << "device_online_status.fuel_online_state: " << (int)device_online_status.fuel_online_state << std::endl;
// std::cout << "device_online_status.high_voltage_online_state: " << (int)device_online_status.high_voltage_online_state << std::endl;
// std::cout << "device_online_status.low_voltage_online_state: " << (int)device_online_status.low_voltage_online_state << std::endl;
// std::cout << "device_online_status.composite_online_state: " << (int)device_online_status.composite_online_state << std::endl;
// std::cout << "device_online_status.composite_backup_online_state: " << (int)device_online_status.composite_backup_online_state << std::endl;
//心跳计数器
heartbeat = data.heartbeat;