From 79ec49a5b2c9669e61f613458cbb7b3202329700 Mon Sep 17 00:00:00 2001 From: lixiangpeng5 Date: Mon, 22 Jan 2024 11:54:38 +0000 Subject: [PATCH] Add log report print for ext hall, posture Signed-off-by: lixiangpeng5 Change-Id: Ie7459ee3cd6394549ecfe4dfe28af359f7b786c2 --- .../adapter/include/sensor_event_callback.h | 7 +++ .../adapter/src/sensor_event_callback.cpp | 51 ++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/services/hdi_connection/adapter/include/sensor_event_callback.h b/services/hdi_connection/adapter/include/sensor_event_callback.h index fee30977..76358cb3 100644 --- a/services/hdi_connection/adapter/include/sensor_event_callback.h +++ b/services/hdi_connection/adapter/include/sensor_event_callback.h @@ -19,6 +19,8 @@ #include "v2_0/isensor_callback.h" #include "v2_0/sensor_types.h" +#include "sensor_data_event.h" + using OHOS::HDI::Sensor::V2_0::HdfSensorEvents; using OHOS::HDI::Sensor::V2_0::ISensorCallback; @@ -28,6 +30,11 @@ class SensorEventCallback : public ISensorCallback { public: virtual ~SensorEventCallback() {} int32_t OnDataEvent(const HdfSensorEvents &event) override; +private: + void ControlSensorPrint(const SensorData &sensorData); + void PrintSensorData(const SensorData &sensorData); + int32_t GetDataDimension(int32_t sensorId); + int64_t postureLastTs_ = 0; }; } // namespace Sensors } // namespace OHOS diff --git a/services/hdi_connection/adapter/src/sensor_event_callback.cpp b/services/hdi_connection/adapter/src/sensor_event_callback.cpp index 734e6de7..bec40190 100644 --- a/services/hdi_connection/adapter/src/sensor_event_callback.cpp +++ b/services/hdi_connection/adapter/src/sensor_event_callback.cpp @@ -16,7 +16,6 @@ #include "hdi_connection.h" #include "sensor_agent_type.h" -#include "sensor_data_event.h" #include "sensor_errors.h" #undef LOG_TAG @@ -28,6 +27,12 @@ using namespace OHOS::HiviewDFX; namespace { std::unique_ptr HdiConnection_ = std::make_unique(); constexpr int32_t HEADPOSTURE_DATA_SIZE = 20; +constexpr int64_t LOG_INTERVAL = 60000000000; +enum { + TWO_DIMENSION = 2, + SEVEN_DIMENSION = 7, + DEFAULT_DIMENSION = 16 +}; } // namespace int32_t SensorEventCallback::OnDataEvent(const HdfSensorEvents &event) @@ -71,10 +76,54 @@ int32_t SensorEventCallback::OnDataEvent(const HdfSensorEvents &event) sensorData.data[i] = event.data[i]; } } + ControlSensorPrint(sensorData); std::unique_lock lk(ISensorHdiConnection::dataMutex_); (void)(reportDataCallback_->*(reportDataCb_))(&sensorData, reportDataCallback_); ISensorHdiConnection::dataCondition_.notify_one(); return ERR_OK; } + +void SensorEventCallback::ControlSensorPrint(const SensorData &sensorData) +{ + if (sensorData.sensorTypeId == SENSOR_TYPE_ID_HALL_EXT) { + PrintSensorData(sensorData); + } + if ((sensorData.sensorTypeId == SENSOR_TYPE_ID_POSTURE) + && ((postureLastTs_ == 0) || (sensorData.timestamp - postureLastTs_ >= LOG_INTERVAL))) { + PrintSensorData(sensorData); + postureLastTs_ = sensorData.timestamp; + } +} + +void SensorEventCallback::PrintSensorData(const SensorData &sensorData) +{ + std::string str; + str += "sensorId: " + std::to_string(sensorData.sensorTypeId) + "\n"; + str += "timestamp: " + std::to_string(sensorData.timestamp) + "\n"; + int32_t dataDim = GetDataDimension(sensorData.sensorTypeId); + auto data = reinterpret_cast(sensorData.data); + for (int32_t i = 0; i < dataDim; ++i) { + str.append(std::to_string(*data)); + if (i != dataDim - 1) { + str.append(", "); + } + ++data; + } + str.append("\n"); + SEN_HILOGI("SensorData: %{public}s", str.c_str()); +} + +int32_t SensorEventCallback::GetDataDimension(int32_t sensorId) +{ + switch (sensorId) { + case SENSOR_TYPE_ID_HALL_EXT: + return TWO_DIMENSION; + case SENSOR_TYPE_ID_POSTURE: + return SEVEN_DIMENSION; + default: + SEN_HILOGW("Unknown sensorId:%{public}d, size:%{public}d", sensorId, DEFAULT_DIMENSION); + return DEFAULT_DIMENSION; + } +} } // namespace Sensors } // namespace OHOS \ No newline at end of file -- Gitee