使用tinyfsm
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
#include "json/json.h"
|
||||
#include "udpComm.h"
|
||||
#include "pmSysvariable.h"
|
||||
#include "fsm.h"
|
||||
#include "PowerManagerFsm.hpp"
|
||||
#include "SQLiteDB.h"
|
||||
#include "driver.h"
|
||||
|
||||
@@ -96,92 +96,81 @@ class PowerManger : public AppCastingMOOSApp
|
||||
double msg_disHighAVolBusFbMsg_Update_time;
|
||||
double msg_disHighBVolBusFbMsg_Update_time;
|
||||
double msg_disLowBusFbMsg_Update_time;
|
||||
|
||||
protected:
|
||||
//===========================交互状态变量==================================
|
||||
Driver m_driver; //设备驱动
|
||||
pmState m_pmCurrentState; //能源系统的当前状态
|
||||
disSysBreakerList m_currentDisBreakerState; //配电断路器状态
|
||||
disSysBreakerList m_targetDisBreakerState;
|
||||
DriverTable m_currentDriverState;
|
||||
DriverTable m_MSDriverCmd;
|
||||
DriverTable m_subDisSysCmd;
|
||||
DriverTable m_subDisSysState;
|
||||
//===========================================================================
|
||||
//系统运行状态
|
||||
unsigned char workCondition;
|
||||
unsigned char currentMod;
|
||||
unsigned char powerState;
|
||||
unsigned char falutLevel;
|
||||
vector<unsigned int> faultCode;
|
||||
unsigned int soc;
|
||||
unsigned int sustainableTime;
|
||||
|
||||
// 配电和CCU的反馈状态
|
||||
msg_CcuStateFbMsg m_CcuCurrentState;
|
||||
msg_disHighVolBusFbMsg m_disHighVolBusCurrentState;
|
||||
msg_disHighAVolBusFbMsg m_disHighAVolBusCurrentState;
|
||||
msg_disHighBVolBusFbMsg m_disHighBVolBusCurrentState;
|
||||
msg_disLowBusFbMsg m_disLowBusState;
|
||||
|
||||
//下位机操作函数
|
||||
ccuColCmd m_CcuColCmd;
|
||||
void disSysOption();
|
||||
void ccuOption();
|
||||
|
||||
char getBreakerOption(char cmd);
|
||||
void initControlCmd();
|
||||
|
||||
//上位机操作函数
|
||||
MSControlCmd m_msCmd;
|
||||
bool buildPowerSysReport();
|
||||
bool getMsCmdFromJson(MSControlCmd &cmd,const string &strJson);
|
||||
|
||||
private:
|
||||
udpComm m_udpComm;
|
||||
XPCUdpSocket *m_pCcuUdpComm;
|
||||
CMOOSThread m_ListenThread;
|
||||
CMOOSThread m_FsmThread;
|
||||
long m_lPort;
|
||||
unsigned int m_nReceiveBufferSizeKB;
|
||||
unsigned int m_nSendBufferSizeKB;
|
||||
double m_current_time;
|
||||
unsigned int m_faultNum;
|
||||
unsigned int m_ticker;
|
||||
|
||||
public:
|
||||
//===========================状态机实现==============================================
|
||||
void printState(FSM_State st, string desp);
|
||||
protected:
|
||||
//===========================交互状态变量==================================
|
||||
Driver m_driver; //设备驱动
|
||||
pmState m_pmCurrentState; //能源系统的当前状态
|
||||
disSysBreakerList m_currentDisBreakerState; //配电断路器状态
|
||||
disSysBreakerList m_targetDisBreakerState;
|
||||
DriverTable m_currentDriverState;
|
||||
DriverTable m_MSDriverCmd;
|
||||
DriverTable m_subDisSysCmd;
|
||||
DriverTable m_subDisSysState;
|
||||
//===========================================================================
|
||||
//系统运行状态
|
||||
unsigned char workCondition;
|
||||
unsigned char currentMod;
|
||||
unsigned char powerState;
|
||||
unsigned char falutLevel;
|
||||
vector<unsigned int> faultCode;
|
||||
unsigned int soc;
|
||||
unsigned int sustainableTime;
|
||||
|
||||
// 配电和CCU的反馈状态
|
||||
msg_CcuStateFbMsg m_CcuCurrentState;
|
||||
msg_disHighVolBusFbMsg m_disHighVolBusCurrentState;
|
||||
msg_disHighAVolBusFbMsg m_disHighAVolBusCurrentState;
|
||||
msg_disHighBVolBusFbMsg m_disHighBVolBusCurrentState;
|
||||
msg_disLowBusFbMsg m_disLowBusState;
|
||||
|
||||
//下位机操作函数
|
||||
ccuColCmd m_CcuColCmd;
|
||||
void disSysOption();
|
||||
void ccuOption();
|
||||
|
||||
char getBreakerOption(char cmd);
|
||||
void initControlCmd();
|
||||
|
||||
//上位机操作函数
|
||||
MSControlCmd m_msCmd;
|
||||
bool buildPowerSysReport();
|
||||
bool getMsCmdFromJson(MSControlCmd &cmd,const string &strJson);
|
||||
|
||||
private:
|
||||
udpComm m_udpComm;
|
||||
XPCUdpSocket *m_pCcuUdpComm;
|
||||
CMOOSThread m_ListenThread;
|
||||
CMOOSThread m_FsmThread;
|
||||
long m_lPort;
|
||||
unsigned int m_nReceiveBufferSizeKB;
|
||||
unsigned int m_nSendBufferSizeKB;
|
||||
double m_current_time;
|
||||
unsigned int m_faultNum;
|
||||
unsigned int m_ticker;
|
||||
|
||||
// 状态机实例
|
||||
PowerManagerFsm m_fsm;
|
||||
|
||||
public:
|
||||
//===========================状态机接口=======================================
|
||||
void printState(const std::string& stateName, const std::string& desp);
|
||||
bool FSM_RUN_IS_OK = true;
|
||||
|
||||
StateData m_stateData;
|
||||
FSM_State m_pmState; //当前状态
|
||||
string m_pmEvent;
|
||||
FSM m_fsm;
|
||||
|
||||
//初始化状态
|
||||
FSM_State m_Inite_s1;
|
||||
static int handleInite_s1(FSM_State &fsm, void* pData);
|
||||
|
||||
//待机状态
|
||||
FSM_State m_Standby_s2;
|
||||
static int handleStandby_s2(FSM_State &fsm, void* pData);
|
||||
|
||||
//岸基备航
|
||||
// FSM_State m_ShoreReady_s3;
|
||||
|
||||
//水中备航
|
||||
|
||||
//自动工况
|
||||
|
||||
//故障处理
|
||||
FSM_State m_Fault_s99;
|
||||
static int handleFault_s99(FSM_State &fsm, void* pData);
|
||||
//======================================================================================
|
||||
int checkError();
|
||||
bool shutdown();
|
||||
bool powerOn();
|
||||
bool powerOff();
|
||||
|
||||
// 初始化状态机
|
||||
void initFsm() {
|
||||
m_fsm.init(this);
|
||||
}
|
||||
|
||||
// 状态机事件触发接口
|
||||
void triggerInitEvent() { m_fsm.triggerInitEvent(); }
|
||||
void triggerStandbyEvent() { m_fsm.triggerStandbyEvent(); }
|
||||
void triggerFaultEvent(unsigned int faultCode) { m_fsm.triggerFaultEvent(faultCode); }
|
||||
//==================================================================================
|
||||
int checkError();
|
||||
bool shutdown();
|
||||
bool powerOn();
|
||||
bool powerOff();
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user