Init basesystem source codes.
[staging/basesystem.git] / vehicleservice / positioning / server / src / nsfw / positioning_application.cpp
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * @file
19  *    positioning_application.cpp
20  * @brief
21  *   Module : POSITIONING
22  *   Implements Vehicle service functionality
23  */
24
25 /*---------------------------------------------------------------------------------*
26  * Include Files                                                                   *
27  *---------------------------------------------------------------------------------*/
28 #include <native_service/frameworkunified_application.h>
29 #include <native_service/frameworkunified_framework_if.h>
30 #include <native_service/frameworkunified_multithreading.h>
31 #include <native_service/frameworkunified_service_protocol.h>
32 #include <native_service/frameworkunified_types.h>
33 #include <native_service/ns_message_center_if.h>
34 #include <peripheral_service/ps_services.h>
35 #include <vehicle_service/POS_sensor_API.h>
36 #include <vehicle_service/POS_gps_API.h>
37 #include <system_service/ss_sm_client_if.h>
38 #include <vehicle_service/positioning_base_library.h>
39 #include <stub/vehicle_notifications.h>
40 #include <peripheral_service/communication_notifications.h>
41 #include <other_service/VP_GetEnv.h>
42 #include <cstdlib>
43 #include <iostream>
44
45 #include "SensorLog.h"
46 #include "positioning_common.h"
47 #include "POS_private.h"
48 #include "Gps_API_private.h"
49 #include "POS_common_private.h"
50 #include "Vehicle_API.h"
51 #include "Vehicle_API_private.h"
52 #include "Sensor_API_private.h"
53 #include "Naviinfo_API.h"
54 #include "VehicleSensor_Thread.h"
55 #include "ClockGPS_Process_Proto.h"
56 #include "VehicleSens_Common.h"
57 #include "VehicleSens_DataMaster.h"
58 #include "VehicleSens_DeliveryCtrl.h"
59 #include "VehicleUtility.h"
60 #include "BackupMgrIf.h"
61 #include "ClockIf.h"
62 #include "CommUsbIf.h"
63 #include "DevDetectSrvIf.h"
64 #include "DiagSrvIf.h"
65 #include "PSMShadowIf.h"
66 #include "VehicleIf.h"
67 #include "positioning_hal.h"
68 #include "gps_hal.h"
69 #include "CommonDefine.h"
70
71 #include "VehicleIf.h"
72
73 /*---------------------------------------------------------------------------------*
74  * Definition                                                                      *
75  *---------------------------------------------------------------------------------*/
76 #define DATMOD_RETRY    (3) /* Number of shared memory generation retries */
77 #define DATMOD_PREINIT  (0) /* Shared Memory State Before Initialization */
78 #define PRIM_NAME_MAX   (32) /* Maximum Name Size */
79
80 /* Mask for managing various notification reception conditions */
81 #define NTFY_MSK_NONE                       (0x00)
82 /* Service availability notification */
83 #define NTFY_MSK_COMMUNICATION_AVAILABILITY (0x01)
84 #define NTFY_MSK_PS_COMMUSB_AVAILABILITY    (0x02)
85 #define NTFY_MSK_PS_PSMSHADOW_AVAILABILITY  (0x04)
86 #define NTFY_MSK_CLOCK_AVAILABILITY         (0x08)
87 #define NTFY_MSK_NS_BACKUPMGR_AVAILABILITY  (0x10)
88 #define NTFY_MSK_SS_DEVDETSRV_AVAILABILITY  (0x20)
89 #define NTFY_MSK_VS_VEHICLE_AVAILABILITY    (0x40)
90 /* Other Notices */
91 #define NTFY_MSK_PS_PSMSHADOW_INIT_COMP     (0x01) /* PSMShadow startup completion notice           */
92
93 /* Thread state */
94 #define THREAD_STS_NOEXIST                  (0x00)
95 #define THREAD_STS_CREATING                 (0x01)
96 #define THREAD_STS_CREATED                  (0x02)
97
98 #define POS_SNDMSG_DTSIZE_1     1       /* SndMSG data size 1Byte  */
99 #define POS_SNDMSG_DTSIZE_2     2       /* SndMSG data size 2Byte  */
100 #define POS_SNDMSG_DTSIZE_20     20     /* SndMSG data size of 20 bytes  */
101 #define POS_SNDMSG_DTSIZE_132     132     /* SndMSG data size: 132 bytes  */
102
103 /* PositioningLogFlag */
104 #define POSITIONINGLOG_FLAG_NAVI 9
105
106 /* Definition for thinning out sensor log at anomaly */
107 #define POSITIONINGLOG_SYS_1_ABNORMAL_DATA_NUM  3
108 #define POSITIONINGLOG_SYS_2_ABNORMAL_DATA_NUM  4
109 #define POSITIONINGLOG_SYS_3_ABNORMAL_DATA_NUM  4
110 #define POSITIONINGLOG_SYS_4_ABNORMAL_DATA_NUM 129
111 #define POSITIONINGLOG_SYS_ABNORMAL_DATA_NUM (POSITIONINGLOG_SYS_1_ABNORMAL_DATA_NUM + \
112                                       POSITIONINGLOG_SYS_2_ABNORMAL_DATA_NUM + \
113                                       POSITIONINGLOG_SYS_3_ABNORMAL_DATA_NUM + \
114                                       POSITIONINGLOG_SYS_4_ABNORMAL_DATA_NUM)
115 #define POSITIONINGLOG_SYS_1_ABNORMAL_DATA_OFFSET 11
116 #define POSITIONINGLOG_SYS_2_ABNORMAL_DATA_OFFSET 32
117 #define POSITIONINGLOG_SYS_3_ABNORMAL_DATA_OFFSET 54
118 #define POSITIONINGLOG_SYS_4_ABNORMAL_DATA_OFFSET 114
119 #define POSITIONINGLOG_SYS_1_ABNORMAL_SET_DATA_OFFSET 0
120 #define POSITIONINGLOG_SYS_2_ABNORMAL_SET_DATA_OFFSET POSITIONINGLOG_SYS_1_ABNORMAL_DATA_NUM
121 #define POSITIONINGLOG_SYS_3_ABNORMAL_SET_DATA_OFFSET (POSITIONINGLOG_SYS_1_ABNORMAL_DATA_NUM + POSITIONINGLOG_SYS_2_ABNORMAL_DATA_NUM)
122 #define POSITIONINGLOG_SYS_4_ABNORMAL_SET_DATA_OFFSET (POSITIONINGLOG_SYS_1_ABNORMAL_DATA_NUM + \
123                                                POSITIONINGLOG_SYS_2_ABNORMAL_DATA_NUM + \
124                                                POSITIONINGLOG_SYS_3_ABNORMAL_DATA_NUM)
125 #define POSITIONINGLOG_SYS_OPC_OFFSET 9
126 #define POSITIONINGLOG_SYS_PULSE_TIME_NUM_OFFSET 114
127 #define POSITIONINGLOG_SYS_NORMAL_DATA 0xC1
128 #define POSITIONINGLOG_SYS_FST_DATA 0xF4
129 #define _pb_strcat(pdest, psrc, size)   (strncat(pdest, psrc, size) , (0))
130
131 // Vehicle sensor information notification message
132 typedef struct {
133   uint32_t did;         // Data ID corresponding to vehicle sensor information
134   uint16_t size;        // Data size of vehicle sensor information
135   uint8_t rcv_flag;      // Vehicle sensor information reception flag
136   uint8_t reserve;      // Reserved
137   uint8_t data[VEHICLE_VSINFO_DSIZE];  // Vehicle sensor information
138 } VEHICLE_UNIT_MSG_VSINFO_DAT;
139
140 // Vehicle sensor information notification message
141 typedef struct {
142   VEHICLE_UNIT_MSG_VSINFO_DAT data;  // Message data
143 } VEHICLE_UNIT_MSG_VSINFO;
144 /*---------------------------------------------------------------------------------*
145  * Structre                                                                        *
146  *---------------------------------------------------------------------------------*/
147 /*!
148    @brief   Structure to create shared data
149 */
150 typedef struct {
151     char    share_data_name[PRIM_NAME_MAX]; /**< Shared data name         */
152     u_int32 data_size;                    /**< Shared data size    */
153 } ST_SHAREDATA;
154
155 /*!
156    @brief   Thread management information
157 */
158 typedef struct {
159     EnumTID_POS     id;           /**< Thread ID                                  */
160     const int8_t*   p_name;        /**< Thread name                                  */
161     PNO             pno;          /**< Process number                                */
162     CbFuncPtr       routine;      /**< Start Routine                             */
163     uint8_t         msk_available; /**< Dependent services Availability                    */
164     uint8_t         msk_ntfy;      /**< Dependency notification                                   */
165     uint8_t         msk_thread;    /**< Dependent threads                               */
166     BOOL            is_depended;   /**< Positioning/Availability->TRUE change dependency */
167     uint8_t         status;       /**< Thread activation state                             */
168     uint8_t         order;        /**< Boot Sequence(Performance)                              */
169     uint8_t         reserve[2];
170 } ST_THREAD_CREATE_INFO;
171
172
173 /* GPS fix count information */
174 typedef struct {
175   uint32_t ul3d;                    /* 3D */
176   uint32_t ul2d;                    /* 2D */
177   uint32_t ul_else;                  /* Not fix */
178   uint8_t dummy[4];                 /* Dummy */
179 } ST_GPS_FIX_CNT;
180
181 /*!
182     @brief Structure that stores the time set by the time setting or the time updated(For GRADE1)
183 */
184 typedef struct {
185     u_int16 year; /* Year */
186     u_int8 month; /* Month */
187     u_int8 date;  /* Day */
188     u_int8 hour;  /* Hour */
189     u_int8 minute;/* Minutes */
190     u_int8 second;/* Minutes */
191     u_int8 flag;  /* Whether or not the time is set */
192 } ST_GPS_SET_TIME;
193
194 /*---------------------------------------------------------------------------------*
195  * Local Function Prototype                                                        *
196  *---------------------------------------------------------------------------------*/
197 static EFrameworkunifiedStatus PositioningOnStartImpl(const HANDLE hApp, const EPWR_SC_WAKEUP_TYPE wakeupType,
198                                  const ESMDataResetModeInfo dataResetMode);
199 static EFrameworkunifiedStatus PosNotifyCommunicationAvailability(HANDLE h_app);
200 static EFrameworkunifiedStatus PosNotifyCommUSBAvailability(HANDLE h_app);
201 static EFrameworkunifiedStatus PosNotifyPSMShadowAvailability(HANDLE h_app);
202 static EFrameworkunifiedStatus PosNotifyPSMShadowInitComp(HANDLE h_app);
203 static EFrameworkunifiedStatus PosNotifyClockAvailability(HANDLE h_app);
204 static EFrameworkunifiedStatus PosNotifyNSBackupMgrAvailability(HANDLE h_app);
205 static EFrameworkunifiedStatus PosNotifyDevDetectSrvAvailability(HANDLE h_app);
206 static EFrameworkunifiedStatus PosNotifyVehicleAvailability(HANDLE h_app);
207
208 static EFrameworkunifiedStatus PosStopThreadDummy(HANDLE h_app);
209 static void PosCreateSharedMemory(void);
210 static void PosCreateThread(HANDLE h_app);
211 static void PosStopThread(void);
212 static void PosBackupDataInit(void);
213
214 /* Message Dispatching Functions */
215 static EFrameworkunifiedStatus PosThreadCreateComp(HANDLE h_app);
216 static EFrameworkunifiedStatus PosThreadStopComp(HANDLE h_app);
217 static EFrameworkunifiedStatus PosPosifRegisterListenerPkgSensorData(HANDLE h_app);
218 static EFrameworkunifiedStatus PosPosifRegisterListenerSensorData(HANDLE h_app);
219 static EFrameworkunifiedStatus PosPosifReqGpsSetting(HANDLE h_app);
220 static EFrameworkunifiedStatus PosPosifSetGpsInfo(HANDLE h_app);
221 static EFrameworkunifiedStatus PosPosifGetGpsInfo(HANDLE h_app);
222 static EFrameworkunifiedStatus PosPosifSetData(HANDLE h_app);
223 static EFrameworkunifiedStatus PosPosifReqGpsReset(HANDLE h_app);
224 static EFrameworkunifiedStatus PosVehicleInfoRcv(HANDLE h_app);
225 static uint32_t PosGetMsg(HANDLE h_app, void** p_buf, uint32_t size);
226 static RET_API  PosSndMsg(PNO pno, CID cid, void* p_msg_body, uint32_t size);
227 static void PosOutputDebugDumpLog(uint8_t* p_buf);
228
229 /* Function scan for device insertion detection */
230 static EFrameworkunifiedStatus PosOnDevDetectOpenSessionAck(HANDLE h_app);
231 static EFrameworkunifiedStatus PosOnDevDetectCloseSessionAck(HANDLE h_app);
232 static EFrameworkunifiedStatus PosOnDevDetectEvent(HANDLE h_app);
233
234 /*---------------------------------------------------------------------------------*
235  * Grobal Value                                                                    *
236  *---------------------------------------------------------------------------------*/
237 /* Thread name */
238 static const int8_t kThreadNamePosMain[15]         = "POS_Main";
239 static const int8_t kThreadNamePosSens[15]         = "POS_Sens";
240 static const int8_t kThreadNamePosGps[15]          = "POS_Gps";
241 static const int8_t kThreadNamePosGpsRecv[15]     = "POS_Gps_Recv";
242 static const int8_t kThreadNamePosGpsRollover[15] = "POS_Gps_Rolovr";
243
244 /** Shared memory generation table */
245 static ST_SHAREDATA g_sharedata_tbl[] = {
246     /* Shared data name to be generated,            Shared data size */
247     { {VEHICLE_SHARE_NAME},                 512 * 11 }, /* Vehicle sensor information acquisition                     */
248 #if 0 /* Less than 0.1 SBU,Not used in _CWORD71_ */
249     { {"SENSOR_SHARE_MEMORY"},              512 * 11 }, /* Vehicle sensor information Pkg acquisition                  */
250     { {"GPS_INT_SIGNAL_SHARE_MEMORY"},      4        }, /* GPS Interrupt Signal Acquisition                      */
251     { {"LOG_SETTING_SHARE_MEMORY"},         36       }, /* DR feature log acquisition                         */
252     { {"GYRO_CONNECT_STTS_SHARE_MEMORY"},   4        }, /* Get Gyro Connection Status                   */
253     { {"EPHEMERIS_NUM_SHARE_MEMORY"},       4        }, /* For acquiring effective ephemeris count at shutdown */
254     { {"LOCALTIME_SHARE_MEMORY"},            12         }, /* Local time acquisition at shutdown     */
255     { {"LONLAT_SHARE_MEMORY"},                8         }, /* Location acquisition at shutdown               */
256 #endif
257     { {'\0'},                                  0         }  /* Termination */
258 };
259
260 /** Sub-thread creation table
261    (1) Thread ID (Locally defined Enumeration)
262    (2) Thread name
263    (3) Process number
264    (4) Start Routine
265    (5) Dependent Availability
266    (6) Dependency notification
267    (7) Dependent threads * If there are dependent threads, do not create them until those threads are created.
268    (8) Positioning/Availability->TRUE depending on change
269    (9) Thread activation state (THREAD_STS_NOEXIST:Not started,THREAD_STS_CREATING:Starting,THREAD_STS_CREATED:Completion of the activation)
270   (10) Boot Sequence(Performance) (0,1,2, ... Note : 0 = Initial value(Not started)) Time of termination,Be destroyed in the reverse order of startup
271  */
272 static ST_THREAD_CREATE_INFO g_pos_thread_create_info_Grade1[] = {  // LCOV_EXCL_BR_LINE 11: unexpected branch
273     {    /* Pos_main */
274         ETID_POS_MAIN, /* (1) */
275         kThreadNamePosMain, /* (2) */
276         PNO_VEHICLE_SENSOR, /* (3) */
277         &VehicleSensThread, /* (4) */
278         (NTFY_MSK_NONE), /* (5) */
279         (NTFY_MSK_NONE), /* (6) */
280         0, /* (7) */
281         TRUE, /* (8) */
282         THREAD_STS_NOEXIST, /* (9) */
283         0 /* (10) */
284     },
285     {    /* Pos_sens */
286         ETID_POS_SENS, /* (1) */
287         kThreadNamePosSens, /* (2) */
288         PNO_LINE_SENS_DRV, /* (3) */
289         &StartLineSensorThreadPositioning, /* (4) */
290         (NTFY_MSK_PS_PSMSHADOW_AVAILABILITY), /* (5) */
291         (NTFY_MSK_NONE), /* (6) */
292         THREAD_STS_MSK_POS_MAIN, /* (7) */
293         FALSE, /* (8) */
294         THREAD_STS_NOEXIST, /* (9) */
295         0 /* (10) */
296     },
297     {    /* Pos_gps */
298         ETID_POS_GPS, /* (1) */
299         kThreadNamePosGps, /* (2) */
300         PNO_NAVI_GPS_MAIN, /* (3) */
301         &StartGpsMainThreadPositioning, /* (4) */
302         (NTFY_MSK_NONE), /* (5) */
303         (NTFY_MSK_NONE), /* (6) */
304         THREAD_STS_MSK_POS_MAIN, /* (7) */
305         TRUE, /* (8) */
306         THREAD_STS_NOEXIST, /* (9) */
307         0 /* (10) */
308     },
309     {    /* Pos_gps_recv */
310         ETID_POS_GPS_RECV, /* (1) */
311         kThreadNamePosGpsRecv, /* (2) */
312         PNO_NAVI_GPS_RCV, /* (3) */
313         &StartGpsRecvThreadPositioning, /* (4) */
314         (NTFY_MSK_NONE), /* (5) */
315         (NTFY_MSK_NONE), /* (6) */
316         THREAD_STS_MSK_POS_GPS, /* (7) */
317         FALSE, /* (8) */
318         THREAD_STS_NOEXIST, /* (9) */
319         0 /* (10) */
320     },
321     {    /* Pos_gps_rollover */
322         ETID_POS_GPS_ROLLOVER, /* (1) */
323         kThreadNamePosGpsRollover, /* (2) */
324         PNO_CLK_GPS, /* (3) */
325         &StartGpsRolloverThreadPositioning, /* (4) */
326         (NTFY_MSK_NS_BACKUPMGR_AVAILABILITY), /* (5) */
327         (NTFY_MSK_NONE), /* (6) */
328         THREAD_STS_MSK_POS_GPS, /* (7) */
329         FALSE, /* (8) */
330         THREAD_STS_NOEXIST, /* (9) */
331         0 /* (10) */
332     },
333     {   /* Termination */
334         ETID_POS_MAX, NULL, 0, NULL, NTFY_MSK_NONE, NTFY_MSK_NONE, 0, FALSE, THREAD_STS_NOEXIST, 0
335     },
336 };
337
338 /* State Management Variables */
339 static bool g_start_flg = false;       /** Start Processed Flag                                */
340 static EnumExeSts_POS g_exe_sts;       /** Positioning running status                                 */
341 static EnumSetupMode_POS g_setup_mode; /** Thread activation mode                                  */
342 static uint8_t g_last_thread_sts;      /** Latest internal thread activation state                            */
343 static uint8_t g_last_srv_sts;         /** Latest service availability                            */
344 static uint8_t g_last_ntfy_sts;           /** Receive state of latest notification                                    */
345 static uint8_t g_last_num_of_thread;   /** Number of Current Startup Threads                                  */
346
347 /** Sub-thread creation table */
348 static ST_THREAD_CREATE_INFO* g_pos_thread_create_info;
349
350 /** Interprocess message receive buffer */
351 static uint8_t g_rcv_msg_buf[MAX_MSG_BUF_SIZE];
352
353 /** Dispatcher Registration Callback Table */
354 static const FrameworkunifiedProtocolCallbackHandler kPositioningPcbhs[] = {  // LCOV_EXCL_BR_LINE 11: unexpected branch
355     {CID_THREAD_CREATE_COMP,                &PosThreadCreateComp                  }, /* Thread start completion notification */
356     {CID_THREAD_STOP_COMP,                  &PosThreadStopComp                    }, /* Thread stop completion notice */
357     {CID_SENSORIF_PKG_DELIVERY_ENTRY_EXT,   &PosPosifRegisterListenerPkgSensorData},
358     {CID_VEHICLEIF_DELIVERY_ENTRY,          &PosPosifRegisterListenerSensorData   },
359     {CID_SENSORIF__CWORD82__REQUEST,              &PosPosifReqGpsSetting                },
360     {CID_NAVIINFO_DELIVER,                  &PosPosifSetGpsInfo                   },
361     {CID_VEHICLEIF_GET_VEHICLE_DATA,        &PosPosifGetGpsInfo                   },
362     {CID_POSIF_SET_DATA,                    &PosPosifSetData                      },
363     {CID_GPS_REQRESET,                      &PosPosifReqGpsReset                  },
364 };
365
366 static const FrameworkunifiedProtocolCallbackHandler kPositioningPcbhsVehicle[] = {  // LCOV_EXCL_BR_LINE 11: unexpected branch
367     {CID_VEHICLESENS_VEHICLE_INFO,              &PosVehicleInfoRcv},
368 };
369
370 /** Dispatcher unregister command ID table */
371 static uint32_t g_positioning_cids[] = {
372     CID_THREAD_CREATE_COMP,
373     CID_THREAD_STOP_COMP,
374     CID_SENSORIF_PKG_DELIVERY_ENTRY_EXT,
375     CID_VEHICLEIF_DELIVERY_ENTRY,
376     CID_SENSORIF__CWORD82__REQUEST,
377     CID_NAVIINFO_DELIVER,
378     CID_VEHICLEIF_GET_VEHICLE_DATA,
379     CID_POSIF_SET_DATA,
380     CID_GPS_REQRESET,
381 };
382
383 static uint32_t g_positioning_cids_vehicle[] = {
384     CID_VEHICLESENS_VEHICLE_INFO,
385 };
386
387
388
389 /** Stop request flag for GPS reception thread */
390 BOOL g_thread_stop_req;
391
392 /*---------------------------------------------------------------------------------*
393  * Function                                                                        *
394  *---------------------------------------------------------------------------------*/
395 /**
396  * @brief
397  *   FrameworkunifiedOnInitialization<br>
398  *   Sends message to Notification Service
399  *
400  *   Mm 21 API perform initialization.<br>
401  *   Generatings shared memories used by Vehicle function block..<br>
402  *   Creates a sub-thread of the Vehicle feature block..
403  *
404  * @param[in]  h_app    Application handle
405  *
406  * @return    eFrameworkunifiedStatusOK    Normal completion
407  *            eFrameworkunifiedStatusFail    ABENDs
408  */
409 EFrameworkunifiedStatus FrameworkunifiedOnInitialization(HANDLE h_app) {
410     RET_API ret_api;
411     EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
412     uint8_t* p_last_srv_sts = &g_last_srv_sts;
413     uint8_t* p_last_thread_sts = &g_last_thread_sts;
414     uint8_t* p_last_ntfy_sts = &g_last_ntfy_sts;
415     ST_THREAD_CREATE_INFO** pp_thr_cre_info = &g_pos_thread_create_info;
416     uint8_t* p_last_num_thr = &g_last_num_of_thread;
417     BOOL* p_thr_stop_req = &g_thread_stop_req;
418     EnumExeSts_POS* p_exe_sts = &g_exe_sts;
419     EnumSetupMode_POS* pe_mode = &g_setup_mode;
420
421     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "+");
422
423     /* Global variable initialization */
424     *p_last_srv_sts = 0;
425     *p_last_thread_sts = 0;
426     *p_last_ntfy_sts = 0;
427     *pp_thr_cre_info = g_pos_thread_create_info_Grade1;
428     *p_last_num_thr = 0;
429     *p_thr_stop_req = FALSE;
430     *p_exe_sts = EPOS_EXE_STS_STOP;
431     *pe_mode = EPOS_SETUP_MODE_NORMAL;
432
433     /* null check */
434     if (h_app == NULL) {  // LCOV_EXCL_BR_LINE 4: nsfw error
435         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "h_app is NULL");
436         e_status = eFrameworkunifiedStatusFail;
437     } else {
438         /* Positioning Base API initialization */
439         ret_api = _pb_Setup_CWORD64_API(h_app);
440         if (ret_api != RET_NORMAL) {  // LCOV_EXCL_BR_LINE 4: can not return error
441             // LCOV_EXCL_START 8: invalid
442             AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
443             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
444                           "_pb_Setup_CWORD64_API ERROR!! [ret_api = %d]",
445                           ret_api);
446
447             e_status = eFrameworkunifiedStatusFail;
448             // LCOV_EXCL_STOP
449         } else {
450             /* Availability at Positioning startup,Set internal thread activation state */
451             if (ChkUnitType(UNIT_TYPE_GRADE1) == true) {  /* GRADE1 environment */
452                 *pp_thr_cre_info = g_pos_thread_create_info_Grade1;
453                 FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, 
454                               "*pp_thr_cre_info = g_pos_thread_create_info_Grade1");
455             } else if (ChkUnitType(UNIT_TYPE_GRADE2) == true) {
456               /*
457                *  Note.
458                *  This feature branches processing depending on the unit type.
459                */
460             } else {
461                 FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "_pb_ChkUnitType UNKNOWN!!");
462             }
463
464             /* Shared Memory Creation */
465             PosCreateSharedMemory();
466
467             if (e_status == eFrameworkunifiedStatusOK) {
468                 /* Register callback functions for Positioning internals */
469                 e_status = FrameworkunifiedAttachCallbacksToDispatcher(h_app,
470                                                         "NS_ANY_SRC",
471                                                         kPositioningPcbhs,
472                                                         _countof(kPositioningPcbhs));  // LCOV_EXCL_BR_LINE 4:nsfw error
473                 if (e_status != eFrameworkunifiedStatusOK) {
474                     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
475                                   "FrameworkunifiedAttachCallbacksToDispatcher ERROR!! [e_status = %d]", e_status);
476                 }
477
478                 (void)VehicleIfAttachCallbacksToDispatcher(kPositioningPcbhsVehicle,
479                                                             _countof(kPositioningPcbhsVehicle));
480             }
481
482             if (e_status == eFrameworkunifiedStatusOK) {  // LCOV_EXCL_BR_LINE 4: nsfw error
483                 /* Positioning/Availability registration */
484                 e_status = FrameworkunifiedRegisterServiceAvailabilityNotification(h_app, POS_AVAILABILITY);
485                 if (eFrameworkunifiedStatusOK != e_status) {
486                     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
487                                   "FrameworkunifiedRegisterServiceAvailabilityNotification ERROR!! [e_status = %d]", e_status);
488                 }
489             }
490
491             if (e_status == eFrameworkunifiedStatusOK) {  // LCOV_EXCL_BR_LINE 4: nsfw error
492                 /* Positioning/Availability -> FALSE */
493                 e_status = FrameworkunifiedPublishServiceAvailability(h_app, FALSE);
494                 if (eFrameworkunifiedStatusOK != e_status) {
495                     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
496                                   "FrameworkunifiedPublishServiceAvailability ERROR!! [e_status = %d]", e_status);
497                 } else {
498                     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "Positioning/Availability -> FALSE");
499                 }
500             }
501
502             /* Communication/Availability Changing notification registration */
503             FrameworkunifiedSubscribeNotificationWithCallback(h_app, NTFY_Communication_Availability, &PosNotifyCommunicationAvailability);  // LCOV_EXCL_BR_LINE 6: not a branch  // NOLINT(whitespace/line_length)
504
505             /* PS_CommUSB/Availability Changing notification registration */
506             (void)CommUsbIfNotifyOnCommUSBAvailability(&PosNotifyCommUSBAvailability);  // LCOV_EXCL_BR_LINE 6: not a branch  // NOLINT(whitespace/line_length)
507
508             /* PS_PSMShadow/Availability Changing notification registration */
509             (void)PSMShadowIfNotifyOnPSMShadowAvailability(&PosNotifyPSMShadowAvailability);  // LCOV_EXCL_BR_LINE 6: not a branch  // NOLINT(whitespace/line_length)
510             /* PS_PSMShadow Startup completion notification registration */
511             (void)PSMShadowIfNotifyOnPSMShadowInitComp(&PosNotifyPSMShadowInitComp);  // LCOV_EXCL_BR_LINE 6: not a branch  // NOLINT(whitespace/line_length)
512
513             /* Clock/Availability Changing notification registration */
514             (void)ClockIfNotifyOnClockAvailability(&PosNotifyClockAvailability);  // LCOV_EXCL_BR_LINE 6: not a branch  // NOLINT(whitespace/line_length)
515
516             /* NS_BackupMgr/Availability Changing notification registration */
517             (void)BackupMgrIfNotifyOnBackupMgrAvailability(&PosNotifyNSBackupMgrAvailability);  // LCOV_EXCL_BR_LINE 6: not a branch  // NOLINT(whitespace/line_length)
518
519             /* Regist Vehilce Availability Notification */
520             (void)VehicleIfNotifyOnVehicleAvailability(&PosNotifyVehicleAvailability);  // LCOV_EXCL_BR_LINE 6: not a branch  // NOLINT(whitespace/line_length)
521
522             /* DeviceDetectionServiceIf initialization */
523             if (DevDetectSrvIfInitialize() == eFrameworkunifiedStatusOK) {
524                 /* SS_DevDetectSrv/Availability Changing notification registration */
525                 (void)DevDetectSrvIfNotifyOnDeviceDetectionAvailability(&PosNotifyDevDetectSrvAvailability);  // LCOV_EXCL_BR_LINE 6: not a branch  // NOLINT(whitespace/line_length)
526             }
527         }
528     }
529
530     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "-");
531
532     return e_status;
533 }
534
535 /**
536  * @brief
537  *   PositioningOnStartImpl
538  */
539 static EFrameworkunifiedStatus PositioningOnStartImpl(const HANDLE hApp, const EPWR_SC_WAKEUP_TYPE wakeupType,
540                                  const ESMDataResetModeInfo dataResetMode) {
541     EnumExeSts_POS* p_exe_sts = &g_exe_sts;
542     EnumSetupMode_POS* pe_mode = &g_setup_mode;
543
544     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "+");
545
546     if (g_start_flg == false) {
547         g_start_flg = true;
548
549         /* Running */
550         *p_exe_sts = EPOS_EXE_STS_RUNNING;
551
552         /* Cold start */
553         if (wakeupType == epsstCOLDSTART) {
554             FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "wakeupType:COLDSTART");
555
556             *p_exe_sts = EPOS_EXE_STS_RUNNING_COLDSTART;
557
558             /* Initialize GPS time setting information */
559             PosBackupDataInit();
560         } else {  /* Time of warm start */
561             FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "wakeupType:WARMSTART");
562         }
563
564         /*  Time of factory initialization */
565         if (dataResetMode == e_SS_SM_DATA_RESET_MODE_FACTORY) {
566             FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "dataResetMode:FACTORYRESET");
567
568             /* Set thread start mode to ""data reset start"" */
569             *pe_mode = EPOS_SETUP_MODE_DATA_RESET;
570
571             /* Initialize GPS time setting information */
572             PosBackupDataInit();
573         }
574
575         PosCreateThread(hApp);
576     }
577
578     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "-");
579     return eFrameworkunifiedStatusOK;
580 }
581
582 /**
583  * @brief
584  *   FrameworkunifiedOnStart
585  */
586 EFrameworkunifiedStatus FrameworkunifiedOnStart(HANDLE hApp) {
587     EFrameworkunifiedStatus ret = eFrameworkunifiedStatusFail;
588     uint32_t size;
589
590     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "+");
591
592     size = PosGetMsg(hApp, reinterpret_cast<void**>(&g_rcv_msg_buf), MAX_MSG_BUF_SIZE);
593     if (size != 0) {
594         T_SS_SM_START_DataStructType* p_start_data;
595         p_start_data = reinterpret_cast<T_SS_SM_START_DataStructType*>(g_rcv_msg_buf);
596
597         ret = PositioningOnStartImpl(hApp, p_start_data->wakeupType, p_start_data->dataResetMode);
598     }
599
600     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "-");
601     return ret;
602 }
603
604 /**
605  * @brief
606  *   FrameworkunifiedOnStop
607  *
608  * @param[in]  h_app    Application handle
609  *
610  * @return    eFrameworkunifiedStatusOK    Normal completion
611  *            eFrameworkunifiedStatusFail    ABENDs
612  */
613 EFrameworkunifiedStatus FrameworkunifiedOnStop(HANDLE h_app) {
614     EFrameworkunifiedStatus e_status;
615     EnumExeSts_POS* p_exe_sts = &g_exe_sts;
616
617     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "+");
618
619     /* null check */
620     if (h_app == NULL) {  // LCOV_EXCL_BR_LINE 200: can not NULL
621         // LCOV_EXCL_START 8: invalid
622         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
623         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "h_app is NULL");
624         // LCOV_EXCL_STOP
625     } else {
626         *p_exe_sts = EPOS_EXE_STS_STOP;
627
628         e_status = FrameworkunifiedPublishServiceAvailability(h_app, FALSE);
629         if (eFrameworkunifiedStatusOK != e_status) {
630             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
631                           "FrameworkunifiedPublishServiceAvailability ERROR!! [e_status = %d]",
632                           e_status);
633         } else {
634             FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "Positioning/Availability -> FALSE");
635         }
636
637         PosStopThread();
638
639         g_start_flg = false;
640     }
641
642     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "-");
643
644     /* Return end response to SM at timing after completion of internal thread stop */
645     return eFrameworkunifiedStatusFail;
646 }
647
648 /**
649  * @brief
650  *   FrameworkunifiedOnPreStart
651  */
652 EFrameworkunifiedStatus FrameworkunifiedOnPreStart(HANDLE hApp) {
653     EFrameworkunifiedStatus ret = eFrameworkunifiedStatusFail;
654     uint32_t size;
655
656     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "+");
657
658     size = PosGetMsg(hApp, reinterpret_cast<void**>(&g_rcv_msg_buf), MAX_MSG_BUF_SIZE);
659     if (size != 0) {
660         T_SS_SM_START_DataStructType* p_start_data;
661         p_start_data = reinterpret_cast<T_SS_SM_START_DataStructType*>(g_rcv_msg_buf);
662
663         ret = PositioningOnStartImpl(hApp, p_start_data->wakeupType, p_start_data->dataResetMode);
664     }
665
666     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "-");
667     return ret;
668 }
669
670 /**
671  * @brief
672  *   FrameworkunifiedOnPreStop
673  */
674 EFrameworkunifiedStatus FrameworkunifiedOnPreStop(HANDLE hApp) {
675     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "+");
676     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "-");
677     return eFrameworkunifiedStatusOK;
678 }
679
680 /**
681  * @brief
682  *   FrameworkunifiedOnBackgroundStart
683  */
684 EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStart(HANDLE hApp) {
685     EFrameworkunifiedStatus ret = eFrameworkunifiedStatusFail;
686     uint32_t size;
687
688     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "+");
689
690     size = PosGetMsg(hApp, reinterpret_cast<void**>(&g_rcv_msg_buf), MAX_MSG_BUF_SIZE);
691     if (size != 0) {
692         T_SS_SM_START_DataStructType* p_start_data;
693         p_start_data = reinterpret_cast<T_SS_SM_START_DataStructType*>(g_rcv_msg_buf);
694
695         ret = PositioningOnStartImpl(hApp, p_start_data->wakeupType, p_start_data->dataResetMode);
696     }
697
698     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "-");
699     return ret;
700 }
701
702 /**
703  * @brief
704  *   FrameworkunifiedOnBackgroundStop
705  */
706 EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStop(HANDLE hApp) {
707     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "+");
708     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "-");
709     return eFrameworkunifiedStatusOK;
710 }
711
712 /**
713  * @brief
714  *   FrameworkunifiedOnDestroy (Not mounted)
715  *
716  * @param[in]  h_app    Application handle
717  *
718  * @return    eFrameworkunifiedStatusOK    Normal completion
719  *            eFrameworkunifiedStatusFail    ABENDs
720  */
721 EFrameworkunifiedStatus FrameworkunifiedOnDestroy(HANDLE h_app) {  // LCOV_EXCL_START 14 Resident process, not called by NSFW
722     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
723     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+");
724     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "-");
725     return eFrameworkunifiedStatusOK;
726 }
727 // LCOV_EXCL_STOP
728
729 /**
730  * @brief
731  *   FrameworkunifiedOnDebugDump
732  *
733  * @param[in]  h_app    Application handle
734  *
735  * @return    eFrameworkunifiedStatusOK    Normal completion
736  *            eFrameworkunifiedStatusFail    ABENDs
737  */
738 EFrameworkunifiedStatus FrameworkunifiedOnDebugDump(HANDLE h_app) {  // LCOV_EXCL_START 7: debug code
739     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
740     static uint8_t              buf_tmp[256];
741     static uint8_t              buf_proc[128];
742     static uint8_t              buf_thread[512];
743     static uint8_t              buf_message[4][DEBUG_DUMP_MAX_SIZE];
744     static uint8_t              buf_mutex[3][DEBUG_DUMP_MAX_SIZE];
745     static uint8_t              buf_timer[DEBUG_DUMP_MAX_SIZE];
746     static uint8_t              buf_event[9][DEBUG_DUMP_MAX_SIZE];
747     static uint8_t              buf_memory[DEBUG_DUMP_MAX_SIZE];
748     static uint8_t              buf_other[DEBUG_DUMP_MAX_SIZE];
749     static uint8_t              buf_nand[256];
750     static uint8_t              buf_ram[256];
751     static uint8_t              buf_gps_format_fail[512];
752     static uint8_t              buf_antenna[256];
753     static uint8_t              buf_gps_info[DEBUG_DUMP_MAX_SIZE];
754     static uint8_t              buf_navi_info[DEBUG_DUMP_MAX_SIZE];
755     static uint8_t              buf_deli_ctrl_tbl[DEBUG_DUMP_MAX_SIZE];
756     static uint8_t              buf_deli_ctrl_tbl_mng[DEBUG_DUMP_MAX_SIZE];
757     static uint8_t              buf_pkg_deli_tbl_mng[DEBUG_DUMP_MAX_SIZE];
758     static uint8_t              buf_deli_pno_tbl[DEBUG_DUMP_MAX_SIZE];
759     static uint8_t              buf_sys[128];
760     int32_t                      i;
761     ST_THREAD_CREATE_INFO*       p_thr_cre_info = g_pos_thread_create_info;
762     ST_GPS_FIX_CNT               st_gps_fix_cnt;
763     ST_GPS_SET_TIME              st_gps_set_time;
764     uint8_t                      len_msg = 4;
765     uint8_t                      len_mtx = 3;
766     uint8_t                      len_evt = 9;
767     EFrameworkunifiedStatus e_status;
768     BOOL b_is_available;
769     UNIT_TYPE e_type = UNIT_TYPE_NONE;
770     u_int8                       sys_recv_flg;
771     uint16_t                     wkn_rollover;
772
773     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+");
774
775     memset(&buf_proc[0],           0x00, sizeof(buf_proc));
776     memset(&buf_thread[0],         0x00, sizeof(buf_thread));
777     memset(&buf_nand[0],           0x00, sizeof(buf_nand));
778     memset(&buf_ram[0],            0x00, sizeof(buf_ram));
779     memset(&buf_gps_format_fail[0],  0x00, sizeof(buf_gps_format_fail));
780     memset(&buf_antenna[0],        0x00, sizeof(buf_antenna));
781     memset(&buf_gps_info[0],        0x00, sizeof(buf_gps_info));
782     memset(&buf_navi_info[0],       0x00, sizeof(buf_navi_info));
783     memset(&buf_deli_ctrl_tbl[0],    0x00, sizeof(buf_deli_ctrl_tbl));
784     memset(&buf_deli_ctrl_tbl_mng[0], 0x00, sizeof(buf_deli_ctrl_tbl_mng));
785     memset(&buf_pkg_deli_tbl_mng[0],  0x00, sizeof(buf_pkg_deli_tbl_mng));
786     memset(&buf_deli_pno_tbl[0],     0x00, sizeof(buf_deli_pno_tbl));
787     memset(&buf_sys[0],            0x00, sizeof(buf_sys));
788
789     for (i = 0; i < len_msg; i++) {
790         memset(&buf_message[i][0], 0x00, sizeof(buf_message[i]));
791     }
792     for (i = 0; i < len_mtx; i++) {
793         memset(&buf_mutex[i][0], 0x00, sizeof(buf_mutex[i]));
794     }
795     memset(&buf_timer[0],   0x00, sizeof(buf_timer));
796     for (i = 0; i < len_evt; i++) {
797         memset(&buf_event[i][0], 0x00, sizeof(buf_event[i]));
798     }
799     memset(&buf_memory[0],  0x00, sizeof(buf_memory));
800     memset(&buf_other[0],   0x00, sizeof(buf_other));
801     e_type = GetEnvSupportInfo();
802
803     /* Availability status of related processes */
804     snprintf(reinterpret_cast<char *>(&buf_proc[0]), sizeof(buf_proc),
805             "Availability\n thread:0x%02x, srv:0x%02x, ntfy:0x%02x",
806             g_last_thread_sts,  /* Latest internal thread activation state */
807             g_last_srv_sts,     /* Latest service availability */
808             g_last_ntfy_sts);   /* Receive state of latest notification         */
809
810     /* Internal thread activation state */
811     snprintf(reinterpret_cast<char *>(&buf_thread[0]), sizeof(buf_thread), "Thread");
812     for (i = 0; i < ETID_POS_MAX; i++) {
813         memset(&buf_tmp[0], 0x00, sizeof(buf_tmp));
814         snprintf(reinterpret_cast<char *>(&buf_tmp[0]), sizeof(buf_tmp),
815                 "\n [%d]id:%d, pno:0x%04x, name:%16s, sts:0x%02x, order:%d",
816                 i,
817                 p_thr_cre_info->id,       /* Thread ID */
818                 p_thr_cre_info->pno,      /* Process number */
819                 p_thr_cre_info->p_name,    /* Thread name */
820                 p_thr_cre_info->status,   /* Thread activation state */
821                 p_thr_cre_info->order);   /* Boot Sequence */
822         _pb_strcat(reinterpret_cast<char *>(&buf_thread[0]), reinterpret_cast<char *>(&buf_tmp[0]), sizeof(buf_tmp));
823         p_thr_cre_info++;
824     }
825
826     /* BASE API control data */
827     /*   Message */
828     (void)_pb_GetDebugMsgMngTbl(&buf_message[0][0], &len_msg);
829     /*   Mutex */
830     (void)_pb_GetDebugMutexMngTbl(&buf_mutex[0][0], &len_mtx);
831     /*   Timer */
832     (void)_pb_GetDebugTimerMngTbl(&buf_timer[0]);
833     /*   Event */
834     (void)_pb_GetDebugEventMngTbl(&buf_event[0][0], &len_evt);
835     /*   Shared Memory */
836     (void)_pb_GetDebugMemoryMngTbl(&buf_memory[0]);
837     /*   Other */
838     (void)_pb_GetDebugOtherMngTbl(&buf_other[0]);
839
840     /* NAND data */
841     snprintf(reinterpret_cast<char *>(&buf_nand[0]), sizeof(buf_nand), "NAND");
842     /*   GPS fix count */
843     memset(&buf_tmp[0], 0x00, sizeof(buf_tmp));
844     memset(&st_gps_fix_cnt, 0x00, sizeof(st_gps_fix_cnt));
845
846     e_status = BackupMgrIfBackupDataRd(D_BK_ID_POS_GPS_FIX_CNT,
847                                         0,
848                                         &st_gps_fix_cnt,
849                                         sizeof(st_gps_fix_cnt), &b_is_available);
850     snprintf(reinterpret_cast<char *>(&buf_tmp[0]), sizeof(buf_tmp),
851             "\n %20s rd:0x%08x av:%d, 3d:%d, 2d:%d, else:%d, dmy:0x%02x%02x%02x%02x",
852             "GPS_FIX_CNT",
853             e_status,
854             b_is_available,
855             st_gps_fix_cnt.ul3d,
856             st_gps_fix_cnt.ul2d,
857             st_gps_fix_cnt.ul_else,
858             st_gps_fix_cnt.dummy[0], st_gps_fix_cnt.dummy[1], st_gps_fix_cnt.dummy[2], st_gps_fix_cnt.dummy[3]);
859     _pb_strcat(reinterpret_cast<char *>(&buf_nand[0]), reinterpret_cast<char *>(&buf_tmp[0]), sizeof(buf_tmp));
860
861     /* Data of the backup RAM */
862     snprintf(reinterpret_cast<char *>(&buf_ram[0]), sizeof(buf_ram), "BackupRAM");
863     /*   Set GPS date and time(Information) */
864     memset(&buf_tmp[0], 0x00, sizeof(buf_tmp));
865     (void)memset( reinterpret_cast<void *>(&st_gps_set_time), 0, (size_t)sizeof(st_gps_set_time) );
866
867     e_status = BackupMgrIfBackupDataRd(D_BK_ID_POS_GPS_TIME_SET_INFO,
868                                         0,
869                                         &st_gps_set_time,
870                                         sizeof(st_gps_set_time),
871                                         &b_is_available);
872     snprintf(reinterpret_cast<char *>(&buf_tmp[0]), sizeof(buf_tmp),
873             "\n %20s rd:0x%08x av:%d, %d/%d/%d %d:%d:%d  flag:0x%02x",
874             "GPS_TIME_SET_INFO",
875             e_status,
876             b_is_available,
877             st_gps_set_time.year,
878             st_gps_set_time.month,
879             st_gps_set_time.date,
880             st_gps_set_time.hour,
881             st_gps_set_time.minute,
882             st_gps_set_time.second,
883             st_gps_set_time.flag);
884     _pb_strcat(reinterpret_cast<char *>(&buf_ram[0]), reinterpret_cast<char *>(&buf_tmp[0]), sizeof(buf_tmp));
885
886     if (e_type == UNIT_TYPE_GRADE1) {
887         /* GPS format anomaly counter  */ /* There is no lock control. */
888         (void)DEVGpsGetDebugGpsFormatFailCnt(&buf_gps_format_fail[0]);
889
890         /* GPS antenna connection status */ /* There is no lock control. */
891         VEHICLESENS_DATA_MASTER st_sns_data = {0};
892         (void)VehicleSensGetGpsAntenna(&st_sns_data, VEHICLESENS_GETMETHOD_LINE);
893         snprintf(reinterpret_cast<char *>(&buf_antenna[0]), sizeof(buf_antenna),
894             "Antenna\n sts:0x%02x",
895             st_sns_data.uc_data[0]);
896
897         /* GPS position time */ /* There is no lock control. */
898         (void)VehicleSensGetDebugPosDate(&buf_gps_info[0], VEHICLESENS_GETMETHOD_GPS);
899     }
900
901     if (e_type == UNIT_TYPE_GRADE1) {
902         /* Navigation position time */ /* There is no lock control. */
903         (void)VehicleSensGetDebugPosDate(&buf_navi_info[0], VEHICLESENS_GETMETHOD_NAVI);
904     }
905
906     /* Delivery table */ /* There is no lock control. */
907     (void)VehicleSensGetDebugDeliveryCtrlTbl(&buf_deli_ctrl_tbl[0]);
908     (void)VehicleSensGetDebugDeliveryCtrlTblMng(&buf_deli_ctrl_tbl_mng[0]);
909     (void)VehicleSensGetDebugPkgDeliveryTblMng(&buf_pkg_deli_tbl_mng[0]);
910     (void)VehicleSensGetDebugDeliveryPnoTbl(&buf_deli_pno_tbl[0]);
911
912     /* Initial Sensor Data Status from Sys */
913     sys_recv_flg = LineSensDrvGetSysRecvFlag();
914     snprintf(reinterpret_cast<char *>(&buf_sys[0]), sizeof(buf_sys),
915             "Rx 1st Sensor Data %d\n", sys_recv_flg);
916
917     /* Dump Information Out */
918     PosOutputDebugDumpLog(&buf_proc[0]);
919     PosOutputDebugDumpLog(&buf_thread[0]);
920     for (i = 0; i < len_msg; i++) {
921         PosOutputDebugDumpLog(&buf_message[i][0]);
922     }
923     for (i = 0; i < len_mtx; i++) {
924         PosOutputDebugDumpLog(&buf_mutex[i][0]);
925     }
926     PosOutputDebugDumpLog(&buf_timer[0]);
927     for (i = 0; i < len_evt; i++) {
928         PosOutputDebugDumpLog(&buf_event[i][0]);
929     }
930     PosOutputDebugDumpLog(&buf_memory[0]);
931     PosOutputDebugDumpLog(&buf_other[0]);
932     PosOutputDebugDumpLog(&buf_nand[0]);
933     PosOutputDebugDumpLog(&buf_ram[0]);
934     if (e_type == UNIT_TYPE_GRADE1) {
935         PosOutputDebugDumpLog(&buf_gps_format_fail[0]);
936         PosOutputDebugDumpLog(&buf_antenna[0]);
937         PosOutputDebugDumpLog(&buf_gps_info[0]);
938     }
939     if (e_type == UNIT_TYPE_GRADE1) {
940         PosOutputDebugDumpLog(&buf_navi_info[0]);
941     }
942     PosOutputDebugDumpLog(&buf_deli_ctrl_tbl[0]);
943     PosOutputDebugDumpLog(&buf_deli_ctrl_tbl_mng[0]);
944     PosOutputDebugDumpLog(&buf_pkg_deli_tbl_mng[0]);
945     PosOutputDebugDumpLog(&buf_deli_pno_tbl[0]);
946     PosOutputDebugDumpLog(&buf_sys[0]);
947
948     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "-");
949     return eFrameworkunifiedStatusOK;
950 }
951 // LCOV_EXCL_STOP
952
953 /**
954  * @brief
955  *   FrameworkunifiedCreateStateMachine (Not mounted)
956  *
957  * @param[in]  h_app    Application handle
958  *
959  * @return    eFrameworkunifiedStatusOK    Normal completion
960  *            eFrameworkunifiedStatusFail    ABENDs
961  */
962 EFrameworkunifiedStatus FrameworkunifiedCreateStateMachine(HANDLE h_app) {  // LCOV_EXCL_START 8 : dead code
963   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
964     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+");
965     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "-");
966     return eFrameworkunifiedStatusOK;
967 }
968 // LCOV_EXCL_STOP
969
970 #ifdef __cplusplus
971 extern "C" {
972 #endif
973 /**
974  * @brief
975  *   Common processing after thread startup
976  *
977  *   Thread naming,Create Message Queue,Thread activation response
978  *
979  * @param[in]  h_app Application handle
980  * @param[in]  e_tid    Thread ID
981  *
982  * @return  Thread activation mode
983  */
984 EnumSetupMode_POS PosSetupThread(HANDLE h_app, EnumTID_POS e_tid) {
985     RET_API ret;
986     ST_THREAD_CREATE_INFO* p_thr_cre_info = g_pos_thread_create_info;
987     ST_THREAD_CREATE_INFO* p_info;
988     ST_THREAD_SETUP_INFO st_setup_info;
989     ST_THREAD_SETUP_INFO* pst_setup_info = &st_setup_info;
990
991     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "+");
992
993     p_info = p_thr_cre_info + e_tid;
994
995     /* Application handle setting */
996     _pb_SetAppHandle(h_app);
997
998     /* Create Message Queue */
999     _pb_CreateMsg(p_info->pno);
1000
1001     /* Get Thread Startup Information */
1002     pst_setup_info->e_mode = EPOS_SETUP_MODE_NORMAL;
1003     (void)PosGetMsg(h_app, reinterpret_cast<void**>(&pst_setup_info), sizeof(ST_THREAD_SETUP_INFO));
1004     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "[e_mode = %d]", pst_setup_info->e_mode);
1005
1006     /* Issue thread creation completion notice */
1007     ret = _pb_SndMsg_Ext(POS_THREAD_NAME, CID_THREAD_CREATE_COMP, sizeof(EnumTID_POS), (const void*)&e_tid, 0);
1008     if (ret != RET_NORMAL) {
1009         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_SndMsg_Ext ERROR!! [ret = %d]", ret);
1010     }
1011
1012     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "-");
1013
1014     return pst_setup_info->e_mode;
1015 }
1016
1017 /**
1018  * @brief
1019  *   Common Processing at Thread Stop
1020  *
1021  *   Thread stop response,Thread destruction
1022  *
1023  * @param[in]  e_tid    Thread ID
1024  */
1025 void PosTeardownThread(EnumTID_POS e_tid) {
1026     RET_API ret;
1027
1028     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "+");
1029
1030     /* Issue thread stop completion notice */
1031     ret = _pb_SndMsg_Ext(POS_THREAD_NAME, CID_THREAD_STOP_COMP, sizeof(EnumTID_POS), (const void*)&e_tid, 0);
1032     if (ret != RET_NORMAL) {
1033         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_SndMsg_Ext ERROR!! [ret = %d]", ret);
1034     }
1035
1036     /* Thread destruction */
1037     _pb_ExitThread((DWORD)0);
1038
1039     /* don't arrive here */
1040     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "-");
1041
1042     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1043     return;  // LCOV_EXCL_LINE 8 : cannot reach here
1044 }
1045
1046 #ifdef __cplusplus
1047 }
1048 #endif
1049
1050 /**
1051  * @brief
1052  *   FrameworkunifiedCreateChildThread dummy functions
1053  *
1054  * @param[in]  Application handle
1055  *
1056  * @return  eFrameworkunifiedStatusOK successful completion
1057  */
1058 static EFrameworkunifiedStatus PosStopThreadDummy(HANDLE h_app) {  // LCOV_EXCL_START 8 : dead code
1059     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1060     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+");
1061     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "-");
1062     return eFrameworkunifiedStatusOK;
1063 }
1064 // LCOV_EXCL_STOP
1065
1066 /*---------------------------------------------------------------------------------*
1067  * Local Function                                                                  *
1068  *---------------------------------------------------------------------------------*/
1069 /**
1070  * @brief
1071  *   Communication services Availability notification callback functions
1072  *
1073  * @param[in]  h_app    Application handle
1074  *
1075  * @return eFrameworkunifiedStatusOK    Normal completion
1076  */
1077 static EFrameworkunifiedStatus PosNotifyCommunicationAvailability(HANDLE h_app) {
1078     BOOL isAvailable;
1079     uint8_t* pLastSrvSts = &g_last_srv_sts;
1080
1081     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+");
1082
1083     isAvailable = FrameworkunifiedIsServiceAvailable(h_app);
1084     if (isAvailable == TRUE) {  // LCOV_EXCL_BR_LINE 4: nsfw error
1085         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Communication/Availability -> TRUE");
1086
1087         *pLastSrvSts |= NTFY_MSK_COMMUNICATION_AVAILABILITY;
1088
1089         PosCreateThread(h_app);
1090
1091         /* Sensor Log Initial Processing(First)*/
1092         SensLogInitialize(NULL);
1093     } else {
1094         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Communication/Availability -> FALSE");
1095
1096         *pLastSrvSts = static_cast<uint8_t>(*pLastSrvSts & ~NTFY_MSK_COMMUNICATION_AVAILABILITY);
1097     }
1098
1099     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "-");
1100
1101     return eFrameworkunifiedStatusOK;
1102 }
1103
1104 /**
1105  * @brief
1106  *   CommUSB services Availability notification callback functions
1107  *
1108  * @param[in]  h_app    Application handle
1109  *
1110  * @return eFrameworkunifiedStatusOK    Normal completion
1111  */
1112 static EFrameworkunifiedStatus PosNotifyCommUSBAvailability(HANDLE h_app) {
1113     BOOL isAvailable;
1114     uint8_t* pLastSrvSts = &g_last_srv_sts;
1115
1116     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+");
1117
1118     isAvailable = FrameworkunifiedIsServiceAvailable(h_app);
1119     if (isAvailable == TRUE) {
1120         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PS_CommUSB/Availability -> TRUE");
1121
1122         *pLastSrvSts |= NTFY_MSK_PS_COMMUSB_AVAILABILITY;
1123
1124         PosCreateThread(h_app);
1125     } else {
1126         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PS_CommUSB/Availability -> FALSE");
1127
1128         *pLastSrvSts = static_cast<uint8_t>(*pLastSrvSts & ~NTFY_MSK_PS_COMMUSB_AVAILABILITY);
1129     }
1130
1131     /* Update CommUSB I/F availability */
1132     CommUsbIfSetAvailability(isAvailable);
1133
1134     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "-");
1135
1136     return eFrameworkunifiedStatusOK;
1137 }
1138
1139 /**
1140  * @brief
1141  *   PSMShadow services Availability notification callback functions
1142  *
1143  * @param[in]  h_app    Application handle
1144  *
1145  * @return eFrameworkunifiedStatusOK    Normal completion
1146  */
1147 static EFrameworkunifiedStatus PosNotifyPSMShadowAvailability(HANDLE h_app) {
1148     BOOL isAvailable;
1149     uint8_t* pLastSrvSts = &g_last_srv_sts;
1150
1151     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+");
1152
1153     isAvailable = FrameworkunifiedIsServiceAvailable(h_app);
1154     if (isAvailable == TRUE) {
1155         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PS_PSMShadow/Availability -> TRUE");
1156
1157         *pLastSrvSts |= NTFY_MSK_PS_PSMSHADOW_AVAILABILITY;
1158
1159         PosCreateThread(h_app);
1160     } else {
1161         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PS_PSMShadow/Availability -> FALSE");
1162
1163         *pLastSrvSts = static_cast<uint8_t>(*pLastSrvSts & ~NTFY_MSK_PS_PSMSHADOW_AVAILABILITY);
1164     }
1165
1166     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "-");
1167
1168     return eFrameworkunifiedStatusOK;
1169 }
1170
1171 /**
1172  * @brief
1173  *   PSMShadow services Callback function for notifying completion of startup
1174  *
1175  * @param[in]  h_app    Application handle
1176  *
1177  * @return eFrameworkunifiedStatusOK    Normal completion
1178  */
1179 static EFrameworkunifiedStatus PosNotifyPSMShadowInitComp(HANDLE h_app) {
1180     uint8_t* pLastNtfySts = &g_last_ntfy_sts;
1181     ST_THREAD_CREATE_INFO* pThrCreInfo = g_pos_thread_create_info;
1182
1183     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+");
1184
1185     *pLastNtfySts |= NTFY_MSK_PS_PSMSHADOW_INIT_COMP;
1186
1187     /* When the Pos_Sens thread is started */
1188     if (((pThrCreInfo + ETID_POS_SENS)->status) == THREAD_STS_CREATED) {
1189         /* External pin status request */
1190         LineSensDrvExtTermStsReq();
1191     }
1192
1193     PosCreateThread(h_app);
1194
1195     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "-");
1196
1197     return eFrameworkunifiedStatusOK;
1198 }
1199
1200 /**
1201  * @brief
1202  *   Clock Services Availability Notification Callback Functions
1203  *
1204  * @param[in]  h_app Application handle
1205  *
1206  * @return eFrameworkunifiedStatusOK successful completion
1207  */
1208 static EFrameworkunifiedStatus PosNotifyClockAvailability(HANDLE h_app) {
1209     BOOL isAvailable;
1210     uint8_t* pLastSrvSts = &g_last_srv_sts;
1211
1212     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+");
1213
1214     isAvailable = FrameworkunifiedIsServiceAvailable(h_app);
1215     if (isAvailable == TRUE) {
1216         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Clock/Availability -> TRUE");
1217
1218         *pLastSrvSts |= NTFY_MSK_CLOCK_AVAILABILITY;
1219
1220         PosCreateThread(h_app);
1221     } else {
1222         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Clock/Availability -> FALSE");
1223
1224         *pLastSrvSts = static_cast<uint8_t>(*pLastSrvSts & ~NTFY_MSK_CLOCK_AVAILABILITY);
1225     }
1226
1227     /* Update Clock I/F availability */
1228     ClockIfSetAvailability(isAvailable);
1229
1230     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "-");
1231
1232     return eFrameworkunifiedStatusOK;
1233 }
1234
1235 /**
1236  * @brief
1237  *   NS_BackupMgr service Availability notification callback function
1238  *
1239  * @param[in]  h_app Application handle
1240  *
1241  * @return eFrameworkunifiedStatusOK successful completion
1242  */
1243 static EFrameworkunifiedStatus PosNotifyNSBackupMgrAvailability(HANDLE h_app) {
1244     EnumExeSts_POS* pExeSts = &g_exe_sts;
1245     uint8_t* pLastSrvSts = &g_last_srv_sts;
1246     ST_THREAD_CREATE_INFO* pThrCreInfo = g_pos_thread_create_info;
1247     EnumSetupMode_POS* peMode = &g_setup_mode;
1248     BOOL bIsAvailable;
1249
1250     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+");
1251
1252     bIsAvailable = FrameworkunifiedIsServiceAvailable(h_app);
1253
1254     /* Update BackupMgr I/F  availability */
1255     BackupMgrIfSetAvailability(bIsAvailable);
1256
1257     if (bIsAvailable == TRUE) {
1258         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "NS_BackupMgr/Availability -> TRUE");
1259
1260         *pLastSrvSts |= NTFY_MSK_NS_BACKUPMGR_AVAILABILITY;
1261
1262         /* Executing after cold start or during factory initialization*/
1263         if ((*pExeSts == EPOS_EXE_STS_RUNNING_COLDSTART) ||
1264             (*peMode == EPOS_SETUP_MODE_DATA_RESET)) {
1265             /* Backup RAM initialization */
1266             PosBackupDataInit();
1267         }
1268
1269         /* When the GPS management thread is started */
1270         if (((pThrCreInfo + ETID_POS_GPS)->status) == THREAD_STS_CREATED) {
1271             if ((*pExeSts == EPOS_EXE_STS_RUNNING_COLDSTART) ||
1272                 (*peMode == EPOS_SETUP_MODE_DATA_RESET)) {
1273               // GPS reset request.
1274               SENSOR_INTERNAL_MSG_BUF  msg_buf = {};
1275               T_APIMSG_MSGBUF_HEADER  *msg_hdr = &msg_buf.hdr;
1276               msg_hdr->hdr.cid         = CID_GPS_REQRESET;
1277               msg_hdr->hdr.msgbodysize = sizeof(POS_RESETINFO);
1278               POS_RESETINFO           *msg_data    = reinterpret_cast<POS_RESETINFO *>(&msg_buf.data);
1279               msg_data->mode           = GPS_RST_COLDSTART;
1280
1281               RET_API ret = _pb_SndMsg(PNO_NAVI_GPS_MAIN, sizeof(msg_buf), &msg_buf, 0);
1282               if (ret != RET_NORMAL) {
1283                   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "_pb_SndMsg ERROR!! [ret=%d]", ret);
1284               }
1285             }
1286
1287             /* Backup data read request to GSP management thread */
1288             (void)DEVGpsSndBackupDataLoadReq();
1289         }
1290         /* Enable Diag Code Writing */
1291         DiagSrvIfSetRegistrationPermission(TRUE);
1292
1293         PosCreateThread(h_app);
1294     } else {
1295         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "NS_BackupMgr/Availability -> FALSE");
1296
1297         *pLastSrvSts = static_cast<uint8_t>(*pLastSrvSts & ~NTFY_MSK_NS_BACKUPMGR_AVAILABILITY);
1298         /* Write prohibited dialog code */
1299         DiagSrvIfSetRegistrationPermission(FALSE);
1300     }
1301
1302     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "-");
1303
1304     return eFrameworkunifiedStatusOK;
1305 }
1306
1307 /**
1308  * @brief
1309  *   SS_DevDetectSrv service Availability Callback Functions
1310  *
1311  * @param[in]  h_app Application handle
1312  *
1313  * @return eFrameworkunifiedStatusOK successful completion
1314  */
1315 static EFrameworkunifiedStatus PosNotifyDevDetectSrvAvailability(HANDLE h_app) {
1316     EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
1317     BOOL isAvailable;
1318     BOOL bDummy;
1319     uint8_t* pLastSrvSts = &g_last_srv_sts;
1320
1321     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "+");
1322
1323     isAvailable = FrameworkunifiedIsServiceAvailable(h_app);
1324
1325     /* Update DevDetectSrv I/F availability */
1326     DevDetectSrvIfSetAvailability(isAvailable);
1327
1328     if (isAvailable == TRUE) {
1329         FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "SS_DevDetectSrv/Availability -> TRUE");
1330         *pLastSrvSts |= NTFY_MSK_SS_DEVDETSRV_AVAILABILITY;
1331
1332         eStatus = DevDetectSrvIfOpenSessionRequest(&bDummy);
1333         if (eFrameworkunifiedStatusOK != eStatus) {
1334             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
1335                 "DeviceDetectionServiceIf OpenSession ERROR!! [eStatus = %d]", eStatus);
1336         } else {
1337             eStatus = DevDetectSrvIfNotifyOnOpenSessionAck(&PosOnDevDetectOpenSessionAck, &bDummy);
1338             if (eFrameworkunifiedStatusOK != eStatus) {
1339                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
1340                     "DeviceDetectionServiceIf NotifyOnOpenSessionAck ERROR!! [eStatus = %d]", eStatus);
1341             }
1342         }
1343     } else {
1344         FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "SS_DevDetectSrv/Availability -> FALSE");
1345         *pLastSrvSts = static_cast<uint8_t>(*pLastSrvSts & ~NTFY_MSK_SS_DEVDETSRV_AVAILABILITY);
1346     }
1347
1348     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "-");
1349
1350     return eFrameworkunifiedStatusOK;
1351 }
1352
1353
1354 /**
1355  * @brief
1356  *   Vehicle Availability notification callback functions
1357  *
1358  * @param[in]  h_app    Application handle
1359  *
1360  * @return eFrameworkunifiedStatusOK    Normal completion
1361  *
1362  */
1363 static EFrameworkunifiedStatus PosNotifyVehicleAvailability(HANDLE h_app) {
1364   BOOL isAvailable;
1365   uint8_t* pLastSrvSts = &g_last_srv_sts;
1366
1367   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+");
1368
1369   isAvailable = FrameworkunifiedIsServiceAvailable(h_app);
1370
1371   /* Update Vechile I/F Abailability */
1372   VehicleIf_SetAvailability(isAvailable);
1373
1374   if (isAvailable == TRUE) {
1375     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Vehicle/Availability -> TRUE");
1376
1377     *pLastSrvSts |= NTFY_MSK_VS_VEHICLE_AVAILABILITY;
1378
1379     if (eFrameworkunifiedStatusFail == VehicleIfDeliveryEntry(VEHICLE_DID_SPEED)) {
1380       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "VehicleIfDeliveryEntry SPEED ERROR");
1381     }
1382
1383     if (eFrameworkunifiedStatusFail == VehicleIfDeliveryEntry(VEHICLE_DID_REV)) {
1384       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "VehicleIfDeliveryEntry REV ERROR");
1385     }
1386
1387     if (eFrameworkunifiedStatusFail == VehicleIfDeliveryEntry(VEHICLE_DID_SPEED_PULSE_VEHICLE)) {
1388       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "VehicleIfDeliveryEntry SPEED PULSE ERROR");
1389     }
1390
1391     PosCreateThread(h_app);
1392
1393   } else {
1394     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Vehicle/Availability -> FALSE");
1395
1396     *pLastSrvSts &= ~NTFY_MSK_VS_VEHICLE_AVAILABILITY;
1397   }
1398
1399   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "-");
1400
1401   return eFrameworkunifiedStatusOK;
1402 }
1403
1404 /**
1405  * @brief
1406  *   Shared Memory Creation for Positioning Function
1407  *
1408  * @return    RET_NORMAL    Normal completion
1409  *            RET_ERROR    ABENDs
1410  */
1411 static void PosCreateSharedMemory(void) {
1412     RET_API    ret_api = RET_NORMAL;
1413     void        *mod_exec_dmy; /* Module data pointer(dummy) */
1414     int           retry; /* Retry counter */
1415     ST_SHAREDATA *p_shm_tbl;
1416
1417     /* Configure Shared Data Generating Tables */
1418     p_shm_tbl = g_sharedata_tbl;
1419
1420     while ( *(p_shm_tbl->share_data_name) != '\0' ) {
1421         for ( retry = 0; retry < DATMOD_RETRY; retry++ ) {
1422             /* Shared Memory Generation */
1423             ret_api = _pb_CreateShareData(p_shm_tbl->share_data_name, p_shm_tbl->data_size, &mod_exec_dmy);
1424             if (ret_api == RET_NORMAL) {  /* If successful */
1425                 /* Set the shared memory status flag to ""Before initialization (0)"" */
1426                 *reinterpret_cast<u_int32 *>(mod_exec_dmy) = DATMOD_PREINIT;
1427
1428                 break;
1429             } else {  /* In the event of failure */
1430                 /* Error Handling */
1431                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
1432                               "_pb_CreateShareData ERROR [ret_api:%d]",
1433                               ret_api);
1434             }
1435         }
1436
1437         if (retry >= DATMOD_RETRY) {
1438             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_CreateShareData failed more %d times.",
1439                                                DATMOD_RETRY);
1440
1441             _pb_Exit();
1442             /* don't arrive here. */
1443         }
1444
1445         /* Next shared memory generation */
1446         p_shm_tbl++;
1447     }
1448
1449     return;
1450 }
1451
1452 /**
1453  * @brief
1454  *   Positioning in-process thread creation
1455  *
1456  * @param[in]  hApp application handles
1457  */
1458 static void PosCreateThread(HANDLE h_app) {
1459     HANDLE    threadHandle;
1460     EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
1461     EnumSetupMode_POS* peMode = &g_setup_mode;
1462     int32_t i;
1463     uint8_t* pLastSrvSts = &g_last_srv_sts;
1464     uint8_t* pLastThreadSts = &g_last_thread_sts;
1465     uint8_t* pLastNtfySts = &g_last_ntfy_sts;
1466     EnumExeSts_POS* pExeSts = &g_exe_sts;
1467     ST_THREAD_CREATE_INFO* pThrCreInfo = g_pos_thread_create_info;
1468
1469     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "+");
1470
1471     for (i = 0; i < ETID_POS_MAX; i++) {
1472         if ((pThrCreInfo->status == THREAD_STS_NOEXIST) && (pThrCreInfo->routine != NULL)) {
1473             FRAMEWORKUNIFIEDLOG(ZONE_28, __FUNCTION__, 
1474                           "i=%d, mskThread=0x%02x, *pLastThreadSts=0x%02x,"\
1475                           "mskAvailable=0x%02x, *pLastSrvSts=0x%02x, mskNtfy=0x%02x, *pLastNtfySts=0x%02x",
1476                           i,
1477                           pThrCreInfo->msk_thread,
1478                           *pLastThreadSts,
1479                           pThrCreInfo->msk_available,
1480                           *pLastSrvSts,
1481                           pThrCreInfo->msk_ntfy,
1482                           *pLastNtfySts);
1483
1484             if ((*pExeSts != EPOS_EXE_STS_STOP)
1485                 && ((((pThrCreInfo->msk_thread) & (*pLastThreadSts)) == pThrCreInfo->msk_thread)
1486                     || (pThrCreInfo->msk_thread == 0))
1487                 && ((((pThrCreInfo->msk_available) & (*pLastSrvSts)) == pThrCreInfo->msk_available)
1488                     || (pThrCreInfo->msk_available == NTFY_MSK_NONE))
1489                 && ((((pThrCreInfo->msk_ntfy) & (*pLastNtfySts)) == pThrCreInfo->msk_ntfy)
1490                     || (pThrCreInfo->msk_ntfy == NTFY_MSK_NONE))) {
1491                 if (pThrCreInfo->pno == PNO_LINE_SENS_DRV || \
1492                     pThrCreInfo->pno == PNO_NAVI_GPS_MAIN || \
1493                     pThrCreInfo->pno == PNO_NAVI_GPS_RCV  ||
1494                     pThrCreInfo->pno == PNO_CLK_GPS) {
1495                         (pThrCreInfo->routine)(h_app);
1496                 } else {
1497                     /* Thread creation */
1498                     threadHandle = FrameworkunifiedCreateChildThread(h_app,
1499                                                        (PCSTR)(pThrCreInfo->p_name),
1500                                                        pThrCreInfo->routine,
1501                                                        &PosStopThreadDummy);
1502                     if (threadHandle == NULL) {  /* If the thread creation fails */
1503                         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
1504                                       "FrameworkunifiedCreateChildThread ERROR!! [tHandle=%p]",
1505                                       threadHandle);
1506                         _pb_Exit();
1507                         /* don't arrive here. */
1508                     } else {
1509                         /* Thread activation (Notify the startup mode) */
1510                         eStatus = FrameworkunifiedStartChildThread(h_app,
1511                                                       threadHandle,
1512                                                       sizeof(EnumSetupMode_POS),
1513                                                       reinterpret_cast<void*>(peMode));
1514                         if (eStatus != eFrameworkunifiedStatusOK) {
1515                             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
1516                                           "FrameworkunifiedStartChildThread ERROR!! [eStatus=%d, name=%s]",
1517                                           eStatus,
1518                                           pThrCreInfo->p_name);
1519                         } else {
1520                             pThrCreInfo->status = THREAD_STS_CREATING;
1521                             FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "name=%s", pThrCreInfo->p_name);
1522                         }
1523                     }
1524                 }
1525             }
1526         }
1527
1528         pThrCreInfo++;
1529     }
1530
1531     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "-");
1532
1533     return;
1534 }
1535
1536
1537 /**
1538  * @brief
1539  *   Termination of Positioning in-process threads
1540  */
1541 static void PosStopThread(void) {
1542     RET_API ret;
1543     ST_THREAD_CREATE_INFO* p_thr_cre_info = g_pos_thread_create_info;
1544     BOOL *p_thr_stop_req = &g_thread_stop_req;
1545     uint8_t uc_msg = 0;
1546     uint8_t uc_order = 0;
1547     PNO us_pno = 0;
1548     int32_t i;
1549
1550     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "+");
1551
1552     for (i = 0; i < ETID_POS_MAX; i++) {
1553         if (uc_order < p_thr_cre_info->order) {
1554             uc_order = p_thr_cre_info->order;
1555             us_pno = p_thr_cre_info->pno;
1556         }
1557         p_thr_cre_info++;
1558     }
1559
1560     if (uc_order != 0) {
1561         /* Send Thread Termination Request */
1562         if (us_pno == PNO_NAVI_GPS_RCV) {
1563             /* Pos_gps_recv Only thread flag control */
1564             *p_thr_stop_req = TRUE;
1565         } else {
1566             ret = PosSndMsg(us_pno, CID_THREAD_STOP_REQ, &uc_msg, sizeof(uc_msg));
1567             if (ret != RET_NORMAL) {
1568                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
1569                               "PosSndMsg ERROR!! [ret = %d]",
1570                               ret);
1571             }
1572         }
1573     }
1574
1575     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "-");
1576
1577     return;
1578 }
1579
1580 /**
1581  * @brief
1582  *   Backup RAM initialization
1583  */
1584 static void PosBackupDataInit(void) {
1585     UNIT_TYPE e_type = UNIT_TYPE_NONE;
1586     EFrameworkunifiedStatus e_status;
1587     BOOL b_is_available;
1588     ST_GPS_SET_TIME st_gps_set_time;
1589
1590     (void)memset( reinterpret_cast<void *>(&st_gps_set_time), 0, (size_t)sizeof(st_gps_set_time) );
1591
1592     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "+");
1593
1594     e_type = GetEnvSupportInfo();
1595     if (e_type == UNIT_TYPE_GRADE1) {
1596         /* Set GPS date and time */
1597         e_status = BackupMgrIfBackupDataWt(D_BK_ID_POS_GPS_TIME_SET_INFO,
1598                                             &st_gps_set_time,
1599                                             0,
1600                                             sizeof(st_gps_set_time),
1601                                             &b_is_available);
1602         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "D_BK_ID_POS_GPS_TIME_SET_INFO:W:Clear");
1603         if (e_status != eFrameworkunifiedStatusOK) {
1604             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
1605                           "BackupMgrIfBackupDataWt ERROR!! [e_status=%d, b_is_available=%d]",
1606                           e_status,
1607                           b_is_available);
1608         }
1609     } else if (e_type == UNIT_TYPE_GRADE2) {
1610       /*
1611        *  Note.
1612        *  This feature branches processing depending on the unit type.
1613        */
1614     } else {
1615         /* No processing */
1616     }
1617
1618     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "-");
1619
1620     return;
1621 }
1622
1623 /**
1624  * @brief
1625  *   Callback function for registering the dispatcher()
1626  *
1627  * @param[in]  h_app    Application handle
1628  *
1629  * @return    eFrameworkunifiedStatusOK    Normal completion
1630  */
1631 static EFrameworkunifiedStatus PosThreadCreateComp(HANDLE h_app) {
1632     EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
1633     uint8_t* pRcvMsg;
1634     uint32_t size;
1635     uint8_t* pLastThreadSts = &g_last_thread_sts;
1636     ST_THREAD_CREATE_INFO* pThrCreInfo = g_pos_thread_create_info;
1637     uint8_t* pLastNumThr = &g_last_num_of_thread;
1638     uint8_t* pLastSrvSts = &g_last_srv_sts;
1639     uint8_t* pLastNtfySts = &g_last_ntfy_sts;
1640     EnumTID_POS eTid;
1641     int32_t i;
1642     static BOOL isSetAvailable = FALSE;
1643
1644     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "+");
1645
1646     pRcvMsg = g_rcv_msg_buf;
1647
1648     size = PosGetMsg(h_app, reinterpret_cast<void**>(&pRcvMsg), MAX_MSG_BUF_SIZE);
1649     if (size != 0) {  // LCOV_EXCL_BR_LINE 4: nsfw error
1650         (*pLastNumThr)++;
1651
1652         eTid = *(reinterpret_cast<EnumTID_POS*>(pRcvMsg));
1653
1654         FRAMEWORKUNIFIEDLOG(ZONE_17, __FUNCTION__, 
1655                       "Get message = [Sender:%s][CID:0x%X]",
1656                       (pThrCreInfo + eTid)->p_name,
1657                       CID_THREAD_CREATE_COMP);
1658
1659         /* Thread Management Variable Updates */
1660         *pLastThreadSts = static_cast<uint8_t>(*pLastThreadSts | (0x1u << eTid));
1661         (pThrCreInfo + eTid)->status = THREAD_STS_CREATED;
1662         (pThrCreInfo + eTid)->order  = *pLastNumThr;
1663
1664         /* Individual processing of started threads */
1665         switch (eTid) {
1666             case ETID_POS_SENS: /* When sensor driver thread startup is completed */
1667             {
1668                 /* When PSMShadow startup completion notice has been received */
1669                 if (((NTFY_MSK_PS_PSMSHADOW_INIT_COMP) & (*pLastNtfySts)) == NTFY_MSK_PS_PSMSHADOW_INIT_COMP) {
1670                     /* External pin status request */
1671                     LineSensDrvExtTermStsReq();
1672                 }
1673                 break;
1674             }
1675             case ETID_POS_GPS: /* When the GPS management thread has started */
1676             {
1677                 /* NSBackupMgr/Availability=When TRUE notification has been received */
1678                 if (((NTFY_MSK_NS_BACKUPMGR_AVAILABILITY) & (*pLastSrvSts)) == NTFY_MSK_NS_BACKUPMGR_AVAILABILITY) {
1679                     /* Backup data read request to GSP management thread */
1680                     (void)DEVGpsSndBackupDataLoadReq();
1681                 }
1682                 break;
1683             }
1684             default: /* Other thread startup completion time */
1685                 break;
1686         }
1687
1688         PosCreateThread(h_app);
1689
1690         for (i = 0; i < ETID_POS_MAX; i++) {
1691             if ((pThrCreInfo->is_depended == TRUE) && (pThrCreInfo->status != THREAD_STS_CREATED)) {
1692                 break; /* Positioning/Availability->TRUE condition does not meet */
1693             }
1694             pThrCreInfo++;
1695         }
1696
1697         if ((i == ETID_POS_MAX) && (isSetAvailable == FALSE)) {
1698             /* Positionig/Availability -> TRUE */
1699             eStatus = FrameworkunifiedPublishServiceAvailability(h_app, TRUE);
1700             if (eFrameworkunifiedStatusOK != eStatus) {
1701                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
1702                               "FrameworkunifiedPublishServiceAvailability ERROR!! [eStatus = %d]",
1703                               eStatus);
1704             } else {
1705                 FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "Positioning/Availability -> TRUE");
1706                 isSetAvailable = TRUE;
1707             }
1708         }
1709     }
1710
1711     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "-");
1712
1713     return eFrameworkunifiedStatusOK;
1714 }
1715
1716
1717 /**
1718  * @brief
1719  *   Callback function for registering the dispatcher()
1720  *
1721  * @param[in]  h_app    Application handle
1722  *
1723  * @return    eFrameworkunifiedStatusOK    Normal completion
1724  */
1725 static EFrameworkunifiedStatus PosThreadStopComp(HANDLE h_app) {
1726     EFrameworkunifiedStatus eStatus;
1727     BOOL bIsAvailable;
1728
1729     uint8_t* pRcvMsg;
1730     uint32_t size;
1731     uint8_t* pLastThreadSts = &g_last_thread_sts;
1732     ST_THREAD_CREATE_INFO* pThrCreInfo = g_pos_thread_create_info;
1733     uint8_t* pLastNumThr = &g_last_num_of_thread;
1734     BOOL *pThrStopReq = &g_thread_stop_req;
1735     EnumTID_POS eTid;
1736
1737     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "+");
1738
1739     pRcvMsg = g_rcv_msg_buf;
1740
1741     size = PosGetMsg(h_app, reinterpret_cast<void**>(&pRcvMsg), MAX_MSG_BUF_SIZE);
1742     if (size != 0) {  // LCOV_EXCL_BR_LINE 4: nsfw error
1743         (*pLastNumThr)--;
1744
1745         eTid = *(reinterpret_cast<EnumTID_POS*>(pRcvMsg));
1746
1747         FRAMEWORKUNIFIEDLOG(ZONE_17, __FUNCTION__, 
1748                       "Get message = [Sender:%s][CID:0x%X]",
1749                       (pThrCreInfo + eTid)->p_name,
1750                       CID_THREAD_STOP_COMP);
1751
1752         *pLastThreadSts = static_cast<uint8_t>(*pLastThreadSts & ~(0x1u << eTid));
1753
1754         (pThrCreInfo + eTid)->status = THREAD_STS_NOEXIST;
1755         (pThrCreInfo + eTid)->order  = 0;
1756
1757         if ((pThrCreInfo + eTid)->pno == PNO_NAVI_GPS_RCV) {
1758             *pThrStopReq = FALSE;
1759         }
1760     }
1761
1762     PosStopThread();
1763
1764     /* When all threads have stopped */
1765     if (*pLastThreadSts == 0) {
1766         /* Unregister callback function */
1767         eStatus = FrameworkunifiedDetachCallbacksFromDispatcher(h_app,
1768                                                    "NS_ANY_SRC",
1769                                                    (const PUI_32)g_positioning_cids,
1770                                                    _countof(g_positioning_cids), NULL);
1771         if (eStatus != eFrameworkunifiedStatusOK) {  /* In the event of failure */
1772             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
1773                           "PositioningDetachCallbacksToDispatcher Failed in FrameworkunifiedOnStop [eStatus:%d]",
1774                           eStatus);
1775         }
1776
1777         /* Sensor log stop processing */
1778         SensLogTerminate();
1779
1780         /* DeviceDetectionServiceIf termination process */
1781         eStatus = DevDetectSrvIfUnRegisterForDeviceDetectionEvent(SS_DEV_DETECT_ANY_USB_EV, &bIsAvailable);
1782         if (eStatus != eFrameworkunifiedStatusOK) {
1783             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
1784                           "DeviceDetectionServiceIf UnRegisterEvent ERROR!! [sts:%d, ava:%d]",
1785                           eStatus,
1786                           bIsAvailable);
1787         } else {
1788             eStatus = DevDetectSrvIfCloseSessionRequest(&bIsAvailable);
1789             if (eFrameworkunifiedStatusOK != eStatus) {
1790                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
1791                               "DeviceDetectionServiceIf CloseSession ERROR!! [sts=%d, ava:%d]",
1792                               eStatus,
1793                               bIsAvailable);
1794             }
1795         }
1796
1797         (void)VehicleIfDetachCallbacksFromDispatcher((const PUI_32)g_positioning_cids_vehicle,
1798                                                             _countof(g_positioning_cids_vehicle));
1799
1800         /* Releasing Base API Resources */
1801         _pb_Teardown_CWORD64_API();
1802
1803         /* Stop processing completion response */
1804         SendInterfaceunifiedOnStopResponseToSystemManager(eFrameworkunifiedStatusOK);
1805     }
1806
1807     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "-");
1808
1809     return eFrameworkunifiedStatusOK;
1810 }
1811
1812 /**
1813  * @brief
1814  *   Callback function for registering the dispatcher(POS_RegisterListenerPkgSensData)
1815  *
1816  *   Send a message to an internal thread.
1817  *
1818  * @param[in]  h_app    Application handle
1819  *
1820  * @return    eFrameworkunifiedStatusOK    Normal completion
1821  */
1822 static EFrameworkunifiedStatus PosPosifRegisterListenerPkgSensorData(HANDLE h_app) {
1823     RET_API ret;
1824     uint8_t* pRcvMsg;
1825     uint32_t size;
1826     EventID ulEventId;
1827     PCSTR pName;
1828     static const PCSTR pNone = "-";
1829
1830     FRAMEWORKUNIFIEDLOG(ZONE_28, __FUNCTION__, "+");
1831
1832     pRcvMsg = g_rcv_msg_buf;
1833
1834     size = PosGetMsg(h_app, reinterpret_cast<void**>(&pRcvMsg), MAX_MSG_BUF_SIZE);
1835     if (size != 0) {  // LCOV_EXCL_BR_LINE 4: nsfw error
1836         pName = _pb_CnvPno2Name((reinterpret_cast<SENSOR_MSG_DELIVERY_ENTRY_DAT*>(pRcvMsg))->pno);
1837         if (pName == NULL) {
1838             pName = pNone;
1839         }
1840         FRAMEWORKUNIFIEDLOG(ZONE_17, __FUNCTION__, 
1841                       "Get message = [Sender:%s][CID:0x%X",
1842                       pName,
1843                       CID_SENSORIF_PKG_DELIVERY_ENTRY_EXT);
1844
1845         /* Send Messages to Internal Thread */
1846         ret = PosSndMsg(PNO_VEHICLE_SENSOR, CID_SENSORIF_PKG_DELIVERY_ENTRY_EXT, pRcvMsg, size);
1847         if (ret != RET_NORMAL) {
1848             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PosSndMsg ERROR!! [ret = %d]", ret);
1849             /* Event Generation */
1850             ulEventId = PosCreateEvent((reinterpret_cast<SENSOR_MSG_DELIVERY_ENTRY_DAT*>(pRcvMsg))->pno);
1851             if (ulEventId != 0) {
1852                 /* Event publishing */
1853                 ret = _pb_SetEvent(ulEventId, SAPI_EVSET_ABSOLUTE, SENSOR_RET_ERROR_INNER);
1854                 if (ret != RET_NORMAL) {
1855                     /* Event issuance failure */
1856                     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_SetEvent ERROR!! [ret = %d]", ret);
1857                 }
1858                 /* Event deletion */
1859                 (void)PosDeleteEvent(ulEventId);
1860             } else {
1861                 /* Event generation failure */
1862                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PosCreateEvent ERROR!!");
1863             }
1864         }
1865     }
1866
1867     FRAMEWORKUNIFIEDLOG(ZONE_28, __FUNCTION__, "-");
1868
1869     return eFrameworkunifiedStatusOK;
1870 }
1871
1872 /**
1873  * @brief
1874  *   Callback function for registering the dispatcher(POS_RegisterListenerSensData)
1875  *
1876  *   Send a message to an internal thread.
1877  *
1878  * @param[in]  h_app    Application handle
1879  *
1880  * @return    eFrameworkunifiedStatusOK    Normal completion
1881  */
1882 static EFrameworkunifiedStatus PosPosifRegisterListenerSensorData(HANDLE h_app) {
1883     RET_API ret;
1884     uint8_t* pRcvMsg;
1885     uint32_t size;
1886     EventID ulEventId;
1887     PCSTR pName;
1888     static const PCSTR pNone = "-";
1889
1890     FRAMEWORKUNIFIEDLOG(ZONE_28, __FUNCTION__, "+");
1891
1892     pRcvMsg = g_rcv_msg_buf;
1893
1894     size = PosGetMsg(h_app, reinterpret_cast<void**>(&pRcvMsg), MAX_MSG_BUF_SIZE);
1895     if (size != 0) {  // LCOV_EXCL_BR_LINE 4: nsfw error
1896         pName = _pb_CnvPno2Name((reinterpret_cast<VEHICLE_MSG_DELIVERY_ENTRY_DAT*>(pRcvMsg))->pno);
1897         if (pName == NULL) {
1898             pName = pNone;
1899         }
1900         FRAMEWORKUNIFIEDLOG(ZONE_17, __FUNCTION__, 
1901                       "Get message = [Sender:%s][CID:0x%X]",
1902                       pName,
1903                       CID_VEHICLEIF_DELIVERY_ENTRY);
1904
1905         /* Send Messages to Internal Thread */
1906         ret = PosSndMsg(PNO_VEHICLE_SENSOR, CID_VEHICLEIF_DELIVERY_ENTRY, pRcvMsg, size);
1907         if (ret != RET_NORMAL) {
1908             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PosSndMsg ERROR!! [ret = %d]", ret);
1909             /* Event Generation */
1910             ulEventId = VehicleCreateEvent((reinterpret_cast<VEHICLE_MSG_DELIVERY_ENTRY_DAT*>(pRcvMsg))->pno);
1911             if (ulEventId != 0) {
1912                 /* Event publishing */
1913                 ret = _pb_SetEvent(ulEventId, SAPI_EVSET_ABSOLUTE, SENSOR_RET_ERROR_INNER);
1914                 if (ret != RET_NORMAL) {
1915                     /* Event issuance failure */
1916                     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_SetEvent ERROR!! [ret = %d]", ret);
1917                 }
1918                 /* Event deletion */
1919                 (void)VehicleDeleteEvent(ulEventId);
1920             } else {
1921                 /* Event generation failure */
1922                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "VehicleCreateEvent ERROR!!");
1923             }
1924         }
1925     }
1926
1927     FRAMEWORKUNIFIEDLOG(ZONE_28, __FUNCTION__, "-");
1928
1929     return eFrameworkunifiedStatusOK;
1930 }
1931
1932 /**
1933  * @brief
1934  *   Callback function for registering the dispatcher(POS_ReqGPSSetting)
1935  *
1936  *   Send a message to an internal thread.
1937  *
1938  * @param[in]  h_app    Application handle
1939  *
1940  * @return    eFrameworkunifiedStatusOK    Normal completion
1941  */
1942 static EFrameworkunifiedStatus PosPosifReqGpsSetting(HANDLE h_app) {
1943     RET_API ret;
1944     uint8_t* pRcvMsg;
1945     uint32_t size;
1946     uint8_t ucResult = SENSLOG_RES_FAIL;
1947
1948     FRAMEWORKUNIFIEDLOG(ZONE_28, __FUNCTION__, "+");
1949
1950     pRcvMsg = g_rcv_msg_buf;
1951
1952     size = PosGetMsg(h_app, reinterpret_cast<void**>(&pRcvMsg), MAX_MSG_BUF_SIZE);
1953     if (size != 0) {  // LCOV_EXCL_BR_LINE 4: nsfw error
1954         FRAMEWORKUNIFIEDLOG(ZONE_17, __FUNCTION__, 
1955                       "Get message = [Sender:-][CID:0x%X]",
1956                       CID_SENSORIF__CWORD82__REQUEST);
1957         ucResult = SENSLOG_RES_SUCCESS;
1958
1959         /* Send Messages to Internal Thread */
1960         ret = PosSndMsg(PNO_VEHICLE_SENSOR, CID_SENSORIF__CWORD82__REQUEST, pRcvMsg, size);
1961         if (ret != RET_NORMAL) {
1962             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PosSndMsg ERROR!! [ret = %d]", ret);
1963         }
1964     }
1965
1966     SensLogWriteInputData(SENSLOG_DATA_I_GPSSET, 0, 0, pRcvMsg, static_cast<uint16_t>(size),
1967                           ucResult, SENSLOG_ON, SENSLOG_ON);
1968     FRAMEWORKUNIFIEDLOG(ZONE_28, __FUNCTION__, "-");
1969
1970     return eFrameworkunifiedStatusOK;
1971 }
1972
1973 /**
1974  * @brief
1975  *   Callback function for registering the dispatcher(POS_SetGPSInfo)
1976  *
1977  *   Send a message to an internal thread.
1978  *
1979  * @param[in]  h_app    Application handle
1980  *
1981  * @return    eFrameworkunifiedStatusOK    Normal completion
1982  */
1983 static EFrameworkunifiedStatus PosPosifSetGpsInfo(HANDLE h_app) {
1984     RET_API ret;
1985     uint8_t* pRcvMsg;
1986     uint32_t size;
1987     uint8_t ucResult = SENSLOG_RES_FAIL;
1988
1989     FRAMEWORKUNIFIEDLOG(ZONE_28, __FUNCTION__, "+");
1990
1991     pRcvMsg = g_rcv_msg_buf;
1992
1993     size = PosGetMsg(h_app, reinterpret_cast<void**>(&pRcvMsg), MAX_MSG_BUF_SIZE);
1994     if (size != 0) {  // LCOV_EXCL_BR_LINE 4: nsfw error
1995         FRAMEWORKUNIFIEDLOG(ZONE_17, __FUNCTION__, 
1996                       "Get message = [Sender:-][CID:0x%X]",
1997                       CID_NAVIINFO_DELIVER);
1998         ucResult = SENSLOG_RES_SUCCESS;
1999
2000         /* Send Messages to Internal Thread */
2001         ret = PosSndMsg(PNO_NAVI_GPS_MAIN, CID_NAVIINFO_DELIVER, pRcvMsg, size);
2002         if (ret != RET_NORMAL) {
2003             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PosSndMsg ERROR!! [ret = %d]", ret);
2004         }
2005     }
2006     SensLogWriteInputData(SENSLOG_DATA_I_GPSINF, 0, 0, pRcvMsg, static_cast<uint16_t>(size),
2007                          ucResult, SENSLOG_ON, SENSLOG_ON);
2008     FRAMEWORKUNIFIEDLOG(ZONE_28, __FUNCTION__, "-");
2009
2010     return eFrameworkunifiedStatusOK;
2011 }
2012
2013 /**
2014  * @brief
2015  *   Callback function for registering the dispatcher(POS_GetGPSInfo)
2016  *
2017  *   Send a message to an internal thread.
2018  *
2019  * @param[in]  h_app    Application handle
2020  *
2021  * @return    eFrameworkunifiedStatusOK    Normal completion
2022  */
2023 static EFrameworkunifiedStatus PosPosifGetGpsInfo(HANDLE h_app) {
2024     RET_API ret;
2025     uint8_t* pRcvMsg;
2026     uint32_t size;
2027     EventID ulEventId;
2028     PCSTR pName;
2029     static const PCSTR pNone = "-";
2030
2031     FRAMEWORKUNIFIEDLOG(ZONE_28, __FUNCTION__, "+");
2032
2033     pRcvMsg = g_rcv_msg_buf;
2034
2035     size = PosGetMsg(h_app, reinterpret_cast<void**>(&pRcvMsg), MAX_MSG_BUF_SIZE);
2036     if (size != 0) {  // LCOV_EXCL_BR_LINE 4: nsfw error
2037         pName = _pb_CnvPno2Name((reinterpret_cast<VEHICLE_MSG_GET_VEHICLE_DATA_DAT*>(pRcvMsg))->pno);
2038         if (pName == NULL) {
2039             pName = pNone;
2040         }
2041         FRAMEWORKUNIFIEDLOG(ZONE_17, __FUNCTION__, 
2042                       "Get message = [Sender:%s][CID:0x%X]",
2043                       pName,
2044                       CID_VEHICLEIF_GET_VEHICLE_DATA);
2045
2046         /* Send Messages to Internal Thread */
2047         ret = PosSndMsg(PNO_VEHICLE_SENSOR, CID_VEHICLEIF_GET_VEHICLE_DATA, pRcvMsg, size);
2048         if (ret != RET_NORMAL) {
2049             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PosSndMsg ERROR!! [ret = %d]", ret);
2050             /* Event Generation */
2051             ulEventId = VehicleCreateEvent((reinterpret_cast<VEHICLE_MSG_GET_VEHICLE_DATA_DAT*>(pRcvMsg))->pno);
2052             if (ulEventId != 0) {
2053                 /* Event publishing */
2054                 ret = _pb_SetEvent(ulEventId, SAPI_EVSET_ABSOLUTE, POS_RET_ERROR_INNER);
2055                 if (ret != RET_NORMAL) {
2056                     /* Event issuance failure */
2057                     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
2058                                   "_pb_SetEvent ERROR!! [ret = %d]",
2059                                   ret);
2060                 }
2061                 /* Event deletion */
2062                 (void)VehicleDeleteEvent(ulEventId);
2063             } else {
2064                 /* Event generation failure */
2065                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "VehicleCreateEvent ERROR!!");
2066             }
2067         }
2068     }
2069
2070     FRAMEWORKUNIFIEDLOG(ZONE_28, __FUNCTION__, "-");
2071
2072     return eFrameworkunifiedStatusOK;
2073 }
2074
2075 /**
2076  * @brief
2077  *   Callback function for registering the dispatcher(CID_POSIF_SET_DATA)
2078  *
2079  *   Send a message to an internal thread.
2080  *
2081  * @param[in]  h_app    Application handle
2082  *
2083  * @return    eFrameworkunifiedStatusOK    Normal completion
2084  */
2085 static EFrameworkunifiedStatus PosPosifSetData(HANDLE h_app) {
2086     RET_API ret;
2087     uint8_t* pRcvMsg;
2088     uint32_t size;
2089     EventID ulEventId;
2090     PCSTR pName;
2091     static const PCSTR pNone = "-";
2092     uint8_t ucResult = SENSLOG_RES_FAIL;
2093
2094     FRAMEWORKUNIFIEDLOG(ZONE_28, __FUNCTION__, "+");
2095
2096     pRcvMsg = g_rcv_msg_buf;
2097
2098     size = PosGetMsg(h_app, reinterpret_cast<void**>(&pRcvMsg), MAX_MSG_BUF_SIZE);
2099     if (size != 0) {  // LCOV_EXCL_BR_LINE 4: nsfw error
2100         ucResult = SENSLOG_RES_SUCCESS;
2101
2102         pName = _pb_CnvPno2Name((reinterpret_cast<POS_MSGINFO*>(pRcvMsg))->pno);
2103         if (pName == NULL) {
2104             pName = pNone;
2105         }
2106         FRAMEWORKUNIFIEDLOG(ZONE_17, __FUNCTION__, 
2107                       "Get message = [Sender:%s][CID:0x%X][DID:0x%X]",
2108                       pName,
2109                       CID_POSIF_SET_DATA,
2110                       (reinterpret_cast<POS_MSGINFO*>(pRcvMsg))->did);
2111
2112         /* Send Messages to Internal Thread */
2113         ret = PosSndMsg(PNO_VEHICLE_SENSOR, CID_POSIF_SET_DATA, pRcvMsg, size);
2114         if (ret != RET_NORMAL) {
2115             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PosSndMsg ERROR!! [ret = %d]", ret);
2116             if ((reinterpret_cast<POS_MSGINFO*>(pRcvMsg))->did == VEHICLE_DID_SETTINGTIME) {
2117                 /* GPS time setting(When waiting for completion of an event, an event is issued. */
2118                 /* Event Generation */
2119                 ulEventId = VehicleCreateEvent((reinterpret_cast<POS_MSGINFO*>(pRcvMsg))->pno);
2120                 if (ulEventId != 0) {
2121                     /* Event publishing */
2122                     ret = _pb_SetEvent(ulEventId, SAPI_EVSET_ABSOLUTE, POS_RET_ERROR_INNER);
2123                     if (ret != RET_NORMAL) {
2124                         /* Event issuance failure */
2125                         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
2126                                       "_pb_SetEvent ERROR!! [ret = %d]",
2127                                       ret);
2128                     }
2129                     /* Event deletion */
2130                     (void)VehicleDeleteEvent(ulEventId);
2131                 } else {
2132                     /* Event generation failure */
2133                     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "VehicleCreateEvent ERROR!!");
2134                 }
2135             }
2136         }
2137     }
2138     SensLogWriteInputData(SENSLOG_DATA_I_UNSPECIFIED,
2139                           (reinterpret_cast<POS_MSGINFO*>(pRcvMsg))->did,
2140                           0,
2141                           pRcvMsg,
2142                           static_cast<uint16_t>(size),
2143                           ucResult,
2144                           SENSLOG_ON,
2145                           SENSLOG_ON);
2146     FRAMEWORKUNIFIEDLOG(ZONE_28, __FUNCTION__, "-");
2147
2148     return eFrameworkunifiedStatusOK;
2149 }
2150
2151 /**
2152  * @brief
2153  *   Callback function for registering the dispatcher(CID_GPS_REQRESET)
2154  *
2155  *   Send a message to an internal thread.
2156  *
2157  * @param[in]  h_app    Application handle
2158  *
2159  * @return    eFrameworkunifiedStatusOK    Normal completion
2160  */
2161 static EFrameworkunifiedStatus PosPosifReqGpsReset(HANDLE h_app) {
2162     RET_API ret;
2163     uint8_t* pRcvMsg;
2164     uint32_t size;
2165     EventID ulEventId;
2166     PCSTR pName;
2167     static const PCSTR pNone = "-";
2168     uint8_t ucResult = SENSLOG_RES_FAIL;
2169
2170     FRAMEWORKUNIFIEDLOG(ZONE_28, __FUNCTION__, "+");
2171
2172     pRcvMsg = g_rcv_msg_buf;
2173
2174     size = PosGetMsg(h_app, reinterpret_cast<void**>(&pRcvMsg), MAX_MSG_BUF_SIZE);
2175     if (size != 0) {  // LCOV_EXCL_BR_LINE 4: nsfw error
2176         ucResult = SENSLOG_RES_SUCCESS;
2177
2178         pName = _pb_CnvPno2Name((reinterpret_cast<POS_RESETINFO*>(pRcvMsg))->snd_pno);
2179         if (pName == NULL) {
2180             pName = pNone;
2181         }
2182         FRAMEWORKUNIFIEDLOG(ZONE_17, __FUNCTION__, 
2183                       "Get message = [Sender:%s][CID:0x%X]",
2184                       pName,
2185                       CID_GPS_REQRESET);
2186
2187         /* Send Messages to Internal Thread */
2188         ret = PosSndMsg(PNO_NAVI_GPS_MAIN, CID_GPS_REQRESET, pRcvMsg, size);
2189         if (ret != RET_NORMAL) {
2190             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PosSndMsg ERROR!! [ret = %d]", ret);
2191
2192             /* Event Generation */
2193             ulEventId = VehicleCreateEvent((reinterpret_cast<POS_RESETINFO*>(pRcvMsg))->snd_pno);
2194             if (0 != ulEventId) {
2195                 /* Event publishing */
2196                 ret = _pb_SetEvent(ulEventId, SAPI_EVSET_ABSOLUTE, POS_RET_ERROR_INNER);
2197                 if (ret != RET_NORMAL) {
2198                     /* Event issuance failure */
2199                     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
2200                                   "_pb_SetEvent ERROR!! [ret = %d]",
2201                                   ret);
2202                 }
2203                 /* Event deletion */
2204                 (void)VehicleDeleteEvent(ulEventId);
2205             } else {
2206                 /* Event generation failure */
2207                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "VehicleCreateEvent ERROR!!");
2208             }
2209         }
2210     }
2211
2212     SensLogWriteInputData(SENSLOG_DATA_I_GPSRST, 0, 0, pRcvMsg, static_cast<uint16_t>(size),
2213                           ucResult, SENSLOG_ON, SENSLOG_ON);
2214     FRAMEWORKUNIFIEDLOG(ZONE_28, __FUNCTION__, "-");
2215
2216     return eFrameworkunifiedStatusOK;
2217 }
2218
2219 /**
2220  * @brief
2221  *   Callback function for registering the dispatcher(CID_VEHICLESENS_VEHICLE_INFO)
2222  *
2223  *   Send a message to an internal thread.
2224  *
2225  * @param[in]  h_app    Application handle
2226  *
2227  * @return    eFrameworkunifiedStatusOK    Normal completion
2228  */
2229 static EFrameworkunifiedStatus PosVehicleInfoRcv(HANDLE h_app) {
2230   LSDRV_MSG_LSDATA_DAT_G line_sns_data;
2231   RET_API ret = RET_NORMAL;
2232
2233   memset(&line_sns_data, 0, sizeof(line_sns_data));
2234   LSDRV_MSG_LSDATA_DAT_G *p_line_sns_data = &line_sns_data;
2235   VEHICLE_UNIT_MSG_VSINFO *p_vehicle_msg = NULL;
2236   uint32_t size = 0;
2237   uint16_t us_speed = 0;
2238
2239   uint8_t* pRcvMsg = g_rcv_msg_buf;
2240
2241   size = PosGetMsg(h_app, reinterpret_cast<void**>(&pRcvMsg), MAX_MSG_BUF_SIZE);
2242   if (size != 0) {  // LCOV_EXCL_BR_LINE 4: nsfw error
2243     memset(p_line_sns_data, 0x00, sizeof(line_sns_data));
2244     p_vehicle_msg = (reinterpret_cast<VEHICLE_UNIT_MSG_VSINFO*>(pRcvMsg));
2245     switch (p_vehicle_msg->data.did) {
2246       // SPEED info
2247       case VEHICLE_DID_SPEED:
2248       {
2249         p_line_sns_data->uc_data_num = LSDRV_KINDS_MAX;
2250         p_line_sns_data->st_data[LSDRV_SPEED_KMPH].ul_did = POSHAL_DID_SPEED_KMPH;
2251         p_line_sns_data->st_data[LSDRV_SPEED_KMPH].uc_size = POS_SNDMSG_DTSIZE_2;
2252         p_line_sns_data->st_data[LSDRV_SPEED_KMPH].uc_sns_cnt = 0;
2253
2254         char p_env_variable[VP_MAX_LENGTH];
2255
2256         VP_GetEnv("VP__CWORD31__SPEED", p_env_variable);
2257         if (0 == strcmp(p_env_variable, "direct")) {
2258           int16_t speed = 0;
2259           // To obtain the vehicle speed from Direct lanes,1 to 2 bytes of received data
2260           memcpy(&speed, &p_vehicle_msg->data.data[0], sizeof(speed));
2261           us_speed = static_cast<uint16_t>(abs(speed));
2262           // Unit conversion [km/h] -> [0.01km/h]
2263           us_speed = static_cast<uint16_t>(us_speed * 100);
2264         } else if (0 == strcmp(p_env_variable, "CAN")) {
2265           UINT16 speed = 0;
2266           // To obtain the vehicle speed from CAN,2 to 3 bytes of received data
2267           memcpy(&speed, &p_vehicle_msg->data.data[1], sizeof(speed));
2268           us_speed = static_cast<uint16_t>(abs(speed));
2269           // Unit conversion [km/h] -> [0.01km/h]
2270           us_speed = static_cast<uint16_t>(us_speed * 100);
2271         } else {
2272           // In case of invalid value, the vehicle speed is acquired by CAN.
2273           UINT16 speed = 0;
2274           memcpy(&speed, &p_vehicle_msg->data.data[1], sizeof(speed));
2275           us_speed = static_cast<uint16_t>(abs(speed));
2276           // Unit conversion [km/h] -> [0.01km/h]
2277           us_speed = static_cast<uint16_t>(us_speed * 100);
2278         }
2279
2280         memcpy(&p_line_sns_data->st_data[LSDRV_SPEED_KMPH].uc_data[0], &us_speed, sizeof(us_speed));
2281
2282         ret = PosSndMsg(PNO_VEHICLE_SENSOR, CID_LINESENS_VEHICLE_DATA_G,
2283                         reinterpret_cast<void*>(p_line_sns_data), sizeof(line_sns_data));
2284
2285         break;
2286       }
2287       // REV information
2288       case VEHICLE_DID_REV:
2289       {
2290         p_line_sns_data->uc_data_num = LSDRV_KINDS_MAX;
2291         p_line_sns_data->st_data[LSDRV_REV].ul_did = VEHICLE_DID_REV;
2292         p_line_sns_data->st_data[LSDRV_REV].uc_size = POS_SNDMSG_DTSIZE_1;
2293         p_line_sns_data->st_data[LSDRV_REV].uc_sns_cnt = 0;
2294         p_line_sns_data->st_data[LSDRV_REV].uc_data[0] = p_vehicle_msg->data.data[0];
2295
2296         ret = PosSndMsg(PNO_VEHICLE_SENSOR, CID_LINESENS_VEHICLE_DATA_G,
2297                             reinterpret_cast<void*>(p_line_sns_data), sizeof(line_sns_data));
2298         break;
2299       }
2300
2301       // Speed Pulse information
2302       case VEHICLE_DID_SPEED_PULSE_VEHICLE:
2303       {
2304         p_line_sns_data->uc_data_num = LSDRV_KINDS_MAX;
2305         p_line_sns_data->st_data[LSDRV_SPEED_PULSE].ul_did = POSHAL_DID_SPEED_PULSE;
2306         p_line_sns_data->st_data[LSDRV_SPEED_PULSE].uc_size = sizeof(float);
2307         p_line_sns_data->st_data[LSDRV_SPEED_PULSE].uc_sns_cnt = 0;
2308
2309         memcpy(&p_line_sns_data->st_data[LSDRV_SPEED_PULSE].uc_data[0],
2310                                             &p_vehicle_msg->data.data[0], sizeof(float));
2311
2312         p_line_sns_data->st_data[LSDRV_PULSE_TIME].ul_did = POSHAL_DID_PULSE_TIME;
2313         p_line_sns_data->st_data[LSDRV_PULSE_TIME].uc_size = sizeof(float);
2314         p_line_sns_data->st_data[LSDRV_PULSE_TIME].uc_sns_cnt = 0;
2315
2316         memcpy(&p_line_sns_data->st_data[LSDRV_PULSE_TIME].uc_data[0],
2317                        &p_vehicle_msg->data.data[sizeof(float)], sizeof(float));
2318
2319         ret = PosSndMsg(PNO_VEHICLE_SENSOR, CID_LINESENS_VEHICLE_DATA_G,
2320                             reinterpret_cast<void*>(p_line_sns_data), sizeof(line_sns_data));
2321
2322         break;
2323       }
2324       default:
2325         break;
2326     }
2327
2328     if (ret != RET_NORMAL) {
2329       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PosSndMsg ERROR!! [ret = %d]", ret);
2330     }
2331   }
2332   return eFrameworkunifiedStatusOK;
2333 }
2334
2335 /**
2336  * @brief
2337  *   Get Message
2338  *
2339  *   Get messages received by the dispatcher
2340  *
2341  * @param[in]  h_app  Application handle
2342  * @param[out] p_buf  Pointer to receive data storage buffer
2343  * @param[in]  Sizes of size receive data storage buffers
2344  *
2345  * @return    Received data size(0:Receiving error)
2346  */
2347 static uint32_t PosGetMsg(HANDLE h_app, void** p_buf, uint32_t size) {
2348     EFrameworkunifiedStatus eStatus;
2349     uint32_t ulSize = 0;
2350     void* pRcvBuf;
2351
2352     /* null check */
2353     if ((h_app == NULL) || (p_buf == NULL)) {  // LCOV_EXCL_BR_LINE 200: can not NULL
2354         // LCOV_EXCL_START 8: invalid
2355         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2356         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
2357                       "Argument ERROR!! [h_app = %p, p_buf = %p]",
2358                       h_app,
2359                       p_buf);
2360         // LCOV_EXCL_STOP
2361     } else {
2362         /* Check the size of received data */
2363         ulSize = FrameworkunifiedGetMsgLength(h_app);
2364         if (ulSize > size) {
2365             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2366                           "Message size ERROR!! [ulSize = %d, maxsize = %d]",
2367                           ulSize,
2368                           size);
2369             ulSize = 0;
2370         } else {
2371             /* Obtain data */
2372             eStatus = FrameworkunifiedGetDataPointer(h_app, &pRcvBuf);
2373             if (eStatus == eFrameworkunifiedStatusOK) {
2374                 *p_buf = pRcvBuf;
2375             } else if (eStatus == eFrameworkunifiedStatusInvldBufSize) {
2376                 eStatus = FrameworkunifiedGetMsgDataOfSize(h_app, *p_buf, ulSize);
2377                 /* When acquisition fails */
2378                 if (eStatus != eFrameworkunifiedStatusOK) {
2379                     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2380                                   "FrameworkunifiedGetMsgDataOfSize ERROR [eStatus:%d]",
2381                                   eStatus);
2382                     ulSize = 0;
2383                 }
2384             } else {
2385                 /* When acquisition fails */
2386                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2387                               "FrameworkunifiedGetDataPointer ERROR [eStatus:%d]",
2388                               eStatus);
2389                 ulSize = 0;
2390             }
2391         }
2392     }
2393
2394     return ulSize;
2395 }
2396
2397 /**
2398  * @brief
2399  *   Sending Messages for Internal Threads
2400  *
2401  *   Adds a header to the message received by the dispatcher and sends it to the internal thread..
2402  *
2403  * @param[in]  pno       PNO
2404  * @param[in]  cid      Command ID
2405  * @param[in]  p_msg_body  Sent message body
2406  * @param[in]  size         Send message size
2407  *
2408  * @return    RET_NORAML    Normal completion
2409  *            RET_ERROR    ABENDs
2410  */
2411 static RET_API PosSndMsg(PNO pno, CID cid, void* p_msg_body, uint32_t size) {
2412     RET_API    ret = RET_NORMAL;
2413     T_APIMSG_MSGBUF_HEADER* p;
2414     static u_int8 sndMsgBuf[MAX_MSG_BUF_SIZE + sizeof(T_APIMSG_MSGBUF_HEADER)];
2415
2416     if ((p_msg_body == NULL) || (size > MAX_MSG_BUF_SIZE)) {
2417         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR!! [p_msg_body = %p, size = %d]", p_msg_body, size);
2418         ret = RET_ERROR;
2419     } else {
2420         p = reinterpret_cast<T_APIMSG_MSGBUF_HEADER*>(sndMsgBuf);
2421
2422         /* Message header addition */
2423         p->hdr.cid = cid;
2424         p->hdr.msgbodysize = static_cast<uint16_t>(size);
2425
2426         /* Copy of the data section */
2427         memcpy((p + 1), p_msg_body, size);
2428
2429         /* Send a message to an internal thread */
2430         ret = _pb_SndMsg(pno, static_cast<uint16_t>(size + sizeof(T_APIMSG_MSGBUF_HEADER)), p, 0);
2431         /* When transmission fails */
2432         if (ret != RET_NORMAL) {
2433             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_SndMsg ERROR [ret = %d]", ret);
2434             ret = RET_ERROR;
2435         }
2436     }
2437
2438     return ret;
2439 }
2440
2441 /**
2442  * @brief
2443  *   SS_DevDetectSrv service OpenSessionAck Callback Functions
2444  *
2445  * @param  none
2446  *
2447  * @return eFrameworkunifiedStatusOK successful completion
2448  */
2449 static EFrameworkunifiedStatus PosOnDevDetectOpenSessionAck(HANDLE h_app) {
2450     EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
2451     BOOL bIsAvailable;
2452
2453     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+");
2454
2455     eStatus = DevDetectSrvIfDecodeOpenSessionResponse(&bIsAvailable);
2456     if (eFrameworkunifiedStatusOK != eStatus) {
2457         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
2458                       "DeviceDetectionServiceIf OpenSession ERROR!! [sts=%d, ava=%d]", eStatus, bIsAvailable);
2459     } else {
2460         eStatus = DevDetectSrvIfRegisterForDeviceDetectionEvent(SS_DEV_DETECT_ANY_USB_EV,
2461                                                                  &PosOnDevDetectEvent,
2462                                                                  NULL,
2463                                                                  &bIsAvailable);
2464         if (eFrameworkunifiedStatusOK != eStatus) {
2465             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
2466                           "DeviceDetectionServiceIf RegisterEvent ERROR!! [sts=%d, ava=%d]", eStatus, bIsAvailable);
2467         } else {
2468             eStatus = DevDetectSrvIfNotifyOnCloseSessionAck(&PosOnDevDetectCloseSessionAck, &bIsAvailable);
2469             if (eFrameworkunifiedStatusOK != eStatus) {
2470                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
2471                                      "DeviceDetectionServiceIf CloseSessionAck ERROR!! [sts=%d, ava=%d]",
2472                               eStatus,
2473                               bIsAvailable);
2474             }
2475         }
2476     }
2477
2478     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "-");
2479     return eFrameworkunifiedStatusOK;
2480 }
2481
2482 /**
2483  * @brief
2484  *   SS_DevDetectSrv service CloseSessionAck Callback Functions
2485  *
2486  * @param  none
2487  *
2488  * @return eFrameworkunifiedStatusOK successful completion
2489  */
2490 static EFrameworkunifiedStatus PosOnDevDetectCloseSessionAck(HANDLE h_app) {
2491     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+");
2492
2493     /* Sensor log stop processing */
2494     SensLogTerminate();
2495
2496     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "-");
2497     return eFrameworkunifiedStatusOK;
2498 }
2499
2500 /**
2501  * @brief
2502  *   SS_DevDetectSrv service Event Callback Functions
2503  *
2504  * @param  none
2505  *
2506  * @return eFrameworkunifiedStatusOK successful completion
2507  */
2508 static EFrameworkunifiedStatus PosOnDevDetectEvent(HANDLE h_app) {
2509     SS_MediaDetectInfo stMedia;
2510     EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
2511     uint32_t ulSize = 0;
2512     uint8_t mode;
2513
2514     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "+");
2515
2516     /* Check the size of received data */
2517     ulSize = FrameworkunifiedGetMsgLength(h_app);
2518     if (ulSize > sizeof(SS_MediaDetectInfo)) {
2519         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Message size ERROR!! [ulSize = %d, maxsize = %ld]",
2520                       ulSize, sizeof(SS_MediaDetectInfo));
2521         ulSize = 0;
2522     } else {
2523         /* Obtain data */
2524         eStatus = FrameworkunifiedGetMsgDataOfSize(h_app, &stMedia, ulSize);
2525         /* When acquisition fails */
2526         if (eStatus != eFrameworkunifiedStatusOK) {
2527             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2528                           "FrameworkunifiedGetMsgDataOfSize ERROR [eStatus:%d]", eStatus);
2529             ulSize = 0;
2530         } else {
2531             if (eUSB == stMedia.dev_type) {
2532                 if (TRUE == stMedia.bIsDeviceAvailable) {
2533                     /* Mount detection */
2534                     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, 
2535                         "USB mounted sts=[%d] path=[%s] fusedav=[%d]",
2536                         stMedia.bIsDeviceAvailable, stMedia.deviceMountpath, stMedia.bIsFuseDav);
2537
2538                     /* NOTE: bIsFuseDav -> From the _CWORD80_'s point of view,                          */
2539                     /*       TRUE(With a USB flash drive inserted into the _CWORD84_,Be synchronized on the FuseDav)*/
2540                     /*       FALSE(USB memory is inserted into the _CWORD80_.)                        */
2541
2542                     if (stMedia.bIsFuseDav == FALSE) {
2543                         /* Inserted into your USB port */
2544                         FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "SensLog Initialize start.");
2545                         /*  Get Debug/Release setting */
2546                         eStatus = NsLogGetFrameworkunifiedLogFlag(POSITIONINGLOG_FLAG_NAVI, &mode);
2547                         /* When acquisition fails */
2548                         if (eStatus != eFrameworkunifiedStatusOK) {
2549                             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2550                             "NsLogGetFrameworkunifiedLogFlag ERROR [eStatus:%d]", eStatus);
2551                         } else {
2552                             if (mode == FRAMEWORKUNIFIEDLOG_FLAG_MODE_DEBUG) {
2553                                 /* Sensor Log Initial Processing(Normal)*/
2554                                 SensLogInitialize(reinterpret_cast<uint8_t *>(stMedia.deviceMountpath));
2555                             }
2556                         }
2557                     } else {
2558                         /* TODO: Mounts (FuseDav synchronized) that are not inserted into your device's USB port are not supported. */
2559                         FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "Don't output SensLog.");
2560                     }
2561                 } else {
2562                     /* Unmount detection */
2563                     if (stMedia.bIsFuseDav == FALSE) {
2564                         /* When it is unmounted to its own USB */
2565                         FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, 
2566                             "USB umounted sts=[%d] fusedav=[%d]",
2567                             stMedia.bIsDeviceAvailable, stMedia.bIsFuseDav);
2568
2569                         /* Sensor log stop processing */
2570                         SensLogTerminate();
2571                     }
2572                 }
2573             }
2574         }
2575     }
2576
2577     FRAMEWORKUNIFIEDLOG(ZONE_INIT, __FUNCTION__, "-");
2578     return eStatus;
2579 }
2580
2581 /**
2582  * @brief Debug dump log output function
2583  *
2584  * @param[in]    *p_buf Pointer to the output string
2585  */
2586 static void PosOutputDebugDumpLog(uint8_t* p_buf) {  // LCOV_EXCL_START 7: uesd only in FrameworkunifiedOnDebugDump
2587     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2588     SSDEBUGDUMP("%s\n", p_buf);
2589     MilliSecSleep(1);
2590     return;
2591 }
2592 // LCOV_EXCL_STOP
2593