Init basesystem source codes.
[staging/basesystem.git] / video_in_hal / vehicleservice / positioning / server / src / Sensor / VehicleSens_Did_GsnsYExt_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_GsnsYExt_l.cpp
19  *  System name    :_CWORD107_
20  *  Subsystem name  :Vehicle sensor process
21  *  Program name  :Vehicle sensor data master(POSHAL_DID_GSNS_Y)
22  *  Module configuration  :VehicleSensInitGsnsYExtl()    Vehicle sensor GSNS_Y initialization function
23  *                  :VehicleSensSetGsnsYExtlG()    Vehicle sensor GSNS_Y SET function
24  *                  :VehicleSensGetGsnsYExtl()    Vehicle sensor GSNS_Y 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  gstGsnsYExt_l;  // NOLINT(readability/nolint)
36
37 /*******************************************************************************
38 * MODULE    : VehicleSensInitGsnsYExtl
39 * ABSTRACT  : Vehicle sensor GSNS_Y initialization function
40 * FUNCTION  : GSNS_Y data master initialization processing
41 * ARGUMENT  : void
42 * NOTE      :
43 * RETURN    : void
44 ******************************************************************************/
45 void VehicleSensInitGsnsYExtl(void) {
46     memset(&gstGsnsYExt_l, 0x00, sizeof(VEHICLESENS_DATA_MASTER_EXT));
47     gstGsnsYExt_l.ul_did    = POSHAL_DID_GSNS_Y;
48     gstGsnsYExt_l.us_size  = VEHICLE_DSIZE_GSNS_Y_EXT_INIT;
49     gstGsnsYExt_l.uc_rcvflag  = VEHICLE_RCVFLAG_OFF;
50 }
51
52 /**
53  * @brief
54  *   Vehicle sensor GSNS_Y SET function
55  *
56  *   Update the GSNS_Y data master
57  *
58  * @param[in]  *pst_data : Pointer to the message data received by the direct line
59  */
60 void VehicleSensSetGsnsYExtlG(const LSDRV_LSDATA_G *pst_data) {
61     VEHICLESENS_DATA_MASTER_EXT *pst_master;
62     u_int16 us_start = 0;
63     u_int16 us_size = 0;
64     u_int16 us_cnt = 0;
65
66     pst_master = &gstGsnsYExt_l;
67     us_size = static_cast<u_int16>(sizeof(u_int16) * 10);  /* Size of one data item: 2byte * 10 data items */
68
69     /* Store the latest one in the internal data structure */
70     us_start = gstPkgTempExt.start_point[GsnsY];  /* Location to store one received message    */
71     /* Stored in data master(Order of reception)*/
72     if (us_start >= VEHICLE_DKEEP_MAX) {
73         /* Store the latest one at position 0 */
74         us_start = VEHICLE_DATA_POS_00;
75         /* If you are discarding old data,,Set a flag */
76         gstPkgTempExt.data_break = VEHICLE_SNS_BREAK;
77     }
78     pst_master->ul_did    = pst_data->ul_did;
79     pst_master->uc_rcvflag  = VEHICLE_RCVFLAG_ON;
80     for (us_cnt = 0; us_cnt < us_size; us_cnt++) {
81         pst_master->uc_data[us_start * us_size + us_cnt] = (u_int8)(pst_data->uc_data[us_cnt]);
82     }
83
84     /* Update next storage start position and latest data storage position */
85     us_start++;
86     gstPkgTempExt.start_point[GsnsY] = us_start;
87
88     /* Update data master size */
89     if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
90         /* Make the size of all extended data masters */
91         pst_master->us_size = VEHICLE_DSIZE_GSNS_Y_EXT;
92     } else {
93         /* Add the size of one received data item */
94         pst_master->us_size = static_cast<u_int16>(pst_master->us_size + us_size);
95     }
96 }
97
98 /*******************************************************************************
99 * MODULE    : VehicleSensGetGsnsYExtl
100 * ABSTRACT  : Vehicle sensor GSNS_Y GET function
101 * FUNCTION  : Provide the GSNS_Y data master
102 * ARGUMENT  : *pst_data : Pointer to the data master acquisition destination
103 * NOTE      :
104 * RETURN    : void
105 ******************************************************************************/
106 void VehicleSensGetGsnsYExtl(VEHICLESENS_DATA_MASTER_EXT *pst_data) {
107   const VEHICLESENS_DATA_MASTER_EXT *pst_master;
108   uint16_t us_size = 0;
109   uint16_t us_data_cnt = 0; // Number of data contained
110   uint16_t us_loop_cnt = 0; // 64 over index
111
112   /* Store the data master in the specified destination. */
113   pst_master           = &gstGsnsYExt_l;
114   pst_data->ul_did     = pst_master->ul_did;
115   pst_data->us_size    = pst_master->us_size;
116   pst_data->uc_rcvflag = pst_master->uc_rcvflag;
117
118   us_size = static_cast<u_int16>(sizeof(u_int16) * 10); /* Size of one data item: 2byte * 10 data items */
119
120   /* Checking whether the number of stored entries is looped */
121   if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
122     us_data_cnt = VEHICLE_DKEEP_MAX;
123   } else {
124     us_data_cnt = gstPkgTempExt.start_point[GsnsY];
125   }
126
127   /* Acquire data from the oldest data master */
128   for (uint16_t us_cnt = 0; us_cnt < us_data_cnt; us_cnt++) {
129     if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
130       /* Get information before loop */
131       if (gstPkgTempExt.start_point[GsnsY] + us_cnt < VEHICLE_DKEEP_MAX) {
132         memcpy(&pst_data->uc_data[us_cnt * us_size],
133                &pst_master->uc_data[(gstPkgTempExt.start_point[GsnsY] + us_cnt) * us_size], us_size);
134       } else {
135         memcpy(&pst_data->uc_data[us_cnt * us_size],
136                &pst_master->uc_data[us_loop_cnt * us_size], us_size);
137         us_loop_cnt++;
138       }
139     } else {
140       memcpy(&pst_data->uc_data[us_cnt * us_size],
141              &pst_master->uc_data[us_cnt * us_size], us_size);
142     }
143   }
144 }
145 #endif