summaryrefslogtreecommitdiffstats
path: root/positioning/client/src/POS_gps_API/Gps_API.cpp
blob: b3da219eb80f36b9e8587a38028ee209e36abfce (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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
/*
 * @copyright Copyright (c) 2016-2019 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.
 */

/**
 * @file
 *  Gps_API.cpp
 * @brief
 *   Module : POSITIONING
 *   GPS I/F service functionality
 */
#include <vehicle_service/positioning_base_library.h>
#include <vehicle_service/POS_define.h>
#include <vehicle_service/POS_gps_API.h>
#include <vehicle_service/POS_common_API.h>
#include <vehicle_service/POS_sensor_API.h>
#include "POS_common_private.h"
#include "POS_private.h"
#include "Vehicle_API_private.h"
#include "Gps_API_private.h"


/**
 * @brief
 *  GPS reset request
 *
 *  Request a GPS reset
 *
 * @param[in] hApp          HANDLE  - Application handle
 * @param[in] ResName       PCSTR   - Destination thread name
 * @param[in] mode          uint8_t - Reset mode
 *
 * @return  POS_RET_NORMAL           Normal completion(Include illegal)<br>
 *          POS_RET_ERROR_PARAM      Parameter error<br>
 *          POS_RET_ERROR_INNER      Internal processing error<br>
 *          POS_RET_ERROR_BUSY       Busy occurrence<br>
 *          POS_RET_ERROR_NOSUPPORT  Unsupported environment
 *
 */
POS_RET_API POS_ReqGPSReset(HANDLE hApp, PCSTR ResName, uint8_t mode) {  // NOLINT(readability/nolint)
    UNIT_TYPE        type = UNIT_TYPE_NONE;    /* Supported HW Configuration Type */
    POS_RET_API      ret = POS_RET_NORMAL;     /* Return value of this function */
    RET_API          ret_api = RET_NORMAL;     /* API return value */
    POS_RESETINFO    snd_msg;                  /* Reset information */
    EventID          event_id;                 /* Event ID */
    int32_t          event_val;                /* Event value */
    PNO              my_pno;                   /* Caller PNO */
    PNO              rs_pno;                   /* Destination PNO */
    uint32_t         pid;                      /* Process ID */
    uint32_t         tid;                      /* Thread ID */
    char             name[128];                /* Name buffer */

    FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "+");

    /* Arguments & Support Configuration Check */
    if ((hApp == NULL) || (ResName == NULL)) {
        ret = POS_RET_ERROR_PARAM;
//    } else if (GPS_RST_COLDSTART != mode) {
//        /* Parameter error except */
//        ret = POS_RET_ERROR_PARAM;
    } else {
        /* Positioning Base API initialization */
        _pb_Setup_CWORD64_API(hApp);

        /* Supported HW Configuration Check */
        type = GetEnvSupportInfo();
        if (UNIT_TYPE_GRADE1 == type) {
            /* GRADE1 */
            ret = POS_RET_NORMAL;
        } else if (UNIT_TYPE_GRADE2 == type) {
          /*
           *  Note.
           *  This feature branches processing depending on the unit type.
           */
            ret = POS_RET_ERROR_NOSUPPORT;
        } else {
            /* Environment error */
            ret = POS_RET_ERROR_NOSUPPORT;
        }

        if (ret == POS_RET_NORMAL) {
            /* Resource acquisition */
            if (VehicleGetResource() == TRUE) {
                /* Event Generation */
                rs_pno = _pb_CnvName2Pno(ResName);
                pid = (u_int32)getpid();
                tid = GetTid();

                snprintf(name, sizeof(name), "PR_p%u_t%u", pid, tid);
                my_pno = _pb_CnvName2Pno(name);
                event_id = VehicleCreateEvent(my_pno);
                if (0 != event_id) {
                    /* Successful event generation */
                    memset(&snd_msg, 0x00, sizeof(POS_RESETINFO));

                    /* Message creation */
                    snd_msg.mode     = mode;      /* Reset mode */
                    snd_msg.snd_pno  = my_pno;    /* Caller PNo. */
                    snd_msg.res_pno  = rs_pno;    /* Destination PNo. */

                    /* Message transmission request */
                    ret_api = _pb_SndMsg_Ext(POS_THREAD_NAME,
                                             CID_GPS_REQRESET,
                                             sizeof(POS_RESETINFO),
                                             reinterpret_cast<void*>(&snd_msg), 0);

                    if (RET_NORMAL == ret_api) {
                        /* If the data setup process is successful,Wait for a completion event */
                        ret_api = _pb_WaitEvent(event_id,
                                                SAPI_EVWAIT_VAL,
                                                VEHICLE_RET_ERROR_MIN, VEHICLE_RET_NORMAL, &event_val, INFINITE);
                        if (RET_NORMAL != ret_api) {
                            /* When not put in event wait state */
                            /* Event generation failure */
                            ret = POS_RET_ERROR_INNER;
                        } else {
                            /* Return from Event Wait */
                            /* Set event value (processing result) as return value */
                            ret = (POS_RET_API)event_val;
                        }
                    } else {
                        /* Message transmission processing failed */
                        ret = POS_RET_ERROR_INNER;
                    }
                    /* Event deletion */
                    ret_api = VehicleDeleteEvent(event_id);
                } else {
                    /* Event generation failure */
                    ret = POS_RET_ERROR_INNER;
                }
            } else {
                /* Insufficient resource */
                ret = POS_RET_ERROR_RESOURCE;
            }
            /* Resource release */
            VehicleReleaseResource();
        }
    }

    FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "- [ret = %d]", ret);
    return ret;
}

