From a0b81882b4a9b7761e2dbfdda37b7559714c416c Mon Sep 17 00:00:00 2001 From: ToshikazuOhiwa Date: Mon, 30 Mar 2020 09:41:01 +0900 Subject: ss-powerservice branch --- power_service/server/include/ss_power.h | 318 ++++++++++++++++ power_service/server/include/ss_power_config.h | 147 ++++++++ .../server/include/ss_power_powerservicelog.h | 85 +++++ power_service/server/include/ss_power_session.h | 70 ++++ .../server/include/ss_power_state_hysteresis.h | 74 ++++ .../server/include/ss_power_state_machine.h | 414 +++++++++++++++++++++ 6 files changed, 1108 insertions(+) create mode 100644 power_service/server/include/ss_power.h create mode 100644 power_service/server/include/ss_power_config.h create mode 100644 power_service/server/include/ss_power_powerservicelog.h create mode 100644 power_service/server/include/ss_power_session.h create mode 100644 power_service/server/include/ss_power_state_hysteresis.h create mode 100644 power_service/server/include/ss_power_state_machine.h (limited to 'power_service/server/include') diff --git a/power_service/server/include/ss_power.h b/power_service/server/include/ss_power.h new file mode 100644 index 00000000..0cec9c0f --- /dev/null +++ b/power_service/server/include/ss_power.h @@ -0,0 +1,318 @@ +/* + * @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_PowerService +/// \brief Handles Power Service Business logic +/// +/////////////////////////////////////////////////////////////////////////////// +#ifndef POWER_SERVICE_SERVER_INCLUDE_SS_POWER_H_ +#define POWER_SERVICE_SERVER_INCLUDE_SS_POWER_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ss_power_session.h" +#include "ss_power_config.h" +#include "ss_power_state_machine.h" +#include "ss_power_powerservicelog.h" + +typedef enum _SS_PSState { + SS_PS_READY_TO_WAKEUP = 0x01, + SS_PS_WAKEUP_INITIATED, + SS_PS_WAKEUP_COMPLETE, + SS_PS_POWER_ON_COMPLETE, + SS_PS_POWER_OFF_INITIATED, + SS_PS_POWER_OFF_COMPLETE, + SS_PS_SHUTDOWN_INITIATED, + SS_PS_SHUTDOWN_COMPLETE + // This is not real state, used only to know total states + , + SS_PS_STATE_MAX +} SS_PSState; + +typedef struct { + std::string m_cmd; + UI_64 m_time; + std::string m_sender; +} Ts_cmdHist; + +typedef std::vector cmdHist; +typedef cmdHist::iterator cmdHistIter; + +class Power { + public: + Power(); + virtual ~Power(); + EFrameworkunifiedStatus Initialize(HANDLE h_app); + static Power & GetInstance(); + + /// Session Request Handlers + EFrameworkunifiedStatus OnOpenSession(HANDLE h_app); + EFrameworkunifiedStatus OnCloseSession(HANDLE h_app); + + /// Session Response\Ack Handlers + EFrameworkunifiedStatus OnWakeUpComplete(HANDLE h_app); + EFrameworkunifiedStatus OnShutdownComplete(HANDLE h_app); + EFrameworkunifiedStatus OnPrintConnections(HANDLE h_app); + EFrameworkunifiedStatus OnPrintStack(HANDLE h_app); + + /// SSM Handlers + + /// Supervisor Handlers + EFrameworkunifiedStatus OnPowerRequestMsg(HANDLE h_app); + EFrameworkunifiedStatus OnSetPowerState(HANDLE h_app); + EFrameworkunifiedStatus OnSetCommWakeUp(HANDLE h_app); + EFrameworkunifiedStatus OnSetCommSleep(HANDLE h_app); + EFrameworkunifiedStatus OnShutdownRequestMsg(HANDLE h_app); + + EFrameworkunifiedStatus OnPowerOnOffNotification(HANDLE h_app); + EFrameworkunifiedStatus OnStartModules(HANDLE h_app); + EFrameworkunifiedStatus OnShutdownModules(HANDLE h_app); + + EFrameworkunifiedStatus OnHysteresisTimeout(HANDLE h_app); + + // System Handlers + EFrameworkunifiedStatus OnSystemLaunchComplete(HANDLE h_app); + EFrameworkunifiedStatus OnSystemShutdownComplete(HANDLE h_app); + EFrameworkunifiedStatus OnWakeUpTimeout(HANDLE h_app); + EFrameworkunifiedStatus OnShutdownTimeout(HANDLE h_app); + + // Get Result query from power test client + EFrameworkunifiedStatus OnCurrentPowerStateQuery(HANDLE h_app); + + EFrameworkunifiedStatus OnSetVoltageState(HANDLE h_app); + EFrameworkunifiedStatus OnSetCrankState(HANDLE h_app); + + EFrameworkunifiedStatus OnSystemModeInfoRequest(HANDLE h_app); + EFrameworkunifiedStatus OnSystemModeInfoResponse(HANDLE h_app); + + EFrameworkunifiedStatus OnInitCompReport(HANDLE h_app); + + EFrameworkunifiedStatus OnSystemMgrConnectionEstablished(HANDLE h_app); + + // + // Start Confirmation callback functions + // + EFrameworkunifiedStatus OnSendStartupConfirmationRequest(HANDLE h_app); + EFrameworkunifiedStatus OnSendStartupConfirmationResponse(HANDLE h_app); + + // + // User Mode Protocol callback functions + // + EFrameworkunifiedStatus OnUserModeResponse(HANDLE h_app); + + // + // Shutdown Condition Notification Protocol function + // + EFrameworkunifiedStatus OnPublishShutdownPopupRequest(HANDLE h_app); + + // + // Power Popup Notification Protocol function + // + EFrameworkunifiedStatus OnPublishPowerPopupRequest(HANDLE h_app); + + // + // HeartBeat Protocol callback functions + // + EFrameworkunifiedStatus On_CWORD56_HeartBeatRequest(HANDLE h_app); + EFrameworkunifiedStatus OnSM_CWORD56_HeartBeatResponse(HANDLE h_app); + + // + // Hard Reset Protocol callback functions + // + EFrameworkunifiedStatus OnCpuResetRequest(HANDLE h_app); + + // + // Remote Data Reset Protocol callback functions + // + EFrameworkunifiedStatus OnRemoteDataResetRequest(HANDLE h_app); + EFrameworkunifiedStatus OnRemoteDataResetResponse(HANDLE h_app); + + cmdHist m__CWORD56_RepHist; + cmdHistIter m__CWORD56_RepIter; + cmdHist m_PubCmdHist; + cmdHistIter m_PubHistIter; + cmdHist m_ErrHist; + cmdHistIter m_ErrHistIter; + cmdHist m_VCmdHist; + cmdHistIter m_VHistIter; + + void SSPowerDebugDump(HANDLE h_app); + + private: +#define LOG_POWERSERVICELOG_CNT(caseid, Cnt) \ + FRAMEWORKUNIFIEDLOG_CNT(ZONE_INFO, Cnt, 0); \ + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " case " #caseid \ + ": FRAMEWORKUNIFIEDLOG_CNT(ZONE_INFO, " #Cnt ", 0)"); + +#define LOG_POWERSERVICELOG_EVT(caseid, Evt, Data0) \ + FRAMEWORKUNIFIEDLOG_EVT(ZONE_INFO, Evt, 1, Data0); \ + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " case " #caseid \ + ": FRAMEWORKUNIFIEDLOG_EVT(ZONE_INFO, " #Evt ", " #Data0 ")"); + +#define LOG_STATUS_IF_ERRORED_PWR_SM_WITH_HIST_LOGGING(l_eStatus, pStr) \ + if (eFrameworkunifiedStatusOK != l_eStatus) { \ + LOG_ERROR(pStr); \ + SetCmdHist(pStr, m_ErrHist, m_ErrHistIter, GetStr(static_cast(l_eStatus)).c_str()); \ + } // End of #define LOG_STATUS_IF_ERRORED(l_eStatus,pStr) + +#define SS_PWR_LOG_HIST(cmd, hist, it, sender, l_eStatus) \ + if (eFrameworkunifiedStatusOK == l_eStatus) { \ + SetCmdHist((static_cast< std::string> (cmd)), (static_cast (hist)), \ + (static_cast (it)), (static_cast< std::string> (sender))); \ + } + //************************************************************************** + // Counter Logging enums & typedefs * + // * + // Counter Event IDs * + typedef enum { // * + CT_Startup_CanSignal = 0x0114, // * + CT_Startup_DiagMsg = 0x0118, // * + // * + CT_Shutdown_CanSignal = 0x0121, // * + CT_Shutdown_Timeout = 0x0124, // * + CT_Shutdown_Temperature = 0x0125, // * + CT_Shutdown_Error = 0x0126, // * + CT_Shutdown_Voltage = 0x0127 // * + } EPWR_COUNTER_EVENT_ID_TYPE; // * + // * + // End of Counter Logging enums & typedefs * + //************************************************************************** + + //************************************************************************** + // Event Logging enums & typedefs * + // * + // Event ID * + typedef enum { // * + // Startup Event IDs * + Ei_StartUp_Cansignal = 0x0101, // * + Ei_StartUp_HK_On = 0x0102, // * + // 0x0103 not specified // * + // 0x0104 not specified // * + // 0x0105 System Svcs not responsible// * + // 0x0106 not specified // * + Ei_StartUp_ActivationLine = 0x0107, // * + Ei_StartUp_DiagMsg = 0x0108, // * + // * + // Shutdown Event IDs * + Ei_shutdown_CANsignal = 0x0201, // * + Ei_shutdown_HkOFF = 0x0202, // * + // 0x0203 not specified // * + // 0x0204 not specified // * + Ei_shutdown_Temperature = 0x0205, // * + Ei_shutdown_NetworkError = 0x0206, // * + Ei_shutdown_Voltage = 0x0207 // * + } EPWR_LOGGING_EVENT_ID_TYPE; // * + // * + // Ei_StartUp_CanSignal byte0 Event Detail * + typedef enum { // * + epseisuedIGNITION = 0x00, // * + epseisuedHK_ON = 0x01, // * + epseisuedDOOR_MODULES = 0x02, // * + // 0x03 not specified // * + // 0x04 not specified // * + epseisuedPASS = 0x05, // * + epseisuedIHTM = 0x06, // * + epseisuedMPM = 0x07, // * + epseisuedSNA = 0xFF // * + } EPWR_LOGGING_EVT_DETAIL_SU_CAN_TYPE; // * + + // + // Ei_StartUp_HkOn + typedef enum { + epseisuedHK_ON_Key = 0x00 + } EPWR_LOGGING_EVT_DETAIL_SU_KEY_TYPE; + + // + // Ei_StartUp_ActivationLine + typedef enum { + epseisuedACV_LINE = 0x00 + } EPWR_LOGGING_EVT_DETAIL_SU_LINE_TYPE; + + // * + // Ei_StartUp_DiagMsg byte0 Event Detail * + typedef enum { // * + epseisuedHU = 0x01, // * + epseisuedCAN = 0x02, // * + } EPWR_LOGGING_EVT_DETAIL_SU_DIAG_TYPE; // * + // * + // Ei_ShutDown_CanSignal byte0 Event Detail * + typedef enum { // * + epseisdcsIGN_STATE = 0x00, // * + epseisdcsHK_ON = 0x01 // * + } EPWR_LOGGING_EVT_DETAIL_SD_CAN_TYPE; // * + // * + // Ei_ShutDown_Temperature byte0 Event Detail * + typedef enum { // * + epseisdtempECU_LOW = 0x00, // * + epseisdtempECU_HIGH = 0x01, // * + } EPWR_LOGGING_EVT_DETAIL_SD_TEMP_TYPE; // * + // * + // Ei_ShutDown_NetworkError byte0 Event Detail * + typedef enum { // * + epseisdneHMI_CAN = 0x00, // * + epseisdneHU_CAN = 0x01 // * + } EPWR_LOGGING_EVT_DETAIL_SD_NETWORK_ERROR_TYPE; // * + // * + // Ei_ShutDown_Voltage byte0 Event Detail * + typedef enum { // * + epseisdnvoltBATTERY_CUT_OFF = 0x00, // * + epseisdnvoltLIMP_HOME = 0x01, // * + epseisdnvoltUNKNOWN = 0xFF // * + } EPWR_LOGGING_EVT_DETAIL_SD_VOLTAGE_TYPE; // * + // * + // End of Event Logging enums & typedefs * + //************************************************************************** + + PowerSessionHandler m_oSessionHandler; + PowerConfigParams m_tConfigData; + PowerStateMachine m_oStateMachine; + UI_32 m_aTimerIDs[15]; + wakeInfo m_WakeUpData; /// WakeUp data received from SPM + SS_PSState m_PowerState; + ePowerSrvVoltageStates m_VoltageState; + ePowerSrvCrankStates m_CrankState; + UI_32 m_MaxShutdownTimeout; + std::map m_PPStateStrMap; + + // Notify Module on Voltage change detected. + EFrameworkunifiedStatus PublishVoltageStateChange(HANDLE h_app); + EFrameworkunifiedStatus ConstructPwrStateResponse(CHAR *f_MessageResponse); + EFrameworkunifiedStatus AddStateInformationToResponse(CHAR *f_MessageResponse); + EFrameworkunifiedStatus AddVoltageInformationToResponse(CHAR *f_MessageResponse); + EFrameworkunifiedStatus AddCrankInformationToResponse(CHAR *f_MessageResponse); + EFrameworkunifiedStatus RegisterAllCallbacksAndNofitications(HANDLE h_app); + VOID SetPowerServiceState(SS_PSState f_NewState); + EFrameworkunifiedStatus ValidateUserModeMessage(HANDLE h_app, + EPWR_USER_MODE_TYPE &l_eUserModeState); // NOLINT (runtime/references) + + pthread_mutex_t pwr_hist_mutex; + + void SetCmdHist(std::string cmd, + cmdHist &hist, // NOLINT (runtime/references) + cmdHistIter &it, // NOLINT (runtime/references) + std::string sender); +}; + +#endif // POWER_SERVICE_SERVER_INCLUDE_SS_POWER_H_ diff --git a/power_service/server/include/ss_power_config.h b/power_service/server/include/ss_power_config.h new file mode 100644 index 00000000..d73a41b4 --- /dev/null +++ b/power_service/server/include/ss_power_config.h @@ -0,0 +1,147 @@ +/* + * @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_PowerService +/// \brief This file supports power service configuration. +/// +/////////////////////////////////////////////////////////////////////////////// +#ifndef POWER_SERVICE_SERVER_INCLUDE_SS_POWER_CONFIG_H_ +#define POWER_SERVICE_SERVER_INCLUDE_SS_POWER_CONFIG_H_ + + +#include +#include +#include +#include +#include +#include "ss_power_powerservicelog.h" + +typedef std::list RequiredModuleList; +typedef RequiredModuleList::iterator RequiredModuleListIter; + +#define SS_PWR__CWORD56__REP_HIST_SIZE (10u) +#define SS_PWR_PUB_CMD_HIST_SIZE (5u) +#define SS_PWR_ERR_HIST_SIZE (5u) +#define SS_PWR_V_HIST_SIZE (10u) +#define SS_PWR_DEBUG_DUMP_MAX_SIZE (4096u) + +typedef struct _PowerConfigParams { // NOLINT (readability/naming) // LCOV_EXCL_BR_LINE 14:it will be called when poweron + typedef struct { + SI_32 timeout; + struct { + BOOL enabled; + SI_32 timeout; + SI_32 tries; + } hysteresis; + } PowerOffInfo; + + SS_String power_logic_plugin; + PowerOffInfo lvi1; + PowerOffInfo lvi2; + PowerOffInfo shutdown; + RequiredModuleList wakeup_modules; + RequiredModuleList shutdown_modules; + RequiredModuleList lvi2_modules; +} PowerConfigParams; + +class PowerConfiguration { + public: + // define all the configuration parmeters that will be used to get data + static const char * kPowerLogicPlugin; + static const char * kLVI1Timeout; + static const char * kLVI1HysteresisTimeout; + static const char * kLVI1HysteresisEnabled; + static const char * kLVI1HysteresisTries; + static const char * kLVI2Timeout; + static const char * kLVI2HysteresisTimeout; + static const char * kLVI2HysteresisEnabled; + static const char * kLVI2HysteresisTries; + static const char * kShutdownTimeout; + static const char * kShutdownHysteresisTimeout; + static const char * kShutdownHysteresisEnabled; + static const char * kShutdownHysteresisTries; + + /// < defines the names in the xml file that are used to get required modules names + static const char * kRequiredWakeupModules; /// < once all the modules have been wakened up send wake-up complete + static const char * kRequiredShutdownModules; /// < once all the modules have been shutdown send shutdown complete + static const char * kRequiredLvi2Modules; /// < once all the modules have been wakened up send wake-up complete + + //////////////////////////////////////////////////////////////////////////////////////////// + /// PowerConfiguration + /// \brief Here it is checked whether the new connection is to be connected or not, if yes then whether the old + /// connection is to be disconnected or to be paused or to be played simultaneously. + /// + /// \param [in] f_configFileName Configuration file name. + /// + /// \return NA + /// + //////////////////////////////////////////////////////////////////////////////////////////// + explicit PowerConfiguration(std::string f_configfilename); + + //////////////////////////////////////////////////////////////////////////////////////////// + /// ~PowerConfiguration + /// \brief Here it is checked whether the new connection is to be connected or not, if yes then whether the old + /// connection is to be disconnected or to be paused or to be played simultaneously. + /// + /// \param [in] pRequestingSrc + /// Source* - Pointer to the requesting source. + /// + /// \return bool + /// bool - TRUE or FALSE + //////////////////////////////////////////////////////////////////////////////////////////// + virtual ~PowerConfiguration(); + + //////////////////////////////////////////////////////////////////////////////////////////// + /// LoadParameters + /// \brief Load module parameters from configuration file. + /// + /// \param [in] params - Ref to variable which to store the loaded module parameters. + /// + /// \return bool + /// bool - TRUE or FALSE + //////////////////////////////////////////////////////////////////////////////////////////// + BOOL LoadParameters(PowerConfigParams & params); // NOLINT (runtime/references) + + //////////////////////////////////////////////////////////////////////////////////////////// + /// LoadDefaultParameters + /// \brief Laod default power services parameters. + /// + /// \param [in] params - Ref to variable for which to store the default module parameters. + /// + /// \return none + //////////////////////////////////////////////////////////////////////////////////////////// + void LoadDefaultParameters(PowerConfigParams & params); // NOLINT (runtime/references) + + //////////////////////////////////////////////////////////////////////////////////////////// + /// PrintConfigInfo + /// \brief Print configuration information. + /// + /// \param [in] params - Ref to variable containing the configuration parameters to load.params + /// + /// \return none. + //////////////////////////////////////////////////////////////////////////////////////////// + void PrintConfigInfo(PowerConfigParams & f_params); // NOLINT (runtime/references) + + protected: + PowerConfiguration(const PowerConfiguration &); + PowerConfiguration & operator =(const PowerConfiguration &); // NOLINT (runtime/references) + + private: + std::string m_ConfigFileName; +}; + +#endif // POWER_SERVICE_SERVER_INCLUDE_SS_POWER_CONFIG_H_ diff --git a/power_service/server/include/ss_power_powerservicelog.h b/power_service/server/include/ss_power_powerservicelog.h new file mode 100644 index 00000000..0269d9a5 --- /dev/null +++ b/power_service/server/include/ss_power_powerservicelog.h @@ -0,0 +1,85 @@ +/* + * @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_PowerService +/// \brief This file supports 002 application logging. +/// +/////////////////////////////////////////////////////////////////////////////// +#ifndef POWER_SERVICE_SERVER_INCLUDE_SS_POWER_POWERSERVICELOG_H_ +#define POWER_SERVICE_SERVER_INCLUDE_SS_POWER_POWERSERVICELOG_H_ +#include + +#define ZONE_INIT ZONEMASK(10) +#define ZONE_FUNC ZONEMASK(11) +#define ZONE_MEM ZONEMASK(12) +#define ZONE_FUNC_IPC ZONEMASK(13) +#define ZONE_POWER_MONITOR ZONEMASK(14) +#define ZONE_POWER_STATEMACHINE ZONEMASK(15) +#define ZONE_16 ZONEMASK(16) +#define ZONE_17 ZONEMASK(17) +#define ZONE_18 ZONEMASK(18) +#define ZONE_19 ZONEMASK(19) +#define ZONE_20 ZONEMASK(20) +#define ZONE_21 ZONEMASK(21) +#define ZONE_22 ZONEMASK(22) +#define ZONE_23 ZONEMASK(23) +#define ZONE_24 ZONEMASK(24) +#define ZONE_25 ZONEMASK(25) +#define ZONE_26 ZONEMASK(26) +#define ZONE_27 ZONEMASK(27) +#define ZONE_INFO_IPC ZONEMASK(28) +#define ZONE_INFO ZONEMASK(29) + +#define ZONE_TEXT_10 "Init" +#define ZONE_TEXT_11 "Function" +#define ZONE_TEXT_12 "Memory" +#define ZONE_TEXT_13 "Ipc Function" +#define ZONE_TEXT_14 "" +#define ZONE_TEXT_15 "Power StateMachine" +#define ZONE_TEXT_16 "" +#define ZONE_TEXT_17 "" +#define ZONE_TEXT_18 "" +#define ZONE_TEXT_19 "" +#define ZONE_TEXT_20 "" +#define ZONE_TEXT_21 "" +#define ZONE_TEXT_22 "" +#define ZONE_TEXT_23 "" +#define ZONE_TEXT_24 "" +#define ZONE_TEXT_25 "" +#define ZONE_TEXT_26 "" +#define ZONE_TEXT_27 "" +#define ZONE_TEXT_28 "Ipc Info" +#define ZONE_TEXT_29 "Info" +// These ARE RESERVED AND SHOULDN'T BE TOUCHED +// USE THEM WHEN REALLY NEEDED!!!!! +#define ZONE_TEXT_30 "Warning" +#define ZONE_TEXT_31 "Error" +#define ZONE_WARN ZONEMASK(30) +#define ZONE_ERR ZONEMASK(31) +#define ALL_ZONES_BUT_IPC_INFO 0xEFFFFFFF + +#ifndef FRAMEWORKUNIFIEDLOGOPTIONS +#define FRAMEWORKUNIFIEDLOGOPTIONS (LMSGQ) // LPRINT , LMSGQ, LSLOGGER +#endif + +#ifndef FRAMEWORKUNIFIEDLOGAPPZONES +#define FRAMEWORKUNIFIEDLOGAPPZONES ZONE_WARN, ZONE_ERR //, ZONE_INFO,ZONE_POWER_STATEMACHINE, ZONE_DEBUG_DUMP, ZONE_FUNC +#endif /* FRAMEWORKUNIFIEDLOGAPPZONES */ + +extern const CHAR AppName[]; // NOLINT (readability/naming) + +#endif // POWER_SERVICE_SERVER_INCLUDE_SS_POWER_POWERSERVICELOG_H_ diff --git a/power_service/server/include/ss_power_session.h b/power_service/server/include/ss_power_session.h new file mode 100644 index 00000000..ae9788f9 --- /dev/null +++ b/power_service/server/include/ss_power_session.h @@ -0,0 +1,70 @@ +/* + * @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_PowerService +/// \brief This file supports power service session management. +/// +/////////////////////////////////////////////////////////////////////////////// +#ifndef POWER_SERVICE_SERVER_INCLUDE_SS_POWER_SESSION_H_ +#define POWER_SERVICE_SERVER_INCLUDE_SS_POWER_SESSION_H_ + +#include +#include +#include +#include +#include "ss_power_config.h" + +typedef std::string SubscriberName; // The name of the module that is trying to open a session with Power + +/* + * + */ +class PowerSessionHandler { + public: + PowerSessionHandler(); + virtual ~PowerSessionHandler(); + EFrameworkunifiedStatus OpenSesion(HANDLE h_app); + EFrameworkunifiedStatus CloseSession(HANDLE h_app); + EFrameworkunifiedStatus StartComplete(HANDLE h_app); + EFrameworkunifiedStatus StopComplete(HANDLE h_app); + + VOID Print(); + + // Methods that do the heavy lifting + BOOL WakeupComplete(RequiredModuleList & wakeup_modules); // NOLINT (runtime/references) + BOOL ShutdownComplete(RequiredModuleList & shutdown_modules); // NOLINT (runtime/references) + EFrameworkunifiedStatus SendToSupervisor(UI_32 cmd, UI_32 length, PVOID data); + BOOL AllClientsInGroupStarted(UI_32 f_ungrpid); + BOOL ClientPresent(PCSTR f_sclientname); + + private: + struct PwSessionInfo { + std::string sz_name; + std::string sz_servicename; + HANDLE hsession; + BOOL frunning; + EPWR_SESSION_TYPE esessiontype; + UI_32 ui_groupid; + }; + + typedef std::map PwSessionMap; + typedef PwSessionMap::iterator PwSessionIter; + + PwSessionMap m_mapSessions; +}; + +#endif // POWER_SERVICE_SERVER_INCLUDE_SS_POWER_SESSION_H_ diff --git a/power_service/server/include/ss_power_state_hysteresis.h b/power_service/server/include/ss_power_state_hysteresis.h new file mode 100644 index 00000000..8220789c --- /dev/null +++ b/power_service/server/include/ss_power_state_hysteresis.h @@ -0,0 +1,74 @@ +/* + * @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_PowerService +/// \brief This file supports power service hysteresis management. +/// +/////////////////////////////////////////////////////////////////////////////// +#ifndef POWER_SERVICE_SERVER_INCLUDE_SS_POWER_STATE_HYSTERESIS_H_ +#define POWER_SERVICE_SERVER_INCLUDE_SS_POWER_STATE_HYSTERESIS_H_ + +#include "ss_power_config.h" + +class PowerStateHysteresis { + public: + PowerStateHysteresis() + : m_unTries(0) { + bzero(&m_tHysteresisInfo, sizeof(m_tHysteresisInfo)); + } + + virtual ~PowerStateHysteresis() { // LCOV_EXCL_START 14: do it when power off + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + m_unTries = 0; + } + // LCOV_EXCL_STOP 14: do it when power off + explicit PowerStateHysteresis(PowerConfigParams::PowerOffInfo & info) // NOLINT (runtime/references) + : m_unTries(0), + m_tHysteresisInfo(info) { + } + void set(PowerConfigParams::PowerOffInfo & info) { // NOLINT (runtime/references) + m_tHysteresisInfo = info; + } + BOOL getEnabled() const { + return m_tHysteresisInfo.hysteresis.enabled; + } + UI_32 getTimeout() const { + return m_tHysteresisInfo.hysteresis.timeout; + } + UI_32 getTries() const { + return m_tHysteresisInfo.hysteresis.tries; + } + + void clearTryCounter() { + m_unTries = 0; + } + void bumbTryCounter() { + m_unTries++; + } + BOOL maxTries() const { + if (m_unTries < getTries()) + return FALSE; + else + return TRUE; + } + + private: + UI_32 m_unTries; + PowerConfigParams::PowerOffInfo m_tHysteresisInfo; +}; + +#endif // POWER_SERVICE_SERVER_INCLUDE_SS_POWER_STATE_HYSTERESIS_H_ diff --git a/power_service/server/include/ss_power_state_machine.h b/power_service/server/include/ss_power_state_machine.h new file mode 100644 index 00000000..fb5b7c33 --- /dev/null +++ b/power_service/server/include/ss_power_state_machine.h @@ -0,0 +1,414 @@ +/* + * @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_PowerService +/// \brief This file supports the power service state machine. +/// +/////////////////////////////////////////////////////////////////////////////// +#ifndef POWER_SERVICE_SERVER_INCLUDE_SS_POWER_STATE_MACHINE_H_ +#define POWER_SERVICE_SERVER_INCLUDE_SS_POWER_STATE_MACHINE_H_ + +#include +#include "ss_power_state_hysteresis.h" + +class PowerSessionHandler; + +class PowerStateMachine { + class Base_State { + public: + virtual void onWakeup(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession) { // NOLINT (runtime/references) + } + virtual void onStartComplete(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + virtual void onLaunchComplete(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + + // LCOV_EXCL_START 200: virtual function + virtual void onShutdown(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession) { // NOLINT (runtime/references) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + } + // LCOV_EXCL_STOP 200: virtual function + virtual void onStopComplete(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + virtual void onShutdownComplete(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + + // LCOV_EXCL_START 200: virtual function + virtual void onNormalVoltageEncountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession) { // NOLINT (runtime/references) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + } + // LCOV_EXCL_STOP 200: virtual function + + // LCOV_EXCL_START 200: virtual function + virtual void onLowVoltage1Encountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession) { // NOLINT (runtime/references) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + } + // LCOV_EXCL_STOP 200: virtual function + + // LCOV_EXCL_START 200: virtual function + virtual void onLowVoltage2Encountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession) { // NOLINT (runtime/references) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + } + // LCOV_EXCL_STOP 200: virtual function + + // LCOV_EXCL_START 200: virtual function + virtual void onSoftwareUpdate(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession) { // NOLINT (runtime/references) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + } + // LCOV_EXCL_STOP 200: virtual function + + // LCOV_EXCL_START 200: virtual function + virtual void onHysteresisAborted(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession) { // NOLINT (runtime/references) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + } + // LCOV_EXCL_STOP 200: virtual function + + // LCOV_EXCL_START 200: virtual function + virtual void onHysteresisTimeout(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession) { // NOLINT (runtime/references) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + } + // LCOV_EXCL_STOP 200: virtual function + virtual PCSTR name() = 0; + + /// State Entry and Exit methods + + // LCOV_EXCL_START 200: virtual function + virtual void onEntry(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession) { // NOLINT (runtime/references) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + } + // LCOV_EXCL_STOP 200: virtual function + + // LCOV_EXCL_START 200: virtual function + virtual void onExit(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession) { // NOLINT (runtime/references) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + } + // LCOV_EXCL_STOP 200: virtual function + }; + + friend class Base_State; + + class Wakeup : public Base_State { + public: + void onWakeup(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onShutdown(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onNormalVoltageEncountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onLowVoltage1Encountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onLowVoltage2Encountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onSoftwareUpdate(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + virtual PCSTR name(); + + // LCOV_EXCL_START 8: fist status, no entry + void onEntry(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession) { // NOLINT (runtime/references) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + } + // LCOV_EXCL_STOP 8: fist status, no entry + void onExit(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession) { // NOLINT (runtime/references) + } + }; + + friend class Wakeup; + + class WakeupActive : public Wakeup { + public: + void onShutdown(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onLowVoltage1Encountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onLowVoltage2Encountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + PCSTR name(); + + void onEntry(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession) { // NOLINT (runtime/references) + } + void onExit(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession) { // NOLINT (runtime/references) + } + }; + + friend class WakeupActive; + + class WakeupPending : public Wakeup { + public: + void onWakeup(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onStartComplete(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onLaunchComplete(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + + void onNormalVoltageEncountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + PCSTR name(); + + void onEntry(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onExit(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession) { // NOLINT (runtime/references) + } + }; + + friend class WakeupPending; + + class Shutdown : public Base_State { + public: + void onWakeup(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onShutdown(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession) { // NOLINT (runtime/references) + } + void onLowVoltage1Encountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onLowVoltage2Encountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onHysteresisAborted(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onHysteresisTimeout(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + PCSTR name(); + + void onEntry(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onExit(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + }; + + friend class Shutdown; + + class ShutdownActive : public Base_State { + public: + void onShutdown(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onLowVoltage1Encountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onLowVoltage2Encountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + PCSTR name(); + + void onEntry(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + }; + + friend class ShutdownActive; + + class LowVoltage1 : public Base_State { + public: + void onWakeup(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onNormalVoltageEncountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onLowVoltage2Encountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onHysteresisAborted(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onHysteresisTimeout(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + PCSTR name(); + + void onEntry(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onExit(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + }; + + friend class LowVoltage1; + + class LowVoltage1Active : public Base_State { + public: + void onNormalVoltageEncountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onLowVoltage2Encountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + PCSTR name(); + + void onEntry(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onExit(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + }; + + friend class LowVoltage1Active; + + class LowVoltage2 : public Base_State { + public: + void onWakeup(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onNormalVoltageEncountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onLowVoltage1Encountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onHysteresisAborted(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onHysteresisTimeout(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + PCSTR name(); + + void onEntry(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onExit(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + }; + + friend class LowVoltage2; + + class LowVoltage2Active : public Base_State { + public: + void onNormalVoltageEncountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onLowVoltage1Encountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + PCSTR name(); + + void onEntry(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onExit(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + }; + + friend class LowVoltage2Active; + + class NormalVoltage : public Base_State { + public: + void onShutdown(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onLowVoltage1Encountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onLowVoltage2Encountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onSoftwareUpdate(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + PCSTR name(); + + void onEntry(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + }; + + friend class NormalVoltage; + + class SoftwareUpdate : public Base_State { + public: + void onShutdown(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onLowVoltage1Encountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onLowVoltage2Encountered(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + PCSTR name(); + + void onEntry(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void onExit(PowerStateMachine &u, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + }; + + friend class SoftwareUpdate; + + public: + typedef enum _Power_State_Machine_Events { + epsmeWAKEUP = epswsPWRON, + epsmeSHUTDOWN = epscnCANSLEEP, + epsmeLVI1_ENCOUNTERED = epsvsLVI1, + epsmeLVI2_ENCOUNTERED = epsvsLVI2, + epsmeNORMAL_VOLTAGE_ENCOUNTERED = epsvsNORMAL, + epsmeSTART_COMPLETE = 0xD1, + epsmeSTOP_COMPLETE = 0xD2, + epsmeSOFTWARE_UPDATE = 0xE1, + epsmeSHUTDOWN_HYSTERESIS_ABORTED = 0xF1, + epsmeLVI1_HYSTERESIS_ABORTED = 0xF2, + epsmeLVI2_HYSTERESIS_ABORTED = 0xF3, + epsmeSHUTDOWN_HYSTERESIS_TM_OUT = 0xFA, + epsmeLVI1_HYSTERESIS_TM_OUT = 0xFB, + epsmeLVI2_HYSTERESIS_TM_OUT = 0xFC, + } ePowerStateMachineEvents; + + PowerStateMachine(); + virtual ~PowerStateMachine(); + void onEvent(HANDLE h_app, PowerSessionHandler & oSession, // NOLINT (runtime/references) + ePowerStateMachineEvents evt); + EFrameworkunifiedStatus initialize(HANDLE h_app, PowerConfigParams & refConfigParms); // NOLINT (runtime/references) + PCSTR name(); + + private: + static Wakeup WakeupState; + static WakeupActive WakeupActiveState; + static WakeupPending WakeupPendingState; + static LowVoltage1 LowVoltage1State; + static LowVoltage1Active LowVoltage1ActiveState; + static LowVoltage2 LowVoltage2State; + static LowVoltage2Active LowVoltage2ActiveState; + static Shutdown ShutdownState; + static ShutdownActive ShutdownActiveState; + static NormalVoltage NormalVoltageState; + static SoftwareUpdate SoftwareUpdateState; + + Base_State *m_pCurrentState; + Base_State *m_pPreviousState; + Base_State *m_pOnHysteresisTimeoutState; + PowerStateHysteresis m_oShutdownHysteresis; + PowerStateHysteresis m_oLowVoltage1Hysteresis; + PowerStateHysteresis m_oLowVoltage2Hysteresis; + RequiredModuleList m_lstWakeupModules; + RequiredModuleList m_lstShutdownModules; + RequiredModuleList m_lstLvi2Modules; + HANDLE m_hHysteresisTimer; + + typedef struct _state_info { + EPWR_POWER_STATE_TYPE wake; + EPWR_VOLTAGE_STATE_TYPE voltage; + EPWR_WAKEUP_LEVEL_TYPE level; + EPWR_WAKEUP_FACTOR_TYPE factor; + EPWR_CRANK_STATE_TYPE crank; + } Pwr_StateInfo; + + Pwr_StateInfo m_tStateInfo; + + PowerStateMachine(PowerStateMachine&); + PowerStateMachine & operator=(PowerStateMachine &); + + /// Helper methods + void NextState(Base_State & refState, HANDLE h_app, // NOLINT (runtime/references) + PowerSessionHandler & oSession); // NOLINT (runtime/references) + void GotoStateOnHysteresisTimeout(Base_State & refState); // NOLINT (runtime/references) + void startHysteresisTimer(PowerStateHysteresis & hys_info); // NOLINT (runtime/references) + void reStartHysteresisTimer(PowerStateHysteresis & hys_info); // NOLINT (runtime/references) + void stopHysteresisTimer(PowerStateHysteresis & hys_info); // NOLINT (runtime/references) + void publishPowerLVIStatus(HANDLE h_app, PCSTR nNotifNm, UI_32 value); + void publishPowerLevelType(HANDLE h_app, UI_32 value); + + void OnVoltage(Base_State * pState, HANDLE h_app, + PowerSessionHandler & oSession); // NOLINT (runtime/references) +}; + +#endif // POWER_SERVICE_SERVER_INCLUDE_SS_POWER_STATE_MACHINE_H_ -- cgit 1.2.3-korg