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 name :VehicleSens_Did_SpeedKmph_l.cpp
19 * System name :_CWORD107_
20 * Subsystem name :Vehicle sensor process
21 * Program name :Vehicle sensor data master(POSHAL_DID_SPEED_KMPH)
22 * Module configuration :VehicleSensInitSpeedKmphl() Vehicle sensor SPEED_KMPH initialization function
23 * :VehicleSensSetSpeedKmphl() Vehicle sensor SPEED_KMPH SET function
24 * :VehicleSensGetSpeedKmphl() Vehicle Sensor SPEED_KMPH GET Function
25 ******************************************************************************/
27 #include <vehicle_service/positioning_base_library.h>
28 #include "VehicleSens_DataMaster.h"
30 /*************************************************/
32 /*************************************************/
33 static VEHICLESENS_DATA_MASTER gstSpeedKmph_l; // NOLINT(readability/nolint)
35 /*******************************************************************************
36 * MODULE : VehicleSensInitSpeedKmphl
37 * ABSTRACT : Vehicle sensor SPEED_KMPH initialization function
38 * FUNCTION : SPEED_KMPH data master initialization processing
42 ******************************************************************************/
43 void VehicleSensInitSpeedKmphl(void) {
46 memset(&gstSpeedKmph_l, 0x00, sizeof(VEHICLESENS_DATA_MASTER));
47 gstSpeedKmph_l.ul_did = POSHAL_DID_SPEED_KMPH;
48 gstSpeedKmph_l.us_size = VEHICLE_DSIZE_SPEED_KMPH;
50 pus = reinterpret_cast<u_int16 *>(gstSpeedKmph_l.uc_data);
51 *pus = VEHICLE_DINIT_SPEED_KMPH;
54 /*******************************************************************************
55 * MODULE : VehicleSensSetSpeedKmphl
56 * ABSTRACT : Vehicle sensor SPEED_KMPH SET function
57 * FUNCTION : Update the SPEED_KMPH data master
58 * ARGUMENT : *pst_data : Pointer to the message data received by the direct line
60 * RETURN : VEHICLESENS_EQ : No data change
61 * VEHICLESENS_NEQ : Data change
62 ******************************************************************************/
63 u_int8 VehicleSensSetSpeedKmphl(const LSDRV_LSDATA *pst_data) { // LCOV_EXCL_START 8: dead code.
64 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
66 VEHICLESENS_DATA_MASTER *pst_master;
68 pst_master = &gstSpeedKmph_l;
70 /* Compare data master and received data */
71 uc_ret = VehicleSensmemcmp(pst_master->uc_data,
72 pst_data->uc_data, pst_data->uc_size); /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
74 /* Received data is set in the data master. */
75 pst_master->ul_did = pst_data->ul_did;
76 pst_master->us_size = pst_data->uc_size; /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
77 pst_master->uc_rcvflag = VEHICLE_RCVFLAG_ON;
78 memset(pst_master->uc_data, 0x00, sizeof(pst_master->uc_data));
79 memcpy(pst_master->uc_data, pst_data->uc_data, pst_data->uc_size); /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
85 /*******************************************************************************
86 * MODULE : VehicleSensSetSpeedKmphlG
87 * ABSTRACT : Vehicle sensor SPEED_KMPH SET function
88 * FUNCTION : Update the SPEED_KMPH data master
89 * ARGUMENT : *pst_data : Pointer to the message data received by the direct line
91 * RETURN : VEHICLESENS_EQ : No data change
92 * VEHICLESENS_NEQ : Data change
93 ******************************************************************************/
94 u_int8 VehicleSensSetSpeedKmphlG(const LSDRV_LSDATA_G *pst_data) {
96 VEHICLESENS_DATA_MASTER *pst_master;
98 static u_int16 pre_speed[2] = {0, 0};
99 u_int16 cur_speed = 0;
100 memcpy(&cur_speed, &pst_data->uc_data[0], sizeof(u_int16));
103 BOOL eq_speed = TRUE;
105 pst_master = &gstSpeedKmph_l;
107 /* Transition of 0->1km/h and 1->0km/h requires 3 consecutive matches. Compliance with driving regulations */
108 under2 = ((pre_speed[1] < 2) && (pre_speed[0] < 2) && (cur_speed < 2));
109 eq_speed = ((pre_speed[1] == pre_speed[0]) && (pre_speed[0] == cur_speed));
111 if ((under2 == TRUE) && (eq_speed != TRUE) && (pst_master->uc_rcvflag == VEHICLE_RCVFLAG_ON)) {
112 uc_ret = VEHICLESENS_EQ; /* Return without data change */
114 /* Received data is set in the data master. */
115 pst_master->ul_did = pst_data->ul_did;
116 pst_master->us_size = pst_data->uc_size; /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
117 pst_master->uc_rcvflag = VEHICLE_RCVFLAG_ON;
120 /* Compare data master and received data */
121 uc_ret = VehicleSensmemcmp(pst_master->uc_data,
122 pst_data->uc_data, pst_data->uc_size); /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
124 /* Received data is set in the data master. */
125 pst_master->ul_did = pst_data->ul_did;
126 pst_master->us_size = pst_data->uc_size; /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
127 pst_master->uc_rcvflag = VEHICLE_RCVFLAG_ON;
128 memcpy(pst_master->uc_data, pst_data->uc_data, pst_data->uc_size); /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
131 /* For the next comparison,Update Speed */
132 pre_speed[1] = pre_speed[0];
133 pre_speed[0] = cur_speed;
138 /*******************************************************************************
139 * MODULE : VehicleSensGetSpeedKmphl
140 * ABSTRACT : Vehicle Sensor SPEED_KMPH GET Function
141 * FUNCTION : Provide the SPEED_KMPH data master
142 * ARGUMENT : *pst_data : Pointer to the data master acquisition destination
145 ******************************************************************************/
146 void VehicleSensGetSpeedKmphl(VEHICLESENS_DATA_MASTER *pst_data) {
147 const VEHICLESENS_DATA_MASTER *pst_master;
149 pst_master = &gstSpeedKmph_l;
151 /* Store the data master in the specified destination. */
152 pst_data->ul_did = pst_master->ul_did;
153 pst_data->us_size = pst_master->us_size;
154 pst_data->uc_rcvflag = pst_master->uc_rcvflag;
155 memcpy(pst_data->uc_data, pst_master->uc_data, pst_master->us_size); /* Ignore->MISRA-C++:2008 Rule 5-0-5 */