Init basesystem source codes.
[staging/basesystem.git] / vehicleservice / positioning / server / src / Sensor / VehicleSens_Did_RevFst_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_RevFst_l.cpp
19  *  System name    :PastModel002
20  *  Subsystem name  :Vehicle sensor process
21  *  Program name  :Vehicle sensor data master(POSHAL_DID_REV_FST)
22  *  Module configuration  :VehicleSensInitRevFstl()  Vehicle Sensor REV Initialization Functions
23  *                  :VehicleSensSetRevFstl()    Vehicle Sensor REV SET Functions
24  *                  :VehicleSensSetRevFstG()    Vehicle Sensor REV SET Functions
25  *                  :VehicleSensGetRevFstl()    Vehicle Sensor REV GET Functions
26  ******************************************************************************/
27
28 #include <vehicle_service/positioning_base_library.h>
29 #include "VehicleSens_DataMaster.h"
30
31 #if CONFIG_SENSOR_EXT_VALID        /* Initial Sensor Support */
32 /*************************************************/
33 /*           Global variable                      */
34 /*************************************************/
35 static  VEHICLESENS_DATA_MASTER_FST  gstRevFst_l;    // NOLINT(readability/nolint)
36
37 /*******************************************************************************
38 * MODULE    : VehicleSensInitRevFstl
39 * ABSTRACT  : Vehicle Sensor REV Initialization Functions
40 * FUNCTION  : REV data master initialization processing
41 * ARGUMENT  : void
42 * NOTE      :
43 * RETURN    : void
44 ******************************************************************************/
45 void VehicleSensInitRevFstl(void) {
46     (void)memset(reinterpret_cast<void *>(&gstRevFst_l), 0, sizeof (VEHICLESENS_DATA_MASTER_FST));
47     gstRevFst_l.ul_did      = POSHAL_DID_REV_FST;
48     gstRevFst_l.us_size      = 0U;
49     gstRevFst_l.uc_rcvflag    = 0U;
50     gstRevFst_l.partition_flg  = 0;
51 }
52
53 /*******************************************************************************
54 * MODULE    : VehicleSensSetRevFstl
55 * ABSTRACT  : Vehicle Sensor REV SET Functions
56 * FUNCTION  : Update the REV data master
57 * ARGUMENT  : *pst_data : Pointer to the message data received by the direct line
58 * NOTE      :
59 * RETURN    : VEHICLESENS_EQ  : No data change
60 *             VEHICLESENS_NEQ  : Data change
61 ******************************************************************************/
62 u_int8 VehicleSensSetRevFstl(const LSDRV_LSDATA_FST *pst_data) {  // LCOV_EXCL_START 8 : dead code
63     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
64     u_int8 uc_ret;
65     VEHICLESENS_DATA_MASTER_FST *pst_master;
66
67     pst_master = &gstRevFst_l;
68
69     /* Compare data master and received data */
70     uc_ret = VehicleSensmemcmp(pst_master->uc_data, pst_data->uc_data, pst_data->uc_size);
71
72     /* Received data is set in the data master. */
73     pst_master->ul_did    = pst_data->ul_did;
74     pst_master->us_size    = pst_data->uc_size;
75     pst_master->uc_rcvflag  = VEHICLE_RCVFLAG_ON;
76     (void)memcpy(reinterpret_cast<void *>(pst_master->uc_data),
77         (const void *)(pst_data->uc_data), (size_t)(pst_data->uc_size));
78
79     return(uc_ret);
80 }
81 // LCOV_EXCL_STOP
82
83 /*******************************************************************************
84 * MODULE    : VehicleSensSetRevFstG
85 * ABSTRACT  : Vehicle Sensor REV SET Functions
86 * FUNCTION  : Update the REV data master
87 * ARGUMENT  : *pst_data : Pointer to the message data received by the direct line
88 * NOTE      :
89 * RETURN    : VEHICLESENS_EQ  : No data change
90 *             VEHICLESENS_NEQ  : Data change
91 ******************************************************************************/
92 u_int8 VehicleSensSetRevFstG(const LSDRV_LSDATA_FST_REV *pst_data) {
93     static u_int8 uc_ret = VEHICLESENS_EQ;
94     VEHICLESENS_DATA_MASTER_FST *pst_master;
95
96     pst_master = &gstRevFst_l;
97
98     u_int8  partition_max;    /* Total number of partitions            */
99     u_int8  partition_num;    /* Data number          */
100
101     partition_max = pst_data->uc_partition_max;
102     partition_num = pst_data->uc_partition_num;
103
104     if (partition_max == 1) {  /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
105         /* Compare data master and received data */
106         uc_ret = VehicleSensmemcmp(pst_master->uc_data,
107                 pst_data->uc_data, pst_data->uc_size);  /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
108
109         /* Received data is set in the data master. */
110         pst_master->ul_did      = pst_data->ul_did;
111         pst_master->us_size      = pst_data->uc_size;
112         pst_master->uc_rcvflag    = VEHICLE_RCVFLAG_ON;
113         pst_master->partition_flg  = 0;
114         memset(pst_master->uc_data, 0x00, sizeof(pst_master->uc_data));
115         memcpy(pst_master->uc_data, pst_data->uc_data, pst_data->uc_size);  /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
116     } else if (partition_max == 2) {  /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
117         if (partition_num == 1) {  /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
118             /* Compare data master and received data */
119             /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
120             uc_ret = VehicleSensmemcmp(pst_master->uc_data, pst_data->uc_data, pst_data->uc_size);
121
122             /* Received data is set in the data master. */
123             pst_master->ul_did      = pst_data->ul_did;
124             /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
125             pst_master->us_size = static_cast<u_int16>(pst_master->us_size + pst_data->uc_size);
126             pst_master->partition_flg  = 1;
127             memcpy(pst_master->uc_data, pst_data->uc_data, pst_data->uc_size);  /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
128         } else if (partition_num == 2) {  /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
129             /* Compare data master and received data */
130             if (uc_ret == VEHICLESENS_EQ) {
131                 uc_ret = VehicleSensmemcmp(&pst_master->uc_data[VEHICLE_DSIZE_REV_FST],
132                             pst_data->uc_data, pst_data->uc_size);  /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
133             }
134
135             /* Received data is set in the data master. */
136             pst_master->ul_did      = pst_data->ul_did;
137             /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
138             pst_master->us_size = static_cast<u_int16>(pst_master->us_size + pst_data->uc_size);
139             pst_master->uc_rcvflag    = VEHICLE_RCVFLAG_ON;
140             pst_master->partition_flg  = 1;
141             memcpy(&pst_master->uc_data[VEHICLE_DSIZE_REV_FST],
142                             pst_data->uc_data, pst_data->uc_size);  /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
143         } else {}
144     } else {}
145
146     return(uc_ret);
147 }
148
149 /*******************************************************************************
150 * MODULE    : VehicleSensGetRevFstl
151 * ABSTRACT  : Vehicle Sensor REV GET Functions
152 * FUNCTION  : Provide a REV data master
153 * ARGUMENT  : *pst_data : Pointer to the data master acquisition destination
154 * NOTE      :
155 * RETURN    : void
156 ******************************************************************************/
157 void VehicleSensGetRevFstl(VEHICLESENS_DATA_MASTER_FST *pst_data) {
158     const VEHICLESENS_DATA_MASTER_FST *pst_master;
159
160     pst_master = &gstRevFst_l;
161
162     /* Store the data master in the specified destination. */
163     pst_data->ul_did    = pst_master->ul_did;
164     pst_data->us_size    = pst_master->us_size;
165     pst_data->uc_rcvflag  = pst_master->uc_rcvflag;
166     pst_data->partition_flg    = pst_master->partition_flg;
167     (void)memcpy(reinterpret_cast<void *>(pst_data->uc_data),
168         (const void *)(pst_master->uc_data), (size_t)(pst_master->us_size));
169 }
170
171 #endif