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_FromAccess.cpp
19 * System name :PastModel002
20 * Subsystem name :Vehicle sensor process
21 * Program name :Functions for accessing vehicle sensor FROM
22 ******************************************************************************/
24 #include <vehicle_service/positioning_base_library.h>
25 #include "VehicleSens_FromAccess.h"
26 #include "ClockDataMng.h"
28 /********************************************************************************
30 ********************************************************************************/
32 /********************************************************************************
33 * prototype declalation *
34 ********************************************************************************/
35 static RET_API VehicleSensReadNV(NV_DATA_VEHICLESENS *p_nv_data);
37 /********************************************************************************
39 ********************************************************************************/
40 #define VEHICLESENS_FROM_ACCESS_DEBUG 0
42 /*******************************************************************************
43 * MODULE : VehicleSensFromAccessInitialize
44 * ABSTRACT : Initializing process
49 ******************************************************************************/
50 void VehicleSensFromAccessInitialize(void) {
51 /* The result of tag registration for non-volatile memory access is stored in g_nv_access_available, so no confirmation is required. */
52 (void)VehicleSensRegistNvTag();
56 /*******************************************************************************
57 * MODULE : VehicleSensRegistNvTag
58 * ABSTRACT : Tag registration process
59 * FUNCTION : Registering Tag Name to Identify Data Storage Destination
62 * RETURN : RET_NORMAL :Successful registration
63 * : RET_ERROR :Registration failure
64 ******************************************************************************/
65 RET_API VehicleSensRegistNvTag(void) {
66 RET_API lret = RET_NORMAL;
70 /*******************************************************************************
71 * MODULE : VehicleSensReadNV
72 * ABSTRACT : Get local time Lonlat
73 * FUNCTION : Reading local time Lonlat from non-volatile memory
74 * ARGUMENT : NV_DATA_VEHICLESENS * p_nv_data : Pointer to data acquired from non-volatile memory
76 * RETURN : RET_NORMAL :Read success
77 * : RET_ERROR :Failed to read
78 ******************************************************************************/
79 static RET_API VehicleSensReadNV(NV_DATA_VEHICLESENS * p_nv_data) { // LCOV_EXCL_START 8 : dead code
80 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
81 RET_API lret = RET_NORMAL;
83 NV_DATA_VEHICLESENS nv_data_tmp;
84 BOOL ret_read = FALSE;
85 BOOL ret_read2 = FALSE;
92 fp = fopen(NV_FILE_VEHICLESENS_TEMP, "rb");
96 if ((fread(reinterpret_cast<void *>(p_nv_data), sizeof(u_int8), sizeof(NV_DATA_VEHICLESENS), fp)) == \
97 sizeof(NV_DATA_VEHICLESENS)) {
98 /* Checksum processing */
99 ptr = reinterpret_cast<u_int8 *>(p_nv_data); /* #QAC confirmation Rule11.4 1Byte accesses for checksums */
103 /* The 2Byte portion from the end of the checksum data is excluded because the checksum storage area. */
104 for (loop = 0; loop < (sizeof(NV_DATA_VEHICLESENS) - 2); loop++) {
105 CK_A = static_cast<u_int8>(CK_A + ptr[loop]);
106 CK_B = static_cast<u_int8>(CK_B + CK_A);
110 if ((p_nv_data->cka == CK_A) && (p_nv_data->ckb == CK_B)) {
113 #if VEHICLESENS_FROM_ACCESS_DEBUG
114 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "NV read, status, year, month, day, hour, min, sec, lat, lon, "\
115 "timediff, update_counter, cka, ckb ");
116 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "NV read, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d ",
117 p_nv_data->localtime.status,
118 p_nv_data->localtime.year,
119 p_nv_data->localtime.month,
120 p_nv_data->localtime.day,
121 p_nv_data->localtime.hour,
122 p_nv_data->localtime.min,
123 p_nv_data->localtime.sec,
124 p_nv_data->lonlat.latitude,
125 p_nv_data->lonlat.longitude,
127 p_nv_data->update_counter,
130 #endif /* VEHICLESENS_FROM_ACCESS_DEBUG */
132 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Checksum1 failed.");
136 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "fread1 failed.");
140 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "fopen1 failed.");
144 fp = fopen(NV_FILE_VEHICLESENS2_TEMP, "rb");
147 if ((fread(reinterpret_cast<void *>(&nv_data_tmp), sizeof(u_int8), sizeof(NV_DATA_VEHICLESENS), fp)) == \
148 sizeof(NV_DATA_VEHICLESENS)) {
149 /* Checksum processing */
150 ptr = reinterpret_cast<u_int8 *>(&nv_data_tmp); /* #QAC confirmation Rule11.4 1Byte accesses for checksums */
154 /* The 2Byte portion from the end of the checksum data is excluded because the checksum storage area. */
155 for (loop = 0; loop < (sizeof(NV_DATA_VEHICLESENS) - 2); loop++) {
156 CK_A = static_cast<u_int8>(CK_A + ptr[loop]);
157 CK_B = static_cast<u_int8>(CK_B + CK_A);
161 if ((nv_data_tmp.cka == CK_A) && (nv_data_tmp.ckb == CK_B)) {
164 #if VEHICLESENS_FROM_ACCESS_DEBUG
165 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "NV read2, status, year, month, day, hour, min, sec, lat, lon, "\
166 "timediff, update_counter, cka, ckb ");
167 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "NV read2, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d ",
168 nv_data_tmp.localtime.status,
169 nv_data_tmp.localtime.year,
170 nv_data_tmp.localtime.month,
171 nv_data_tmp.localtime.day,
172 nv_data_tmp.localtime.hour,
173 nv_data_tmp.localtime.min,
174 nv_data_tmp.localtime.sec,
175 nv_data_tmp.lonlat.latitude,
176 nv_data_tmp.lonlat.longitude,
177 nv_data_tmp.timediff,
178 nv_data_tmp.update_counter,
181 #endif /* VEHICLESENS_FROM_ACCESS_DEBUG */
183 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Checksum2 failed.");
187 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "fread2 failed.");
191 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "fopen2 failed.");
195 /* Check the read results of File 1 and File 2. */
196 if ((ret_read == TRUE) && (ret_read2 == TRUE)) {
197 /* Whether File 1 or File 2 is the most recent file,Check with the update count counter */
198 if (p_nv_data->update_counter < nv_data_tmp.update_counter) {
199 (void)memcpy(reinterpret_cast<void *>(p_nv_data), reinterpret_cast<void *>(&nv_data_tmp), \
200 sizeof(NV_DATA_VEHICLESENS));
203 } else if (ret_read == TRUE) {
206 } else if (ret_read2 == TRUE) {
208 (void)memcpy(reinterpret_cast<void *>(p_nv_data), reinterpret_cast<void *>(&nv_data_tmp), \
209 sizeof(NV_DATA_VEHICLESENS));
212 /* Read failed for both file 1 and file 2 */
213 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "fread failed.");
220 /*******************************************************************************
221 * MODULE : VehicleSensReadNVLocalTime
222 * ABSTRACT : Local time acquisition at shutdown
223 * FUNCTION : Read local time at shutdown from non-volatile memory
224 * ARGUMENT : LOCALTIME * local_time : Local time at shutdown
226 * RETURN : RET_NORMAL :Successful acquisition
227 * : RET_ERROR :Failed to acquire
228 ******************************************************************************/
229 RET_API VehicleSensReadNVLocalTime(LOCALTIME * local_time) {
230 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
232 NV_DATA_VEHICLESENS nv_data;
234 lret = VehicleSensReadNV(&nv_data);
236 if (lret == RET_NORMAL) {
237 (void)memcpy(reinterpret_cast<void *>(local_time), (const void *)(&nv_data.localtime), sizeof(LOCALTIME));
243 /*******************************************************************************
244 * MODULE : VehicleSensReadNVLonLat
245 * ABSTRACT : Obtain position at shutdown
246 * FUNCTION : Read the shutdown position from the non-volatile memory
247 * ARGUMENT : LONLAT * lonlat : Shutdown position
249 * RETURN : RET_NORMAL :Successful acquisition
250 * : RET_ERROR :Failed to acquire
251 ******************************************************************************/
252 RET_API VehicleSensReadNVLonLat(LONLAT * lonlat) {
253 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
255 NV_DATA_VEHICLESENS nv_data;
257 lret = VehicleSensReadNV(&nv_data);
259 if (lret == RET_NORMAL) {
260 (void)memcpy(reinterpret_cast<void *>(lonlat), (const void *)(&nv_data.lonlat), sizeof(LONLAT));
266 /*******************************************************************************
267 * MODULE : VehicleSensReadNVTimeDiff
268 * ABSTRACT : Shutdown time difference acquisition
269 * FUNCTION : Reading the shutdown time difference from the non-volatile memory
270 * ARGUMENT : int32 * time_diff : Shutdown position
272 * RETURN : RET_NORMAL :Successful acquisition
273 * : RET_ERROR :Failed to acquire
274 ******************************************************************************/
275 RET_API VehicleSensReadNVTimeDiff(int32 * time_diff) {
276 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
278 NV_DATA_VEHICLESENS nv_data;
280 lret = VehicleSensReadNV(&nv_data);
282 if (lret == RET_NORMAL) {
283 *time_diff = nv_data.timediff;
289 /*******************************************************************************
290 * MODULE : VehicleSensStoreLonlat
291 * ABSTRACT : Store location data in non-volatile memory
293 * ARGUMENT : LONLAT * plonlat : Position data
296 ******************************************************************************/
297 void VehicleSensStoreLonlat(LONLAT * plonlat) {
298 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
303 /*******************************************************************************
304 * MODULE : VehicleSensWriteNVLocaltime
305 * ABSTRACT : Local Time Write
306 * FUNCTION : Write local time
307 * ARGUMENT : LOCALTIME * local_time : Local time
309 * RETURN : RET_NORMAL :Successful write
310 * : RET_ERROR :Writing failure
311 ******************************************************************************/
312 RET_API VehicleSensWriteNVLocaltime(LOCALTIME * local_time, int32 * time_diff) {
313 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
314 RET_API lret = RET_NORMAL;