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.
17 /*******************************************************************************
18 * File name :VehicleSens_Did_GsnsXExt_l.cpp
19 * System name :_CWORD107_
20 * Subsystem name :Vehicle sensor process
21 * Program name :Vehicle sensor data master(POSHAL_DID_GSNS_X)
22 * Module configuration :VehicleSensInitGsnsXExtl() Vehicle sensor GSNS_X initialization function
23 * :VehicleSensSetGsnsXExtlG() Vehicle sensor GSNS_X SET function
24 * :VehicleSensGetGsnsXExtl() Vehicle sensor GSNS_X GET function
25 ******************************************************************************/
27 #include <vehicle_service/positioning_base_library.h>
28 #include "VehicleSens_DataMaster.h"
30 /* Ignore->MISRA-C++:2008 Rule 2-7-2 */
31 #if CONFIG_SENSOR_EXT_VALID /* Initial Sensor Support */
32 /*************************************************/
34 /*************************************************/
35 static VEHICLESENS_DATA_MASTER_EXT gstGsnsXExt_l; // NOLINT(readability/nolint)
37 /*******************************************************************************
38 * MODULE : VehicleSensInitGsnsXExtl
39 * ABSTRACT : Vehicle sensor GSNS_X initialization function
40 * FUNCTION : GSNS_X data master initialization processing
44 ******************************************************************************/
45 void VehicleSensInitGsnsXExtl(void) {
46 memset(&gstGsnsXExt_l, 0x00, sizeof(VEHICLESENS_DATA_MASTER_EXT));
47 gstGsnsXExt_l.ul_did = POSHAL_DID_GSNS_X;
48 gstGsnsXExt_l.us_size = VEHICLE_DSIZE_GSNS_X_EXT_INIT;
49 gstGsnsXExt_l.uc_rcvflag = VEHICLE_RCVFLAG_OFF;
54 * Vehicle sensor GSNS_X SET function
56 * Update the GSNS_X data master
58 * @param[in] *pst_data : Pointer to the message data received by the direct line
60 void VehicleSensSetGsnsXExtlG(const LSDRV_LSDATA_G *pst_data) {
61 VEHICLESENS_DATA_MASTER_EXT *pst_master;
66 pst_master = &gstGsnsXExt_l;
67 us_size = static_cast<u_int16>(sizeof(u_int16) * 10); /* Size of one data item: 2byte * 10 data items */
69 /* Store the latest one in the internal data structure */
70 us_start = gstPkgTempExt.start_point[GsnsX]; /* 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;
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]);
84 /* Update next storage start position and latest data storage position */
86 gstPkgTempExt.start_point[GsnsX] = us_start;
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_X_EXT;
93 /* Add the size of one received data item */
94 pst_master->us_size = static_cast<u_int16>(pst_master->us_size + us_size);
98 /*******************************************************************************
99 * MODULE : VehicleSensGetGsnsXExtl
100 * ABSTRACT : Vehicle sensor GSNS_X GET function
101 * FUNCTION : Provide the GSNS_X data master
102 * ARGUMENT : *pst_data : Pointer to the data master acquisition destination
105 ******************************************************************************/
106 void VehicleSensGetGsnsXExtl(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
112 /* Store the data master in the specified destination. */
113 pst_master = &gstGsnsXExt_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;
118 us_size = static_cast<u_int16>(sizeof(u_int16) * 10); /* Size of one data item: 2byte * 10 data items */
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;
124 us_data_cnt = gstPkgTempExt.start_point[GsnsX];
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[GsnsX] + us_cnt < VEHICLE_DKEEP_MAX) {
132 memcpy(&pst_data->uc_data[us_cnt * us_size],
133 &pst_master->uc_data[(gstPkgTempExt.start_point[GsnsX] + us_cnt) * us_size], us_size);
135 memcpy(&pst_data->uc_data[us_cnt * us_size],
136 &pst_master->uc_data[us_loop_cnt * us_size], us_size);
140 memcpy(&pst_data->uc_data[us_cnt * us_size],
141 &pst_master->uc_data[us_cnt * us_size], us_size);