优化udp通信代码,增加配电系统通信解析,增加能源系统状态定义
This commit is contained in:
@@ -18,7 +18,7 @@ using namespace std;
|
||||
bool _ListenCB(void * pParam)
|
||||
{
|
||||
PowerManger* pMe = (PowerManger* )pParam;
|
||||
return pMe->ListenLoopCCU();
|
||||
return pMe->ListenLoopUDP();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
@@ -84,7 +84,23 @@ bool PowerManger::Iterate()
|
||||
{
|
||||
AppCastingMOOSApp::Iterate();
|
||||
// Do your thing here!
|
||||
if(!m_udpComm.m_qReceiveCcuStateBuffer.empty())
|
||||
{
|
||||
m_CcuCurrentState = m_udpComm.m_qReceiveCcuStateBuffer.front();
|
||||
cout << m_CcuCurrentState.checkCode << endl;
|
||||
m_udpComm.m_qReceiveCcuStateBuffer.pop();
|
||||
}
|
||||
|
||||
if(!m_udpComm.sError.empty())
|
||||
{
|
||||
for(int i=0;i<m_udpComm.sError.size();i++)
|
||||
{
|
||||
cout<<MOOS::ConsoleColours::red()<< m_udpComm.sError[i] << MOOS::ConsoleColours::reset() << endl;
|
||||
}
|
||||
m_udpComm.sError.clear();
|
||||
}
|
||||
//AppCastingMOOSApp::PostReport();
|
||||
m_udpComm.clearMsgQueue();
|
||||
return(true);
|
||||
}
|
||||
|
||||
@@ -124,9 +140,15 @@ bool PowerManger::OnStartUp()
|
||||
registerVariables();
|
||||
|
||||
if(m_pCcuUdpComm = setUdpScoket(IPORT))
|
||||
{
|
||||
cout<<MOOS::ConsoleColours::green()<< "UDP set succeed!"<< MOOS::ConsoleColours::reset() << endl;
|
||||
MOOSTrace("UDP set succeed");
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<MOOS::ConsoleColours::red()<< "UDP set Fild!"<< MOOS::ConsoleColours::reset() << endl;
|
||||
MOOSTrace("UDP set faile");
|
||||
}
|
||||
m_ListenThread.Initialise(_ListenCB,this);
|
||||
m_ListenThread.Start();
|
||||
return(true);
|
||||
@@ -177,71 +199,35 @@ XPCUdpSocket* PowerManger::setUdpScoket(long lPort)
|
||||
return pUdpSocket;
|
||||
}
|
||||
|
||||
bool PowerManger::ListenLoopCCU()
|
||||
bool PowerManger::ListenLoopUDP()
|
||||
{
|
||||
unsigned char Buff[MAX_UDP_PKT_SIZE];
|
||||
cout << "------------------" << endl;
|
||||
cout << "SIZEOF" << sizeof(msg_CcuStateFbMsg) << endl;
|
||||
while(!m_ListenThread.IsQuitRequested())
|
||||
{
|
||||
int nRead = m_pCcuUdpComm->iRecieveMessage(Buff,sizeof(Buff));
|
||||
cout<<MOOS::ConsoleColours::yellow()<< "RECEVE DATA COUNT:" << nRead << MOOS::ConsoleColours::reset() << endl;
|
||||
if(nRead > 0)
|
||||
{
|
||||
//判断消息
|
||||
char *header = new char[sizeof(m_header)];
|
||||
unsigned short id;
|
||||
memcpy(header,Buff,sizeof(m_header));
|
||||
if(!m_udpComm.getMsgId(header,id))
|
||||
if(!m_udpComm.pushMsgToQueue(Buff))
|
||||
{
|
||||
cout << "------------------" << endl;
|
||||
cout << "id:" << id << endl;
|
||||
cout << "getMsgId faile" << endl;
|
||||
for(int i=0;i<m_udpComm.sError.size();i++)
|
||||
{
|
||||
cout<<MOOS::ConsoleColours::red()<< m_udpComm.sError[i] << MOOS::ConsoleColours::reset() << endl;
|
||||
}
|
||||
}
|
||||
delete []header;
|
||||
//处理消息
|
||||
switch (id)
|
||||
{
|
||||
case CCU_STATE_FB_ID: //CCU_STATE_FB 0x0051
|
||||
msg_CcuStateFbMsg s;
|
||||
if(m_udpComm.getCcuState((char *)Buff,s))
|
||||
{
|
||||
cout << "------------------" << endl;
|
||||
// cout << "id:" << s.header.id << endl;
|
||||
cout << "currentWorkCondition:" << (double)s.currentWorkCondition << endl;
|
||||
cout << "fcuState:" << (double)s.fcuState << endl;
|
||||
cout << "fcuFaultLeve:" << (double)s.fcuFaultLeve << endl;
|
||||
cout << "powerLimit:" << (double)s.powerLimit << endl;
|
||||
cout << "checkCode:" << (double)s.checkCode << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0;i < m_udpComm.sError.size();i++)
|
||||
cout << m_udpComm.sError[i] << endl;
|
||||
m_udpComm.sError.clear();
|
||||
}
|
||||
break;
|
||||
case CCU_SET_PARM_FB_ID: //CCU_SET_PARM_FB 0x0040
|
||||
msg_CcuSetParmFbMsg p;
|
||||
if(m_udpComm.getCcuSetParmFb((char *)Buff,p))
|
||||
{
|
||||
cout << "------------------" << endl;
|
||||
cout << "id:" << p.header.id << endl;
|
||||
cout << "Flas:" << p.flag << endl;
|
||||
cout << "FailCode" << p.failureCode << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0;i < m_udpComm.sError.size();i++)
|
||||
cout << m_udpComm.sError[i] << endl;
|
||||
m_udpComm.sError.clear();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool PowerManger::updatePmState()
|
||||
{
|
||||
m_pmCurrentState.ccustate = m_CcuCurrentState.data;
|
||||
m_pmCurrentState.bus1State = m_disHighVolBusCurrentState.data;
|
||||
m_pmCurrentState.bus2State = m_disHighAVolBusCurrentState.data;
|
||||
m_pmCurrentState.bus3State = m_disHighBVolBusCurrentState.data;
|
||||
m_pmCurrentState.bus4State = m_disLowBusState.data;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -19,22 +19,25 @@
|
||||
#define PowerManger_HEADER
|
||||
#define UNIX
|
||||
|
||||
#include <queue>
|
||||
#include "MOOS/libMOOS/Thirdparty/AppCasting/AppCastingMOOSApp.h"
|
||||
#include "MOOS/libMOOS/Utils/MOOSThread.h"
|
||||
#include "MOOS/libMOOS/Comms/XPCUdpSocket.h"
|
||||
#include "ccuUdpMsg.h"
|
||||
#include "json/json.h"
|
||||
#include "udpComm.h"
|
||||
#include "pmSysvariable.h"
|
||||
|
||||
#define IPORT 5000
|
||||
#define MAX_UDP_PKT_SIZE 65535
|
||||
|
||||
class PowerManger : public AppCastingMOOSApp
|
||||
{
|
||||
public:
|
||||
PowerManger();
|
||||
~PowerManger();
|
||||
public:
|
||||
bool ListenLoopCCU();
|
||||
bool ListenLoopUDP();
|
||||
|
||||
protected: // Standard MOOSApp functions to overload
|
||||
bool OnNewMail(MOOSMSG_LIST &NewMail);
|
||||
@@ -47,24 +50,30 @@ class PowerManger : public AppCastingMOOSApp
|
||||
protected: // app function
|
||||
// bool _ListenCB();
|
||||
XPCUdpSocket* setUdpScoket(long lPort);
|
||||
//
|
||||
bool buildStateReport();
|
||||
|
||||
bool updatePmState();
|
||||
|
||||
bool buildEquipmentReport();
|
||||
bool buildDisributionReport();
|
||||
bool buildSubDistributionReport();
|
||||
bool buildPredictionReport();
|
||||
bool buildPredictionReport();
|
||||
|
||||
protected: // app variables
|
||||
long m_lPort;
|
||||
unsigned int m_nReceiveBufferSizeKB;
|
||||
unsigned int m_nSendBufferSizeKB;
|
||||
|
||||
udpComm m_udpComm;
|
||||
|
||||
XPCUdpSocket *m_pCcuUdpComm;
|
||||
pmState m_pmCurrentState;
|
||||
|
||||
msg_CcuStateFbMsg m_CcuCurrentState;
|
||||
msg_disHighVolBusFbMsg m_disHighVolBusCurrentState;
|
||||
msg_disHighAVolBusFbMsg m_disHighAVolBusCurrentState;
|
||||
msg_disHighBVolBusFbMsg m_disHighBVolBusCurrentState;
|
||||
msg_disLowBusFbMsg m_disLowBusState;
|
||||
private: // Configuration variables
|
||||
CMOOSThread m_ListenThread;
|
||||
udpComm m_udpComm;
|
||||
XPCUdpSocket *m_pCcuUdpComm;
|
||||
CMOOSThread m_ListenThread;
|
||||
long m_lPort;
|
||||
unsigned int m_nReceiveBufferSizeKB;
|
||||
unsigned int m_nSendBufferSizeKB;
|
||||
|
||||
// CMOOSThread m_SendThread;
|
||||
private: // State variables
|
||||
};
|
||||
|
||||
+202
-78
@@ -1,10 +1,15 @@
|
||||
#ifndef CCUUDPMSG__H
|
||||
#define CCUUDPMSG__H
|
||||
#include "pmSysvariable.h"
|
||||
|
||||
#define CCU_UDPMSG_START1 0x20
|
||||
#define CCU_UDPMSG_START2 0x20
|
||||
#define CCU_STATE_FB_ID 0x0051
|
||||
#define CCU_SET_PARM_ID 0x0040
|
||||
#define CCU_SET_PARM_FB_ID 0x0041
|
||||
#define CCU_SET_PARM_FB_ID 0x0040
|
||||
#define DIS_HVBUS_FB_ID 0x0005
|
||||
#define DIS_HVBUSA_FB_ID 0x0006
|
||||
#define DIS_HVBUSB_FB_ID 0x0007
|
||||
#define DIS_LVBUS_FB_ID 0x0008
|
||||
|
||||
#pragma pack (1)
|
||||
typedef unsigned int Checksum;
|
||||
@@ -106,83 +111,202 @@ typedef struct {
|
||||
// 复合管控状态反馈
|
||||
typedef struct {
|
||||
m_header header;
|
||||
unsigned char currentWorkCondition;
|
||||
unsigned char fcuState;
|
||||
unsigned char fcuFaultLeve;
|
||||
float powerLimit;
|
||||
float totalPowerGeneration;
|
||||
float ch4o;
|
||||
float o2;
|
||||
float fcuVoltage;
|
||||
float fcuCurrent;
|
||||
float o2Level;
|
||||
float placeholder1;
|
||||
float exchangerTemperature;
|
||||
float fcuOutPower;
|
||||
float fcuOutIns;
|
||||
float fcuVoltageIns;
|
||||
float fcuVoltagePower;
|
||||
float fcuCurrentIns;
|
||||
float fcuCurrentPower;
|
||||
float h2Concentration1;
|
||||
float h2Concentration2;
|
||||
float o2Concentration1;
|
||||
float o2Concentration2;
|
||||
float ch4oConcentration1;
|
||||
float ch4oConcentration2;
|
||||
float backpressure1;
|
||||
float backpressure2;
|
||||
unsigned char flameDetection;
|
||||
unsigned char fcuGZ_1L;
|
||||
unsigned char fcuGZ_1H;
|
||||
unsigned char fcuGZ_2L;
|
||||
unsigned char fcuGZ_2H;
|
||||
unsigned char fcuGZ_3L;
|
||||
unsigned char fcuGZ_3H;
|
||||
unsigned char insPosRelayState;
|
||||
unsigned char insNegRelayState;
|
||||
unsigned char powerPosRelayState;
|
||||
unsigned char powerNegRelayState;
|
||||
unsigned short insBatLimit;
|
||||
unsigned short powerBatLimit;
|
||||
unsigned char insBatSoc;
|
||||
unsigned char powerBatSoc;
|
||||
unsigned short insBatTotalElectricity;
|
||||
unsigned short powerBatTotalElectricity;
|
||||
unsigned short insBatCurrentElectricity;
|
||||
unsigned short powerBatCurrentElectricity;
|
||||
unsigned char insChargeState;
|
||||
unsigned char powerChargeState;
|
||||
unsigned short insLinkVoltage;
|
||||
unsigned short insPackVoltage;
|
||||
unsigned short insCurrent;
|
||||
unsigned short insPosInsulationResistance;
|
||||
unsigned short insNegInsulationResistance;
|
||||
unsigned short powerLinkVoltage;
|
||||
unsigned short powerPackVoltage;
|
||||
unsigned short powerCurrent;
|
||||
unsigned short powerPosInsulationResistance;
|
||||
unsigned short powerNegInsulationResistance;
|
||||
unsigned char insEmergencyStatusWord;
|
||||
unsigned char powerEmergencyStatusWord;
|
||||
unsigned char insAlarmIdentificationWord;
|
||||
unsigned char powerAlarmIdentificationWord;
|
||||
unsigned char insCurrentSocHold1;
|
||||
unsigned char insCurrentSocHold2;
|
||||
unsigned char insCurrentSocHold3;
|
||||
unsigned char fcuCurrentToInsLimit1;
|
||||
unsigned char fcuCurrentToinsLimit2;
|
||||
unsigned char powerCurrentSocHold1;
|
||||
unsigned char powerCurrentSocHold2;
|
||||
unsigned char powerCurrentSocHold3;
|
||||
unsigned char powerCurrentToInsLimit1;
|
||||
unsigned char powerCurrentToinsLimit2;
|
||||
float placeholder2;
|
||||
float placeholder3;
|
||||
float placeholder4;
|
||||
float placeholder5;
|
||||
ccuState data;
|
||||
// unsigned char currentWorkCondition;
|
||||
// unsigned char fcuState;
|
||||
// unsigned char fcuFaultLeve;
|
||||
// float powerLimit;
|
||||
// float totalPowerGeneration;
|
||||
// float ch4o;
|
||||
// float o2;
|
||||
// float fcuVoltage;
|
||||
// float fcuCurrent;
|
||||
// float o2Level;
|
||||
// float placeholder1;
|
||||
// float exchangerTemperature;
|
||||
// float fcuOutPower;
|
||||
// float fcuOutIns;
|
||||
// float fcuVoltageIns;
|
||||
// float fcuVoltagePower;
|
||||
// float fcuCurrentIns;
|
||||
// float fcuCurrentPower;
|
||||
// float h2Concentration1;
|
||||
// float h2Concentration2;
|
||||
// float o2Concentration1;
|
||||
// float o2Concentration2;
|
||||
// float ch4oConcentration1;
|
||||
// float ch4oConcentration2;
|
||||
// float backpressure1;
|
||||
// float backpressure2;
|
||||
// unsigned char flameDetection;
|
||||
// unsigned char fcuGZ_1L;
|
||||
// unsigned char fcuGZ_1H;
|
||||
// unsigned char fcuGZ_2L;
|
||||
// unsigned char fcuGZ_2H;
|
||||
// unsigned char fcuGZ_3L;
|
||||
// unsigned char fcuGZ_3H;
|
||||
// unsigned char insPosRelayState;
|
||||
// unsigned char insNegRelayState;
|
||||
// unsigned char powerPosRelayState;
|
||||
// unsigned char powerNegRelayState;
|
||||
// unsigned short insBatLimit;
|
||||
// unsigned short powerBatLimit;
|
||||
// unsigned char insBatSoc;
|
||||
// unsigned char powerBatSoc;
|
||||
// unsigned short insBatTotalElectricity;
|
||||
// unsigned short powerBatTotalElectricity;
|
||||
// unsigned short insBatCurrentElectricity;
|
||||
// unsigned short powerBatCurrentElectricity;
|
||||
// unsigned char insChargeState;
|
||||
// unsigned char powerChargeState;
|
||||
// unsigned short insLinkVoltage;
|
||||
// unsigned short insPackVoltage;
|
||||
// unsigned short insCurrent;
|
||||
// unsigned short insPosInsulationResistance;
|
||||
// unsigned short insNegInsulationResistance;
|
||||
// unsigned short powerLinkVoltage;
|
||||
// unsigned short powerPackVoltage;
|
||||
// unsigned short powerCurrent;
|
||||
// unsigned short powerPosInsulationResistance;
|
||||
// unsigned short powerNegInsulationResistance;
|
||||
// unsigned char insEmergencyStatusWord;
|
||||
// unsigned char powerEmergencyStatusWord;
|
||||
// unsigned char insAlarmIdentificationWord;
|
||||
// unsigned char powerAlarmIdentificationWord;
|
||||
// unsigned char insCurrentSocHold1;
|
||||
// unsigned char insCurrentSocHold2;
|
||||
// unsigned char insCurrentSocHold3;
|
||||
// unsigned char fcuCurrentToInsLimit1;
|
||||
// unsigned char fcuCurrentToinsLimit2;
|
||||
// unsigned char powerCurrentSocHold1;
|
||||
// unsigned char powerCurrentSocHold2;
|
||||
// unsigned char powerCurrentSocHold3;
|
||||
// unsigned char powerCurrentToInsLimit1;
|
||||
// unsigned char powerCurrentToinsLimit2;
|
||||
// float placeholder2;
|
||||
// float placeholder3;
|
||||
// float placeholder4;
|
||||
// float placeholder5;
|
||||
Checksum checkCode;
|
||||
} msg_CcuStateFbMsg;
|
||||
#pragma pack ()
|
||||
|
||||
//高压母线配电反馈
|
||||
typedef struct {
|
||||
m_header header;
|
||||
disHighVolBusState data;
|
||||
// unsigned char fuelCellCircuitBreaker;
|
||||
// unsigned char powerLithiumBatteryCircuitBreaker;
|
||||
// unsigned char propulsionMotorCircuitBreaker;
|
||||
// unsigned char lithiumBatteryGroupInstrumentCircuitBreaker;
|
||||
// unsigned char dcDc5ModuleCircuitBreaker;
|
||||
// unsigned char bowHighVoltageDistributionBoxCircuitBreaker;
|
||||
// unsigned char sternFTDevice45CircuitBreaker;
|
||||
// unsigned char sternRudderSwitch1CircuitBreaker;
|
||||
// unsigned char sternRudderSwitch2CircuitBreaker;
|
||||
// unsigned char fbReservedCircuitBreaker;
|
||||
// unsigned char tyzReservedCircuitBreaker;
|
||||
// unsigned char reservedCircuitBreaker;
|
||||
// unsigned char busInsulationLow;
|
||||
// unsigned char busAInsulationHigh;
|
||||
// unsigned char lostPower;
|
||||
// unsigned char lostEmerPower;
|
||||
// unsigned short powerBusVoltage;
|
||||
// unsigned short dcDc5ModuleCurrent;
|
||||
// unsigned short powerBusCurrent;
|
||||
// unsigned short busbarAVoltage;
|
||||
// unsigned short propulsionMotorControlBoxCurrent;
|
||||
// unsigned short busbarACurrent;
|
||||
// unsigned short lithiumBatteryGroupMeterCurrent;
|
||||
// unsigned short bowHighVoltageDistributionBoxCurrent;
|
||||
// unsigned short sternFTDevice45Current;
|
||||
// unsigned short tyzReservedSwitchCurrent;
|
||||
// unsigned short sternRudderSwitch1Current;
|
||||
// unsigned short reservedCurrent1; // 改为 reservedCurrent1 以避免重名
|
||||
// unsigned short sternRudderSwitch2Current;
|
||||
// unsigned short reservedCurrent2; // 改为 reservedCurrent2 以避免重名
|
||||
// unsigned short fbReservedSwitchCurrent;
|
||||
// unsigned short reservedCurrent3; // 改为 reservedCurrent3 以避免重名
|
||||
Checksum checkCode;
|
||||
} msg_disHighVolBusFbMsg;
|
||||
|
||||
// 高压母线A配电反馈
|
||||
typedef struct {
|
||||
m_header header;
|
||||
disHighAVolBusState data;
|
||||
// unsigned char bowFTDevice123CircuitBreaker;
|
||||
// unsigned char actuatorCircuitBreaker;
|
||||
// unsigned char mastSteeringGearControlBoxCircuitBreaker;
|
||||
// unsigned char xczCircuitBreaker;
|
||||
// unsigned char bowRudderControlBoxCircuitBreaker;
|
||||
// unsigned char openWaterCoverStartCylinderCircuitBreaker;
|
||||
// unsigned char instrumentPowerFailureSignal;
|
||||
// unsigned char emergencyPowerFailureSignal;
|
||||
// unsigned char waterIngressionAlarm;
|
||||
// unsigned short busbarBVoltage;
|
||||
// unsigned short busbarBCurrent;
|
||||
// unsigned short bowFTDevice123Current;
|
||||
// unsigned short actuatorCurrent;
|
||||
// unsigned short mastSteeringGearControlBoxCurrent;
|
||||
// unsigned short xczCurrent;
|
||||
// unsigned short bowRudderControlBoxCurrent;
|
||||
// unsigned short openWaterCoverStartCylinderCurrent;
|
||||
Checksum checkCode;
|
||||
} msg_disHighAVolBusFbMsg;
|
||||
|
||||
// 高压母线B配电反馈
|
||||
typedef struct {
|
||||
m_header header;
|
||||
disHighBVolBusState data;
|
||||
// unsigned char lithiumBatteryGroupInstrumentCircuitBreaker;
|
||||
// unsigned char bowLowVoltageDistributionBoxCircuitBreaker;
|
||||
// unsigned char unit4InstrumentDC48VCircuitBreaker;
|
||||
// unsigned char dcC1DCDistributionPanelCircuitBreaker;
|
||||
// unsigned char reservedCircuitBreaker1; // 为了区分,添加了数字后缀
|
||||
// unsigned char reservedCircuitBreaker2; // 为了区分,添加了数字后缀
|
||||
// unsigned char emergencyLithiumBatteryGroup2CircuitBreaker;
|
||||
// unsigned char instrumentPowerFailureSignal;
|
||||
// unsigned char emergencyPowerFailureSignal;
|
||||
// unsigned char instrumentBusbarInsulationLow;
|
||||
// unsigned short instrumentBusbarVoltage;
|
||||
// unsigned short bowLowVoltageDistributionBoxCurrent;
|
||||
// unsigned short dcC1InstrumentDC48VCurrent;
|
||||
// unsigned short reservedCurrent1; // 为了区分,添加了数字后缀
|
||||
// unsigned short emergencyLithiumBatteryGroup2Current;
|
||||
// unsigned short lithiumBatteryGroupInstrumentCurrent;
|
||||
// unsigned short unit4InstrumentDC48VCurrent;
|
||||
// unsigned short reservedCurrent2; // 为了区分,添加了数字后缀
|
||||
// unsigned short emergency2BusbarVoltage;
|
||||
// unsigned short compositeEnergyManagementSystemEmergencyDC48VCurrent;
|
||||
// unsigned short fuelCellSecuritySystemEmergencyDC48VCurrent;
|
||||
// unsigned short plcControlPowerCurrent;
|
||||
Checksum checkCode;
|
||||
} msg_disHighBVolBusFbMsg;
|
||||
|
||||
//仪表汇流排配电反馈
|
||||
typedef struct {
|
||||
m_header header;
|
||||
disLowBusState data;
|
||||
// unsigned char unit1CircuitBreaker;
|
||||
// unsigned char unit2CircuitBreaker;
|
||||
// unsigned char unit3CircuitBreaker;
|
||||
// unsigned char unit5CircuitBreaker;
|
||||
// unsigned char bowPZDeviceCircuitBreaker;
|
||||
// unsigned char reservedCircuitBreaker1; // 为了区分,添加了数字后缀
|
||||
// unsigned char reservedCircuitBreaker2; // 为了区分,添加了数字后缀
|
||||
// unsigned char emergencyLithiumBatteryGroup1CircuitBreaker;
|
||||
// unsigned char powerFailureSignal;
|
||||
// unsigned char waterIngressionAlarm;
|
||||
// unsigned short instrumentBusbarVoltage;
|
||||
// unsigned short instrumentBusbarCurrent;
|
||||
// unsigned short unit1Current;
|
||||
// unsigned short unit2Current;
|
||||
// unsigned short unit3Current;
|
||||
// unsigned short unit5Current;
|
||||
// unsigned short bowPZDeviceCurrent;
|
||||
// unsigned short emergencyLithiumBatteryGroup1Current;
|
||||
// unsigned short emergency1BusbarVoltage;
|
||||
Checksum checkCode;
|
||||
} msg_disLowBusFbMsg;
|
||||
|
||||
#pragma pack ()
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
#ifndef PMSYSVARIABLE_H
|
||||
#define PMSYSVARIABLE_H
|
||||
#pragma pack (1)
|
||||
typedef struct ccuState
|
||||
{
|
||||
unsigned char currentWorkCondition;
|
||||
unsigned char fcuState;
|
||||
unsigned char fcuFaultLeve;
|
||||
float powerLimit;
|
||||
float totalPowerGeneration;
|
||||
float ch4o;
|
||||
float o2;
|
||||
float fcuVoltage;
|
||||
float fcuCurrent;
|
||||
float o2Level;
|
||||
float placeholder1;
|
||||
float exchangerTemperature;
|
||||
float fcuOutPower;
|
||||
float fcuOutIns;
|
||||
float fcuVoltageIns;
|
||||
float fcuVoltagePower;
|
||||
float fcuCurrentIns;
|
||||
float fcuCurrentPower;
|
||||
float h2Concentration1;
|
||||
float h2Concentration2;
|
||||
float o2Concentration1;
|
||||
float o2Concentration2;
|
||||
float ch4oConcentration1;
|
||||
float ch4oConcentration2;
|
||||
float backpressure1;
|
||||
float backpressure2;
|
||||
unsigned char flameDetection;
|
||||
unsigned char fcuGZ_1L;
|
||||
unsigned char fcuGZ_1H;
|
||||
unsigned char fcuGZ_2L;
|
||||
unsigned char fcuGZ_2H;
|
||||
unsigned char fcuGZ_3L;
|
||||
unsigned char fcuGZ_3H;
|
||||
unsigned char insPosRelayState;
|
||||
unsigned char insNegRelayState;
|
||||
unsigned char powerPosRelayState;
|
||||
unsigned char powerNegRelayState;
|
||||
unsigned short insBatLimit;
|
||||
unsigned short powerBatLimit;
|
||||
unsigned char insBatSoc;
|
||||
unsigned char powerBatSoc;
|
||||
unsigned short insBatTotalElectricity;
|
||||
unsigned short powerBatTotalElectricity;
|
||||
unsigned short insBatCurrentElectricity;
|
||||
unsigned short powerBatCurrentElectricity;
|
||||
unsigned char insChargeState;
|
||||
unsigned char powerChargeState;
|
||||
unsigned short insLinkVoltage;
|
||||
unsigned short insPackVoltage;
|
||||
unsigned short insCurrent;
|
||||
unsigned short insPosInsulationResistance;
|
||||
unsigned short insNegInsulationResistance;
|
||||
unsigned short powerLinkVoltage;
|
||||
unsigned short powerPackVoltage;
|
||||
unsigned short powerCurrent;
|
||||
unsigned short powerPosInsulationResistance;
|
||||
unsigned short powerNegInsulationResistance;
|
||||
unsigned char insEmergencyStatusWord;
|
||||
unsigned char powerEmergencyStatusWord;
|
||||
unsigned char insAlarmIdentificationWord;
|
||||
unsigned char powerAlarmIdentificationWord;
|
||||
unsigned char insCurrentSocHold1;
|
||||
unsigned char insCurrentSocHold2;
|
||||
unsigned char insCurrentSocHold3;
|
||||
unsigned char fcuCurrentToInsLimit1;
|
||||
unsigned char fcuCurrentToinsLimit2;
|
||||
unsigned char powerCurrentSocHold1;
|
||||
unsigned char powerCurrentSocHold2;
|
||||
unsigned char powerCurrentSocHold3;
|
||||
unsigned char powerCurrentToInsLimit1;
|
||||
unsigned char powerCurrentToinsLimit2;
|
||||
float placeholder2;
|
||||
float placeholder3;
|
||||
float placeholder4;
|
||||
float placeholder5;
|
||||
} ccuState;
|
||||
|
||||
typedef struct disHighVolBusState
|
||||
{
|
||||
unsigned char fuelCellCircuitBreaker;
|
||||
unsigned char powerLithiumBatteryCircuitBreaker;
|
||||
unsigned char propulsionMotorCircuitBreaker;
|
||||
unsigned char lithiumBatteryGroupInstrumentCircuitBreaker;
|
||||
unsigned char dcDc5ModuleCircuitBreaker;
|
||||
unsigned char bowHighVoltageDistributionBoxCircuitBreaker;
|
||||
unsigned char sternFTDevice45CircuitBreaker;
|
||||
unsigned char sternRudderSwitch1CircuitBreaker;
|
||||
unsigned char sternRudderSwitch2CircuitBreaker;
|
||||
unsigned char fbReservedCircuitBreaker;
|
||||
unsigned char tyzReservedCircuitBreaker;
|
||||
unsigned char reservedCircuitBreaker;
|
||||
unsigned char busInsulationLow;
|
||||
unsigned char busAInsulationHigh;
|
||||
unsigned char lostPower;
|
||||
unsigned char lostEmerPower;
|
||||
unsigned short powerBusVoltage;
|
||||
unsigned short dcDc5ModuleCurrent;
|
||||
unsigned short powerBusCurrent;
|
||||
unsigned short busbarAVoltage;
|
||||
unsigned short propulsionMotorControlBoxCurrent;
|
||||
unsigned short busbarACurrent;
|
||||
unsigned short lithiumBatteryGroupMeterCurrent;
|
||||
unsigned short bowHighVoltageDistributionBoxCurrent;
|
||||
unsigned short sternFTDevice45Current;
|
||||
unsigned short tyzReservedSwitchCurrent;
|
||||
unsigned short sternRudderSwitch1Current;
|
||||
unsigned short reservedCurrent1; // 改为 reservedCurrent1 以避免重名
|
||||
unsigned short sternRudderSwitch2Current;
|
||||
unsigned short reservedCurrent2; // 改为 reservedCurrent2 以避免重名
|
||||
unsigned short fbReservedSwitchCurrent;
|
||||
unsigned short reservedCurrent3; // 改为 reservedCurrent3 以避免重名
|
||||
}disHighVolBusState;
|
||||
|
||||
typedef struct disHighAVolBusState
|
||||
{
|
||||
unsigned char bowFTDevice123CircuitBreaker;
|
||||
unsigned char actuatorCircuitBreaker;
|
||||
unsigned char mastSteeringGearControlBoxCircuitBreaker;
|
||||
unsigned char xczCircuitBreaker;
|
||||
unsigned char bowRudderControlBoxCircuitBreaker;
|
||||
unsigned char openWaterCoverStartCylinderCircuitBreaker;
|
||||
unsigned char instrumentPowerFailureSignal;
|
||||
unsigned char emergencyPowerFailureSignal;
|
||||
unsigned char waterIngressionAlarm;
|
||||
unsigned short busbarBVoltage;
|
||||
unsigned short busbarBCurrent;
|
||||
unsigned short bowFTDevice123Current;
|
||||
unsigned short actuatorCurrent;
|
||||
unsigned short mastSteeringGearControlBoxCurrent;
|
||||
unsigned short xczCurrent;
|
||||
unsigned short bowRudderControlBoxCurrent;
|
||||
unsigned short openWaterCoverStartCylinderCurrent;
|
||||
}disHighAVolBusState;
|
||||
|
||||
typedef struct disHighBVolBusState
|
||||
{
|
||||
unsigned char lithiumBatteryGroupInstrumentCircuitBreaker;
|
||||
unsigned char bowLowVoltageDistributionBoxCircuitBreaker;
|
||||
unsigned char unit4InstrumentDC48VCircuitBreaker;
|
||||
unsigned char dcC1DCDistributionPanelCircuitBreaker;
|
||||
unsigned char reservedCircuitBreaker1; // 为了区分,添加了数字后缀
|
||||
unsigned char reservedCircuitBreaker2; // 为了区分,添加了数字后缀
|
||||
unsigned char emergencyLithiumBatteryGroup2CircuitBreaker;
|
||||
unsigned char instrumentPowerFailureSignal;
|
||||
unsigned char emergencyPowerFailureSignal;
|
||||
unsigned char instrumentBusbarInsulationLow;
|
||||
unsigned short instrumentBusbarVoltage;
|
||||
unsigned short bowLowVoltageDistributionBoxCurrent;
|
||||
unsigned short dcC1InstrumentDC48VCurrent;
|
||||
unsigned short reservedCurrent1; // 为了区分,添加了数字后缀
|
||||
unsigned short emergencyLithiumBatteryGroup2Current;
|
||||
unsigned short lithiumBatteryGroupInstrumentCurrent;
|
||||
unsigned short unit4InstrumentDC48VCurrent;
|
||||
unsigned short reservedCurrent2; // 为了区分,添加了数字后缀
|
||||
unsigned short emergency2BusbarVoltage;
|
||||
unsigned short compositeEnergyManagementSystemEmergencyDC48VCurrent;
|
||||
unsigned short fuelCellSecuritySystemEmergencyDC48VCurrent;
|
||||
unsigned short plcControlPowerCurrent;
|
||||
}disHighBVolBusState;
|
||||
|
||||
typedef struct disLowBusState
|
||||
{
|
||||
unsigned char unit1CircuitBreaker;
|
||||
unsigned char unit2CircuitBreaker;
|
||||
unsigned char unit3CircuitBreaker;
|
||||
unsigned char unit5CircuitBreaker;
|
||||
unsigned char bowPZDeviceCircuitBreaker;
|
||||
unsigned char reservedCircuitBreaker1; // 为了区分,添加了数字后缀
|
||||
unsigned char reservedCircuitBreaker2; // 为了区分,添加了数字后缀
|
||||
unsigned char emergencyLithiumBatteryGroup1CircuitBreaker;
|
||||
unsigned char powerFailureSignal;
|
||||
unsigned char waterIngressionAlarm;
|
||||
unsigned short instrumentBusbarVoltage;
|
||||
unsigned short instrumentBusbarCurrent;
|
||||
unsigned short unit1Current;
|
||||
unsigned short unit2Current;
|
||||
unsigned short unit3Current;
|
||||
unsigned short unit5Current;
|
||||
unsigned short bowPZDeviceCurrent;
|
||||
unsigned short emergencyLithiumBatteryGroup1Current;
|
||||
unsigned short emergency1BusbarVoltage;
|
||||
}disLowBusState;
|
||||
#pragma pack (0)
|
||||
|
||||
typedef struct pmState
|
||||
{
|
||||
ccuState ccustate;
|
||||
disHighVolBusState bus1State;
|
||||
disHighAVolBusState bus2State;
|
||||
disHighBVolBusState bus3State;
|
||||
disLowBusState bus4State;
|
||||
} PmState;
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "udpComm.h"
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
udpComm::udpComm() {}
|
||||
|
||||
@@ -15,6 +16,7 @@ Checksum udpComm::calculateChecksum(const unsigned char* data, int size)
|
||||
}
|
||||
return checksum;
|
||||
}
|
||||
|
||||
bool udpComm::getMsgId(char *m,unsigned short &id)
|
||||
{
|
||||
m_header h;
|
||||
@@ -84,4 +86,253 @@ bool udpComm::getCcuSetParmFb(char *m, msg_CcuSetParmFbMsg &s)
|
||||
|
||||
s = *p;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool udpComm::getDisSysHVBusFb(char *m, msg_disHighVolBusFbMsg &s)
|
||||
{
|
||||
m_header h;
|
||||
Checksum sum;
|
||||
msg_disHighVolBusFbMsg *p;
|
||||
p = reinterpret_cast<msg_disHighVolBusFbMsg *>(m);
|
||||
h = p->header;
|
||||
// 判断消息是否有效
|
||||
if (h.start1!= 0x20 || h.start2!= 0x20) {
|
||||
sError.push_back("DisSys HVBus Msg Header errar");
|
||||
return false;
|
||||
}
|
||||
if (h.id!= DIS_HVBUS_FB_ID) {
|
||||
sError.push_back("DisSys HVBus Msg ID error");
|
||||
return false;
|
||||
}
|
||||
sum = calculateChecksum((unsigned char*)m, sizeof(msg_disHighVolBusFbMsg));
|
||||
if (sum!= p->checkCode) {
|
||||
sError.push_back("DisSys HVBus Msg Check error");
|
||||
return false;
|
||||
}
|
||||
s = *p;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool udpComm::getDisSysHVABusFb(char *m, msg_disHighAVolBusFbMsg &s)
|
||||
{
|
||||
m_header h;
|
||||
Checksum sum;
|
||||
msg_disHighAVolBusFbMsg *p;
|
||||
p = reinterpret_cast<msg_disHighAVolBusFbMsg *>(m);
|
||||
h = p->header;
|
||||
// 判断消息是否有效
|
||||
if (h.start1!= 0x20 || h.start2!= 0x20) {
|
||||
sError.push_back("DisSys HVABus Msg Header errar");
|
||||
return false;
|
||||
}
|
||||
if (h.id!= DIS_HVBUSA_FB_ID) {
|
||||
sError.push_back("DisSys HVABus Msg ID error");
|
||||
return false;
|
||||
}
|
||||
sum = calculateChecksum((unsigned char*)m, sizeof(msg_disHighAVolBusFbMsg));
|
||||
if (sum!= p->checkCode) {
|
||||
sError.push_back("DisSys HVABus Msg Check error");
|
||||
return false;
|
||||
}
|
||||
s = *p;
|
||||
return true;
|
||||
}
|
||||
bool udpComm::getDisSysHVBBusFb(char *m, msg_disHighBVolBusFbMsg &s)
|
||||
{
|
||||
m_header h;
|
||||
Checksum sum;
|
||||
msg_disHighBVolBusFbMsg *p;
|
||||
p = reinterpret_cast<msg_disHighBVolBusFbMsg *>(m);
|
||||
h = p->header;
|
||||
// 判断消息是否有效
|
||||
if (h.start1!= 0x20 || h.start2!= 0x20) {
|
||||
sError.push_back("DisSys HVBBus Msg Header errar");
|
||||
return false;
|
||||
}
|
||||
if (h.id!= DIS_HVBUSB_FB_ID) {
|
||||
sError.push_back("DisSys HVBBus Msg ID error");
|
||||
return false;
|
||||
}
|
||||
sum = calculateChecksum((unsigned char*)m, sizeof(msg_disHighBVolBusFbMsg));
|
||||
if (sum!= p->checkCode) {
|
||||
sError.push_back("DisSys HVBBus Msg Check error");
|
||||
return false;
|
||||
}
|
||||
s = *p;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool udpComm::getDisSysLVBusFb(char *m, msg_disLowBusFbMsg &s)
|
||||
{
|
||||
m_header h;
|
||||
Checksum sum;
|
||||
msg_disLowBusFbMsg *p;
|
||||
p = reinterpret_cast<msg_disLowBusFbMsg *>(m);
|
||||
h = p->header;
|
||||
// 判断消息是否有效
|
||||
if (h.start1!= 0x20 || h.start2!= 0x20) {
|
||||
sError.push_back("DisSys LVBus Msg Header errar");
|
||||
return false;
|
||||
}
|
||||
if (h.id!= DIS_LVBUS_FB_ID) {
|
||||
sError.push_back("DisSys LVBus Msg ID error");
|
||||
return false;
|
||||
}
|
||||
sum = calculateChecksum((unsigned char*)m, sizeof(msg_disLowBusFbMsg));
|
||||
if (sum!= p->checkCode) {
|
||||
sError.push_back("DisSys LVBus Msg Check error");
|
||||
return false;
|
||||
}
|
||||
s = *p;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool udpComm::pushMsgToQueue(unsigned char *m)
|
||||
{
|
||||
if(m==NULL)
|
||||
{
|
||||
sError.push_back("pushMsgToQueue faile,Msg is NULL");
|
||||
return false;
|
||||
}
|
||||
unsigned char* Buff = m;
|
||||
//判断消息
|
||||
char *header = new char[sizeof(m_header)];
|
||||
unsigned short id;
|
||||
memcpy(header,Buff,sizeof(m_header));
|
||||
if(!getMsgId(header,id))
|
||||
{
|
||||
sError.push_back("pushMsgToQueue faile,Msg ID error");
|
||||
return false;
|
||||
}
|
||||
delete []header;
|
||||
//输入消息
|
||||
switch (id)
|
||||
{
|
||||
case CCU_STATE_FB_ID: //CCU_STATE_FB 0x0051
|
||||
msg_CcuStateFbMsg s;
|
||||
if(getCcuState((char *)Buff,s))
|
||||
{
|
||||
if(m_qReceiveCcuStateBuffer.size()<QUENUE_SIZE)
|
||||
m_qReceiveCcuStateBuffer.push(s);
|
||||
else
|
||||
{
|
||||
sError.push_back("pushMsgToQueue faile,CcuState buffer is full");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//sError.push_back();
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case CCU_SET_PARM_FB_ID: //CCU_SET_PARM_FB 0x0040
|
||||
msg_CcuSetParmFbMsg p;
|
||||
if(getCcuSetParmFb((char *)Buff,p))
|
||||
{
|
||||
if(m_qReceiveCcuSetParmBuffer.size()<QUENUE_SIZE)
|
||||
m_qReceiveCcuSetParmBuffer.push(p);
|
||||
else
|
||||
{
|
||||
sError.push_back("pushMsgToQueue faile,CcuSetParm buffer is full");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case DIS_HVBUS_FB_ID: //DIS_HVBUS_FB 0x0020
|
||||
msg_disHighVolBusFbMsg h;
|
||||
if(getDisSysHVBusFb((char *)Buff,h))
|
||||
{
|
||||
if(m_qReceiveDisHighVolBusBuffer.size()<QUENUE_SIZE)
|
||||
m_qReceiveDisHighVolBusBuffer.push(h);
|
||||
else
|
||||
{
|
||||
sError.push_back("pushMsgToQueue faile,DisSysHVBus buffer is full");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case DIS_HVBUSA_FB_ID: //DIS_HVBUSA_FB 0x0006
|
||||
msg_disHighAVolBusFbMsg a;
|
||||
if(getDisSysHVABusFb((char *)Buff,a))
|
||||
{
|
||||
if(m_qReceiveDisHighAVolBusBuffer.size()<QUENUE_SIZE)
|
||||
m_qReceiveDisHighAVolBusBuffer.push(a);
|
||||
else
|
||||
{
|
||||
sError.push_back("pushMsgToQueue faile,DisSysHVABus buffer is full");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case DIS_HVBUSB_FB_ID: //DIS_HVBUSB_FB 0x0007
|
||||
msg_disHighBVolBusFbMsg b;
|
||||
if(getDisSysHVBBusFb((char *)Buff,b))
|
||||
{
|
||||
if(m_qReceiveDisHighBVolBusBuffer.size()<QUENUE_SIZE)
|
||||
m_qReceiveDisHighBVolBusBuffer.push(b);
|
||||
else
|
||||
{
|
||||
sError.push_back("pushMsgToQueue faile,DisSysHVBBus buffer is full");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case DIS_LVBUS_FB_ID: //DIS_LVBUS_FB 0x0008
|
||||
msg_disLowBusFbMsg l;
|
||||
if(getDisSysLVBusFb((char *)Buff,l))
|
||||
{
|
||||
if(m_qReceiveDisLowBusBuffer.size()<QUENUE_SIZE)
|
||||
m_qReceiveDisLowBusBuffer.push(l);
|
||||
else
|
||||
{
|
||||
sError.push_back("pushMsgToQueue faile,DisSysLVBus buffer is full");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool udpComm::clearMsgQueue()
|
||||
{
|
||||
while(!m_qReceiveCcuStateBuffer.empty())
|
||||
m_qReceiveCcuStateBuffer.pop();
|
||||
|
||||
while(!m_qReceiveCcuSetParmBuffer.empty())
|
||||
m_qReceiveCcuSetParmBuffer.pop();
|
||||
|
||||
while(!m_qReceiveDisHighVolBusBuffer.empty())
|
||||
m_qReceiveDisHighVolBusBuffer.pop();
|
||||
|
||||
while(!m_qReceiveDisHighAVolBusBuffer.empty())
|
||||
m_qReceiveDisHighAVolBusBuffer.pop();
|
||||
|
||||
while(!m_qReceiveDisHighBVolBusBuffer.empty())
|
||||
m_qReceiveDisHighBVolBusBuffer.pop();
|
||||
|
||||
while(!m_qReceiveDisLowBusBuffer.empty())
|
||||
m_qReceiveDisLowBusBuffer.pop();
|
||||
return true;
|
||||
}
|
||||
@@ -3,21 +3,42 @@
|
||||
#include "ccuUdpMsg.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include <string.h>
|
||||
|
||||
#define QUENUE_SIZE 100
|
||||
class udpComm {
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
udpComm();
|
||||
~udpComm();
|
||||
|
||||
bool pushMsgToQueue(unsigned char *m);
|
||||
bool clearMsgQueue();
|
||||
|
||||
bool getMsgId(char *m,unsigned short &id);
|
||||
|
||||
bool getCcuState(char *m, msg_CcuStateFbMsg &s);
|
||||
bool getCcuSetParmFb(char *m, msg_CcuSetParmFbMsg &s);
|
||||
|
||||
bool getDisSysHVBusFb(char *m, msg_disHighVolBusFbMsg &s);
|
||||
bool getDisSysHVABusFb(char *m, msg_disHighAVolBusFbMsg &s);
|
||||
bool getDisSysHVBBusFb(char *m, msg_disHighBVolBusFbMsg &s);
|
||||
bool getDisSysLVBusFb(char *m, msg_disLowBusFbMsg &s);
|
||||
|
||||
bool sendCcuColCmd(const msg_CcuColCmdMsg m);
|
||||
bool sendCcuSetParmCmd(const msg_CcuSetParmMsg m);
|
||||
|
||||
Checksum calculateChecksum(const unsigned char* data, int size);
|
||||
|
||||
std::vector<std::string> sError;
|
||||
std::queue<msg_CcuStateFbMsg> m_qReceiveCcuStateBuffer;
|
||||
std::queue<msg_CcuSetParmFbMsg> m_qReceiveCcuSetParmBuffer;
|
||||
std::queue<msg_disHighVolBusFbMsg> m_qReceiveDisHighVolBusBuffer;
|
||||
std::queue<msg_disHighAVolBusFbMsg> m_qReceiveDisHighAVolBusBuffer;
|
||||
std::queue<msg_disHighBVolBusFbMsg> m_qReceiveDisHighBVolBusBuffer;
|
||||
std::queue<msg_disLowBusFbMsg> m_qReceiveDisLowBusBuffer;
|
||||
|
||||
private:
|
||||
msg_CcuColCmdMsg m_ccuColCmd;
|
||||
|
||||
Reference in New Issue
Block a user