146 lines
4.2 KiB
C++
146 lines
4.2 KiB
C++
/*
|
|
* @Author: zhaojingkui 1553836110@qq.com
|
|
* @Date: 2024-10-22 16:47:01
|
|
* @LastEditors: zhaojingkui 1553836110@qq.com
|
|
* @LastEditTime: 2024-10-22 18:03:29
|
|
* @FilePath: /H100PowerManger/src/pPowerManger/PowerManger.h
|
|
* @Description:
|
|
*
|
|
* Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
|
|
*/
|
|
/************************************************************/
|
|
/* NAME: */
|
|
/* ORGN: MIT, Cambridge MA */
|
|
/* FILE: PowerManger.h */
|
|
/* DATE: December 29th, 1963 */
|
|
/************************************************************/
|
|
|
|
#ifndef PowerManger_HEADER
|
|
#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 "MOOS/libMOOS/Utils/MOOSUtilityFunctions.h"
|
|
#include "MOOS/libMOOS/Utils/ConsoleColours.h"
|
|
#include "ccuUdpMsg.h"
|
|
#include "json/json.h"
|
|
#include "udpComm.h"
|
|
#include "pmSysvariable.h"
|
|
#include "fsm.h"
|
|
|
|
#define VAR_TO_STR(var) #var
|
|
|
|
#define IPORT 5000
|
|
#define CCUPORT 5001
|
|
#define CCUHOST "127.0.0.1"
|
|
#define MAX_UDP_PKT_SIZE 65535
|
|
#define SKEW_TOLERANCE 5
|
|
|
|
#define PM_STATE_VAR "uPower_pmState_st"
|
|
#define PM_CURRENTSTATE_VAR "uPower_currentState_st"
|
|
#define PM_DISSTATE_VAR "uPower_disSysState_st"
|
|
#define PM_LIBATSTATE_VAR "uPower_liBatState_st"
|
|
#define PM_FCSSTATE_VAR "uPower_fcsState_st"
|
|
|
|
|
|
class PowerManger : public AppCastingMOOSApp
|
|
{
|
|
public:
|
|
PowerManger();
|
|
~PowerManger();
|
|
public:
|
|
bool ListenLoopUDP();
|
|
|
|
protected: // Standard MOOSApp functions to overload
|
|
bool OnNewMail(MOOSMSG_LIST &NewMail);
|
|
bool Iterate();
|
|
bool OnConnectToServer();
|
|
bool OnStartUp();
|
|
bool buildReport();
|
|
void registerVariables();
|
|
|
|
protected: // app function
|
|
// bool _ListenCB();
|
|
bool updatePmState();
|
|
void updateTime(){m_current_time = MOOSTime();}
|
|
bool IsSkewed(double dfTimeNow, double * pdfSkew = NULL);
|
|
string getTypeName(const string typeName);
|
|
|
|
|
|
|
|
//通信相关
|
|
XPCUdpSocket* setUdpScoket(long lPort);
|
|
bool disSystemOperation(disBreaker optBreaker, disBreakerOpt);
|
|
bool buildPowerSysReport();
|
|
|
|
protected: // app variables
|
|
//系统状态
|
|
unsigned char workCondition;
|
|
unsigned char currentMod;
|
|
unsigned char powerState;
|
|
unsigned char falutLevel;
|
|
vector<unsigned int> faultCode;
|
|
unsigned int soc;
|
|
unsigned int sustainableTime;
|
|
pmState m_pmCurrentState;
|
|
bool m_connected;
|
|
// 当前传输状态
|
|
msg_CcuStateFbMsg m_CcuCurrentState;
|
|
msg_disHighVolBusFbMsg m_disHighVolBusCurrentState;
|
|
msg_disHighAVolBusFbMsg m_disHighAVolBusCurrentState;
|
|
msg_disHighBVolBusFbMsg m_disHighBVolBusCurrentState;
|
|
msg_disLowBusFbMsg m_disLowBusState;
|
|
|
|
private: // Configuration variables
|
|
udpComm m_udpComm;
|
|
XPCUdpSocket *m_pCcuUdpComm;
|
|
CMOOSThread m_ListenThread;
|
|
long m_lPort;
|
|
unsigned int m_nReceiveBufferSizeKB;
|
|
unsigned int m_nSendBufferSizeKB;
|
|
double m_current_time;
|
|
unsigned int m_faultNum;
|
|
|
|
// CMOOSThread m_SendThread;
|
|
private: //
|
|
bool inline saveStringToJsonFile(const string &strJson, const string &strFileName);
|
|
|
|
|
|
public: //状态实现
|
|
|
|
void printState(FSM_State st, string desp){
|
|
cout << MOOS::ConsoleColours::Yellow() << "STATE " << st.id << " [" << st.name << "] " << MOOS::ConsoleColours::reset();
|
|
cout << MOOS::ConsoleColours::Blue() << " -> " << MOOS::ConsoleColours::reset();
|
|
// 检查desp是否有“故障”
|
|
if (desp.find("故障") != string::npos) {
|
|
cout << MOOS::ConsoleColours::Red() << desp << MOOS::ConsoleColours::reset() << endl;
|
|
return;
|
|
}
|
|
cout << MOOS::ConsoleColours::Green() << desp << MOOS::ConsoleColours::reset() << endl;
|
|
}
|
|
|
|
FSM_State m_pmState; //当前状态
|
|
string m_pmEvent;
|
|
FSM m_fsm;
|
|
//系统状态定义
|
|
FSM_State m_state1;
|
|
FSM_State m_state2;
|
|
FSM_State m_state3;
|
|
|
|
FSM_State startState;
|
|
FSM_State stopState;
|
|
//初始化状态
|
|
FSM_State m_Inite_s1;
|
|
static int handleInite_s1(FSM_State &fsm, void* pData);
|
|
|
|
//故障处理
|
|
FSM_State m_Fault_s99;
|
|
static int handleFault_s99(FSM_State &fsm, void* pData);
|
|
|
|
};
|
|
|
|
#endif
|