• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup Sensor
18  * @{
19  *
20  * @brief Provides unified APIs for sensor services to access sensor drivers.
21  *
22  * A sensor service can obtain a sensor driver object or agent and then call APIs provided by this object or agent to
23  * access different types of sensor devices based on the sensor IDs, thereby obtaining sensor information,
24  * subscribing to or unsubscribing from sensor data, enabling or disabling a sensor,
25  * setting the sensor data reporting mode, and setting sensor options such as the accuracy and measurement range.
26  *
27  * @since 2.2
28  */
29 
30 /**
31  * @file sensor_if.h
32  *
33  * @brief Declares the APIs provided by the sensor module for obtaining sensor information, subscribing to or
34  * unsubscribing from sensor data, enabling or disabling a sensor, setting the sensor data reporting mode,
35  * and setting sensor options such as the accuracy and measurement range.
36  *
37  * @since 2.2
38  * @version 1.0
39  */
40 
41 #ifndef SENSOR_IF_H
42 #define SENSOR_IF_H
43 
44 #include "sensor_type.h"
45 
46 #ifdef __cplusplus
47 #if __cplusplus
48 extern "C" {
49 #endif
50 #endif /* __cplusplus */
51 
52 /**
53  * @brief Defines the functions for performing basic operations on sensors.
54  *
55  * The operations include obtaining sensor information, subscribing to or unsubscribing from sensor data,
56  * enabling or disabling a sensor, setting the sensor data reporting mode, and setting sensor options such as
57  * the accuracy and measurement range.
58  */
59 struct SensorInterface {
60     /**
61      * @brief Obtains information about all sensors in the system.
62      *
63      * @param sensorInfo Indicates the double pointer to the information about all sensors in the system.
64      * The information about a sensor generally includes the sensor name, sensor vendor, firmware version,
65      * hardware version, sensor type ID, sensor ID, maximum measurement range, accuracy, and power. For details,
66      * see {@link SensorInformation}.
67      * @param count Indicates the pointer to the total number of sensors in the system.
68      * @return Returns <b>0</b> if the information is obtained; returns a negative value otherwise.
69      *
70      * @since 2.2
71      * @version 1.0
72      */
73     int32_t (*GetAllSensors)(struct SensorInformation **sensorInfo, int32_t *count);
74 
75     /**
76      * @brief Enables the sensor available in the sensor list based on the specified sensor ID.
77      * The subscriber can obtain the sensor data only after the sensor is enabled.
78      *
79      * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}.
80      * @return Returns <b>0</b> if the sensor is successfully enabled; returns a negative value otherwise.
81      *
82      * @since 2.2
83      * @version 1.0
84      */
85     int32_t (*Enable)(int32_t sensorId);
86 
87     /**
88      * @brief Disables an enabled sensor.
89      *
90      * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}.
91      * @return Returns <b>0</b> if the sensor is successfully disabled; returns a negative value otherwise.
92      *
93      * @since 2.2
94      * @version 1.0
95      */
96     int32_t (*Disable)(int32_t sensorId);
97 
98     /**
99      * @brief Sets the data sampling interval and data reporting interval for the specified sensor.
100      *
101      * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}.
102      * @param samplingInterval Indicates the sensor data sampling interval to set, in nanoseconds.
103      * @param reportInterval Indicates the sensor data reporting interval, in nanoseconds.
104      * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise.
105      *
106      * @since 2.2
107      * @version 1.0
108      */
109     int32_t (*SetBatch)(int32_t sensorId, int64_t samplingInterval, int64_t reportInterval);
110 
111     /**
112      * @brief Sets the data reporting mode for the specified sensor.
113      *
114      * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}.
115      * @param mode Indicates the data reporting mode to set. For details, see {@link SensorModeType}.
116      * @return Returns <b>0</b> if the sensor data reporting mode is successfully set;
117      * returns a negative value otherwise.
118      *
119      * @since 2.2
120      * @version 1.0
121      */
122     int32_t (*SetMode)(int32_t sensorId, int32_t mode);
123 
124     /**
125      * @brief Sets options for the specified sensor, including its measurement range and accuracy.
126      *
127      * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}.
128      * @param option Indicates the options to set, such as the measurement range and accuracy.
129      * @return Returns <b>0</b> if the options are successfully set; returns a negative value otherwise.
130      *
131      * @since 2.2
132      * @version 1.0
133      */
134     int32_t (*SetOption)(int32_t sensorId, uint32_t option);
135 
136     /**
137      * @brief Registers the callback for reporting sensor data to the subscriber.
138      *
139      * @param groupId Indicates the sensor group ID.
140      * The sensorId enumeration value range is 128-160, which means that the medical sensor service is subscribed.
141      * It only needs to be subscribed once successfully, and there is no need to subscribe repeatedly.
142      * The sensorId enumeration value range is not within 128-160, which means that the traditional sensor
143      * is subscribed, and the subscription is successful once.
144      * @param cb Indicates the callback to register. For details, see {@link RecordDataCallback}.
145      * @return Returns <b>0</b> if the callback is successfully registered; returns a negative value otherwise.
146      *
147      * @since 2.2
148      * @version 1.0
149      */
150     int32_t (*Register)(int32_t groupId, RecordDataCallback cb);
151 
152     /**
153      * @brief Deregisters the callback for reporting sensor data.
154      *
155      * @param groupId Indicates the sensor group ID.
156      * The sensorId enumeration value range is 128-160, which means that the medical sensor service is subscribed.
157      * It only needs to cancel the subscription once successfully, and there is no need to
158      * cancel the subscription repeatedly. The sensorId enumeration value range is not within 128-160,
159      * which means that the traditional sensor is subscribed. You can cancel the subscription once successfully.
160      * @param cb Indicates the callback to register. For details, see {@link RecordDataCallback}.
161      * @return Returns <b>0</b> if the callback is successfully deregistered; returns a negative value otherwise.
162      *
163      * @since 2.2
164      * @version 1.0
165      */
166     int32_t (*Unregister)(int32_t groupId, RecordDataCallback cb);
167 
168     /**
169      * @brief Obtain the sensor event data in the small system.
170      *
171      * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}.
172      * @param event Indicates the vector of the sensor event data in the system.
173      * The sensor event data includes the sensor ID, sensor algorithm version, data generation time,
174      * data options (such as the measurement range and accuracy), data reporting mode, data address, and data length.
175      * For details, see {@link HdfSensorEvents}.
176      * @return Returns <b>0</b> if the event data is obtained; returns a negative value otherwise.
177      *
178      * @since 2.2
179      * @version 1.0
180      */
181     int32_t (*ReadData)(int32_t sensorId, struct SensorEvents *event);
182 };
183 
184 /**
185  * @brief Creates a <b>SensorInterface</b> instance.
186  *
187  * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}.
188  * You can use the instance to obtain sensor information, subscribe to or unsubscribe from sensor data,
189  * enable or disable a sensor, set the sensor data reporting mode, and set the sensor options such as the accuracy and
190  * measurement range.
191  * @param cb Indicates the callback to register. For details, see {@link RecordDataCallback}.
192  * @return Returns a non-zero value if the instance is successfully created; returns <b>0</b> otherwise.
193  *
194  * @since 2.2
195  * @version 1.0
196  */
197 const struct SensorInterface *NewSensorInterfaceInstance(void);
198 
199 /**
200  * @brief Releases the <b>SensorInterface</b> instance.
201  *
202  * @return Returns <b>0</b> if the instance is successfully released; returns a negative value otherwise.
203  *
204  * @since 2.2
205  * @version 1.0
206  */
207 int32_t FreeSensorInterfaceInstance(void);
208 
209 #ifdef __cplusplus
210 #if __cplusplus
211 }
212 #endif
213 #endif /* __cplusplus */
214 
215 #endif /* SENSOR_IF_H */
216 /** @} */
217