/* * @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 #define JSON_USE_EXCEPTION 1 #include #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 "PowerManagerFsm.hpp" #include "SQLiteDB.h" #include "driver.h" #include "LowerCommManager.h" #include "UpperCommManager.h" #define IPORT 5000 #define CCUPORT 5001 #define CCUHOST "127.0.0.1" #define MAX_UDP_PKT_SIZE 65535 #define SKEW_TOLERANCE 5 class PowerManger : public AppCastingMOOSApp { public: PowerManger(); ~PowerManger(); public: bool FsmLoop(); protected: // Standard MOOSApp functions to overload bool OnNewMail(MOOSMSG_LIST &NewMail); bool Iterate(); bool OnConnectToServer(); bool OnStartUp(); bool buildReport(); void registerVariables(); public: void updateTime(){m_current_time = MOOSTime();} //数据库 SQLiteDB* m_db; bool writeDataToDB(); /************************************************************/ /* |<------------FEEDBACK--------<-- */ /* | | */ /* IN-->+-------[STATE CONTROL]---------+--->OUT */ /* */ /************************************************************/ public: //===========================IN============================================ DriverTable m_MSDriverCmd; MSControlCmd m_msCmd; //===========================OUT=========================================== DriverTable m_subDisSysCmd; ccuColCmd m_CcuColCmd; disSysBreakerList m_targetDisBreakerState; //===========================FEEDBACK====================================== pmState m_pmCurrentState; //能源系统的当前状态 disSysBreakerList m_currentDisBreakerState; //配电断路器状态 DriverTable m_currentDriverState; DriverTable m_subDisSysState; int m_depth; int m_missionCode; //===========================STATE========================================= unsigned char workCondition; unsigned char currentMod; unsigned char powerState; unsigned char falutLevel; vector faultCode; unsigned int soc; unsigned int sustainableTime; unsigned int m_faultNum; Driver m_driver; //设备表处理 std::string m_pmEvent; // 状态机事件描述 //===========================CONFIG======================================== long m_lPort; unsigned int m_nReceiveBufferSizeKB; unsigned int m_nSendBufferSizeKB; double m_current_time; unsigned int m_ticker; int connectState; //=============================过程函数====================================== void initControlCmd(); private: // CMOOSThread m_FsmThread; LowerCommManager* m_lowerCommManager; UpperCommManager* m_upperCommManager; // // 状态机实例 // PowerManagerFsm m_fsm; public: //===========================状态机接口======================================= void printState(const std::string& stateName, const std::string& desp); bool FSM_RUN_IS_OK = true; //================================================================================== int checkError(); bool shutdown(); bool powerOn(); bool powerOff(); bool sendNotification(const std::string& key, const std::string& value) { return Notify(key, value); } }; #endif