summaryrefslogtreecommitdiffstats
path: root/positioning/client/src/POS_sensor_API/Sensor_API.cpp
blob: 179eb92680be7389d8aee712fff82953ea2ea433 (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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
/*
 * @copyright Copyright (c) 2016-2020 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 name        :Sensor_API.cpp
 *    System name        :GPF
 *    Subsystem name    :Sensor I/F library
 *    Program name    :SensorI/F API
 ******************************************************************************/

#include <stdio.h>
#include <vehicle_service/POS_sensor_API.h>
#include <vehicle_service/POS_define.h>
#include <vehicle_service/POS_sensor_API.h>
#include <vehicle_service/positioning_base_library.h>
#include "POS_sensor_private.h"
#include "Sensor_Common_API.h"
#include "Sensor_API_private.h"
#include "Sensor_Common_API.h"
#include "Vehicle_API_Dummy.h"
#include "Vehicle_API_private.h"
#include "Naviinfo_API.h"
#include "POS_private.h"

/*************************************************/
/*           Global variable                      */
/*************************************************/
/********************************************************************************
 * TAG      :TG_GPS_REQ_RESET
 * ABSTRACT :GPS reset request
 * NOTE     :I/F information between host applications(Reset mode)
 ********************************************************************************/
/**
 * @brief    POS_RegisterListenerPkgSensData Return code list
 */
static const SENSOR_RET_PKG g_ret_list_reg_lis_pkg_sens_data[SENSOR_PUBLIC_DID_NUM] = {
    /* GRADE2   GRADE1     DID (Key)     */
    {TRUE,      TRUE,     POS_DID_SPEED_PULSE        },
    {FALSE,     TRUE,     POS_DID_SPEED_KMPH         },
    {TRUE,      TRUE,     POS_DID_GYRO_X             },
    {TRUE,      TRUE,     POS_DID_GYRO_Y             },
    {TRUE,      TRUE,     POS_DID_GYRO_Z             },
    {TRUE,      TRUE,     POS_DID_GSNS_X             },
    {TRUE,      TRUE,     POS_DID_GSNS_Y             },
    {TRUE,      TRUE,     POS_DID_GSNS_Z             },
    {FALSE,     TRUE,     POS_DID_GPS_ANTENNA        },
    {TRUE,      TRUE,     POS_DID_SNS_COUNTER        },
    {FALSE,     TRUE,     POS_DID_SPEED_PULSE_FST    },
    {FALSE,     TRUE,     POS_DID_GYRO_X_FST         },
    {FALSE,     TRUE,     POS_DID_GYRO_Y_FST         },
    {FALSE,     TRUE,     POS_DID_GYRO_Z_FST         },
    {FALSE,     TRUE,     POS_DID_GPS__CWORD82__NMEA },
    {FALSE,     TRUE,     POS_DID_GPS__CWORD82___CWORD44_GP4   },
    {FALSE,     TRUE,     POS_DID_GPS__CWORD82__FULLBINARY },
    {FALSE,     TRUE,     POS_DID_GPS_NMEA           },
    {TRUE,      TRUE,     POS_DID_REV                },
    {FALSE,     TRUE,     POS_DID_REV_FST            },
    {TRUE,      TRUE,     POS_DID_GYRO_TEMP          },
    {FALSE,     TRUE,     POS_DID_GYRO_TEMP_FST      },
    {FALSE,     TRUE,     POS_DID_GSNS_X_FST         },
    {FALSE,     TRUE,     POS_DID_GSNS_Y_FST         },
    {FALSE,     TRUE,     POS_DID_GSNS_Z_FST         },
    {TRUE,      TRUE,     POS_DID_PULSE_TIME         },
    {FALSE,     TRUE,     POS_DID_GPS_CLOCK_DRIFT    },
    {FALSE,     TRUE,     POS_DID_GPS_CLOCK_FREQ     },
    {FALSE,     TRUE,     VEHICLE_DID_GPS_TIME       }, /* For local use */
    {FALSE,     TRUE,     VEHICLE_DID_GPS_TIME_RAW   }, /* For local use */
    {FALSE,     TRUE,     VEHICLE_DID_GPS_WKNROLLOVER}  /* For local use */
};

/**
 * @brief    POS_RegisterListenerSensData Return code list
 */
static const SENSOR_RET_PKG g_ret_list_reg_lis_sens_data[SENSOR_PUBLIC_DID_NUM] = {
    /* GRADE2   GRADE1     DID (Key)     */
    {TRUE,      TRUE,      POS_DID_SPEED_PULSE        },
    {FALSE,     TRUE,      POS_DID_SPEED_KMPH         },
    {TRUE,      TRUE,      POS_DID_GYRO_X             },
    {TRUE,      TRUE,      POS_DID_GYRO_Y             },
    {TRUE,      TRUE,      POS_DID_GYRO_Z             },
    {TRUE,      TRUE,      POS_DID_GSNS_X             },
    {TRUE,      TRUE,      POS_DID_GSNS_Y             },
    {TRUE,      TRUE,      POS_DID_GSNS_Z             },
    {TRUE,      TRUE,      POS_DID_GPS_ANTENNA        },
    {FALSE,     TRUE,      POS_DID_SNS_COUNTER        },
    {TRUE,      TRUE,      POS_DID_SPEED_PULSE_FST    },
    {TRUE,      TRUE,      POS_DID_GYRO_X_FST         },
    {TRUE,      TRUE,      POS_DID_GYRO_Y_FST         },
    {TRUE,      TRUE,      POS_DID_GYRO_Z_FST         },
    {TRUE,      TRUE,      POS_DID_GPS__CWORD82__NMEA },
    {FALSE,     TRUE,      POS_DID_GPS__CWORD82___CWORD44_GP4   },
    {TRUE,      TRUE,      POS_DID_GPS__CWORD82__FULLBINARY },
    {FALSE,     TRUE,      POS_DID_GPS_NMEA           },
    {FALSE,     TRUE,      POS_DID_REV                },
    {TRUE,      TRUE,      POS_DID_REV_FST            },
    {TRUE,      TRUE,      POS_DID_GYRO_TEMP          },
    {TRUE,      TRUE,      POS_DID_GYRO_TEMP_FST      },
    {TRUE,      TRUE,      POS_DID_GSNS_X_FST         },
    {TRUE,      TRUE,      POS_DID_GSNS_Y_FST         },
    {TRUE,      TRUE,      POS_DID_GSNS_Z_FST         },
    {FALSE,     TRUE,      POS_DID_PULSE_TIME         },
    {FALSE,     TRUE,      POS_DID_GPS_CLOCK_DRIFT    },
    {FALSE,     TRUE,      POS_DID_GPS_CLOCK_FREQ     },
    {FALSE,     TRUE,      VEHICLE_DID_GPS_TIME           }, /* For local use */
    {FALSE,     TRUE,      VEHICLE_DID_GPS_TIME_RAW       }, /* For local use */
    {FALSE,     TRUE,      VEHICLE_DID_GPS_WKNROLLOVER    }  /* For local use */
};

/**
 * @brief    POS_GetSensData Return code list
 */
static const SENSOR_RET_PKG g_ret_list_get_sens_data[SENSOR_PUBLIC_DID_NUM] = {
    /* GRADE2   GRADE1     DID (Key)     */
    {TRUE,      TRUE,      POS_DID_SPEED_PULSE        },
    {FALSE,     TRUE,      POS_DID_SPEED_KMPH         },
    {TRUE,      TRUE,      POS_DID_GYRO_X             },
    {TRUE,      TRUE,      POS_DID_GYRO_Y             },
    {TRUE,      TRUE,      POS_DID_GYRO_Z             },
    {TRUE,      TRUE,      POS_DID_GSNS_X             },
    {TRUE,      TRUE,      POS_DID_GSNS_Y             },
    {TRUE,      TRUE,      POS_DID_GSNS_Z             },
    {TRUE,      TRUE,      POS_DID_GPS_ANTENNA        },
    {FALSE,     TRUE,      POS_DID_SNS_COUNTER        },
    {FALSE,     TRUE,      POS_DID_SPEED_PULSE_FST    },
    {FALSE,     TRUE,      POS_DID_GYRO_X_FST         },
    {FALSE,     TRUE,      POS_DID_GYRO_Y_FST         },
    {FALSE,     TRUE,      POS_DID_GYRO_Z_FST         },
    {TRUE,      TRUE,      POS_DID_GPS__CWORD82__NMEA       },
    {FALSE,     TRUE,      POS_DID_GPS__CWORD82___CWORD44_GP4   },
    {TRUE,      TRUE,      POS_DID_GPS__CWORD82__FULLBINARY },
    {FALSE,     TRUE,      POS_DID_GPS_NMEA           },
    {FALSE,     TRUE,      POS_DID_REV                },
    {FALSE,     TRUE,      POS_DID_REV_FST            },
    {TRUE,      TRUE,      POS_DID_GYRO_TEMP          },
    {FALSE,     TRUE,      POS_DID_GYRO_TEMP_FST      },
    {FALSE,     TRUE,      POS_DID_GSNS_X_FST         },
    {FALSE,     TRUE,      POS_DID_GSNS_Y_FST         },
    {FALSE,     TRUE,      POS_DID_GSNS_Z_FST         },
    {FALSE,     TRUE,      POS_DID_PULSE_TIME         },
    {FALSE,     TRUE,      POS_DID_GPS_CLOCK_DRIFT    },
    {FALSE,     TRUE,      POS_DID_GPS_CLOCK_FREQ     },
    {FALSE,     TRUE,      VEHICLE_DID_GPS_TIME           }, /* For local use */
    {FALSE,     TRUE,      VEHICLE_DID_GPS_TIME_RAW       }, /* For local use */
    {FALSE,     TRUE,      VEHICLE_DID_GPS_WKNROLLOVER    }  /* For local use */
};

/**
 * @brief
 *   DID-decision functions for Sensor API
 *
 *    Determines whether or not the DID specified by the public API corresponds to the DID.
 *
 * @param[in]     did    Data ID
 * @param[in]    mode    Operation mode 1:For Package Delivery Registration API<br>
 *                                 2:For Sensor Data Delivery Registration API<br>
 *                                 3:For Sensor Data Acquisition API
 *
 * @return    TRUE    Be supported
 *             FALSE    Not supported
 */
BOOL SensorJudgeDid(DID did, uint8_t mode) {
    BOOL                    ret = FALSE;
    UNIT_TYPE               type;
    const SENSOR_RET_PKG    *pkg_list = NULL;
    int32_t i;

    /* Set Return pakage list */
    switch (mode) {
        case MODE_REGISTER_LISTENER_PKG_SENS_DATA: /* POS_RegisterListenerPkgSensData */
        {
            pkg_list = g_ret_list_reg_lis_pkg_sens_data;
            break;
        }
        case MODE_REGISTER_LISTENER_SENSDATA: /* POS_RegisterListenerSensData */
        {
            pkg_list = g_ret_list_reg_lis_sens_data;
            break;
        }
        case MODE_GET_SENSDATA: /* POS_GetSensData */
        {
            pkg_list = g_ret_list_get_sens_data;
            break;
        }
        default:
            /* Error log */
            FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [mode = %d]", mode);
            break;
    }

    if (pkg_list != NULL) {
        /* Search Return code list for DID */
        for (i = 0; i < SENSOR_PUBLIC_DID_NUM; i++) {
            if (did == pkg_list[i].did) {
                break;
            }
        }

        if (i != SENSOR_PUBLIC_DID_NUM) {
            /* Get Unit type */
            type = GetEnvSupportInfo();
            switch (type) {
                case UNIT_TYPE_GRADE1:
                {
                    ret = pkg_list[i].GRADE1_ret;
                    break;
                }
                case UNIT_TYPE_GRADE2:
                {
                    /*
                     *  Note.
                     *  This feature branches processing depending on the unit type.
                     */
                    ret = pkg_list[i].GRADE2_ret;
                    break;
                }
                default:
                    /* Error log */
                    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
                                  "GetEnvSupportInfo ERROR [type = %d]", type);
                    break;
            }
        } else {
            /* Error log */
            FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [did = %d]", did);
        }
    }

    return ret;
}

