完成了网页控制断路器

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;
}