/**
 * @brief
 *  Get GPS version
 *
 *  Get GPS version information
 *
 * @param[in] hApp          HANDLE   - Application handle
 * @param[in] buf_size      uint8_t  - Storage size of version information(Byte)
 * @param[in] buf           int8_t*  - Pointer to store the version information
 * @param[in] size          uint8_t* - Size of the character string written to buf(Byte)
 *
 * @return  POS_RET_NORMAL           Normal completion(Include illegal)<br>
 *          POS_RET_ERROR_PARAM      Parameter error<br>
 *          POS_RET_ERROR_NOSUPPORT  Unsupported environment
 *
 */
POS_RET_API POS_GetGPSVersion(HANDLE hApp,  // NOLINT(readability/nolint)
                            uint8_t buf_size,
                            int8_t* buf,  // NOLINT(readability/nolint)
                            uint8_t* size) {
    POS_RET_API  ret = POS_RET_NORMAL;     /* Return value */
    UNIT_TYPE    type = UNIT_TYPE_NONE;    /* Supported HW Configuration Type */

    FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "+");

    /* Positioning Base API initialization */
    _pb_Setup_CWORD64_API(hApp);

    /* Supported HW Configuration Check */
    type = GetEnvSupportInfo();
    if (UNIT_TYPE_GRADE1 == type) {
        /* GRADE1 */
        ret = POS_RET_ERROR_NOSUPPORT;
    } else if (UNIT_TYPE_GRADE2 == type) {
      /*
       *  Note.
       *  This feature branches processing depending on the unit type.
       */
        ret = POS_RET_ERROR_NOSUPPORT;
    } else {
        /* Environment error */
        ret = POS_RET_ERROR_NOSUPPORT;
    }
    FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "- [ret = %d]", ret);
    return ret;
}

/**
 * @brief
 *  GPS time setting request delivery registration
 *
 *  Register delivery of GPS time setting request
 *
 * @param[in] hApp          HANDLE  - Application handle
 * @param[in] notifyName    PCSTR   - Destination thread name
 * @param[in] ucCtrlFlg     uint8_t - Delivery control(Delivery registration/Delivery stop/Resume delivery)
 *
 * @return POS_RET_NORMAL               Normal completion(Include illegal)<br>
 *         POS_RET_ERROR_BUFFULL        Buffer-full<br>
 *         POS_RET_ERROR_INNER          Internal error<br>
 *         POS_RET_ERROR_PARAM          Parameter error<br>
 *         POS_RET_ERROR_NOSUPPORT      Unsupported environment
 *
 */
