增加了udp的测试代码,增加了时间获取函数,完善了ccu发送指令的函数

This commit is contained in:
zjk
2025-02-18 16:57:11 +08:00
parent 2599050c1f
commit a179789b3f
12 changed files with 247 additions and 99 deletions
+58 -13
View File
@@ -37,10 +37,19 @@ PowerManger::PowerManger()
falutLevel = 0;
soc = 0;
sustainableTime = 0;
m_connected = false;
m_faultNum = 0;
m_ticker = 0;
faultCode.push_back(0);
msg_CcuStateFbMsg_Update_time = 0;
// msg_CcuSetParmFbMsg_Update_time = 0;
msg_disHighVolBusFbMsg_Update_time = 0;
msg_disHighAVolBusFbMsg_Update_time = 0;
msg_disHighBVolBusFbMsg_Update_time = 0;
msg_disLowBusFbMsg_Update_time = 0;
connectState = 0;
//初始化断路器状态
initTargetDisBreakerState();
@@ -115,22 +124,27 @@ bool PowerManger::OnConnectToServer()
//---------------------------------------------------------
// Procedure: Iterate()
// happens AppTick times per second
//固定为4Hz
bool PowerManger::Iterate()
{
AppCastingMOOSApp::Iterate();
//1. 更新当前状态
updatePmState();
updateTime();
updateConnectState();
//2. 运行状态机
if (FSM_RUN_IS_OK)
m_FsmThread.Start();
else
m_FsmThread.Stop();
//进行配电系统操作
disSysOption();
//3. 输出报告
buildPowerSysReport();
//3. 进行操作 每秒执行一次
if (m_ticker++ % 5 == 0)
{
//a. 配电系统操作
disSysOption();
//b. ccu操作
//c. 输出报告
buildPowerSysReport();
}
//4. 打印错误信息
if(!m_udpComm.sError.empty())
{
@@ -263,7 +277,6 @@ bool PowerManger::ListenLoopUDP()
cout<<MOOS::ConsoleColours::red()<< m_udpComm.sError[i] << MOOS::ConsoleColours::reset() << endl;
}
}
m_connected = true;
}
// updatePmState();
}
@@ -281,6 +294,31 @@ bool PowerManger::FsmLoop()
return true;
}
bool PowerManger::updateConnectState()
{
double seck = 0;
updateTime();
connectState = 0;
IsSkewed(msg_CcuStateFbMsg_Update_time,&seck);
connectState++;
// cout << "seck:" << seck << endl;
IsSkewed(msg_disHighVolBusFbMsg_Update_time,&seck);
connectState++;
// cout << "seck:" << seck << endl;
IsSkewed(msg_disHighAVolBusFbMsg_Update_time,&seck);
connectState++;
// cout << "seck:" << seck << endl;
IsSkewed(msg_disHighBVolBusFbMsg_Update_time,&seck);
connectState++;
// cout << "seck:" << seck << endl;
IsSkewed(msg_disLowBusFbMsg_Update_time,&seck);
connectState++;
// cout << "seck:" << seck << endl;
return true;
}
bool PowerManger::updatePmState()
{
//1. 更新下位机状态
@@ -290,6 +328,7 @@ bool PowerManger::updatePmState()
m_udpComm.popMsgFormQueue(time,m_CcuCurrentState);
m_pmCurrentState.ccustate = m_CcuCurrentState.data;
m_db->insertCcuData(m_CcuCurrentState.data); //写入数据库
msg_CcuStateFbMsg_Update_time = time;
}
if(!m_udpComm.m_qReceiveDisHighVolBusBuffer.empty())
{
@@ -297,6 +336,7 @@ bool PowerManger::updatePmState()
m_udpComm.popMsgFormQueue(time,m_disHighVolBusCurrentState);
m_pmCurrentState.bus1State = m_disHighVolBusCurrentState.data;
m_db->insertDisHighVolBusData(m_disHighVolBusCurrentState.data); //写入数据库
msg_disHighVolBusFbMsg_Update_time = time;
}
if(!m_udpComm.m_qReceiveDisHighAVolBusBuffer.empty())
{
@@ -304,6 +344,7 @@ bool PowerManger::updatePmState()
m_udpComm.popMsgFormQueue(time,m_disHighAVolBusCurrentState);
m_pmCurrentState.bus2State = m_disHighAVolBusCurrentState.data;
m_db->insertDisHighAVolBusData(m_disHighAVolBusCurrentState.data); //写入数据库
msg_disHighAVolBusFbMsg_Update_time = time;
}
if(!m_udpComm.m_qReceiveDisHighBVolBusBuffer.empty())
{
@@ -311,6 +352,7 @@ bool PowerManger::updatePmState()
m_udpComm.popMsgFormQueue(time,m_disHighBVolBusCurrentState);
m_pmCurrentState.bus3State = m_disHighBVolBusCurrentState.data;
m_db->insertDisHighBVolBusData(m_disHighBVolBusCurrentState.data); //写入数据库
msg_disHighBVolBusFbMsg_Update_time = time;
}
if(!m_udpComm.m_qReceiveDisLowBusBuffer.empty())
{
@@ -318,6 +360,7 @@ bool PowerManger::updatePmState()
m_udpComm.popMsgFormQueue(time,m_disLowBusState);
m_pmCurrentState.bus4State = m_disLowBusState.data;
m_db->insertDisLowBusData(m_disLowBusState.data); //写入数据库
msg_disLowBusFbMsg_Update_time = time;
}
return true;
}
@@ -396,6 +439,9 @@ void PowerManger::disSysOption()
//a. 高压母线的断路器
disHighVolBusCmd a;
a.fuelCellCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.fuelCellCircuitBreaker);
a.lithiumBatteryGroupInstrumentCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.lithiumBatteryGroupInstrumentCircuitBreaker);
a.dcDc5ModuleCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.dcDc5ModuleCircuitBreaker);
a.powerLithiumBatteryCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.powerLithiumBatteryCircuitBreaker);
a.propulsionMotorCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.propulsionMotorCircuitBreaker);
a.bowHighVoltageDistributionBoxCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.bowHighVoltageDistributionBoxCircuitBreaker);
a.tyzReservedCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.tyzReservedCircuitBreaker);
@@ -485,9 +531,9 @@ void PowerManger::printState(FSM_State st, string desp){
int PowerManger::handleInite_s1(FSM_State &fsm, void* pData)
{
PowerManger* pm = (PowerManger*)pData;
//1. 检查复合管控器连接 如果10S则进入故障状态
//1. 检查通信是否正常 如果超时则进入故障状态
double StartTime = pm->GetAppStartTime();
while (!pm->m_connected)
while (!pm->connectState == 5)
{
MOOSPause(1000);
pm->updateTime();
@@ -495,7 +541,7 @@ int PowerManger::handleInite_s1(FSM_State &fsm, void* pData)
if(dft > 10)
{
pm->m_pmState = pm->m_Fault_s99;
pm->m_faultNum = 1; // 通信超时
pm->m_faultNum = 1;
break;
}
string desp = "等待复合管控消息 : " + to_string(10-dft);
@@ -536,7 +582,6 @@ int PowerManger::handleStandby_s2(FSM_State &fsm, void* pData)
}
int PowerManger::handleFault_s99(FSM_State &fsm, void* pData)
{
// cout << fsm.name << endl;
@@ -561,7 +606,7 @@ void PowerManger::initTargetDisBreakerState()
m_targetDisBreakerState.bus1Breaker.fuelCellCircuitBreaker = 0;
m_targetDisBreakerState.bus1Breaker.powerLithiumBatteryCircuitBreaker = 1; //动力锂电池默认接入
m_targetDisBreakerState.bus1Breaker.propulsionMotorCircuitBreaker = 0;
m_targetDisBreakerState.bus1Breaker.lithiumBatteryGroupInstrumentCircuitBreaker = 0; //仪表锂电池默认接入
m_targetDisBreakerState.bus1Breaker.lithiumBatteryGroupInstrumentCircuitBreaker = 1; //仪表锂电池默认接入
m_targetDisBreakerState.bus1Breaker.dcDc5ModuleCircuitBreaker = 1; //DC-DC模块默认接入
m_targetDisBreakerState.bus1Breaker.bowHighVoltageDistributionBoxCircuitBreaker = 1; //艏部高压母线断路器默认接入
m_targetDisBreakerState.bus1Breaker.sternFTDevice45CircuitBreaker = 0; // sternFTDevice45CircuitBreaker默认接入