/**
 * @brief
 *    Vehicle Sensor Information Extended Package Delivery Registration
 *  Sensor information is delivered for the first time.,Extension Packaging and Registering for Delivery.
 *
 * @param[in]  hApp                    Application handle
 * @param[in]  notifyName            Destination thread name
 * @param[in]  ucPkgNum                Number of package data(1 to 16)
 * @param[in]  *pulDid                Pointer to an array of data IDs for vehicle information
 * @param[in]  ucCtrlFlg            Delivery control<br>
 *                Delivery registration: SENSOR_DELIVERY_REGIST<br>
 *                Delivery stop: SENSOR_DELIVERY_STOP        (Note: Not mounted)<br>
 *                Resume delivery: SENSOR_DELIVERY_RESTART    (Note: Not mounted)
 * @param[in]  ucDeliveryTiming        Delivery timing<br>
 *                Updating    : SENSOR_DELIVERY_TIMING_UPDATE<br>
 *                Changing    : SENSOR_DELIVERY_TIMING_CHANGE
 *
 * @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_DID            Unregistered ID<br>
 *            SENSOR_RET_ERROR_BUFFULL        FULL of delivery registers<br>
 *            SENSOR_RET_ERROR_NOSUPPORT        Unsupported environment<br>
 *            SENSOR_RET_ERROR_INNER            Internal abnormality
 *
 */
