增加了通信协议解析的功能
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
#--------------------------------------------------------
|
||||
# The CMakeLists.txt for: appPowerMangerGui
|
||||
# Author(s):
|
||||
#--------------------------------------------------------
|
||||
|
||||
SET(SRC
|
||||
PowerMangerGui.cpp
|
||||
PowerMangerGui_Info.cpp
|
||||
main.cpp
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(appPowerMangerGui ${SRC})
|
||||
|
||||
TARGET_LINK_LIBRARIES(appPowerMangerGui
|
||||
${MOOS_LIBRARIES}
|
||||
mbutil
|
||||
m
|
||||
pthread)
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/************************************************************/
|
||||
/* NAME: */
|
||||
/* ORGN: MIT */
|
||||
/* FILE: PowerMangerGui.cpp */
|
||||
/* DATE: */
|
||||
/************************************************************/
|
||||
|
||||
#include <iterator>
|
||||
#include "MBUtils.h"
|
||||
#include "PowerMangerGui.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
//---------------------------------------------------------
|
||||
// Constructor
|
||||
|
||||
PowerMangerGui::PowerMangerGui()
|
||||
{
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// Destructor
|
||||
|
||||
PowerMangerGui::~PowerMangerGui()
|
||||
{
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// Procedure: OnNewMail
|
||||
|
||||
bool PowerMangerGui::OnNewMail(MOOSMSG_LIST &NewMail)
|
||||
{
|
||||
MOOSMSG_LIST::iterator p;
|
||||
|
||||
for(p=NewMail.begin(); p!=NewMail.end(); p++) {
|
||||
CMOOSMsg &msg = *p;
|
||||
|
||||
#if 0 // Keep these around just for template
|
||||
string key = msg.GetKey();
|
||||
string comm = msg.GetCommunity();
|
||||
double dval = msg.GetDouble();
|
||||
string sval = msg.GetString();
|
||||
string msrc = msg.GetSource();
|
||||
double mtime = msg.GetTime();
|
||||
bool mdbl = msg.IsDouble();
|
||||
bool mstr = msg.IsString();
|
||||
#endif
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// Procedure: OnConnectToServer
|
||||
|
||||
bool PowerMangerGui::OnConnectToServer()
|
||||
{
|
||||
RegisterVariables();
|
||||
return(true);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// Procedure: Iterate()
|
||||
// happens AppTick times per second
|
||||
|
||||
bool PowerMangerGui::Iterate()
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// Procedure: OnStartUp()
|
||||
// happens before connection is open
|
||||
|
||||
bool PowerMangerGui::OnStartUp()
|
||||
{
|
||||
list<string> sParams;
|
||||
m_MissionReader.EnableVerbatimQuoting(false);
|
||||
if(m_MissionReader.GetConfiguration(GetAppName(), sParams)) {
|
||||
list<string>::iterator p;
|
||||
for(p=sParams.begin(); p!=sParams.end(); p++) {
|
||||
string line = *p;
|
||||
string param = tolower(biteStringX(line, '='));
|
||||
string value = line;
|
||||
|
||||
if(param == "foo") {
|
||||
//handled
|
||||
}
|
||||
else if(param == "bar") {
|
||||
//handled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RegisterVariables();
|
||||
return(true);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// Procedure: RegisterVariables
|
||||
|
||||
void PowerMangerGui::RegisterVariables()
|
||||
{
|
||||
// Register("FOOBAR", 0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/************************************************************/
|
||||
/* NAME: */
|
||||
/* ORGN: MIT */
|
||||
/* FILE: PowerMangerGui.h */
|
||||
/* DATE: */
|
||||
/************************************************************/
|
||||
|
||||
#ifndef PowerMangerGui_HEADER
|
||||
#define PowerMangerGui_HEADER
|
||||
|
||||
#include "FL/Fl.H"
|
||||
#include "MOOS/libMOOS/MOOSLib.h"
|
||||
|
||||
class PowerMangerGui : public CMOOSApp {
|
||||
public:
|
||||
PowerMangerGui();
|
||||
~PowerMangerGui();
|
||||
bool minWindows();
|
||||
|
||||
protected: // Standard MOOSApp functions to overload
|
||||
bool OnNewMail(MOOSMSG_LIST &NewMail);
|
||||
bool Iterate();
|
||||
bool OnConnectToServer();
|
||||
bool OnStartUp();
|
||||
|
||||
protected:
|
||||
void RegisterVariables();
|
||||
|
||||
private: // Configuration variables
|
||||
private: // State variables
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,115 @@
|
||||
/****************************************************************/
|
||||
/* NAME: */
|
||||
/* ORGN: MIT Cambridge MA */
|
||||
/* FILE: PowerMangerGui_Info.cpp */
|
||||
/* DATE: Dec 29th 1963 */
|
||||
/****************************************************************/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include "PowerMangerGui_Info.h"
|
||||
#include "ColorParse.h"
|
||||
#include "ReleaseInfo.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Procedure: showSynopsis
|
||||
|
||||
void showSynopsis()
|
||||
{
|
||||
blk("SYNOPSIS: ");
|
||||
blk("------------------------------------ ");
|
||||
blk(" The appPowerMangerGui application is used for ");
|
||||
blk(" ");
|
||||
blk(" ");
|
||||
blk(" ");
|
||||
blk(" ");
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Procedure: showHelpAndExit
|
||||
|
||||
void showHelpAndExit()
|
||||
{
|
||||
blk(" ");
|
||||
blu("=============================================================== ");
|
||||
blu("Usage: appPowerMangerGui file.moos [OPTIONS] ");
|
||||
blu("=============================================================== ");
|
||||
blk(" ");
|
||||
showSynopsis();
|
||||
blk(" ");
|
||||
blk("Options: ");
|
||||
mag(" --alias","=<ProcessName> ");
|
||||
blk(" Launch appPowerMangerGui with the given process name ");
|
||||
blk(" rather than appPowerMangerGui. ");
|
||||
mag(" --example, -e ");
|
||||
blk(" Display example MOOS configuration block. ");
|
||||
mag(" --help, -h ");
|
||||
blk(" Display this help message. ");
|
||||
mag(" --interface, -i ");
|
||||
blk(" Display MOOS publications and subscriptions. ");
|
||||
mag(" --version,-v ");
|
||||
blk(" Display the release version of appPowerMangerGui. ");
|
||||
blk(" ");
|
||||
blk("Note: If argv[2] does not otherwise match a known option, ");
|
||||
blk(" then it will be interpreted as a run alias. This is ");
|
||||
blk(" to support pAntler launching conventions. ");
|
||||
blk(" ");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Procedure: showExampleConfigAndExit
|
||||
|
||||
void showExampleConfigAndExit()
|
||||
{
|
||||
blk(" ");
|
||||
blu("=============================================================== ");
|
||||
blu("appPowerMangerGui Example MOOS Configuration ");
|
||||
blu("=============================================================== ");
|
||||
blk(" ");
|
||||
blk("ProcessConfig = appPowerMangerGui ");
|
||||
blk("{ ");
|
||||
blk(" AppTick = 4 ");
|
||||
blk(" CommsTick = 4 ");
|
||||
blk(" ");
|
||||
blk("} ");
|
||||
blk(" ");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Procedure: showInterfaceAndExit
|
||||
|
||||
void showInterfaceAndExit()
|
||||
{
|
||||
blk(" ");
|
||||
blu("=============================================================== ");
|
||||
blu("appPowerMangerGui INTERFACE ");
|
||||
blu("=============================================================== ");
|
||||
blk(" ");
|
||||
showSynopsis();
|
||||
blk(" ");
|
||||
blk("SUBSCRIPTIONS: ");
|
||||
blk("------------------------------------ ");
|
||||
blk(" NODE_MESSAGE = src_node=alpha,dest_node=bravo,var_name=FOO, ");
|
||||
blk(" string_val=BAR ");
|
||||
blk(" ");
|
||||
blk("PUBLICATIONS: ");
|
||||
blk("------------------------------------ ");
|
||||
blk(" Publications are determined by the node message content. ");
|
||||
blk(" ");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Procedure: showReleaseInfoAndExit
|
||||
|
||||
void showReleaseInfoAndExit()
|
||||
{
|
||||
showReleaseInfo("appPowerMangerGui", "gpl");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/****************************************************************/
|
||||
/* NAME: */
|
||||
/* ORGN: MIT Cambridge MA */
|
||||
/* FILE: PowerMangerGui_Info.h */
|
||||
/* DATE: Dec 29th 1963 */
|
||||
/****************************************************************/
|
||||
|
||||
#ifndef PowerMangerGui_INFO_HEADER
|
||||
#define PowerMangerGui_INFO_HEADER
|
||||
|
||||
void showSynopsis();
|
||||
void showHelpAndExit();
|
||||
void showExampleConfigAndExit();
|
||||
void showInterfaceAndExit();
|
||||
void showReleaseInfoAndExit();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
//------------------------------------------------
|
||||
// appPowerMangerGui config block
|
||||
|
||||
ProcessConfig = appPowerMangerGui
|
||||
{
|
||||
AppTick = 4
|
||||
CommsTick = 4
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/************************************************************/
|
||||
/* NAME: */
|
||||
/* ORGN: MIT */
|
||||
/* FILE: main.cpp */
|
||||
/* DATE: */
|
||||
/************************************************************/
|
||||
|
||||
#include <string>
|
||||
#include "MBUtils.h"
|
||||
#include "ColorParse.h"
|
||||
#include "PowerMangerGui.h"
|
||||
#include "PowerMangerGui_Info.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
string mission_file;
|
||||
string run_command = argv[0];
|
||||
|
||||
for(int i=1; i<argc; i++) {
|
||||
string argi = argv[i];
|
||||
if((argi=="-v") || (argi=="--version") || (argi=="-version"))
|
||||
showReleaseInfoAndExit();
|
||||
else if((argi=="-e") || (argi=="--example") || (argi=="-example"))
|
||||
showExampleConfigAndExit();
|
||||
else if((argi == "-h") || (argi == "--help") || (argi=="-help"))
|
||||
showHelpAndExit();
|
||||
else if((argi == "-i") || (argi == "--interface"))
|
||||
showInterfaceAndExit();
|
||||
else if(strEnds(argi, ".moos") || strEnds(argi, ".moos++"))
|
||||
mission_file = argv[i];
|
||||
else if(strBegins(argi, "--alias="))
|
||||
run_command = argi.substr(8);
|
||||
else if(i==2)
|
||||
run_command = argi;
|
||||
}
|
||||
|
||||
if(mission_file == "")
|
||||
showHelpAndExit();
|
||||
|
||||
cout << termColor("green");
|
||||
cout << "appPowerMangerGui launching as " << run_command << endl;
|
||||
cout << termColor() << endl;
|
||||
|
||||
PowerMangerGui PowerMangerGui;
|
||||
|
||||
PowerMangerGui.Run(run_command.c_str(), mission_file.c_str());
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -181,6 +181,7 @@ bool PowerManger::ListenLoopCCU()
|
||||
{
|
||||
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));
|
||||
@@ -201,16 +202,17 @@ bool PowerManger::ListenLoopCCU()
|
||||
//处理消息
|
||||
switch (id)
|
||||
{
|
||||
case 0x0051: //CCU_STATE_FB 0x0051
|
||||
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 << "id:" << s.header.id << endl;
|
||||
cout << "currentWorkCondition:" << (double)s.currentWorkCondition << endl;
|
||||
cout << "fcuState:" << s.fcuState << endl;
|
||||
cout << "fcuFaultLeve:" << s.fcuFaultLeve << endl;
|
||||
cout << "powerLimit:" << s.powerLimit << 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
|
||||
{
|
||||
@@ -219,7 +221,7 @@ bool PowerManger::ListenLoopCCU()
|
||||
m_udpComm.sError.clear();
|
||||
}
|
||||
break;
|
||||
case 0x0040: //CCU_SET_PARM_FB 0x0040
|
||||
case CCU_SET_PARM_FB_ID: //CCU_SET_PARM_FB 0x0040
|
||||
msg_CcuSetParmFbMsg p;
|
||||
if(m_udpComm.getCcuSetParmFb((char *)Buff,p))
|
||||
{
|
||||
|
||||
@@ -47,6 +47,12 @@ class PowerManger : public AppCastingMOOSApp
|
||||
protected: // app function
|
||||
// bool _ListenCB();
|
||||
XPCUdpSocket* setUdpScoket(long lPort);
|
||||
//
|
||||
bool buildStateReport();
|
||||
bool buildEquipmentReport();
|
||||
bool buildDisributionReport();
|
||||
bool buildSubDistributionReport();
|
||||
bool buildPredictionReport();
|
||||
|
||||
protected: // app variables
|
||||
long m_lPort;
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
#ifndef CCUUDPMSG__H
|
||||
#define CCUUDPMSG__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
|
||||
|
||||
#pragma pack (1)
|
||||
typedef unsigned int Checksum;
|
||||
|
||||
typedef struct {
|
||||
@@ -177,5 +183,6 @@ typedef struct {
|
||||
float placeholder5;
|
||||
Checksum checkCode;
|
||||
} msg_CcuStateFbMsg;
|
||||
#pragma pack ()
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,13 +4,24 @@
|
||||
udpComm::udpComm() {}
|
||||
|
||||
udpComm::~udpComm() {}
|
||||
|
||||
|
||||
Checksum udpComm::calculateChecksum(const unsigned char* data, int size)
|
||||
{
|
||||
Checksum checksum = 0;
|
||||
int size_data = size - sizeof(Checksum);
|
||||
for (int i = 0; i < size_data; i++) {
|
||||
checksum += data[i];
|
||||
}
|
||||
return checksum;
|
||||
}
|
||||
bool udpComm::getMsgId(char *m,unsigned short &id)
|
||||
{
|
||||
m_header h;
|
||||
h = *reinterpret_cast<m_header *>(m);
|
||||
// 判断消息是否有效
|
||||
if (h.start1!= 0x20 || h.start2!= 0x20) {
|
||||
// sError.push_back("Msg Header errar");
|
||||
sError.push_back("Msg Header errar");
|
||||
return false;
|
||||
}
|
||||
id = h.id;
|
||||
@@ -31,39 +42,13 @@ bool udpComm::getCcuState(char *m, msg_CcuStateFbMsg &s) {
|
||||
}
|
||||
if (h.id != 0x0051) {
|
||||
sError.push_back("CcuState Msg ID error");
|
||||
// std::cout << "-------" <<h.id << std::endl;
|
||||
return false;
|
||||
}
|
||||
sum =
|
||||
h.id + h.length + h.start1 + h.start2 + p->currentWorkCondition +
|
||||
p->fcuState + p->fcuFaultLeve + p->powerLimit + p->totalPowerGeneration +
|
||||
p->ch4o + p->o2 + p->fcuVoltage + p->fcuCurrent + p->o2Level +
|
||||
p->placeholder1 + p->exchangerTemperature + p->fcuOutPower +
|
||||
p->fcuOutIns + p->fcuVoltageIns + p->fcuVoltagePower + p->fcuCurrentIns +
|
||||
p->fcuCurrentPower + p->h2Concentration1 + p->h2Concentration2 +
|
||||
p->o2Concentration1 + p->o2Concentration2 + p->ch4oConcentration1 +
|
||||
p->ch4oConcentration2 + p->backpressure1 + p->backpressure2 +
|
||||
p->flameDetection + p->fcuGZ_1L + p->fcuGZ_1H + p->fcuGZ_2L +
|
||||
p->fcuGZ_2H + p->fcuGZ_3L + p->fcuGZ_3H + p->insPosRelayState +
|
||||
p->insNegRelayState + p->powerNegRelayState + p->powerPosRelayState +
|
||||
p->insBatLimit + p->powerBatLimit + p->insBatSoc + p->powerBatSoc +
|
||||
p->insBatTotalElectricity + p->powerBatTotalElectricity +
|
||||
p->insBatCurrentElectricity + p->powerBatCurrentElectricity +
|
||||
p->insChargeState + p->powerChargeState + p->insLinkVoltage +
|
||||
p->insPackVoltage + p->insCurrent + p->insPosInsulationResistance +
|
||||
p->insNegInsulationResistance + p->powerLinkVoltage +
|
||||
p->powerPackVoltage + p->powerCurrent + p->powerPosInsulationResistance +
|
||||
p->powerNegInsulationResistance + p->insEmergencyStatusWord +
|
||||
p->powerEmergencyStatusWord + p->insAlarmIdentificationWord +
|
||||
p->powerAlarmIdentificationWord + p->insCurrentSocHold1 +
|
||||
p->insCurrentSocHold2 + p->insCurrentSocHold3 + p->fcuCurrentToInsLimit1 +
|
||||
p->fcuCurrentToinsLimit2 + p->powerCurrentSocHold1 +
|
||||
p->powerCurrentSocHold2 + p->powerCurrentSocHold3 +
|
||||
p->powerCurrentToInsLimit1 + p->powerCurrentToinsLimit2 +
|
||||
p->placeholder2 + p->placeholder3 + p->placeholder5;
|
||||
sum = calculateChecksum((unsigned char*)m, sizeof(msg_CcuStateFbMsg));
|
||||
|
||||
if (sum != p->checkCode) {
|
||||
sError.push_back("CcuStat Msg Check error");
|
||||
//return false; TODO: 暂时不校验
|
||||
return false;
|
||||
}
|
||||
s = *p;
|
||||
return true;
|
||||
@@ -90,7 +75,7 @@ bool udpComm::getCcuSetParmFb(char *m, msg_CcuSetParmFbMsg &s)
|
||||
return false;
|
||||
}
|
||||
|
||||
sum = h.id + h.length + h.start1 + h.start2 + p->flag + p->failureCode;
|
||||
sum = calculateChecksum((unsigned char*)m, sizeof(msg_CcuSetParmFbMsg));
|
||||
|
||||
if (sum!= p->checkCode) {
|
||||
sError.push_back("CcuSetParm Msg Check error");
|
||||
|
||||
@@ -14,6 +14,9 @@ public:
|
||||
bool getCcuSetParmFb(char *m, msg_CcuSetParmFbMsg &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;
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user