diff --git a/sensor/v1_0/BUILD.gn b/sensor/v1_0/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0dcab2c5d7376f44e9126c77e1272782401c0b40 --- /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 0000000000000000000000000000000000000000..bb697a5c1114067988d88d47dfcedf568dc59a98 --- /dev/null +++ b/sensor/v1_0/ISensorCallback.idl @@ -0,0 +1,48 @@ +/* + * 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. + */ + +/** + * @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 new file mode 100644 index 0000000000000000000000000000000000000000..04e2ec1cf6f6d2bc2277408201ade481d9811605 --- /dev/null +++ b/sensor/v1_0/ISensorInterface.idl @@ -0,0 +1,149 @@ +/* + * 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. + */ + +/** + * @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 new file mode 100644 index 0000000000000000000000000000000000000000..9b3c348d837f750a9349fe706fc25298361c015b --- /dev/null +++ b/sensor/v1_0/SensorTypes.idl @@ -0,0 +1,78 @@ +/* + * 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. + */ + +/** + * @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; /**< 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; /**< 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 */ +};