common_library: gettid is multiple declaration in cl_error
[staging/basesystem.git] / video_in_hal / vehicleservice / positioning / server / src / Sensor / VehicleSens_Did_SpeedPulseExt_l.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 name    :VehicleSens_Did_SpeedPulseExt_l.cpp
19  *  System name    :_CWORD107_
20  *  Subsystem name  :Vehicle sensor process
21  *  Program name  :Vehicle sensor data master(POSHAL_DID_SPEED_PULSE)
22  *  Module configuration  :VehicleSensInitSpeedPulseExtl()  Vehicle sensor SPEED_PULSE initialization function
23  *                  :VehicleSensSetSpeedPulseExtlG()  Vehicle Sensor SPEED_PULSE SET Function
24  *                  :VehicleSensGetSpeedPulseExtl()    Vehicle Sensor SPEED_PULSE GET Function
25  ******************************************************************************/
26
27 #include <vehicle_service/positioning_base_library.h>
28 #include "VehicleSens_DataMaster.h"
29
30 /* Ignore->MISRA-C++:2008 Rule 2-7-2 */
31 #if CONFIG_SENSOR_EXT_VALID        /* Initial Sensor Support */
32 /*************************************************/
33 /*           Global variable                      */
34 /*************************************************/
35 static  VEHICLESENS_DATA_MASTER_EXT  gstSpeedPulseExt_l;    // NOLINT(readability/nolint)
36
37 /*******************************************************************************
38 * MODULE    : VehicleSensInitSpeedPulseExtl
39 * ABSTRACT  : Vehicle sensor SPEED_PULSE initialization function
40 * FUNCTION  : SPEED_PULSE data master initialization processing
41 * ARGUMENT  : void
42 * NOTE      :
43 * RETURN    : void
44 ******************************************************************************/
45 void VehicleSensInitSpeedPulseExtl(void) {
46     u_int16  *pus;
47
48     memset(&gstSpeedPulseExt_l, 0x00, sizeof(VEHICLESENS_DATA_MASTER_EXT));
49     gstSpeedPulseExt_l.ul_did  = POSHAL_DID_SPEED_PULSE;
50     gstSpeedPulseExt_l.us_size  = VEHICLE_DSIZE_SPEED_PULSE_EXT_INIT;
51
52     pus    = reinterpret_cast<u_int16 *>(gstSpeedPulseExt_l.uc_data);
53     memset(reinterpret_cast<void*>(pus), VEHICLE_DINIT_SPEED_PULSE, VEHICLE_DSIZE_SPEED_PULSE_EXT);
54 }
55
56 /*******************************************************************************
57 * MODULE    : VehicleSensSetSpeedPulseExtlG
58 * ABSTRACT  : Vehicle Sensor SPEED_PULSE SET Function
59 * FUNCTION  : Update the SPEED_PULSE data master
60 * ARGUMENT  : *pst_data : Pointer to the message data received by the direct line
61 * NOTE      :
62 * RETURN    : VEHICLESENS_EQ  : No data change
63 *             VEHICLESENS_NEQ  : Data change
64 ******************************************************************************/
65 void VehicleSensSetSpeedPulseExtlG(const LSDRV_LSDATA_G *pst_data) {
66     VEHICLESENS_DATA_MASTER_EXT *pst_master;
67     u_int16 us_start = 0;
68     u_int16 us_size = 0;
69     u_int16 us_cnt = 0;
70
71     pst_master = &gstSpeedPulseExt_l;
72     us_size = static_cast<u_int16>(sizeof(u_int16) * 10);  /* Size of one data item: 2byte * 10 data items */
73
74     /* Retrieve the location where the received one is stored */
75     us_start = gstPkgTempExt.start_point[SpeedPulse];
76
77     /* Stored in data master(Order of reception)*/
78     if (us_start >= VEHICLE_DKEEP_MAX) {
79         /* Store the latest one at position 0 */
80         us_start = VEHICLE_DATA_POS_00;
81         /* If you are discarding old data,,Set a flag */
82         gstPkgTempExt.data_break = VEHICLE_SNS_BREAK;
83     }
84     pst_master->ul_did    = pst_data->ul_did;
85     pst_master->uc_rcvflag  = VEHICLE_RCVFLAG_ON;
86     for (us_cnt = 0; us_cnt < us_size; us_cnt++) {
87         pst_master->uc_data[us_start * us_size + us_cnt] = (u_int8)(pst_data->uc_data[us_cnt]);
88     }
89
90     /* Update next storage start position and latest data storage position */
91     us_start++;
92     gstPkgTempExt.start_point[SpeedPulse] = us_start;
93     /* Update data master size */
94     if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
95         /* Make the size of all extended data masters */
96         pst_master->us_size = VEHICLE_DSIZE_SPEED_PULSE_EXT;
97     } else {
98         /* Add the size of one received data item */
99         pst_master->us_size = static_cast<u_int16>(pst_master->us_size + us_size);
100     }
101 }
102
103 /*******************************************************************************
104 * MODULE    : VehicleSensGetSpeedPulseExtl
105 * ABSTRACT  : Vehicle Sensor SPEED_PULSE GET Function
106 * FUNCTION  : Provide the SPEED_PULSE data master
107 * ARGUMENT  : *pst_data : Pointer to the data master acquisition destination
108 * NOTE      :
109 * RETURN    : void
110 ******************************************************************************/
111 void VehicleSensGetSpeedPulseExtl(VEHICLESENS_DATA_MASTER_EXT *pst_data) {
112   const VEHICLESENS_DATA_MASTER_EXT *pst_master;
113   uint16_t us_size = 0;
114   uint16_t us_data_cnt = 0; // Number of data contained
115   uint16_t us_loop_cnt = 0; // 64 over index
116
117   /* Store the data master in the specified destination. */
118   pst_master      = &gstSpeedPulseExt_l;
119   pst_data->ul_did    = pst_master->ul_did;
120   pst_data->us_size    = pst_master->us_size;
121   pst_data->uc_rcvflag  = pst_master->uc_rcvflag;
122
123   us_size = static_cast<u_int16>(sizeof(u_int16) * 10); /* Size of one data item: 2byte * 10 data items */
124
125   /* Checking whether the number of stored entries is looped */
126   if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
127     us_data_cnt = VEHICLE_DKEEP_MAX;
128   } else {
129     us_data_cnt = gstPkgTempExt.start_point[SpeedPulse];
130   }
131
132   /* Acquire data from the newest data master */
133   for (uint16_t us_cnt = 0; us_cnt < us_data_cnt; us_cnt++) {
134     if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
135       /* Get information before loop */
136       if (gstPkgTempExt.start_point[SpeedPulse] + us_cnt < VEHICLE_DKEEP_MAX) {
137         memcpy(&pst_data->uc_data[us_cnt * us_size],
138                &pst_master->uc_data[(gstPkgTempExt.start_point[SpeedPulse] + us_cnt) * us_size], us_size);
139       } else {
140         memcpy(&pst_data->uc_data[us_cnt * us_size],
141                &pst_master->uc_data[us_loop_cnt * us_size], us_size);
142         us_loop_cnt++;
143       }
144     } else {
145       memcpy(&pst_data->uc_data[us_cnt * us_size],
146              &pst_master->uc_data[us_cnt * us_size], us_size);
147     }
148   }
149 }
150 #endif