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 This file supports the power service test client.
21 ///////////////////////////////////////////////////////////////////////////////
24 #include <system_service/ss_power_service_local.h>
25 #include <native_service/frameworkunified_application.h>
26 #include <native_service/frameworkunified_framework_if.h>
27 #include <other_service/itoa.h>
30 #include "ss_power_powerservicelog.h"
32 using namespace std; // NOLINT (build/namespaces)
34 #define SS_CRANK_STATE_STRING_LENGTH 5
35 #define SS_VOLTAGE_STATE_STRING_LENGTH 5
36 #define SS_MODULE_STATE_STRING_LENGTH 5
37 #define SS_HEX_BASE_VALUE 16
39 const CHAR ReeadyToWakeUpDescription[] = "_READY_TO_WAKEUP:";
40 const CHAR WakeUpInitiatedDescription[] = "_WAKEUP_INITIATED:";
41 const CHAR WakeUpCompletedDescription[] = "_WAKEUP_COMPLETED:";
42 const CHAR PowerOnCompletedDescription[] = "_POWER_ON_COMPLETED:";
43 const CHAR PowerOffInitiatedDescription[] = "_POWER_OFF_INITIATED:";
44 const CHAR PowerOffCompletedDescription[] = "_POWER_OFF_COMPLETED:";
45 const CHAR ShutdownInitiatedDescription[] = "_SHUTDOWN_INITIATED:";
46 const CHAR ShutdownCompletedDescription[] = "_SHUTDOWN_COMPLETED:";
48 const CHAR CrankInvalidDescription[] = "_INVALID:";
49 const CHAR CrankEntryDescription[] = "_ENTRY:";
50 const CHAR CrankExitDescription[] = "_EXIT:";
52 const CHAR VoltageInvalidDescription[] = "_INVALID:";
53 const CHAR VoltageNormalDescription[] = "_NORMAL:";
54 const CHAR VoltageLVI1Description[] = "_LVI1:";
55 const CHAR VoltageLVI2Description[] = "_LVI2:";
57 ///////////////////////////////////////////////////////////////////////
58 /// AddCrankInformationToResponse
60 //////////////////////////////////////////////////////////////////////
61 EFrameworkunifiedStatus Power::AddCrankInformationToResponse(CHAR *f_MessageResponse) {
62 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
63 FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "+");
64 CHAR l_Buffer[SS_CRANK_STATE_STRING_LENGTH] = { 0 };
67 std::map<ePowerSrvCrankStates, std::string> CrankMap;
68 CrankMap[epscsINVALID] = CrankInvalidDescription;
69 CrankMap[epscsENTRY] = CrankEntryDescription;
70 CrankMap[epscsEXIT] = CrankExitDescription;
72 // confirm that CrankState value would fit in buffer array
73 if (m_CrankState < 0xFFFF) { // LCOV_EXCL_BR_LINE 8: dead code
74 itoa(m_CrankState, l_Buffer, SS_HEX_BASE_VALUE);
75 while (l_Buffer[l_Index]) {
76 l_Buffer[l_Index] = toupper(l_Buffer[l_Index]);
81 if (MaxRespMsg > (strlen(f_MessageResponse) + strlen(CrankMap[m_CrankState].c_str()) + strlen(l_Buffer))) { // LCOV_EXCL_BR_LINE 8: dead code // NOLINT[whitespace/line_length]
82 strcat(f_MessageResponse, l_Buffer); // NOLINT (runtime/printf)
83 strcat(f_MessageResponse, CrankMap[m_CrankState].c_str()); // NOLINT (runtime/printf)
88 "Buffer Overrun Condition : Failed to add Crank State description to response");
89 l_eStatus = eFrameworkunifiedStatusFail;
92 FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "-");
95 ///////////////////////////////////////////////////////////////////////
96 /// AddVoltageInformationToResponse
98 //////////////////////////////////////////////////////////////////////
99 EFrameworkunifiedStatus Power::AddVoltageInformationToResponse(CHAR *f_MessageResponse) {
100 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
101 FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "+");
102 CHAR l_Buffer[SS_VOLTAGE_STATE_STRING_LENGTH] = { 0 };
105 std::map<ePowerSrvVoltageStates, std::string> VoltageMap;
106 VoltageMap[epsvsINVALID] = VoltageInvalidDescription;
107 VoltageMap[epsvsNORMAL] = VoltageNormalDescription;
108 VoltageMap[epsvsLVI1] = VoltageLVI1Description;
109 VoltageMap[epsvsLVI2] = VoltageLVI2Description;
111 // confirm that VoltageState value would fit in buffer array
112 if (m_VoltageState < 0xFFFF) { // LCOV_EXCL_BR_LINE 8: dead code
113 itoa(m_VoltageState, l_Buffer, SS_HEX_BASE_VALUE);
114 while (l_Buffer[l_Index]) {
115 l_Buffer[l_Index] = toupper(l_Buffer[l_Index]);
120 if (MaxRespMsg > (strlen(f_MessageResponse) + strlen(VoltageMap[m_VoltageState].c_str()) + strlen(l_Buffer))) { // LCOV_EXCL_BR_LINE 8: dead code // NOLINT[whitespace/line_length]
121 strcat(f_MessageResponse, l_Buffer); // NOLINT (runtime/printf)
122 strcat(f_MessageResponse, VoltageMap[m_VoltageState].c_str()); // NOLINT (runtime/printf)
127 "Buffer Overrun Condition : Failed to add Voltage State description to response");
128 l_eStatus = eFrameworkunifiedStatusFail;
131 FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "-");
134 ///////////////////////////////////////////////////////////////////////
135 /// AddStateInformationToResponse
138 //////////////////////////////////////////////////////////////////////
139 EFrameworkunifiedStatus Power::AddStateInformationToResponse(CHAR *f_MessageResponse) {
140 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
141 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
142 FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "+");
143 CHAR l_Buffer[SS_MODULE_STATE_STRING_LENGTH] = { 0 };
146 std::map<SS_PSState, std::string> StateMap; // State Map
147 StateMap[SS_PS_READY_TO_WAKEUP] = ReeadyToWakeUpDescription;
148 StateMap[SS_PS_WAKEUP_INITIATED] = WakeUpInitiatedDescription;
149 StateMap[SS_PS_WAKEUP_COMPLETE] = WakeUpCompletedDescription;
150 StateMap[SS_PS_POWER_ON_COMPLETE] = PowerOnCompletedDescription;
151 StateMap[SS_PS_POWER_OFF_INITIATED] = PowerOffInitiatedDescription;
152 StateMap[SS_PS_POWER_OFF_COMPLETE] = PowerOffCompletedDescription;
153 StateMap[SS_PS_SHUTDOWN_INITIATED] = ShutdownInitiatedDescription;
154 StateMap[SS_PS_SHUTDOWN_COMPLETE] = ShutdownCompletedDescription;
156 // confirm that PowerState value would fit in buffer array
157 if (m_PowerState < 0xFFFF) { // LCOV_EXCL_BR_LINE 8: dead code
158 itoa(m_PowerState, l_Buffer, SS_HEX_BASE_VALUE);
159 while (l_Buffer[l_Index]) {
160 l_Buffer[l_Index] = toupper(l_Buffer[l_Index]);
165 if (MaxRespMsg > (strlen(f_MessageResponse) + strlen(StateMap[m_PowerState].c_str()) + strlen(l_Buffer))) { // LCOV_EXCL_BR_LINE 8: dead code // NOLINT[whitespace/line_length]
166 strcat(f_MessageResponse, l_Buffer); // NOLINT (runtime/printf)
167 strcat(f_MessageResponse, StateMap[m_PowerState].c_str()); // NOLINT (runtime/printf)
172 "Buffer Overrun Condition : Failed to add Module State description to response");
173 l_eStatus = eFrameworkunifiedStatusFail;
176 FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "-");
180 ///////////////////////////////////////////////////////////////////////
181 /// ConstructPwrStateResponse
184 //////////////////////////////////////////////////////////////////////
185 EFrameworkunifiedStatus Power::ConstructPwrStateResponse(CHAR *f_MessageResponse) {
186 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
187 FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "+");
189 if (f_MessageResponse == NULL) { // LCOV_EXCL_BR_LINE 8: dead code
190 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
191 return eFrameworkunifiedStatusFail;
194 if (eFrameworkunifiedStatusOK == (l_eStatus = AddStateInformationToResponse(f_MessageResponse))) { // LCOV_EXCL_BR_LINE 8: dead code // NOLINT[whitespace/line_length]
195 if (eFrameworkunifiedStatusOK == (l_eStatus = AddVoltageInformationToResponse(f_MessageResponse))) { // LCOV_EXCL_BR_LINE 8: dead code // NOLINT[whitespace/line_length]
196 if (eFrameworkunifiedStatusOK == (l_eStatus = AddCrankInformationToResponse(f_MessageResponse))) { // LCOV_EXCL_BR_LINE 8: dead code // NOLINT[whitespace/line_length]
197 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Response Constructed");
202 FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "-");