Init basesystem source codes.
[staging/basesystem.git] / video_in_hal / vehicleservice / positioning / server / src / Sensor / VehicleSens_Did_GsnsXFst_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
19  *  VehicleSens_Did_GsnsXFst_l.cpp
20  * @brief
21  *  Vehicle sensor data master(POSHAL_DID_GSNS_X_FST)
22  */
23
24 #include <vehicle_service/positioning_base_library.h>
25 #include "VehicleSens_DataMaster.h"
26
27 /*************************************************/
28 /*           Global variable                      */
29 /*************************************************/
30 static  VEHICLESENS_DATA_MASTER_FST  g_st_gsnsx_fst_l;    // NOLINT(readability/nolint)
31
32 /**
33  * @brief
34  *   Vehicle sensor GSNS_X initialization function
35  *
36  *   GSNS_X data master initialization processing
37  */
38 void VehicleSensInitGsnsXFstl(void) {
39     memset(&g_st_gsnsx_fst_l, 0x00, sizeof(VEHICLESENS_DATA_MASTER_FST));
40     g_st_gsnsx_fst_l.ul_did        = POSHAL_DID_GSNS_X_FST;
41     g_st_gsnsx_fst_l.us_size      = VEHICLE_DSIZE_GSNS_X_EXT_INIT;
42     g_st_gsnsx_fst_l.uc_rcvflag      = VEHICLE_RCVFLAG_OFF;
43     g_st_gsnsx_fst_l.partition_flg  = 0;
44 }
45
46 /**
47  * @brief
48  *   Vehicle sensor GSNS_X SET function
49  *
50  *   Update the GSNS_X data master
51  *
52  * @param[in]  *pst_data : Pointer to the message data received by the direct line
53  *
54  * @return  VEHICLESENS_EQ  No data change<br>
55  *      VEHICLESENS_NEQ Data change
56  */
57 u_int8 VehicleSensSetGsnsXFstG(const LSDRV_LSDATA_FST_GSENSOR_X *pst_data) {
58     static u_int8 uc_ret  = VEHICLESENS_EQ;
59     VEHICLESENS_DATA_MASTER_FST *pst_master;
60
61     u_int8  partition_max;    /* Total number of partitions            */
62     u_int8  partition_num;    /* Data number          */
63
64     pst_master = &g_st_gsnsx_fst_l;
65
66     partition_max = pst_data->uc_partition_max;
67     partition_num = pst_data->uc_partition_num;
68
69     if (partition_max == 1) {
70         /* Compare data master and received data */
71         uc_ret = VehicleSensmemcmp(pst_master->uc_data, pst_data->uc_data, pst_data->uc_size);
72
73         /* Received data is set in the data master. */
74         pst_master->ul_did      = pst_data->ul_did;
75         pst_master->us_size      = pst_data->uc_size;
76         pst_master->uc_rcvflag    = VEHICLE_RCVFLAG_ON;
77         pst_master->partition_flg  = 0;
78         memset(pst_master->uc_data, 0x00, sizeof(pst_master->uc_data));
79         memcpy(pst_master->uc_data, pst_data->uc_data, pst_data->uc_size);
80     } else if (partition_max == 2) {
81         if (partition_num == 1) {
82             /* Compare data master and received data */
83             uc_ret = VehicleSensmemcmp(pst_master->uc_data, pst_data->uc_data, pst_data->uc_size);
84
85             /* Received data is set in the data master. */
86             pst_master->ul_did      = pst_data->ul_did;
87             pst_master->us_size      = static_cast<u_int16>(pst_master->us_size + pst_data->uc_size);
88             pst_master->partition_flg  = 1;
89             memcpy(pst_master->uc_data, pst_data->uc_data, pst_data->uc_size);
90         } else if (partition_num == 2) {
91             /* Compare data master and received data */
92             if (uc_ret == VEHICLESENS_EQ) {
93                 uc_ret = VehicleSensmemcmp(&pst_master->uc_data[VEHICLE_DSIZE_GSNSX_FST],
94                     pst_data->uc_data, pst_data->uc_size);
95             }
96
97             /* Received data is set in the data master. */
98             pst_master->ul_did      = pst_data->ul_did;
99             pst_master->us_size      = static_cast<u_int16>(pst_master->us_size + pst_data->uc_size);
100             pst_master->uc_rcvflag    = VEHICLE_RCVFLAG_ON;
101             pst_master->partition_flg  = 1;
102             memcpy(&pst_master->uc_data[VEHICLE_DSIZE_GSNSX_FST], pst_data->uc_data, pst_data->uc_size);
103         } else { }
104     } else { }
105     return(uc_ret);
106 }
107
108 /**
109  * @brief
110  *   Vehicle sensor GSNS_X GET function
111  *
112  *   Provide the GSNS_X data master
113  *
114  * @param[in]  Pointer to the data master acquisition destination
115  */
116 void VehicleSensGetGsnsXFstl(VEHICLESENS_DATA_MASTER_FST *pst_data) {
117     const VEHICLESENS_DATA_MASTER_FST *pst_master;
118
119     pst_master = &g_st_gsnsx_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 }