/* * @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 "logc/loguru.hpp" #include "MOOS/libMOOS/Thirdparty/AppCasting/AppCastingMOOSApp.h" #include "MOOS/libMOOS/Utils/MOOSThread.h" #include "MOOS/libMOOS/Utils/MOOSUtilityFunctions.h" #include "MOOS/libMOOS/Utils/ConsoleColours.h" #include "../udpcomm/ccuUdpMsg.h" #include "json/json.h" #include "udpcomm/udpComm.h" #include "pmSysvariable.h" #include "fsm/PowerManagerFsm.hpp" #include "driver.h" #include "LowerCommManager.h" #include "UpperCommManager.h" #include "sqlit3/SQLite.h" #include "systemData.h" #include "httpserver/httpserver.h" #include "faultCode.h" #define IPORT 5001 #define CCUPORT 7000 #define CCUHOST "192.168.0.140" // #define CCUHOST "127.0.0.0" #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();} unsigned char getFaultLevel(); //数据库 SQLite* m_db; //http HttpServer* m_httpServer; //系统数据 SystemData* m_systemData; /************************************************************/ /* |<------------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; DriverTable m_subDisSysFault; int m_depth; MissionState m_missionState; //===========================STATE========================================= unsigned char workCondition; unsigned char currentMod; unsigned char powerState; unsigned char faultLevel; vector faultCode; unsigned int soc; unsigned int sustainableTime; unsigned int m_faultNum; Driver m_driver; //设备表处理 unsigned char m_leakage; std::set m_faultCodes; // std::set m_disSysFaultCodes; //============================Device Option================================ std::queue m_deviceCmdQuenue; mutable std::mutex m_deviceCmdMutex; void pushDeviceCommand(DeviceSwitchCmd cmd); bool popDeviceCommand(DeviceSwitchCmd &cmd); bool isDeviceCmdEmpty() const; //===========================CONFIG======================================== long m_lPort; unsigned int m_nReceiveBufferSizeKB; unsigned int m_nSendBufferSizeKB; double m_current_time; unsigned int m_ticker; double m_skew; int connectState; //=============================过程函数====================================== void initControlCmd(); public: // 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 sendNotification(const std::string& key, const std::string& value) { return Notify(key, value); } public: double GetPublicAppFreq() { return GetAppFreq(); } unsigned int GetPublicCommsFreq() { return GetCommsFreq(); } double GetPublicAppStartTime() { return GetAppStartTime(); } double GetPublicCPULoad() { return GetCPULoad(); } double GetPublicTimeSinceIterate() { return GetTimeSinceIterate(); } double GetPublicLastIterateTime() { return GetLastIterateTime(); } int GetPublicIterateCount() { return GetIterateCount(); } string GetServerHost() { return m_sServerHost; } int GetServerPort() { return m_lServerPort; } public: //故障注入 void injectFault(unsigned type,unsigned int faultCode); }; #endif