common_library: gettid is multiple declaration in cl_error
[staging/basesystem.git] / video_in_hal / vehicleservice / positioning / server / src / Sensor / VehicleSens_Did_RevExt_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
19  *  VehicleSens_Did_RevExt_l.cpp
20  * @brief
21  *  Vehicle sensor data master(POSHAL_DID_REV)
22  */
23
24 #include <vehicle_service/positioning_base_library.h>
25 #include "VehicleSens_DataMaster.h"
26
27 /*************************************************/
28 /*           Global variable                      */
29 /*************************************************/
30 static  VEHICLESENS_DATA_MASTER_EXT  g_st_revext_l;    // NOLINT(readability/nolint)
31
32 /**
33  * @brief
34  *   Vehicle Sensor REV Initialization Functions
35  *
36  *   REV data master initialization processing
37  *
38  * @param[in]  none
39  */
40 void VehicleSensInitRevExtl(void) {
41     u_int16  *pus;
42
43     memset(&g_st_revext_l, 0x00, sizeof(VEHICLESENS_DATA_MASTER_EXT));
44     g_st_revext_l.ul_did    = POSHAL_DID_REV;
45     g_st_revext_l.us_size    = VEHICLE_DSIZE_REV_EXT_INIT;
46     g_st_revext_l.uc_rcvflag  = VEHICLE_RCVFLAG_OFF;
47     pus    = reinterpret_cast<u_int16 *>(g_st_revext_l.uc_data);
48     memset(reinterpret_cast<void*>(pus), VEHICLE_DINIT_SNS_COUNTER, VEHICLE_DSIZE_REV_EXT);
49 }
50
51 /**
52  * @brief
53  *   Vehicle Sensor REV SET Functions
54  *
55  *   Update the REV data master
56  *
57  * @param[in]  *pst_data : Pointer to the message data received by the direct line
58  */
59 void VehicleSensSetRevExtlG(const LSDRV_LSDATA_G *pst_data) {
60     VEHICLESENS_DATA_MASTER_EXT *pst_master;
61     u_int16 us_start = 0;
62
63     pst_master = &g_st_revext_l;
64
65     /* Retrieve the location where the received one is stored */
66     us_start = gstPkgTempExt.start_point[Rev];
67
68     /* Stored in data master(Order of reception)*/
69     if (us_start >= VEHICLE_DKEEP_MAX) {
70         /* Store the latest one at position 0 */
71         us_start = VEHICLE_DATA_POS_00;
72         /* If you are discarding old data,,Set a flag */
73         gstPkgTempExt.data_break = VEHICLE_SNS_BREAK;
74     }
75     pst_master->ul_did      = pst_data->ul_did;
76     pst_master->uc_rcvflag    = VEHICLE_RCVFLAG_ON;
77     pst_master->uc_data[us_start]  = pst_data->uc_data[0];
78
79     /* Update next storage start position and latest data storage position */
80     us_start++;
81     gstPkgTempExt.start_point[Rev] = us_start;
82
83     /* Update data master size */
84     if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
85         /* Make the size of all extended data masters */
86         pst_master->us_size = VEHICLE_DSIZE_REV_EXT;
87     } else {
88         /* Add the size of one received data item */
89         pst_master->us_size = static_cast<u_int16>(pst_master->us_size + sizeof(u_int8));
90     }
91 }
92
93 /**
94  * @brief
95  *   Vehicle Sensor REV GET Functions
96  *
97  *   Provide a REV data master
98  *
99  * @param[in]  *pst_data : Pointer to the data master acquisition destination
100  */
101 void VehicleSensGetRevExtl(VEHICLESENS_DATA_MASTER_EXT *pst_data) {
102   const VEHICLESENS_DATA_MASTER_EXT *pst_master;
103   uint16_t us_data_cnt = 0; // Number of data contained
104   uint16_t us_loop_cnt = 0; // 64 over index
105
106   /* Store the data master in the specified destination. */
107   pst_master      = &g_st_revext_l;
108   pst_data->ul_did    = pst_master->ul_did;
109   pst_data->us_size    = pst_master->us_size;
110   pst_data->uc_rcvflag  = pst_master->uc_rcvflag;
111
112   /* Checking whether the number of stored entries is looped */
113   if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
114     us_data_cnt = VEHICLE_DKEEP_MAX;
115   } else {
116     us_data_cnt = gstPkgTempExt.start_point[Rev];
117   }
118
119   /* Acquire data from the newest data master */
120   for (uint16_t us_cnt = 0; us_cnt < us_data_cnt; us_cnt++) {
121     if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
122       /* Get information before loop */
123       if (gstPkgTempExt.start_point[Rev] + us_cnt < VEHICLE_DKEEP_MAX) {
124         pst_data->uc_data[us_cnt] = pst_master->uc_data[(gstPkgTempExt.start_point[Rev] + us_cnt)];
125       } else {
126         pst_data->uc_data[us_cnt] = pst_master->uc_data[us_loop_cnt];
127         us_loop_cnt++;
128       }
129     } else {
130       pst_data->uc_data[us_cnt] = pst_master->uc_data[us_cnt];
131     }
132   }
133 }
134