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