SENSOR_RET_API POS_RegisterListenerPkgSensData(HANDLE hApp,
                                               PCSTR notifyName,
                                               uint8_t ucPkgNum,
                                               DID *pulDid, uint8_t ucCtrlFlg, uint8_t ucDeliveryTiming) {
    SENSOR_RET_API                   ret;            /* Return value */
    BOOL                             ret_b;
    RET_API                          ret_api;      /* System API return value */
    EventID                          event_id;     /* Event ID */
    int32_t                          event_val;    /* Event value */
    SENSOR_MSG_DELIVERY_ENTRY_DAT    data;         /* Message data */
    int32_t                          i;            /* Generic counters */
    PNO                              ch_pno;       /* Converted internal PNO    */
    UNIT_TYPE                        type;         /* Supported HW Configuration Type    */

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

    ret = SENSOR_RET_NORMAL;
    /* Check Handle */
    if (hApp == NULL) {
        /* NULL terminates with an abnormal parameter */
        ret = SENSOR_RET_ERROR_PARAM;
    }

    if (ret == SENSOR_RET_NORMAL) {
        /* 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 {
            /* Environment error */
            ret = SENSOR_RET_ERROR_NOSUPPORT;
        }
    }

    if (ret == SENSOR_RET_NORMAL) {
        /* Check Delivery Control Designation */
        if (SENSOR_DELIVERY_REGIST != ucCtrlFlg) {
            /* Parameters other than delivery registration terminated abnormally. */
            ret = SENSOR_RET_ERROR_PARAM;
        } else if ((ucDeliveryTiming != SENSOR_DELIVERY_TIMING_CHANGE) &&
                   (ucDeliveryTiming != SENSOR_DELIVERY_TIMING_UPDATE)) {
            /* Check delivery timing */
            /* Change delivery timing,Terminate as a parameter error except update */
            ret = SENSOR_RET_ERROR_PARAM;
        } else if (notifyName == NULL) {
            /* Check Thread Name */
            /* NULL terminates with an abnormal parameter */
            ret = SENSOR_RET_ERROR_PARAM;
        } else if ((0 == ucPkgNum) || (SENSOR_PKG_DELIVERY_MAX < ucPkgNum)) {
            /* Check Package Data Count */
            /* Out-of-range is terminated as a parameter error. */
            ret = SENSOR_RET_ERROR_PARAM;
        } else if (pulDid == NULL) {
            /* Check Data ID */
            /* NULL terminates with an abnormal parameter */
            ret = SENSOR_RET_ERROR_PARAM;
        } else {
            /* Check if data ID is acceptable */
            for (i = 0; i < ucPkgNum; i++) {
                /* Judge DID */
                ret_b = SENSOR_DID_JUDGE_REGLIS_PKG(pulDid[i]);
                if (ret_b == FALSE) {
                    /* An unacceptable ID terminates with an abnormal parameter. */
                    ret = SENSOR_RET_ERROR_PARAM;
                    break;
                } else {
                    ret = SENSOR_RET_NORMAL;
                }
            }
        }
    }

    if (ret == SENSOR_RET_NORMAL) {
        /* Resource acquisition */
        if (VehicleGetResource() == TRUE) {

        /* Initialization */
        event_id = 0;
        event_val = 0;
        memset(reinterpret_cast<void *>(&data), 0, sizeof(SENSOR_MSG_DELIVERY_ENTRY_DAT));

        /* Get PNO from Thread Name */
        ch_pno = _pb_CnvName2Pno(notifyName);

        /* Event Generation */
        event_id = PosCreateEvent(ch_pno);

        if (0 != event_id) {
            /* Successful event generation */

            /*--------------------------------------------------------------*
             *    Send Vehicle Sensor Information Delivery Registration Message                    *
             *--------------------------------------------------------------*/
            /* Create Message Data */
            data.pno             = ch_pno;
            data.pkg_num         = ucPkgNum;
            data.delivery_timing = ucDeliveryTiming;
            data.ctrl_flg        = ucCtrlFlg;
            data.event_id        = event_id;
            for (i = 0; i < ucPkgNum; i++) {
                data.did[i] = pulDid[i];
            }

            /* Messaging */
            ret_api = PosSndMsg(ch_pno,
                                PNO_VEHICLE_SENSOR,
                                CID_SENSORIF_PKG_DELIVERY_ENTRY_EXT,
                                (uint16_t)sizeof(SENSOR_MSG_DELIVERY_ENTRY_DAT),
                                (const void *)&data);

            if (RET_NORMAL == ret_api) {
                /* Message transmission processing is successful */
                /* Wait for completion event from vehicle sensor thread */
                ret_api = _pb_WaitEvent(event_id,
                                        SAPI_EVWAIT_VAL,
                                        SENSOR_RET_ERROR_MIN,
                                        SENSOR_RET_NORMAL,
                                        &event_val,
                                        POS_API_TIME_OUT_MS);
                if (RET_NORMAL != ret_api) {
                    /* Return an internal error */
                    ret = SENSOR_RET_ERROR_INNER;
                } else {
                    /* Return from Event Wait */
                    /* Set event value (processing result) as return value */
                    ret = (SENSOR_RET_API)event_val;
                }
            } else {
                /* Message transmission processing failed */
                /* Return an internal error */
                ret = SENSOR_RET_ERROR_INNER;
            }

            /* Event deletion */
            ret_api = PosDeleteEvent(event_id);
        } else {
            /* Event generation failure */
            ret = SENSOR_RET_ERROR_CREATE_EVENT;
        }
        } else {
            /* When resource shortage occurs, the system terminates with an insufficient resource error. */
            ret = SENSOR_RET_ERROR_RESOURCE;
        }
        /* Resource release */
        VehicleReleaseResource();
    }

    /* Internal debug log output */
    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "- [ret = %d]", ret);

    return ret;
}

