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 @file Naviinfo_API.cpp
19 @detail Naviinfo_API Functions
20 @lib libNaviinfo_API.so
21 ******************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
26 #include "Naviinfo_API.h"
27 #include <vehicle_service/POS_define.h>
28 #include <vehicle_service/POS_sensor_API.h>
29 #include <vehicle_service/POS_gps_API.h>
30 #include "Vehicle_API_Dummy.h"
31 #include "POS_private.h"
32 #include <native_service/frameworkunified_types.h> // NOLINT(build/include_order)
34 void PosCnvGpsInfo(NAVIINFO_ALL *navi_loc_info);
39 * GPS information setting
43 * @param[in] hApp HANDLE - Application handle
44 * @param[in] navilocinfo NAVIINFO_ALL* - Pointer to GPS information storage area
46 * @return NAVIINFO_RET_NORMAL Normal completion<br>
47 * NAVIINFO_RET_ERROR_PARAM Parameter error<br>
48 * NAVIINFO_RET_ERROR_INNER Internal error<br>
49 * NAVIINFO_RET_ERROR_NOSUPPORT Unsupported environment
52 NAVIINFO_RET_API POS_SetGPSInfo(HANDLE hApp, NAVIINFO_ALL *navilocinfo)
54 NAVIINFO_RET_API ret = NAVIINFO_RET_NORMAL; /* Return value of this function */
55 UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */
56 NAVIINFO_ALL navi_loc_info_tmp; /* Conversion quantity area */
60 if (navilocinfo == NULL) {
61 /** Parameter error */
62 ret = NAVIINFO_RET_ERROR_PARAM;
63 } else if (hApp == NULL) {
64 /** Parameter error */
65 ret = NAVIINFO_RET_ERROR_PARAM;
67 /* Positioning Base API initialization */
68 _pb_Setup_CWORD64_API(hApp);
70 /* Supported HW Configuration Check */
71 type = GetEnvSupportInfo();
72 if (UNIT_TYPE_GRADE1 == type) {
74 ret = NAVIINFO_RET_NORMAL;
75 } else if (UNIT_TYPE_GRADE2 == type) {
78 * This feature branches processing depending on the unit type.
80 ret = NAVIINFO_RET_ERROR_NOSUPPORT;
82 /* Environment error */
83 ret = NAVIINFO_RET_ERROR_NOSUPPORT;
87 if (ret == NAVIINFO_RET_NORMAL) {
88 /* Parameter range check */
89 if (navilocinfo->stNaviGps.tdsts != 0) { /* Other than ""Time not calibrated after receiver reset"" */
90 /* Positioning status information */
91 if (POS_RET_ERROR == POS_CHKPARAMU8(navilocinfo->stDiagGps.stFix.ucFixSts, 0, 2)) {
92 return NAVIINFO_RET_ERROR_PARAM;
95 if (POS_RET_ERROR == POS_CHKPARAM32(navilocinfo->stDiagGps.stFix.stWgs84.lLat, -82944000, 82944000)) {
96 return NAVIINFO_RET_ERROR_PARAM;
99 if (POS_RET_ERROR == POS_CHKPARAM32(navilocinfo->stDiagGps.stFix.stWgs84.lLon, -165888000, 165888000)) {
100 return NAVIINFO_RET_ERROR_PARAM;
102 /* Measurement Azimuth */
103 if (POS_RET_ERROR == POS_CHKPARAMU16(navilocinfo->stNaviGps.heading, 0, 3599)) {
104 return NAVIINFO_RET_ERROR_PARAM;
107 if (POS_RET_ERROR == POS_CHKPARAMU8(navilocinfo->stNaviGps.utc.month, 1, 12)) {
108 return NAVIINFO_RET_ERROR_PARAM;
111 if (POS_RET_ERROR == POS_CHKPARAMU8(navilocinfo->stNaviGps.utc.date, 1, 31)) {
112 return NAVIINFO_RET_ERROR_PARAM;
115 if (POS_RET_ERROR == POS_CHKPARAMU8(navilocinfo->stNaviGps.utc.hour, 0, 23)) {
116 return NAVIINFO_RET_ERROR_PARAM;
119 if (POS_RET_ERROR == POS_CHKPARAMU8(navilocinfo->stNaviGps.utc.minute, 0, 59)) {
120 return NAVIINFO_RET_ERROR_PARAM;
123 if (POS_RET_ERROR == POS_CHKPARAMU8(navilocinfo->stNaviGps.utc.second, 0, 59)) {
124 return NAVIINFO_RET_ERROR_PARAM;
127 /* Date and Time Status */
128 if (POS_RET_ERROR == POS_CHKPARAMU8(navilocinfo->stNaviGps.tdsts, 0, 2)) {
129 return NAVIINFO_RET_ERROR_PARAM;
132 /* Copy to conversion area */
133 memcpy(&navi_loc_info_tmp, navilocinfo, sizeof(NAVIINFO_ALL));
134 /** Data unit conversion */
135 PosCnvGpsInfo(&navi_loc_info_tmp);
137 /* Resource acquisition */
138 if (VehicleGetResource() == TRUE) {
140 /** Send navigation information to vehicle sensor */
141 ret_api = _pb_SndMsg_Ext(POS_THREAD_NAME,
142 CID_NAVIINFO_DELIVER,
143 sizeof(NAVIINFO_ALL),
144 reinterpret_cast<void*>(&navi_loc_info_tmp), 0);
145 if (ret_api != RET_NORMAL) {
146 /** Message transmission failure */
147 ret = NAVIINFO_RET_ERROR_INNER;
150 /* When resource shortage occurs, the system terminates with an insufficient resource error. */
151 ret = NAVIINFO_RET_ERROR_RESOURCE;
153 /* Resource release */
154 VehicleReleaseResource();
162 * GPS information acquisition
164 * Access GPS information
166 * @param[in] hApp HANDLE - Application handle
167 * @param[in] navidiaginfo NAVIINFO_DIAG_GPS* - Pointer to GPS information storage area
169 * @return NAVIINFO_RET_NORMAL Normal completion<br>
170 * NAVIINFO_RET_ERROR_PARAM Parameter error<br>
171 * NAVIINFO_RET_ERROR_INNER Internal error<br>
172 * NAVIINFO_RET_ERROR_NOSUPPORT Unsupported environment
175 NAVIINFO_RET_API POS_GetGPSInfo(HANDLE hApp, NAVIINFO_DIAG_GPS *navidiaginfo)
177 NAVIINFO_RET_API ret = NAVIINFO_RET_NORMAL; /* Return value of this function */
178 UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */
179 int32_t ret_veh; /* VehicleAPI Return Values */
180 NAVIINFO_DIAG_GPS dest_data; /* Data acquisition area */
183 if (navidiaginfo == NULL) {
184 /** Parameter error */
185 ret = NAVIINFO_RET_ERROR_PARAM;
186 } else if (hApp == NULL) {
187 /** Parameter error */
188 ret = NAVIINFO_RET_ERROR_PARAM;
190 /* Positioning Base API initialization */
191 _pb_Setup_CWORD64_API(hApp);
193 /* Supported HW Configuration Check */
194 type = GetEnvSupportInfo();
195 if (UNIT_TYPE_GRADE1 == type) {
197 ret = NAVIINFO_RET_NORMAL;
198 } else if (UNIT_TYPE_GRADE2 == type) {
201 * This feature branches processing depending on the unit type.
203 ret = NAVIINFO_RET_ERROR_NOSUPPORT;
205 /* Environment error */
206 ret = NAVIINFO_RET_ERROR_NOSUPPORT;
210 if (ret == NAVIINFO_RET_NORMAL) {
211 /** Acquisition of navigation data for Diag provide */
212 ret_veh = PosGetProc(
213 (DID)VEHICLE_DID_NAVIINFO_DIAG_GPS,
214 reinterpret_cast<void*>(&dest_data),
215 (u_int16)sizeof(dest_data));
217 if (static_cast<int32_t>(sizeof(NAVIINFO_DIAG_GPS)) > ret_veh) {
218 /** Failed to acquire */
219 if (ret_veh == POS_RET_ERROR_RESOURCE) {
220 ret = NAVIINFO_RET_ERROR_RESOURCE;
222 ret = NAVIINFO_RET_ERROR_INNER;
225 /** Successful acquisition */
226 memcpy( navidiaginfo, &dest_data, sizeof(NAVIINFO_DIAG_GPS));
233 /* ++ GPS _CWORD82_ support */
236 * GPS setting transmission request
238 * Requesting GPS Settings with Complete Return
240 * @param[in] hApp HANDLE - Application handle
241 * @param[in] p_data SENSOR_MSG_SEND_DAT* - GPS setting information to be sent
243 * @return SENSOR_RET_NORMAL Normal completion<br>
244 * SENSOR_RET_ERROR_CREATE_EVENT Event generation failure<br>
245 * SENSOR_RET_ERROR_PARAM Parameter error<br>
246 * SENSOR_RET_ERROR_DID Unregistered DID<br>
247 * SENSOR_RET_ERROR_NOSUPPORT Unsupported environment
250 int32 POS_ReqGPSSetting(HANDLE hApp, SENSOR_MSG_SEND_DAT *p_data) { /* Ignore->MISRA-C++:2008 Rule 7-1-2 */
251 SENSOR_RET_API ret = SENSOR_RET_NORMAL; /* Return value */
252 RET_API ret_api; /* System API return value */
253 uint16_t expected_size; /* Message size for the specified DID */
255 UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */
258 /* Parameter error */
259 ret = SENSOR_RET_ERROR_PARAM;
262 if (ret == SENSOR_RET_NORMAL) {
263 /* Positioning Base API initialization */
264 _pb_Setup_CWORD64_API(hApp);
266 /* Argument check (DID) + Size calculation */
267 if (p_data != reinterpret_cast<SENSOR_MSG_SEND_DAT*>(NULL)) {
268 switch (p_data->did) {
269 case VEHICLE_DID_GPS__CWORD82__SETINITIAL:
274 case VEHICLE_DID_GPS__CWORD82__SETRMODE:
279 case VEHICLE_DID_GPS__CWORD82__SETRMODEEX:
284 case VEHICLE_DID_GPS__CWORD82__SELSENT:
289 case VEHICLE_DID_GPS__CWORD82__SETSBAS:
294 case VEHICLE_DID_GPS__CWORD82__SETCONF1:
299 case VEHICLE_DID_GPS__CWORD82__SETCONF2:
304 default: /* Ignore->MISRA-C++:2008 Rule 6-3-1, 6-4-1 */
305 ret = SENSOR_RET_ERROR_DID;
309 ret = SENSOR_RET_ERROR_PARAM;
313 /* Supported HW Configuration Check */
314 if (ret == SENSOR_RET_NORMAL) {
315 type = GetEnvSupportInfo();
316 if (UNIT_TYPE_GRADE1 == type) {
318 ret = SENSOR_RET_NORMAL;
319 } else if (UNIT_TYPE_GRADE2 == type) {
322 * This feature branches processing depending on the unit type.
324 ret = SENSOR_RET_ERROR_NOSUPPORT;
326 /* Environment error */
327 ret = SENSOR_RET_ERROR_NOSUPPORT;
331 if (ret == SENSOR_RET_NORMAL) {
332 /* Argument check (Size)*/
333 if (expected_size != p_data->usSize) {
334 ret = SENSOR_RET_ERROR_PARAM;
336 /* Message buffer initialization */
338 /* Create message data */
340 /* Resource acquisition */
341 if (VehicleGetResource() == TRUE) {
342 /* External Process Transmission and Reception Messages */
343 FRAMEWORKUNIFIEDLOG(ZONE_27, __FUNCTION__,
344 "POSITIONING: POS_ReqGPSSetting() --> cid = %d",
345 CID_SENSORIF__CWORD82__REQUEST);
346 ret_api = _pb_SndMsg_Ext(POS_THREAD_NAME,
347 CID_SENSORIF__CWORD82__REQUEST,
348 sizeof(SENSOR_MSG_SEND_DAT),
349 reinterpret_cast<void *>(p_data), 0);
350 FRAMEWORKUNIFIEDLOG(ZONE_27, __FUNCTION__, "POSITIONING: POS_ReqGPSSetting() <--");
352 if (ret_api != RET_NORMAL) {
353 ret = SENSOR_RET_ERROR_CREATE_EVENT;
356 /* When resource shortage occurs, the system terminates with an insufficient resource error. */
357 ret = SENSOR_RET_ERROR_RESOURCE;
359 /* Resource release */
360 VehicleReleaseResource();
366 /* -- GPS _CWORD82_ support */
370 * GPS information conversion process
372 * Convert GPS information to a format to be provided to the vehicle sensor
375 * @param[in] navi_loc_info NAVIINFO_ALL* - GPS information pointer
379 void PosCnvGpsInfo(NAVIINFO_ALL *navi_loc_info) {
384 /* Unit conversion of fix altitude[1m]->[0.01m] */
385 tmp = (int64_t)((int64_t)(navi_loc_info->stNaviGps.altitude) * 100);
386 if (tmp > static_cast<int32_t>(0x7FFFFFFF)) {
387 /* +Overflow of digits */
388 altitude = static_cast<int32_t>(0x7FFFFFFF);
389 } else if (tmp < static_cast<int32_t>(0x80000000)) { /* Ignore->MISRA-C:2004 Rule 3.1 */
390 /* -Overflow of digits */
391 altitude = static_cast<int32_t>(0x80000000); /* Ignore->MISRA-C:2004 Rule 3.1 */
393 altitude = static_cast<int32_t>(tmp);
395 navi_loc_info->stNaviGps.altitude = altitude;
397 /* Measurement Azimuth Conversion[0.Once]->[0.01 degree] */
398 heading = navi_loc_info->stNaviGps.heading;
399 heading = static_cast<uint16_t>(heading - ((heading / 3600) * 3600));
400 heading = static_cast<uint16_t>(heading * 10);
401 navi_loc_info->stNaviGps.heading = heading;