summaryrefslogtreecommitdiffstats
path: root/systemservice/interface_unified/library/src/ss_pwrsvc_if.cpp
blob: 86d8ebbe705afb084fbcd02c1ea28ba7dcaf8a74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/*
 * @copyright Copyright (c) 2016-2020 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_PowerServiceIf
/// \brief    This file supports the Power Service module interface.
///
///////////////////////////////////////////////////////////////////////////////
#include "system_service/ss_power_service_if.h"
#include <string.h>
#include <native_service/frameworkunified_application.h>
#include <native_service/frameworkunified_framework_if.h>
#include <native_service/frameworkunified_types.h>
#include <native_service/frameworkunified_framework_types.h>
#include "system_service/ss_power_service.h"
#include "system_service/ss_power_service_protocol.h"
#include "system_service/ss_power_service_notifications.h"
#include "system_service/ss_system_if.h"
#include "system_service/ss_services.h"
#include "system_service/ss_string_maps.h"
#include "system_service/ss_templates.h"
#include "ss_power_if_interfaceunifiedlog.h"

HANDLE OpenPowerService(HANDLE f_hApp) {
  EFrameworkunifiedStatus l_eStatus;
  HANDLE l_hService = NULL;
  if (NULL == f_hApp) {
    l_eStatus = eFrameworkunifiedStatusInvldHandle;
    LOG_ERROR("NULL == f_App");
  } else if (NULL == (l_hService = FrameworkunifiedOpenService(f_hApp, SERVICE_POWER))) {
    l_eStatus = eFrameworkunifiedStatusNullPointer;
    LOG_ERROR("FrameworkunifiedOpenService(f_hApp, SERVICE_POWER)");
  }
  return l_hService;
}

EFrameworkunifiedStatus ClosePowerService(HANDLE f_hApp, HANDLE f_hService) {
  EFrameworkunifiedStatus l_eStatus;
  if (NULL == f_hApp) {
    l_eStatus = eFrameworkunifiedStatusInvldHandle;
    LOG_ERROR("NULL == f_App");
  } else if (NULL == f_hService) {
    l_eStatus = eFrameworkunifiedStatusInvldHandle;
    LOG_ERROR("NULL == f_hService");
  } else {
    l_eStatus = FrameworkunifiedCloseService(f_hApp, f_hService);
    LOG_STATUS(l_eStatus, "FrameworkunifiedCloseService(f_hApp, f_hService)");
    f_hService = NULL;
  }
  return l_eStatus;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
/// Session Related Requests
/// Any client can also use FrameworkunifiedOpenSession and FrameworkunifiedOpenSessionWithData.
/// In that case, the PVOID data passed as a parameter should be MM_OpenSessionRequestIf
/// to open a session with the Power Service.
/// The client can also use the below API for Opening a session with Power Service.
///////////////////////////////////////////////////////////////////////////////////////////////////

EFrameworkunifiedStatus PwrServiceOpenSessionRequest(HANDLE f_hService,
                                        EPWR_SESSION_TYPE f_eSessionType) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;

  if (NULL == f_hService) {
    l_eStatus = eFrameworkunifiedStatusInvldHandle;
    LOG_ERROR("NULL == f_hService");
  } else if (epsstUNKNOWN == f_eSessionType) {
    l_eStatus = eFrameworkunifiedStatusInvldParam;
    LOG_ERROR("epsstUNKNOWN == f_eSessionType");
  } else {
    l_eStatus = FrameworkunifiedOpenSessionWithData(f_hService, &f_eSessionType,
                                       sizeof(f_eSessionType));
    LOG_STATUS(l_eStatus, "FrameworkunifiedOpenSessionWithData()");
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}

EFrameworkunifiedStatus PwrServiceCloseSessionRequest(HANDLE f_hService, HANDLE f_hSession) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;

  if (NULL == f_hService) {
    l_eStatus = eFrameworkunifiedStatusInvldHandle;
    LOG_ERROR("NULL == f_hService");
  } else if (NULL == f_hSession) {
    l_eStatus = eFrameworkunifiedStatusInvldHandle;
    LOG_ERROR("NULL == f_hSession");
  } else {
    CALL_AND_LOG_STATUS(FrameworkunifiedCloseSession(f_hService, f_hSession));
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}

EFrameworkunifiedStatus PwrServiceDecodeOpenSessionResponse(HANDLE f_hApp,
                                               HANDLE& f_hSession) {  // NOLINT (runtime/references)
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;

  if (NULL == f_hApp) {
    l_eStatus = eFrameworkunifiedStatusInvldHandle;
    LOG_ERROR("NULL == f_App");
  } else {
    if (NULL == (f_hSession = FrameworkunifiedGetOpenSessionHandle(f_hApp))) {
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
             " Error: FrameworkunifiedGetOpenSessionHandle('%s') returned NULL",
             FrameworkunifiedGetAppName(f_hApp));
      l_eStatus = eFrameworkunifiedStatusNullPointer;
    }
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}

EFrameworkunifiedStatus PwrServiceSetVoltageState(HANDLE f_hSession,
                                     EPWR_VOLTAGE_STATE_TYPE f_eVoltage_state) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;
  if (NULL == f_hSession) {
    l_eStatus = eFrameworkunifiedStatusInvldHandle;
    LOG_ERROR("NULL == f_hSession");
  } else if (epsvsINVALID == f_eVoltage_state) {
    l_eStatus = eFrameworkunifiedStatusInvldParam;
    LOG_ERROR("epsvsINVALID == f_eVoltage_state");
  } else {
    Pwr_ServiceSetInterface l_tServiceSetIf;
    std::memset(&l_tServiceSetIf, 0, sizeof(l_tServiceSetIf));
    l_tServiceSetIf.data.voltage.state = f_eVoltage_state;
    l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_VOLTAGE_STATE,
                           sizeof(l_tServiceSetIf), (PVOID) &l_tServiceSetIf);
    LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_VOLTAGE_STATE)");
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}

EFrameworkunifiedStatus PwrServiceSetCrankState(HANDLE f_hSession,
                                   EPWR_CRANK_STATE_TYPE f_eCrank_state) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;

  if (NULL == f_hSession) {
    l_eStatus = eFrameworkunifiedStatusInvldHandle;
    LOG_ERROR("NULL == f_hSession");
  } else if (epscsINVALID == f_eCrank_state) {
    l_eStatus = eFrameworkunifiedStatusInvldParam;
    LOG_ERROR("epsvsINVALID == f_eCrank_state");
  } else {
    Pwr_ServiceSetInterface l_tServiceSetIf;
    std::memset(&l_tServiceSetIf, 0, sizeof(l_tServiceSetIf));
    l_tServiceSetIf.data.crank.state = f_eCrank_state;
    l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_CRANK_STATE,
                           sizeof(l_tServiceSetIf), (PVOID) &l_tServiceSetIf);
    LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_CRANK_STATE)");
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}

EFrameworkunifiedStatus PwrServiceSendShutdownRequest(
    HANDLE f_hSession, EPWR_SHUTDOWN_REQUEST_MSG_STRUCT &f_eState) {  // NOLINT (runtime/references)
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;
  if (NULL == f_hSession) {
    l_eStatus = eFrameworkunifiedStatusInvldHandle;
    LOG_ERROR("NULL == f_hSession");
  } else {
    Pwr_ServiceSetInterface l_tServiceSetIf;
    std::memset(&l_tServiceSetIf, 0, sizeof(l_tServiceSetIf));
    l_tServiceSetIf.data.shutdownRequestMsg = f_eState;
    l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_SHUTDOWN_REQUEST_MSG,
                           sizeof(l_tServiceSetIf), &l_tServiceSetIf);

    LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_SHUTDOWN_REQUEST_MSG)");
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus PwrServiceSendShutdownRequest(

EFrameworkunifiedStatus PwrServiceSendSetShutdownPopupRequest(
    HANDLE f_hSession, EPWR_SHUTDOWN_POPUP_TYPE f_eShutdownPopup) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;
  if (NULL == f_hSession) {
    l_eStatus = eFrameworkunifiedStatusInvldHandle;
    LOG_ERROR("NULL == f_hSession");
  } else {
    Pwr_ServiceSetInterface l_tServiceSetIf;
    std::memset(&l_tServiceSetIf, 0, sizeof(l_tServiceSetIf));
    switch (f_eShutdownPopup) {
      case epsspPowerSave1:
      case epsspPowerSave2:
      case epsspPowerSave3:
      case epsspPowerSaveClr:
      case epsspLowVoltage1:
      case epsspLowVoltage2:
      case epsspLowVoltage3:
      case epsspLowVoltageClr:
      case epsspBattCouplingSW1:
      case epsspBattCouplingSW2:
      case epsspBattCouplingSW3:
      case epsspBattCouplingSWClr:
      case epsspAbnormalTemp_1st:
      case epsspAbnormalTemp_Clr:
      case epsspLimpHome_1st:
      case epsspLimpHome_2nd:
      case epsspLimpHome_3rd:
      case epsspLimpHome_Clr:
      case epsspProdMd_1st:
      case epsspProdMd_Clr:
      case epsspTransMd_1st:
      case epsspTransMd_Clr:
      case epsspAllClr:
        l_tServiceSetIf.data.shutdownPopup.shutdownPopupEvent =
            f_eShutdownPopup;
        l_eStatus = FrameworkunifiedSendMsg(f_hSession,
                               SS_POWER_PUBLISH_SHUTDOWN_CONDITION_REQ,
                               sizeof(l_tServiceSetIf), &l_tServiceSetIf);
        LOG_STATUS(l_eStatus,
                   "FrameworkunifiedSendMsg(SS_POWER_PUBLISH_SHUTDOWN_CONDITION_REQ)");
        break;

      default:
        FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
               " Error: Unknown 'ShutdownPopup' value: 0x%X/%d",
               f_eShutdownPopup, f_eShutdownPopup);
        l_eStatus = eFrameworkunifiedStatusInvldParam;
        break;
    }
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus PwrServiceSendSetShutdownPopupRequest( HANDLE f_hSession,

EFrameworkunifiedStatus PwrServiceSendStartupConfirmationMsgRequest(
    HANDLE f_hSession, EPWR_SC_MSG_STRUCT f_eState) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;
  if (NULL == f_hSession) {
    l_eStatus = eFrameworkunifiedStatusInvldHandle;
    LOG_ERROR("NULL == f_hSession");
  } else {
    Pwr_ServiceSetInterface l_tServiceSetIf;
    std::memset(&l_tServiceSetIf, 0, sizeof(l_tServiceSetIf));
    l_tServiceSetIf.data.startupConfirmationMsg = f_eState;
    l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_FWD_START_CONFIRMATION_MSG_REQ,
                           sizeof(l_tServiceSetIf), &l_tServiceSetIf);

    LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_FWD_START_CONFIRMATION_MSG_REQ)");
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus PwrServiceSendStartupConfirmationMsgRequest ( HANDLE f_hSession,

EFrameworkunifiedStatus PwrServiceSystemModeInfoRequest(HANDLE f_hSession) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;
  if (NULL == f_hSession) {
    l_eStatus = eFrameworkunifiedStatusInvldHandle;
    LOG_ERROR("NULL == f_hSession");
  } else {
    l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_SYSTEM_MODE_INFO_REQ, 0, NULL);
    LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_SYSTEM_MODE_INFO_REQ)");
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}

EFrameworkunifiedStatus PwrServiceSendInitCompReport(HANDLE f_hSession) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;
  if (NULL == f_hSession) {
    l_eStatus = eFrameworkunifiedStatusInvldHandle;
    LOG_ERROR("NULL == f_hSession");
  } else {
    l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_INITCOMP_REP, 0, NULL);
    LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_INITCOMP_REP)");
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}

EFrameworkunifiedStatus PwrServiceSendPowerRequest(
    HANDLE f_hSession, EPWR_POWER_REQUEST_MSG_STRUCT_WITH_UMCR &f_eState) {  // NOLINT (runtime/references)
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;
  if (NULL == f_hSession) {
    l_eStatus = eFrameworkunifiedStatusInvldHandle;
    LOG_ERROR("NULL == f_hSession");
  } else {
    Pwr_ServiceSetInterface l_tServiceSetIf;
    std::memset(&l_tServiceSetIf, 0, sizeof(l_tServiceSetIf));
    l_tServiceSetIf.data.powerRequestMsg = f_eState;
    l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_POWER_REQUEST_MSG,
                           sizeof(l_tServiceSetIf), (PVOID) &l_tServiceSetIf);

    char l_cBuf[200] = { 0 };
    snprintf(
        l_cBuf,
        sizeof(l_cBuf),
        "FrameworkunifiedSendMsg(SS_POWER_POWER_REQUEST_MSG(%s, %s))",
        GetStr(l_tServiceSetIf.data.powerRequestMsg.userMode).c_str(),
        GetStr(l_tServiceSetIf.data.powerRequestMsg.userModeChangeReason).c_str());
    LOG_STATUS(l_eStatus, l_cBuf);
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus PwrServiceSendPowerRequest( HANDLE f_hSession

EFrameworkunifiedStatus PwrServiceSendHeartBeatRequest(HANDLE f_hSession,
                                          EPWR_HB_REQ_MSG_STRUCT *f_eHbReqMsg) {
  FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;
  if (NULL == f_hSession) {
    l_eStatus = eFrameworkunifiedStatusInvldHandle;
    LOG_ERROR("NULL == f_hSession");
  } else {
    l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_HEARTBEAT_REQ,
                           sizeof(EPWR_HB_REQ_MSG_STRUCT),
                           reinterpret_cast<void *>(f_eHbReqMsg));
    LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_HEARTBEAT_REQ)");
  }
  FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // LCOV_EXCL_BR_LINE 10:Because the last line