/*******************************************************************************
 * MODULE    : PosCreateEvent
 * ABSTRACT  : Event creation process
 * FUNCTION  : Generate an event
 * ARGUMENT  : pno        : Thread ID
 * NOTE      :
 * RETURN    : Non-zero        : Event ID
 *           : Zero            : Event generation failure
 ******************************************************************************/
EventID PosCreateEvent(PNO pno) {
    EventID    event_id;          /* Event ID */
    char       event_name[32];    /* Event name character string buffer */
    RET_API    ret_api;           /* System API return value */

    /* Initialization of event name character string buffer */
    (void)memset(reinterpret_cast<void *>(event_name), 0, sizeof(event_name));

    /* Event name creation */
    snprintf(event_name, sizeof(event_name), "SENSOR_%X", pno);    /* Ignore->MISRA-C++:2008 Rule 5-2-12 */

    /* Event Generation */
    event_id = _pb_CreateEvent(FALSE , 0, event_name);    /* Ignore->MISRA-C++:2008 Rule 5-2-12 */

    if (0 != event_id) {
        /* For successful event generation */

        /* Initialize the event */
        ret_api = _pb_SetEvent(event_id, SAPI_EVSET_ABSOLUTE, SENSOR_EVENT_VAL_INIT);
        if (RET_NORMAL != ret_api) {
            /* Event initialization failed */

            /* Delete Event and Return Event Generation Failed */
            ret_api = PosDeleteEvent(event_id);
            event_id = 0;
        }
    }

    return event_id;
}

