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_PowerServiceIf
19 /// \brief This file supports the Power Service module interface.
21 ///////////////////////////////////////////////////////////////////////////////
22 #include "system_service/ss_power_service_if.h"
24 #include <native_service/frameworkunified_application.h>
25 #include <native_service/frameworkunified_framework_if.h>
26 #include <native_service/frameworkunified_types.h>
27 #include <native_service/frameworkunified_framework_types.h>
28 #include "system_service/ss_power_service.h"
29 #include "system_service/ss_power_service_protocol.h"
30 #include "system_service/ss_power_service_notifications.h"
31 #include "system_service/ss_system_if.h"
32 #include "system_service/ss_services.h"
33 #include "system_service/ss_string_maps.h"
34 #include "system_service/ss_templates.h"
35 #include "ss_power_if_interfaceunifiedlog.h"
37 HANDLE OpenPowerService(HANDLE f_hApp) {
38 EFrameworkunifiedStatus l_eStatus;
39 HANDLE l_hService = NULL;
41 l_eStatus = eFrameworkunifiedStatusInvldHandle;
42 LOG_ERROR("NULL == f_App");
43 } else if (NULL == (l_hService = FrameworkunifiedOpenService(f_hApp, SERVICE_POWER))) {
44 l_eStatus = eFrameworkunifiedStatusNullPointer;
45 LOG_ERROR("FrameworkunifiedOpenService(f_hApp, SERVICE_POWER)");
50 EFrameworkunifiedStatus ClosePowerService(HANDLE f_hApp, HANDLE f_hService) {
51 EFrameworkunifiedStatus l_eStatus;
53 l_eStatus = eFrameworkunifiedStatusInvldHandle;
54 LOG_ERROR("NULL == f_App");
55 } else if (NULL == f_hService) {
56 l_eStatus = eFrameworkunifiedStatusInvldHandle;
57 LOG_ERROR("NULL == f_hService");
59 l_eStatus = FrameworkunifiedCloseService(f_hApp, f_hService);
60 LOG_STATUS(l_eStatus, "FrameworkunifiedCloseService(f_hApp, f_hService)");
66 ///////////////////////////////////////////////////////////////////////////////////////////////////
67 /// Session Related Requests
68 /// Any client can also use FrameworkunifiedOpenSession and FrameworkunifiedOpenSessionWithData.
69 /// In that case, the PVOID data passed as a parameter should be MM_OpenSessionRequestIf
70 /// to open a session with the Power Service.
71 /// The client can also use the below API for Opening a session with Power Service.
72 ///////////////////////////////////////////////////////////////////////////////////////////////////
74 EFrameworkunifiedStatus PwrServiceOpenSessionRequest(HANDLE f_hService,
75 EPWR_SESSION_TYPE f_eSessionType) {
76 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
77 EFrameworkunifiedStatus l_eStatus;
79 if (NULL == f_hService) {
80 l_eStatus = eFrameworkunifiedStatusInvldHandle;
81 LOG_ERROR("NULL == f_hService");
82 } else if (epsstUNKNOWN == f_eSessionType) {
83 l_eStatus = eFrameworkunifiedStatusInvldParam;
84 LOG_ERROR("epsstUNKNOWN == f_eSessionType");
86 l_eStatus = FrameworkunifiedOpenSessionWithData(f_hService, &f_eSessionType,
87 sizeof(f_eSessionType));
88 LOG_STATUS(l_eStatus, "FrameworkunifiedOpenSessionWithData()");
90 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
94 EFrameworkunifiedStatus PwrServiceCloseSessionRequest(HANDLE f_hService, HANDLE f_hSession) {
95 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
96 EFrameworkunifiedStatus l_eStatus;
98 if (NULL == f_hService) {
99 l_eStatus = eFrameworkunifiedStatusInvldHandle;
100 LOG_ERROR("NULL == f_hService");
101 } else if (NULL == f_hSession) {
102 l_eStatus = eFrameworkunifiedStatusInvldHandle;
103 LOG_ERROR("NULL == f_hSession");
105 CALL_AND_LOG_STATUS(FrameworkunifiedCloseSession(f_hService, f_hSession));
108 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
112 EFrameworkunifiedStatus PwrServiceDecodeOpenSessionResponse(HANDLE f_hApp,
113 HANDLE& f_hSession) { // NOLINT (runtime/references)
114 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
115 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
117 if (NULL == f_hApp) {
118 l_eStatus = eFrameworkunifiedStatusInvldHandle;
119 LOG_ERROR("NULL == f_App");
121 if (NULL == (f_hSession = FrameworkunifiedGetOpenSessionHandle(f_hApp))) {
122 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
123 " Error: FrameworkunifiedGetOpenSessionHandle('%s') returned NULL",
124 FrameworkunifiedGetAppName(f_hApp));
125 l_eStatus = eFrameworkunifiedStatusNullPointer;
128 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
132 EFrameworkunifiedStatus PwrServiceSetVoltageState(HANDLE f_hSession,
133 EPWR_VOLTAGE_STATE_TYPE f_eVoltage_state) {
134 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
135 EFrameworkunifiedStatus l_eStatus;
136 if (NULL == f_hSession) {
137 l_eStatus = eFrameworkunifiedStatusInvldHandle;
138 LOG_ERROR("NULL == f_hSession");
139 } else if (epsvsINVALID == f_eVoltage_state) {
140 l_eStatus = eFrameworkunifiedStatusInvldParam;
141 LOG_ERROR("epsvsINVALID == f_eVoltage_state");
143 Pwr_ServiceSetInterface l_tServiceSetIf;
144 std::memset(&l_tServiceSetIf, 0, sizeof(l_tServiceSetIf));
145 l_tServiceSetIf.data.voltage.state = f_eVoltage_state;
146 l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_VOLTAGE_STATE,
147 sizeof(l_tServiceSetIf), (PVOID) &l_tServiceSetIf);
148 LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_VOLTAGE_STATE)");
150 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
154 EFrameworkunifiedStatus PwrServiceSetCrankState(HANDLE f_hSession,
155 EPWR_CRANK_STATE_TYPE f_eCrank_state) {
156 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
157 EFrameworkunifiedStatus l_eStatus;
159 if (NULL == f_hSession) {
160 l_eStatus = eFrameworkunifiedStatusInvldHandle;
161 LOG_ERROR("NULL == f_hSession");
162 } else if (epscsINVALID == f_eCrank_state) {
163 l_eStatus = eFrameworkunifiedStatusInvldParam;
164 LOG_ERROR("epsvsINVALID == f_eCrank_state");
166 Pwr_ServiceSetInterface l_tServiceSetIf;
167 std::memset(&l_tServiceSetIf, 0, sizeof(l_tServiceSetIf));
168 l_tServiceSetIf.data.crank.state = f_eCrank_state;
169 l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_CRANK_STATE,
170 sizeof(l_tServiceSetIf), (PVOID) &l_tServiceSetIf);
171 LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_CRANK_STATE)");
173 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
177 EFrameworkunifiedStatus PwrServiceSendShutdownRequest(
178 HANDLE f_hSession, EPWR_SHUTDOWN_REQUEST_MSG_STRUCT &f_eState) { // NOLINT (runtime/references)
179 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
180 EFrameworkunifiedStatus l_eStatus;
181 if (NULL == f_hSession) {
182 l_eStatus = eFrameworkunifiedStatusInvldHandle;
183 LOG_ERROR("NULL == f_hSession");
185 Pwr_ServiceSetInterface l_tServiceSetIf;
186 std::memset(&l_tServiceSetIf, 0, sizeof(l_tServiceSetIf));
187 l_tServiceSetIf.data.shutdownRequestMsg = f_eState;
188 l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_SHUTDOWN_REQUEST_MSG,
189 sizeof(l_tServiceSetIf), &l_tServiceSetIf);
191 LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_SHUTDOWN_REQUEST_MSG)");
194 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
196 } // End of EFrameworkunifiedStatus PwrServiceSendShutdownRequest(
198 EFrameworkunifiedStatus PwrServiceSendSetShutdownPopupRequest(
199 HANDLE f_hSession, EPWR_SHUTDOWN_POPUP_TYPE f_eShutdownPopup) {
200 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
201 EFrameworkunifiedStatus l_eStatus;
202 if (NULL == f_hSession) {
203 l_eStatus = eFrameworkunifiedStatusInvldHandle;
204 LOG_ERROR("NULL == f_hSession");
206 Pwr_ServiceSetInterface l_tServiceSetIf;
207 std::memset(&l_tServiceSetIf, 0, sizeof(l_tServiceSetIf));
208 switch (f_eShutdownPopup) {
209 case epsspPowerSave1:
210 case epsspPowerSave2:
211 case epsspPowerSave3:
212 case epsspPowerSaveClr:
213 case epsspLowVoltage1:
214 case epsspLowVoltage2:
215 case epsspLowVoltage3:
216 case epsspLowVoltageClr:
217 case epsspBattCouplingSW1:
218 case epsspBattCouplingSW2:
219 case epsspBattCouplingSW3:
220 case epsspBattCouplingSWClr:
221 case epsspAbnormalTemp_1st:
222 case epsspAbnormalTemp_Clr:
223 case epsspLimpHome_1st:
224 case epsspLimpHome_2nd:
225 case epsspLimpHome_3rd:
226 case epsspLimpHome_Clr:
227 case epsspProdMd_1st:
228 case epsspProdMd_Clr:
229 case epsspTransMd_1st:
230 case epsspTransMd_Clr:
232 l_tServiceSetIf.data.shutdownPopup.shutdownPopupEvent =
234 l_eStatus = FrameworkunifiedSendMsg(f_hSession,
235 SS_POWER_PUBLISH_SHUTDOWN_CONDITION_REQ,
236 sizeof(l_tServiceSetIf), &l_tServiceSetIf);
237 LOG_STATUS(l_eStatus,
238 "FrameworkunifiedSendMsg(SS_POWER_PUBLISH_SHUTDOWN_CONDITION_REQ)");
242 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
243 " Error: Unknown 'ShutdownPopup' value: 0x%X/%d",
244 f_eShutdownPopup, f_eShutdownPopup);
245 l_eStatus = eFrameworkunifiedStatusInvldParam;
249 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
251 } // End of EFrameworkunifiedStatus PwrServiceSendSetShutdownPopupRequest( HANDLE f_hSession,
253 EFrameworkunifiedStatus PwrServiceSendStartupConfirmationMsgRequest(
254 HANDLE f_hSession, EPWR_SC_MSG_STRUCT f_eState) {
255 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
256 EFrameworkunifiedStatus l_eStatus;
257 if (NULL == f_hSession) {
258 l_eStatus = eFrameworkunifiedStatusInvldHandle;
259 LOG_ERROR("NULL == f_hSession");
261 Pwr_ServiceSetInterface l_tServiceSetIf;
262 std::memset(&l_tServiceSetIf, 0, sizeof(l_tServiceSetIf));
263 l_tServiceSetIf.data.startupConfirmationMsg = f_eState;
264 l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_FWD_START_CONFIRMATION_MSG_REQ,
265 sizeof(l_tServiceSetIf), &l_tServiceSetIf);
267 LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_FWD_START_CONFIRMATION_MSG_REQ)");
269 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
271 } // End of EFrameworkunifiedStatus PwrServiceSendStartupConfirmationMsgRequest ( HANDLE f_hSession,
273 EFrameworkunifiedStatus PwrServiceSystemModeInfoRequest(HANDLE f_hSession) {
274 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
275 EFrameworkunifiedStatus l_eStatus;
276 if (NULL == f_hSession) {
277 l_eStatus = eFrameworkunifiedStatusInvldHandle;
278 LOG_ERROR("NULL == f_hSession");
280 l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_SYSTEM_MODE_INFO_REQ, 0, NULL);
281 LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_SYSTEM_MODE_INFO_REQ)");
283 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
287 EFrameworkunifiedStatus PwrServiceSendInitCompReport(HANDLE f_hSession) {
288 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
289 EFrameworkunifiedStatus l_eStatus;
290 if (NULL == f_hSession) {
291 l_eStatus = eFrameworkunifiedStatusInvldHandle;
292 LOG_ERROR("NULL == f_hSession");
294 l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_INITCOMP_REP, 0, NULL);
295 LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_INITCOMP_REP)");
297 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
301 EFrameworkunifiedStatus PwrServiceSendPowerRequest(
302 HANDLE f_hSession, EPWR_POWER_REQUEST_MSG_STRUCT_WITH_UMCR &f_eState) { // NOLINT (runtime/references)
303 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
304 EFrameworkunifiedStatus l_eStatus;
305 if (NULL == f_hSession) {
306 l_eStatus = eFrameworkunifiedStatusInvldHandle;
307 LOG_ERROR("NULL == f_hSession");
309 Pwr_ServiceSetInterface l_tServiceSetIf;
310 std::memset(&l_tServiceSetIf, 0, sizeof(l_tServiceSetIf));
311 l_tServiceSetIf.data.powerRequestMsg = f_eState;
312 l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_POWER_REQUEST_MSG,
313 sizeof(l_tServiceSetIf), (PVOID) &l_tServiceSetIf);
315 char l_cBuf[200] = { 0 };
319 "FrameworkunifiedSendMsg(SS_POWER_POWER_REQUEST_MSG(%s, %s))",
320 GetStr(l_tServiceSetIf.data.powerRequestMsg.userMode).c_str(),
321 GetStr(l_tServiceSetIf.data.powerRequestMsg.userModeChangeReason).c_str());
322 LOG_STATUS(l_eStatus, l_cBuf);
324 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
326 } // End of EFrameworkunifiedStatus PwrServiceSendPowerRequest( HANDLE f_hSession
328 EFrameworkunifiedStatus PwrServiceSendHeartBeatRequest(HANDLE f_hSession,
329 EPWR_HB_REQ_MSG_STRUCT *f_eHbReqMsg) {
330 FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "+");
331 EFrameworkunifiedStatus l_eStatus;
332 if (NULL == f_hSession) {
333 l_eStatus = eFrameworkunifiedStatusInvldHandle;
334 LOG_ERROR("NULL == f_hSession");
336 l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_HEARTBEAT_REQ,
337 sizeof(EPWR_HB_REQ_MSG_STRUCT),
338 reinterpret_cast<void *>(f_eHbReqMsg));
339 LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_HEARTBEAT_REQ)");
341 FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "-");
343 } // LCOV_EXCL_BR_LINE 10:Because the last line