2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * VehicleSens_Did_GyroTempExt_l.cpp
21 * Vehicle sensor data master(POSHAL_DID_GYRO_TEMP)
24 #include <vehicle_service/positioning_base_library.h>
25 #include "VehicleSens_DataMaster.h"
27 /*************************************************/
29 /*************************************************/
30 static VEHICLESENS_DATA_MASTER_EXT g_stgyro_temp_ext_l; // NOLINT(readability/nolint)
34 * Vehicle sensor gyro temperature initialization function
36 * Gyro Temperature Data Master Initialization Processing
38 void VehicleSensInitGyroTempExtl(void) {
39 (void)memset(reinterpret_cast<void *>(&g_stgyro_temp_ext_l), 0, sizeof(VEHICLESENS_DATA_MASTER_EXT));
40 g_stgyro_temp_ext_l.ul_did = POSHAL_DID_GYRO_TEMP;
41 g_stgyro_temp_ext_l.us_size = VEHICLE_DSIZE_GYRO_TEMP_EXT_INIT;
42 g_stgyro_temp_ext_l.uc_rcvflag = VEHICLE_RCVFLAG_OFF;
47 * Vehicle Sensor Gyro Temperature SET Function
49 * Update the gyro temperature data master
51 * @param[in] *pst_data : Pointer to the message data received by the direct line
53 * @return VEHICLESENS_EQ No data change<br>
54 * VEHICLESENS_NEQ Data change
56 void VehicleSensSetGyroTempExtlG(const LSDRV_LSDATA_G *pst_data) {
57 VEHICLESENS_DATA_MASTER_EXT *pst_master;
62 pst_master = &g_stgyro_temp_ext_l;
63 us_size = sizeof(u_int16); /* Size of one data item: 2byte */
65 /* Store the latest one in the internal data structure */
66 us_start = gstPkgTempExt.start_point[GyroTemp]; /* Location to store one received message */
67 /* Stored in data master(Order of reception)*/
68 if (us_start == VEHICLE_DKEEP_MAX) {
69 /* Store the latest one at position 0 */
70 us_start = VEHICLE_DATA_POS_00;
71 /* If you are discarding old data,,Set a flag */
72 gstPkgTempExt.data_break = VEHICLE_SNS_BREAK;
74 pst_master->ul_did = pst_data->ul_did;
75 pst_master->uc_rcvflag = VEHICLE_RCVFLAG_ON;
76 for (us_cnt = 0; us_cnt < us_size; us_cnt++) {
77 pst_master->uc_data[us_start * us_size + us_cnt] = (u_int8)(pst_data->uc_data[us_cnt]);
80 /* Update next storage start position and latest data storage position. */
82 gstPkgTempExt.start_point[GyroTemp] = us_start;
84 /* Update data master size */
85 if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
86 /* Make the size of all extended data masters */
87 pst_master->us_size = VEHICLE_DSIZE_GYRO_TEMP_EXT;
89 /* Add the size of one received data item */
90 pst_master->us_size = static_cast<u_int16>(pst_master->us_size + us_size);
96 * Vehicle Sensor Gyro Temperature GET Function
98 * Provide a gyro temperature data master
100 * @param[in] Pointer to the data master acquisition destination
102 void VehicleSensGetGyroTempExtl(VEHICLESENS_DATA_MASTER_EXT *pst_data) {
103 const VEHICLESENS_DATA_MASTER_EXT *pst_master;
104 uint16_t us_size = 0;
105 uint16_t us_data_cnt = 0; // Number of data contained
106 uint16_t us_loop_cnt = 0; // 64 over index
108 /* Store the data master in the specified destination. */
109 pst_master = &g_stgyro_temp_ext_l;
110 pst_data->ul_did = pst_master->ul_did;
111 pst_data->us_size = pst_master->us_size;
112 pst_data->uc_rcvflag = pst_master->uc_rcvflag;
114 us_size = sizeof(u_int16); /* Size of one data item: 2byte */
116 /* Checking whether the number of stored entries is looped */
117 if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
118 us_data_cnt = VEHICLE_DKEEP_MAX;
120 us_data_cnt = gstPkgTempExt.start_point[GyroTemp];
123 /* Acquire data from the oldest data master */
124 for (uint16_t us_cnt = 0; us_cnt < us_data_cnt; us_cnt++) {
125 if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
126 /* Get information before loop */
127 if (gstPkgTempExt.start_point[GyroTemp] + us_cnt < VEHICLE_DKEEP_MAX) {
128 memcpy(&pst_data->uc_data[us_cnt * us_size],
129 &pst_master->uc_data[(gstPkgTempExt.start_point[GyroTemp] + us_cnt) * us_size], us_size);
131 memcpy(&pst_data->uc_data[us_cnt * us_size],
132 &pst_master->uc_data[us_loop_cnt * us_size], us_size);
136 memcpy(&pst_data->uc_data[us_cnt * us_size],
137 &pst_master->uc_data[us_cnt * us_size], us_size);