From 053654c0824b8efb0bd50a0e5625399b49ffbba4 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Wed, 23 Mar 2022 14:53:08 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9senso=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- .../adapter/src/hdi_connection.cpp | 20 +++++++------------ utils/include/report_data_callback.h | 6 +++--- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp index af655e30..18462f58 100644 --- a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp @@ -80,20 +80,14 @@ int32_t HdiConnection::GetSensorList(std::vector& sensorList) return ret; } for (int32_t i = 0; i < static_cast(sensorInfos.size()); i++) { - const std::string sensorName(sensorInfos[i].sensorName); - const std::string vendorName(sensorInfos[i].vendorName); - const std::string firmwareVersion(sensorInfos[i].firmwareVersion); - const std::string hardwareVersion(sensorInfos[i].hardwareVersion); - const int32_t sensorId = sensorInfos[i].sensorId; - const float maxRange = sensorInfos[i].maxRange; Sensor sensor; - sensor.SetSensorId(sensorId); - sensor.SetSensorTypeId(sensorId); - sensor.SetFirmwareVersion(firmwareVersion.c_str()); - sensor.SetHardwareVersion(hardwareVersion.c_str()); - sensor.SetMaxRange(maxRange); - sensor.SetSensorName(sensorName.c_str()); - sensor.SetVendorName(vendorName.c_str()); + sensor.SetSensorId(sensorInfos[i].sensorId); + sensor.SetSensorTypeId(sensorInfos[i].sensorId); + sensor.SetFirmwareVersion(sensorInfos[i].firmwareVersion.c_str()); + sensor.SetHardwareVersion(sensorInfos[i].hardwareVersion.c_str()); + sensor.SetMaxRange(sensorInfos[i].maxRange); + sensor.SetSensorName(sensorInfos[i].sensorName.c_str()); + sensor.SetVendorName(sensorInfos[i].vendorName.c_str()); sensor.SetResolution(sensorInfos[i].accuracy); sensor.SetPower(sensorInfos[i].power); sensorList.push_back(sensor); diff --git a/utils/include/report_data_callback.h b/utils/include/report_data_callback.h index a1b7a297..5d12164c 100644 --- a/utils/include/report_data_callback.h +++ b/utils/include/report_data_callback.h @@ -29,7 +29,7 @@ constexpr int32_t SENSOR_DATA_LENGHT = 64; struct CircularEventBuf { struct SensorEvent *circularBuf; - int32_t readPosition; + int32_t readPos; int32_t writePosition; int32_t eventNum; }; @@ -38,12 +38,12 @@ class ReportDataCallback : public RefBase { public: ReportDataCallback(); ~ReportDataCallback(); - int32_t ZReportDataCallback(const struct SensorEvent *event, sptr cb); + int32_t ReportDataCallback(const struct SensorEvent *event, sptr cb); struct CircularEventBuf &GetEventData(); struct CircularEventBuf eventsBuf_; }; -using ZReportDataCb = int32_t (ReportDataCallback::*)(const struct SensorEvent *event, sptr cb); +using ReportDataCb = int32_t (ReportDataCallback::*)(const struct SensorEvent *event, sptr cb); } // namespace Sensors } // namespace OHOS #endif // REPORT_DATA_CALLBACK_H -- Gitee From bc763151aefb52922e23b95efed845cf51a92a57 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Thu, 24 Mar 2022 10:57:41 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9senso=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- services/sensor/src/sensor_service.cpp | 2 +- utils/include/report_data_callback.h | 4 ++-- utils/src/report_data_callback.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/sensor/src/sensor_service.cpp b/services/sensor/src/sensor_service.cpp index 774ae79c..faef66c0 100644 --- a/services/sensor/src/sensor_service.cpp +++ b/services/sensor/src/sensor_service.cpp @@ -111,7 +111,7 @@ bool SensorService::InitDataCallback() HiLog::Error(LABEL, "%{public}s failed, reportDataCallback_ cannot be null", __func__); return false; } - ZReportDataCb cb = &ReportDataCallback::ZReportDataCallback; + ReportDataCb cb = &ReportDataCallback::ReportEventCallback; auto ret = sensorHdiConnection_.RegisteDataReport(cb, reportDataCallback_); if (ret != ERR_OK) { HiLog::Error(LABEL, "%{public}s RegisterDataReport failed", __func__); diff --git a/utils/include/report_data_callback.h b/utils/include/report_data_callback.h index 5d12164c..1bd9bb70 100644 --- a/utils/include/report_data_callback.h +++ b/utils/include/report_data_callback.h @@ -38,12 +38,12 @@ class ReportDataCallback : public RefBase { public: ReportDataCallback(); ~ReportDataCallback(); - int32_t ReportDataCallback(const struct SensorEvent *event, sptr cb); + int32_t ReportEventCallback(const struct SensorEvent *event, sptr cb); struct CircularEventBuf &GetEventData(); struct CircularEventBuf eventsBuf_; }; -using ReportDataCb = int32_t (ReportDataCallback::*)(const struct SensorEvent *event, sptr cb); +using ZReportDataCb = int32_t (ReportDataCallback::*)(const struct SensorEvent *event, sptr cb); } // namespace Sensors } // namespace OHOS #endif // REPORT_DATA_CALLBACK_H diff --git a/utils/src/report_data_callback.cpp b/utils/src/report_data_callback.cpp index 4317c7cd..c3687a99 100644 --- a/utils/src/report_data_callback.cpp +++ b/utils/src/report_data_callback.cpp @@ -51,7 +51,7 @@ ReportDataCallback::~ReportDataCallback() eventsBuf_.eventNum = 0; } -int32_t ReportDataCallback::ZReportDataCallback(const struct SensorEvent* event, sptr cb) +int32_t ReportDataCallback::ReportEventCallback(const struct SensorEvent* event, sptr cb) { if (event == nullptr) { HiLog::Error(LABEL, "%{public}s sensor data is null", __func__); -- Gitee From e489888c6fa00d7dfe1525a064ea47c2591ce5c6 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Thu, 24 Mar 2022 11:01:14 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9senso=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- services/sensor/src/sensor_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/sensor/src/sensor_service.cpp b/services/sensor/src/sensor_service.cpp index faef66c0..212b46b0 100644 --- a/services/sensor/src/sensor_service.cpp +++ b/services/sensor/src/sensor_service.cpp @@ -111,7 +111,7 @@ bool SensorService::InitDataCallback() HiLog::Error(LABEL, "%{public}s failed, reportDataCallback_ cannot be null", __func__); return false; } - ReportDataCb cb = &ReportDataCallback::ReportEventCallback; + ZReportDataCb cb = &ReportDataCallback::ReportEventCallback; auto ret = sensorHdiConnection_.RegisteDataReport(cb, reportDataCallback_); if (ret != ERR_OK) { HiLog::Error(LABEL, "%{public}s RegisterDataReport failed", __func__); -- Gitee From f6adf00a45e5c8c09f2a8a0e6cdae01c99b92a2f Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Thu, 24 Mar 2022 14:42:36 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9senso=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- services/sensor/src/sensor_data_processer.cpp | 16 ++++++++-------- utils/src/report_data_callback.cpp | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/services/sensor/src/sensor_data_processer.cpp b/services/sensor/src/sensor_data_processer.cpp index dd02a4c8..748bef5f 100644 --- a/services/sensor/src/sensor_data_processer.cpp +++ b/services/sensor/src/sensor_data_processer.cpp @@ -308,10 +308,10 @@ int32_t SensorDataProcesser::CacheSensorEvent(const struct SensorEvent &event, s void SensorDataProcesser::EventFilter(struct CircularEventBuf &eventsBuf) { uint32_t realSensorId = 0; - uint32_t sensorId = static_cast(eventsBuf.circularBuf[eventsBuf.readPosition].sensorTypeId); + uint32_t sensorId = static_cast(eventsBuf.circularBuf[eventsBuf.readPos].sensorTypeId); std::vector> channelList; if (sensorId == FLUSH_COMPLETE_ID) { - realSensorId = static_cast(eventsBuf.circularBuf[eventsBuf.readPosition].sensorTypeId); + realSensorId = static_cast(eventsBuf.circularBuf[eventsBuf.readPos].sensorTypeId); channelList = clientInfo_.GetSensorChannel(realSensorId); } else { channelList = clientInfo_.GetSensorChannel(sensorId); @@ -325,7 +325,7 @@ void SensorDataProcesser::EventFilter(struct CircularEventBuf &eventsBuf) flushVec = it->second; for (auto &channel : flushVec) { if (flushInfo_.IsFlushChannelValid(channelList, channel.flushChannel)) { - SendEvents(channel.flushChannel, eventsBuf.circularBuf[eventsBuf.readPosition]); + SendEvents(channel.flushChannel, eventsBuf.circularBuf[eventsBuf.readPos]); flushInfo_.ClearFlushInfoItem(realSensorId); break; } else { @@ -347,7 +347,7 @@ void SensorDataProcesser::EventFilter(struct CircularEventBuf &eventsBuf) /* if has some suspend flush, but this flush come from the flush function rather than enable, so we need to calling GetSensorStatus to decided whether send this event. */ if (channel->GetSensorStatus()) { - SendEvents(channel, eventsBuf.circularBuf[eventsBuf.readPosition]); + SendEvents(channel, eventsBuf.circularBuf[eventsBuf.readPos]); } } } @@ -369,10 +369,10 @@ int32_t SensorDataProcesser::ProcessEvents(sptr dataCallback int32_t eventNum = eventsBuf.eventNum; for (int32_t i = 0; i < eventNum; i++) { EventFilter(eventsBuf); - delete[] eventsBuf.circularBuf[eventsBuf.readPosition].data; - eventsBuf.readPosition++; - if (eventsBuf.readPosition == CIRCULAR_BUF_LEN) { - eventsBuf.readPosition = 0; + delete[] eventsBuf.circularBuf[eventsBuf.readPos].data; + eventsBuf.readPos++; + if (eventsBuf.readPos == CIRCULAR_BUF_LEN) { + eventsBuf.readPos = 0; } eventsBuf.eventNum--; } diff --git a/utils/src/report_data_callback.cpp b/utils/src/report_data_callback.cpp index c3687a99..702fd0e7 100644 --- a/utils/src/report_data_callback.cpp +++ b/utils/src/report_data_callback.cpp @@ -35,7 +35,7 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { ReportDataCallback::ReportDataCallback() { eventsBuf_.circularBuf = new struct SensorEvent[CIRCULAR_BUF_LEN]; - eventsBuf_.readPosition = 0; + eventsBuf_.readPos = 0; eventsBuf_.writePosition = 0; eventsBuf_.eventNum = 0; } @@ -46,7 +46,7 @@ ReportDataCallback::~ReportDataCallback() delete[] eventsBuf_.circularBuf; } eventsBuf_.circularBuf = nullptr; - eventsBuf_.readPosition = 0; + eventsBuf_.readPos = 0; eventsBuf_.writePosition = 0; eventsBuf_.eventNum = 0; } @@ -74,7 +74,7 @@ int32_t ReportDataCallback::ReportEventCallback(const struct SensorEvent* event, cb->eventsBuf_.writePosition += 1; } if (leftSize < 1) { - cb->eventsBuf_.readPosition = cb->eventsBuf_.writePosition; + cb->eventsBuf_.readPos = cb->eventsBuf_.writePosition; } cb->eventsBuf_.eventNum += 1; if (cb->eventsBuf_.eventNum >= CIRCULAR_BUF_LEN) { -- Gitee From 73536a7e7dfb37c35947efda4eb2807d24edc77a Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Thu, 24 Mar 2022 15:44:44 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9senso=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- .vscode/settings.json | 5 +++++ .../sensor/hdi_connection/adapter/src/hdi_connection.cpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..e0e59387 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "string": "cpp" + } +} \ No newline at end of file diff --git a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp index 18462f58..50b1f926 100644 --- a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp @@ -79,7 +79,7 @@ int32_t HdiConnection::GetSensorList(std::vector& sensorList) HiLog::Error(LABEL, "%{public}s get sensor list failed", __func__); return ret; } - for (int32_t i = 0; i < static_cast(sensorInfos.size()); i++) { + for (size_t i = 0; i < sensorInfos.size(); i++) { Sensor sensor; sensor.SetSensorId(sensorInfos[i].sensorId); sensor.SetSensorTypeId(sensorInfos[i].sensorId); -- Gitee From 8a786826bda875497671eb9c346f3d4f6b958c28 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Thu, 24 Mar 2022 15:55:22 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E5=88=A0=E9=99=A4.vscode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- .vscode/settings.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index e0e59387..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "files.associations": { - "string": "cpp" - } -} \ No newline at end of file -- Gitee