From 1123ab1ec2300e29c3a7313a87982e510abb3c41 Mon Sep 17 00:00:00 2001 From: yangjunrui Date: Fri, 17 Dec 2021 14:21:58 +0800 Subject: [PATCH 1/2] feat : add sensor hdi ipc service implementation Signed-off-by: yangjunrui --- sensor/v1_0/BUILD.gn | 28 +++++++++++++++++++++++ sensor/v1_0/ISensorCallback.idl | 22 ++++++++++++++++++ sensor/v1_0/ISensorInterface.idl | 30 +++++++++++++++++++++++++ sensor/v1_0/SensorTypes.idl | 38 ++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 sensor/v1_0/BUILD.gn create mode 100644 sensor/v1_0/ISensorCallback.idl create mode 100644 sensor/v1_0/ISensorInterface.idl create mode 100644 sensor/v1_0/SensorTypes.idl diff --git a/sensor/v1_0/BUILD.gn b/sensor/v1_0/BUILD.gn new file mode 100644 index 00000000..0dcab2c5 --- /dev/null +++ b/sensor/v1_0/BUILD.gn @@ -0,0 +1,28 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//drivers/adapter/uhdf2/hdi.gni") + +hdi("sensor") { + package = "sensor.v1_0" + + module_name = "sensor_service" + + sources = [ + "ISensorCallback.idl", + "ISensorInterface.idl", + "SensorTypes.idl", + ] + + language = "cpp" +} diff --git a/sensor/v1_0/ISensorCallback.idl b/sensor/v1_0/ISensorCallback.idl new file mode 100644 index 00000000..4e31ba6f --- /dev/null +++ b/sensor/v1_0/ISensorCallback.idl @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sensor.v1_0; + +import sensor.v1_0.SensorTypes; + +[callback] interface ISensorCallback { + OnDataEvent([in] struct HdfSensorEvents event); +} diff --git a/sensor/v1_0/ISensorInterface.idl b/sensor/v1_0/ISensorInterface.idl new file mode 100644 index 00000000..a136b9d3 --- /dev/null +++ b/sensor/v1_0/ISensorInterface.idl @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sensor.v1_0; + +import sensor.v1_0.SensorTypes; +import sensor.v1_0.ISensorCallback; + +interface ISensorInterface { + GetAllSensorInfo([out] struct HdfSensorInformation[] info); + Enable([in] int sensorId); + Disable([in] int sensorId); + SetBatch([in] int sensorId,[in] long samplingInterval, [in] long reportInterval); + SetMode([in] int sensorId, [in] int mode); + SetOption([in] int sensorId, [in] unsigned int option); + Register([in] ISensorCallback callbackObj); + Unregister(); +} diff --git a/sensor/v1_0/SensorTypes.idl b/sensor/v1_0/SensorTypes.idl new file mode 100644 index 00000000..f15dce2c --- /dev/null +++ b/sensor/v1_0/SensorTypes.idl @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sensor.v1_0; + +struct HdfSensorInformation { + String sensorName; + String vendorName; + String firmwareVersion; + String hardwareVersion; + int sensorTypeId; + int sensorId; + float maxRange; + float accuracy; + float power; +}; + +struct HdfSensorEvents { + int sensorId; + int version; + int timestamp; + unsigned int option; + int mode; + unsigned char[] data; + unsigned int dataLen; +}; -- Gitee From a1b0b7bd65a06ae5cac494935f47daa27890e18c Mon Sep 17 00:00:00 2001 From: yangjunrui Date: Fri, 17 Dec 2021 19:05:02 +0800 Subject: [PATCH 2/2] feat : add sensor hdi ipc service implementation Signed-off-by: yangjunrui --- sensor/v1_0/ISensorCallback.idl | 26 +++++++ sensor/v1_0/ISensorInterface.idl | 119 +++++++++++++++++++++++++++++++ sensor/v1_0/SensorTypes.idl | 72 ++++++++++++++----- 3 files changed, 201 insertions(+), 16 deletions(-) diff --git a/sensor/v1_0/ISensorCallback.idl b/sensor/v1_0/ISensorCallback.idl index 4e31ba6f..bb697a5c 100644 --- a/sensor/v1_0/ISensorCallback.idl +++ b/sensor/v1_0/ISensorCallback.idl @@ -13,10 +13,36 @@ * limitations under the License. */ +/** + * @addtogroup Sensor + * @{ + * + * @brief Provides unified APIs for sensor services to access sensor drivers. + * + * A sensor service can obtain a sensor driver object or agent and then call APIs provided by this object or agent to + * access different types of sensor devices based on the sensor IDs, thereby obtaining sensor information, + * subscribing to or unsubscribing from sensor data, enabling or disabling a sensor, + * setting the sensor data reporting mode, and setting sensor options such as the accuracy and measurement range. + * + * @version 1.0 + */ + package sensor.v1_0; import sensor.v1_0.SensorTypes; +/** + * @brief Defines the callback for reporting sensor data. This callback needs to be registered when + * a sensor user subscribes to sensor data. Only after the sensor is enabled, the sensor data subscriber can receive + * sensor data. For details, see {@link ISensorInterface}. + * + * @since 2.2 + */ [callback] interface ISensorCallback { + /** + * @brief Defines the function for reporting sensor data. + * + * @since 2.2 + */ OnDataEvent([in] struct HdfSensorEvents event); } diff --git a/sensor/v1_0/ISensorInterface.idl b/sensor/v1_0/ISensorInterface.idl index a136b9d3..04e2ec1c 100644 --- a/sensor/v1_0/ISensorInterface.idl +++ b/sensor/v1_0/ISensorInterface.idl @@ -13,18 +13,137 @@ * limitations under the License. */ +/** + * @addtogroup Sensor + * @{ + * + * @brief Provides unified APIs for sensor services to access sensor drivers. + * + * A sensor service can obtain a sensor driver object or agent and then call APIs provided by this object or agent to + * access different types of sensor devices based on the sensor IDs, thereby obtaining sensor information, + * subscribing to or unsubscribing from sensor data, enabling or disabling a sensor, + * setting the sensor data reporting mode, and setting sensor options such as the accuracy and measurement range. + * + * @since 2.2 + */ + +/** + * @file ISensorInterface.idl + * + * @brief Declares the APIs provided by the sensor module for obtaining sensor information, subscribing to or + * unsubscribing from sensor data, enabling or disabling a sensor, setting the sensor data reporting mode, + * and setting sensor options such as the accuracy and measurement range. + * + * @since 2.2 + * @version 1.0 + */ + package sensor.v1_0; import sensor.v1_0.SensorTypes; import sensor.v1_0.ISensorCallback; +/** + * @brief Defines the functions for performing basic operations on sensors. + * + * The operations include obtaining sensor information, subscribing to or unsubscribing from sensor data, + * enabling or disabling a sensor, setting the sensor data reporting mode, and setting sensor options such as + * the accuracy and measurement range. + */ interface ISensorInterface { + /** + * @brief Obtains information about all sensors in the system. + * + * @param info Indicates the vector of the information about all sensors in the system. + * The information about a sensor generally includes the sensor name, sensor vendor, firmware version, + * hardware version, sensor type ID, sensor ID, maximum measurement range, accuracy, and power. For details, + * see {@link HdfSensorInformation}. + * @return Returns 0 if the information is obtained; returns a negative value otherwise. + * + * @since 2.2 + * @version 1.0 + */ GetAllSensorInfo([out] struct HdfSensorInformation[] info); + + /** + * @brief Enables the sensor available in the sensor list based on the specified sensor ID. + * The subscriber can obtain the sensor data only after the sensor is enabled. + * + * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}. + * @return Returns 0 if the sensor is successfully enabled; returns a negative value otherwise. + * + * @since 2.2 + * @version 1.0 + */ Enable([in] int sensorId); + + /** + * @brief Disables an enabled sensor. + * + * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}. + * @return Returns 0 if the sensor is successfully disabled; returns a negative value otherwise. + * + * @since 2.2 + * @version 1.0 + */ Disable([in] int sensorId); + + /** + * @brief Sets the data sampling interval and data reporting interval for the specified sensor. + * + * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}. + * @param samplingInterval Indicates the sensor data sampling interval to set, in nanoseconds. + * @param reportInterval Indicates the sensor data reporting interval, in nanoseconds. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * + * @since 2.2 + * @version 1.0 + */ SetBatch([in] int sensorId,[in] long samplingInterval, [in] long reportInterval); + + /** + * @brief Sets the data reporting mode for the specified sensor. + * + * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}. + * @param mode Indicates the data reporting mode to set. For details, see {@link SensorModeType}. + * @return Returns 0 if the sensor data reporting mode is successfully set; + * returns a negative value otherwise. + * + * @since 2.2 + * @version 1.0 + */ SetMode([in] int sensorId, [in] int mode); + + /** + * @brief Sets options for the specified sensor, including its measurement range and accuracy. + * + * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}. + * @param option Indicates the options to set, such as the measurement range and accuracy. + * @return Returns 0 if the options are successfully set; returns a negative value otherwise. + * + * @since 2.2 + * @version 1.0 + */ SetOption([in] int sensorId, [in] unsigned int option); + + /** + * @brief Registers the callback for reporting sensor data to the subscriber. + * + * @param callbackObj Indicates the callback to register. For details, see {@link ISensorCallback}. + * @return Returns 0 if the callback is successfully registered; returns a negative value otherwise. + * + * @since 2.2 + * @version 1.0 + */ Register([in] ISensorCallback callbackObj); + + /** + * @brief Deregisters the callback for reporting sensor data. + * + * @return Returns 0 if the callback is successfully deregistered; returns a negative value otherwise. + * + * @since 2.2 + * @version 1.0 + */ Unregister(); } diff --git a/sensor/v1_0/SensorTypes.idl b/sensor/v1_0/SensorTypes.idl index f15dce2c..9b3c348d 100644 --- a/sensor/v1_0/SensorTypes.idl +++ b/sensor/v1_0/SensorTypes.idl @@ -13,26 +13,66 @@ * limitations under the License. */ +/** + * @addtogroup Sensor + * @{ + * + * @brief Provides unified APIs for sensor services to access sensor drivers. + * + * A sensor service can obtain a sensor driver object or agent and then call APIs provided by this object or agent to + * access different types of sensor devices based on the sensor IDs, thereby obtaining sensor information, + * subscribing to or unsubscribing from sensor data, enabling or disabling a sensor, + * setting the sensor data reporting mode, and setting sensor options such as the accuracy and measurement range. + * + * @version 1.0 + */ + +/** + * @file SensorTypes.idl + * + * @brief Defines the data used by the sensor module, including the sensor information, + * and reported sensor data. + * + * @since 2.2 + * @version 1.0 + */ + package sensor.v1_0; +/** + * @brief Defines basic sensor information. + * + * Information about a sensor includes the sensor name, vendor, firmware version, hardware version, sensor type ID, + * sensor ID, maximum measurement range, accuracy, and power. + * + * @since 2.2 + */ struct HdfSensorInformation { - String sensorName; - String vendorName; - String firmwareVersion; - String hardwareVersion; - int sensorTypeId; - int sensorId; - float maxRange; - float accuracy; - float power; + String sensorName; /**< Sensor name */ + String vendorName; /**< Sensor vendor */ + String firmwareVersion; /**< Sensor firmware version */ + String hardwareVersion; /**< Sensor hardware version */ + int sensorTypeId; /**< Sensor type ID (described in {@link SensorTypeTag}) */ + int sensorId; /**< Sensor ID, defined by the sensor driver developer */ + float maxRange; /**< Maximum measurement range of the sensor */ + float accuracy; /**< Sensor accuracy */ + float power; /**< Sensor power */ }; +/** + * @brief Defines the data reported by the sensor. + * + * The reported sensor data includes the sensor ID, sensor algorithm version, data generation time, + * data options (such as the measurement range and accuracy), data reporting mode, data address, and data length. + * + * @since 2.2 + */ struct HdfSensorEvents { - int sensorId; - int version; - int timestamp; - unsigned int option; - int mode; - unsigned char[] data; - unsigned int dataLen; + int sensorId; /**< Sensor ID */ + int version; /**< Sensor algorithm version */ + int timestamp; /**< Time when sensor data was generated */ + unsigned int option; /**< Sensor data options, including the measurement range and accuracy */ + int mode; /**< Sensor data reporting mode */ + unsigned char[] data; /**< Sensor data vector */ + unsigned int dataLen; /**< Sensor data length */ }; -- Gitee