diff options
Diffstat (limited to 'vehicleservice/positioning/client/src')
11 files changed, 3074 insertions, 0 deletions
diff --git a/vehicleservice/positioning/client/src/POS_common_API/Common_API.cpp b/vehicleservice/positioning/client/src/POS_common_API/Common_API.cpp new file mode 100755 index 0000000..f266dec --- /dev/null +++ b/vehicleservice/positioning/client/src/POS_common_API/Common_API.cpp @@ -0,0 +1,889 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Common_API.cpp + * @brief + * Module : POSITIONING + * Common I/F service functionality + */ +#include <vehicle_service/positioning_base_library.h> +#include <vehicle_service/POS_define.h> +#include <vehicle_service/POS_common_API.h> +#include "POS_common_private.h" +#include "Vehicle_API_private.h" +#include "POS_private.h" + +/** + * @brief + * Latitude and longitude informationDelivery registration + * + * Registering Latitude and Longitude Information Delivery + * + * @param[in] hApp HANDLE - Application handle + * @param[in] notifyName PCSTR - Destination thread name + * @param[in] ucCtrlFlg uint8_t - Delivery control(Delivery registration/Delivery stop/Resume delivery) + * @param[in] ucDeliveryTiming uint8_t - Delivery timing(Changing/Updating) + * @param[in] ucGetMethod uint8_t - Acquisition method(GPS/Navigation/Not specified) + * + * @return POS_RET_NORMAL Normal completion(Include illegal)<br> + * POS_RET_ERROR_BUFFULL Buffer-full<br> + * POS_RET_ERROR_INNER Internal error<br> + * POS_RET_ERROR_PARAM Parameter error<br> + * POS_RET_ERROR_NOSUPPORT Unsupported environment + * + */ +POS_RET_API POS_RegisterListenerLonLat(HANDLE hApp, // NOLINT(readability/nolint) + PCSTR notifyName, // NOLINT(readability/nolint) + uint8_t ucCtrlFlg, // NOLINT(readability/nolint) + uint8_t ucDeliveryTiming, // NOLINT(readability/nolint) + uint8_t ucGetMethod) { // NOLINT(readability/nolint) + POS_RET_API ret = POS_RET_NORMAL; /* Return value of this function */ + SENSOR_RET_API ret_sens = SENSOR_RET_NORMAL; /* API return value */ + UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */ + DID did = VEHICLE_DID_LOCATION_LONLAT; /* Data ID */ + + /* Internal debug log output */ + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+"); + + /* Arguments & Support Configuration Check */ + if ((ucDeliveryTiming != SENSOR_DELIVERY_TIMING_CHANGE) && + (ucDeliveryTiming != SENSOR_DELIVERY_TIMING_UPDATE)) { + /* Change delivery timing,Terminate as a parameter error except update */ + ret = POS_RET_ERROR_PARAM; + } else if (ucCtrlFlg != SENSOR_DELIVERY_REGIST) { + /* Parameters other than delivery registration are terminated abnormally when delivery control is terminated. */ + ret = POS_RET_ERROR_PARAM; + } else if (hApp == NULL) { + /* If the handler is NULL, the process terminates with an error. */ + ret = POS_RET_ERROR_PARAM; + } else if (notifyName == NULL) { + /* If the thread name is NULL, it terminates with an abnormal parameter. */ + ret = POS_RET_ERROR_PARAM; + } else { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Supported HW Configuration Check */ + type = GetEnvSupportInfo(); + + if (UNIT_TYPE_GRADE1 == type) { + /* GRADE1 */ + ret = POS_RET_NORMAL; + if (ucGetMethod == SENSOR_GET_METHOD_GPS) { + did = VEHICLE_DID_LOCATION_LONLAT; + } else if ((ucGetMethod == SENSOR_GET_METHOD_NAVI) || + (ucGetMethod == SENSOR_GET_METHOD_AUTO)) { + did = VEHICLE_DID_LOCATION_LONLAT_NAVI; + } else { + /* End as a parameter error abnormality except for GPS/unspecified acquisition method */ + ret = POS_RET_ERROR_PARAM; + } + } else if (UNIT_TYPE_GRADE2 == type) { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = POS_RET_ERROR_NOSUPPORT; + } else { + /* Environment error */ + ret = POS_RET_ERROR_NOSUPPORT; + } + } + + /* Delivery registration */ + if (ret == POS_RET_NORMAL) { + /* Delivery registry SensorAPI calls */ + ret_sens = PosRegisterListenerProc(notifyName, /* Destination thread name */ + did, /* Data ID */ + ucCtrlFlg, /* Delivery control */ + ucDeliveryTiming); /* Delivery timing */ + + /* Decision of delivery registration result */ + if (ret_sens == SENSOR_RET_NORMAL) { + ret = POS_RET_NORMAL; + } else if (ret_sens == SENSOR_RET_ERROR_PARAM) { + ret = POS_RET_ERROR_PARAM; + } else if (ret_sens == SENSOR_RET_ERROR_BUFFULL) { + ret = POS_RET_ERROR_BUFFULL; + } else if (ret_sens == SENSOR_RET_ERROR_RESOURCE) { + ret = POS_RET_ERROR_RESOURCE; + } else { + ret = POS_RET_ERROR_INNER; + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "- [ret = %d]", ret); + return ret; +} + +/** + * @brief + * Altitude information delivery registration + * + * Register for the delivery of altitude information + * + * @param[in] hApp HANDLE - Application handle + * @param[in] notifyName PCSTR - Destination thread name + * @param[in] ucCtrlFlg uint8_t - Delivery control(Delivery registration/Delivery stop/Resume delivery) + * @param[in] ucDeliveryTiming uint8_t - Delivery timing(Changing/Updating) + * @param[in] ucGetMethod uint8_t - Acquisition method(GPS/Navigation/Not specified) + * + * @return POS_RET_NORMAL Normal completion(Include illegal)<br> + * POS_RET_ERROR_PARAM Parameter error<br> + * POS_RET_ERROR_NOSUPPORT Unsupported environment + * + */ +POS_RET_API POS_RegisterListenerAltitude(HANDLE hApp, // NOLINT(readability/nolint) + PCSTR notifyName, // NOLINT(readability/nolint) + uint8_t ucCtrlFlg, // NOLINT(readability/nolint) + uint8_t ucDeliveryTiming, // NOLINT(readability/nolint) + uint8_t ucGetMethod) { // NOLINT(readability/nolint) + POS_RET_API ret = POS_RET_NORMAL; /* Return value */ + SENSOR_RET_API ret_sens = SENSOR_RET_NORMAL; /* API return value */ + UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */ + DID did = VEHICLE_DID_LOCATION_ALTITUDE; /* Data ID */ + + /* Internal debug log output */ + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+"); + + /* Arguments & Support Configuration Check */ + if ((ucDeliveryTiming != SENSOR_DELIVERY_TIMING_CHANGE) && + (ucDeliveryTiming != SENSOR_DELIVERY_TIMING_UPDATE)) { + /* Change delivery timing,Terminate as a parameter error except update */ + ret = POS_RET_ERROR_PARAM; + } else if (ucCtrlFlg != SENSOR_DELIVERY_REGIST) { + /* Parameters other than delivery registration are terminated abnormally when delivery control is terminated. */ + ret = POS_RET_ERROR_PARAM; + } else if (hApp == NULL) { + /* If the handler is NULL, the process terminates with an error. */ + ret = POS_RET_ERROR_PARAM; + } else if (notifyName == NULL) { + /* If the thread name is NULL, it terminates with an abnormal parameter. */ + ret = POS_RET_ERROR_PARAM; + } else { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Supported HW Configuration Check */ + type = GetEnvSupportInfo(); + if (UNIT_TYPE_GRADE1 == type) { + /* GRADE1 */ + ret = POS_RET_NORMAL; + if ((ucGetMethod == SENSOR_GET_METHOD_GPS) || + (ucGetMethod == SENSOR_GET_METHOD_AUTO)) { + did = VEHICLE_DID_LOCATION_ALTITUDE; + } else { + /* End as a parameter error abnormality except for GPS/unspecified acquisition method */ + ret = POS_RET_ERROR_PARAM; + } + } else if (UNIT_TYPE_GRADE2 == type) { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = SENSOR_RET_ERROR_NOSUPPORT; + } else { + /* Environment error */ + ret = SENSOR_RET_ERROR_NOSUPPORT; + } + } + + /* Delivery registration */ + if (ret == POS_RET_NORMAL) { + /* Delivery registry SensorAPI calls */ + ret_sens = PosRegisterListenerProc(notifyName, /* Destination thread name */ + did, /* Data ID */ + ucCtrlFlg, /* Delivery control */ + ucDeliveryTiming); /* Delivery timing */ + + /* Decision of delivery registration result */ + if (ret_sens == SENSOR_RET_NORMAL) { + ret = POS_RET_NORMAL; + } else if (ret_sens == SENSOR_RET_ERROR_PARAM) { + ret = POS_RET_ERROR_PARAM; + } else if (ret_sens == SENSOR_RET_ERROR_BUFFULL) { + ret = POS_RET_ERROR_BUFFULL; + } else if (ret_sens == SENSOR_RET_ERROR_RESOURCE) { + ret = POS_RET_ERROR_RESOURCE; + } else { + ret = POS_RET_ERROR_INNER; + } + } + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "- [ret = %d]", ret); + return ret; +} + +/** + * @brief + * Vehicle Speed Information Transmission Registration + * + * Register delivery of vehicle speed information + * + * @param[in] hApp HANDLE - Application handle + * @param[in] notifyName PCSTR - Destination thread name + * @param[in] ucCtrlFlg uint8_t - Delivery control(Delivery registration/Delivery stop/Resume delivery) + * @param[in] ucDeliveryTiming uint8_t - Delivery timing(Changing/Updating) + * @param[in] ucGetMethod uint8_t - Acquisition method(POS/Navigation/Not specified) + * + * @return POS_RET_NORMAL Normal completion(Include illegal)<br> + * POS_RET_ERROR_BUFFULL Buffer-full<br> + * POS_RET_ERROR_INNER Internal error<br> + * POS_RET_ERROR_PARAM Parameter error<br> + * POS_RET_ERROR_NOSUPPORT Unsupported environment + * + */ +POS_RET_API POS_RegisterListenerSpeed(HANDLE hApp, // NOLINT(readability/nolint) + PCSTR notifyName, // NOLINT(readability/nolint) + uint8_t ucCtrlFlg, // NOLINT(readability/nolint) + uint8_t ucDeliveryTiming, // NOLINT(readability/nolint) + uint8_t ucGetMethod) { // NOLINT(readability/nolint) + POS_RET_API ret = POS_RET_NORMAL; /* Return value of this function */ + SENSOR_RET_API ret_sens = SENSOR_RET_NORMAL; /* API return value */ + UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */ + DID did; /* Data ID */ + + /* Internal debug log output */ + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+"); + + /* Arguments & Support Configuration Check */ + if ((ucDeliveryTiming != SENSOR_DELIVERY_TIMING_CHANGE) && + (ucDeliveryTiming != SENSOR_DELIVERY_TIMING_UPDATE)) { + /* Change delivery timing,Terminate as a parameter error except update */ + ret = POS_RET_ERROR_PARAM; + } else if (ucCtrlFlg != SENSOR_DELIVERY_REGIST) { + /* Parameters other than delivery registration are terminated abnormally when delivery control is terminated. */ + ret = POS_RET_ERROR_PARAM; + } else if (hApp == NULL) { + /* If the handler is NULL, the process terminates with an error. */ + ret = POS_RET_ERROR_PARAM; + } else if (notifyName == NULL) { + /* If the thread name is NULL, it terminates with an abnormal parameter. */ + ret = POS_RET_ERROR_PARAM; + } else { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Supported HW Configuration Check */ + type = GetEnvSupportInfo(); + if (UNIT_TYPE_GRADE1 == type) { + /* GRADE1 */ + ret = POS_RET_NORMAL; + if (ucGetMethod == SENSOR_GET_METHOD_POS) { + did = VEHICLE_DID_MOTION_SPEED_INTERNAL; + } else if ((ucGetMethod == SENSOR_GET_METHOD_NAVI) || + (ucGetMethod == SENSOR_GET_METHOD_AUTO)) { + did = VEHICLE_DID_MOTION_SPEED_NAVI; + } else { + ret = POS_RET_ERROR_PARAM; + } + } else if (UNIT_TYPE_GRADE2 == type) { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = POS_RET_ERROR_NOSUPPORT; + } else { + /* Environment error */ + ret = POS_RET_ERROR_NOSUPPORT; + } + } + + /* Delivery registration */ + if (ret == POS_RET_NORMAL) { + /* Delivery registry SensorAPI calls */ + ret_sens = PosRegisterListenerProc(notifyName, /* Destination thread name */ + did, /* Data ID */ + ucCtrlFlg, /* Delivery control */ + ucDeliveryTiming); /* Delivery timing */ + + /* Decision of delivery registration result */ + if (ret_sens == SENSOR_RET_NORMAL) { + ret = POS_RET_NORMAL; + } else if (ret_sens == SENSOR_RET_ERROR_PARAM) { + ret = POS_RET_ERROR_PARAM; + } else if (ret_sens == SENSOR_RET_ERROR_BUFFULL) { + ret = POS_RET_ERROR_BUFFULL; + } else if (ret_sens == SENSOR_RET_ERROR_RESOURCE) { + ret = POS_RET_ERROR_RESOURCE; + } else { + ret = POS_RET_ERROR_INNER; + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "- [ret = %d]", ret); + return ret; +} + +/** + * @brief + * Compass Information Transmission Register + * + * Register the delivery of the vehicle orientation information + * + * @param[in] hApp HANDLE - Application handle + * @param[in] notifyName PCSTR - Destination thread name + * @param[in] ucCtrlFlg uint8_t - Delivery control(Delivery registration/Delivery stop/Resume delivery) + * @param[in] ucDeliveryTiming uint8_t - Delivery timing(Changing/Updating) + * @param[in] ucGetMethod uint8_t - Acquisition method(GPS/Navigation/Not specified) + * + * @return POS_RET_NORMAL Normal completion(Include illegal)<br> + * POS_RET_ERROR_PARAM Parameter error<br> + * POS_RET_ERROR_NOSUPPORT Unsupported environment + * + */ +POS_RET_API POS_RegisterListenerHeading(HANDLE hApp, // NOLINT(readability/nolint) + PCSTR notifyName, // NOLINT(readability/nolint) + uint8_t ucCtrlFlg, // NOLINT(readability/nolint) + uint8_t ucDeliveryTiming, // NOLINT(readability/nolint) + uint8_t ucGetMethod) { // NOLINT(readability/nolint) + POS_RET_API ret = POS_RET_NORMAL; /* Return value */ + SENSOR_RET_API ret_sens = SENSOR_RET_NORMAL; /* API return value */ + UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */ + DID did = VEHICLE_DID_MOTION_HEADING; /* TODO VEHICLE_DID_LOCATION_HEADING Missing */ + /* Data ID */ + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+"); + + /* Arguments & Support Configuration Check */ + if ((ucDeliveryTiming != SENSOR_DELIVERY_TIMING_CHANGE) && + (ucDeliveryTiming != SENSOR_DELIVERY_TIMING_UPDATE)) { + /* Change delivery timing,Terminate as a parameter error except update */ + ret = POS_RET_ERROR_PARAM; + } else if (ucCtrlFlg != SENSOR_DELIVERY_REGIST) { + /* Parameters other than delivery registration are terminated abnormally when delivery control is terminated. */ + ret = POS_RET_ERROR_PARAM; + } else if (hApp == NULL) { + /* If the handler is NULL, the process terminates with an error. */ + ret = POS_RET_ERROR_PARAM; + } else if (notifyName == NULL) { + /* If the thread name is NULL, it terminates with an abnormal parameter. */ + ret = POS_RET_ERROR_PARAM; + } else { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Supported HW Configuration Check */ + type = GetEnvSupportInfo(); + if (UNIT_TYPE_GRADE1 == type) { + /* GRADE1 */ + ret = POS_RET_NORMAL; + if (ucGetMethod == SENSOR_GET_METHOD_GPS) { + did = VEHICLE_DID_MOTION_HEADING; + } else if ((ucGetMethod == SENSOR_GET_METHOD_NAVI) || + (ucGetMethod == SENSOR_GET_METHOD_AUTO)) { + did = VEHICLE_DID_MOTION_HEADING_NAVI; + } else { + /* End as a parameter error abnormality except for GPS/unspecified acquisition method */ + ret = POS_RET_ERROR_PARAM; + } + } else if (UNIT_TYPE_GRADE2 == type) { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = SENSOR_RET_ERROR_NOSUPPORT; + } else { + /* Environment error */ + ret = SENSOR_RET_ERROR_NOSUPPORT; + } + } + + /* Delivery registration */ + if (ret == POS_RET_NORMAL) { + /* Delivery registry SensorAPI calls */ + ret_sens = PosRegisterListenerProc(notifyName, /* Destination thread name */ + did, /* Data ID */ + ucCtrlFlg, /* Delivery control */ + ucDeliveryTiming); /* Delivery timing */ + + /* Decision of delivery registration result */ + if (ret_sens == SENSOR_RET_NORMAL) { + ret = POS_RET_NORMAL; + } else if (ret_sens == SENSOR_RET_ERROR_PARAM) { + ret = POS_RET_ERROR_PARAM; + } else if (ret_sens == SENSOR_RET_ERROR_BUFFULL) { + ret = POS_RET_ERROR_BUFFULL; + } else if (ret_sens == SENSOR_RET_ERROR_RESOURCE) { + ret = POS_RET_ERROR_RESOURCE; + } else { + ret = POS_RET_ERROR_INNER; + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "- [ret = %d]", ret); + return ret; +} + +/** + * @brief + * Get Lltitude and longitude information + * + * Get Lltitude and longitude information + * + * @param[in] hApp HANDLE - Application handle + * @param[in] dat SENSORLOCATION_LONLATINFO_DAT* - Pointer to the acquired latitude/longitude information storage destination + * @param[in] ucGetMethod uint8_t - Acquisition method(GPS/Navigation/Not specified) + * + * @return POS_RET_NORMAL Normal completion(Include illegal)<br> + * POS_RET_ERROR_PARAM Parameter error<br> + * POS_RET_ERROR_NOSUPPORT Unsupported environment<br> + * POS_RET_ERROR_INNER Internal error + * + */ +POS_RET_API POS_GetLonLat(HANDLE hApp, // NOLINT(readability/nolint) + SENSORLOCATION_LONLATINFO_DAT *dat, // NOLINT(readability/nolint) + uint8_t ucGetMethod) { // NOLINT(readability/nolint) + POS_RET_API ret = POS_RET_NORMAL; /* Return value */ + UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */ + DID did = VEHICLE_DID_LOCATION_LONLAT; /* DID */ + int32_t ret_get_proc; /* POS_GetProc Return Values */ + + /* Internal debug log output */ + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "+"); + + /* Arguments & Support Configuration Check */ + if (hApp == NULL) { + /* If the handler is NULL, the process terminates with an error. */ + ret = POS_RET_ERROR_PARAM; + } else if (dat == NULL) { + /* If the longitude/latitude data is NULL, it ends with an abnormal parameter. */ + ret = POS_RET_ERROR_PARAM; + } else { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Supported HW Configuration Check */ + type = GetEnvSupportInfo(); + if (UNIT_TYPE_GRADE1 == type) { + /* GRADE1 */ + if (ucGetMethod == SENSOR_GET_METHOD_GPS) { + did = VEHICLE_DID_LOCATION_LONLAT; + } else if ((ucGetMethod == SENSOR_GET_METHOD_NAVI) || + (ucGetMethod == SENSOR_GET_METHOD_AUTO)) { + did = VEHICLE_DID_LOCATION_LONLAT_NAVI; + } else { + /* End as a parameter error abnormality except for GPS/unspecified acquisition method */ + ret = POS_RET_ERROR_PARAM; + } + } else if (UNIT_TYPE_GRADE2 == type) { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = POS_RET_ERROR_NOSUPPORT; + } else { + /* Environment error */ + ret = POS_RET_ERROR_NOSUPPORT; + } + } + + /* Sensor information acquisition */ + if (ret == POS_RET_NORMAL) { + /* Data acquisition process */ + ret_get_proc = PosGetProc(did, reinterpret_cast<void *>(dat), sizeof(SENSORLOCATION_LONLATINFO_DAT)); + if (static_cast<int32_t>(sizeof(SENSORLOCATION_LONLATINFO_DAT)) > ret_get_proc) { + /* Failed to acquire */ + if (ret_get_proc == POS_RET_ERROR_RESOURCE) { + /* Insufficient resource */ + ret = POS_RET_ERROR_RESOURCE; + } else { + ret = POS_RET_ERROR_INNER; + } + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PosGetProc ERROR [ret = %d]", ret); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "- [ret = %d]", ret); + return ret; +} + +/** + * @brief + * Altitude information acquisition + * + * Obtain altitude information + * + * @param[in] hApp HANDLE - Application handle + * @param[in] dat SENSORLOCATION_ALTITUDEINFO_DAT* - Pointer to the acquired altitude information storage destination + * @param[in] ucGetMethod uint8_t - Acquisition method(GPS/Not specified) + * + * @return POS_RET_NORMAL Normal completion(Include illegal)<br> + * POS_RET_ERROR_PARAM Parameter error<br> + * POS_RET_ERROR_NOSUPPORT Unsupported environment<br> + * POS_RET_ERROR_INNER Internal error + * + */ +POS_RET_API POS_GetAltitude(HANDLE hApp, // NOLINT(readability/nolint) + SENSORLOCATION_ALTITUDEINFO_DAT *dat, // NOLINT(readability/nolint) + uint8_t ucGetMethod) { // NOLINT(readability/nolint) + POS_RET_API ret = POS_RET_NORMAL; /* Return value */ + UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */ + DID did = VEHICLE_DID_LOCATION_ALTITUDE; /* DID */ + int32_t ret_get_proc; /* POS_GetProc Return Values */ + + /* Internal debug log output */ + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "+"); + + /* Arguments & Support Configuration Check */ + if (hApp == NULL) { + /* If the handler is NULL, the process terminates with an error. */ + ret = POS_RET_ERROR_PARAM; + } else if (dat == NULL) { + /* If the altitude data is NULL, it terminates with an abnormal parameter. */ + ret = POS_RET_ERROR_PARAM; + } else { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Supported HW Configuration Check */ + type = GetEnvSupportInfo(); + if (UNIT_TYPE_GRADE1 == type) { + /* GRADE1 */ + if ((ucGetMethod == SENSOR_GET_METHOD_GPS) || + (ucGetMethod == SENSOR_GET_METHOD_AUTO)) { + did = VEHICLE_DID_LOCATION_ALTITUDE; + } else { + /* End as a parameter error abnormality except for GPS/unspecified acquisition method */ + ret = POS_RET_ERROR_PARAM; + } + } else if (UNIT_TYPE_GRADE2 == type) { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = POS_RET_ERROR_NOSUPPORT; + } else { + /* Environment error */ + ret = POS_RET_ERROR_NOSUPPORT; + } + } + /* Sensor information acquisition */ + if (ret == POS_RET_NORMAL) { + /* Data acquisition process */ + ret_get_proc = PosGetProc(did, reinterpret_cast<void *>(dat), sizeof(SENSORLOCATION_ALTITUDEINFO_DAT)); + if (static_cast<int32_t>(sizeof(SENSORLOCATION_ALTITUDEINFO_DAT)) > ret_get_proc) { + /* Failed to acquire */ + if (ret_get_proc == POS_RET_ERROR_RESOURCE) { + /* Insufficient resource */ + ret = POS_RET_ERROR_RESOURCE; + } else { + ret = POS_RET_ERROR_INNER; + } + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PosGetProc ERROR [ret = %d]", ret); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "- [ret = %d]", ret); + return ret; +} + +/** + * @brief + * Vehicle Speed Information Acquisition + * + * Obtain vehicle speed information + * + * @param[in] hApp HANDLE - Application handle + * @param[in] dat SENSORMOTION_SPEEDINFO_DAT* - Pointer to the acquired car speed information storage destination + * @param[in] ucGetMethod uint8_t - Acquisition method(GPS/Navigation/Not specified) + * + * @return POS_RET_NORMAL Normal completion(Include illegal)<br> + * POS_RET_ERROR_PARAM Parameter error<br> + * POS_RET_ERROR_NOSUPPORT Unsupported environment<br> + * POS_RET_ERROR_INNER Internal error + * + */ +POS_RET_API POS_GetSpeed(HANDLE hApp, // NOLINT(readability/nolint) + SENSORMOTION_SPEEDINFO_DAT *dat, // NOLINT(readability/nolint) + uint8_t ucGetMethod) { // NOLINT(readability/nolint) + POS_RET_API ret = POS_RET_NORMAL; /* Return value */ + UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */ + DID did; /* Data ID */ + int32_t ret_get_proc; /* POS_GetProc Return Values */ + + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "+"); + if (hApp == NULL) { + /* If the handler is NULL, the process terminates with an error. */ + ret = POS_RET_ERROR_PARAM; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [hApp = %p]", hApp); + } else if (dat == NULL) { + /* When the pointer to the vehicle speed data storage destination is NULL, the pointer terminates with an error in the parameter. */ + ret = POS_RET_ERROR_PARAM; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [dat = %p]", dat); + } else { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Supported HW Configuration Check */ + type = GetEnvSupportInfo(); + if (UNIT_TYPE_GRADE1 == type) { + /* GRADE1 */ + ret = POS_RET_NORMAL; + if (ucGetMethod == SENSOR_GET_METHOD_POS) { + did = VEHICLE_DID_MOTION_SPEED_INTERNAL; + } else if ((ucGetMethod == SENSOR_GET_METHOD_NAVI) || + (ucGetMethod == SENSOR_GET_METHOD_AUTO)) { + did = VEHICLE_DID_MOTION_SPEED_NAVI; + } else { + /* End as a parameter error abnormality except for POS/unspecified acquisition method */ + ret = POS_RET_ERROR_PARAM; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Argument ERROR [type = %d, ucGetMethod = %d]", + type, ucGetMethod); + } + } else if (UNIT_TYPE_GRADE2 == type) { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = POS_RET_ERROR_NOSUPPORT; + } else { + /* Environment error */ + ret = POS_RET_ERROR_NOSUPPORT; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "GetEnvSupportInfo ERROR [type = %d]", type); + } + } + + if (ret == POS_RET_NORMAL) { + /* Data acquisition process */ + ret_get_proc = PosGetProc(did, dat, sizeof(SENSORMOTION_SPEEDINFO_DAT)); + if (static_cast<int32_t>(sizeof(SENSORMOTION_SPEEDINFO_DAT)) > ret_get_proc) { + /* Failed to acquire */ + if (ret_get_proc == POS_RET_ERROR_RESOURCE) { + /* Insufficient resource */ + ret = POS_RET_ERROR_RESOURCE; + } else { + ret = POS_RET_ERROR_INNER; + } + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PosGetProc ERROR [ret = %d]", ret); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "- [ret = %d]", ret); + + return ret; +} + +/** + * @brief + * Compass information acquisition + * + * Get Bill Direction Information + * + * @param[in] hApp HANDLE - Application handle + * @param[in] dat SENSORMOTION_HEADINGINFO_DAT* - Pointer to the acquired altitude information storage destination + * @param[in] ucGetMethod uint8_t - Acquisition method(GPS/Navigation/Not specified) + * + * @return POS_RET_NORMAL Normal completion(Include illegal)<br> + * POS_RET_ERROR_PARAM Parameter error<br> + * POS_RET_ERROR_NOSUPPORT Unsupported environment<br> + * POS_RET_ERROR_INNER Internal error + * + */ +POS_RET_API POS_GetHeading(HANDLE hApp, // NOLINT(readability/nolint) + SENSORMOTION_HEADINGINFO_DAT *dat, // NOLINT(readability/nolint) + uint8_t ucGetMethod) { // NOLINT(readability/nolint) + POS_RET_API ret = POS_RET_NORMAL; /* Return value */ + UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */ + DID did = VEHICLE_DID_MOTION_HEADING; /* Data ID */ + int32_t ret_get_proc; /* POS_GetProc Return Values */ + + /* Internal debug log output */ + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "+"); + + /* Arguments & Support Configuration Check */ + if (hApp == NULL) { + /* If the handler is NULL, the process terminates with an error. */ + ret = POS_RET_ERROR_PARAM; + } else if (dat == NULL) { + /* If the longitude/latitude data is NULL, it ends with an abnormal parameter. */ + ret = POS_RET_ERROR_PARAM; + } else { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Supported HW Configuration Check */ + type = GetEnvSupportInfo(); + if (UNIT_TYPE_GRADE1 == type) { + /* GRADE1 */ + if (ucGetMethod == SENSOR_GET_METHOD_GPS) { + did = VEHICLE_DID_MOTION_HEADING; + } else if ((ucGetMethod == SENSOR_GET_METHOD_NAVI) || + (ucGetMethod == SENSOR_GET_METHOD_AUTO)) { + did = VEHICLE_DID_MOTION_HEADING_NAVI; + } else { + /* End as a parameter error abnormality except for GPS/unspecified acquisition method */ + ret = POS_RET_ERROR_PARAM; + } + } else if (UNIT_TYPE_GRADE2 == type) { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = SENSOR_RET_ERROR_NOSUPPORT; + } else { + /* Environment error */ + ret = SENSOR_RET_ERROR_NOSUPPORT; + } + } + /* Sensor information acquisition */ + if (ret == POS_RET_NORMAL) { + /* Data acquisition process */ + ret_get_proc = PosGetProc(did, reinterpret_cast<void *>(dat), sizeof(SENSORMOTION_HEADINGINFO_DAT)); + if (static_cast<int32_t>(sizeof(SENSORMOTION_HEADINGINFO_DAT)) > ret_get_proc) { + /** Failed to acquire */ + if (ret_get_proc == POS_RET_ERROR_RESOURCE) { + /** Insufficient resource */ + ret = POS_RET_ERROR_RESOURCE; + } else { + ret = POS_RET_ERROR_INNER; + } + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PosGetProc ERROR [ret = %d]", ret); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "- [ret = %d]", ret); + return ret; +} + +/** + * @brief + * Vehicle speed information setting + * + * Setting Vehicle Speed Information + * + * @param[in] hApp HANDLE - Application handle + * @param[in] navispped uint16_t - Vehicle speed information[Unit:1.0km/h] + * + * @return POS_RET_NORMAL Normal completion(Include illegal)<br> + * POS_RET_ERROR_PARAM Parameter error<br> + * POS_RET_ERROR_NOSUPPORT Unsupported environment + * + */ +POS_RET_API POS_SetSpeedInfo(HANDLE hApp, uint16_t navispeed) { // NOLINT(readability/nolint) + POS_RET_API ret = POS_RET_NORMAL; /* Return value */ + UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */ + uint16_t speed; /* Vehicle speed */ + + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "+"); + + /* Arguments & Support Configuration Check */ + if (hApp == NULL) { + ret = POS_RET_ERROR_PARAM; + } else { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Supported HW Configuration Check */ + type = GetEnvSupportInfo(); + if (UNIT_TYPE_GRADE1 == type) { + /* GRADE1 */ + ret = POS_RET_NORMAL; + } else if (UNIT_TYPE_GRADE2 == type) { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = SENSOR_RET_ERROR_NOSUPPORT; + } else { + /* Environment error */ + ret = SENSOR_RET_ERROR_NOSUPPORT; + } + } + + if (ret == POS_RET_NORMAL) { + /* Adjustment by unit [1.0km/h]->[0.01m/sec] */ + speed = static_cast<uint16_t>(navispeed * 10000 / 360); + /* Data setting(After setting,Immediate termination) */ + ret = PosSetProc(VEHICLE_DID_MOTION_SPEED_NAVI, + reinterpret_cast<void *>(&speed), sizeof(uint16_t), FALSE); + } + + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "- [ret = %d]", ret); + return ret; +} + +/** + * @brief + * Location information setting + * + * Set location information + * + * @param[in] hApp HANDLE - Application handle + * @param[in] posData POS_POSDATA - Pointer to location information + * + * @return POS_RET_NORMAL Normal completion(Include illegal)<br> + * POS_RET_ERROR_PARAM Parameter error<br> + * POS_RET_ERROR_INNER Internal error<br> + * POS_RET_ERROR_NOSUPPORT Unsupported environment + * + */ +POS_RET_API POS_SetLocationInfo(HANDLE hApp, POS_POSDATA* pstPosData) { // NOLINT(readability/nolint) + POS_RET_API ret = POS_RET_NORMAL; /* Return value of this function */ + UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */ + + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "+"); + + /* Arguments & Support Configuration Check */ + if ((pstPosData == NULL) || (hApp == NULL)) { + ret = POS_RET_ERROR_PARAM; + } else { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Supported HW Configuration Check */ + type = GetEnvSupportInfo(); + if (UNIT_TYPE_GRADE1 == type) { + /* GRADE1 */ + ret = POS_RET_NORMAL; + } else if (UNIT_TYPE_GRADE2 == type) { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = SENSOR_RET_ERROR_NOSUPPORT; + } else { + /* Environment error */ + ret = SENSOR_RET_ERROR_NOSUPPORT; + } + } + + if (ret == POS_RET_NORMAL) { + /* Data status check */ + if ((0x01 > pstPosData->status) || (0x0F < pstPosData->status)) { + ret = POS_RET_ERROR_PARAM; + } else { + /* Parameter range check */ + /* Latitude */ + if ((pstPosData->status & POS_LOC_INFO_LAT) == POS_LOC_INFO_LAT) { + (void)POS_CHKPARAM32(pstPosData->latitude, -41472000, 41472000); + } + /* Longitude */ + if ((pstPosData->status & POS_LOC_INFO_LON) == POS_LOC_INFO_LON) { + (void)POS_CHKPARAM32(pstPosData->longitude, -82944000, 82944000); + } + /* Orientation */ + if ((pstPosData->status & POS_LOC_INFO_HEAD) == POS_LOC_INFO_HEAD) { + (void)POS_CHKPARAM16(pstPosData->heading, -179, 180); + } + + /* Data setting(After setting,Immediate termination) */ + ret = PosSetProc(VEHICLE_DID_GPS_CUSTOMDATA_NAVI, // == POSHAL_DID_GPS_CUSTOMDATA_NAVI + reinterpret_cast<void *>(pstPosData), sizeof(POS_POSDATA), FALSE); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "- [ret = %d]", ret); + return ret; +} diff --git a/vehicleservice/positioning/client/src/POS_common_API/Makefile b/vehicleservice/positioning/client/src/POS_common_API/Makefile new file mode 100755 index 0000000..4d7a90f --- /dev/null +++ b/vehicleservice/positioning/client/src/POS_common_API/Makefile @@ -0,0 +1,47 @@ +# +# @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +######### installed shared library(*.so) ############# +INST_SHLIBS = libPOS_common_API + +######### compiled sources ############# +libPOS_common_API_SRCS += Common_API.cpp + +######### add include path ############# +CPPFLAGS += -I../../../server/include/common +CPPFLAGS += -I../../include +CPPFLAGS += -I../../../server/include/nsfw + +######### add compile option ############# +CPPFLAGS += -DLINUX -fPIC + +LDFLAGS += -Wl,--no-undefined +LDFLAGS += -Wl,--no-as-needed +CPPFLAGS += -Werror=implicit-function-declaration +CPPFLAGS += -Werror=format-security +CPPFLAGS += -Wconversion +CPPFLAGS += -Wint-to-pointer-cast +CPPFLAGS += -Wpointer-arith +CPPFLAGS += -Wformat + +######### linked library (dynamic) ############# +LDLIBS += -Wl,-Bdynamic -lNS_FrameworkUnified +LDLIBS += -Wl,-Bdynamic -lPOS_base_API +LDLIBS += -Wl,-Bdynamic -lvp + +######### add library path ############# +LDFLAGS += -shared + +include ../../../../vehicle_service.mk diff --git a/vehicleservice/positioning/client/src/POS_common_API/libPOS_common_API.ver b/vehicleservice/positioning/client/src/POS_common_API/libPOS_common_API.ver new file mode 100755 index 0000000..afc7f3a --- /dev/null +++ b/vehicleservice/positioning/client/src/POS_common_API/libPOS_common_API.ver @@ -0,0 +1,37 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +# +# libPOS_common_API version script +# +{ + global: + POS_GetAltitude; + POS_GetHeading; + POS_GetLonLat; + POS_GetSpeed; + POS_RegisterListenerAltitude; + POS_RegisterListenerHeading; + POS_RegisterListenerLonLat; + POS_RegisterListenerSpeed; + POS_SetLocationInfo; + POS_SetSpeedInfo; + + POS_SetLocationInfoNmea; + local: + *; +}; + diff --git a/vehicleservice/positioning/client/src/POS_gps_API/Gps_API.cpp b/vehicleservice/positioning/client/src/POS_gps_API/Gps_API.cpp new file mode 100755 index 0000000..7395f9d --- /dev/null +++ b/vehicleservice/positioning/client/src/POS_gps_API/Gps_API.cpp @@ -0,0 +1,456 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Gps_API.cpp + * @brief + * Module : POSITIONING + * GPS I/F service functionality + */ +#include <vehicle_service/positioning_base_library.h> +#include <vehicle_service/POS_define.h> +#include <vehicle_service/POS_gps_API.h> +#include <vehicle_service/POS_common_API.h> +#include <vehicle_service/POS_sensor_API.h> +#include "POS_common_private.h" +#include "POS_private.h" +#include "Vehicle_API_private.h" +#include "Gps_API_private.h" + + +/** + * @brief + * GPS reset request + * + * Request a GPS reset + * + * @param[in] hApp HANDLE - Application handle + * @param[in] ResName PCSTR - Destination thread name + * @param[in] mode uint8_t - Reset mode + * + * @return POS_RET_NORMAL Normal completion(Include illegal)<br> + * POS_RET_ERROR_PARAM Parameter error<br> + * POS_RET_ERROR_INNER Internal processing error<br> + * POS_RET_ERROR_BUSY Busy occurrence<br> + * POS_RET_ERROR_NOSUPPORT Unsupported environment + * + */ +POS_RET_API POS_ReqGPSReset(HANDLE hApp, PCSTR ResName, uint8_t mode) { // NOLINT(readability/nolint) + UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */ + POS_RET_API ret = POS_RET_NORMAL; /* Return value of this function */ + RET_API ret_api = RET_NORMAL; /* API return value */ + POS_RESETINFO snd_msg; /* Reset information */ + EventID event_id; /* Event ID */ + int32_t event_val; /* Event value */ + PNO my_pno; /* Caller PNO */ + PNO rs_pno; /* Destination PNO */ + uint32_t pid; /* Process ID */ + uint32_t tid; /* Thread ID */ + char name[128]; /* Name buffer */ + + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "+"); + + /* Arguments & Support Configuration Check */ + if ((hApp == NULL) || (ResName == NULL)) { + ret = POS_RET_ERROR_PARAM; + } else if (GPS_RST_COLDSTART != mode) { + /* Parameter error except */ + ret = POS_RET_ERROR_PARAM; + } else { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Supported HW Configuration Check */ + type = GetEnvSupportInfo(); + if (UNIT_TYPE_GRADE1 == type) { + /* GRADE1 */ + ret = POS_RET_NORMAL; + } else if (UNIT_TYPE_GRADE2 == type) { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = POS_RET_ERROR_NOSUPPORT; + } else { + /* Environment error */ + ret = POS_RET_ERROR_NOSUPPORT; + } + + if (ret == POS_RET_NORMAL) { + /* Resource acquisition */ + if (VehicleGetResource() == TRUE) { + /* Event Generation */ + rs_pno = _pb_CnvName2Pno(ResName); + pid = (uint32_t)getpid(); + tid = GetTid(); + + snprintf(name, sizeof(name), "PR_p%u_t%u", pid, tid); + my_pno = _pb_CnvName2Pno(name); + event_id = VehicleCreateEvent(my_pno); + if (0 != event_id) { + /* Successful event generation */ + memset(&snd_msg, 0x00, sizeof(POS_RESETINFO)); + + /* Message creation */ + snd_msg.mode = mode; /* Reset mode */ + snd_msg.snd_pno = my_pno; /* Caller PNo. */ + snd_msg.res_pno = rs_pno; /* Destination PNo. */ + + /* Message transmission request */ + ret_api = _pb_SndMsg_Ext(POS_THREAD_NAME, + CID_GPS_REQRESET, + sizeof(POS_RESETINFO), + reinterpret_cast<void*>(&snd_msg), 0); + + if (RET_NORMAL == ret_api) { + /* If the data setup process is successful,Wait for a completion event */ + ret_api = _pb_WaitEvent(event_id, + SAPI_EVWAIT_VAL, + VEHICLE_RET_ERROR_MIN, VEHICLE_RET_NORMAL, &event_val, INFINITE); + if (RET_NORMAL != ret_api) { + /* When not put in event wait state */ + /* Event generation failure */ + ret = POS_RET_ERROR_INNER; + } else { + /* Return from Event Wait */ + /* Set event value (processing result) as return value */ + ret = (POS_RET_API)event_val; + } + } else { + /* Message transmission processing failed */ + ret = POS_RET_ERROR_INNER; + } + /* Event deletion */ + ret_api = VehicleDeleteEvent(event_id); + } else { + /* Event generation failure */ + ret = POS_RET_ERROR_INNER; + } + } else { + /* Insufficient resource */ + ret = POS_RET_ERROR_RESOURCE; + } + /* Resource release */ + VehicleReleaseResource(); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "- [ret = %d]", ret); + return ret; +} + +/** + * @brief + * GPS time setting request delivery registration + * + * Register delivery of GPS time setting request + * + * @param[in] hApp HANDLE - Application handle + * @param[in] notifyName PCSTR - Destination thread name + * @param[in] ucCtrlFlg uint8_t - Delivery control(Delivery registration/Delivery stop/Resume delivery) + * + * @return POS_RET_NORMAL Normal completion(Include illegal)<br> + * POS_RET_ERROR_BUFFULL Buffer-full<br> + * POS_RET_ERROR_INNER Internal error<br> + * POS_RET_ERROR_PARAM Parameter error<br> + * POS_RET_ERROR_NOSUPPORT Unsupported environment + * + */ +POS_RET_API POS_RegisterListenerGPSTimeSetReq(HANDLE hApp, // NOLINT(readability/nolint) + PCSTR notifyName, // NOLINT(readability/nolint) + uint8_t ucCtrlFlg) { // NOLINT(readability/nolint) + POS_RET_API ret = POS_RET_NORMAL; /* Return value of this function */ + SENSOR_RET_API ret_sens = SENSOR_RET_NORMAL; /* API return value */ + UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */ + + /* Internal debug log output */ + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+"); + + /* Arguments & Support Configuration Check */ + if ((hApp == NULL) || (notifyName == NULL)) { + ret = POS_RET_ERROR_PARAM; + } else if (SENSOR_DELIVERY_REGIST != ucCtrlFlg) { + /* Parameter error other than delivery registration */ + ret = POS_RET_ERROR_PARAM; + } else { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Supported HW Configuration Check */ + type = GetEnvSupportInfo(); + if (UNIT_TYPE_GRADE1 == type) { + /* GRADE1 */ + ret = POS_RET_NORMAL; + } else if (UNIT_TYPE_GRADE2 == type) { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = POS_RET_ERROR_NOSUPPORT; + } else { + /* Environment error */ + ret = POS_RET_ERROR_NOSUPPORT; + } + } + + /* Delivery registration */ + if (POS_RET_NORMAL == ret) { + /* Delivery registry SensorAPI calls */ + ret_sens = PosRegisterListenerProc(notifyName, /* Destination thread name */ + VEHICLE_DID_SETTINGTIME, /* Data ID */ + ucCtrlFlg, /* Delivery control */ + VEHICLE_DELIVERY_TIMING_UPDATE); /* Delivery timing */ + + /* Decision of delivery registration result */ + if (ret_sens == SENSOR_RET_NORMAL) { + ret = POS_RET_NORMAL; + } else if (ret_sens == SENSOR_RET_ERROR_PARAM) { + ret = POS_RET_ERROR_PARAM; + } else if (ret_sens == SENSOR_RET_ERROR_BUFFULL) { + ret = POS_RET_ERROR_BUFFULL; + } else if (ret_sens == SENSOR_RET_ERROR_RESOURCE) { + ret = POS_RET_ERROR_RESOURCE; + } else { + ret = POS_RET_ERROR_INNER; + } + } + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "- [ret = %d]", ret); + return ret; +} + +/** + * @brief + * GPS time setting + * + * Set the GPS time + * + * @param[in] hApp HANDLE - Application handle + * @param[in] pstDateTime POS_DATETIME - Pointer to GPS time information + * + * @return POS_RET_NORMAL Normal completion(Include illegal)<br> + * POS_RET_ERROR_INNER Internal error<br> + * POS_RET_ERROR_TIMEOUT Timeout error<br> + * POS_RET_ERROR_PARAM Parameter error<br> + * POS_RET_ERROR_NOSUPPORT Unsupported environment + * + */ +POS_RET_API POS_SetGPStime(HANDLE hApp, POS_DATETIME* pstDateTime) { // NOLINT(readability/nolint) + POS_RET_API ret = POS_RET_NORMAL; /* Return value of this function */ + UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */ + + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "+"); + + /* Arguments & Support Configuration Check */ + if ((pstDateTime == NULL) || (hApp == NULL)) { + ret = POS_RET_ERROR_PARAM; + } else { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Supported HW Configuration Check */ + type = GetEnvSupportInfo(); + if (UNIT_TYPE_GRADE1 == type) { + /* GRADE1 */ + ret = POS_RET_NORMAL; + } else if (UNIT_TYPE_GRADE2 == type) { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = POS_RET_ERROR_NOSUPPORT; + } else { + /* Environment error */ + ret = POS_RET_ERROR_NOSUPPORT; + } + } + + if (ret == POS_RET_NORMAL) { + /* Parameter range check */ + /* Month */ + if (POS_RET_ERROR == POS_CHKPARAMU8(pstDateTime->month, 1, 12)) { + return POS_RET_ERROR_PARAM; + } + /* Day */ + if (POS_RET_ERROR == POS_CHKPARAMU8(pstDateTime->date, 1, 31)) { + return POS_RET_ERROR_PARAM; + } + /* Hour */ + if (POS_RET_ERROR == POS_CHKPARAMU8(pstDateTime->hour, 0, 23)) { + return POS_RET_ERROR_PARAM; + } + /* Minutes */ + if (POS_RET_ERROR == POS_CHKPARAMU8(pstDateTime->minute, 0, 59)) { + return POS_RET_ERROR_PARAM; + } + /* Second */ + if (POS_RET_ERROR == POS_CHKPARAMU8(pstDateTime->second, 0, 59)) { + return POS_RET_ERROR_PARAM; + } + + /* Data setting(Immediate recovery)*/ + ret = PosSetProc(VEHICLE_DID_SETTINGTIME, + reinterpret_cast<void*>(pstDateTime), sizeof(POS_DATETIME), FALSE); + } + + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "- [ret = %d]", ret); + return ret; +} + +/** + * @brief + * GPS Time Delivery Registration + * + * Registering GPS time delivery + * + * @param[in] hApp HANDLE - Application handle + * @param[in] nofifyName PCSTR - Destination thread name + * @param[in] ucCtrlFlg uint8_t - Delivery control(Delivery registration/Delivery stop/Resume delivery) + * @param[in] ucDeliveryTiming uint8_t - Delivery timing(Changing/Updating) + * + * @return SENSOR_RET_NORMAL Successful registration<br> + * SENSOR_RET_ERROR_CREATE_EVENT Event generation failure<br> + * SENSOR_RET_ERROR_PARAM Parameter error<br> + * SENSOR_RET_ERROR_BUFFULL FULL of delivery registers<br> + * SENSOR_RET_ERROR_NOSUPPORT Unsupported environment + * + */ +SENSOR_RET_API POS_RegisterListenerGPStime(HANDLE hApp, // NOLINT(readability/nolint) + PCSTR notifyName, // NOLINT(readability/nolint) + uint8_t ucCtrlFlg, // NOLINT(readability/nolint) + uint8_t ucDeliveryTiming) { // NOLINT(readability/nolint) + SENSOR_RET_API ret = SENSOR_RET_NORMAL; + UNIT_TYPE type = UNIT_TYPE_NONE; + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+"); + + if (hApp == NULL) { + /* Parameter error */ + ret = SENSOR_RET_ERROR_PARAM; + } else { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Supported HW Configuration Check */ + type = GetEnvSupportInfo(); + if (UNIT_TYPE_GRADE1 == type) { + /* GRADE1 */ + ret = SENSOR_RET_NORMAL; + } else if (UNIT_TYPE_GRADE2 == type) { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = SENSOR_RET_ERROR_NOSUPPORT; + } else { + /* fail */ + ret = SENSOR_RET_ERROR_NOSUPPORT; + } + } + + if (SENSOR_RET_NORMAL == ret) { + if (notifyName == NULL) { + /* Parameter error */ + ret = SENSOR_RET_ERROR_PARAM; + } + if (ucCtrlFlg != SENSOR_DELIVERY_REGIST) { + /* Parameter error */ + ret = SENSOR_RET_ERROR_PARAM; + } + if ((ucDeliveryTiming != SENSOR_DELIVERY_TIMING_CHANGE) && + (ucDeliveryTiming != SENSOR_DELIVERY_TIMING_UPDATE)) { + /* Parameter error */ + ret = SENSOR_RET_ERROR_PARAM; + } + } + + if (SENSOR_RET_NORMAL == ret) { + /* Delivery registration process */ + ret = PosRegisterListenerProc(notifyName, VEHICLE_DID_GPS_TIME, ucCtrlFlg, ucDeliveryTiming); + } + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "- [ret = %d]", ret); + return ret; +} + +/** + * @brief + * Get GPS time + * + * Get the GPS time + * + * @param[in] hApp HANDLE - Application handle + * @param[in] *dat SENSOR_GPSTIME - Pointer to GPS time information + * + * @return POS_RET_NORMAL Normal completion(Include illegal)<br> + * POS_RET_ERROR_INNER Internal error<br> + * POS_RET_ERROR_PARAM Parameter error<br> + * POS_RET_ERROR_NOSUPPORT Unsupported environment + * + */ +POS_RET_API POS_GetGPStime(HANDLE hApp, SENSOR_GPSTIME* dat) { // NOLINT(readability/nolint) + POS_RET_API ret = POS_RET_NORMAL; /* Return value */ + UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */ + DID did = VEHICLE_DID_GPS_TIME; /* DID */ + int32_t ret_get_proc; /* POS_GetProc Return Values */ + + /* Internal debug log output */ + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "+"); + + /* Arguments & Support Configuration Check */ + if (hApp == NULL) { + /* If the handler is NULL, the process terminates with an error. */ + ret = POS_RET_ERROR_PARAM; + } else if (dat == NULL) { + /* If the longitude/latitude data is NULL, it ends with an abnormal parameter. */ + ret = POS_RET_ERROR_PARAM; + } else { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Supported HW Configuration Check */ + type = GetEnvSupportInfo(); + if (UNIT_TYPE_GRADE1 == type) { + ret = POS_RET_NORMAL; + } else { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = POS_RET_ERROR_NOSUPPORT; + } + } + + /* Sensor information acquisition */ + if (ret == POS_RET_NORMAL) { + /* Data acquisition process */ + ret_get_proc = PosGetProc(did, reinterpret_cast<void*>(dat), sizeof(SENSOR_GPSTIME)); + if (static_cast<int32_t>(sizeof(SENSOR_GPSTIME)) > ret_get_proc) { + /* Failed to acquire */ + if (ret_get_proc == POS_RET_ERROR_RESOURCE) { + /* Insufficient resource */ + ret = POS_RET_ERROR_RESOURCE; + } else { + ret = POS_RET_ERROR_INNER; + } + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PosGetProc ERROR [ret = %d]", ret); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "- [ret = %d]", ret); + + return ret; +} diff --git a/vehicleservice/positioning/client/src/POS_gps_API/Makefile b/vehicleservice/positioning/client/src/POS_gps_API/Makefile new file mode 100755 index 0000000..c6391a9 --- /dev/null +++ b/vehicleservice/positioning/client/src/POS_gps_API/Makefile @@ -0,0 +1,51 @@ +# +# @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +######### installed shared library(*.so) ############# +INST_SHLIBS = libPOS_gps_API + +######### compiled sources ############# +libPOS_gps_API_SRCS += Gps_API.cpp +libPOS_gps_API_SRCS += Naviinfo_API.cpp + +######### add include path ############# +CPPFLAGS += -I../../../server/include/common +CPPFLAGS += -I../../include +CPPFLAGS += -I../../../server/include/nsfw + +CPPFLAGS += -I../Vehicle_API +CPPFLAGS += -I../Vehicle_API/common + +######### add compile option ############# +CPPFLAGS += -DLINUX -fPIC + +LDFLAGS += -Wl,--no-undefined +LDFLAGS += -Wl,--no-as-needed +CPPFLAGS += -Werror=implicit-function-declaration +CPPFLAGS += -Werror=format-security +CPPFLAGS += -Wconversion +CPPFLAGS += -Wint-to-pointer-cast +CPPFLAGS += -Wpointer-arith +CPPFLAGS += -Wformat + +######### linked library (dynamic) ############# +LDLIBS += -Wl,-Bdynamic -lNS_FrameworkUnified +LDLIBS += -Wl,-Bdynamic -lPOS_base_API +LDLIBS += -Wl,-Bdynamic -lvp + +######### add library path ############# +LDFLAGS += -shared + +include ../../../../vehicle_service.mk diff --git a/vehicleservice/positioning/client/src/POS_gps_API/Naviinfo_API.cpp b/vehicleservice/positioning/client/src/POS_gps_API/Naviinfo_API.cpp new file mode 100755 index 0000000..cfe04ff --- /dev/null +++ b/vehicleservice/positioning/client/src/POS_gps_API/Naviinfo_API.cpp @@ -0,0 +1,404 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/****************************************************************************** +@file Naviinfo_API.cpp +@detail Naviinfo_API Functions +@lib libNaviinfo_API.so +******************************************************************************/ + +/***************************************************************************** + * Include * + *****************************************************************************/ +#include "Naviinfo_API.h" +#include <vehicle_service/POS_define.h> +#include <vehicle_service/POS_sensor_API.h> +#include <vehicle_service/POS_gps_API.h> +#include "Vehicle_API_Dummy.h" +#include "POS_private.h" +#include <native_service/frameworkunified_types.h> // NOLINT(build/include_order) + +void PosCnvGpsInfo(NAVIINFO_ALL *navi_loc_info); + + +/** + * @brief + * GPS information setting + * + * Set GPS information + * + * @param[in] hApp HANDLE - Application handle + * @param[in] navilocinfo NAVIINFO_ALL* - Pointer to GPS information storage area + * + * @return NAVIINFO_RET_NORMAL Normal completion<br> + * NAVIINFO_RET_ERROR_PARAM Parameter error<br> + * NAVIINFO_RET_ERROR_INNER Internal error<br> + * NAVIINFO_RET_ERROR_NOSUPPORT Unsupported environment + * + */ +NAVIINFO_RET_API POS_SetGPSInfo(HANDLE hApp, NAVIINFO_ALL *navilocinfo) +{ + NAVIINFO_RET_API ret = NAVIINFO_RET_NORMAL; /* Return value of this function */ + UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */ + NAVIINFO_ALL navi_loc_info_tmp; /* Conversion quantity area */ + RET_API ret_api; + + /** NULL checking */ + if (navilocinfo == NULL) { + /** Parameter error */ + ret = NAVIINFO_RET_ERROR_PARAM; + } else if (hApp == NULL) { + /** Parameter error */ + ret = NAVIINFO_RET_ERROR_PARAM; + } else { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Supported HW Configuration Check */ + type = GetEnvSupportInfo(); + if (UNIT_TYPE_GRADE1 == type) { + /* GRADE1 */ + ret = NAVIINFO_RET_NORMAL; + } else if (UNIT_TYPE_GRADE2 == type) { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = NAVIINFO_RET_ERROR_NOSUPPORT; + } else { + /* Environment error */ + ret = NAVIINFO_RET_ERROR_NOSUPPORT; + } + } + + if (ret == NAVIINFO_RET_NORMAL) { + /* Parameter range check */ + if (navilocinfo->stNaviGps.tdsts != 0) { /* Other than ""Time not calibrated after receiver reset"" */ + /* Positioning status information */ + if (POS_RET_ERROR == POS_CHKPARAMU8(navilocinfo->stDiagGps.stFix.ucFixSts, 0, 2)) { + return NAVIINFO_RET_ERROR_PARAM; + } + /* Latitude */ + if (POS_RET_ERROR == POS_CHKPARAM32(navilocinfo->stDiagGps.stFix.stWgs84.lLat, -82944000, 82944000)) { + return NAVIINFO_RET_ERROR_PARAM; + } + /* Longitude */ + if (POS_RET_ERROR == POS_CHKPARAM32(navilocinfo->stDiagGps.stFix.stWgs84.lLon, -165888000, 165888000)) { + return NAVIINFO_RET_ERROR_PARAM; + } + /* Measurement Azimuth */ + if (POS_RET_ERROR == POS_CHKPARAMU16(navilocinfo->stNaviGps.heading, 0, 3599)) { + return NAVIINFO_RET_ERROR_PARAM; + } + /* UTC(Month) */ + if (POS_RET_ERROR == POS_CHKPARAMU8(navilocinfo->stNaviGps.utc.month, 1, 12)) { + return NAVIINFO_RET_ERROR_PARAM; + } + /* UTC(Day) */ + if (POS_RET_ERROR == POS_CHKPARAMU8(navilocinfo->stNaviGps.utc.date, 1, 31)) { + return NAVIINFO_RET_ERROR_PARAM; + } + /* UTC(Hour) */ + if (POS_RET_ERROR == POS_CHKPARAMU8(navilocinfo->stNaviGps.utc.hour, 0, 23)) { + return NAVIINFO_RET_ERROR_PARAM; + } + /* UTC(Minutes) */ + if (POS_RET_ERROR == POS_CHKPARAMU8(navilocinfo->stNaviGps.utc.minute, 0, 59)) { + return NAVIINFO_RET_ERROR_PARAM; + } + /* UTC(Second) */ + if (POS_RET_ERROR == POS_CHKPARAMU8(navilocinfo->stNaviGps.utc.second, 0, 59)) { + return NAVIINFO_RET_ERROR_PARAM; + } + } + /* Date and Time Status */ + if (POS_RET_ERROR == POS_CHKPARAMU8(navilocinfo->stNaviGps.tdsts, 0, 2)) { + return NAVIINFO_RET_ERROR_PARAM; + } + + /* Copy to conversion area */ + memcpy(&navi_loc_info_tmp, navilocinfo, sizeof(NAVIINFO_ALL)); + /** Data unit conversion */ + PosCnvGpsInfo(&navi_loc_info_tmp); + + /* Resource acquisition */ + if (VehicleGetResource() == TRUE) { + + /** Send navigation information to vehicle sensor */ + ret_api = _pb_SndMsg_Ext(POS_THREAD_NAME, + CID_NAVIINFO_DELIVER, + sizeof(NAVIINFO_ALL), + reinterpret_cast<void*>(&navi_loc_info_tmp), 0); + if (ret_api != RET_NORMAL) { + /** Message transmission failure */ + ret = NAVIINFO_RET_ERROR_INNER; + } + } else { + /* When resource shortage occurs, the system terminates with an insufficient resource error. */ + ret = NAVIINFO_RET_ERROR_RESOURCE; + } + /* Resource release */ + VehicleReleaseResource(); + } + + return ret; +} + +/** + * @brief + * GPS information acquisition + * + * Access GPS information + * + * @param[in] hApp HANDLE - Application handle + * @param[in] navidiaginfo NAVIINFO_DIAG_GPS* - Pointer to GPS information storage area + * + * @return NAVIINFO_RET_NORMAL Normal completion<br> + * NAVIINFO_RET_ERROR_PARAM Parameter error<br> + * NAVIINFO_RET_ERROR_INNER Internal error<br> + * NAVIINFO_RET_ERROR_NOSUPPORT Unsupported environment + * + */ +NAVIINFO_RET_API POS_GetGPSInfo(HANDLE hApp, NAVIINFO_DIAG_GPS *navidiaginfo) +{ + NAVIINFO_RET_API ret = NAVIINFO_RET_NORMAL; /* Return value of this function */ + UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */ + int32_t ret_veh; /* VehicleAPI Return Values */ + NAVIINFO_DIAG_GPS dest_data; /* Data acquisition area */ + + /** NULL checking */ + if (navidiaginfo == NULL) { + /** Parameter error */ + ret = NAVIINFO_RET_ERROR_PARAM; + } else if (hApp == NULL) { + /** Parameter error */ + ret = NAVIINFO_RET_ERROR_PARAM; + } else { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Supported HW Configuration Check */ + type = GetEnvSupportInfo(); + if (UNIT_TYPE_GRADE1 == type) { + /* GRADE1 */ + ret = NAVIINFO_RET_NORMAL; + } else if (UNIT_TYPE_GRADE2 == type) { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = NAVIINFO_RET_ERROR_NOSUPPORT; + } else { + /* Environment error */ + ret = NAVIINFO_RET_ERROR_NOSUPPORT; + } + } + + if (ret == NAVIINFO_RET_NORMAL) { + /** Acquisition of navigation data for Diag provide */ + ret_veh = PosGetProc( + (DID)VEHICLE_DID_NAVIINFO_DIAG_GPS, + reinterpret_cast<void*>(&dest_data), + (u_int16)sizeof(dest_data)); + + if (static_cast<int32_t>(sizeof(NAVIINFO_DIAG_GPS)) > ret_veh) { + /** Failed to acquire */ + if (ret_veh == POS_RET_ERROR_RESOURCE) { + ret = NAVIINFO_RET_ERROR_RESOURCE; + } else { + ret = NAVIINFO_RET_ERROR_INNER; + } + } else { + /** Successful acquisition */ + memcpy( navidiaginfo, &dest_data, sizeof(NAVIINFO_DIAG_GPS)); + } + } + + return ret; +} + +/* ++ GPS _CWORD82_ support */ +/** + * @brief + * GPS setting transmission request + * + * Requesting GPS Settings with Complete Return + * + * @param[in] hApp HANDLE - Application handle + * @param[in] p_data SENSOR_MSG_SEND_DAT* - GPS setting information to be sent + * + * @return SENSOR_RET_NORMAL Normal completion<br> + * SENSOR_RET_ERROR_CREATE_EVENT Event generation failure<br> + * SENSOR_RET_ERROR_PARAM Parameter error<br> + * SENSOR_RET_ERROR_DID Unregistered DID<br> + * SENSOR_RET_ERROR_NOSUPPORT Unsupported environment + * + */ +int32 POS_ReqGPSSetting(HANDLE hApp, SENSOR_MSG_SEND_DAT *p_data) { /* Ignore->MISRA-C++:2008 Rule 7-1-2 */ + SENSOR_RET_API ret = SENSOR_RET_NORMAL; /* Return value */ + RET_API ret_api; /* System API return value */ + uint16_t expected_size; /* Message size for the specified DID */ + + UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */ + + if (hApp == NULL) { + /* Parameter error */ + ret = SENSOR_RET_ERROR_PARAM; + } + + if (ret == SENSOR_RET_NORMAL) { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Argument check (DID) + Size calculation */ + if (p_data != reinterpret_cast<SENSOR_MSG_SEND_DAT*>(NULL)) { + switch (p_data->did) { + case VEHICLE_DID_GPS__CWORD82__SETINITIAL: + { + expected_size = 71; + break; + } + case VEHICLE_DID_GPS__CWORD82__SETRMODE: + { + expected_size = 50; + break; + } + case VEHICLE_DID_GPS__CWORD82__SETRMODEEX: + { + expected_size = 63; + break; + } + case VEHICLE_DID_GPS__CWORD82__SELSENT: + { + expected_size = 21; + break; + } + case VEHICLE_DID_GPS__CWORD82__SETSBAS: + { + expected_size = 34; + break; + } + case VEHICLE_DID_GPS__CWORD82__SETCONF1: + { + expected_size = 37; + break; + } + case VEHICLE_DID_GPS__CWORD82__SETCONF2: + { + expected_size = 45; + break; + } + default: /* Ignore->MISRA-C++:2008 Rule 6-3-1, 6-4-1 */ + ret = SENSOR_RET_ERROR_DID; + break; + } + } else { + ret = SENSOR_RET_ERROR_PARAM; + } + } + + /* Supported HW Configuration Check */ + if (ret == SENSOR_RET_NORMAL) { + type = GetEnvSupportInfo(); + if (UNIT_TYPE_GRADE1 == type) { + /* GRADE1 */ + ret = SENSOR_RET_NORMAL; + } else if (UNIT_TYPE_GRADE2 == type) { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = SENSOR_RET_ERROR_NOSUPPORT; + } else { + /* Environment error */ + ret = SENSOR_RET_ERROR_NOSUPPORT; + } + } + + if (ret == SENSOR_RET_NORMAL) { + /* Argument check (Size)*/ + if (expected_size != p_data->usSize) { + ret = SENSOR_RET_ERROR_PARAM; + } else { + /* Message buffer initialization */ + + /* Create message data */ + + /* Resource acquisition */ + if (VehicleGetResource() == TRUE) { + /* External Process Transmission and Reception Messages */ + FRAMEWORKUNIFIEDLOG(ZONE_27, __FUNCTION__, + "POSITIONING: POS_ReqGPSSetting() --> cid = %d", + CID_SENSORIF__CWORD82__REQUEST); + ret_api = _pb_SndMsg_Ext(POS_THREAD_NAME, + CID_SENSORIF__CWORD82__REQUEST, + sizeof(SENSOR_MSG_SEND_DAT), + reinterpret_cast<void *>(p_data), 0); + FRAMEWORKUNIFIEDLOG(ZONE_27, __FUNCTION__, "POSITIONING: POS_ReqGPSSetting() <--"); + + if (ret_api != RET_NORMAL) { + ret = SENSOR_RET_ERROR_CREATE_EVENT; + } + } else { + /* When resource shortage occurs, the system terminates with an insufficient resource error. */ + ret = SENSOR_RET_ERROR_RESOURCE; + } + /* Resource release */ + VehicleReleaseResource(); + } + } + + return ret; +} +/* -- GPS _CWORD82_ support */ + +/** + * @brief + * GPS information conversion process + * + * Convert GPS information to a format to be provided to the vehicle sensor + * + * @param[in] none + * @param[in] navi_loc_info NAVIINFO_ALL* - GPS information pointer + * + * @return none + */ +void PosCnvGpsInfo(NAVIINFO_ALL *navi_loc_info) { + int32_t altitude; + int64_t tmp; + uint16_t heading; + + /* Unit conversion of fix altitude[1m]->[0.01m] */ + tmp = (int64_t)((int64_t)(navi_loc_info->stNaviGps.altitude) * 100); + if (tmp > static_cast<int32_t>(0x7FFFFFFF)) { + /* +Overflow of digits */ + altitude = static_cast<int32_t>(0x7FFFFFFF); + } else if (tmp < static_cast<int32_t>(0x80000000)) { /* Ignore->MISRA-C:2004 Rule 3.1 */ + /* -Overflow of digits */ + altitude = static_cast<int32_t>(0x80000000); /* Ignore->MISRA-C:2004 Rule 3.1 */ + } else { + altitude = static_cast<int32_t>(tmp); + } + navi_loc_info->stNaviGps.altitude = altitude; + + /* Measurement Azimuth Conversion[0.Once]->[0.01 degree] */ + heading = navi_loc_info->stNaviGps.heading; + heading = static_cast<uint16_t>(heading - ((heading / 3600) * 3600)); + heading = static_cast<uint16_t>(heading * 10); + navi_loc_info->stNaviGps.heading = heading; + + return; +} diff --git a/vehicleservice/positioning/client/src/POS_gps_API/libPOS_gps_API.ver b/vehicleservice/positioning/client/src/POS_gps_API/libPOS_gps_API.ver new file mode 100755 index 0000000..038c99e --- /dev/null +++ b/vehicleservice/positioning/client/src/POS_gps_API/libPOS_gps_API.ver @@ -0,0 +1,34 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +# +# libPOS_gps_API version script +# +{ + global: + POS_GetGPSInfo; + POS_GetGPSVersion; + POS_RegisterListenerGPSTimeSetReq; + POS_RegisterListenerGPStime; + POS_ReqGPSReset; + POS_ReqGPSSetting; + POS_SetGPSInfo; + POS_SetGPStime; + POS_GetGPStime; + local: + *; +}; + diff --git a/vehicleservice/positioning/client/src/POS_sensor_API/Makefile b/vehicleservice/positioning/client/src/POS_sensor_API/Makefile new file mode 100755 index 0000000..a4f627f --- /dev/null +++ b/vehicleservice/positioning/client/src/POS_sensor_API/Makefile @@ -0,0 +1,48 @@ +# +# @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +######### installed shared library(*.so) ############# +INST_SHLIBS = libPOS_sensor_API + +######### compiled sources ############# +libPOS_sensor_API_SRCS += Sensor_API.cpp +libPOS_sensor_API_SRCS += Vehicle_API.cpp + +######### add include path ############# +CPPFLAGS += -I../../../server/include/common +CPPFLAGS += -I../../include +CPPFLAGS += -I../../../server/include/nsfw + +######### add compile option ############# +CPPFLAGS += -DLINUX -fPIC + +LDFLAGS += -Wl,--no-undefined +LDFLAGS += -Wl,--no-as-needed +CPPFLAGS += -Werror=implicit-function-declaration +CPPFLAGS += -Werror=format-security +CPPFLAGS += -Wconversion +CPPFLAGS += -Wint-to-pointer-cast +CPPFLAGS += -Wpointer-arith +CPPFLAGS += -Wformat + +######### linked library (dynamic) ############# +LDLIBS += -Wl,-Bdynamic -lNS_FrameworkUnified +LDLIBS += -Wl,-Bdynamic -lPOS_base_API +LDLIBS += -Wl,-Bdynamic -lvp +######### add library path ############# +LDFLAGS += -shared + + +include ../../../../vehicle_service.mk diff --git a/vehicleservice/positioning/client/src/POS_sensor_API/Sensor_API.cpp b/vehicleservice/positioning/client/src/POS_sensor_API/Sensor_API.cpp new file mode 100755 index 0000000..179eb92 --- /dev/null +++ b/vehicleservice/positioning/client/src/POS_sensor_API/Sensor_API.cpp @@ -0,0 +1,784 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/******************************************************************************* + * File name :Sensor_API.cpp + * System name :GPF + * Subsystem name :Sensor I/F library + * Program name :SensorI/F API + ******************************************************************************/ + +#include <stdio.h> +#include <vehicle_service/POS_sensor_API.h> +#include <vehicle_service/POS_define.h> +#include <vehicle_service/POS_sensor_API.h> +#include <vehicle_service/positioning_base_library.h> +#include "POS_sensor_private.h" +#include "Sensor_Common_API.h" +#include "Sensor_API_private.h" +#include "Sensor_Common_API.h" +#include "Vehicle_API_Dummy.h" +#include "Vehicle_API_private.h" +#include "Naviinfo_API.h" +#include "POS_private.h" + +/*************************************************/ +/* Global variable */ +/*************************************************/ +/******************************************************************************** + * TAG :TG_GPS_REQ_RESET + * ABSTRACT :GPS reset request + * NOTE :I/F information between host applications(Reset mode) + ********************************************************************************/ +/** + * @brief POS_RegisterListenerPkgSensData Return code list + */ +static const SENSOR_RET_PKG g_ret_list_reg_lis_pkg_sens_data[SENSOR_PUBLIC_DID_NUM] = { + /* GRADE2 GRADE1 DID (Key) */ + {TRUE, TRUE, POS_DID_SPEED_PULSE }, + {FALSE, TRUE, POS_DID_SPEED_KMPH }, + {TRUE, TRUE, POS_DID_GYRO_X }, + {TRUE, TRUE, POS_DID_GYRO_Y }, + {TRUE, TRUE, POS_DID_GYRO_Z }, + {TRUE, TRUE, POS_DID_GSNS_X }, + {TRUE, TRUE, POS_DID_GSNS_Y }, + {TRUE, TRUE, POS_DID_GSNS_Z }, + {FALSE, TRUE, POS_DID_GPS_ANTENNA }, + {TRUE, TRUE, POS_DID_SNS_COUNTER }, + {FALSE, TRUE, POS_DID_SPEED_PULSE_FST }, + {FALSE, TRUE, POS_DID_GYRO_X_FST }, + {FALSE, TRUE, POS_DID_GYRO_Y_FST }, + {FALSE, TRUE, POS_DID_GYRO_Z_FST }, + {FALSE, TRUE, POS_DID_GPS__CWORD82__NMEA }, + {FALSE, TRUE, POS_DID_GPS__CWORD82___CWORD44_GP4 }, + {FALSE, TRUE, POS_DID_GPS__CWORD82__FULLBINARY }, + {FALSE, TRUE, POS_DID_GPS_NMEA }, + {TRUE, TRUE, POS_DID_REV }, + {FALSE, TRUE, POS_DID_REV_FST }, + {TRUE, TRUE, POS_DID_GYRO_TEMP }, + {FALSE, TRUE, POS_DID_GYRO_TEMP_FST }, + {FALSE, TRUE, POS_DID_GSNS_X_FST }, + {FALSE, TRUE, POS_DID_GSNS_Y_FST }, + {FALSE, TRUE, POS_DID_GSNS_Z_FST }, + {TRUE, TRUE, POS_DID_PULSE_TIME }, + {FALSE, TRUE, POS_DID_GPS_CLOCK_DRIFT }, + {FALSE, TRUE, POS_DID_GPS_CLOCK_FREQ }, + {FALSE, TRUE, VEHICLE_DID_GPS_TIME }, /* For local use */ + {FALSE, TRUE, VEHICLE_DID_GPS_TIME_RAW }, /* For local use */ + {FALSE, TRUE, VEHICLE_DID_GPS_WKNROLLOVER} /* For local use */ +}; + +/** + * @brief POS_RegisterListenerSensData Return code list + */ +static const SENSOR_RET_PKG g_ret_list_reg_lis_sens_data[SENSOR_PUBLIC_DID_NUM] = { + /* GRADE2 GRADE1 DID (Key) */ + {TRUE, TRUE, POS_DID_SPEED_PULSE }, + {FALSE, TRUE, POS_DID_SPEED_KMPH }, + {TRUE, TRUE, POS_DID_GYRO_X }, + {TRUE, TRUE, POS_DID_GYRO_Y }, + {TRUE, TRUE, POS_DID_GYRO_Z }, + {TRUE, TRUE, POS_DID_GSNS_X }, + {TRUE, TRUE, POS_DID_GSNS_Y }, + {TRUE, TRUE, POS_DID_GSNS_Z }, + {TRUE, TRUE, POS_DID_GPS_ANTENNA }, + {FALSE, TRUE, POS_DID_SNS_COUNTER }, + {TRUE, TRUE, POS_DID_SPEED_PULSE_FST }, + {TRUE, TRUE, POS_DID_GYRO_X_FST }, + {TRUE, TRUE, POS_DID_GYRO_Y_FST }, + {TRUE, TRUE, POS_DID_GYRO_Z_FST }, + {TRUE, TRUE, POS_DID_GPS__CWORD82__NMEA }, + {FALSE, TRUE, POS_DID_GPS__CWORD82___CWORD44_GP4 }, + {TRUE, TRUE, POS_DID_GPS__CWORD82__FULLBINARY }, + {FALSE, TRUE, POS_DID_GPS_NMEA }, + {FALSE, TRUE, POS_DID_REV }, + {TRUE, TRUE, POS_DID_REV_FST }, + {TRUE, TRUE, POS_DID_GYRO_TEMP }, + {TRUE, TRUE, POS_DID_GYRO_TEMP_FST }, + {TRUE, TRUE, POS_DID_GSNS_X_FST }, + {TRUE, TRUE, POS_DID_GSNS_Y_FST }, + {TRUE, TRUE, POS_DID_GSNS_Z_FST }, + {FALSE, TRUE, POS_DID_PULSE_TIME }, + {FALSE, TRUE, POS_DID_GPS_CLOCK_DRIFT }, + {FALSE, TRUE, POS_DID_GPS_CLOCK_FREQ }, + {FALSE, TRUE, VEHICLE_DID_GPS_TIME }, /* For local use */ + {FALSE, TRUE, VEHICLE_DID_GPS_TIME_RAW }, /* For local use */ + {FALSE, TRUE, VEHICLE_DID_GPS_WKNROLLOVER } /* For local use */ +}; + +/** + * @brief POS_GetSensData Return code list + */ +static const SENSOR_RET_PKG g_ret_list_get_sens_data[SENSOR_PUBLIC_DID_NUM] = { + /* GRADE2 GRADE1 DID (Key) */ + {TRUE, TRUE, POS_DID_SPEED_PULSE }, + {FALSE, TRUE, POS_DID_SPEED_KMPH }, + {TRUE, TRUE, POS_DID_GYRO_X }, + {TRUE, TRUE, POS_DID_GYRO_Y }, + {TRUE, TRUE, POS_DID_GYRO_Z }, + {TRUE, TRUE, POS_DID_GSNS_X }, + {TRUE, TRUE, POS_DID_GSNS_Y }, + {TRUE, TRUE, POS_DID_GSNS_Z }, + {TRUE, TRUE, POS_DID_GPS_ANTENNA }, + {FALSE, TRUE, POS_DID_SNS_COUNTER }, + {FALSE, TRUE, POS_DID_SPEED_PULSE_FST }, + {FALSE, TRUE, POS_DID_GYRO_X_FST }, + {FALSE, TRUE, POS_DID_GYRO_Y_FST }, + {FALSE, TRUE, POS_DID_GYRO_Z_FST }, + {TRUE, TRUE, POS_DID_GPS__CWORD82__NMEA }, + {FALSE, TRUE, POS_DID_GPS__CWORD82___CWORD44_GP4 }, + {TRUE, TRUE, POS_DID_GPS__CWORD82__FULLBINARY }, + {FALSE, TRUE, POS_DID_GPS_NMEA }, + {FALSE, TRUE, POS_DID_REV }, + {FALSE, TRUE, POS_DID_REV_FST }, + {TRUE, TRUE, POS_DID_GYRO_TEMP }, + {FALSE, TRUE, POS_DID_GYRO_TEMP_FST }, + {FALSE, TRUE, POS_DID_GSNS_X_FST }, + {FALSE, TRUE, POS_DID_GSNS_Y_FST }, + {FALSE, TRUE, POS_DID_GSNS_Z_FST }, + {FALSE, TRUE, POS_DID_PULSE_TIME }, + {FALSE, TRUE, POS_DID_GPS_CLOCK_DRIFT }, + {FALSE, TRUE, POS_DID_GPS_CLOCK_FREQ }, + {FALSE, TRUE, VEHICLE_DID_GPS_TIME }, /* For local use */ + {FALSE, TRUE, VEHICLE_DID_GPS_TIME_RAW }, /* For local use */ + {FALSE, TRUE, VEHICLE_DID_GPS_WKNROLLOVER } /* For local use */ +}; + +/** + * @brief + * DID-decision functions for Sensor API + * + * Determines whether or not the DID specified by the public API corresponds to the DID. + * + * @param[in] did Data ID + * @param[in] mode Operation mode 1:For Package Delivery Registration API<br> + * 2:For Sensor Data Delivery Registration API<br> + * 3:For Sensor Data Acquisition API + * + * @return TRUE Be supported + * FALSE Not supported + */ +BOOL SensorJudgeDid(DID did, uint8_t mode) { + BOOL ret = FALSE; + UNIT_TYPE type; + const SENSOR_RET_PKG *pkg_list = NULL; + int32_t i; + + /* Set Return pakage list */ + switch (mode) { + case MODE_REGISTER_LISTENER_PKG_SENS_DATA: /* POS_RegisterListenerPkgSensData */ + { + pkg_list = g_ret_list_reg_lis_pkg_sens_data; + break; + } + case MODE_REGISTER_LISTENER_SENSDATA: /* POS_RegisterListenerSensData */ + { + pkg_list = g_ret_list_reg_lis_sens_data; + break; + } + case MODE_GET_SENSDATA: /* POS_GetSensData */ + { + pkg_list = g_ret_list_get_sens_data; + break; + } + default: + /* Error log */ + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [mode = %d]", mode); + break; + } + + if (pkg_list != NULL) { + /* Search Return code list for DID */ + for (i = 0; i < SENSOR_PUBLIC_DID_NUM; i++) { + if (did == pkg_list[i].did) { + break; + } + } + + if (i != SENSOR_PUBLIC_DID_NUM) { + /* Get Unit type */ + type = GetEnvSupportInfo(); + switch (type) { + case UNIT_TYPE_GRADE1: + { + ret = pkg_list[i].GRADE1_ret; + break; + } + case UNIT_TYPE_GRADE2: + { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = pkg_list[i].GRADE2_ret; + break; + } + default: + /* Error log */ + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "GetEnvSupportInfo ERROR [type = %d]", type); + break; + } + } else { + /* Error log */ + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [did = %d]", did); + } + } + + return ret; +} + +/** + * @brief + * Vehicle Sensor Information Extended Package Delivery Registration + * Sensor information is delivered for the first time.,Extension Packaging and Registering for Delivery. + * + * @param[in] hApp Application handle + * @param[in] notifyName Destination thread name + * @param[in] ucPkgNum Number of package data(1 to 16) + * @param[in] *pulDid Pointer to an array of data IDs for vehicle information + * @param[in] ucCtrlFlg Delivery control<br> + * Delivery registration: SENSOR_DELIVERY_REGIST<br> + * Delivery stop: SENSOR_DELIVERY_STOP (Note: Not mounted)<br> + * Resume delivery: SENSOR_DELIVERY_RESTART (Note: Not mounted) + * @param[in] ucDeliveryTiming Delivery timing<br> + * Updating : SENSOR_DELIVERY_TIMING_UPDATE<br> + * Changing : SENSOR_DELIVERY_TIMING_CHANGE + * + * @return SENSOR_RET_NORMAL Successful registration<br> + * SENSOR_RET_ERROR_CREATE_EVENT Event generation failure<br> + * SENSOR_RET_ERROR_PARAM Parameter error<br> + * SENSOR_RET_ERROR_DID Unregistered ID<br> + * SENSOR_RET_ERROR_BUFFULL FULL of delivery registers<br> + * SENSOR_RET_ERROR_NOSUPPORT Unsupported environment<br> + * SENSOR_RET_ERROR_INNER Internal abnormality + * + */ +SENSOR_RET_API POS_RegisterListenerPkgSensData(HANDLE hApp, + PCSTR notifyName, + uint8_t ucPkgNum, + DID *pulDid, uint8_t ucCtrlFlg, uint8_t ucDeliveryTiming) { + SENSOR_RET_API ret; /* Return value */ + BOOL ret_b; + RET_API ret_api; /* System API return value */ + EventID event_id; /* Event ID */ + int32_t event_val; /* Event value */ + SENSOR_MSG_DELIVERY_ENTRY_DAT data; /* Message data */ + int32_t i; /* Generic counters */ + PNO ch_pno; /* Converted internal PNO */ + UNIT_TYPE type; /* Supported HW Configuration Type */ + + /* Internal debug log output */ + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+"); + + ret = SENSOR_RET_NORMAL; + /* Check Handle */ + if (hApp == NULL) { + /* NULL terminates with an abnormal parameter */ + ret = SENSOR_RET_ERROR_PARAM; + } + + if (ret == SENSOR_RET_NORMAL) { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Supported HW Configuration Check */ + type = GetEnvSupportInfo(); + if (UNIT_TYPE_GRADE1 == type) { + /* GRADE1 */ + ret = SENSOR_RET_NORMAL; + } else if (UNIT_TYPE_GRADE2 == type) { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = SENSOR_RET_ERROR_NOSUPPORT; + } else { + /* Environment error */ + ret = SENSOR_RET_ERROR_NOSUPPORT; + } + } + + if (ret == SENSOR_RET_NORMAL) { + /* Check Delivery Control Designation */ + if (SENSOR_DELIVERY_REGIST != ucCtrlFlg) { + /* Parameters other than delivery registration terminated abnormally. */ + ret = SENSOR_RET_ERROR_PARAM; + } else if ((ucDeliveryTiming != SENSOR_DELIVERY_TIMING_CHANGE) && + (ucDeliveryTiming != SENSOR_DELIVERY_TIMING_UPDATE)) { + /* Check delivery timing */ + /* Change delivery timing,Terminate as a parameter error except update */ + ret = SENSOR_RET_ERROR_PARAM; + } else if (notifyName == NULL) { + /* Check Thread Name */ + /* NULL terminates with an abnormal parameter */ + ret = SENSOR_RET_ERROR_PARAM; + } else if ((0 == ucPkgNum) || (SENSOR_PKG_DELIVERY_MAX < ucPkgNum)) { + /* Check Package Data Count */ + /* Out-of-range is terminated as a parameter error. */ + ret = SENSOR_RET_ERROR_PARAM; + } else if (pulDid == NULL) { + /* Check Data ID */ + /* NULL terminates with an abnormal parameter */ + ret = SENSOR_RET_ERROR_PARAM; + } else { + /* Check if data ID is acceptable */ + for (i = 0; i < ucPkgNum; i++) { + /* Judge DID */ + ret_b = SENSOR_DID_JUDGE_REGLIS_PKG(pulDid[i]); + if (ret_b == FALSE) { + /* An unacceptable ID terminates with an abnormal parameter. */ + ret = SENSOR_RET_ERROR_PARAM; + break; + } else { + ret = SENSOR_RET_NORMAL; + } + } + } + } + + if (ret == SENSOR_RET_NORMAL) { + /* Resource acquisition */ + if (VehicleGetResource() == TRUE) { + + /* Initialization */ + event_id = 0; + event_val = 0; + memset(reinterpret_cast<void *>(&data), 0, sizeof(SENSOR_MSG_DELIVERY_ENTRY_DAT)); + + /* Get PNO from Thread Name */ + ch_pno = _pb_CnvName2Pno(notifyName); + + /* Event Generation */ + event_id = PosCreateEvent(ch_pno); + + if (0 != event_id) { + /* Successful event generation */ + + /*--------------------------------------------------------------* + * Send Vehicle Sensor Information Delivery Registration Message * + *--------------------------------------------------------------*/ + /* Create Message Data */ + data.pno = ch_pno; + data.pkg_num = ucPkgNum; + data.delivery_timing = ucDeliveryTiming; + data.ctrl_flg = ucCtrlFlg; + data.event_id = event_id; + for (i = 0; i < ucPkgNum; i++) { + data.did[i] = pulDid[i]; + } + + /* Messaging */ + ret_api = PosSndMsg(ch_pno, + PNO_VEHICLE_SENSOR, + CID_SENSORIF_PKG_DELIVERY_ENTRY_EXT, + (uint16_t)sizeof(SENSOR_MSG_DELIVERY_ENTRY_DAT), + (const void *)&data); + + if (RET_NORMAL == ret_api) { + /* Message transmission processing is successful */ + /* Wait for completion event from vehicle sensor thread */ + ret_api = _pb_WaitEvent(event_id, + SAPI_EVWAIT_VAL, + SENSOR_RET_ERROR_MIN, + SENSOR_RET_NORMAL, + &event_val, + POS_API_TIME_OUT_MS); + if (RET_NORMAL != ret_api) { + /* Return an internal error */ + ret = SENSOR_RET_ERROR_INNER; + } else { + /* Return from Event Wait */ + /* Set event value (processing result) as return value */ + ret = (SENSOR_RET_API)event_val; + } + } else { + /* Message transmission processing failed */ + /* Return an internal error */ + ret = SENSOR_RET_ERROR_INNER; + } + + /* Event deletion */ + ret_api = PosDeleteEvent(event_id); + } else { + /* Event generation failure */ + ret = SENSOR_RET_ERROR_CREATE_EVENT; + } + } else { + /* When resource shortage occurs, the system terminates with an insufficient resource error. */ + ret = SENSOR_RET_ERROR_RESOURCE; + } + /* Resource release */ + VehicleReleaseResource(); + } + + /* Internal debug log output */ + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "- [ret = %d]", ret); + + return ret; +} + +/******************************************************************************* + * MODULE : PosCreateEvent + * ABSTRACT : Event creation process + * FUNCTION : Generate an event + * ARGUMENT : pno : Thread ID + * NOTE : + * RETURN : Non-zero : Event ID + * : Zero : Event generation failure + ******************************************************************************/ +EventID PosCreateEvent(PNO pno) { + EventID event_id; /* Event ID */ + char event_name[32]; /* Event name character string buffer */ + RET_API ret_api; /* System API return value */ + + /* Initialization of event name character string buffer */ + (void)memset(reinterpret_cast<void *>(event_name), 0, sizeof(event_name)); + + /* Event name creation */ + snprintf(event_name, sizeof(event_name), "SENSOR_%X", pno); /* Ignore->MISRA-C++:2008 Rule 5-2-12 */ + + /* Event Generation */ + event_id = _pb_CreateEvent(FALSE , 0, event_name); /* Ignore->MISRA-C++:2008 Rule 5-2-12 */ + + if (0 != event_id) { + /* For successful event generation */ + + /* Initialize the event */ + ret_api = _pb_SetEvent(event_id, SAPI_EVSET_ABSOLUTE, SENSOR_EVENT_VAL_INIT); + if (RET_NORMAL != ret_api) { + /* Event initialization failed */ + + /* Delete Event and Return Event Generation Failed */ + ret_api = PosDeleteEvent(event_id); + event_id = 0; + } + } + + return event_id; +} + +/******************************************************************************* + * MODULE : PosDeleteEvent + * ABSTRACT : Event deletion processing + * FUNCTION : Delete events + * ARGUMENT : event_id : Event ID of the event to delete + * NOTE : + * RETURN : RET_NORMAL : Normal completion + * : RET_EV_NONE : Specified event does not exist + ******************************************************************************/ +RET_API PosDeleteEvent(EventID event_id) { + return(_pb_DeleteEvent(event_id)); +} + +/******************************************************************************* + * MODULE : SensorLinkShareData + * ABSTRACT : Link to shared memory + * FUNCTION : Link to shared memory + * ARGUMENT : **share_top : Storage destination of shared memory top address + * : *share_size : Storage destination of shared memory area size + * : *offset : Offset storage destination to free shared memory area + * NOTE : + * RETURN : RET_NORMAL : Normal completion + * : RET_ERROR : There is no shared memory area. + ******************************************************************************/ +RET_API SensorLinkShareData(void **share_top, uint32_t *share_size, uint16_t *offset) { // LCOV_EXCL_START 8:dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + RET_API ret_api; /* System API return value */ + SemID sem_id; /* Semaphore ID */ + SENSOR_SHARE *share_top_tmp; + int32_t i; + + /* Initialization */ + ret_api = RET_ERROR; + + /* Create Semaphore */ + sem_id = _pb_CreateSemaphore(const_cast<char *>(SENSOR_SEMAPHO_NAME)); + if (0 != sem_id) { + /* Semaphore Lock */ + ret_api = _pb_SemLock(sem_id); + if (RET_NORMAL == ret_api) { + /* Link to shared memory */ + ret_api = _pb_LinkShareData(const_cast<char *>(SENSOR_SHARE_NAME), share_top, share_size); + if (RET_NORMAL == ret_api) { + /* By searching the free shared memory area,Offset is calculated if there is free space. */ + share_top_tmp = reinterpret_cast<SENSOR_SHARE *>(*share_top); + + /* Because the first block of the shared memory area is the control area,Loop from i = 1 */ + for (i = 1; i < SENSOR_SHARE_BLOCK_NUM; i++) { + if (SENSOR_SHARE_UNLOCK == share_top_tmp->mng.lock_info[i]) { + break; + } + } + if (i < SENSOR_SHARE_BLOCK_NUM) { + /* Empty space */ + /* Lock the block */ + share_top_tmp->mng.lock_info[i] = SENSOR_SHARE_LOCK; + + /* Calculate the offset to the block */ + *offset = static_cast<uint16_t>(i * SENSOR_SHARE_BLOCK_SIZE); + + /* Normal completion */ + ret_api = RET_NORMAL; + } else { + /* No free space */ + ret_api = RET_ERROR; + } + } else { + /* Failed link to shared memory */ + ret_api = RET_ERROR; + } + /* Semaphore unlock */ + _pb_SemUnlock(sem_id); + } else { + /* Semaphore lock failed */ + ret_api = RET_ERROR; + } + } else { + /* Semaphore creation failed */ + ret_api = RET_ERROR; + } + + return ret_api; +} +// LCOV_EXCL_STOP + +/******************************************************************************* + * MODULE : SensorUnLinkShareData + * ABSTRACT : Unlinking shared memory + * FUNCTION : Unlink shared memory + * ARGUMENT : *share_top : Start address of shared memory + * : offset : Offset to shared memory free area + * NOTE : + * RETURN : RET_NORMAL : Normal completion + * : RET_ERROR : There is no shared memory area./semaphore error + ******************************************************************************/ +RET_API SensorUnLinkShareData(SENSOR_SHARE *share_top, uint16_t offset) { // LCOV_EXCL_START 8:dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + RET_API ret_api; /* System API return value */ + SemID sem_id; /* Semaphore ID */ + int32_t i; + + /* Initialization */ + ret_api = RET_ERROR; + + /* Create Semaphore */ + sem_id = _pb_CreateSemaphore(const_cast<char *>(SENSOR_SEMAPHO_NAME)); + if (0 != sem_id) { + /* Semaphore Lock */ + ret_api = _pb_SemLock(sem_id); + if (RET_NORMAL == ret_api) { + /* Unlock the block */ + i = static_cast<int32>(offset) / SENSOR_SHARE_BLOCK_SIZE; + share_top->mng.lock_info[i] = SENSOR_SHARE_UNLOCK; + + /* Semaphore unlock */ + _pb_SemUnlock(sem_id); + + /* Normal completion */ + ret_api = RET_NORMAL; + } else { + /* Semaphore lock failed */ + ret_api = RET_ERROR; + } + } else { + /* Semaphore creation failed */ + ret_api = RET_ERROR; + } + + return ret_api; +} +// LCOV_EXCL_STOP + +/******************************************************************************* + * MODULE : SensorSetShareData + * ABSTRACT : Write processing to shared memory + * FUNCTION : Write shared memory + * ARGUMENT : *share_top : Start address of shared memory + * : offset : Offsets to shared memory write destination + * : *data_src : + : size_src : + * NOTE : + * RETURN : void + ******************************************************************************/ +void SensorSetShareData(void *share_top, uint16_t offset, const void *data_src, uint16_t size_src) { // LCOV_EXCL_START 8:dead code // NOLINT(whitespace/line_length) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + SENSOR_SHARE_BLOCK_DAT *share_dat; + + /* Calculate Shared Memory Write Address */ + share_dat = reinterpret_cast<SENSOR_SHARE_BLOCK_DAT *>(reinterpret_cast<uint8_t *>(share_top) + offset); + /* #QAC confirmation Rule11.4 Use structure for member reference(Cast according to shared memory link IF) */ + + /* Clear Shared Memory */ + memset(reinterpret_cast<void *>(share_dat), 0, sizeof(SENSOR_SHARE_BLOCK_DAT)); + + /* Set write size to shared memory */ + share_dat->size = size_src; + + /* Set specified data in shared memory */ + memcpy(reinterpret_cast<void *>(&share_dat->data), data_src, (size_t)size_src); +} +// LCOV_EXCL_STOP + +/******************************************************************************* + * MODULE : PosSndMsg + * ABSTRACT : Message transmission processing + * FUNCTION : Send a message to the specified PNO + * ARGUMENT : pno_src : Source PNO + * : pno_dest : Destination PNO + * : cid : Command ID + * : msg_len : Message data body length + * : *msg_len : Pointer to message data + * NOTE : + * RETURN : RET_NORMAL : Normal completion + * : RET_ERRNOTRDY : Destination process is not wakeup + * : RET_ERRMSGFULL : Message queue overflows + * : RET_ERRPARAM : Buffer size error + ******************************************************************************/ +RET_API PosSndMsg(PNO pno_src, PNO pno_dest, CID cid, uint16_t msg_len, const void *msg_data) { + SENSOR_INTERNAL_MSG_BUF msg_buf; /* message buffer */ + T_APIMSG_MSGBUF_HEADER *msg_hdr; /* Pointer to the message header */ + RET_API ret_api; /* Return value */ + PCSTR thread_name; /* Destination thread name */ + + /* Internal debug log output */ + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "+"); + + /* _CWORD71_ processing speed(Memset modification) */ + /* Initializing the header of the message buffer */ + memset(reinterpret_cast<void *>(&msg_buf.hdr), 0, sizeof(T_APIMSG_MSGBUF_HEADER)); + + /* Get pointer to send buffer */ + msg_hdr = reinterpret_cast<T_APIMSG_MSGBUF_HEADER *>(reinterpret_cast<void *>(&msg_buf)); + + /*--------------------------------------------------------------* + * Create message headers * + *--------------------------------------------------------------*/ + msg_hdr->hdr.sndpno = pno_src; /* Source PNO */ + msg_hdr->hdr.cid = cid; /* Command ID */ + msg_hdr->hdr.msgbodysize = msg_len; /* Message data body length */ + + /*--------------------------------------------------------------* + * Create message data * + *--------------------------------------------------------------*/ + if ((0 != msg_data) && (0 != msg_len)) { /* Ignore->MISRA-C++:2008 Rule 5-0-5 */ + /* Set the message data */ + memcpy(reinterpret_cast<void *>(msg_buf.data), msg_data, (size_t)msg_len); + } + /*--------------------------------------------------------------* + * Send messages * + *--------------------------------------------------------------*/ + /* Get Thread Name from PNO */ + if (pno_dest <= SYS_PNO_MAX) { + thread_name = POS_THREAD_NAME; + } else { + thread_name = _pb_CnvPno2Name(pno_dest); + } + + if ((pno_dest <= SYS_PNO_MAX) && (pno_src <= SYS_PNO_MAX)) { + /* Internal debug log output */ + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "[LOG pno_dest = 0x%x]", pno_dest); + + /* Internal Process Transmission and Reception Messages */ + ret_api = _pb_SndMsg(pno_dest, + (uint16_t)(sizeof(T_APIMSG_MSGBUF_HEADER) + msg_len),/* Ignore->MISRA-C++:2008 Rule 5-0-5 */ + reinterpret_cast<void *>(&msg_buf), 0); + } else { + /* Internal debug log output */ + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, + "[LOG thread_name = %s, cid = 0x%x]", thread_name, cid); + + /* External Process Transmission and Reception Messages */ + ret_api = _pb_SndMsg_Ext(thread_name, + cid, + (uint16_t)(msg_len), /* Ignore->MISRA-C++:2008 Rule 5-0-5 */ + reinterpret_cast<void *>(&(msg_buf.data)), 0); + } + /* If RET_ERROR,Register a dialog if called from a Vehicle related thread */ /* Task_30332 */ + if (ret_api == RET_ERROR) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "[ERROR]"); + } + + /* Internal debug log output */ + FRAMEWORKUNIFIEDLOG(ZONE_26, __FUNCTION__, "- [ret = %d]", ret_api); + + return ret_api; +} + +/** + * @brief + * Sensor information acquisition + * + * Obtain sensor information + * + * @param[in] hApp HANDLE - Application handle + * @param[in] did DID - Data ID for vehicle information + * @param[in] dest_data void* - Pointer representing the storage destination of vehicle sensor information + * @param[in] dest_size uint16_t - Storage destination size of vehicle sensor information(byte) + * + * @return 0 or more Stored data size(Include illegal)<br> + * POS_RET_ERROR_CREATE_EVENT Event generation failure<br> + * POS_RET_ERROR_OUTOF_MEMORY Shared memory allocation failed<br> + * POS_RET_ERROR_SIZE Storage destination size error<br> + * POS_RET_ERROR_DID Unregistered ID<br> + * POS_RET_ERROR_NOSUPPORT Unsupported environment + * + */ +POS_RET_API POS_GetSensData(HANDLE hApp, DID did, void *dest_data, uint16_t dest_size) +{ + POS_RET_API ret; /* Return value */ + UNIT_TYPE type = UNIT_TYPE_NONE; /* Supported HW Configuration Type */ + BOOL ret_b; + + /** NULL checking */ + if ((hApp == NULL) || (dest_data == NULL)) { + /** Parameter error */ + ret = POS_RET_ERROR_PARAM; + } else { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Supported HW Configuration Check */ + type = GetEnvSupportInfo(); + if (UNIT_TYPE_GRADE1 == type) { + /* GRADE1 */ + ret = POS_RET_NORMAL; + } else if (UNIT_TYPE_GRADE2 == type) { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = POS_RET_ERROR_NOSUPPORT; + } else { + /* Environment error */ + ret = POS_RET_ERROR_NOSUPPORT; + } + } + + if (ret == NAVIINFO_RET_NORMAL) { + /* Judge DID*/ + ret_b = SENSOR_DID_JUDGE_GET(did); + if (ret_b == FALSE) { + /* An unacceptable ID is regarded as a parameter error. */ + ret = POS_RET_ERROR_PARAM; + } else { + /* Data acquisition process */ + ret = PosGetProc(did, dest_data, dest_size); + } + } + + return ret; +} diff --git a/vehicleservice/positioning/client/src/POS_sensor_API/Vehicle_API.cpp b/vehicleservice/positioning/client/src/POS_sensor_API/Vehicle_API.cpp new file mode 100755 index 0000000..3cd97f8 --- /dev/null +++ b/vehicleservice/positioning/client/src/POS_sensor_API/Vehicle_API.cpp @@ -0,0 +1,292 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/******************************************************************************* + * File name :Vehicle_API.cpp + * System name :GPF + * Subsystem name :Vehicle I/F library + * Program name :Vehicle I/F API + * Module configuration :POS_RegisterListenerSensData() Vehicle sensor information delivery registration + ******************************************************************************/ +#include <vehicle_service/positioning_base_library.h> +#include <stdio.h> +#include <vehicle_service/POS_sensor_API.h> +#include "Sensor_API_private.h" +#include "Vehicle_API_Dummy.h" +#include "Vehicle_API_private.h" +#include "POS_private.h" + +/*************************************************/ +/* Global variable */ +/*************************************************/ + +/******************************************************************************* + * initialize +******************************************************************************/ +VEHICLE_RET_API VehicleInitialize(u_int32 (*sighand)()) { // LCOV_EXCL_START 8:dead code // NOLINT(readability/nolint) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + RET_API _CWORD64_api_ret; + VEHICLE_RET_API ret; + + _CWORD64_api_ret = _pb_Setup_CWORD64_API(NULL); + + if (_CWORD64_api_ret == RET_NORMAL) { + ret = RET_NORMAL; + } else { + ret = RET_ERROR; + } + return ret; +} +// LCOV_EXCL_STOP + +/** + * @brief + * Vehicle sensor information delivery registration + * Register delivery of vehicle sensor information + * + * @param[in] hApp Application handle + * @param[in] notifyName Destination thread name + * @param[in] ulDid Pointer to an array of data IDs for vehicle information + * @param[in] ucCtrlFlg Delivery control<br> + * Delivery registration: SENSOR_DELIVERY_REGIST<br> + * Delivery stop: SENSOR_DELIVERY_STOP (Note: Not mounted)<br> + * Resume delivery: SENSOR_DELIVERY_RESTART (Note: Not mounted) + * @param[in] ucDeliveryTiming Delivery timing<br> + * Updating : SENSOR_DELIVERY_TIMING_UPDATE<br> + * Changing : SENSOR_DELIVERY_TIMING_CHANGE + * + * @return SENSOR_RET_NORMAL Successful registration<br> + * SENSOR_RET_ERROR_CREATE_EVENT Event generation failure<br> + * SENSOR_RET_ERROR_PARAM Parameter error<br> + * SENSOR_RET_ERROR_DID Unregistered ID<br> + * SENSOR_RET_ERROR_BUFFULL FULL of delivery registers<br> + * SENSOR_RET_ERROR_NOSUPPORT Unsupported environment + * + */ +SENSOR_RET_API POS_RegisterListenerSensData(HANDLE hApp, + PCSTR notifyName, DID ulDid, u_int8 ucCtrlFlg, u_int8 ucDeliveryTiming) { + SENSOR_RET_API ret; /* Return value */ + UNIT_TYPE type; /* Supported HW Configuration Type */ + BOOL ret_b; + + /* Internal debug log output */ + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "+"); + + /* Check Delivery Control Designation */ + ret = SENSOR_RET_NORMAL; + /* Arguments & Support Configuration Check */ + if ((ucDeliveryTiming != SENSOR_DELIVERY_TIMING_CHANGE) && + (ucDeliveryTiming != SENSOR_DELIVERY_TIMING_UPDATE)) { + /* Change delivery timing,Terminate as a parameter error except update */ + ret = SENSOR_RET_ERROR_PARAM; + } else if (SENSOR_DELIVERY_REGIST != ucCtrlFlg) { + /* Parameters other than delivery registration terminated abnormally. */ + ret = SENSOR_RET_ERROR_PARAM; + } else if (hApp == NULL) { + /* Check Handle */ + /* NULL terminates with an abnormal parameter */ + ret = SENSOR_RET_ERROR_PARAM; + } else if (notifyName == NULL) { + /* Check Thread Name */ + /* NULL terminates with an abnormal parameter */ + ret = SENSOR_RET_ERROR_PARAM; + } else { + /* Positioning Base API initialization */ + _pb_Setup_CWORD64_API(hApp); + + /* Supported HW Configuration Check */ + type = GetEnvSupportInfo(); + if (UNIT_TYPE_GRADE1 == type) { + /* GRADE1 */ + ret = SENSOR_RET_NORMAL; + } else if (UNIT_TYPE_GRADE2 == type) { + /* + * Note. + * This feature branches processing depending on the unit type. + */ + ret = SENSOR_RET_ERROR_NOSUPPORT; + } else { + /* Environment error */ + ret = SENSOR_RET_ERROR_NOSUPPORT; + } + } + + if (SENSOR_RET_NORMAL == ret) { + /* Judge DID */ + ret_b = SENSOR_DID_JUDGE_REGLIS(ulDid); + if (ret_b == FALSE) { + /* An unacceptable ID is regarded as a parameter error. */ + ret = SENSOR_RET_ERROR_PARAM; + } else { + /* Delivery registration process */ + ret = PosRegisterListenerProc(notifyName, ulDid, ucCtrlFlg, ucDeliveryTiming); + } + } + + /* Internal debug log output */ + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "- [ret = %d]", ret); + + return ret; +} + +/******************************************************************************* + * MODULE : PosSetShareData + * ABSTRACT : Write processing to shared memory + * FUNCTION : Write shared memory + * ARGUMENT : *share_top : Start address of shared memory + * : offset : Offsets to shared memory write destination + * : *data_src : Data + * : size_src : Size + * NOTE : + * RETURN : void + ******************************************************************************/ +void PosSetShareData(void *share_top, u_int16 offset, const void *data_src, u_int16 size_src) { + VEHICLE_SHARE_BLOCK_DAT *share_dat; + /* Calculate Shared Memory Write Address */ + share_dat = reinterpret_cast<VEHICLE_SHARE_BLOCK_DAT *>(reinterpret_cast<u_int8 *>(share_top) + offset); + + /* _CWORD71_ processing speed(Memset modification) */ + /* Clear Shared Memory(Unused area) */ + share_dat->reserve[0] = 0; + share_dat->reserve[1] = 0; + + /* Set write size to shared memory */ + share_dat->size = size_src; + + /* Set specified data in shared memory */ + memcpy(reinterpret_cast<void *>(share_dat->data), data_src, (size_t)size_src); +} + +/******************************************************************************* +* MODULE : VehicleGetDrData +* ABSTRACT : DR information acquisition +* FUNCTION : Retrieves DR information (optional data) by returning to completion. +* ARGUMENT : pno : Thread ID +* : did : Data ID for DR information +* : *dest_data : Pointer to the storage destination of DR information +* : dest_size : Storage destination size of DR information(byte) +* NOTE : +* RETURN : Zero or more : Stored data size +* : VEHICLE_RET_ERROR_CREATE_EVENT : Event generation failure +* : VEHICLE_RET_ERROR_OUTOF_MEMORY : Shared memory allocation failed +* : VEHICLE_RET_ERROR_SIZE : Storage destination size error +* : VEHICLE_RET_ERROR_DID : Unregistered ID +******************************************************************************/ +int32 VehicleGetDrData(PNO pno, DID did, void *dest_data, u_int16 dest_size) { // LCOV_EXCL_START 8:dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + VEHICLE_RET_API ret; /* Return value */ + RET_API ret_api; /* System API return value */ + EventID event_id; /* Event ID */ + int32 event_val; /* Event value */ + void *share_top; /* Start address of shared memory */ + u_int32 share_size; /* Size of shared memory area */ + u_int16 offset; /* Offset to free shared memory area */ + VEHICLE_SHARE_BLOCK_DAT *share_dat; /* Address of free shared memory area */ + VEHICLE_MSG_GET_VEHICLE_DATA_DAT data; /* Message data */ + + /* Initialization */ + event_id = 0; + event_val = 0; + memset(reinterpret_cast<void *>(&data), 0, sizeof(VEHICLE_MSG_GET_VEHICLE_DATA_DAT)); + + /* Event Generation */ + event_id = VehicleCreateEvent(pno); + + if (0 != event_id) { + /* Successful event generation */ + /* Allocate shared memory */ + ret_api = VehicleLinkShareData(reinterpret_cast<void **>(&share_top), &share_size, &offset); + if (RET_NORMAL != ret_api) { + /* Failed to allocate shared memory */ + ret = VEHICLE_RET_ERROR_OUTOF_MEMORY; + } else { + /* When the shared memory is allocated successfully */ + + /* Calculate start address of free shared memory area */ + share_dat = reinterpret_cast<VEHICLE_SHARE_BLOCK_DAT *>(reinterpret_cast<u_int8 *>(share_top) + offset); + + /* Send vehicle sensor information acquisition message */ + data.did = did; + data.pno = pno; + data.offset = offset; + data.size = VEHICLE_SHARE_BLOCK_DSIZE; + data.event_id = event_id; + /* Messaging */ + + ret_api = VehicleSndMsg(pno, + PNO_VEHICLE_SENSOR, + CID_VEHICLEIF_GET_DR_DATA, + sizeof(VEHICLE_MSG_GET_VEHICLE_DATA_DAT), + (const void *)&data); + + if (RET_NORMAL == ret_api) { + /* Message transmission processing is successful */ + /* Wait for completion event from vehicle sensor thread */ + ret_api = _pb_WaitEvent(event_id, + SAPI_EVWAIT_VAL, + VEHICLE_RET_ERROR_MIN, VEHICLE_RET_NORMAL, &event_val, INFINITE); + if (RET_NORMAL != ret_api) { + /* When not put in event wait state */ + /* Return an event generation failure */ + ret = VEHICLE_RET_ERROR_CREATE_EVENT; + } else { + /* Return from Event Wait */ + + /* Link to shared memory */ + ret_api = _pb_LinkShareData(const_cast<char *>(VEHICLE_SHARE_NAME), &share_top, &share_size); + + /* Calculate the address of the shared memory storage area. */ + share_dat = reinterpret_cast<VEHICLE_SHARE_BLOCK_DAT *>(reinterpret_cast<u_int8 *>(share_top) + + offset); + + if (event_val < 0) { + /* Vehicle sensor information acquisition failure */ + ret = (VEHICLE_RET_API)event_val; + } else if (RET_NORMAL != ret_api) { + /* Shared memory error */ + ret = VEHICLE_RET_ERROR_OUTOF_MEMORY; + } else if (dest_size < share_dat->size) { + /* Storage destination size error */ + ret = VEHICLE_RET_ERROR_SIZE; + } else { + /* Vehicle sensor information acquisition success */ + + /* Copy from shared memory to user memory */ + memcpy(dest_data, share_dat->data, (size_t)share_dat->size); + + /* Set Write Size to Return Value */ + ret = static_cast<int32>(share_dat->size); + } + } + } else { + /* Message transmission processing failed */ + /* Return an event generation failure */ + ret = VEHICLE_RET_ERROR_CREATE_EVENT; + } + /* Free shared memory */ + (void)VehicleUnLinkShareData(reinterpret_cast<VEHICLE_SHARE*>(share_top), offset); + } + + /* Event deletion */ + ret_api = VehicleDeleteEvent(event_id); + + } else { + /* Event generation failure */ + ret = VEHICLE_RET_ERROR_CREATE_EVENT; + } + return ret; +} +// LCOV_EXCL_STOP diff --git a/vehicleservice/positioning/client/src/POS_sensor_API/libPOS_sensor_API.ver b/vehicleservice/positioning/client/src/POS_sensor_API/libPOS_sensor_API.ver new file mode 100755 index 0000000..10fd95b --- /dev/null +++ b/vehicleservice/positioning/client/src/POS_sensor_API/libPOS_sensor_API.ver @@ -0,0 +1,32 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +# +# libPOS_sensor_API version script +# +{ + global: + POS_GetSensData; + POS_RegisterListenerPkgSensData; + POS_RegisterListenerSensData; + *PosSndMsg*; + *PosCreateEvent*; + *PosDeleteEvent*; + *PosSetShareData*; + local: + *; +}; + |