修改了次级配电协议,优化消息结构

This commit is contained in:
zjk
2025-05-14 10:02:47 +08:00
parent a0e16ec538
commit 476be20025
43 changed files with 2229 additions and 1226 deletions
+119 -1
View File
@@ -77,8 +77,11 @@ bool LowerCommManager::initUdpComm(){
}
void LowerCommManager::processPeriodicTasks() {
sendCcuCommand(m_pm->m_CcuColCmd);
//延时5ms
usleep(5000);
sendDisSysCommand(m_pm->m_targetDisBreakerState);
m_udpComm->clearMsgQueue();
}
bool LowerCommManager::sendCcuCommand(const ccuColCmd cmd){
@@ -105,6 +108,7 @@ bool LowerCommManager::sendDisSysCommand(const disSysBreakerList& cmd){
a.reservedCircuitBreaker = getBreakerOption(cmd.bus1Breaker.reservedCircuitBreaker);
a.fbReservedCircuitBreaker = getBreakerOption(cmd.bus1Breaker.fbReservedCircuitBreaker);
m_udpComm->sendDisSysCmd(a);
usleep(5000);
//b. 高压汇流排A断路器
disHighAVolBusCmd b;
b.bowFTDevice123CircuitBreaker = getBreakerOption(cmd.bus2Breaker.bowFTDevice123CircuitBreaker);
@@ -114,6 +118,7 @@ bool LowerCommManager::sendDisSysCommand(const disSysBreakerList& cmd){
b.bowRudderControlBoxCircuitBreaker = getBreakerOption(cmd.bus2Breaker.bowRudderControlBoxCircuitBreaker);
b.openWaterCoverStartCylinderCircuitBreaker = getBreakerOption(cmd.bus2Breaker.openWaterCoverStartCylinderCircuitBreaker);
m_udpComm->sendDisSysCmd(b);
usleep(5000);
//c. 高压汇流排B断路器
disHighBVolBusCmd c;
c.lithiumBatteryGroupInstrumentCircuitBreaker = getBreakerOption(cmd.bus3Breaker.lithiumBatteryGroupInstrumentCircuitBreaker);
@@ -124,6 +129,7 @@ bool LowerCommManager::sendDisSysCommand(const disSysBreakerList& cmd){
c.reservedCircuitBreaker2 = getBreakerOption(cmd.bus3Breaker.reservedCircuitBreaker2);
c.emergencyLithiumBatteryGroup2CircuitBreaker = getBreakerOption(cmd.bus3Breaker.emergencyLithiumBatteryGroup2CircuitBreaker);
m_udpComm->sendDisSysCmd(c);
usleep(5000);
//d. 闭合低压汇流排断路器
disLowBusCmd d;
d.unit1CircuitBreaker = getBreakerOption(cmd.bus4Breaker.unit1CircuitBreaker);
@@ -135,6 +141,7 @@ bool LowerCommManager::sendDisSysCommand(const disSysBreakerList& cmd){
d.reservedCircuitBreaker2 = getBreakerOption(cmd.bus4Breaker.reservedCircuitBreaker2);
d.emergencyLithiumBatteryGroup1CircuitBreaker = getBreakerOption(cmd.bus4Breaker.emergencyLithiumBatteryGroup1CircuitBreaker);
m_udpComm->sendDisSysCmd(d);
usleep(5000);
//将指令写入数据库
// m_pm->m_db->insertDisSysCmd(a);
// m_pm->m_db->insertDisSysCmd(b);
@@ -157,6 +164,8 @@ bool LowerCommManager::updatePoweSystemStates(){
m_udpComm->popMsgFormQueue(time,m_CcuCurrentState);
m_pm->m_pmCurrentState.ccustate = m_CcuCurrentState.data;
// m_db->insertCcuData(m_CcuCurrentState.data); //写入数据库
//DEBUG
coutMsg(m_CcuCurrentState);
msg_CcuStateFbMsg_Update_time = time;
}
if(!m_udpComm->m_qReceiveDisHighVolBusBuffer.empty())
@@ -256,7 +265,7 @@ bool LowerCommManager::listenThreadFunc()
try
{
int nRead = m_udpComm->udpScoket->iRecieveMessage(Buff, sizeof(Buff));
//cout<<MOOS::ConsoleColours::yellow()<< "RECEVE DATA COUNT:" << nRead << MOOS::ConsoleColours::reset() << endl;
cout<<MOOS::ConsoleColours::yellow()<< "RECEVE DATA COUNT:" << nRead << MOOS::ConsoleColours::reset() << endl;
if(nRead > 0)
{
try {
@@ -342,3 +351,112 @@ 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;
os << "起始符1 (start1): 0x" << std::setw(2) << static_cast<int>(p.header.start1) << "\n";
os << "起始符2 (start2): 0x" << std::setw(2) << static_cast<int>(p.header.start2) << "\n";
os << "标识符 (identifier): 0x" << std::setw(4) << p.header.id << "\n";
os << std::dec << "数据长度 (length): " << p.header.length << "\n";
os << "运行模式 (fc_mode): 0x" << std::hex << std::setw(2) << static_cast<int>(p.data.fc_mode) << "\n";
os << "燃料电池状态 (fc_status): 0x" << std::setw(2) << static_cast<int>(p.data.fc_status) << "\n";
os << "故障等级 (fc_fault_level): 0x" << std::setw(2) << static_cast<int>(p.data.fc_fault_level) << "\n";
os << std::dec;
os << "输出功率限制 (output_power_limit): " << p.data.output_power_limit << " W\n";
os << "累计发电时间 (total_generation_time): " << p.data.total_generation_time * 0.1 << " 小时\n";
os << "发电总功率 (total_generation_power): " << p.data.total_generation_power << " W\n";
os << "一级故障字 (fault_level_1): 0x" << std::hex << p.data.fault_level_1 << "\n";
os << "二级故障字 (fault_level_2): 0x" << p.data.fault_level_2 << "\n";
os << "三级故障字 (fault_level_3): 0x" << p.data.fault_level_3 << "\n";
os << "四级故障字 (fault_level_4): 0x" << p.data.fault_level_4 << "\n";
os << std::dec;
os << "储氢剩余容量 (hydrogen_capacity): " << static_cast<int>(p.data.hydrogen_capacity) << "%\n";
os << "液氧剩余容量 (liquid_oxygen_capacity): " << static_cast<int>(p.data.liquid_oxygen_capacity) << "%\n";
os << "钯膜最高温度 (palladium_temp): " << p.data.palladium_temp << " ℃\n";
os << "主水路压力 (main_pipe_pressure): " << p.data.main_pipe_pressure * 0.01 << " kPa\n";
os << "辅水路压力 (aux_pipe_pressure): " << p.data.aux_pipe_pressure * 0.01 << " kPa\n";
os << "舱室压力1 (cabin_pressure1): " << p.data.cabin_pressure1 * 0.01 << " kPa\n";
os << "舱室压力2 (cabin_pressure2): " << p.data.cabin_pressure2 * 0.01 << " kPa\n";
os << "舱室温度1 (cabin_temp1): " << p.data.cabin_temp1 * 0.01 << " ℃\n";
os << "舱室温度2 (cabin_temp2): " << p.data.cabin_temp2 * 0.01 << " ℃\n";
os << "舱室湿度1 (cabin_humidity1): " << p.data.cabin_humidity1 * 0.01 << " %RH\n";
os << "舱室湿度2 (cabin_humidity2): " << p.data.cabin_humidity2 * 0.01 << " %RH\n";
os << "火焰探测器1状态 (flame_detector1): 0x" << std::hex << static_cast<int>(p.data.flame_detector1) << "\n";
os << "火焰探测器2状态 (flame_detector2): 0x" << static_cast<int>(p.data.flame_detector2) << "\n";
os << std::dec;
os << "氢气浓度1 (h2_concentration1): " << p.data.h2_concentration1 * 0.01 << "% LEL\n";
os << "氢气浓度2 (h2_concentration2): " << p.data.h2_concentration2 * 0.01 << "% LEL\n";
os << "氢气浓度3 (h2_concentration3): " << p.data.h2_concentration3 * 0.01 << "% LEL\n";
os << "氧气浓度1 (o2_concentration1): " << p.data.o2_concentration1 * 0.01 << "% LEL\n";
os << "氧气浓度2 (o2_concentration2): " << p.data.o2_concentration2 * 0.01 << "% LEL\n";
os << "甲醇浓度1 (ch3oh_concentration1): " << p.data.ch3oh_concentration1 * 0.01 << "% LEL\n";
os << "甲醇浓度2 (ch3oh_concentration2): " << p.data.ch3oh_concentration2 * 0.01 << "% LEL\n";
for (int i = 0; i < 18; ++i)
os << "保留字段 reserved1[" << i << "]: 0x" << std::hex << p.data.reserved1[i] << "\n";
for (int i = 0; i < 6; ++i)
os << "动力电池报警标志 dyn_alarm_flag[" << i << "]: 0x" << std::hex << static_cast<int>(p.data.dyn_alarm_flag[i]) << "\n";
for (int i = 0; i < 6; ++i)
os << "仪表电池报警标志 ins_alarm_flag[" << i << "]: 0x" << std::hex << static_cast<int>(p.data.ins_alarm_flag[i]) << "\n";
os << "仪表正极/充电继电器状态 (ins_relay_status1): 0x" << std::hex << static_cast<int>(p.data.ins_relay_status1) << "\n";
os << "仪表预充/负极继电器状态 (ins_relay_status2): 0x" << static_cast<int>(p.data.ins_relay_status2) << "\n";
os << "动力正极/充电继电器状态 (dyn_relay_status1): 0x" << static_cast<int>(p.data.dyn_relay_status1) << "\n";
os << "动力预充/负极继电器状态 (dyn_relay_status2): 0x" << static_cast<int>(p.data.dyn_relay_status2) << "\n";
os << std::dec;
os << "仪表最大放电功率 (ins_max_discharge_power): " << p.data.ins_max_discharge_power * 0.05 << " kW\n";
os << "动力最大放电功率 (dyn_max_discharge_power): " << p.data.dyn_max_discharge_power * 0.05 << " kW\n";
os << "仪表SOC (ins_soc): " << static_cast<int>(p.data.ins_soc) << "%\n";
os << "动力SOC (dyn_soc): " << static_cast<int>(p.data.dyn_soc) << "%\n";
os << "仪表电池总能量 (ins_total_energy): " << p.data.ins_total_energy << " kWh\n";
os << "动力电池总能量 (dyn_total_energy): " << p.data.dyn_total_energy << " kWh\n";
os << "仪表输入功率 (ins_power_input): " << p.data.ins_power_input << " kW\n";
os << "动力输入功率 (dyn_power_input): " << p.data.dyn_power_input << " kW\n";
os << "仪表充电状态 (ins_charge_status): 0x" << std::hex << static_cast<int>(p.data.ins_charge_status) << "\n";
os << "动力充电状态 (dyn_charge_status): 0x" << static_cast<int>(p.data.dyn_charge_status) << "\n";
os << std::dec;
os << "仪表LINK电压: " << p.data.ins_voltage_link * 0.01 << " V\n";
os << "仪表PACK电压: " << p.data.ins_voltage_pack * 0.01 << " V\n";
os << "仪表电流: " << p.data.ins_current * 0.01 << " A\n";
os << "仪表正端绝缘电阻: " << p.data.ins_resistance_pos << " kΩ\n";
os << "仪表负端绝缘电阻: " << p.data.ins_resistance_neg << " kΩ\n";
os << "动力LINK电压: " << p.data.dyn_voltage_link * 0.01 << " V\n";
os << "动力PACK电压: " << p.data.dyn_voltage_pack * 0.01 << " V\n";
os << "动力电流: " << p.data.dyn_current * 0.01 << " A\n";
os << "动力正端绝缘电阻: " << p.data.dyn_resistance_pos << " kΩ\n";
os << "动力负端绝缘电阻: " << p.data.dyn_resistance_neg << " kΩ\n";
os << "仪表紧急状态 (ins_emergency_status): 0x" << std::hex << static_cast<int>(p.data.ins_emergency_status) << "\n";
os << "动力紧急状态 (dyn_emergency_status): 0x" << static_cast<int>(p.data.dyn_emergency_status) << "\n";
for (int i = 0; i < 2; ++i)
os << "保留字段 reserved2[" << i << "]: 0x" << std::hex << static_cast<int>(p.data.reserved2[i]) << "\n";
for (int i = 0; i < 6; ++i)
os << "SOC门限值 ins_soc_threshold" << i+1 << ": 0x" << std::hex << static_cast<int>(p.data.ins_soc_threshold1) << "\n";
for (int i = 0; i < 4; ++i)
os << "功率限制 ins_power_limit" << i+1 << ": 0x" << std::hex << static_cast<int>(p.data.ins_power_limit1) << "\n";
os << "设备在线状态1 (device_online_flag1): 0x" << std::hex << p.data.device_online_flag1 << "\n";
os << "设备在线状态2 (device_online_flag2): 0x" << p.data.device_online_flag2 << "\n";
// os << "保留字段 reserved3: 0x" << p.data.reserved1 << "\n";
os << "主机心跳 (reserved4): 0x" << p.data.heartbeat << "\n";
os << "校验和 (checksum): 0x" << p.checkCode << "\n";
os << std::dec;
}