/*******************************************************************************
 * MODULE    : PosDeleteEvent
 * ABSTRACT  : Event deletion processing
 * FUNCTION  : Delete events
 * ARGUMENT  : event_id    : Event ID of the event to delete
 * NOTE      :
 * RETURN    : RET_NORMAL    : Normal completion
 *           : RET_EV_NONE    : Specified event does not exist
 ******************************************************************************/
RET_API PosDeleteEvent(EventID event_id) {
    return(_pb_DeleteEvent(event_id));
}

/*******************************************************************************
 * MODULE    : SensorLinkShareData
 * ABSTRACT  : Link to shared memory
 * FUNCTION  : Link to shared memory
 * ARGUMENT  : **share_top    : Storage destination of shared memory top address
 *           : *share_size    : Storage destination of shared memory area size
 *           : *offset    : Offset storage destination to free shared memory area
 * NOTE      :
 * RETURN    : RET_NORMAL    : Normal completion
 *           : RET_ERROR    : There is no shared memory area.
 ******************************************************************************/
RET_API SensorLinkShareData(void **share_top, uint32_t *share_size, uint16_t *offset) {  // LCOV_EXCL_START 8:dead code
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    RET_API         ret_api;    /* System API return value */
    SemID           sem_id;     /* Semaphore ID */
    SENSOR_SHARE    *share_top_tmp;
    int32_t         i;

    /* Initialization */
    ret_api = RET_ERROR;

    /* Create Semaphore */
    sem_id = _pb_CreateSemaphore(const_cast<char *>(SENSOR_SEMAPHO_NAME));
    if (0 != sem_id) {
        /* Semaphore Lock */
        ret_api = _pb_SemLock(sem_id);
        if (RET_NORMAL == ret_api) {
            /* Link to shared memory */
            ret_api = _pb_LinkShareData(const_cast<char *>(SENSOR_SHARE_NAME), share_top, share_size);
            if (RET_NORMAL == ret_api) {
                /* By searching the free shared memory area,Offset is calculated if there is free space. */
                share_top_tmp = reinterpret_cast<SENSOR_SHARE *>(*share_top);

                /* Because the first block of the shared memory area is the control area,Loop from i = 1 */
                for (i = 1; i < SENSOR_SHARE_BLOCK_NUM; i++) {
                    if (SENSOR_SHARE_UNLOCK == share_top_tmp->mng.lock_info[i]) {
                        break;
                    }
                }
                if (i < SENSOR_SHARE_BLOCK_NUM) {
                    /* Empty space */
                    /* Lock the block */
                    share_top_tmp->mng.lock_info[i] = SENSOR_SHARE_LOCK;

                    /* Calculate the offset to the block */
                    *offset = static_cast<uint16_t>(i * SENSOR_SHARE_BLOCK_SIZE);

                    /* Normal completion */
                    ret_api = RET_NORMAL;
                } else {
                    /* No free space */
                    ret_api = RET_ERROR;
                }
            } else {
                /* Failed link to shared memory */
                ret_api = RET_ERROR;
            }
            /* Semaphore unlock */
            _pb_SemUnlock(sem_id);
        } else {
            /* Semaphore lock failed */
            ret_api = RET_ERROR;
        }
    } else {
        /* Semaphore creation failed */
        ret_api = RET_ERROR;
    }

    return ret_api;
}
// LCOV_EXCL_STOP

