From 0ed5cdcbd21739241356e6253a5b78a267192710 Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Mon, 21 Mar 2022 11:03:14 +0800 Subject: [PATCH 1/2] Signed-off-by:hellohyh001 Signed-off-by: hellohyh001 --- interfaces/native/src/geomagnetic_field.cpp | 4 +-- .../hardware/include/hdi_service_impl.h | 2 +- .../hardware/src/hdi_service_impl.cpp | 27 +++++++++++-------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/interfaces/native/src/geomagnetic_field.cpp b/interfaces/native/src/geomagnetic_field.cpp index 239f16c9..1b7c0f2d 100644 --- a/interfaces/native/src/geomagnetic_field.cpp +++ b/interfaces/native/src/geomagnetic_field.cpp @@ -181,8 +181,8 @@ void GeomagneticField::GetLongitudeTrigonometric() cosMLongitude[0] = 1.0f; sinMLongitude[1] = static_cast(sin(geocentricLongitude)); cosMLongitude[1] = static_cast(cos(geocentricLongitude)); - for (int32_t index = 2; index < GAUSSIAN_COEFFICIENT_DIMENSION; ++index) { - int32_t x = index >> 1; + for (uint32_t index = 2; index < GAUSSIAN_COEFFICIENT_DIMENSION; ++index) { + uint32_t x = index >> 1; sinMLongitude[index] = (sinMLongitude[index - x] * cosMLongitude[x] + cosMLongitude[index - x] * sinMLongitude[x]); cosMLongitude[index] = (cosMLongitude[index - x] * cosMLongitude[x] diff --git a/services/sensor/hdi_connection/hardware/include/hdi_service_impl.h b/services/sensor/hdi_connection/hardware/include/hdi_service_impl.h index 46399700..9c9d041e 100644 --- a/services/sensor/hdi_connection/hardware/include/hdi_service_impl.h +++ b/services/sensor/hdi_connection/hardware/include/hdi_service_impl.h @@ -52,7 +52,7 @@ public: private: DISALLOW_COPY_AND_MOVE(HdiServiceImpl); static void DataReportThread(); - std::vector g_enableSensos; + std::vector g_enableSensors; std::thread dataReportThread_; static RecordDataCallback g_callback; static int64_t g_samplingInterval; diff --git a/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp b/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp index 65842fb9..a4c0f50f 100644 --- a/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp +++ b/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp @@ -70,15 +70,15 @@ int32_t HdiServiceImpl::EnableSensor(uint32_t sensorId) HiLog::Error(LABEL, "%{public}s enable sensor failed", __func__); return -1; } - if (std::count(supportSensors.begin(), supportSensors.end(), sensorId) == 0) { + if (std::find(supportSensors.begin(), supportSensors.end(), sensorId) == supportSensors.end()) { HiLog::Error(LABEL, "%{public}s not support enable sensorId: %{public}d", __func__, sensorId); - return -1; + return ERR_NO_INIT; } - if (std::count(g_enableSensos.begin(), g_enableSensos.end(), sensorId) != 0) { + if (std::find(g_enableSensors.begin(), g_enableSensors.end(), sensorId) != g_enableSensors.end()) { HiLog::Info(LABEL, "%{public}s sensorId: %{public}d has been enabled", __func__, sensorId); return ERR_OK; } - g_enableSensos.push_back(sensorId); + g_enableSensors.push_back(sensorId); if (!dataReportThread_.joinable() || g_isStop) { if (dataReportThread_.joinable()) { dataReportThread_.join(); @@ -93,17 +93,22 @@ int32_t HdiServiceImpl::EnableSensor(uint32_t sensorId) int32_t HdiServiceImpl::DisableSensor(uint32_t sensorId) { HiLog::Info(LABEL, "%{public}s in", __func__); - if (std::count(supportSensors.begin(), supportSensors.end(), sensorId) == 0) { + if (std::find(supportSensors.begin(), supportSensors.end(), sensorId) == supportSensors.end()) { HiLog::Error(LABEL, "%{public}s not support disable sensorId: %{public}d", __func__, sensorId); - return -1; + return ERR_NO_INIT; } - if (std::count(g_enableSensos.begin(), g_enableSensos.end(), sensorId) == 0) { + if (std::find(g_enableSensors.begin(), g_enableSensors.end(), sensorId) == g_enableSensors.end()) { HiLog::Error(LABEL, "%{public}s sensorId: %{public}d should be enable first", __func__, sensorId); - return -1; + return ERR_NO_INIT; + } + std::vector::iterator iter; + for (iter = g_enableSensors.begin(); iter != g_enableSensors.end(); ++iter) { + if (*iter == sensorId) { + g_enableSensors.erase(iter++); + break; + } } - auto iter = std::remove(g_enableSensos.begin(), g_enableSensos.end(), sensorId); - g_enableSensos.erase(iter, g_enableSensos.end()); - if (g_enableSensos.empty()) { + if (g_enableSensors.empty()) { g_isStop = true; } return ERR_OK; -- Gitee From 8e55cb85c8904dcd3f780f9a902ab947efb365e3 Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Mon, 21 Mar 2022 11:09:17 +0800 Subject: [PATCH 2/2] Signed-off-by:hellohyh001 Signed-off-by: hellohyh001 --- services/sensor/hdi_connection/adapter/src/hdi_connection.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp index 978d5a5e..af655e30 100644 --- a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp @@ -35,8 +35,8 @@ sptr sensorInterface_ = nullptr; sptr eventCallback_ = nullptr; std::map sensorBasicInfoMap_; std::mutex sensorBasicInfoMutex_; -constexpr int32_t GET_HDI_SERVICE_COUNT = 10; -constexpr uint32_t WAIT_MS = 100; +constexpr int32_t GET_HDI_SERVICE_COUNT = 30; +constexpr uint32_t WAIT_MS = 200; } ZReportDataCb HdiConnection::reportDataCb_ = nullptr; -- Gitee