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 * @file LineSensDrv_Api.cpp
20 /*---------------------------------------------------------------------------*/
23 #include "LineSensDrv_Api.h"
24 #include "positioning_def.h"
26 /*---------------------------------------------------------------------------*/
29 #define LSDRV_GPS_DATA_TOP_TH 5 // Threshold for determining the beginning of GPS data
30 #define LSDRV_SENS_DATA_RCV_WAIT_TIME 400 // Sensor data wait time of GPS reception flag ON(Total)
31 #define LSDRV_SENS_DATA_RCV_WAIT_TERM 50 // Sensor data wait time of GPS reception flag ON(1 time)
33 #define LSDRV_EST_GPS_CNT_ARRAY_NUM 3U // Number of arrays for holding estimated GPS counter
34 #define LSDRV_EST_GPS_CNT_ENABLE_TH 5U // Estimated GPS counter enable/disable determination threshold
35 #define LSDRV_EST_GPS_CNT_ADD_VALUE 10U // Estimated GPS counter update addition value
37 // GPS data reception cycle:1sec sensor counters: 100ms
40 #define LINE_SENS_DRV_API_DEBUG_SWITCH 0 // 0:OFF 1:ON
42 /*---------------------------------------------------------------------------*/
45 static HANDLE g_gps_irq_mutex = NULL; // GPS received flag Mutex handles
46 static BOOL g_rcv_pps_int = FALSE; // PPS interrupt reception flag (GPS->_CWORD102_)
47 static BOOL g_rcv_gps_irq = FALSE; // GPS reception flag (GPS->_CWORD56_)
48 static u_int8 g_rcv_gps_sens_cnt_tmp = 0; // Sensor counter when GPS reception flag is ON(for retention)
49 static u_int8 g_rcv_gps_sens_cnt = 0; // Sensor counter when GPS reception flag is ON
50 static u_int8 g_gps_sens_cnt_top = 0; // Sensor counter when first GPS data is received
51 static u_int8 g_est_gps_cnt[LSDRV_EST_GPS_CNT_ARRAY_NUM]; // Array for storing estimated GPS counter values
52 static BOOL g_est_gps_cnt_available = FALSE; // Estimated GPS counter value enable/disable judgment
54 typedef struct VehicleSensDataMaster {
55 DID ul_did; // Data ID
56 u_int16 us_size; // Size of the data
57 u_int8 uc_rcv_flag; // Receive flag
58 u_int8 uc_sns_cnt; // Sensor counter
59 u_int8 uc_data[132]; // Vehicle sensor data
60 } VEHICLESENS_DATA_MASTER;
63 /*******************************************************************************
64 * MODULE : DeliveryLineSensorDataPositioning
65 * ABSTRACT : LineSensor vehicle signaling notification messages sending process
66 * FUNCTION : Send LineSensor vehicle signalling notification messages
67 * ARGUMENT : *pstSendBuf:Transmitted data
68 * : uc_data_num :Number of sent data
71 ******************************************************************************/
72 void DeliveryLineSensorDataPositioning(LSDRV_MSG_LSDATA_G* pst_send_buf, u_int8 uc_data_num) {
73 if (pst_send_buf != NULL) {
74 /* Initializing sent messages */
75 memset(reinterpret_cast<void *>(&(pst_send_buf->st_head)), 0, sizeof(T_APIMSG_MSGBUF_HEADER));
77 /* Message Header Settings */
78 pst_send_buf->st_head.hdr.sndpno = PNO_LINE_SENS_DRV; /* Source process number */
79 pst_send_buf->st_head.hdr.cid = CID_LINESENS_VEHICLE_DATA_G; /* Command ID */
80 pst_send_buf->st_head.hdr.msgbodysize = sizeof(LSDRV_MSG_LSDATA_DAT_G); /* Message data body length */
82 /* Message data is already set */
83 pst_send_buf->st_para.uc_data_num = uc_data_num;
86 (void)_pb_ZcSndMsg(PNO_VEHICLE_SENSOR, sizeof( LSDRV_MSG_LSDATA_G ), 0);
90 /*******************************************************************************
91 * MODULE : LineSensDrvApi_Initialize
92 * ABSTRACT : LineSensDrvApi initialization process
93 * FUNCTION : LineSensDrvApi initialization process
97 ******************************************************************************/
98 BOOL LineSensDrvApiInitialize(void) {
101 g_gps_irq_mutex = _pb_CreateMutex(NULL, FALSE, MUTEX_GPS_IRQ_FLG);
103 if (g_gps_irq_mutex == 0) {
106 g_rcv_gps_irq = FALSE;
107 g_rcv_gps_sens_cnt_tmp = 0;
108 LineSensDrvApiInitEstGpsCnt();
115 /*******************************************************************************
116 * MODULE : LineSensDrvApi_InitEstGpsCnt
117 * ABSTRACT : Estimated GPS counter related parameter initialization processing
118 * FUNCTION : Estimated GPS counter related parameter initialization processing
122 ******************************************************************************/
123 void LineSensDrvApiInitEstGpsCnt(void) {
124 /* Initializing process */
125 g_rcv_pps_int = FALSE;
126 g_rcv_gps_sens_cnt = 0;
127 g_gps_sens_cnt_top = 0;
129 (void)memset(reinterpret_cast<void *>(&g_est_gps_cnt[0]), 0, sizeof(g_est_gps_cnt));
130 g_est_gps_cnt_available = FALSE;
135 /*---------------------------------------------------------------------------*/