/*******************************************************************************
 * MODULE    : SensorUnLinkShareData
 * ABSTRACT  : Unlinking shared memory
 * FUNCTION  : Unlink shared memory
 * ARGUMENT  : *share_top    : Start address of shared memory
 *           : offset        : Offset to shared memory free area
 * NOTE      :
 * RETURN    : RET_NORMAL    : Normal completion
 *           : RET_ERROR    : There is no shared memory area./semaphore error
 ******************************************************************************/
RET_API SensorUnLinkShareData(SENSOR_SHARE *share_top, uint16_t offset) {  // LCOV_EXCL_START 8:dead code
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    RET_API    ret_api;    /* System API return value */
    SemID      sem_id;     /* Semaphore ID */
    int32_t    i;

    /* Initialization */
    ret_api = RET_ERROR;

    /* Create Semaphore */
    sem_id = _pb_CreateSemaphore(const_cast<char *>(SENSOR_SEMAPHO_NAME));
    if (0 != sem_id) {
        /* Semaphore Lock */
        ret_api = _pb_SemLock(sem_id);
        if (RET_NORMAL == ret_api) {
            /* Unlock the block */
            i = static_cast<int32>(offset) / SENSOR_SHARE_BLOCK_SIZE;
            share_top->mng.lock_info[i] = SENSOR_SHARE_UNLOCK;

            /* Semaphore unlock */
            _pb_SemUnlock(sem_id);

            /* Normal completion */
            ret_api = RET_NORMAL;
        } else {
            /* Semaphore lock failed */
            ret_api = RET_ERROR;
        }
    } else {
        /* Semaphore creation failed */
        ret_api = RET_ERROR;
    }

    return ret_api;
}
// LCOV_EXCL_STOP

