04e66b543f899289b9fd47c81d1275acd3ba4bf2
[staging/basesystem.git] / video_in_hal / vehicleservice / positioning / server / src / Sensor / VehicleSens_Did_PulseTimeExt_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_PulseTimeExt_l.cpp
20  * @brief
21  *  Vehicle sensor data master(POSHAL_DID_PULSE_TIME)
22  */
23
24 #include <vehicle_service/positioning_base_library.h>
25 #include "VehicleSens_DataMaster.h"
26
27 /*---------------------------------------------------------------------------------*
28  * Global Value                                                                    *
29  *---------------------------------------------------------------------------------*/
30 static VEHICLESENS_DATA_MASTER_EXT  g_st_pulsetime_ext_l;    // NOLINT(readability/nolint)
31
32 /**
33  * @brief
34  *   Vehicle sensor inter-pulse time initialization function
35  *
36  *   Inter-pulse time data master initialization processing
37  */
38 void VehicleSensInitPulseTimeExtl(void) {
39     (void)memset(reinterpret_cast<void *>(&g_st_pulsetime_ext_l), 0, sizeof(VEHICLESENS_DATA_MASTER_EXT));
40     g_st_pulsetime_ext_l.ul_did    = POSHAL_DID_PULSE_TIME;
41     g_st_pulsetime_ext_l.us_size  = VEHICLE_DSIZE_PULSE_TIME_EXT_INIT;
42     g_st_pulsetime_ext_l.uc_rcvflag  = VEHICLE_RCVFLAG_OFF;
43 }
44
45 /**
46  * @brief
47  *   Vehicle sensor pulse time SET function
48  *
49  *   Update the interpulse time data master
50  *
51  * @param[in]  *pst_data : Pointer to the message data received by the direct line
52  *
53  * @return  VEHICLESENS_EQ  No data change<br>
54  *      VEHICLESENS_NEQ Data change
55  */
56 void VehicleSensSetPulseTimeExtlG(const LSDRV_LSDATA_G *pst_data) {
57     VEHICLESENS_DATA_MASTER_EXT *pst_master;
58     u_int16 us_size = 0;
59     u_int16 us_start = 0;
60     u_int16 us_cnt = 0;
61
62     pst_master = &g_st_pulsetime_ext_l;
63     /* 4byte * (Number of data items + 32 data items) */
64     us_size = static_cast<u_int16>(sizeof(u_int32) * (1 + VEHICLE_SNS_INFO_PULSE_NUM));
65
66     /* Retrieve the location where the received one is stored */
67     us_start = gstPkgTempExt.start_point[PulseTime];
68
69     /* Stored in data master(Order of reception)*/
70     if (us_start >= VEHICLE_DKEEP_MAX) {
71         /* Store the latest one at position 0 */
72         us_start = VEHICLE_DATA_POS_00;
73         /* If you are discarding old data,,Set a flag */
74         gstPkgTempExt.data_break = VEHICLE_SNS_BREAK;
75     }
76     pst_master->ul_did    = pst_data->ul_did;
77     pst_master->uc_rcvflag  = VEHICLE_RCVFLAG_ON;
78     for (us_cnt = 0; us_cnt < us_size; us_cnt++) {
79         pst_master->uc_data[us_start * us_size + us_cnt] = (u_int8)(pst_data->uc_data[us_cnt]);
80     }
81
82     /* Update next storage start position and latest data storage position */
83     us_start++;
84     gstPkgTempExt.start_point[PulseTime] = us_start;
85
86     /* Update data master size */
87     if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
88         /* Make the size of all extended data masters */
89         pst_master->us_size = VEHICLE_DSIZE_PULSE_TIME_EXT;
90     } else {
91         /* Add the size of one received data item */
92         pst_master->us_size = static_cast<u_int16>(pst_master->us_size + us_size);
93     }
94 }
95
96 /**
97  * @brief
98  *   Vehicle sensor pulse time GET function
99  *
100  *   Provide interpulse time data master
101  *
102  * @param[in]  Pointer to the data master acquisition destination
103  */
104 void VehicleSensGetPulseTimeExtl(VEHICLESENS_DATA_MASTER_EXT *pst_data) {
105   const VEHICLESENS_DATA_MASTER_EXT *pst_master;
106   u_int16 us_size = 0;
107   uint16_t us_data_cnt = 0; // Number of data contained
108   uint16_t us_loop_cnt = 0; // 64 over index
109
110   /* Store the data master in the specified destination. */
111   pst_master      = &g_st_pulsetime_ext_l;
112   pst_data->ul_did    = pst_master->ul_did;
113   pst_data->us_size    = pst_master->us_size;
114   pst_data->uc_rcvflag  = pst_master->uc_rcvflag;
115
116   /* Size of one data item: 4byte * (Number of data items + 32 data items) */
117   us_size = static_cast<u_int16>(sizeof(u_int32) * (1 + VEHICLE_SNS_INFO_PULSE_NUM));
118
119   /* Checking whether the number of stored entries is looped */
120   if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
121     us_data_cnt = VEHICLE_DKEEP_MAX;
122   } else {
123     us_data_cnt = gstPkgTempExt.start_point[PulseTime];
124   }
125
126   /* Acquire data from the oldest data master */
127   for (uint16_t us_cnt = 0; us_cnt < us_data_cnt; us_cnt++) {
128     if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
129       /* Get information before loop */
130       if (gstPkgTempExt.start_point[PulseTime] + us_cnt < VEHICLE_DKEEP_MAX) {
131         memcpy(&pst_data->uc_data[us_cnt * us_size],
132                &pst_master->uc_data[(gstPkgTempExt.start_point[PulseTime] + us_cnt) * us_size], us_size);
133       } else {
134         memcpy(&pst_data->uc_data[us_cnt * us_size],
135                &pst_master->uc_data[us_loop_cnt * us_size], us_size);
136         us_loop_cnt++;
137       }
138     } else {
139       memcpy(&pst_data->uc_data[us_cnt * us_size],
140              &pst_master->uc_data[us_cnt * us_size], us_size);
141     }
142   }
143 }