• 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  * @version 1.0
28  */
29 
30 /**
31  * @file sensor_type.h
32  *
33  * @brief Defines the data used by the sensor module, including the sensor types, sensor information,
34  * and reported sensor data.
35  *
36  * @since 2.2
37  * @version 1.0
38  */
39 
40 #ifndef SENSOR_TYPE_H
41 #define SENSOR_TYPE_H
42 
43 #include <stdint.h>
44 
45 #ifdef __cplusplus
46 #if __cplusplus
47 extern "C" {
48 #endif
49 #endif /* __cplusplus */
50 
51 #define SENSOR_NAME_MAX_LEN       32 /**< Maximum length of the sensor name */
52 #define SENSOR_VERSION_MAX_LEN    16 /**< Maximum length of the sensor version */
53 
54 /**
55  * @brief Enumerates return values of the sensor module.
56  *
57  * @since 2.2
58  */
59 enum SensorStatus {
60     SENSOR_SUCCESS           = 0,    /**< The operation is successful. */
61     SENSOR_FAILURE           = -1,   /**< The operation failed. */
62     SENSOR_NOT_SUPPORT       = -2,   /**< The operation is not supported. */
63     SENSOR_INVALID_PARAM     = -3,   /**< The sensor parameter is invalid. */
64     SENSOR_INVALID_SERVICE   = -4,   /**< The sensor service is invalid. */
65     SENSOR_NULL_PTR          = -5,   /**< The pointer is null. */
66 };
67 
68 /**
69  * @brief Enumerates sensor types.
70  *
71  * @since 2.2
72  */
73 enum SensorTypeTag {
74     SENSOR_TYPE_NONE                = 0,   /**< None, for testing only */
75     SENSOR_TYPE_ACCELEROMETER       = 1,   /**< Acceleration sensor */
76     SENSOR_TYPE_GYROSCOPE           = 2,   /**< Gyroscope sensor */
77     SENSOR_TYPE_PHOTOPLETHYSMOGRAPH = 3,   /**< Photoplethysmography sensor */
78     SENSOR_TYPE_ELECTROCARDIOGRAPH  = 4,   /**< Electrocardiogram (ECG) sensor */
79     SENSOR_TYPE_AMBIENT_LIGHT       = 5,   /**< Ambient light sensor */
80     SENSOR_TYPE_MAGNETIC_FIELD      = 6,   /**< Magnetic field sensor */
81     SENSOR_TYPE_CAPACITIVE          = 7,   /**< Capacitive sensor */
82     SENSOR_TYPE_BAROMETER           = 8,   /**< Barometric pressure sensor */
83     SENSOR_TYPE_TEMPERATURE         = 9,   /**< Temperature sensor */
84     SENSOR_TYPE_HALL                = 10,  /**< Hall effect sensor */
85     SENSOR_TYPE_GESTURE             = 11,  /**< Gesture sensor */
86     SENSOR_TYPE_PROXIMITY           = 12,  /**< Proximity sensor */
87     SENSOR_TYPE_HUMIDITY            = 13,  /**< Humidity sensor */
88     SENSOR_TYPE_COLOR               = 14,  /**< Color sensor */
89     SENSOR_TYPE_SAR                 = 15,  /**< SAR sensor */
90     SENSOR_TYPE_AMBIENT_LIGHT1      = 16,  /**< Secondary ambient light sensor*/
91     SENSOR_TYPE_HALL1               = 17,  /**< Secondary hall effect sensor */
92     SENSOR_TYPE_MEDICAL_BEGIN       = 128, /**< The begin of medical sensorId enumeration value range */
93     SENSOR_TYPE_MEDICAL_END         = 160, /**< The end of medical sensorId enumeration value range */
94     SENSOR_TYPE_PHYSICAL_MAX        = 255, /**< Maximum type of a physical sensor */
95     SENSOR_TYPE_ORIENTATION         = 256, /**< Orientation sensor */
96     SENSOR_TYPE_GRAVITY             = 257, /**< Gravity sensor */
97     SENSOR_TYPE_LINEAR_ACCELERATION = 258, /**< Linear acceleration sensor */
98     SENSOR_TYPE_ROTATION_VECTOR     = 259, /**< Rotation vector sensor */
99     SENSOR_TYPE_AMBIENT_TEMPERATURE = 260, /**< Ambient temperature sensor */
100     SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED = 261,   /**< Uncalibrated magnetic field sensor */
101     SENSOR_TYPE_GAME_ROTATION_VECTOR        = 262,   /**< Game rotation vector sensor */
102     SENSOR_TYPE_GYROSCOPE_UNCALIBRATED      = 263,   /**< Uncalibrated gyroscope sensor */
103     SENSOR_TYPE_SIGNIFICANT_MOTION          = 264,   /**< Significant motion sensor */
104     SENSOR_TYPE_PEDOMETER_DETECTION         = 265,   /**< Pedometer detection sensor */
105     SENSOR_TYPE_PEDOMETER                   = 266,   /**< Pedometer sensor */
106     SENSOR_TYPE_POSTURE                     = 267,   /**< Posture sensor */
107     SENSOR_TYPE_HEADPOSTURE                 = 268,   /**< Headposture sensor */
108     SENSOR_TYPE_DROP_DETECT                 = 269,   /**< Drop detection sensor */
109     SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR = 277,   /**< Geomagnetic rotation vector sensor */
110     SENSOR_TYPE_HEART_RATE                  = 278,   /**< Heart rate sensor */
111     SENSOR_TYPE_DEVICE_ORIENTATION          = 279,   /**< Device orientation sensor */
112     SENSOR_TYPE_WEAR_DETECTION              = 280,   /**< Wear detection sensor */
113     SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED  = 281,   /**< Uncalibrated acceleration sensor */
114     SENSOR_TYPE_MAX,                                 /**< Maximum number of sensor types */
115 };
116 
117 /**
118  * @brief Enumerates accuracy types of sensors.
119  *
120  * @since 2.2
121  */
122 enum SensorAccuracyType {
123     SENSOR_NO_ACCURACY     = 0,  /**< No accuracy */
124     SENSOR_LOW_ACCURACY    = 1,  /**< Low accuracy */
125     SENSOR_MEDIUM_ACCURACY = 2,  /**< Medium accuracy */
126     SENSOR_HIGH_ACCURACY   = 3,  /**< High accuracy */
127     SENSOR_MAX_ACCURACY,         /**< Maximum accuracy */
128 };
129 
130 /**
131  * @brief Enumerates measurement ranges of sensors.
132  *
133  * @since 2.2
134  */
135 enum SensorRangeType {
136     SENSOR_RANGE_LEVEL1 = 0, /**< Measurement range level 1 */
137     SENSOR_RANGE_LEVEL2 = 1, /**< Measurement range level 2 */
138     SENSOR_RANGE_LEVEL3 = 2, /**< Measurement range level 3 */
139     SENSOR_RANGE_LEVEL_MAX,  /**< Maximum measurement range level */
140 };
141 
142 /**
143  * @brief Enumerates data reporting modes of sensors.
144  *
145  * @since 2.2
146  */
147 enum SensorModeType {
148     SENSOR_MODE_DEFAULT   = 0, /**< Default data reporting mode */
149     SENSOR_MODE_REALTIME  = 1, /**< Real-time data reporting mode to report a group of data each time */
150     SENSOR_MODE_ON_CHANGE = 2, /**< Real-time data reporting mode to report data upon status changes */
151     SENSOR_MODE_ONE_SHOT  = 3, /**< Real-time data reporting mode to report data only once */
152     SENSOR_MODE_FIFO_MODE = 4, /**< FIFO-based data reporting mode to report data based on the configured cache size */
153     SENSOR_MODE_MAX,           /**< Maximum sensor data reporting mode */
154 };
155 
156 /**
157  * @brief Enumerates hardware service group for sensors
158  *
159  * @since 2.2
160  */
161 enum SensorGroupType {
162     TRADITIONAL_SENSOR_TYPE = 0, /**< traditional sensor type, the sensorId enumeration value range is 128-160 */
163     MEDICAL_SENSOR_TYPE = 1,  /**< medical sensor type, the sensorId enumeration value range is not within 128-160 */
164     SENSOR_GROUP_TYPE_MAX,          /**< Maximum sensor type*/
165 };
166 
167 /**
168  * @brief Defines basic sensor information.
169  *
170  * Information about a sensor includes the sensor name, vendor, firmware version, hardware version, sensor type ID,
171  * sensor ID, maximum measurement range, accuracy, and power.
172  *
173  * @since 2.2
174  */
175 struct SensorInformation {
176     char sensorName[SENSOR_NAME_MAX_LEN]; /**< Sensor name */
177     char vendorName[SENSOR_NAME_MAX_LEN]; /**< Sensor vendor */
178     char firmwareVersion[SENSOR_VERSION_MAX_LEN]; /**< Sensor firmware version */
179     char hardwareVersion[SENSOR_VERSION_MAX_LEN]; /**< Sensor hardware version */
180     int32_t sensorTypeId; /**< Sensor type ID (described in {@link SensorTypeTag}) */
181     int32_t sensorId;     /**< Sensor ID, defined by the sensor driver developer */
182     float maxRange;       /**< Maximum measurement range of the sensor */
183     float accuracy;       /**< Sensor accuracy */
184     float power;          /**< Sensor power */
185     int64_t minDelay;     /**< Minimum sample period allowed in microseconds */
186     int64_t maxDelay;     /**< Maxmum sample period allowed in microseconds */
187     uint32_t fifoMaxEventCount; /**< Maxmum number of events of this sensor that could be batched */
188     uint32_t reserved;    /**< Reserved fields */
189 };
190 
191 /**
192  * @brief Defines the data reported by the sensor.
193  *
194  * The reported sensor data includes the sensor ID, sensor algorithm version, data generation time,
195  * data options (such as the measurement range and accuracy), data reporting mode, data address, and data length.
196  *
197  * @since 2.2
198  */
199 struct SensorEvents {
200     int32_t sensorId;  /**< Sensor ID */
201     int32_t version;   /**< Sensor algorithm version */
202     int64_t timestamp; /**< Time when sensor data was generated */
203     uint32_t option;   /**< Sensor data options, including the measurement range and accuracy */
204     int32_t mode;      /**< Sensor data reporting mode */
205     uint8_t *data;     /**< Sensor data address */
206     uint32_t dataLen;  /**< Sensor data length */
207 };
208 
209 /**
210  * @brief Defines SDC reports data object operations to the node.
211  *
212  * The reported sensor data includes the offset, type, ddrSize, minRateLevel, maxRateLevel, reserved, memAddr.
213  *
214  * @since 4.1
215  */
216 struct SdcSensorInfo {
217     uint64_t offset;
218     int32_t sensorId;
219     int32_t ddrSize;
220     int32_t minRateLevel;
221     int32_t maxRateLevel;
222     uint64_t memAddr;
223     int32_t reserved;
224 };
225 
226 /**
227  * @brief Defines the callback for reporting sensor data. This callback needs to be registered when
228  * a sensor user subscribes to sensor data. Only after the sensor is enabled, the sensor data subscriber can receive
229  * sensor data. For details, see {@link SensorInterface}.
230  *
231  * @since 2.2
232  */
233 typedef int32_t (*RecordDataCallback)(const struct SensorEvents*);
234 
235 #ifdef __cplusplus
236 #if __cplusplus
237 }
238 #endif
239 #endif /* __cplusplus */
240 
241 #endif /* SENSOR_TYPE_H */
242 /** @} */
243