POS_RET_API POS_RegisterListenerGPSTimeSetReq(HANDLE hApp,  // NOLINT(readability/nolint)
                                            PCSTR notifyName,  // NOLINT(readability/nolint)
                                            uint8_t ucCtrlFlg) {  // NOLINT(readability/nolint)
    POS_RET_API       ret = POS_RET_NORMAL;      /* Return value of this function */
    SENSOR_RET_API    ret_sens = SENSOR_RET_NORMAL;  /* API return value */
    UNIT_TYPE         type = UNIT_TYPE_NONE;      /* Supported HW Configuration Type */

    /* Internal debug log output */
    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+");

    /* Arguments & Support Configuration Check */
    if ((hApp == NULL) || (notifyName == NULL)) {
        ret = POS_RET_ERROR_PARAM;
    } else if (SENSOR_DELIVERY_REGIST != ucCtrlFlg) {
        /* Parameter error other than delivery registration */
        ret = POS_RET_ERROR_PARAM;
    } else {
        /* Positioning Base API initialization */
        _pb_Setup_CWORD64_API(hApp);

        /* Supported HW Configuration Check */
        type = GetEnvSupportInfo();
        if (UNIT_TYPE_GRADE1 == type) {
            /* GRADE1 */
            ret = POS_RET_NORMAL;
        } else if (UNIT_TYPE_GRADE2 == type) {
          /*
           *  Note.
           *  This feature branches processing depending on the unit type.
           */
            ret = POS_RET_ERROR_NOSUPPORT;
        } else {
            /* Environment error */
            ret = POS_RET_ERROR_NOSUPPORT;
        }
    }

    /* Delivery registration */
    if (POS_RET_NORMAL == ret) {
        /* Delivery registry SensorAPI calls */
        ret_sens = PosRegisterListenerProc(notifyName,                         /* Destination thread name */
                                           VEHICLE_DID_SETTINGTIME,            /* Data ID */
                                           ucCtrlFlg,                          /* Delivery control */
                                           VEHICLE_DELIVERY_TIMING_UPDATE);    /* Delivery timing */

        /* Decision of delivery registration result */
        if (ret_sens == SENSOR_RET_NORMAL) {
            ret = POS_RET_NORMAL;
        } else if (ret_sens == SENSOR_RET_ERROR_PARAM) {
            ret = POS_RET_ERROR_PARAM;
        } else if (ret_sens == SENSOR_RET_ERROR_BUFFULL) {
            ret = POS_RET_ERROR_BUFFULL;
        } else if (ret_sens == SENSOR_RET_ERROR_RESOURCE) {
            ret = POS_RET_ERROR_RESOURCE;
        } else {
            ret = POS_RET_ERROR_INNER;
        }
    }
    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "- [ret = %d]", ret);
    return ret;
}

/**
 * @brief
 *  GPS time setting
 *
 *  Set the GPS time
 *
 * @param[in] hApp          HANDLE        - Application handle
 * @param[in] pstDateTime   POS_DATETIME  - Pointer to GPS time information
 *
 * @return POS_RET_NORMAL               Normal completion(Include illegal)<br>
 *         POS_RET_ERROR_INNER          Internal error<br>
 *         POS_RET_ERROR_TIMEOUT        Timeout error<br>
 *         POS_RET_ERROR_PARAM          Parameter error<br>
 *         POS_RET_ERROR_NOSUPPORT      Unsupported environment
 *
 */
