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.
21 * Inner functions of Positoning API
24 #ifndef POSITIONING_CLIENT_INCLUDE_POS_PRIVATE_H_
25 #define POSITIONING_CLIENT_INCLUDE_POS_PRIVATE_H_
27 /*---------------------------------------------------------------------------------*
29 *---------------------------------------------------------------------------------*/
30 #include <vehicle_service/positioning_base_library.h>
31 #include <vehicle_service/POS_define.h>
32 #include "Vehicle_API_Dummy.h"
33 #include "Vehicle_API_private.h"
34 #include "Naviinfo_API.h"
35 #include "POS_common_private.h"
36 #include <asm/unistd.h>
37 #include <other_service/VP_GetEnv.h>
38 #include <other_service/env_vehicleparameterlibrary.h>
39 #include "CommonDefine.h"
40 /*---------------------------------------------------------------------------------*
41 * Function Prototype *
42 *---------------------------------------------------------------------------------*/
43 /* Shared Library Value Area Check Function */
44 inline UNIT_TYPE GetEnvSupportInfo(void);
45 inline BOOL ChkUnitType(UNIT_TYPE type);
46 inline RET_API MunMapDeviceIo(HANDLE dev, uint32_t map_size);
47 inline RET_API MilliSecSleep(uint32_t mill_time);
48 inline POS_RET_API PosChkParam8(int8_t data, int8_t min, int8_t max, const char* fn, int32_t line);
49 inline POS_RET_API PosChkParam16(int16_t data, int16_t min, int16_t max, const char* fn, int32_t line);
50 inline POS_RET_API PosChkParam32(int32_t data, int32_t min, int32_t max, const char* fn, int32_t line);
51 inline POS_RET_API PosChkParamU8(uint8_t data, uint8_t min, uint8_t max, const char* fn, int32_t line);
52 inline POS_RET_API PosChkParamU16(uint16_t data, uint16_t min, uint16_t max, const char* fn, int32_t line);
53 inline POS_RET_API PosChkParamU32(uint32_t data, uint32_t min, uint32_t max, const char* fn, int32_t line);
55 /* Shared Intra-Library Core Functions */
56 inline POS_RET_API PosSetProc(DID did, void *p_data, uint16_t size, uint8_t is_event);
57 inline POS_RET_API PosGetProc(DID did, void *p_data, uint16_t dest_size);
58 inline SENSOR_RET_API PosRegisterListenerProc(PCSTR notify_name,
59 DID did, u_int8 ctrl_flg, u_int8 delivery_timing);
61 /* General Functions in Shared Libraries */
62 inline EventID VehicleCreateEvent(PNO pno);
63 inline RET_API VehicleDeleteEvent(EventID event_id);
64 inline RET_API VehicleLinkShareData(void **share_top, uint32_t *share_size, uint16_t *offset);
65 inline RET_API VehicleUnLinkShareData(VEHICLE_SHARE *share_top, uint16_t offset);
66 inline RET_API VehicleSndMsg(PNO pno_src, PNO pno_dest, CID cid, uint16_t msg_len, const void *msg_data);
67 inline BOOL VehicleGetResource(void);
68 inline void VehicleReleaseResource(void);
69 inline uint32_t GetTid(void);
70 /*---------------------------------------------------------------------------------*
72 *---------------------------------------------------------------------------------*/
73 #define POS_CHKPARAM8(data, min, max) PosChkParam8(data, min, max, __func__, __LINE__)
74 #define POS_CHKPARAM16(data, min, max) PosChkParam16(data, min, max, __func__, __LINE__)
75 #define POS_CHKPARAM32(data, min, max) PosChkParam32(data, min, max, __func__, __LINE__)
76 #define POS_CHKPARAMU8(data, min, max) PosChkParamU8(data, min, max, __func__, __LINE__)
77 #define POS_CHKPARAMU16(data, min, max) PosChkParamU16(data, min, max, __func__, __LINE__)
78 #define POS_CHKPARAMU32(data, min, max) PosChkParamU32(data, min, max, __func__, __LINE__)
79 #define POS_API_TIME_OUT_MS 5000 /* Timeout period(ms) */
81 /*---------------------------------------------------------------------------------*
83 *---------------------------------------------------------------------------------*/
84 UNIT_TYPE GetEnvSupportInfo(void) {
85 UNIT_TYPE ret_type = UNIT_TYPE_GRADE1;
87 char env_area[VP_MAX_LENGTH];
88 char env_grade[VP_MAX_LENGTH];
89 char* p_env_grade = env_grade;
90 char* p_env_area = env_area;
94 * This feature branches processing depending on the area and grade type.
97 VP_GetEnv(VP_VEHICLEPARAMETERLIBRARY_AREA, p_env_area);
99 if (0 == strcmp(p_env_area, "AREA1")) {
100 ret_type = UNIT_TYPE_GRADE2;
101 } else if (0 == strcmp(p_env_area, "AREA2")) {
102 memset(&env_grade, 0x00, sizeof(env_grade));
103 VP_GetEnv(VP_VEHICLEPARAMETERLIBRARY_GRADE, p_env_grade);
104 if (0 == strcmp(p_env_grade, "_CWORD95_") ||
105 0 == strcmp(p_env_grade, "_CWORD101_") ||
106 0 == strcmp(p_env_grade, "_CWORD61_")) {
107 ret_type = UNIT_TYPE_GRADE2;
116 BOOL ChkUnitType(UNIT_TYPE type) {
120 type_temp = GetEnvSupportInfo();
121 if ((type_temp & type) != 0) {
130 RET_API MunMapDeviceIo(HANDLE dev, uint32_t map_size) {
134 RET_API MilliSecSleep(uint32_t mill_time) {
138 /* Discard the time slice */
144 /* Abort processing indefinitely */
150 /* Sleep for Specified Time */
151 usleep(mill_time * 1000);
160 * Data Valid Value Determination(int8)
162 * @param[in] date int8_t Object data
163 * @param[in] min int8_t Target Data Valid Value Range(Minimum value)
164 * @param[in] max int8_t Target Data Valid Value Range(Maximum value)
165 * @param[in] fn const char* Pointer to the function name
166 * @param[in] line int32_t Number of lines
168 * @return POS_RET_NORMAL Within the valid range<br>
169 * POS_RET_ERROR Out of scope<br>
170 * POS_RET_ERROR_PARAM Argument error
172 inline POS_RET_API PosChkParam8(int8_t data, int8_t min, int8_t max, const char* fn, int32_t line) {
173 POS_RET_API ret = POS_RET_NORMAL;
176 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Argument ERROR!! fn=%p", fn);
177 ret = POS_RET_ERROR_PARAM;
179 if ((data < min) || (max < data)) {
181 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
182 "%s/%d/Out of range!! data=%d[%d, %d]",
183 fn, line, data, min, max);
192 * Data Valid Value Determination(int16)
194 * @param[in] date int16_t Object data
195 * @param[in] min int16_t Target Data Valid Value Range(Minimum value)
196 * @param[in] max int16_t Target Data Valid Value Range(Maximum value)
197 * @param[in] fn const char* Pointer to the function name
198 * @param[in] line int32_t Number of lines
200 * @return POS_RET_NORMAL Within the valid range<br>
201 * POS_RET_ERROR Out of scope<br>
202 * POS_RET_ERROR_PARAM Argument error
204 inline POS_RET_API PosChkParam16(int16_t data, int16_t min, int16_t max, const char* fn, int32_t line) {
205 POS_RET_API ret = POS_RET_NORMAL;
208 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Argument ERROR!! fn=%p", fn);
209 ret = POS_RET_ERROR_PARAM;
211 if ((data < min) || (max < data)) {
213 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
214 "%s/%d/Out of range!! data=%d[%d, %d]",
215 fn, line, data, min, max);
224 * Data Valid Value Determination(int32)
226 * @param[in] date int32_t Object data
227 * @param[in] min int32_t Target Data Valid Value Range(Minimum value)
228 * @param[in] max int32_t Target Data Valid Value Range(Maximum value)
229 * @param[in] fn const char* Pointer to the function name
230 * @param[in] line int32_t Number of lines
232 * @return POS_RET_NORMAL Within the valid range<br>
233 * POS_RET_ERROR Out of scope<br>
234 * POS_RET_ERROR_PARAM Argument error
236 inline POS_RET_API PosChkParam32(int32_t data, int32_t min, int32_t max, const char* fn, int32_t line) {
237 POS_RET_API ret = POS_RET_NORMAL;
240 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Argument ERROR!! fn=%p", fn);
241 ret = POS_RET_ERROR_PARAM;
243 if ((data < min) || (max < data)) {
245 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
246 "%s/%d/Out of range!! data=%d[%d, %d]",
247 fn, line, data, min, max);
256 * Data Valid Value Determination(unsigned int8)
258 * @param[in] date uint8_t Object data
259 * @param[in] min uint8_t Target Data Valid Value Range(Minimum value)
260 * @param[in] max uint8_t Target Data Valid Value Range(Maximum value)
261 * @param[in] fn const char* Pointer to the function name
262 * @param[in] line int32_t Number of lines
264 * @return POS_RET_NORMAL Within the valid range<br>
265 * POS_RET_ERROR Out of scope<br>
266 * POS_RET_ERROR_PARAM Argument error
268 inline POS_RET_API PosChkParamU8(uint8_t data, uint8_t min, uint8_t max, const char* fn, int32_t line) {
269 POS_RET_API ret = POS_RET_NORMAL;
272 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Argument ERROR!! fn=%p", fn);
273 ret = POS_RET_ERROR_PARAM;
275 if ((data < min) || (max < data)) {
277 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
278 "%s/%d/Out of range!! data=%u[%u, %u]",
279 fn, line, data, min, max);
288 * Data Valid Value Determination(unsigned int16)
290 * @param[in] date uint16_t Object data
291 * @param[in] min uint16_t Target Data Valid Value Range(Minimum value)
292 * @param[in] max uint16_t Target Data Valid Value Range(Maximum value)
293 * @param[in] fn const char* Pointer to the function name
294 * @param[in] line int32_t Number of lines
296 * @return POS_RET_NORMAL Within the valid range<br>
297 * POS_RET_ERROR Out of scope<br>
298 * POS_RET_ERROR_PARAM Argument error
300 inline POS_RET_API PosChkParamU16(uint16_t data, uint16_t min, uint16_t max, const char* fn, int32_t line) {
301 POS_RET_API ret = POS_RET_NORMAL;
304 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Argument ERROR!! fn=%p", fn);
305 ret = POS_RET_ERROR_PARAM;
307 if ((data < min) || (max < data)) {
309 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
310 "%s/%d/Out of range!! data=%u[%u, %u]",
311 fn, line, data, min, max);
320 * Data Valid Value Determination(unsigned int32)
322 * @param[in] date uint32_t Object data
323 * @param[in] min uint32_t Target Data Valid Value Range(Minimum value)
324 * @param[in] max uint32_t Target Data Valid Value Range(Maximum value)
325 * @param[in] fn const char* Pointer to the function name
326 * @param[in] line int32_t Number of lines
328 * @return POS_RET_NORMAL Within the valid range<br>
329 * POS_RET_ERROR Out of scope<br>
330 * POS_RET_ERROR_PARAM Argument error
332 inline POS_RET_API PosChkParamU32(uint32_t data, uint32_t min, uint32_t max, const char* fn, int32_t line) {
333 POS_RET_API ret = POS_RET_NORMAL;
336 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Argument ERROR!! fn=%p", fn);
337 ret = POS_RET_ERROR_PARAM;
339 if ((data < min) || (max < data)) {
341 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
342 "%s/%d/Out of range!! data=%u[%u, %u]",
343 fn, line, data, min, max);
352 * Data setting process(Internal processing)
354 * Set the specified information
356 * @param[in] did DID - Data ID
357 * @param[in] p_data void* - Configuration data
358 * @param[in] size uint16_t - Setting data size
359 * @param[in] is_event uint8_t - Event wait status(TRUE/FALSE)
361 * @return POS_RET_NORMAL Normal completion(Include illegal)<br>
362 * POS_RET_ERROR_PARAM Parameter error<br>
363 * POS_RET_ERROR_INNER Internal error
365 inline POS_RET_API PosSetProc(DID did, void *p_data, uint16_t size, uint8_t is_event) {
366 POS_RET_API ret = POS_RET_NORMAL; /* Return value of this function */
367 RET_API ret_api = RET_NORMAL; /* API return value */
368 POS_MSGINFO snd_msg; /* Message */
369 EventID event_id; /* Event ID */
370 int32_t event_val; /* Event value */
371 PNO pno; /* Calling thread PNO */
372 uint32_t pid; /* Process ID */
373 uint32_t tid; /* Thread ID */
376 /* Data size check */
377 if (POS_MSG_INFO_DSIZE < size) {
378 ret = POS_RET_ERROR_PARAM;
380 /* Resource acquisition */
381 if (VehicleGetResource() == TRUE) {
383 /* _CWORD71_ processing speed(Memset modification) */
384 /* Initialization of areas that do not contain values */
386 snd_msg.rcv_flag = 0;
391 memcpy(snd_msg.data, p_data, size);
393 if (TRUE == is_event) {
394 /* After requesting data setting,Wait for the setting completion(Event Wait) */
396 /* Event Generation */
397 pid = static_cast<uint32_t>(getpid());
400 snprintf(name, sizeof(name), "PS_p%u_t%u", pid, tid);
401 pno = _pb_CnvName2Pno(name);
402 event_id = VehicleCreateEvent(pno);
404 /* Set the source Pno of message data */
408 /* Successful event generation */
410 /* Send NAVI Sensor Data Setting to Vehicle Sensor */
411 ret_api = VehicleSndMsg(pno,
415 (uint16_t)sizeof(POS_MSGINFO) - POS_MSG_INFO_DSIZE + snd_msg.size, /* variable length */
416 (const void *)&snd_msg);
418 if (RET_NORMAL == ret_api) {
419 /* If the data setup process is successful,Wait for a completion event */
420 ret_api = _pb_WaitEvent(event_id,
422 VEHICLE_RET_ERROR_MIN,
423 VEHICLE_RET_NORMAL, &event_val, POS_API_TIME_OUT_MS);
424 if (RET_NORMAL != ret_api) {
425 /* Return an internal error */
426 ret = POS_RET_ERROR_INNER;
428 /* Return from Event Wait */
429 /* Set event value (processing result) as return value */
430 ret = (POS_RET_API)event_val;
433 /* Message transmission processing failed */
434 ret = POS_RET_ERROR_INNER;
437 ret_api = VehicleDeleteEvent(event_id);
439 /* Event generation failure */
440 ret = POS_RET_ERROR_INNER;
443 /* After setting data,Immediate termination */
445 /* Send NAVI Sensor Data Setting to Vehicle Sensor */
446 ret_api = _pb_SndMsg_Ext(POS_THREAD_NAME,
448 sizeof(POS_MSGINFO), reinterpret_cast<void*>(&snd_msg), 0);
449 if (ret_api != RET_NORMAL) {
450 /* Message transmission failure */
451 ret = POS_RET_ERROR_INNER;
455 /* Insufficient resource */
456 ret = POS_RET_ERROR_RESOURCE;
458 /* Resource release */
459 VehicleReleaseResource();
467 * Sensor information acquisition(Internal processing)
469 * @param[in] did DID - Data ID for vehicle information
470 * @param[in] p_data void* - Pointer representing the storage destination of vehicle sensor information
471 * @param[in] dest_size uint16_t - Storage destination size of vehicle sensor information(byte)
473 * @return 0 or more Stored data size(Include illegal)<br>
474 * POS_RET_ERROR_CREATE_EVENT Event generation failure<br>
475 * POS_RET_ERROR_OUTOF_MEMORY Shared memory allocation failed<br>
476 * POS_RET_ERROR_SIZE Storage destination size error<br>
477 * POS_RET_ERROR_DID Unregistered ID<br>
479 inline POS_RET_API PosGetProc(DID did, void *p_data, uint16_t dest_size) {
480 POS_RET_API ret; /* Return value */
481 RET_API ret_api; /* System API return value */
482 EventID event_id; /* Event ID */
483 int32_t event_val; /* Event value */
484 void *share_top; /* Start address of shared memory */
485 uint32_t share_size; /* Size of shared memory area */
486 uint16_t offset; /* Offset to free shared memory area */
487 VEHICLE_SHARE_BLOCK_DAT *share_dat; /* Address of free shared memory area */
488 VEHICLE_MSG_GET_VEHICLE_DATA_DAT data; /* Message data */
489 PNO pno; /* Calling thread PNO */
490 uint32_t pid; /* Process ID */
491 uint32_t tid; /* Thread ID */
494 /* Resource acquisition */
495 if (VehicleGetResource() == TRUE) {
499 memset(reinterpret_cast<void *>(&data), 0, sizeof(VEHICLE_MSG_GET_VEHICLE_DATA_DAT));
501 /* Event Generation */
502 pid = static_cast<uint32_t>(getpid());
505 snprintf(name, sizeof(name), "PG_p%u_t%u", pid, tid);
506 pno = _pb_CnvName2Pno(name);
507 event_id = VehicleCreateEvent(pno);
510 /* Successful event generation */
512 /* Allocate shared memory */
513 ret_api = VehicleLinkShareData(reinterpret_cast<void **>(&share_top), &share_size, &offset);
514 if (RET_NORMAL != ret_api) {
515 /* Failed to allocate shared memory */
516 ret = POS_RET_ERROR_OUTOF_MEMORY;
517 } else { /* When the shared memory is allocated successfully */
518 /* Calculate start address of free shared memory area */
519 share_dat = reinterpret_cast<VEHICLE_SHARE_BLOCK_DAT *>(reinterpret_cast<u_int8 *>(share_top)
522 /* Send vehicle sensor information acquisition message */
525 data.offset = offset;
526 data.size = VEHICLE_SHARE_BLOCK_DSIZE;
529 ret_api = VehicleSndMsg(pno,
531 CID_VEHICLEIF_GET_VEHICLE_DATA,
532 sizeof(VEHICLE_MSG_GET_VEHICLE_DATA_DAT), (const void *)&data);
534 /* Message transmission processing is successful */
535 if (RET_NORMAL == ret_api) {
536 /* Wait for completion event from vehicle sensor thread */
537 ret_api = _pb_WaitEvent(event_id,
539 VEHICLE_RET_ERROR_MIN,
540 VEHICLE_RET_NORMAL, &event_val, POS_API_TIME_OUT_MS);
542 if (RET_NORMAL != ret_api) {
543 /* Return an internal error */
544 ret = POS_RET_ERROR_INNER;
545 } else { /* Return from Event Wait */
546 /* Link to shared memory */
547 ret_api = _pb_LinkShareData(const_cast<char *>(VEHICLE_SHARE_NAME),
548 &share_top, &share_size);
550 /* Calculate the address of the shared memory storage area. */
551 share_dat = reinterpret_cast<VEHICLE_SHARE_BLOCK_DAT *>(reinterpret_cast<u_int8 *>(share_top)
555 /* Vehicle sensor information acquisition failure */
556 ret = (VEHICLE_RET_API)event_val;
557 } else if (RET_NORMAL != ret_api) {
558 /* Shared memory error */
559 ret = POS_RET_ERROR_OUTOF_MEMORY;
560 } else if (dest_size < share_dat->size) {
561 /* Storage destination size error */
562 ret = POS_RET_ERROR_SIZE;
563 } else { /* Vehicle sensor information acquisition success */
564 /* Copy from shared memory to user memory */
565 memcpy(p_data, share_dat->data, (size_t)share_dat->size);
567 /* Set Write Size to Return Value */
568 ret = static_cast<int32>(share_dat->size);
571 } else { /* Message transmission processing failed */
572 /* Return an event generation failure */
573 ret = POS_RET_ERROR_CREATE_EVENT;
575 /* Free shared memory */
576 (void)VehicleUnLinkShareData(reinterpret_cast<VEHICLE_SHARE*>(share_top), offset);
579 ret_api = VehicleDeleteEvent(event_id);
581 /* Event generation failure */
582 ret = POS_RET_ERROR_CREATE_EVENT;
585 /* Insufficient resource */
586 ret = POS_RET_ERROR_RESOURCE;
588 /* Resource release */
589 VehicleReleaseResource();
596 * Delivery registration process(Internal processing)
598 * @param[in] notify_name Destination thread name
599 * @param[in] did Pointer to an array of data IDs for vehicle information
600 * @param[in] ctrl_flg Delivery control<br>
601 * Delivery registration: SENSOR_DELIVERY_REGIST<br>
602 * Delivery stop: SENSOR_DELIVERY_STOP (Note: Not mounted)<br>
603 * Resume delivery: SENSOR_DELIVERY_RESTART (Note: Not mounted)
604 * @param[in] delivery_timing Delivery timing<br>
605 * Updating : SENSOR_DELIVERY_TIMING_UPDATE<br>
606 * Changing : SENSOR_DELIVERY_TIMING_CHANGE
608 * @return SENSOR_RET_NORMAL Successful registration<br>
609 * SENSOR_RET_ERROR_CREATE_EVENT Event generation failure<br>
610 * SENSOR_RET_ERROR_PARAM Parameter error<br>
611 * SENSOR_RET_ERROR_DID Unregistered ID<br>
612 * SENSOR_RET_ERROR_BUFFULL FULL of delivery registers<br>
613 * SENSOR_RET_ERROR_INNER Internal abnormality<br>
615 inline SENSOR_RET_API PosRegisterListenerProc(PCSTR notify_name, DID did, u_int8 ctrl_flg, u_int8 delivery_timing) {
616 SENSOR_RET_API ret; /* Return value */
617 RET_API ret_api; /* System API return value */
618 EventID event_id; /* Event ID */
619 int32 event_val; /* Event value */
620 VEHICLE_MSG_DELIVERY_ENTRY_DAT data; /* Message data */
621 PNO pno; /* Converted internal PNO */
623 /* Resource acquisition */
624 if (VehicleGetResource() == TRUE) {
629 /* Get PNO from Thread Name */
630 pno = _pb_CnvName2Pno(notify_name);
632 /* Event Generation */
633 event_id = VehicleCreateEvent(pno);
636 /* Successful event generation */
638 /*--------------------------------------------------------------*
639 * Send Vehicle Sensor Information Delivery Registration Message *
640 *--------------------------------------------------------------*/
641 /* Create Message Data */
644 data.delivery_timing = delivery_timing;
645 data.ctrl_flg = ctrl_flg;
646 data.event_id = event_id;
649 ret_api = VehicleSndMsg(pno,
651 CID_VEHICLEIF_DELIVERY_ENTRY,
652 (uint16_t)sizeof(VEHICLE_MSG_DELIVERY_ENTRY_DAT), (const void *)&data);
654 if (RET_NORMAL == ret_api) {
655 /* Message transmission processing is successful */
656 /* Wait for completion event from vehicle sensor thread */
657 ret_api = _pb_WaitEvent(event_id,
659 VEHICLE_RET_ERROR_MIN,
660 VEHICLE_RET_NORMAL, &event_val, POS_API_TIME_OUT_MS);
661 if (RET_NORMAL != ret_api) {
662 /* Return an internal error */
663 ret = SENSOR_RET_ERROR_INNER;
665 /* Return from Event Wait */
666 /* Set event value (processing result) as return value */
667 ret = (SENSOR_RET_API)event_val;
670 /* Message transmission processing failed */
671 /* Return an internal error */
672 ret = SENSOR_RET_ERROR_INNER;
675 ret_api = VehicleDeleteEvent(event_id);
677 /* Event generation failure */
678 ret = SENSOR_RET_ERROR_CREATE_EVENT;
681 /* Insufficient resource */
682 ret = SENSOR_RET_ERROR_RESOURCE;
684 /* Resource release */
685 VehicleReleaseResource();
690 /*******************************************************************************
691 * MODULE : VehicleCreateEvent
692 * ABSTRACT : Event creation process
693 * FUNCTION : Generate an event
694 * ARGUMENT : pno : Thread ID
696 * RETURN : Non-zero : Event ID
697 * : Zero : Event generation failure
698 ******************************************************************************/
699 inline EventID VehicleCreateEvent(PNO pno) {
700 EventID event_id; /* Event ID */
701 char event_name[32]; /* Event name character string buffer */
702 RET_API ret_api; /* System API return value */
705 /* Initialization of event name character string buffer */
706 memset(reinterpret_cast<void *>(event_name), 0, sizeof(event_name));
707 /* Event name creation */
708 snprintf(event_name, sizeof(event_name), "VEHICLE_%X", pno);
710 /* Event Generation */
711 event_id = _pb_CreateEvent(FALSE, 0, event_name);
714 /* For successful event generation */
716 /* Initialize the event */
717 ret_api = _pb_SetEvent(event_id, SAPI_EVSET_ABSOLUTE, VEHICLE_EVENT_VAL_INIT);
718 if (RET_NORMAL != ret_api) {
719 /* Event initialization failed */
720 /* Delete Event and Return Event Generation Failed */
721 ret_api = VehicleDeleteEvent(event_id);
729 /*******************************************************************************
730 * MODULE : VehicleDeleteEvent
731 * ABSTRACT : Event deletion processing
732 * FUNCTION : Delete events
733 * ARGUMENT : event_id : Event ID of the event to delete
735 * RETURN : RET_NORMAL : Normal completion
736 * : RET_EV_NONE : Specified event does not exist
737 ******************************************************************************/
738 inline RET_API VehicleDeleteEvent(EventID event_id) {
739 return(_pb_DeleteEvent(event_id));
742 /*******************************************************************************
743 * MODULE : VehicleLinkShareData
744 * ABSTRACT : Link to shared memory
745 * FUNCTION : Link to shared memory
746 * ARGUMENT : **share_top : Storage destination of shared memory top address
747 * : *share_size : Storage destination of shared memory area size
748 * : *offset : Offset storage destination to free shared memory area
750 * RETURN : RET_NORMAL : Normal completion
751 * : RET_ERROR : There is no shared memory area.
752 ******************************************************************************/
753 inline RET_API VehicleLinkShareData(void **share_top, uint32_t *share_size, uint16_t *offset) {
754 RET_API ret_api; /* System API return value */
755 SemID sem_id; /* Semaphore ID */
756 VEHICLE_SHARE *share_top_tmp;
762 /* Create Semaphore */
763 sem_id = _pb_CreateSemaphore(const_cast<char *>(VEHICLE_SEMAPHO_NAME));
766 ret_api = _pb_SemLock(sem_id);
767 if (RET_NORMAL == ret_api) {
768 /* Link to shared memory */
769 ret_api = _pb_LinkShareData(const_cast<char *>(VEHICLE_SHARE_NAME), share_top, share_size);
770 if (RET_NORMAL == ret_api) {
771 /* By searching the free shared memory area,Offset is calculated if there is free space. */
772 share_top_tmp = reinterpret_cast<VEHICLE_SHARE *>(*share_top);
774 /* Because the first block of the shared memory area is the control area,Loop from i = 1 */
775 for (i = 1; i < VEHICLE_SHARE_BLOCK_NUM; i++) {
776 if (VEHICLE_SHARE_UNLOCK == share_top_tmp->mng.lock_info[i]) {
780 if (i < VEHICLE_SHARE_BLOCK_NUM) {
783 share_top_tmp->mng.lock_info[i] = VEHICLE_SHARE_LOCK;
785 /* Calculate the offset to the block */
786 *offset = static_cast<u_int16>(i * VEHICLE_SHARE_BLOCK_SIZE);
788 /* Normal completion */
789 ret_api = RET_NORMAL;
795 /* Failed link to shared memory */
798 /* Semaphore unlock */
799 _pb_SemUnlock(sem_id);
801 /* Semaphore lock failed */
805 /* Semaphore creation failed */
812 /*******************************************************************************
813 * MODULE : VehicleUnLinkShareData
814 * ABSTRACT : Unlinking shared memory
815 * FUNCTION : Unlink shared memory
816 * ARGUMENT : *share_top : Start address of shared memory
817 * : offset : Offset to shared memory free area
819 * RETURN : RET_NORMAL : Normal completion
820 * : RET_ERROR : There is no shared memory area./semaphore error
821 ******************************************************************************/
822 inline RET_API VehicleUnLinkShareData(VEHICLE_SHARE *share_top, uint16_t offset) {
823 RET_API ret_api; /* System API return value */
824 SemID sem_id; /* Semaphore ID */
830 /* Create Semaphore */
831 sem_id = _pb_CreateSemaphore(const_cast<char *>(VEHICLE_SEMAPHO_NAME));
834 ret_api = _pb_SemLock(sem_id);
835 if (RET_NORMAL == ret_api) {
836 /* Unlock the block */
837 i = static_cast<int32>(offset) / VEHICLE_SHARE_BLOCK_SIZE;
838 share_top->mng.lock_info[i] = VEHICLE_SHARE_UNLOCK;
840 /* Semaphore unlock */
841 _pb_SemUnlock(sem_id);
843 /* Normal completion */
844 ret_api = RET_NORMAL;
846 /* Semaphore lock failed */
850 /* Semaphore creation failed */
857 /*******************************************************************************
858 * MODULE : VehicleSndMsg
859 * ABSTRACT : Message transmission processing
860 * FUNCTION : Send a message to the specified PNO
861 * ARGUMENT : pno_src : Source PNO
862 * : pno_dest : Destination PNO
864 * : msg_len : Message data body length
865 * : *msg_data : Pointer to message data
867 * RETURN : RET_NORMAL : Normal completion
868 * : RET_ERRNOTRDY : Destination process is not wakeup
869 * : RET_ERRMSGFULL : Message queue overflows
870 * : RET_ERRPARAM : Buffer size error
871 ******************************************************************************/
872 inline RET_API VehicleSndMsg(PNO pno_src, PNO pno_dest, CID cid, uint16_t msg_len, const void *msg_data) {
873 VEHICLE_MSG_BUF msg_buf; /* message buffer */
874 T_APIMSG_MSGBUF_HEADER *msg_hdr; /* Pointer to the message header */
875 RET_API ret_api; /* Return value */
876 PCSTR thread_name; /* Destination thread name */
879 /* Internal debug log output */
880 FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__,
881 "+ [pno_src = 0x%x, pno_dest = 0x%x]", pno_src, pno_dest);
883 /* _CWORD71_ processing speed(Memset modification) */
884 /* Initializing the header of the message buffer */
885 memset(reinterpret_cast<void *>(&msg_buf.hdr), 0, sizeof(T_APIMSG_MSGBUF_HEADER));
887 /* Get pointer to send buffer */
888 msg_hdr = reinterpret_cast<T_APIMSG_MSGBUF_HEADER *>(reinterpret_cast<void *>(&msg_buf));
890 /*--------------------------------------------------------------*
891 * Create message headers *
892 *--------------------------------------------------------------*/
893 msg_hdr->hdr.sndpno = pno_src; /* Source PNO */
894 msg_hdr->hdr.cid = cid; /* Command ID */
895 msg_hdr->hdr.msgbodysize = msg_len; /* Message data body length */
897 /*--------------------------------------------------------------*
898 * Create message data *
899 *--------------------------------------------------------------*/
900 if ((0 != msg_data) && (0 != msg_len)) {
901 /* Set the message data */
902 memcpy(reinterpret_cast<void *>(msg_buf.data), msg_data, (size_t)msg_len);
904 /*--------------------------------------------------------------*
906 *--------------------------------------------------------------*/
907 /* Get Thread Name from PNO */
908 if (pno_dest <= SYS_PNO_MAX) {
909 thread_name = POS_THREAD_NAME;
911 thread_name = _pb_CnvPno2Name(pno_dest);
914 if ((pno_dest <= SYS_PNO_MAX) && (pno_src <= SYS_PNO_MAX)) {
915 /* Internal debug log output */
916 FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "[LOG pno_dest = 0x%x]", pno_dest);
918 /* Internal Process Transmission and Reception Messages */
919 ret_api = _pb_SndMsg(pno_dest,
920 (uint16_t)(sizeof(T_APIMSG_MSGBUF_HEADER) + msg_len),
921 reinterpret_cast<void *>(&msg_buf), 0);
923 /* External Process Transmission and Reception Messages */
924 ret_api = _pb_SndMsg_Ext(thread_name,
926 (uint16_t)(msg_len), /* Ignore->MISRA-C++:2008 Rule 5-0-5 */
927 reinterpret_cast<void *>(&(msg_buf.data)), 0);
929 FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "-");
936 * Resource Acquisition Decision
940 * @return TRUE Normal<br>
941 * FALSE Abnormality(Insufficient resource)
943 inline BOOL VehicleGetResource(void) {
944 BOOL ret[4] = {TRUE, TRUE, TRUE, TRUE};
947 ret[1] = _pb_GetMsgResource();
948 ret[2] = _pb_GetMutexResource();
949 ret[3] = _pb_GetOtherResource();
951 for (idx = 1; idx < 4; idx++) {
952 if (ret[idx] == FALSE) {
968 inline void VehicleReleaseResource(void) {
969 _pb_ReleaseMsgResource();
970 _pb_ReleaseMutexResource();
971 _pb_ReleaseOtherResource();
976 inline uint32_t GetTid(void) {
977 return (uint32_t)syscall(__NR_gettid);
981 #endif // POSITIONING_CLIENT_INCLUDE_POS_PRIVATE_H_