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.
21 * Module : POSITIONING
22 * GPS I/F service functionality
24 #include <vehicle_service/positioning_base_library.h>
25 #include <vehicle_service/POS_define.h>
26 #include <vehicle_service/POS_gps_API.h>
27 #include <vehicle_service/POS_common_API.h>
28 #include <vehicle_service/POS_sensor_API.h>
29 #include "POS_common_private.h"
30 #include "POS_private.h"
31 #include "Vehicle_API_private.h"
32 #include "Gps_API_private.h"
41 * @param[in] hApp HANDLE - Application handle
42 * @param[in] ResName PCSTR - Destination thread name
43 * @param[in] mode uint8_t - Reset mode
45 * @return POS_RET_NORMAL Normal completion(Include illegal)<br>
46 * POS_RET_ERROR_PARAM Parameter error<br>
47 * POS_RET_ERROR_INNER Internal processing error<br>
48 * POS_RET_ERROR_BUSY Busy occurrence<br>
49 * POS_RET_ERROR_NOSUPPORT Unsupported environment
52 POS_RET_API POS_ReqGPSReset(HANDLE hApp, PCSTR ResName, uint8_t mode) { // NOLINT(readability/nolint)
53 UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */
54 POS_RET_API ret = POS_RET_NORMAL; /* Return value of this function */
55 RET_API ret_api = RET_NORMAL; /* API return value */
56 POS_RESETINFO snd_msg; /* Reset information */
57 EventID event_id; /* Event ID */
58 int32_t event_val; /* Event value */
59 PNO my_pno; /* Caller PNO */
60 PNO rs_pno; /* Destination PNO */
61 uint32_t pid; /* Process ID */
62 uint32_t tid; /* Thread ID */
63 char name[128]; /* Name buffer */
65 FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "+");
67 /* Arguments & Support Configuration Check */
68 if ((hApp == NULL) || (ResName == NULL)) {
69 ret = POS_RET_ERROR_PARAM;
70 } else if (GPS_RST_COLDSTART != mode) {
71 /* Parameter error except */
72 ret = POS_RET_ERROR_PARAM;
74 /* Positioning Base API initialization */
75 _pb_Setup_CWORD64_API(hApp);
77 /* Supported HW Configuration Check */
78 type = GetEnvSupportInfo();
79 if (UNIT_TYPE_GRADE1 == type) {
82 } else if (UNIT_TYPE_GRADE2 == type) {
85 * This feature branches processing depending on the unit type.
87 ret = POS_RET_ERROR_NOSUPPORT;
89 /* Environment error */
90 ret = POS_RET_ERROR_NOSUPPORT;
93 if (ret == POS_RET_NORMAL) {
94 /* Resource acquisition */
95 if (VehicleGetResource() == TRUE) {
96 /* Event Generation */
97 rs_pno = _pb_CnvName2Pno(ResName);
98 pid = (uint32_t)getpid();
101 snprintf(name, sizeof(name), "PR_p%u_t%u", pid, tid);
102 my_pno = _pb_CnvName2Pno(name);
103 event_id = VehicleCreateEvent(my_pno);
105 /* Successful event generation */
106 memset(&snd_msg, 0x00, sizeof(POS_RESETINFO));
108 /* Message creation */
109 snd_msg.mode = mode; /* Reset mode */
110 snd_msg.snd_pno = my_pno; /* Caller PNo. */
111 snd_msg.res_pno = rs_pno; /* Destination PNo. */
113 /* Message transmission request */
114 ret_api = _pb_SndMsg_Ext(POS_THREAD_NAME,
116 sizeof(POS_RESETINFO),
117 reinterpret_cast<void*>(&snd_msg), 0);
119 if (RET_NORMAL == ret_api) {
120 /* If the data setup process is successful,Wait for a completion event */
121 ret_api = _pb_WaitEvent(event_id,
123 VEHICLE_RET_ERROR_MIN, VEHICLE_RET_NORMAL, &event_val, INFINITE);
124 if (RET_NORMAL != ret_api) {
125 /* When not put in event wait state */
126 /* Event generation failure */
127 ret = POS_RET_ERROR_INNER;
129 /* Return from Event Wait */
130 /* Set event value (processing result) as return value */
131 ret = (POS_RET_API)event_val;
134 /* Message transmission processing failed */
135 ret = POS_RET_ERROR_INNER;
138 ret_api = VehicleDeleteEvent(event_id);
140 /* Event generation failure */
141 ret = POS_RET_ERROR_INNER;
144 /* Insufficient resource */
145 ret = POS_RET_ERROR_RESOURCE;
147 /* Resource release */
148 VehicleReleaseResource();
152 FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "- [ret = %d]", ret);
158 * GPS time setting request delivery registration
160 * Register delivery of GPS time setting request
162 * @param[in] hApp HANDLE - Application handle
163 * @param[in] notifyName PCSTR - Destination thread name
164 * @param[in] ucCtrlFlg uint8_t - Delivery control(Delivery registration/Delivery stop/Resume delivery)
166 * @return POS_RET_NORMAL Normal completion(Include illegal)<br>
167 * POS_RET_ERROR_BUFFULL Buffer-full<br>
168 * POS_RET_ERROR_INNER Internal error<br>
169 * POS_RET_ERROR_PARAM Parameter error<br>
170 * POS_RET_ERROR_NOSUPPORT Unsupported environment
173 POS_RET_API POS_RegisterListenerGPSTimeSetReq(HANDLE hApp, // NOLINT(readability/nolint)
174 PCSTR notifyName, // NOLINT(readability/nolint)
175 uint8_t ucCtrlFlg) { // NOLINT(readability/nolint)
176 POS_RET_API ret = POS_RET_NORMAL; /* Return value of this function */
177 SENSOR_RET_API ret_sens = SENSOR_RET_NORMAL; /* API return value */
178 UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */
180 /* Internal debug log output */
181 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+");
183 /* Arguments & Support Configuration Check */
184 if ((hApp == NULL) || (notifyName == NULL)) {
185 ret = POS_RET_ERROR_PARAM;
186 } else if (SENSOR_DELIVERY_REGIST != ucCtrlFlg) {
187 /* Parameter error other than delivery registration */
188 ret = POS_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 = POS_RET_NORMAL;
198 } else if (UNIT_TYPE_GRADE2 == type) {
201 * This feature branches processing depending on the unit type.
203 ret = POS_RET_ERROR_NOSUPPORT;
205 /* Environment error */
206 ret = POS_RET_ERROR_NOSUPPORT;
210 /* Delivery registration */
211 if (POS_RET_NORMAL == ret) {
212 /* Delivery registry SensorAPI calls */
213 ret_sens = PosRegisterListenerProc(notifyName, /* Destination thread name */
214 VEHICLE_DID_SETTINGTIME, /* Data ID */
215 ucCtrlFlg, /* Delivery control */
216 VEHICLE_DELIVERY_TIMING_UPDATE); /* Delivery timing */
218 /* Decision of delivery registration result */
219 if (ret_sens == SENSOR_RET_NORMAL) {
220 ret = POS_RET_NORMAL;
221 } else if (ret_sens == SENSOR_RET_ERROR_PARAM) {
222 ret = POS_RET_ERROR_PARAM;
223 } else if (ret_sens == SENSOR_RET_ERROR_BUFFULL) {
224 ret = POS_RET_ERROR_BUFFULL;
225 } else if (ret_sens == SENSOR_RET_ERROR_RESOURCE) {
226 ret = POS_RET_ERROR_RESOURCE;
228 ret = POS_RET_ERROR_INNER;
231 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "- [ret = %d]", ret);
241 * @param[in] hApp HANDLE - Application handle
242 * @param[in] pstDateTime POS_DATETIME - Pointer to GPS time information
244 * @return POS_RET_NORMAL Normal completion(Include illegal)<br>
245 * POS_RET_ERROR_INNER Internal error<br>
246 * POS_RET_ERROR_TIMEOUT Timeout error<br>
247 * POS_RET_ERROR_PARAM Parameter error<br>
248 * POS_RET_ERROR_NOSUPPORT Unsupported environment
251 POS_RET_API POS_SetGPStime(HANDLE hApp, POS_DATETIME* pstDateTime) { // NOLINT(readability/nolint)
252 POS_RET_API ret = POS_RET_NORMAL; /* Return value of this function */
253 UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */
255 FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "+");
257 /* Arguments & Support Configuration Check */
258 if ((pstDateTime == NULL) || (hApp == NULL)) {
259 ret = POS_RET_ERROR_PARAM;
261 /* Positioning Base API initialization */
262 _pb_Setup_CWORD64_API(hApp);
264 /* Supported HW Configuration Check */
265 type = GetEnvSupportInfo();
266 if (UNIT_TYPE_GRADE1 == type) {
268 ret = POS_RET_NORMAL;
269 } else if (UNIT_TYPE_GRADE2 == type) {
272 * This feature branches processing depending on the unit type.
274 ret = POS_RET_ERROR_NOSUPPORT;
276 /* Environment error */
277 ret = POS_RET_ERROR_NOSUPPORT;
281 if (ret == POS_RET_NORMAL) {
282 /* Parameter range check */
284 if (POS_RET_ERROR == POS_CHKPARAMU8(pstDateTime->month, 1, 12)) {
285 return POS_RET_ERROR_PARAM;
288 if (POS_RET_ERROR == POS_CHKPARAMU8(pstDateTime->date, 1, 31)) {
289 return POS_RET_ERROR_PARAM;
292 if (POS_RET_ERROR == POS_CHKPARAMU8(pstDateTime->hour, 0, 23)) {
293 return POS_RET_ERROR_PARAM;
296 if (POS_RET_ERROR == POS_CHKPARAMU8(pstDateTime->minute, 0, 59)) {
297 return POS_RET_ERROR_PARAM;
300 if (POS_RET_ERROR == POS_CHKPARAMU8(pstDateTime->second, 0, 59)) {
301 return POS_RET_ERROR_PARAM;
304 /* Data setting(Immediate recovery)*/
305 ret = PosSetProc(VEHICLE_DID_SETTINGTIME,
306 reinterpret_cast<void*>(pstDateTime), sizeof(POS_DATETIME), FALSE);
309 FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "- [ret = %d]", ret);
315 * GPS Time Delivery Registration
317 * Registering GPS time delivery
319 * @param[in] hApp HANDLE - Application handle
320 * @param[in] nofifyName PCSTR - Destination thread name
321 * @param[in] ucCtrlFlg uint8_t - Delivery control(Delivery registration/Delivery stop/Resume delivery)
322 * @param[in] ucDeliveryTiming uint8_t - Delivery timing(Changing/Updating)
324 * @return SENSOR_RET_NORMAL Successful registration<br>
325 * SENSOR_RET_ERROR_CREATE_EVENT Event generation failure<br>
326 * SENSOR_RET_ERROR_PARAM Parameter error<br>
327 * SENSOR_RET_ERROR_BUFFULL FULL of delivery registers<br>
328 * SENSOR_RET_ERROR_NOSUPPORT Unsupported environment
331 SENSOR_RET_API POS_RegisterListenerGPStime(HANDLE hApp, // NOLINT(readability/nolint)
332 PCSTR notifyName, // NOLINT(readability/nolint)
333 uint8_t ucCtrlFlg, // NOLINT(readability/nolint)
334 uint8_t ucDeliveryTiming) { // NOLINT(readability/nolint)
335 SENSOR_RET_API ret = SENSOR_RET_NORMAL;
336 UNIT_TYPE type = UNIT_TYPE_NONE;
338 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+");
341 /* Parameter error */
342 ret = SENSOR_RET_ERROR_PARAM;
344 /* Positioning Base API initialization */
345 _pb_Setup_CWORD64_API(hApp);
347 /* Supported HW Configuration Check */
348 type = GetEnvSupportInfo();
349 if (UNIT_TYPE_GRADE1 == type) {
351 ret = SENSOR_RET_NORMAL;
352 } else if (UNIT_TYPE_GRADE2 == type) {
355 * This feature branches processing depending on the unit type.
357 ret = SENSOR_RET_ERROR_NOSUPPORT;
360 ret = SENSOR_RET_ERROR_NOSUPPORT;
364 if (SENSOR_RET_NORMAL == ret) {
365 if (notifyName == NULL) {
366 /* Parameter error */
367 ret = SENSOR_RET_ERROR_PARAM;
369 if (ucCtrlFlg != SENSOR_DELIVERY_REGIST) {
370 /* Parameter error */
371 ret = SENSOR_RET_ERROR_PARAM;
373 if ((ucDeliveryTiming != SENSOR_DELIVERY_TIMING_CHANGE) &&
374 (ucDeliveryTiming != SENSOR_DELIVERY_TIMING_UPDATE)) {
375 /* Parameter error */
376 ret = SENSOR_RET_ERROR_PARAM;
380 if (SENSOR_RET_NORMAL == ret) {
381 /* Delivery registration process */
382 ret = PosRegisterListenerProc(notifyName, VEHICLE_DID_GPS_TIME, ucCtrlFlg, ucDeliveryTiming);
385 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "- [ret = %d]", ret);
395 * @param[in] hApp HANDLE - Application handle
396 * @param[in] *dat SENSOR_GPSTIME - Pointer to GPS time information
398 * @return POS_RET_NORMAL Normal completion(Include illegal)<br>
399 * POS_RET_ERROR_INNER Internal error<br>
400 * POS_RET_ERROR_PARAM Parameter error<br>
401 * POS_RET_ERROR_NOSUPPORT Unsupported environment
404 POS_RET_API POS_GetGPStime(HANDLE hApp, SENSOR_GPSTIME* dat) { // NOLINT(readability/nolint)
405 POS_RET_API ret = POS_RET_NORMAL; /* Return value */
406 UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */
407 DID did = VEHICLE_DID_GPS_TIME; /* DID */
408 int32_t ret_get_proc; /* POS_GetProc Return Values */
410 /* Internal debug log output */
411 FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "+");
413 /* Arguments & Support Configuration Check */
415 /* If the handler is NULL, the process terminates with an error. */
416 ret = POS_RET_ERROR_PARAM;
417 } else if (dat == NULL) {
418 /* If the longitude/latitude data is NULL, it ends with an abnormal parameter. */
419 ret = POS_RET_ERROR_PARAM;
421 /* Positioning Base API initialization */
422 _pb_Setup_CWORD64_API(hApp);
424 /* Supported HW Configuration Check */
425 type = GetEnvSupportInfo();
426 if (UNIT_TYPE_GRADE1 == type) {
427 ret = POS_RET_NORMAL;
431 * This feature branches processing depending on the unit type.
433 ret = POS_RET_ERROR_NOSUPPORT;
437 /* Sensor information acquisition */
438 if (ret == POS_RET_NORMAL) {
439 /* Data acquisition process */
440 ret_get_proc = PosGetProc(did, reinterpret_cast<void*>(dat), sizeof(SENSOR_GPSTIME));
441 if (static_cast<int32_t>(sizeof(SENSOR_GPSTIME)) > ret_get_proc) {
442 /* Failed to acquire */
443 if (ret_get_proc == POS_RET_ERROR_RESOURCE) {
444 /* Insufficient resource */
445 ret = POS_RET_ERROR_RESOURCE;
447 ret = POS_RET_ERROR_INNER;
449 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PosGetProc ERROR [ret = %d]", ret);
453 FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "- [ret = %d]", ret);