//POS_RET_API POS_SetGPStime(HANDLE hApp, POS_DATETIME* pstDateTime) {  // NOLINT(readability/nolint)
//    POS_RET_API    ret = POS_RET_NORMAL;     /* Return value of this function */
//    UNIT_TYPE      type = UNIT_TYPE_NONE;    /* Supported HW Configuration Type */
//
//    FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "+");
//
//    /* Arguments & Support Configuration Check */
//    if ((pstDateTime == NULL) || (hApp == NULL)) {
//        ret = POS_RET_ERROR_PARAM;
//    } else {
//        /* Positioning Base API initialization */
//        _pb_Setup_CWORD64_API(hApp);
//
//        /* Supported HW Configuration Check */
//        type = GetEnvSupportInfo();
//        if (UNIT_TYPE_GRADE1 == type) {
//            /* GRADE1 */
//            ret = POS_RET_NORMAL;
//        } else if (UNIT_TYPE_GRADE2 == type) {
//          /*
//           *  Note.
//           *  This feature branches processing depending on the unit type.
//           */
//            ret = POS_RET_ERROR_NOSUPPORT;
//        } else {
//            /* Environment error */
//            ret = POS_RET_ERROR_NOSUPPORT;
//        }
//    }
//
//    if (ret == POS_RET_NORMAL) {
//        /* Parameter range check */
//        /* Month */
//        if (POS_RET_ERROR == POS_CHKPARAMU8(pstDateTime->month, 1, 12)) {
//            return POS_RET_ERROR_PARAM;
//        }
//        /* Day */
//        if (POS_RET_ERROR == POS_CHKPARAMU8(pstDateTime->date, 1, 31)) {
//            return POS_RET_ERROR_PARAM;
//        }
//        /* Hour */
//        if (POS_RET_ERROR == POS_CHKPARAMU8(pstDateTime->hour, 0, 23)) {
//            return POS_RET_ERROR_PARAM;
//        }
//        /* Minutes */
//        if (POS_RET_ERROR == POS_CHKPARAMU8(pstDateTime->minute, 0, 59)) {
//            return POS_RET_ERROR_PARAM;
//        }
//        /* Second */
//        if (POS_RET_ERROR == POS_CHKPARAMU8(pstDateTime->second, 0, 59)) {
//            return POS_RET_ERROR_PARAM;
//        }
//
//        /* Data setting(Immediate recovery)*/
//        ret = PosSetProc(VEHICLE_DID_SETTINGTIME,
//                         reinterpret_cast<void*>(pstDateTime), sizeof(POS_DATETIME), FALSE);
//    }
//
//    FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "- [ret = %d]", ret);
//    return ret;
//}

/**
 * @brief
 *  GPS Time Delivery Registration
 *
 *  Registering GPS time delivery
 *
 * @param[in]  hApp          HANDLE  - Application handle
 * @param[in]  nofifyName      PCSTR   - Destination thread name
 * @param[in]  ucCtrlFlg      uint8_t - Delivery control(Delivery registration/Delivery stop/Resume delivery)
 * @param[in]  ucDeliveryTiming   uint8_t - Delivery timing(Changing/Updating)
 *
 * @return  SENSOR_RET_NORMAL               Successful registration<br>
 *      SENSOR_RET_ERROR_CREATE_EVENT   Event generation failure<br>
 *      SENSOR_RET_ERROR_PARAM          Parameter error<br>
 *      SENSOR_RET_ERROR_BUFFULL        FULL of delivery registers<br>
 *          SENSOR_RET_ERROR_NOSUPPORT      Unsupported environment
 *
 */
