2 * @copyright Copyright (c) 2018-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.
21 * Vehicle Service Interface
24 /*---------------------------------------------------------------------------------*
26 *---------------------------------------------------------------------------------*/
27 #include <vehicle_service/positioning_base_library.h>
28 #include <stub/Vehicle_Sensor_Common_API.h>
29 #include <stub/Vehicle_API.h>
30 #include <stub/vehicle_notifications.h>
32 #include "VehicleIf.h"
34 /*---------------------------------------------------------------------------------*
36 *---------------------------------------------------------------------------------*/
38 /*---------------------------------------------------------------------------------*
40 *---------------------------------------------------------------------------------*/
42 /*---------------------------------------------------------------------------------*
43 * Local Function Prototype *
44 *---------------------------------------------------------------------------------*/
46 /*---------------------------------------------------------------------------------*
48 *---------------------------------------------------------------------------------*/
49 static BOOL gb_vehicleAvailability = FALSE;
51 /*---------------------------------------------------------------------------------*
53 *---------------------------------------------------------------------------------*/
56 * Registering Vehicle Services IF Callback Functions
58 * @param[in] *p_msg_handler Callback function table
59 * @param[in] Ui_handler_count Number of callback functions
60 * @return eFrameworkunifiedStatusOK
61 * @return eFrameworkunifiedStatusFail
63 EFrameworkunifiedStatus VehicleIfAttachCallbacksToDispatcher( // NOLINT(readability/nolint)
64 _FrameworkunifiedProtocolCallbackHandler const* p_msg_handler,
65 unsigned int ui_handler_count) {
66 EFrameworkunifiedStatus estatus = eFrameworkunifiedStatusFail;
69 happ = _pb_GetAppHandle();
71 estatus = FrameworkunifiedAttachCallbacksToDispatcher(happ, "NS_ANY_SRC", p_msg_handler, ui_handler_count);
72 if (eFrameworkunifiedStatusOK != estatus) { // LCOV_EXCL_BR_LINE 4: nsfw error
73 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
74 "FrameworkunifiedAttachCallbacksToDispatcher ERROR!! [estatus=%d]", estatus);
77 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_GetAppHandle ERROR!! [happ=%p]", happ);
85 * Vehicle IF: Set Availability Status
87 * @details This function sets status of Vehicle/Availablity stored in local. <br>
88 * Only when the status is true, Vehicle I/F is called by wrappers.
90 * @param[in] BOOL bIsAvailable : Availability Status
92 void VehicleIf_SetAvailability(BOOL bIsAvailable)
94 gb_vehicleAvailability = bIsAvailable;
96 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "gb_vehicleAvailability=%d", gb_vehicleAvailability);
103 * Remove Vehicle Services IF Callback Functions
105 * @param[in] *p_msg_handler CID table
106 * @param[in] ui_handler_count Number of CIDs
107 * @return eFrameworkunifiedStatusOK
108 * @return eFrameworkunifiedStatusFail
110 EFrameworkunifiedStatus VehicleIfDetachCallbacksFromDispatcher(const PUI_32 pui_cmd_array, UI_32 ui_command_count) {
111 EFrameworkunifiedStatus estatus = eFrameworkunifiedStatusFail;
114 happ = _pb_GetAppHandle();
116 estatus = FrameworkunifiedDetachCallbacksFromDispatcher(happ, "NS_ANY_SRC", pui_cmd_array, ui_command_count, NULL);
117 /* In the event of failure */
118 if (eFrameworkunifiedStatusOK != estatus) {
119 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
120 "PositioningDetachCallbacksToDispatcher Failed in FrameworkunifiedOnStop [estatus=%d]", estatus);
123 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_GetAppHandle ERROR!! [happ=%p]", happ);
131 * Vehicle IF: Get Type of Transmission
133 * @details This function is wrapper function of Vehicle I/F. <br>
134 * You can get the type of transmission of the vehicle.
136 * @param[out] uint8_t* pType : Type of Transmission
137 * @param[out] BOOL* bIsAvailable : Availability Status
139 * @return eFrameworkunifiedStatusOK
140 * @return eFrameworkunifiedStatusFail
143 //EFrameworkunifiedStatus VehicleIf_GetTypeOfTransmission(uint8_t* pType, BOOL* pbIsAvailable)
144 EFrameworkunifiedStatus VehicleIf_GetTypeOfTransmission(uint8_t* pType, uint8_t* pPkb, BOOL* pbIsAvailable)
146 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusFail;
151 #if 1 /* Plus _CWORD27_ Gear Data Support 180115 */
153 #endif /* Plus _CWORD27_ Gear Data Support 180115 */
156 if (gb_vehicleAvailability == TRUE)
158 hApp = _pb_GetAppHandle();
161 ret = Vehicle_GetVehicleData(hApp, VEHICLE_DID_VARTRM1, &ucVartrm, sizeof(ucVartrm));
162 if (ret < VEHICLE_RET_NORMAL)
164 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "ERROR: Vehicle_GetVehicleData:%d", ret);
168 eStatus = eFrameworkunifiedStatusOK;
172 case VEHICLE_SNS_VARTRM1_AT:
173 case VEHICLE_SNS_VARTRM1_CVT:
174 case VEHICLE_SNS_VARTRM1_HV_AT:
176 *pType = VEHICLEIF_TRANSMISSION_TYPE_AT;
179 case VEHICLE_SNS_VARTRM1_MT:
180 case VEHICLE_SNS_VARTRM1_MMT:
181 case VEHICLE_SNS_VARTRM1_SMT:
183 *pType = VEHICLEIF_TRANSMISSION_TYPE_MT;
186 case VEHICLE_SNS_VARTRM1_UNCERTAINTY:
188 *pType = VEHICLEIF_TRANSMISSION_TYPE_UNKNOWN;
193 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
194 "ERROR: Type of transmission is unknown. (%d)", ucVartrm);
196 *pType = VEHICLEIF_TRANSMISSION_TYPE_UNKNOWN;
202 #if 1 /* Plus _CWORD27_ Gear Data Support 180115 */
203 ret = Vehicle_GetVehicleData(hApp, VEHICLE_DID_PKB, &ucPkb, sizeof(ucPkb));
204 if (ret < VEHICLE_RET_NORMAL)
206 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "ERROR: Vehicle_GetVehicleData:%d", ret);
210 eStatus = eFrameworkunifiedStatusOK;
214 case VEHICLE_SNS_OFF: // R-state
215 //case VEHICLE_SNS_ANTI: // Antilock(Vehicle undefined)
217 *pPkb = VEHICLEIF_PKB_OFF;
220 case VEHICLE_SNS_ON: // Lock state
222 *pPkb = VEHICLEIF_PKB_ON;
227 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
228 "ERROR: State of parking brake is unknown. (%d)", ucPkb);
230 *pPkb = VEHICLEIF_PKB_OFF;
235 #endif /* Plus _CWORD27_ Gear Data Support 180115 */
240 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "ERROR: _pb_GetAppHandle hApp:%p", hApp);
248 *pbIsAvailable = gb_vehicleAvailability;
255 * Vehicle Services IF Availability Change Notification Registration
257 * @param[in] fp_on_cmd Callback function
258 * @return eFrameworkunifiedStatusOK
259 * @return eFrameworkunifiedStatusFail
261 EFrameworkunifiedStatus VehicleIfNotifyOnVehicleAvailability(CbFuncPtr fp_on_cmd) {
262 EFrameworkunifiedStatus estatus = eFrameworkunifiedStatusFail;
265 happ = _pb_GetAppHandle();
267 /* Vehicle/Availability Changing notification registration */
268 estatus = FrameworkunifiedSubscribeNotificationWithCallback(happ, NTFY_Vehicle_Availability, fp_on_cmd); // LCOV_EXCL_BR_LINE 6:unexpected branch //NOLINT (whitespace/line_length)
269 if (eFrameworkunifiedStatusOK != estatus) { // LCOV_EXCL_BR_LINE 4: nsfw error
270 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
271 "PositioningSubscriveNotificationswithCallback ERROR!! [estatus=%d]", estatus);
274 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_GetAppHandle ERROR!! [happ=%p]", happ);
282 * Vehicle IF: Get Shift Position
284 * @details This function is wrapper function of Vehicle I/F. <br>
285 * You can get the shift position of the vehicle.
287 * @param[out] uint8_t* pShift : Shift Position
288 * @param[out] BOOL* bIsAvailable : Availability Status
290 * @return eFrameworkunifiedStatusOK
291 * @return eFrameworkunifiedStatusFail
293 EFrameworkunifiedStatus VehicleIf_GetShiftPosition(uint8_t* pShift, BOOL* pbIsAvailable)
295 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusFail;
299 if (gb_vehicleAvailability == TRUE)
301 hApp = _pb_GetAppHandle();
304 ret = Vehicle_GetVehicleData(hApp, VEHICLE_DID_SHIFT, pShift, sizeof(*pShift));
305 if (ret < VEHICLE_RET_NORMAL)
307 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "ERROR: Vehicle_GetVehicleData:%d", ret);
311 eStatus = eFrameworkunifiedStatusOK;
316 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "ERROR: _pb_GetAppHandle hApp:%p", hApp);
324 *pbIsAvailable = gb_vehicleAvailability;
332 * Vehicle services IF Info data-delivery registry
335 * @return eFrameworkunifiedStatusOK
336 * @return eFrameworkunifiedStatusFail
339 EFrameworkunifiedStatus VehicleIfDeliveryEntry(uint32_t ul_did) {
340 EFrameworkunifiedStatus estatus = eFrameworkunifiedStatusFail;
342 VEHICLE_RET_API iret;
344 if (TRUE == gb_vehicleAvailability) {
345 happ = _pb_GetAppHandle();
347 /* Sensor data delivery registration */
348 iret = Vehicle_DeliveryEntry(happ, (PCSTR)POS_THREAD_NAME, ul_did,
349 VEHICLE_DELIVERY_REGIST, VEHICLE_DELIVERY_TIMING_UPDATE);
350 if (VEHICLE_RET_NORMAL != iret) {
351 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
352 "Vehicle_DeliveryEntry ERROR!! [iret=%d]", iret);
354 estatus = eFrameworkunifiedStatusOK;
357 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_GetAppHandle ERROR!! [happ=%p]", happ);