2 * @copyright Copyright (c) 2019-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.
17 /*******************************************************************************
18 * File name :VehicleSens_Did_GsnsZExt_l.cpp
19 * Subsystem name :Vehicle sensor process
20 * Program name :Vehicle sensor data master(POSHAL_DID_GSNS_Z)
21 * Module configuration :VehicleSensInitGsnsZExtl() Vehicle sensor GSNS_Z initialization function
22 * :VehicleSensSetGsnsZExtlG() Vehicle sensor GSNS_Z SET function
23 * :VehicleSensGetGsnsZExtl() Vehicle sensor GSNS_Z GET function
24 ******************************************************************************/
26 #include "VehicleSens_DataMaster.h"
28 #if CONFIG_SENSOR_EXT_VALID /* Initial Sensor Support */
29 /*************************************************/
31 /*************************************************/
32 static VEHICLESENS_DATA_MASTER_EXT gstGsnsZExt_l; // NOLINT(readability/nolint)
34 /*******************************************************************************
35 * MODULE : VehicleSensInitGsnsZExtl
36 * ABSTRACT : Vehicle sensor GSNS_Z initialization function
37 * FUNCTION : GSNS_Z data master initialization processing
41 ******************************************************************************/
42 void VehicleSensInitGsnsZExtl(void) {
43 memset(&gstGsnsZExt_l, 0x00, sizeof(VEHICLESENS_DATA_MASTER_EXT));
44 gstGsnsZExt_l.ul_did = POSHAL_DID_GSNS_Z;
45 gstGsnsZExt_l.us_size = VEHICLE_DSIZE_GSNS_Z_EXT_INIT;
46 gstGsnsZExt_l.uc_rcvflag = VEHICLE_RCVFLAG_OFF;
51 * Vehicle sensor GSNS_Z SET function
53 * Update the GSNS_Z data master
55 * @param[in] *pst_data : Pointer to the message data received by the direct line
57 void VehicleSensSetGsnsZExtlG(const LSDRV_LSDATA_G *pst_data) {
58 VEHICLESENS_DATA_MASTER_EXT *pst_master;
63 pst_master = &gstGsnsZExt_l;
64 us_size = static_cast<u_int16>(sizeof(u_int16) * 10); /* Size of one data item: 2byte * 10 data items */
66 /* Store the latest one in the internal data structure */
67 us_start = gstPkgTempExt.start_point[GsnsZ]; /* Location to store one received message */
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;
75 pst_master->ul_did = pst_data->ul_did;
76 pst_master->uc_rcvflag = VEHICLE_RCVFLAG_ON;
77 for (us_cnt = 0; us_cnt < us_size; us_cnt++) {
78 pst_master->uc_data[us_start * us_size + us_cnt] = (u_int8)(pst_data->uc_data[us_cnt]);
81 /* Update next storage start position and latest data storage position */
83 gstPkgTempExt.start_point[GsnsZ] = us_start;
85 /* Update data master size */
86 if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
87 /* Make the size of all extended data masters */
88 pst_master->us_size = VEHICLE_DSIZE_GSNS_Z_EXT;
90 /* Add the size of one received data item */
91 pst_master->us_size = static_cast<u_int16>(pst_master->us_size + us_size);
95 /*******************************************************************************
96 * MODULE : VehicleSensGetGsnsZExtl
97 * ABSTRACT : Vehicle sensor GSNS_Z GET function
98 * FUNCTION : Provide the GSNS_Z data master
99 * ARGUMENT : *pst_data : Pointer to the data master acquisition destination
102 ******************************************************************************/
103 void VehicleSensGetGsnsZExtl(VEHICLESENS_DATA_MASTER_EXT *pst_data) {
104 const VEHICLESENS_DATA_MASTER_EXT *pst_master;
105 uint16_t us_size = 0;
106 uint16_t us_data_cnt = 0; // Number of data contained
107 uint16_t us_loop_cnt = 0; // 64 over index
109 /* Store the data master in the specified destination. */
110 pst_master = &gstGsnsZExt_l;
111 pst_data->ul_did = pst_master->ul_did;
112 pst_data->us_size = pst_master->us_size;
113 pst_data->uc_rcvflag = pst_master->uc_rcvflag;
115 us_size = static_cast<u_int16>(sizeof(u_int16) * 10); /* Size of one data item: 2byte * 10 data items */
117 /* Checking whether the number of stored entries is looped */
118 if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
119 us_data_cnt = VEHICLE_DKEEP_MAX;
121 us_data_cnt = gstPkgTempExt.start_point[GsnsZ];
124 /* Acquire data from the oldest data master */
125 for (uint16_t us_cnt = 0; us_cnt < us_data_cnt; us_cnt++) {
126 if (gstPkgTempExt.data_break == VEHICLE_SNS_BREAK) {
127 /* Get information before loop */
128 if (gstPkgTempExt.start_point[GsnsZ] + us_cnt < VEHICLE_DKEEP_MAX) {
129 memcpy(&pst_data->uc_data[us_cnt * us_size],
130 &pst_master->uc_data[(gstPkgTempExt.start_point[GsnsZ] + us_cnt) * us_size], us_size);
132 memcpy(&pst_data->uc_data[us_cnt * us_size],
133 &pst_master->uc_data[us_loop_cnt * us_size], us_size);
137 memcpy(&pst_data->uc_data[us_cnt * us_size],
138 &pst_master->uc_data[us_cnt * us_size], us_size);