/*******************************************************************************
 * MODULE    : SensorSetShareData
 * ABSTRACT  : Write processing to shared memory
 * FUNCTION  : Write shared memory
 * ARGUMENT  : *share_top    : Start address of shared memory
 *           : offset        : Offsets to shared memory write destination
 *           : *data_src    :
             : size_src :
 * NOTE      :
 * RETURN    : void
 ******************************************************************************/
void SensorSetShareData(void *share_top, uint16_t offset, const void *data_src, uint16_t size_src) {  // LCOV_EXCL_START 8:dead code  // NOLINT(whitespace/line_length)
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    SENSOR_SHARE_BLOCK_DAT *share_dat;

    /* Calculate Shared Memory Write Address */
    share_dat = reinterpret_cast<SENSOR_SHARE_BLOCK_DAT *>(reinterpret_cast<uint8_t *>(share_top) + offset);
    /* #QAC confirmation Rule11.4 Use structure for member reference(Cast according to shared memory link IF) */

    /* Clear Shared Memory */
    memset(reinterpret_cast<void *>(share_dat), 0, sizeof(SENSOR_SHARE_BLOCK_DAT));

    /* Set write size to shared memory */
    share_dat->size = size_src;

    /* Set specified data in shared memory */
    memcpy(reinterpret_cast<void *>(&share_dat->data), data_src, (size_t)size_src);
}
// LCOV_EXCL_STOP

/*******************************************************************************
 * MODULE    : PosSndMsg
 * ABSTRACT  : Message transmission processing
 * FUNCTION  : Send a message to the specified PNO
 * ARGUMENT  : pno_src            : Source PNO
 *           : pno_dest        : Destination PNO
 *           : cid            : Command ID
 *           : msg_len            : Message data body length
 *           : *msg_len        : Pointer to message data
 * NOTE      :
 * RETURN    : RET_NORMAL        : Normal completion
 *           : RET_ERRNOTRDY    : Destination process is not wakeup
 *           : RET_ERRMSGFULL    : Message queue overflows
 *           : RET_ERRPARAM        : Buffer size error
 ******************************************************************************/
