Init basesystem source codes.
[staging/basesystem.git] / vehicleservice / positioning / server / src / Sensor / VehicleSens_Did_GsnsZFst_l.cpp
1 /*
2  * @copyright Copyright (c) 2019-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_GsnsZFst_l.cpp
20  * @brief
21  *  Vehicle sensor data master(POSHAL_DID_GSNS_Z_FST)
22  */
23
24 #include "VehicleSens_DataMaster.h"
25
26 /*************************************************/
27 /*           Global variable                      */
28 /*************************************************/
29 static  VEHICLESENS_DATA_MASTER_FST  g_st_gsnsz_fst_l;  // NOLINT(readability/nolint)
30
31 /**
32  * @brief
33  *   Vehicle sensor GSNS_Z initialization function
34  *
35  *   GSNS_Z data master initialization processing
36  */
37 void VehicleSensInitGsnsZFstl(void) {
38     memset(&g_st_gsnsz_fst_l, 0x00, sizeof(VEHICLESENS_DATA_MASTER_FST));
39     g_st_gsnsz_fst_l.ul_did        = POSHAL_DID_GSNS_Z_FST;
40     g_st_gsnsz_fst_l.us_size       = VEHICLE_DSIZE_GSNS_Z_EXT_INIT;
41     g_st_gsnsz_fst_l.uc_rcvflag    = VEHICLE_RCVFLAG_OFF;
42     g_st_gsnsz_fst_l.partition_flg = 0;
43 }
44
45 /**
46  * @brief
47  *   Vehicle sensor GSNS_Z SET function
48  *
49  *   Update the GSNS_Z 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 u_int8 VehicleSensSetGsnsZFstG(const LSDRV_LSDATA_FST_GSENSOR_Z *pst_data) {
57     static u_int8 uc_ret  = VEHICLESENS_EQ;
58     VEHICLESENS_DATA_MASTER_FST *pst_master;
59
60     u_int8  partition_max;    /* Total number of partitions */
61     u_int8  partition_num;    /* Data number                */
62
63     pst_master = &g_st_gsnsz_fst_l;
64
65     partition_max = pst_data->uc_partition_max;
66     partition_num = pst_data->uc_partition_num;
67
68     if (partition_max == 1) {
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         pst_master->partition_flg = 0;
77         memset(pst_master->uc_data, 0x00, sizeof(pst_master->uc_data));
78         memcpy(pst_master->uc_data, pst_data->uc_data, pst_data->uc_size);
79     } else if (partition_max == 2) {
80         if (partition_num == 1) {
81             /* Compare data master and received data */
82             uc_ret = VehicleSensmemcmp(pst_master->uc_data, pst_data->uc_data, pst_data->uc_size);
83
84             /* Received data is set in the data master. */
85             pst_master->ul_did      = pst_data->ul_did;
86             pst_master->us_size      = static_cast<u_int16>(pst_master->us_size + pst_data->uc_size);
87             pst_master->partition_flg  = 1;
88             memcpy(pst_master->uc_data, pst_data->uc_data, pst_data->uc_size);
89         } else if (partition_num == 2) {
90             /* Compare data master and received data */
91             if (uc_ret == VEHICLESENS_EQ) {
92                 uc_ret = VehicleSensmemcmp(&pst_master->uc_data[VEHICLE_DSIZE_GSNSZ_FST],
93                     pst_data->uc_data, pst_data->uc_size);
94             }
95
96             /* Received data is set in the data master. */
97             pst_master->ul_did        = pst_data->ul_did;
98             pst_master->us_size       = static_cast<u_int16>(pst_master->us_size + pst_data->uc_size);
99             pst_master->uc_rcvflag    = VEHICLE_RCVFLAG_ON;
100             pst_master->partition_flg = 1;
101             memcpy(&pst_master->uc_data[VEHICLE_DSIZE_GSNSZ_FST], pst_data->uc_data, pst_data->uc_size);
102         } else {}
103     } else {}
104
105     return(uc_ret);
106 }
107
108 /**
109  * @brief
110  *   Vehicle sensor GSNS_Z GET function
111  *
112  *   Provide the GSNS_Z data master
113  *
114  * @param[in]  Pointer to the data master acquisition destination
115  */
116 void VehicleSensGetGsnsZFstl(VEHICLESENS_DATA_MASTER_FST *pst_data) {
117     const VEHICLESENS_DATA_MASTER_FST *pst_master;
118
119     pst_master = &g_st_gsnsz_fst_l;
120
121     /* Store the data master in the specified destination. */
122     pst_data->ul_did        = pst_master->ul_did;
123     pst_data->us_size       = pst_master->us_size;
124     pst_data->uc_rcvflag    = pst_master->uc_rcvflag;
125     pst_data->partition_flg = pst_master->partition_flg;
126     memcpy(pst_data->uc_data, pst_master->uc_data, pst_master->us_size);
127 }