mirror of
https://gitee.com/openharmony/sensors_sensor
synced 2025-03-03 11:59:35 +00:00
Merge branch 'master' of https://gitee.com/openharmony/sensors_sensor into lxp
Change-Id: I5b1ebefb48d8116995b002079e34da26f572fd1c
This commit is contained in:
commit
2c1d8b8599
@ -34,3 +34,10 @@ if (!defined(global_parts_info) ||
|
||||
} else {
|
||||
hdf_drivers_interface_sensor = false
|
||||
}
|
||||
|
||||
if (build_variant == "root") {
|
||||
sensor_default_defines += [ "BUILD_VARIANT_ENG" ]
|
||||
sensor_build_eng = true
|
||||
} else {
|
||||
sensor_build_eng = false
|
||||
}
|
||||
|
@ -66,10 +66,8 @@ ohos_shared_library("libsensor_service") {
|
||||
|
||||
if (hdf_drivers_interface_sensor) {
|
||||
sources += [
|
||||
"hdi_connection/adapter/src/compatible_connection.cpp",
|
||||
"hdi_connection/adapter/src/hdi_connection.cpp",
|
||||
"hdi_connection/adapter/src/sensor_event_callback.cpp",
|
||||
"hdi_connection/hardware/src/hdi_service_impl.cpp",
|
||||
"hdi_connection/interface/src/sensor_hdi_connection.cpp",
|
||||
"src/sensor_data_processer.cpp",
|
||||
]
|
||||
@ -77,9 +75,18 @@ ohos_shared_library("libsensor_service") {
|
||||
include_dirs += [
|
||||
"$SUBSYSTEM_DIR/services/hdi_connection/interface/include",
|
||||
"$SUBSYSTEM_DIR/services/hdi_connection/adapter/include",
|
||||
"$SUBSYSTEM_DIR/services/hdi_connection/hardware/include",
|
||||
]
|
||||
|
||||
if (sensor_build_eng) {
|
||||
sources += [
|
||||
"hdi_connection/adapter/src/compatible_connection.cpp",
|
||||
"hdi_connection/hardware/src/hdi_service_impl.cpp",
|
||||
]
|
||||
|
||||
include_dirs +=
|
||||
[ "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include" ]
|
||||
}
|
||||
|
||||
external_deps += [ "drivers_interface_sensor:libsensor_proxy_1.1" ]
|
||||
}
|
||||
|
||||
@ -141,10 +148,8 @@ ohos_shared_library("libsensor_service_static") {
|
||||
|
||||
if (hdf_drivers_interface_sensor) {
|
||||
sources += [
|
||||
"hdi_connection/adapter/src/compatible_connection.cpp",
|
||||
"hdi_connection/adapter/src/hdi_connection.cpp",
|
||||
"hdi_connection/adapter/src/sensor_event_callback.cpp",
|
||||
"hdi_connection/hardware/src/hdi_service_impl.cpp",
|
||||
"hdi_connection/interface/src/sensor_hdi_connection.cpp",
|
||||
"src/sensor_data_processer.cpp",
|
||||
]
|
||||
@ -152,9 +157,18 @@ ohos_shared_library("libsensor_service_static") {
|
||||
include_dirs += [
|
||||
"$SUBSYSTEM_DIR/services/hdi_connection/interface/include",
|
||||
"$SUBSYSTEM_DIR/services/hdi_connection/adapter/include",
|
||||
"$SUBSYSTEM_DIR/services/hdi_connection/hardware/include",
|
||||
]
|
||||
|
||||
if (sensor_build_eng) {
|
||||
sources += [
|
||||
"hdi_connection/adapter/src/compatible_connection.cpp",
|
||||
"hdi_connection/hardware/src/hdi_service_impl.cpp",
|
||||
]
|
||||
|
||||
include_dirs +=
|
||||
[ "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include" ]
|
||||
}
|
||||
|
||||
external_deps += [ "drivers_interface_sensor:libsensor_proxy_1.1" ]
|
||||
}
|
||||
|
||||
|
@ -29,8 +29,6 @@ constexpr HiLogLabel LABEL = { LOG_CORE, SENSOR_LOG_DOMAIN, "CompatibleConnectio
|
||||
|
||||
ReportDataCb CompatibleConnection::reportDataCb_ = nullptr;
|
||||
sptr<ReportDataCallback> CompatibleConnection::reportDataCallback_ = nullptr;
|
||||
std::mutex ISensorHdiConnection::dataMutex_;
|
||||
std::condition_variable ISensorHdiConnection::dataCondition_;
|
||||
int32_t CompatibleConnection::ConnectHdi()
|
||||
{
|
||||
SEN_HILOGI("Connect hdi success");
|
||||
|
@ -14,16 +14,22 @@
|
||||
*/
|
||||
#include "sensor_hdi_connection.h"
|
||||
|
||||
#ifdef BUILD_VARIANT_ENG
|
||||
#include "compatible_connection.h"
|
||||
#endif // BUILD_VARIANT_ENG
|
||||
|
||||
#include "hdi_connection.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "sensor_errors.h"
|
||||
std::mutex OHOS::Sensors::ISensorHdiConnection::dataMutex_;
|
||||
std::condition_variable OHOS::Sensors::ISensorHdiConnection::dataCondition_;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Sensors {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
namespace {
|
||||
constexpr HiLogLabel LABEL = { LOG_CORE, SENSOR_LOG_DOMAIN, "SensorHdiConnection" };
|
||||
#ifdef BUILD_VARIANT_ENG
|
||||
constexpr float MAX_RANGE = 9999.0;
|
||||
constexpr float POWER = 20.0;
|
||||
constexpr float RESOLITION = 0.000001;
|
||||
@ -35,6 +41,7 @@ std::unordered_set<int32_t> g_supportMockSensors = {
|
||||
SENSOR_TYPE_ID_SAR,
|
||||
SENSOR_TYPE_ID_HEADPOSTURE
|
||||
};
|
||||
#endif // BUILD_VARIANT_ENG
|
||||
}
|
||||
|
||||
int32_t SensorHdiConnection::ConnectHdi()
|
||||
@ -43,6 +50,7 @@ int32_t SensorHdiConnection::ConnectHdi()
|
||||
int32_t ret = ConnectHdiService();
|
||||
if (ret != ERR_OK) {
|
||||
SEN_HILOGE("Connect hdi service failed, try to connect compatible connection, ret:%{public}d", ret);
|
||||
#ifdef BUILD_VARIANT_ENG
|
||||
iSensorHdiConnection_ = std::make_unique<CompatibleConnection>();
|
||||
ret = ConnectHdiService();
|
||||
if (ret != ERR_OK) {
|
||||
@ -59,6 +67,7 @@ int32_t SensorHdiConnection::ConnectHdi()
|
||||
if (ret != ERR_OK) {
|
||||
SEN_HILOGE("Connect mock sensors compatible connection failed, ret:%{public}d", ret);
|
||||
}
|
||||
#endif // BUILD_VARIANT_ENG
|
||||
return ret;
|
||||
}
|
||||
return ERR_OK;
|
||||
@ -83,6 +92,7 @@ int32_t SensorHdiConnection::ConnectHdiService()
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
#ifdef BUILD_VARIANT_ENG
|
||||
int32_t SensorHdiConnection::ConnectCompatibleHdi()
|
||||
{
|
||||
if (iSensorCompatibleHdiConnection_ == nullptr) {
|
||||
@ -165,12 +175,14 @@ Sensor SensorHdiConnection::GenerateHeadPostureSensor()
|
||||
sensorHeadPosture.SetMaxSamplePeriodNs(MAX_SAMPLE_PERIOD_NS);
|
||||
return sensorHeadPosture;
|
||||
}
|
||||
#endif // BUILD_VARIANT_ENG
|
||||
|
||||
int32_t SensorHdiConnection::GetSensorList(std::vector<Sensor> &sensorList)
|
||||
{
|
||||
CHKPR(iSensorHdiConnection_, GET_SENSOR_LIST_ERR);
|
||||
std::lock_guard<std::mutex> sensorLock(sensorMutex_);
|
||||
sensorList.assign(sensorList_.begin(), sensorList_.end());
|
||||
#ifdef BUILD_VARIANT_ENG
|
||||
if (!hdiConnectionStatus_) {
|
||||
return ERR_OK;
|
||||
}
|
||||
@ -189,6 +201,7 @@ int32_t SensorHdiConnection::GetSensorList(std::vector<Sensor> &sensorList)
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif // BUILD_VARIANT_ENG
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
@ -196,6 +209,7 @@ int32_t SensorHdiConnection::EnableSensor(int32_t sensorId)
|
||||
{
|
||||
StartTrace(HITRACE_TAG_SENSORS, "EnableSensor");
|
||||
int32_t ret = ENABLE_SENSOR_ERR;
|
||||
#ifdef BUILD_VARIANT_ENG
|
||||
if (FindOneInMockSet(sensorId)) {
|
||||
CHKPR(iSensorCompatibleHdiConnection_, ENABLE_SENSOR_ERR);
|
||||
ret = iSensorCompatibleHdiConnection_->EnableSensor(sensorId);
|
||||
@ -206,6 +220,7 @@ int32_t SensorHdiConnection::EnableSensor(int32_t sensorId)
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif // BUILD_VARIANT_ENG
|
||||
CHKPR(iSensorHdiConnection_, ENABLE_SENSOR_ERR);
|
||||
ret = iSensorHdiConnection_->EnableSensor(sensorId);
|
||||
FinishTrace(HITRACE_TAG_SENSORS);
|
||||
@ -220,6 +235,7 @@ int32_t SensorHdiConnection::DisableSensor(int32_t sensorId)
|
||||
{
|
||||
StartTrace(HITRACE_TAG_SENSORS, "DisableSensor");
|
||||
int32_t ret = DISABLE_SENSOR_ERR;
|
||||
#ifdef BUILD_VARIANT_ENG
|
||||
if (FindOneInMockSet(sensorId)) {
|
||||
CHKPR(iSensorCompatibleHdiConnection_, DISABLE_SENSOR_ERR);
|
||||
ret = iSensorCompatibleHdiConnection_->DisableSensor(sensorId);
|
||||
@ -230,6 +246,7 @@ int32_t SensorHdiConnection::DisableSensor(int32_t sensorId)
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif // BUILD_VARIANT_ENG
|
||||
CHKPR(iSensorHdiConnection_, DISABLE_SENSOR_ERR);
|
||||
ret = iSensorHdiConnection_->DisableSensor(sensorId);
|
||||
FinishTrace(HITRACE_TAG_SENSORS);
|
||||
@ -244,6 +261,7 @@ int32_t SensorHdiConnection::SetBatch(int32_t sensorId, int64_t samplingInterval
|
||||
{
|
||||
StartTrace(HITRACE_TAG_SENSORS, "SetBatch");
|
||||
int32_t ret = SET_SENSOR_CONFIG_ERR;
|
||||
#ifdef BUILD_VARIANT_ENG
|
||||
if (FindOneInMockSet(sensorId)) {
|
||||
CHKPR(iSensorCompatibleHdiConnection_, SET_SENSOR_CONFIG_ERR);
|
||||
ret = iSensorCompatibleHdiConnection_->SetBatch(sensorId, samplingInterval, reportInterval);
|
||||
@ -254,6 +272,7 @@ int32_t SensorHdiConnection::SetBatch(int32_t sensorId, int64_t samplingInterval
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif // BUILD_VARIANT_ENG
|
||||
CHKPR(iSensorHdiConnection_, SET_SENSOR_CONFIG_ERR);
|
||||
ret = iSensorHdiConnection_->SetBatch(sensorId, samplingInterval, reportInterval);
|
||||
FinishTrace(HITRACE_TAG_SENSORS);
|
||||
@ -268,6 +287,7 @@ int32_t SensorHdiConnection::SetMode(int32_t sensorId, int32_t mode)
|
||||
{
|
||||
StartTrace(HITRACE_TAG_SENSORS, "SetMode");
|
||||
int32_t ret = SET_SENSOR_MODE_ERR;
|
||||
#ifdef BUILD_VARIANT_ENG
|
||||
if (FindOneInMockSet(sensorId)) {
|
||||
CHKPR(iSensorCompatibleHdiConnection_, SET_SENSOR_MODE_ERR);
|
||||
ret = iSensorCompatibleHdiConnection_->SetMode(sensorId, mode);
|
||||
@ -278,6 +298,7 @@ int32_t SensorHdiConnection::SetMode(int32_t sensorId, int32_t mode)
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif // BUILD_VARIANT_ENG
|
||||
CHKPR(iSensorHdiConnection_, SET_SENSOR_MODE_ERR);
|
||||
ret = iSensorHdiConnection_->SetMode(sensorId, mode);
|
||||
FinishTrace(HITRACE_TAG_SENSORS);
|
||||
@ -297,6 +318,7 @@ int32_t SensorHdiConnection::RegisterDataReport(ReportDataCb cb, sptr<ReportData
|
||||
SEN_HILOGE("Registe dataReport failed");
|
||||
return REGIST_CALLBACK_ERR;
|
||||
}
|
||||
#ifdef BUILD_VARIANT_ENG
|
||||
if (iSensorCompatibleHdiConnection_ != nullptr) {
|
||||
ret = iSensorCompatibleHdiConnection_->RegisterDataReport(cb, reportDataCallback);
|
||||
if (ret != ERR_OK) {
|
||||
@ -304,6 +326,7 @@ int32_t SensorHdiConnection::RegisterDataReport(ReportDataCb cb, sptr<ReportData
|
||||
return REGIST_CALLBACK_ERR;
|
||||
}
|
||||
}
|
||||
#endif // BUILD_VARIANT_ENG
|
||||
FinishTrace(HITRACE_TAG_SENSORS);
|
||||
return ret;
|
||||
}
|
||||
@ -316,6 +339,7 @@ int32_t SensorHdiConnection::DestroyHdiConnection()
|
||||
SEN_HILOGE("Destroy hdi connection failed");
|
||||
return DEVICE_ERR;
|
||||
}
|
||||
#ifdef BUILD_VARIANT_ENG
|
||||
if (iSensorCompatibleHdiConnection_ != nullptr) {
|
||||
ret = iSensorCompatibleHdiConnection_->DestroyHdiConnection();
|
||||
if (ret != ERR_OK) {
|
||||
@ -323,6 +347,7 @@ int32_t SensorHdiConnection::DestroyHdiConnection()
|
||||
}
|
||||
return DEVICE_ERR;
|
||||
}
|
||||
#endif // BUILD_VARIANT_ENG
|
||||
return ret;
|
||||
}
|
||||
} // namespace Sensors
|
||||
|
@ -32,7 +32,9 @@ using namespace OHOS::HiviewDFX;
|
||||
namespace {
|
||||
constexpr HiLogLabel LABEL = { LOG_CORE, SENSOR_LOG_DOMAIN, "SensorDump" };
|
||||
constexpr int32_t MAX_DUMP_PARAMETERS = 32;
|
||||
#ifdef BUILD_VARIANT_ENG
|
||||
constexpr uint32_t MAX_DUMP_DATA_SIZE = 10;
|
||||
#endif // BUILD_VARIANT_ENG
|
||||
constexpr uint32_t MS_NS = 1000000;
|
||||
|
||||
enum {
|
||||
@ -104,7 +106,9 @@ void SensorDump::ParseCommand(int32_t fd, const std::vector<std::string> &args,
|
||||
int32_t optionIndex = 0;
|
||||
struct option dumpOptions[] = {
|
||||
{"channel", no_argument, 0, 'c'},
|
||||
#ifdef BUILD_VARIANT_ENG
|
||||
{"data", no_argument, 0, 'd'},
|
||||
#endif // BUILD_VARIANT_ENG
|
||||
{"open", no_argument, 0, 'o'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"list", no_argument, 0, 'l'},
|
||||
@ -136,10 +140,12 @@ void SensorDump::ParseCommand(int32_t fd, const std::vector<std::string> &args,
|
||||
DumpSensorChannel(fd, clientInfo);
|
||||
break;
|
||||
}
|
||||
#ifdef BUILD_VARIANT_ENG
|
||||
case 'd': {
|
||||
DumpSensorData(fd, clientInfo);
|
||||
break;
|
||||
}
|
||||
#endif // BUILD_VARIANT_ENG
|
||||
case 'o': {
|
||||
DumpOpeningSensor(fd, sensors, clientInfo);
|
||||
break;
|
||||
@ -174,7 +180,9 @@ void SensorDump::DumpHelp(int32_t fd)
|
||||
dprintf(fd, " -l, --list: dump the sensor list\n");
|
||||
dprintf(fd, " -c, --channel: dump the sensor data channel info\n");
|
||||
dprintf(fd, " -o, --open: dump the opening sensors\n");
|
||||
#ifdef BUILD_VARIANT_ENG
|
||||
dprintf(fd, " -d, --data: dump the last 10 packages sensor data\n");
|
||||
#endif // BUILD_VARIANT_ENG
|
||||
}
|
||||
|
||||
bool SensorDump::DumpSensorList(int32_t fd, const std::vector<Sensor> &sensors)
|
||||
@ -233,6 +241,7 @@ bool SensorDump::DumpOpeningSensor(int32_t fd, const std::vector<Sensor> &sensor
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef BUILD_VARIANT_ENG
|
||||
bool SensorDump::DumpSensorData(int32_t fd, ClientInfo &clientInfo)
|
||||
{
|
||||
dprintf(fd, "Last 10 packages sensor data:\n");
|
||||
@ -258,6 +267,7 @@ bool SensorDump::DumpSensorData(int32_t fd, ClientInfo &clientInfo)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif // BUILD_VARIANT_ENG
|
||||
|
||||
void SensorDump::DumpCurrentTime(int32_t fd)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user