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 :Vehicle_API.cpp
20 * Subsystem name :Vehicle I/F library
21 * Program name :Vehicle I/F API
22 * Module configuration :POS_RegisterListenerSensData() Vehicle sensor information delivery registration
23 ******************************************************************************/
24 #include <vehicle_service/positioning_base_library.h>
26 #include <vehicle_service/POS_sensor_API.h>
27 #include "Sensor_API_private.h"
28 #include "Vehicle_API_Dummy.h"
29 #include "Vehicle_API_private.h"
30 #include "POS_private.h"
32 /*************************************************/
34 /*************************************************/
36 /*******************************************************************************
38 ******************************************************************************/
39 VEHICLE_RET_API VehicleInitialize(u_int32 (*sighand)()) { // LCOV_EXCL_START 8:dead code // NOLINT(readability/nolint)
40 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
41 RET_API _CWORD64_api_ret;
44 _CWORD64_api_ret = _pb_Setup_CWORD64_API(NULL);
46 if (_CWORD64_api_ret == RET_NORMAL) {
57 * Vehicle sensor information delivery registration
58 * Register delivery of vehicle sensor information
60 * @param[in] hApp Application handle
61 * @param[in] notifyName Destination thread name
62 * @param[in] ulDid Pointer to an array of data IDs for vehicle information
63 * @param[in] ucCtrlFlg Delivery control<br>
64 * Delivery registration: SENSOR_DELIVERY_REGIST<br>
65 * Delivery stop: SENSOR_DELIVERY_STOP (Note: Not mounted)<br>
66 * Resume delivery: SENSOR_DELIVERY_RESTART (Note: Not mounted)
67 * @param[in] ucDeliveryTiming Delivery timing<br>
68 * Updating : SENSOR_DELIVERY_TIMING_UPDATE<br>
69 * Changing : SENSOR_DELIVERY_TIMING_CHANGE
71 * @return SENSOR_RET_NORMAL Successful registration<br>
72 * SENSOR_RET_ERROR_CREATE_EVENT Event generation failure<br>
73 * SENSOR_RET_ERROR_PARAM Parameter error<br>
74 * SENSOR_RET_ERROR_DID Unregistered ID<br>
75 * SENSOR_RET_ERROR_BUFFULL FULL of delivery registers<br>
76 * SENSOR_RET_ERROR_NOSUPPORT Unsupported environment
79 SENSOR_RET_API POS_RegisterListenerSensData(HANDLE hApp,
80 PCSTR notifyName, DID ulDid, u_int8 ucCtrlFlg, u_int8 ucDeliveryTiming) {
81 SENSOR_RET_API ret; /* Return value */
82 UNIT_TYPE type; /* Supported HW Configuration Type */
85 /* Internal debug log output */
86 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+");
88 /* Check Delivery Control Designation */
89 ret = SENSOR_RET_NORMAL;
90 /* Arguments & Support Configuration Check */
91 if ((ucDeliveryTiming != SENSOR_DELIVERY_TIMING_CHANGE) &&
92 (ucDeliveryTiming != SENSOR_DELIVERY_TIMING_UPDATE)) {
93 /* Change delivery timing,Terminate as a parameter error except update */
94 ret = SENSOR_RET_ERROR_PARAM;
95 } else if (SENSOR_DELIVERY_REGIST != ucCtrlFlg) {
96 /* Parameters other than delivery registration terminated abnormally. */
97 ret = SENSOR_RET_ERROR_PARAM;
98 } else if (hApp == NULL) {
100 /* NULL terminates with an abnormal parameter */
101 ret = SENSOR_RET_ERROR_PARAM;
102 } else if (notifyName == NULL) {
103 /* Check Thread Name */
104 /* NULL terminates with an abnormal parameter */
105 ret = SENSOR_RET_ERROR_PARAM;
107 /* Positioning Base API initialization */
108 _pb_Setup_CWORD64_API(hApp);
110 /* Supported HW Configuration Check */
111 type = GetEnvSupportInfo();
112 if (UNIT_TYPE_GRADE1 == type) {
114 ret = SENSOR_RET_NORMAL;
115 } else if (UNIT_TYPE_GRADE2 == type) {
118 * This feature branches processing depending on the unit type.
120 ret = SENSOR_RET_ERROR_NOSUPPORT;
122 /* Environment error */
123 ret = SENSOR_RET_ERROR_NOSUPPORT;
127 if (SENSOR_RET_NORMAL == ret) {
129 ret_b = SENSOR_DID_JUDGE_REGLIS(ulDid);
130 if (ret_b == FALSE) {
131 /* An unacceptable ID is regarded as a parameter error. */
132 ret = SENSOR_RET_ERROR_PARAM;
134 /* Delivery registration process */
135 ret = PosRegisterListenerProc(notifyName, ulDid, ucCtrlFlg, ucDeliveryTiming);
139 /* Internal debug log output */
140 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "- [ret = %d]", ret);
145 /*******************************************************************************
146 * MODULE : PosSetShareData
147 * ABSTRACT : Write processing to shared memory
148 * FUNCTION : Write shared memory
149 * ARGUMENT : *share_top : Start address of shared memory
150 * : offset : Offsets to shared memory write destination
155 ******************************************************************************/
156 void PosSetShareData(void *share_top, u_int16 offset, const void *data_src, u_int16 size_src) {
157 VEHICLE_SHARE_BLOCK_DAT *share_dat;
158 /* Calculate Shared Memory Write Address */
159 share_dat = reinterpret_cast<VEHICLE_SHARE_BLOCK_DAT *>(reinterpret_cast<u_int8 *>(share_top) + offset);
161 /* _CWORD71_ processing speed(Memset modification) */
162 /* Clear Shared Memory(Unused area) */
163 share_dat->reserve[0] = 0;
164 share_dat->reserve[1] = 0;
166 /* Set write size to shared memory */
167 share_dat->size = size_src;
169 /* Set specified data in shared memory */
170 memcpy(reinterpret_cast<void *>(share_dat->data), data_src, (size_t)size_src);
173 /*******************************************************************************
174 * MODULE : VehicleGetDrData
175 * ABSTRACT : DR information acquisition
176 * FUNCTION : Retrieves DR information (optional data) by returning to completion.
177 * ARGUMENT : pno : Thread ID
178 * : did : Data ID for DR information
179 * : *dest_data : Pointer to the storage destination of DR information
180 * : dest_size : Storage destination size of DR information(byte)
182 * RETURN : Zero or more : Stored data size
183 * : VEHICLE_RET_ERROR_CREATE_EVENT : Event generation failure
184 * : VEHICLE_RET_ERROR_OUTOF_MEMORY : Shared memory allocation failed
185 * : VEHICLE_RET_ERROR_SIZE : Storage destination size error
186 * : VEHICLE_RET_ERROR_DID : Unregistered ID
187 ******************************************************************************/
188 int32 VehicleGetDrData(PNO pno, DID did, void *dest_data, u_int16 dest_size) { // LCOV_EXCL_START 8:dead code
189 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
190 VEHICLE_RET_API ret; /* Return value */
191 RET_API ret_api; /* System API return value */
192 EventID event_id; /* Event ID */
193 int32 event_val; /* Event value */
194 void *share_top; /* Start address of shared memory */
195 u_int32 share_size; /* Size of shared memory area */
196 u_int16 offset; /* Offset to free shared memory area */
197 VEHICLE_SHARE_BLOCK_DAT *share_dat; /* Address of free shared memory area */
198 VEHICLE_MSG_GET_VEHICLE_DATA_DAT data; /* Message data */
203 memset(reinterpret_cast<void *>(&data), 0, sizeof(VEHICLE_MSG_GET_VEHICLE_DATA_DAT));
205 /* Event Generation */
206 event_id = VehicleCreateEvent(pno);
209 /* Successful event generation */
210 /* Allocate shared memory */
211 ret_api = VehicleLinkShareData(reinterpret_cast<void **>(&share_top), &share_size, &offset);
212 if (RET_NORMAL != ret_api) {
213 /* Failed to allocate shared memory */
214 ret = VEHICLE_RET_ERROR_OUTOF_MEMORY;
216 /* When the shared memory is allocated successfully */
218 /* Calculate start address of free shared memory area */
219 share_dat = reinterpret_cast<VEHICLE_SHARE_BLOCK_DAT *>(reinterpret_cast<u_int8 *>(share_top) + offset);
221 /* Send vehicle sensor information acquisition message */
224 data.offset = offset;
225 data.size = VEHICLE_SHARE_BLOCK_DSIZE;
226 data.event_id = event_id;
229 ret_api = VehicleSndMsg(pno,
231 CID_VEHICLEIF_GET_DR_DATA,
232 sizeof(VEHICLE_MSG_GET_VEHICLE_DATA_DAT),
233 (const void *)&data);
235 if (RET_NORMAL == ret_api) {
236 /* Message transmission processing is successful */
237 /* Wait for completion event from vehicle sensor thread */
238 ret_api = _pb_WaitEvent(event_id,
240 VEHICLE_RET_ERROR_MIN, VEHICLE_RET_NORMAL, &event_val, INFINITE);
241 if (RET_NORMAL != ret_api) {
242 /* When not put in event wait state */
243 /* Return an event generation failure */
244 ret = VEHICLE_RET_ERROR_CREATE_EVENT;
246 /* Return from Event Wait */
248 /* Link to shared memory */
249 ret_api = _pb_LinkShareData(const_cast<char *>(VEHICLE_SHARE_NAME), &share_top, &share_size);
251 /* Calculate the address of the shared memory storage area. */
252 share_dat = reinterpret_cast<VEHICLE_SHARE_BLOCK_DAT *>(reinterpret_cast<u_int8 *>(share_top)
256 /* Vehicle sensor information acquisition failure */
257 ret = (VEHICLE_RET_API)event_val;
258 } else if (RET_NORMAL != ret_api) {
259 /* Shared memory error */
260 ret = VEHICLE_RET_ERROR_OUTOF_MEMORY;
261 } else if (dest_size < share_dat->size) {
262 /* Storage destination size error */
263 ret = VEHICLE_RET_ERROR_SIZE;
265 /* Vehicle sensor information acquisition success */
267 /* Copy from shared memory to user memory */
268 memcpy(dest_data, share_dat->data, (size_t)share_dat->size);
270 /* Set Write Size to Return Value */
271 ret = static_cast<int32>(share_dat->size);
275 /* Message transmission processing failed */
276 /* Return an event generation failure */
277 ret = VEHICLE_RET_ERROR_CREATE_EVENT;
279 /* Free shared memory */
280 (void)VehicleUnLinkShareData(reinterpret_cast<VEHICLE_SHARE*>(share_top), offset);
284 ret_api = VehicleDeleteEvent(event_id);
287 /* Event generation failure */
288 ret = VEHICLE_RET_ERROR_CREATE_EVENT;