2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 /***************************************************************************
18 @file VehicleUtility.cpp
19 @detail Common processing function of Vehicle
20 *****************************************************************************/
22 #include "VehicleUtility.h"
23 #include <vehicle_service/positioning_base_library.h>
26 #include "positioning_common.h"
29 /*---------------------------------------------------------------------------------*
31 *---------------------------------------------------------------------------------*/
32 /** Timer management table */
33 static VEHICLEUTILITY_TIM_MNG g_st_tim_mng;
35 /** Timer setting information table */
36 static const VEHICLEUTILITY_TIM_INFO g_tim_info[TIM_NUM] = {
38 {TIMVAL_GPS_STARTUP, PNO_NAVI_GPS_MAIN}, /* Start confirmation monitoring timer */
39 {TIMVAL_GPS_RCVCYCLDAT, PNO_NAVI_GPS_MAIN}, /* Periodic reception data monitoring timer */
40 {TIMVAL_GPS_RCVACK, PNO_NAVI_GPS_MAIN}, /* ACK reception monitoring timer */
41 {TIMVAL_GPS_NAVIFST, PNO_NAVI_GPS_MAIN}, /* Initial Navigation Monitoring Timer */
42 {TIMVAL_GPS_NAVICYCLE, PNO_NAVI_GPS_MAIN}, /* Navi monitoring timer */
43 {TIMVAL_GPS_NAVIDISRPT, PNO_NAVI_GPS_MAIN}, /* Navigation Monitoring Disruption Log Output Timer */
44 {TIMVAL_GPS_DIAGCLKGUARD, PNO_NAVI_GPS_MAIN}, /* Diag provision time guard monitoring timer */
45 {TIMVAL_GPS_NMEADATAGUARD, PNO_NAVI_GPS_MAIN}, /* NMEA data-providing guard monitoring timer */
46 {TIMVAL_GPS_RECOVERY, PNO_NAVI_GPS_MAIN}, /* GPS recovery timer */
47 {TIMVAL_GPS_RECEIVERERR, PNO_NAVI_GPS_MAIN}, /* GPS receiver anomaly detection timer */
48 /* Sensor Related Extensions */
49 {TIMVAL_SNS_RCVFSTDAT, PNO_VEHICLE_SENSOR}, /* Initial cyclic sensor data reception monitoring timer */
50 {TIMVAL_SNS_RCVCYCLDAT, PNO_VEHICLE_SENSOR}, /* Cyclic sensor data reception monitoring timer */
51 {TIMVAL_SNS_RCVDISRPT, PNO_VEHICLE_SENSOR}, /* Cyclic sensor data interruption log output timer */
54 /*---------------------------------------------------------------------------------*
56 *---------------------------------------------------------------------------------*/
57 static uint16_t VehicleUtilityTimeMakSeqNo(VEHICLEUTILITY_TIM_KIND tim_kind);
59 /***************************************************************************
60 @brief send message function for Vehicle domain.
61 @outline send message function with put error diag function if error occurred.
62 @type Completion return type
63 @param[in] PNO pno : PNO
64 @param[in] u_int16 size : size of message data
65 @param[in] void* msgbuf : message data
66 @param[in] u_int16 mode : mode
69 @retval RET_NORMAL : Normal end
70 @retval RET_ERROR : Abnormal end
71 *****************************************************************************/
72 RET_API VehicleUtilitySndMsg(PNO pno, u_int16 size, void *msgbuf, u_int16 mode) {
74 if (msgbuf != NULL) { // LCOV_EXCL_BR_LINE 6: msgbuf cannot be null
75 ret_api = _pb_SndMsg(pno, size, msgbuf, mode);
76 /* RET_ERROR: Execute _pb_Exit() after dialog registration */
77 if (ret_api == RET_ERROR) {
78 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_SndMsg ERROR [ret_api:%d]", ret_api);
81 ret_api = RET_ERRPARAM;
87 /***************************************************************************
88 @brief send message function for Vehicle domain.
89 @outline receive message function with put error diag function if error occurred.
90 @type Completion return type
91 @param[in] PNO pno : PNO
92 @param[in] u_int16 size : size of message data
93 @param[in] void* msgbuf : message data
94 @param[in] u_int16 mode : mode
97 @retval RET_NORMAL : Normal end
98 @retval RET_ERROR : Abnormal end
99 *****************************************************************************/
100 RET_API VehicleUtilityRcvMsg(PNO pno, u_int16 size, void **msgbuf, u_int16 mode)
104 if (msgbuf != NULL) { // LCOV_EXCL_BR_LINE 6: msgbuf cannot be null
105 ret_api = _pb_RcvMsg(pno, size, msgbuf, mode);
106 /* For RET_ERROR Sys_Exit() after dialog registration */
107 if (ret_api == RET_ERROR) {
108 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_RcvMsg ERROR [ret_api:%d]", ret_api);
111 ret_api = RET_ERRPARAM;
117 /***************************************************************************
118 @brief Diagcode submit for Vehicle domain.
119 @outline submit the DiagCode for Vehicle domain.
120 @type Completion return type
121 @param[in] u_int32 err_id : Diag Code
122 @param[in] u_int16 positioning_code : Positioning Code
123 @param[in] void* msgbuf : message data
125 *****************************************************************************/
126 void VehicleUtilityDiagCodePut(u_int32 err_id, u_int16 positioning_code) { // LCOV_EXCL_START 8 : dead code
127 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
133 * Timer function initialization processing
136 void VehicleUtilityInitTimer(void) {
137 VEHICLEUTILITY_TIM_MNG *pst_tim_mng;
140 pst_tim_mng = &g_st_tim_mng;
142 /* Initialize timer management table */
143 memset(pst_tim_mng, 0x00, sizeof(VEHICLEUTILITY_TIM_MNG));
145 for (i = 0; i < TIM_NUM; i++) {
146 pst_tim_mng->sts[i].flag = TIMER_OFF;
147 pst_tim_mng->sts[i].cnt = 0;
153 * Timer start processing<br>
155 * Starts a timer of the specified type<br>
156 * 1.Increment total number of timer start<br>
157 * 2.Timer Sequence Number Creation<br>
158 * 3.Get timeout value<br>
161 * @param[in] Tim_kind Timer type
163 * @return TRUE Normal completion<br>
166 BOOL VehicleUtilitySetTimer(VEHICLEUTILITY_TIM_KIND tim_kind) {
167 VEHICLEUTILITY_TIM_MNG *pst_tim_mng;
168 const uint32_t *p_time_val;
170 RET_API api_ret; /* Timer API return value */
174 pst_tim_mng = &g_st_tim_mng;
176 p_time_val = &(g_tim_info[tim_kind].timer_val); /* Timer set value */
177 p_pno = &(g_tim_info[tim_kind].pno); /* Notify party PNO */
179 if (pst_tim_mng->sts[tim_kind].flag == TIMER_ON) {
180 /*-----------------------------------------------------------------------*/
181 /* When the same timer has already started */
182 /* Terminate without starting the timer because the timer is set multiple times. */
183 /*-----------------------------------------------------------------------*/
186 /*-----------------------------------------------------------------------*/
187 /* Count up the timer counter of the corresponding timer by 1. */
188 /*-----------------------------------------------------------------------*/
189 if (pst_tim_mng->sts[tim_kind].cnt >= TIM_CNTMAX) {
190 /*-----------------------------------------------------------------------*/
191 /* When the count reaches the maximum number,Count again from 1 */
192 /*-----------------------------------------------------------------------*/
193 pst_tim_mng->sts[tim_kind].cnt = TIM_CNTMIN;
195 /*-----------------------------------------------------------------------*/
196 /* If the count has not reached the maximum,Count up */
197 /*-----------------------------------------------------------------------*/
198 pst_tim_mng->sts[tim_kind].cnt++;
201 /*-----------------------------------------------------------------------*/
202 /* Creating Timer Sequence Numbers */
203 /*-----------------------------------------------------------------------*/
204 seq_no = VehicleUtilityTimeMakSeqNo(tim_kind);
206 /*-----------------------------------------------------------------------*/
207 /* Start the timer */
208 /*-----------------------------------------------------------------------*/
209 api_ret = _pb_ReqTimerStart(*p_pno, seq_no, TIMER_TYPE_USN, (u_int32)*p_time_val);
210 if (api_ret != RET_NORMAL) {
212 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
213 "_pb_ReqTimerStart ERROR!! [api_ret=%d]", api_ret);
215 /*-----------------------------------------------------------------------*/
216 /* Successful timer start */
217 /* Set the start/stop flag of the corresponding timer to start (MCSUB_ON) */
218 /*-----------------------------------------------------------------------*/
219 pst_tim_mng->sts[tim_kind].flag = TIMER_ON;
228 * Timer stop processing<br>
230 * Stops a timer of the specified type<br>
231 * 1.Get the sequence number of the specified type<br>
234 * @param[in] Tim_kind Timer type
235 * @param[in] pno Process number
237 * @return TRUE Normal completion<br>
240 BOOL VehicleUtilityStopTimer(VEHICLEUTILITY_TIM_KIND tim_kind) {
241 VEHICLEUTILITY_TIM_MNG *pst_tim_mng;
247 pst_tim_mng = &g_st_tim_mng;
249 p_pno = &(g_tim_info[tim_kind].pno); /* Notify party PNO */
251 /* Check timer start/stop flag */
252 if (pst_tim_mng->sts[tim_kind].flag == TIMER_OFF) {
253 /* If it is already stopped, do nothing. */
256 /*-----------------------------------------------------------------------*/
257 /* Creating Timer Sequence Numbers */
258 /*-----------------------------------------------------------------------*/
259 seq_no = VehicleUtilityTimeMakSeqNo(tim_kind);
261 /*-----------------------------------------------------------------------*/
262 /* Set the corresponding timer to stop */
263 /*-----------------------------------------------------------------------*/
264 api_ret = _pb_TimerStop(*p_pno, seq_no, TIMER_TYPE_USN);
265 if (api_ret != RET_NORMAL) {
267 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_TimerStop ERROR!! [api_ret=%d]", api_ret);
270 /*-----------------------------------------------------------------------*/
271 /* Set the start/stop flag of the corresponding timer to stop (MCSUB_OFF) */
272 /* Set the ID of the corresponding timer to invalid (DEV_TED_INVALID) */
273 /*-----------------------------------------------------------------------*/
274 pst_tim_mng->sts[tim_kind].flag = TIMER_OFF;
281 * Timer Sequence Number Determination<br>
283 * Determine whether the timer sequence number corresponds to the one being managed
285 * @param[in] seqno Timer Sequence Number
287 * @return TRUE Normal completion(No problem)<br>
288 * FALSE abend(Unusual number)<br>
290 BOOL VehicleUtilityTimeJdgKnd(uint16_t seqno) { // LCOV_EXCL_START 8 : dead code
291 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
292 VEHICLEUTILITY_TIM_MNG *pst_tim_mng;
297 pst_tim_mng = &g_st_tim_mng;
299 timekind = (u_int8)((seqno & 0xff00) >> 8);
300 count = (u_int8)(seqno & 0x00ff);
302 /* Timer type is unexpected */
303 if (timekind >= TIM_NUM) {
306 if ((pst_tim_mng->sts[timekind].cnt == count) &&
307 (pst_tim_mng->sts[timekind].flag == TIMER_ON)) {
308 /* The counter matches and the counter start/stop flag is "Start". */
311 /* Not applicable due to differences */
322 * Timer Sequence Number Creation<br>
324 * Creating a Sequence Number for a Timer<br>
325 * 1. The upper 1 byte is the timer type.,So that the lower 1 times is the total number of timer starts
326 * Create a sequence number.
328 * @param[in] Tim_kind Timer type
330 * @return Timer Sequence Number
332 static uint16_t VehicleUtilityTimeMakSeqNo(VEHICLEUTILITY_TIM_KIND tim_kind) {
333 VEHICLEUTILITY_TIM_MNG *pst_tim_mng;
334 u_int16 seq_no; /* Timer Sequence Number */
336 pst_tim_mng = &g_st_tim_mng;
338 /*------------------------------------------------------------------------*/
339 /* Definition of Sequence Number */
340 /* |------------------- Sequence number(2Byte) -----------------------| */
342 /* +-------------------------------+-----------------------------------+ */
343 /* | Timer type(1Byte) | Counter(1Byte)(0x01 ? 0xFF) | */
344 /* +-------------------------------+-----------------------------------+ */
345 /* For the timer type,0x00 ? (Number of timers-1) */
346 /* For counters,0x01 ? 0xFF(Do not use 0x00.) */
347 /* (Counters are counted up each time a timer is started. */
348 /* Count up when counter is 0xFF, */
349 /* Be counted up from the 0x01) */
350 /*------------------------------------------------------------------------*/
351 seq_no = static_cast<u_int16>(((u_int16)tim_kind << 8) | (pst_tim_mng->sts[tim_kind].cnt));
358 * External pin status request
360 void LineSensDrvExtTermStsReq(void) {
361 T_APIMSG_MSGBUF_HEADER st_snd_msg;
364 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+");
366 memset(&st_snd_msg, 0x00, sizeof(st_snd_msg));
368 st_snd_msg.hdr.sndpno = PNO_LINE_SENS_DRV;
369 st_snd_msg.hdr.respno = 0x0000;
370 st_snd_msg.hdr.cid = CID_EXTTERM_REQ;
371 st_snd_msg.hdr.msgbodysize = 0x00; /* No data */
372 st_snd_msg.hdr.rid = 0x00;
375 lret = _pb_SndMsg(PNO_LINE_SENS_DRV, sizeof(T_APIMSG_MSGBUF_HEADER), &st_snd_msg, 0);
376 if (lret != RET_NORMAL) {
377 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_SndMsg ERROR!! lret=%d", lret);
381 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "-");
389 * Backup data read request send processing<BR>
391 * @return RET_NORMAL Normal completion
392 * @return RET_ERROR ABENDs
394 RET_API DEVGpsSndBackupDataLoadReq(void) {
396 T_APIMSG_MSGBUF_HEADER st_snd_msg;
398 /** Create GPS Data Notification Message */
399 (void)memset(&st_snd_msg, 0x00, sizeof(st_snd_msg)); /* QAC 3200 */
400 /** Message header */
401 st_snd_msg.hdr.sndpno = 0x0000;
402 st_snd_msg.hdr.respno = 0x0000;
403 st_snd_msg.hdr.cid = CID_GPS_BACKUPDATA_LOAD;
404 st_snd_msg.hdr.msgbodysize = 0x00;
405 st_snd_msg.hdr.rid = 0x00;
408 lret = _pb_SndMsg(PNO_NAVI_GPS_MAIN, sizeof(st_snd_msg), &st_snd_msg, 0);
409 if (lret != RET_NORMAL) {
410 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_SndMsg ERROR!! [lret=%d]", lret);
419 * Acquisition of GPS-format error count information (dump)
421 * @param[out] p_buf Dump information
423 void DEVGpsGetDebugGpsFormatFailCnt(void* p_buf) { // LCOV_EXCL_START 8 : dead code
424 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
426 snprintf(reinterpret_cast<char *>(p_buf), \
427 512, "GPS Format Fail Count is not supported.\n"); // NOLINT(readability/nolint)
435 * Initial sensor data reception flag acquisition
437 u_int8 LineSensDrvGetSysRecvFlag(void) { // LCOV_EXCL_START 7: uesd only in FrameworkunifiedOnDebugDump
438 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
445 * Get GPS Rollover Standard Week Number
447 * @return GPS rollover base week number
449 uint16_t DEVGpsGetWknRollover(void) { // LCOV_EXCL_START 7: uesd only in FrameworkunifiedOnDebugDump
450 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert