• 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 PanSensor
18  * @{
19  *
20  * @brief Provides standard open APIs for you to use common capabilities of sensors.
21  *
22  * For example, you can call these APIs to obtain sensor information,
23  * subscribe to or unsubscribe from sensor data, enable or disable a sensor,
24  * and set the sensor data reporting mode.
25  *
26  * @since 5
27  */
28 
29 /**
30  * @file sensor_agent.h
31  *
32  * @brief Declares common APIs for sensor management, such as APIs for subscribing to
33  * and obtaining sensor data, enabling a sensor, and setting the sensor data reporting mode.
34  *
35  * @since 5
36  */
37 
38 #ifndef SENSOR_AGENT_H
39 #define SENSOR_AGENT_H
40 
41 #include "hilog/log.h"
42 #include "sensor_agent_type.h"
43 
44 #undef LOG_TAG
45 #define LOG_TAG "SENSOR_LITE"
46 
47 #ifdef __cplusplus
48 #if __cplusplus
49 extern "C" {
50 #endif
51 #endif
52 
53 /**
54  * @brief Obtains information about all sensors in the system.
55  *
56  * @param sensorInfo Indicates the double pointer to the information about all sensors in the system.
57  * For details, see {@link SensorInfo}.
58  * @param count Indicates the pointer to the total number of sensors in the system.
59  * @return Returns <b>0</b> if the information is obtained; returns a non-zero value otherwise.
60  *
61  * @since 5
62  */
63 int32_t GetAllSensors(SensorInfo **sensorInfo, int32_t *count);
64 
65 /**
66  * @brief Subscribes to sensor data. The system will report the obtained sensor data to the subscriber.
67  *
68  * @param sensorTypeId Indicates the ID of a sensor type. For details, see {@link SensorTypeId}.
69  * @param user Indicates the pointer to the sensor subscriber that requests sensor data. For details,
70  * see {@link SensorUser}. A subscriber can obtain data from only one sensor.
71  * @return Returns <b>0</b> if the subscription is successful; returns a non-zero value otherwise.
72  *
73  * @since 5
74  */
75 int32_t SubscribeSensor(int32_t sensorTypeId, SensorUser *user);
76 
77 /**
78  * @brief Unsubscribes from sensor data.
79  *
80  * @param sensorTypeId Indicates the ID of a sensor type. For details, see {@link SensorTypeId}.
81  * @param user Indicates the pointer to the sensor subscriber that requests sensor data.
82  * For details, see {@link SensorUser}. A subscriber can obtain data from only one sensor.
83  * @return Returns <b>0</b> if the unsubscription is successful; returns a non-zero value otherwise.
84  *
85  * @since 5
86  */
87 int32_t UnsubscribeSensor(int32_t sensorTypeId, SensorUser *user);
88 
89 /**
90  * @brief Sets the data sampling interval and data reporting interval for the specified sensor.
91  *
92  * @param sensorTypeId Indicates the ID of a sensor type. For details, see {@link SensorTypeId}.
93  * @param user Indicates the pointer to the sensor subscriber that requests sensor data.
94  * For details, see {@link SensorUser}. A subscriber can obtain data from only one sensor.
95  * @param samplingInterval Indicates the sensor data sampling interval to set, in nanoseconds.
96  * @param reportInterval Indicates the sensor data reporting interval, in nanoseconds.
97  * @return Returns <b>0</b> if the setting is successful; returns a non-zero value otherwise.
98  *
99  * @since 5
100  */
101 int32_t SetBatch(int32_t sensorTypeId, SensorUser *user, int64_t samplingInterval, int64_t reportInterval);
102 
103 /**
104  * @brief Enables the sensor that has been subscribed to. The subscriber can obtain the sensor data
105  * only after the sensor is enabled.
106  *
107  * @param sensorTypeId Indicates the ID of a sensor type. For details, see {@link SensorTypeId}.
108  * @param user Indicates the pointer to the sensor subscriber that requests sensor data.
109  * For details, see {@link SensorUser}. A subscriber can obtain data from only one sensor.
110  * @return Returns <b>0</b> if the sensor is successfully enabled; returns a non-zero value otherwise.
111  *
112  * @since 5
113  */
114 int32_t ActivateSensor(int32_t sensorTypeId, SensorUser *user);
115 
116 /**
117  * @brief Disables an enabled sensor.
118  *
119  * @param sensorTypeId Indicates the ID of a sensor type. For details, see {@link SensorTypeId}.
120  * @param user Indicates the pointer to the sensor subscriber that requests sensor data.
121  * For details, see {@link SensorUser}. A subscriber can obtain data from only one sensor.
122  * @return Returns <b>0</b> if the sensor is successfully disabled; returns a non-zero value otherwise.
123  *
124  * @since 5
125  */
126 int32_t DeactivateSensor(int32_t sensorTypeId, SensorUser *user);
127 
128 /**
129  * @brief Sets the data reporting mode for the specified sensor.
130  *
131  * @param sensorTypeId Indicates the ID of a sensor type. For details, see {@link SensorTypeId}.
132  * @param user Indicates the pointer to the sensor subscriber that requests sensor data.
133  * For details, see {@link SensorUser}. A subscriber can obtain data from only one sensor.
134  * @param mode Indicates the data reporting mode to set. For details, see {@link SensorMode}.
135  * @return Returns <b>0</b> if the sensor data reporting mode is successfully set; returns a non-zero value otherwise.
136  *
137  * @since 5
138  */
139 int32_t SetMode(int32_t sensorTypeId, SensorUser *user, int32_t mode);
140 
141 #ifdef __cplusplus
142 #if __cplusplus
143 }
144 #endif
145 #endif
146 #endif /* SENSOR_AGENT_H */
147 /** @} */