SENSOR_RET_API POS_RegisterListenerGPStime(HANDLE hApp,  // NOLINT(readability/nolint)
                                           PCSTR notifyName,  // NOLINT(readability/nolint)
                                           uint8_t ucCtrlFlg,  // NOLINT(readability/nolint)
                                           uint8_t ucDeliveryTiming) {  // NOLINT(readability/nolint)
    SENSOR_RET_API  ret = SENSOR_RET_NORMAL;
    UNIT_TYPE       type = UNIT_TYPE_NONE;

    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+");

    if (hApp == NULL) {
        /* Parameter error */
        ret = SENSOR_RET_ERROR_PARAM;
    } else {
        /* Positioning Base API initialization */
        _pb_Setup_CWORD64_API(hApp);

        /* Supported HW Configuration Check */
        type = GetEnvSupportInfo();
        if (UNIT_TYPE_GRADE1 == type) {
            /* GRADE1 */
            ret = SENSOR_RET_NORMAL;
        } else if (UNIT_TYPE_GRADE2 == type) {
          /*
           *  Note.
           *  This feature branches processing depending on the unit type.
           */
            ret = SENSOR_RET_ERROR_NOSUPPORT;
        } else {
            /* fail */
            ret = SENSOR_RET_ERROR_NOSUPPORT;
        }
    }

    if (SENSOR_RET_NORMAL == ret) {
        if (notifyName == NULL) {
            /* Parameter error */
            ret = SENSOR_RET_ERROR_PARAM;
        }
        if (ucCtrlFlg != SENSOR_DELIVERY_REGIST) {
            /* Parameter error */
            ret = SENSOR_RET_ERROR_PARAM;
        }
        if ((ucDeliveryTiming != SENSOR_DELIVERY_TIMING_CHANGE) &&
            (ucDeliveryTiming != SENSOR_DELIVERY_TIMING_UPDATE)) {
            /* Parameter error */
            ret = SENSOR_RET_ERROR_PARAM;
        }
    }

    if (SENSOR_RET_NORMAL == ret) {
        /* Delivery registration process */
        ret = PosRegisterListenerProc(notifyName, VEHICLE_DID_GPS_TIME, ucCtrlFlg, ucDeliveryTiming);
    }

    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "- [ret = %d]", ret);
    return ret;
}

/**
 * @brief
 *  Get GPS time
 *
 *  Get the GPS time
 *
 * @param[in] hApp   HANDLE         - Application handle
 * @param[in] *dat   SENSOR_GPSTIME - Pointer to GPS time information
 *
 * @return POS_RET_NORMAL               Normal completion(Include illegal)<br>
 *         POS_RET_ERROR_INNER          Internal error<br>
 *         POS_RET_ERROR_PARAM          Parameter error<br>
 *         POS_RET_ERROR_NOSUPPORT      Unsupported environment
 *
 */
//POS_RET_API POS_GetGPStime(HANDLE hApp, SENSOR_GPSTIME* dat) {  // NOLINT(readability/nolint)
//    POS_RET_API ret = POS_RET_NORMAL;          /* Return value */
//    UNIT_TYPE   type = UNIT_TYPE_NONE;         /* Supported HW Configuration Type */
//    DID         did = VEHICLE_DID_GPS_TIME;    /* DID */
//    int32       ret_get_proc;                  /* POS_GetProc Return Values */
//
//    /* Internal debug log output */
//    FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "+");
//
//    /* Arguments & Support Configuration Check */
//    if (hApp == NULL) {
//        /* If the handler is NULL, the process terminates with an error. */
//        ret = POS_RET_ERROR_PARAM;
//    } else if (dat == NULL) {
//        /* If the longitude/latitude data is NULL, it ends with an abnormal parameter. */
//        ret = POS_RET_ERROR_PARAM;
//    } else {
//        /* Positioning Base API initialization */
//        _pb_Setup_CWORD64_API(hApp);
//
//        /* Supported HW Configuration Check */
//        type = GetEnvSupportInfo();
//        if (UNIT_TYPE_GRADE1 == type) {
//            ret = POS_RET_NORMAL;
//        } else {
//          /*
//           *  Note.
//           *  This feature branches processing depending on the unit type.
//           */
//            ret = POS_RET_ERROR_NOSUPPORT;
//        }
//    }
//
//    /* Sensor information acquisition */
//    if (ret == POS_RET_NORMAL) {
//        /* Data acquisition process */
//        ret_get_proc = PosGetProc(did, reinterpret_cast<void*>(dat), sizeof(SENSOR_GPSTIME));
//        if (static_cast<int32>(sizeof(SENSOR_GPSTIME)) > ret_get_proc) {
//            /** Failed to acquire */
//            if (ret_get_proc == POS_RET_ERROR_RESOURCE) {
//                /** Insufficient resource */
//                ret = POS_RET_ERROR_RESOURCE;
//            } else {
//                ret = POS_RET_ERROR_INNER;
//            }
//            FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PosGetProc ERROR [ret = %d]", ret);
//        }
//    }
//
//    FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "- [ret = %d]", ret);
//
//    return ret;
//}