• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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_type.h
31  *
32  * @brief Defines the basic data used by the sensor agent to manage sensors.
33  *
34  * @since 5
35  */
36 
37 #ifndef SENSOR_AGENT_TYPE_H
38 #define SENSOR_AGENT_TYPE_H
39 
40 #include <stdint.h>
41 
42 #ifdef __cplusplus
43 #if __cplusplus
44 extern "C" {
45 #endif
46 #endif
47 
48 /** Maximum length of the sensor name */
49 #ifndef NAME_MAX_LEN
50 #define NAME_MAX_LEN 128
51 #endif /* NAME_MAX_LEN */
52 /** Size of sensor data */
53 #ifndef SENSOR_USER_DATA_SIZE
54 #define SENSOR_USER_DATA_SIZE 104
55 #endif /* SENSOR_USER_DATA_SIZE */
56 /** Maximum length of the sensor version */
57 #ifndef VERSION_MAX_LEN
58 #define VERSION_MAX_LEN 16
59 #endif /* SENSOR_USER_DATA_SIZE */
60 
61 /**
62  * @brief Enumerates sensor types.
63  *
64  * @since 5
65  */
66 typedef enum SensorTypeId {
67     SENSOR_TYPE_ID_NONE = 0,                   /**< None */
68     SENSOR_TYPE_ID_ACCELEROMETER = 1,          /**< Acceleration sensor */
69     SENSOR_TYPE_ID_GYROSCOPE = 2,              /**< Gyroscope sensor */
70     SENSOR_TYPE_ID_AMBIENT_LIGHT = 5,          /**< Ambient light sensor */
71     SENSOR_TYPE_ID_MAGNETIC_FIELD = 6,         /**< Magnetic field sensor */
72     SENSOR_TYPE_ID_CAPACITIVE = 7,             /**< Capacitive sensor */
73     SENSOR_TYPE_ID_BAROMETER = 8,              /**< Barometric pressure sensor */
74     SENSOR_TYPE_ID_TEMPERATURE = 9,            /**< Temperature sensor */
75     SENSOR_TYPE_ID_HALL = 10,                  /**< Hall effect sensor */
76     SENSOR_TYPE_ID_GESTURE = 11,               /**< Gesture sensor */
77     SENSOR_TYPE_ID_PROXIMITY = 12,             /**< Proximity sensor */
78     SENSOR_TYPE_ID_HUMIDITY = 13,              /**< Humidity sensor */
79     SENSOR_TYPE_ID_COLOR = 14,                 /**< Color sensor */
80     SENSOR_TYPE_ID_SAR = 15,                   /**< Sar sensor */
81     SENSOR_TYPE_ID_AMBIENT_LIGHT1 = 16,        /**< Secondary ambient light sensor */
82     SENSOR_TYPE_ID_HALL_EXT = 17,              /**< Extended hall effect sensor */
83     SENSOR_TYPE_ID_PROXIMITY1 = 18,            /**< Secondary proximity sensor */
84     SENSOR_TYPE_ID_PHYSICAL_MAX = 0xFF,        /**< Maximum type ID of a physical sensor */
85     SENSOR_TYPE_ID_ORIENTATION = 256,          /**< Orientation sensor */
86     SENSOR_TYPE_ID_GRAVITY = 257,              /**< Gravity sensor */
87     SENSOR_TYPE_ID_LINEAR_ACCELERATION = 258,  /**< Linear acceleration sensor */
88     SENSOR_TYPE_ID_ROTATION_VECTOR = 259,      /**< Rotation vector sensor */
89     SENSOR_TYPE_ID_AMBIENT_TEMPERATURE = 260,  /**< Ambient temperature sensor */
90     SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED = 261,  /**< Uncalibrated magnetic field sensor */
91     SENSOR_TYPE_ID_GAME_ROTATION_VECTOR = 262,    /**< Game rotation vector sensor */
92     SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED = 263,  /**< Uncalibrated gyroscope sensor */
93     SENSOR_TYPE_ID_SIGNIFICANT_MOTION = 264,    /**< Significant motion sensor */
94     SENSOR_TYPE_ID_PEDOMETER_DETECTION = 265,   /**< Pedometer detection sensor */
95     SENSOR_TYPE_ID_PEDOMETER = 266,             /**< Pedometer sensor */
96     SENSOR_TYPE_ID_POSTURE = 267,               /**< Posture sensor */
97     SENSOR_TYPE_ID_HEADPOSTURE = 268,           /**< Head posture sensor */
98     SENSOR_TYPE_ID_DROP_DETECTION = 269,       /**< Drop detection sensor */
99     SENSOR_TYPE_ID_GEOMAGNETIC_ROTATION_VECTOR = 277,  /**< Geomagnetic rotation vector sensor */
100     SENSOR_TYPE_ID_HEART_RATE = 278,            /**< Heart rate sensor */
101     SENSOR_TYPE_ID_DEVICE_ORIENTATION = 279,    /**< Device orientation sensor */
102     SENSOR_TYPE_ID_WEAR_DETECTION = 280,        /**< Wear detection sensor */
103     SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED = 281,   /**< Uncalibrated acceleration sensor */
104     SENSOR_TYPE_ID_RPC = 282,     /**< Radio power control sensor */
105     SENSOR_TYPE_ID_FUSION_PRESSURE = 283,     /**< Fusion pressure sensor */
106     SENSOR_TYPE_ID_MAX = 300,      /**< Maximum number of sensor type IDs*/
107 } SensorTypeId;
108 
109 /**
110  * @brief Defines sensor information.
111  *
112  * @since 5
113  */
114 typedef struct SensorInfo {
115     char sensorName[NAME_MAX_LEN];   /**< Sensor name */
116     char vendorName[NAME_MAX_LEN];   /**< Sensor vendor */
117     char firmwareVersion[VERSION_MAX_LEN];  /**< Sensor firmware version */
118     char hardwareVersion[VERSION_MAX_LEN];  /**< Sensor hardware version */
119     int32_t sensorTypeId = -1;  /**< Sensor type ID */
120     int32_t sensorId = -1;      /**< Sensor ID */
121     float maxRange = 0.0;        /**< Maximum measurement range of the sensor */
122     float precision = 0.0;       /**< Sensor accuracy */
123     float power = 0.0;           /**< Sensor power */
124     int64_t minSamplePeriod = -1; /**< Minimum sample period allowed, in ns */
125     int64_t maxSamplePeriod = -1; /**< Maximum sample period allowed, in ns */
126 } SensorInfo;
127 
128 /**
129  * @brief Enumerates the accuracy levels of data reported by a sensor.
130  *
131  * @since 11
132  */
133 typedef enum SensorAccuracy {
134     /**< The sensor data is unreliable.
135      * It is possible that the sensor does not contact with the device to measure.*/
136     ACCURACY_UNRELIABLE = 0,
137     /**< The sensor data is at a low accuracy level.
138      * You are required to calibrate the data based on the environment before using it. */
139     ACCURACY_LOW = 1,
140     /**< The sensor data is at a medium accuracy level.
141      * You are advised to calibrate the data based on the environment before using it. */
142     ACCURACY_MEDIUM = 2,
143     /**< The sensor data is at a high accuracy level.
144      * The data can be used directly. */
145     ACCURACY_HIGH = 3,
146 } SensorAccuracy;
147 
148 /**
149  * @brief Defines the data reported by the sensor.
150  *
151  * @since 5
152  */
153 typedef struct SensorEvent {
154     int32_t sensorTypeId = -1;  /**< Sensor type ID */
155     int32_t version = -1;       /**< Sensor algorithm version */
156     int64_t timestamp = -1;     /**< Time when sensor data was reported */
157     int32_t option = -1;       /**< Sensor data options, including the measurement range and accuracy */
158     int32_t mode = -1;          /**< Sensor data reporting mode (described in {@link SensorMode}) */
159     uint8_t *data = nullptr;         /**< Sensor data */
160     uint32_t dataLen = 0;      /**< Sensor data length */
161 } SensorEvent;
162 
163 /**
164  * @brief Defines the callback for data reporting by the sensor agent.
165  *
166  * @since 5
167  */
168 typedef void (*RecordSensorCallback)(SensorEvent *event);
169 
170 /**
171  * @brief Defines a reserved field for the sensor data subscriber.
172  *
173  * @since 5
174  */
175 typedef struct UserData {
176     char userData[SENSOR_USER_DATA_SIZE];  /**< Reserved for the sensor data subscriber */
177 } UserData;
178 
179 /**
180  * @brief Defines information about the sensor data subscriber.
181  *
182  * @since 5
183  */
184 typedef struct SensorUser {
185     char name[NAME_MAX_LEN];  /**< Name of the sensor data subscriber */
186     RecordSensorCallback callback;   /**< Callback for reporting sensor data */
187     UserData *userData = nullptr;              /**< Reserved field for the sensor data subscriber */
188 } SensorUser;
189 
190 /**
191  * @brief Enumerates data reporting modes of sensors.
192  *
193  * @since 5
194  */
195 typedef enum SensorMode {
196     SENSOR_DEFAULT_MODE = 0,   /**< Default data reporting mode */
197     SENSOR_REALTIME_MODE = 1,  /**< Real-time data reporting mode to report a group of data each time */
198     SENSOR_ON_CHANGE = 2,   /**< Real-time data reporting mode to report data upon status changes */
199     SENSOR_ONE_SHOT = 3,    /**< Real-time data reporting mode to report data only once */
200     SENSOR_FIFO_MODE = 4,   /**< FIFO-based data reporting mode to report data based on the <b>BatchCnt</b> setting */
201     SENSOR_MODE_MAX2,        /**< Maximum sensor data reporting mode */
202 } SensorMode;
203 
204 /**
205  * @brief Defines the struct of the data reported by the acceleration sensor.
206  * This sensor measures the acceleration applied to the device on three physical axes (x, y, and z), in m/s2.
207  *
208  */
209 typedef struct AccelData {
210     float x = 0.0;
211     float y = 0.0;
212     float z = 0.0;
213 } AccelData;
214 
215 /**
216  * @brief Defines the struct of the data reported by the linear acceleration sensor.
217  * This sensor measures the linear acceleration applied to the device on three physical axes (x, y, and z), in m/s2.
218  */
219 typedef struct LinearAccelData {
220     float x = 0.0;
221     float y = 0.0;
222     float z = 0.0;
223 } LinearAccelData;
224 
225 /**
226  * @brief Defines the struct of the data reported by the gyroscope sensor.
227  * This sensor measures the angular velocity of the device on three physical axes (x, y, and z), in rad/s.
228  */
229 typedef struct GyroscopeData {
230     float x = 0.0;
231     float y = 0.0;
232     float z = 0.0;
233 } GyroscopeData;
234 
235 /**
236  * @brief Defines the struct of the data reported by the gravity sensor.
237  * This sensor measures the acceleration of gravity applied to the device on three physical axes (x, y, and z), in m/s2.
238  */
239 typedef struct GravityData {
240     float x = 0.0;
241     float y = 0.0;
242     float z = 0.0;
243 } GravityData;
244 
245 /**
246  * @brief Defines the struct of the data reported by the uncalibrated acceleration sensor.
247  * This sensor measures the uncalibrated acceleration applied to the device on three physical axes (x, y, and z),
248  * in m/s2.
249  */
250 typedef struct AccelUncalibratedData {
251     float x = 0.0;
252     float y = 0.0;
253     float z = 0.0;
254     float biasX = 0.0;
255     float biasY = 0.0;
256     float biasZ = 0.0;
257 } AccelUncalibratedData;
258 
259 /**
260  * @brief Defines the struct of the data reported by the uncalibrated gyroscope sensor.
261  * This sensor measures the uncalibrated angular velocity of the device on three physical axes (x, y, and z), in rad/s.
262  */
263 typedef struct GyroUncalibratedData {
264     float x = 0.0;
265     float y = 0.0;
266     float z = 0.0;
267     float biasX = 0.0;
268     float biasY = 0.0;
269     float biasZ = 0.0;
270 } GyroUncalibratedData;
271 
272 /**
273  * @brief Defines the struct of the data reported by the significant motion sensor.
274  * This sensor detects whether there is substantial motion in the device on the three physical axes (x, y, and z).
275  * The value <b>1</b> means that there is substantial motion, and <b>0</b> means the opposite.
276  */
277 typedef struct SignificantMotionData {
278     float scalar = 0.0;
279 } SignificantMotionData;
280 
281 /**
282  * @brief Defines the struct of the data reported by the pedometer detection sensor.
283  * This sensor detects whether a user is walking.
284  * The value <b>1</b> means that the user is walking, and <b>0</b> means the opposite.
285  */
286 typedef struct PedometerDetectData {
287     float scalar = 0.0;
288 } PedometerDetectData;
289 
290 /**
291  * @brief Defines the struct of the data reported by the pedometer sensor.
292  * This sensor counts the number of steps taken by a user.
293  */
294 typedef struct PedometerData {
295     float steps = 0.0;
296 } PedometerData;
297 
298 /**
299  * @brief Defines the struct of the data reported by the ambient temperature sensor.
300  * This sensor measures the ambient temperature, in degrees Celsius (°C).
301  */
302 typedef struct AmbientTemperatureData {
303     float temperature = 0.0;
304 } AmbientTemperatureData;
305 
306 /**
307  * @brief Defines the struct of the data reported by the humidity sensor.
308  * This sensor measures the relative humidity of the environment,
309  * expressed as a percentage (%).
310  */
311 typedef struct HumidityData {
312     float humidity = 0.0;
313 } HumidityData;
314 
315 /**
316  * @brief Defines the struct of the data reported by the temperature sensor.
317  * This sensor measures the relative temperature of the environment, in degrees Celsius (°C).
318  */
319 typedef struct TemperatureData {
320     float temperature = 0.0;
321 } TemperatureData;
322 
323 /**
324  * @brief Defines the struct of the data reported by the magnetic field sensor.
325  * This sensor measures the ambient geomagnetic field in three physical axes (x, y, z), in μT.
326  */
327 typedef struct MagneticFieldData {
328     float x = 0.0;
329     float y = 0.0;
330     float z = 0.0;
331 } MagneticFieldData;
332 
333 /**
334  * @brief Defines the struct of the data reported by the uncalibrated magnetic field sensor.
335  * This sensor measures the uncalibrated ambient geomagnetic field in three physical axes (x, y, z), in μT.
336  */
337 typedef struct MagneticFieldUncalibratedData {
338     float x = 0.0;
339     float y = 0.0;
340     float z = 0.0;
341     float biasX = 0.0;
342     float biasY = 0.0;
343     float biasZ = 0.0;
344 } MagneticFieldUncalibratedData;
345 
346 /**
347  * @brief Defines the struct of the data reported by the barometer sensor.
348  * This sensor measures the atmospheric pressure, in hPa or mb.
349  */
350 typedef struct BarometerData {
351     float pressure = 0.0;
352 } BarometerData;
353 
354 /**
355  * @brief Defines the struct of the data reported by the device orientation sensor.
356  * This sensor measures the direction of rotation of the device, in rad.
357  */
358 typedef struct DeviceOrientationData {
359     float scalar = 0.0;
360 } DeviceOrientationData;
361 
362 /**
363  * @brief Defines the struct of the data reported by the orientation sensor.
364  * This sensor measures the angle of rotation of the device around all three physical axes (z, x, y), in rad.
365  */
366 typedef struct OrientationData {
367     float alpha = 0.0; /**< The device rotates at an angle around the Z axis. */
368     float beta = 0.0;  /**< The device rotates at an angle around the X axis. */
369     float gamma = 0.0; /**< The device rotates at an angle around the Y axis. */
370 } OrientationData;
371 
372 /**
373  * @brief Defines the struct of the data reported by the rotation vector sensor.
374  * This sensor measures the rotation vector of the device.
375  * It is synthesized by the acceleration sensor and gyroscope sensor.
376  */
377 typedef struct RotationVectorData {
378     float x = 0.0;
379     float y = 0.0;
380     float z = 0.0;
381     float w = 0.0;
382 } RotationVectorData;
383 
384 /**
385  * @brief Defines the struct of the data reported by the game rotation vector sensor.
386  * This sensor measures the game rotation vector of the device.
387  * It is synthesized by the acceleration sensor and gyroscope sensor.
388  */
389 typedef struct GameRotationVectorData {
390     float x = 0.0;
391     float y = 0.0;
392     float z = 0.0;
393     float w = 0.0;
394 } GameRotationVectorData;
395 
396 /**
397  * @brief Defines the struct of the data reported by the geomagnetic rotation vector sensor.
398  * This sensor measures the geomagnetic rotation vector of the device.
399  * It is synthesized by the acceleration sensor and magnetic field sensor.
400  */
401 typedef struct GeomagneticRotaVectorData {
402     float x = 0.0;
403     float y = 0.0;
404     float z = 0.0;
405     float w = 0.0;
406 } GeomagneticRotaVectorData;
407 
408 /**
409  * @brief Defines the struct of the data reported by the proximity light sensor.
410  * This sensor measures the proximity or distance of visible objects relative to the device display,
411  * where 0 indicates proximity and 1 indicates distance.
412  */
413 typedef struct ProximityData {
414     float distance = 0.0;
415 } ProximityData;
416 
417 /**
418  * @brief Defines the struct of the data reported by the ambient light sensor.
419  * This sensor measures the intensity of light around the device, in lux.
420  */
421 typedef struct AmbientLightData {
422     float intensity = 0.0;
423     float colorTemperature = 0.0;
424     float infraredLuminance = 0.0;
425 } AmbientLightData;
426 
427 /**
428  * @brief Defines the struct of the data reported by the hall effect sensor.
429  * This sensor measures whether there is magnetic attraction around the device.
430  * The value <b>1</b> means that there is magnet attraction, and <b>0</b> means the opposite.
431  */
432 typedef struct HallData {
433     float status = 0.0;
434 } HallData;
435 
436 /**
437  * @brief Defines the struct of the data reported by the heart rate sensor.
438  * This sensor measures a user's heart rate, in bpm.
439  */
440 typedef struct HeartRateData {
441     float heartRate = 0.0;
442 } HeartRateData;
443 
444 /**
445  * @brief Defines the struct of the data reported by the wear detection sensor.
446  * This sensor detects whether a user is wearing a wearable device.
447  * The value <b>1</b> means that the user is wearing a wearable device, and <b>0</b> means the opposite.
448  */
449 typedef struct WearDetectionData {
450     float value = 0.0;
451 } WearDetectionData;
452 
453 /**
454  * @brief Defines the struct of the data reported by the color sensor.
455  * This sensor is used to measure the luminous intensity (in lux) and color temperature (in Kelvin).
456  */
457 typedef struct ColorData {
458     float lightIntensity = 0.0;
459     float colorTemperature = 0.0;
460 } ColorData;
461 
462 /**
463  * @brief Defines the struct of the data reported by the SAR sensor.
464  * This sensor measures the SAR, in W/kg.
465  */
466 typedef struct SarData {
467     float absorptionRatio = 0.0;
468 } SarData;
469 
470 /**
471  * @brief Defines the struct of the data reported by the RPC sensor.
472  * This sensor measures the radio power control.
473  */
474 typedef struct RPCData {
475     float absorptionRatio = 0.0;
476     float threshold = 0.0;
477     float offset = 0.0;
478 } RPCData;
479 
480 /**
481  * @brief Defines the struct of the data reported by the posture sensor.
482  * This sensor measures the angle between two screens, in degrees. The angle ranges from 0 to 180.
483  */
484 typedef struct PostureData {
485     float gxm = 0.0f; /**< The main screen acceleration on the x axis */
486     float gym = 0.0f; /**< The main screen acceleration on the y axis */
487     float gzm = 0.0f; /**< The main screen acceleration on the z axis */
488     float gxs = 0.0f; /**< The second screen acceleration on the x axis */
489     float gys = 0.0f; /**< The second screen acceleration on the y axis */
490     float gzs = 0.0f; /**< The second screen acceleration on the z axis */
491     float angle = 0.0f; /**< The angle between two screens. The angle ranges from 0 to 180 degrees. */
492     float screenAndPostureStatus = 0.0f; /**< The screen and posture status. */
493     float gxt = 0.0f; /**< The third screen acceleration on the x axis */
494     float gyt = 0.0f; /**< The third screen acceleration on the y axis */
495     float gzt = 0.0f; /**< The third screen acceleration on the z axis */
496     float abAngle = 0.0f; /**< The angle between second and third screen. The angle ranges from 0 to 180 degrees. */
497     float abFoldedState = 0.0f; /**< The state between second and third screen. */
498 } PostureData;
499 
500 /**
501  * @brief Defines the struct of the data reported by the head posture sensor.
502  * This sensor measures the head posture of user.
503  */
504 typedef struct HeadPostureData {
505     int32_t order = 0;
506     float w = 0.0;
507     float x = 0.0;
508     float y = 0.0;
509     float z = 0.0;
510 } HeadPostureData;
511 
512 typedef struct DropDetectionData {
513     float status = 0.0;
514 } DropDetectionData;
515 
516 typedef struct SensorActiveInfo {
517     int32_t pid = -1;        /**< PID */
518     int32_t sensorId = -1;   /**< Sensor ID */
519     int64_t samplingPeriodNs = -1;  /**< Sample period, in ns */
520     int64_t maxReportDelayNs = -1;  /**< Maximum Report Delay, in ns */
521 } SensorActiveInfo;
522 
523 typedef struct FusionPressureData {
524     float fusionPressure = 0.0f;
525 } FusionPressureData;
526 
527 typedef void (*SensorActiveInfoCB)(SensorActiveInfo &sensorActiveInfo);
528 
529 #ifdef __cplusplus
530 #if __cplusplus
531 }
532 #endif
533 #endif
534 #endif /* SENSOR_AGENT_TYPE_H */
535 /**< @} */
536