From ddec368a81cabd56f90147086c8ba97fc0dd69e8 Mon Sep 17 00:00:00 2001 From: sidecai <1142566470@qq.com> Date: Thu, 28 Aug 2025 15:53:14 +0800 Subject: [PATCH] batching Signed-off-by: sidecai <1142566470@qq.com> --- .../gnss/hdi_service/gnss_interface_impl.cpp | 76 +++++++++++++++++-- 1 file changed, 69 insertions(+), 7 deletions(-) diff --git a/location/gnss/hdi_service/gnss_interface_impl.cpp b/location/gnss/hdi_service/gnss_interface_impl.cpp index b7c767ae95..34fb6a9764 100644 --- a/location/gnss/hdi_service/gnss_interface_impl.cpp +++ b/location/gnss/hdi_service/gnss_interface_impl.cpp @@ -252,6 +252,38 @@ void NmeaCallback(int64_t timestamp, const char* nmea, int length) } } +void CachedLocationUpdate(const GnssLocation** locationArray, size_t arrayLength) +{ + std::vector locationArrayNew; + for (size_t i = 0; i < arrayLength; i++) { + if (locationArray[i] == nullptr) { + continue; + } + LocationInfo locationNew; + locationNew.fieldValidity = locationArray[i]->fieldValidity; + locationNew.latitude = locationArray[i]->latitude; + locationNew.longitude = locationArray[i]->longitude; + locationNew.altitude = locationArray[i]->altitude; + locationNew.horizontalAccuracy = locationArray[i]->horizontalAccuracy; + locationNew.speed = locationArray[i]->speed; + locationNew.bearing = locationArray[i]->bearing; + locationNew.verticalAccuracy = locationArray[i]->verticalAccuracy; + locationNew.speedAccuracy = locationArray[i]->speedAccuracy; + locationNew.bearingAccuracy = locationArray[i]->bearingAccuracy; + locationNew.timeForFix = locationArray[i]->timeForFix; + locationNew.timeSinceBoot = locationArray[i]->timeSinceBoot; + locationNew.timeUncertainty = locationArray[i]->timeUncertainty; + locationArrayNew.push_back(locationNew); + } + std::unique_lock lock(g_mutex); + for (const auto& iter : g_locationCallBackMap) { + auto& callback = iter.second; + if (callback != nullptr) { + callback->ReportCachedLocation(locationArrayNew); + } + } +} + void GetGnssBasicCallbackMethods(GnssBasicCallbackIfaces* device) { if (device == nullptr) { @@ -272,8 +304,8 @@ void GetGnssCacheCallbackMethods(GnssCacheCallbackIfaces* device) if (device == nullptr) { return; } - device->size = 0; - device->cachedLocationUpdate = nullptr; + device->size = sizeof(GnssCacheCallbackIfaces); + device->cachedLocationUpdate = CachedLocationUpdate; } void GetGnssCallbackMethods(GnssCallbackStruct* device) @@ -318,11 +350,21 @@ int32_t GnssInterfaceImpl::SetGnssConfigPara(const GnssConfigPara& para) HDF_LOGE("%{public}s:GetGnssVendorInterface return nullptr.", __func__); return HDF_ERR_INVALID_PARAM; } - g_configPara.startCategory = static_cast(GnssStartCategory::GNSS_START_CATEGORY_NORMAL); - g_configPara.u.gnssBasicConfig.gnssMode = para.gnssBasic.gnssMode; - g_configPara.u.gnssBasicConfig.size = sizeof(GnssBasicConfigPara); - int ret = gnssInterface->setGnssConfigPara(&g_configPara); - HDF_LOGI("%{public}s, ret=%{public}d", __func__, ret); + int ret; + if (para.gnssBasic.gnssMode < GNSS_WORKING_MODE_STANDALONE) { + g_configPara.startCategory = static_cast(GnssStartCategory::GNSS_START_CATEGORY_GNSS_CACHE); + g_configPara.u.gnssCacheConfig.interval = para.gnssCaching.interval; + g_configPara.u.gnssCacheConfig.fifoFullNotify = para.gnssCaching.fifoFullNotify; + g_configPara.u.gnssCacheConfig.size = sizeof(GnssCachingConfig); + ret = gnssInterface->setGnssConfigPara(&g_configPara); + HDF_LOGI("%{public}s, cache ret=%{public}d", __func__, ret); + } else { + g_configPara.startCategory = static_cast(GnssStartCategory::GNSS_START_CATEGORY_NORMAL); + g_configPara.u.gnssBasicConfig.gnssMode = para.gnssBasic.gnssMode; + g_configPara.u.gnssBasicConfig.size = sizeof(GnssBasicConfigPara); + ret = gnssInterface->setGnssConfigPara(&g_configPara); + HDF_LOGI("%{public}s, gnss ret=%{public}d", __func__, ret); + } return ret; } @@ -480,12 +522,32 @@ int32_t GnssInterfaceImpl::SetPredictGnssData(const std::string& data) int32_t GnssInterfaceImpl::GetCachedGnssLocationsSize(int32_t& size) { HDF_LOGI("%{public}s.", __func__); + auto gnssInterface = LocationVendorInterface::GetInstance()->GetGnssVendorInterface(); + if (gnssInterface == nullptr) { + HDF_LOGE("%{public}s:GetGnssVendorInterface return nullptr.", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (gnssInterface->getCachedLocationsSize == nullptr) { + HDF_LOGE("%{public}s:getCachedLocationsSize return nullptr.", __func__); + return HDF_ERR_INVALID_PARAM; + } + size = gnssInterface->getCachedLocationsSize(); return HDF_SUCCESS; } int32_t GnssInterfaceImpl::GetCachedGnssLocations() { HDF_LOGI("%{public}s.", __func__); + auto gnssInterface = LocationVendorInterface::GetInstance()->GetGnssVendorInterface(); + if (gnssInterface == nullptr) { + HDF_LOGE("%{public}s:GetGnssVendorInterface return nullptr.", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (gnssInterface->flushCachedGnssLocations == nullptr) { + HDF_LOGE("%{public}s:flushCachedGnssLocations return nullptr.", __func__); + return HDF_ERR_INVALID_PARAM; + } + gnssInterface->flushCachedGnssLocations(); return HDF_SUCCESS; } -- Gitee