2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup tag_PowerService
19 /// \brief Handles Power Service Business logic
21 ///////////////////////////////////////////////////////////////////////////////
22 #ifndef POWER_SERVICE_SERVER_INCLUDE_SS_POWER_H_
23 #define POWER_SERVICE_SERVER_INCLUDE_SS_POWER_H_
25 #include <system_service/ss_power_service.h>
26 #include <system_service/ss_power_service_protocol.h>
27 #include <system_service/ss_string_maps.h>
28 #include <system_service/ss_templates.h>
29 #include <native_service/frameworkunified_types.h>
35 #include "ss_power_session.h"
36 #include "ss_power_config.h"
37 #include "ss_power_state_machine.h"
38 #include "ss_power_powerservicelog.h"
40 typedef enum _SS_PSState {
41 SS_PS_READY_TO_WAKEUP = 0x01,
42 SS_PS_WAKEUP_INITIATED,
43 SS_PS_WAKEUP_COMPLETE,
44 SS_PS_POWER_ON_COMPLETE,
45 SS_PS_POWER_OFF_INITIATED,
46 SS_PS_POWER_OFF_COMPLETE,
47 SS_PS_SHUTDOWN_INITIATED,
48 SS_PS_SHUTDOWN_COMPLETE
49 // This is not real state, used only to know total states
60 typedef std::vector<Ts_cmdHist> cmdHist;
61 typedef cmdHist::iterator cmdHistIter;
67 EFrameworkunifiedStatus Initialize(HANDLE h_app);
68 static Power & GetInstance();
70 /// Session Request Handlers
71 EFrameworkunifiedStatus OnOpenSession(HANDLE h_app);
72 EFrameworkunifiedStatus OnCloseSession(HANDLE h_app);
74 /// Session Response\Ack Handlers
75 EFrameworkunifiedStatus OnWakeUpComplete(HANDLE h_app);
76 EFrameworkunifiedStatus OnShutdownComplete(HANDLE h_app);
77 EFrameworkunifiedStatus OnPrintConnections(HANDLE h_app);
78 EFrameworkunifiedStatus OnPrintStack(HANDLE h_app);
82 /// Supervisor Handlers
83 EFrameworkunifiedStatus OnPowerRequestMsg(HANDLE h_app);
84 EFrameworkunifiedStatus OnSetPowerState(HANDLE h_app);
85 EFrameworkunifiedStatus OnSetCommWakeUp(HANDLE h_app);
86 EFrameworkunifiedStatus OnSetCommSleep(HANDLE h_app);
87 EFrameworkunifiedStatus OnShutdownRequestMsg(HANDLE h_app);
89 EFrameworkunifiedStatus OnPowerOnOffNotification(HANDLE h_app);
90 EFrameworkunifiedStatus OnStartModules(HANDLE h_app);
91 EFrameworkunifiedStatus OnShutdownModules(HANDLE h_app);
93 EFrameworkunifiedStatus OnHysteresisTimeout(HANDLE h_app);
96 EFrameworkunifiedStatus OnSystemLaunchComplete(HANDLE h_app);
97 EFrameworkunifiedStatus OnSystemShutdownComplete(HANDLE h_app);
98 EFrameworkunifiedStatus OnWakeUpTimeout(HANDLE h_app);
99 EFrameworkunifiedStatus OnShutdownTimeout(HANDLE h_app);
101 // Get Result query from power test client
102 EFrameworkunifiedStatus OnCurrentPowerStateQuery(HANDLE h_app);
104 EFrameworkunifiedStatus OnSetVoltageState(HANDLE h_app);
105 EFrameworkunifiedStatus OnSetCrankState(HANDLE h_app);
107 EFrameworkunifiedStatus OnSystemModeInfoRequest(HANDLE h_app);
108 EFrameworkunifiedStatus OnSystemModeInfoResponse(HANDLE h_app);
110 EFrameworkunifiedStatus OnInitCompReport(HANDLE h_app);
112 EFrameworkunifiedStatus OnSystemMgrConnectionEstablished(HANDLE h_app);
115 // Start Confirmation callback functions
117 EFrameworkunifiedStatus OnSendStartupConfirmationRequest(HANDLE h_app);
118 EFrameworkunifiedStatus OnSendStartupConfirmationResponse(HANDLE h_app);
121 // User Mode Protocol callback functions
123 EFrameworkunifiedStatus OnUserModeResponse(HANDLE h_app);
126 // Shutdown Condition Notification Protocol function
128 EFrameworkunifiedStatus OnPublishShutdownPopupRequest(HANDLE h_app);
131 // Power Popup Notification Protocol function
133 EFrameworkunifiedStatus OnPublishPowerPopupRequest(HANDLE h_app);
136 // HeartBeat Protocol callback functions
138 EFrameworkunifiedStatus On_CWORD56_HeartBeatRequest(HANDLE h_app);
139 EFrameworkunifiedStatus OnSM_CWORD56_HeartBeatResponse(HANDLE h_app);
142 // Hard Reset Protocol callback functions
144 EFrameworkunifiedStatus OnCpuResetRequest(HANDLE h_app);
147 // Remote Data Reset Protocol callback functions
149 EFrameworkunifiedStatus OnRemoteDataResetRequest(HANDLE h_app);
150 EFrameworkunifiedStatus OnRemoteDataResetResponse(HANDLE h_app);
152 cmdHist m__CWORD56_RepHist;
153 cmdHistIter m__CWORD56_RepIter;
154 cmdHist m_PubCmdHist;
155 cmdHistIter m_PubHistIter;
157 cmdHistIter m_ErrHistIter;
159 cmdHistIter m_VHistIter;
161 void SSPowerDebugDump(HANDLE h_app);
164 #define LOG_POWERSERVICELOG_CNT(caseid, Cnt) \
165 FRAMEWORKUNIFIEDLOG_CNT(ZONE_INFO, Cnt, 0); \
166 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " case " #caseid \
167 ": FRAMEWORKUNIFIEDLOG_CNT(ZONE_INFO, " #Cnt ", 0)");
169 #define LOG_POWERSERVICELOG_EVT(caseid, Evt, Data0) \
170 FRAMEWORKUNIFIEDLOG_EVT(ZONE_INFO, Evt, 1, Data0); \
171 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " case " #caseid \
172 ": FRAMEWORKUNIFIEDLOG_EVT(ZONE_INFO, " #Evt ", " #Data0 ")");
174 #define LOG_STATUS_IF_ERRORED_PWR_SM_WITH_HIST_LOGGING(l_eStatus, pStr) \
175 if (eFrameworkunifiedStatusOK != l_eStatus) { \
177 SetCmdHist(pStr, m_ErrHist, m_ErrHistIter, GetStr(static_cast<EFrameworkunifiedStatus>(l_eStatus)).c_str()); \
178 } // End of #define LOG_STATUS_IF_ERRORED(l_eStatus,pStr)
180 #define SS_PWR_LOG_HIST(cmd, hist, it, sender, l_eStatus) \
181 if (eFrameworkunifiedStatusOK == l_eStatus) { \
182 SetCmdHist((static_cast< std::string> (cmd)), (static_cast<cmdHist&> (hist)), \
183 (static_cast<cmdHistIter&> (it)), (static_cast< std::string> (sender))); \
185 //**************************************************************************
186 // Counter Logging enums & typedefs *
188 // Counter Event IDs *
190 CT_Startup_CanSignal = 0x0114, // *
191 CT_Startup_DiagMsg = 0x0118, // *
193 CT_Shutdown_CanSignal = 0x0121, // *
194 CT_Shutdown_Timeout = 0x0124, // *
195 CT_Shutdown_Temperature = 0x0125, // *
196 CT_Shutdown_Error = 0x0126, // *
197 CT_Shutdown_Voltage = 0x0127 // *
198 } EPWR_COUNTER_EVENT_ID_TYPE; // *
200 // End of Counter Logging enums & typedefs *
201 //**************************************************************************
203 //**************************************************************************
204 // Event Logging enums & typedefs *
208 // Startup Event IDs *
209 Ei_StartUp_Cansignal = 0x0101, // *
210 Ei_StartUp_HK_On = 0x0102, // *
211 // 0x0103 not specified // *
212 // 0x0104 not specified // *
213 // 0x0105 System Svcs not responsible// *
214 // 0x0106 not specified // *
215 Ei_StartUp_ActivationLine = 0x0107, // *
216 Ei_StartUp_DiagMsg = 0x0108, // *
218 // Shutdown Event IDs *
219 Ei_shutdown_CANsignal = 0x0201, // *
220 Ei_shutdown_HkOFF = 0x0202, // *
221 // 0x0203 not specified // *
222 // 0x0204 not specified // *
223 Ei_shutdown_Temperature = 0x0205, // *
224 Ei_shutdown_NetworkError = 0x0206, // *
225 Ei_shutdown_Voltage = 0x0207 // *
226 } EPWR_LOGGING_EVENT_ID_TYPE; // *
228 // Ei_StartUp_CanSignal byte0 Event Detail *
230 epseisuedIGNITION = 0x00, // *
231 epseisuedHK_ON = 0x01, // *
232 epseisuedDOOR_MODULES = 0x02, // *
233 // 0x03 not specified // *
234 // 0x04 not specified // *
235 epseisuedPASS = 0x05, // *
236 epseisuedIHTM = 0x06, // *
237 epseisuedMPM = 0x07, // *
238 epseisuedSNA = 0xFF // *
239 } EPWR_LOGGING_EVT_DETAIL_SU_CAN_TYPE; // *
244 epseisuedHK_ON_Key = 0x00
245 } EPWR_LOGGING_EVT_DETAIL_SU_KEY_TYPE;
248 // Ei_StartUp_ActivationLine
250 epseisuedACV_LINE = 0x00
251 } EPWR_LOGGING_EVT_DETAIL_SU_LINE_TYPE;
254 // Ei_StartUp_DiagMsg byte0 Event Detail *
256 epseisuedHU = 0x01, // *
257 epseisuedCAN = 0x02, // *
258 } EPWR_LOGGING_EVT_DETAIL_SU_DIAG_TYPE; // *
260 // Ei_ShutDown_CanSignal byte0 Event Detail *
262 epseisdcsIGN_STATE = 0x00, // *
263 epseisdcsHK_ON = 0x01 // *
264 } EPWR_LOGGING_EVT_DETAIL_SD_CAN_TYPE; // *
266 // Ei_ShutDown_Temperature byte0 Event Detail *
268 epseisdtempECU_LOW = 0x00, // *
269 epseisdtempECU_HIGH = 0x01, // *
270 } EPWR_LOGGING_EVT_DETAIL_SD_TEMP_TYPE; // *
272 // Ei_ShutDown_NetworkError byte0 Event Detail *
274 epseisdneHMI_CAN = 0x00, // *
275 epseisdneHU_CAN = 0x01 // *
276 } EPWR_LOGGING_EVT_DETAIL_SD_NETWORK_ERROR_TYPE; // *
278 // Ei_ShutDown_Voltage byte0 Event Detail *
280 epseisdnvoltBATTERY_CUT_OFF = 0x00, // *
281 epseisdnvoltLIMP_HOME = 0x01, // *
282 epseisdnvoltUNKNOWN = 0xFF // *
283 } EPWR_LOGGING_EVT_DETAIL_SD_VOLTAGE_TYPE; // *
285 // End of Event Logging enums & typedefs *
286 //**************************************************************************
288 PowerSessionHandler m_oSessionHandler;
289 PowerConfigParams m_tConfigData;
290 PowerStateMachine m_oStateMachine;
291 UI_32 m_aTimerIDs[15];
292 wakeInfo m_WakeUpData; /// WakeUp data received from SPM
293 SS_PSState m_PowerState;
294 ePowerSrvVoltageStates m_VoltageState;
295 ePowerSrvCrankStates m_CrankState;
296 UI_32 m_MaxShutdownTimeout;
297 std::map<SS_PSState, std::string> m_PPStateStrMap;
299 // Notify Module on Voltage change detected.
300 EFrameworkunifiedStatus PublishVoltageStateChange(HANDLE h_app);
301 EFrameworkunifiedStatus ConstructPwrStateResponse(CHAR *f_MessageResponse);
302 EFrameworkunifiedStatus AddStateInformationToResponse(CHAR *f_MessageResponse);
303 EFrameworkunifiedStatus AddVoltageInformationToResponse(CHAR *f_MessageResponse);
304 EFrameworkunifiedStatus AddCrankInformationToResponse(CHAR *f_MessageResponse);
305 EFrameworkunifiedStatus RegisterAllCallbacksAndNofitications(HANDLE h_app);
306 VOID SetPowerServiceState(SS_PSState f_NewState);
307 EFrameworkunifiedStatus ValidateUserModeMessage(HANDLE h_app,
308 EPWR_USER_MODE_TYPE &l_eUserModeState); // NOLINT (runtime/references)
310 pthread_mutex_t pwr_hist_mutex;
312 void SetCmdHist(std::string cmd,
313 cmdHist &hist, // NOLINT (runtime/references)
314 cmdHistIter &it, // NOLINT (runtime/references)
318 #endif // POWER_SERVICE_SERVER_INCLUDE_SS_POWER_H_