RET_API PosSndMsg(PNO pno_src, PNO pno_dest, CID cid, uint16_t msg_len, const void *msg_data) {
    SENSOR_INTERNAL_MSG_BUF   msg_buf;        /* message buffer */
    T_APIMSG_MSGBUF_HEADER    *msg_hdr;       /* Pointer to the message header */
    RET_API                   ret_api;        /* Return value */
    PCSTR                     thread_name;    /* Destination thread name                */

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

    /* _CWORD71_ processing speed(Memset modification) */
    /* Initializing the header of the message buffer */
    memset(reinterpret_cast<void *>(&msg_buf.hdr), 0, sizeof(T_APIMSG_MSGBUF_HEADER));

    /* Get pointer to send buffer */
    msg_hdr = reinterpret_cast<T_APIMSG_MSGBUF_HEADER *>(reinterpret_cast<void *>(&msg_buf));

    /*--------------------------------------------------------------*
     *    Create message headers                                    *
     *--------------------------------------------------------------*/
    msg_hdr->hdr.sndpno         = pno_src;    /* Source PNO */
    msg_hdr->hdr.cid            = cid;        /* Command ID */
    msg_hdr->hdr.msgbodysize    = msg_len;    /* Message data body length */

    /*--------------------------------------------------------------*
     *    Create message data                                    *
     *--------------------------------------------------------------*/
    if ((0 != msg_data) && (0 != msg_len)) {    /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
        /* Set the message data */
        memcpy(reinterpret_cast<void *>(msg_buf.data), msg_data, (size_t)msg_len);
    }
    /*--------------------------------------------------------------*
     * Send messages                                            *
     *--------------------------------------------------------------*/
    /* Get Thread Name from PNO */
    if (pno_dest <= SYS_PNO_MAX) {
        thread_name = POS_THREAD_NAME;
    } else {
        thread_name = _pb_CnvPno2Name(pno_dest);
    }

    if ((pno_dest <= SYS_PNO_MAX) && (pno_src <= SYS_PNO_MAX)) {
        /* Internal debug log output */
        FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "[LOG pno_dest = 0x%x]", pno_dest);

        /* Internal Process Transmission and Reception Messages */
        ret_api = _pb_SndMsg(pno_dest,
                             (uint16_t)(sizeof(T_APIMSG_MSGBUF_HEADER) + msg_len),/* Ignore->MISRA-C++:2008 Rule 5-0-5 */
                             reinterpret_cast<void *>(&msg_buf), 0);
    } else {
        /* Internal debug log output */
        FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, 
                      "[LOG thread_name = %s, cid = 0x%x]", thread_name, cid);

        /* External Process Transmission and Reception Messages */
        ret_api = _pb_SndMsg_Ext(thread_name,
                                 cid,
                                 (uint16_t)(msg_len),    /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
                                 reinterpret_cast<void *>(&(msg_buf.data)), 0);
    }
    /* If RET_ERROR,Register a dialog if called from a Vehicle related thread */ /* Task_30332 */
    if (ret_api == RET_ERROR) {
        FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "[ERROR]");
    }

    /* Internal debug log output */
    FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "- [ret = %d]", ret_api);

    return ret_api;
}

/**
 * @brief
 *  Sensor information acquisition
 *
 *  Obtain sensor information
 *
 * @param[in] hApp          HANDLE   - Application handle
 * @param[in] did         DID      - Data ID for vehicle information
 * @param[in] dest_data     void*    - Pointer representing the storage destination of vehicle sensor information
 * @param[in] dest_size    uint16_t - Storage destination size of vehicle sensor information(byte)
 *
 * @return  0 or more                        Stored data size(Include illegal)<br>
 *          POS_RET_ERROR_CREATE_EVENT   Event generation failure<br>
 *          POS_RET_ERROR_OUTOF_MEMORY   Shared memory allocation failed<br>
 *          POS_RET_ERROR_SIZE           Storage destination size error<br>
 *          POS_RET_ERROR_DID            Unregistered ID<br>
 *          POS_RET_ERROR_NOSUPPORT      Unsupported environment
 *
 */
POS_RET_API POS_GetSensData(HANDLE hApp, DID did, void *dest_data, uint16_t dest_size)
{
    POS_RET_API     ret;                               /* Return value */
    UNIT_TYPE       type = UNIT_TYPE_NONE;            /* Supported HW Configuration Type    */
    BOOL            ret_b;

    /** NULL checking */
    if ((hApp == NULL) || (dest_data == NULL)) {
        /** Parameter error */
        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 == NAVIINFO_RET_NORMAL) {
        /* Judge DID*/
        ret_b = SENSOR_DID_JUDGE_GET(did);
        if (ret_b == FALSE) {
            /* An unacceptable ID is regarded as a parameter error. */
            ret = POS_RET_ERROR_PARAM;
        } else {
            /* Data acquisition process */
            ret = PosGetProc(did, dest_data, dest_size);
        }
    }

    return ret;
}