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_PHYSICAL_MAX = 0xFF, /**< Maximum type ID of a physical sensor */ 82 SENSOR_TYPE_ID_ORIENTATION = 256, /**< Orientation sensor */ 83 SENSOR_TYPE_ID_GRAVITY = 257, /**< Gravity sensor */ 84 SENSOR_TYPE_ID_LINEAR_ACCELERATION = 258, /**< Linear acceleration sensor */ 85 SENSOR_TYPE_ID_ROTATION_VECTOR = 259, /**< Rotation vector sensor */ 86 SENSOR_TYPE_ID_AMBIENT_TEMPERATURE = 260, /**< Ambient temperature sensor */ 87 SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED = 261, /**< Uncalibrated magnetic field sensor */ 88 SENSOR_TYPE_ID_GAME_ROTATION_VECTOR = 262, /**< Game rotation vector sensor */ 89 SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED = 263, /**< Uncalibrated gyroscope sensor */ 90 SENSOR_TYPE_ID_SIGNIFICANT_MOTION = 264, /**< Significant motion sensor */ 91 SENSOR_TYPE_ID_PEDOMETER_DETECTION = 265, /**< Pedometer detection sensor */ 92 SENSOR_TYPE_ID_PEDOMETER = 266, /**< Pedometer sensor */ 93 SENSOR_TYPE_ID_GEOMAGNETIC_ROTATION_VECTOR = 277, /**< Geomagnetic rotation vector sensor */ 94 SENSOR_TYPE_ID_HEART_RATE = 278, /**< Heart rate sensor */ 95 SENSOR_TYPE_ID_DEVICE_ORIENTATION = 279, /**< Device orientation sensor */ 96 SENSOR_TYPE_ID_WEAR_DETECTION = 280, /**< Wear detection sensor */ 97 SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED = 281, /**< Uncalibrated acceleration sensor */ 98 SENSOR_TYPE_ID_MAX = 30, /**< Maximum number of sensor type IDs*/ 99 } SensorTypeId; 100 101 /** 102 * @brief Defines sensor information. 103 * 104 * @since 5 105 */ 106 typedef struct SensorInfo { 107 char sensorName[NAME_MAX_LEN]; /**< Sensor name */ 108 char vendorName[NAME_MAX_LEN]; /**< Sensor vendor */ 109 char firmwareVersion[VERSION_MAX_LEN]; /**< Sensor firmware version */ 110 char hardwareVersion[VERSION_MAX_LEN]; /**< Sensor hardware version */ 111 int32_t sensorTypeId; /**< Sensor type ID */ 112 int32_t sensorId; /**< Sensor ID */ 113 float maxRange; /**< Maximum measurement range of the sensor */ 114 float precision; /**< Sensor accuracy */ 115 float power; /**< Sensor power */ 116 int64_t minSamplePeriod; /**< Minimum sample period allowed, in ns */ 117 int64_t maxSamplePeriod; /**< Maximum sample period allowed, in ns */ 118 } SensorInfo; 119 120 /** 121 * @brief Defines the data reported by the sensor. 122 * 123 * @since 5 124 */ 125 typedef struct SensorEvent { 126 int32_t sensorTypeId; /**< Sensor type ID */ 127 int32_t version; /**< Sensor algorithm version */ 128 int64_t timestamp; /**< Time when sensor data was reported */ 129 uint32_t option; /**< Sensor data options, including the measurement range and accuracy */ 130 int32_t mode; /**< Sensor data reporting mode (described in {@link SensorMode}) */ 131 uint8_t *data = nullptr; /**< Sensor data */ 132 uint32_t dataLen; /**< Sensor data length */ 133 } SensorEvent; 134 135 /** 136 * @brief Defines the callback for data reporting by the sensor agent. 137 * 138 * @since 5 139 */ 140 typedef void (*RecordSensorCallback)(SensorEvent *event); 141 142 /** 143 * @brief Defines a reserved field for the sensor data subscriber. 144 * 145 * @since 5 146 */ 147 typedef struct UserData { 148 char userData[SENSOR_USER_DATA_SIZE]; /**< Reserved for the sensor data subscriber */ 149 } UserData; 150 151 /** 152 * @brief Defines information about the sensor data subscriber. 153 * 154 * @since 5 155 */ 156 typedef struct SensorUser { 157 char name[NAME_MAX_LEN]; /**< Name of the sensor data subscriber */ 158 RecordSensorCallback callback; /**< Callback for reporting sensor data */ 159 UserData *userData = nullptr; /**< Reserved field for the sensor data subscriber */ 160 } SensorUser; 161 162 /** 163 * @brief Enumerates data reporting modes of sensors. 164 * 165 * @since 5 166 */ 167 typedef enum SensorMode { 168 SENSOR_DEFAULT_MODE = 0, /**< Default data reporting mode */ 169 SENSOR_REALTIME_MODE = 1, /**< Real-time data reporting mode to report a group of data each time */ 170 SENSOR_ON_CHANGE = 2, /**< Real-time data reporting mode to report data upon status changes */ 171 SENSOR_ONE_SHOT = 3, /**< Real-time data reporting mode to report data only once */ 172 SENSOR_FIFO_MODE = 4, /**< FIFO-based data reporting mode to report data based on the <b>BatchCnt</b> setting */ 173 SENSOR_MODE_MAX2, /**< Maximum sensor data reporting mode */ 174 } SensorMode; 175 176 /** 177 * @brief Defines the accelerometer data structure. Measures the acceleration applied to 178 * the device on three physical axes (x, y, and z) in m/s2. 179 * 180 */ 181 typedef struct AccelData { 182 float x; 183 float y; 184 float z; 185 } AccelData; 186 187 /** 188 * @brief Defines the linear accelerometer data structure. Measures the linear acceleration applied to 189 * the device on three physical axes (x, y, and z) in m/s2. 190 */ 191 typedef struct LinearAccelData { 192 float x; 193 float y; 194 float z; 195 } LinearAccelData; 196 197 /** 198 * @brief Defines the gyroscope sensor data structure. Measures the rotational angular velocity of the 199 * device on three physical axes (x, y, and z) in rad/s. 200 */ 201 typedef struct GyroscopeData { 202 float x; 203 float y; 204 float z; 205 } GyroscopeData; 206 207 /** 208 * @brief Defines the gravity sensor data structure. Measures the acceleration of gravity applied 209 * to the device on three physical axes (x, y, and z) in m/s2. 210 */ 211 typedef struct GravityData { 212 float x; 213 float y; 214 float z; 215 } GravityData; 216 217 /** 218 * @brief Defines the uncalibrated accelerometer data structure. Measures the uncalibrated accelerometer applied to 219 * the device on three physical axes (x, y, and z) in m/s2. 220 */ 221 typedef struct AccelUncalibratedData { 222 float x; 223 float y; 224 float z; 225 float biasX; 226 float biasY; 227 float biasZ; 228 } AccelUncalibratedData; 229 230 /** 231 * @brief Defines the uncalibrated gyroscope sensor data structure. Measures the uncalibrated rotational angular velocity of the 232 * device on three physical axes (x, y, and z) in rad/s. 233 */ 234 typedef struct GyroUncalibratedData { 235 float x; 236 float y; 237 float z; 238 float biasX; 239 float biasY; 240 float biasZ; 241 } GyroUncalibratedData; 242 243 /** 244 * @brief Defines the significant Motion sensor data structure. Measures whether there is substantial motion in the device on 245 * the three physical axes (x, y, and z); a value of 1 indicates the presence of large motion; and a value of 0 indicates that 246 * there is no large movement. 247 */ 248 typedef struct SignificantMotionData { 249 float scalar; 250 } SignificantMotionData; 251 252 /** 253 * @brief Defines the pedometer detection sensor data structure. Detects the user's step counting action; if the value is 1, it 254 * means that the user has generated the action of counting walking; if the value is 0, it means that the user has not moved. 255 */ 256 typedef struct PedometerDetectData { 257 float scalar; 258 } PedometerDetectData; 259 260 /** 261 * @brief Defines the pedometer sensor data structure. Counts the number of steps taken by the user. 262 */ 263 typedef struct PedometerData { 264 float steps; 265 } PedometerData; 266 267 /** 268 * @brief Defines the ambient temperature sensor data structure. Measures ambient temperature in degrees Celsius (°C) 269 */ 270 typedef struct AmbientTemperatureData { 271 float temperature; 272 } AmbientTemperatureData; 273 274 /** 275 * @brief Define the humidity sensor data structure. Measures the relative humidity of the environment, 276 * expressed as a percentage (%). 277 */ 278 typedef struct HumidityData { 279 float humidity; 280 } HumidityData; 281 282 /** 283 * @brief Define the temperature sensor data structure. Measures the relative temperature of the environment 284 * in degrees Celsius (°C) 285 */ 286 typedef struct TemperatureData { 287 float temperature; 288 } TemperatureData; 289 290 /** 291 * @brief Defines the magnetic field sensor data structure. Measure the ambient geomagnetic field in three 292 * physical axes (x, y, z) in μT. 293 */ 294 typedef struct MagneticFieldData { 295 float x; 296 float y; 297 float z; 298 } MagneticFieldData; 299 300 /** 301 * @brief Defines the uncalibrated magnetic field sensor data structure. Measure the uncalibrated ambient geomagnetic field in three 302 * physical axes (x, y, z) in μT. 303 */ 304 typedef struct MagneticFieldUncalibratedData { 305 float x; 306 float y; 307 float z; 308 float biasX; 309 float biasY; 310 float biasZ; 311 } MagneticFieldUncalibratedData; 312 313 /** 314 * @brief Defines the barometer sensor data structure. Measures ambient air pressure in : hPa or mbar. 315 */ 316 typedef struct BarometerData { 317 float pressure; 318 } BarometerData; 319 320 /** 321 * @brief Defines the device orientation sensor data structure. Measure the direction of rotation of the device in rad. 322 */ 323 typedef struct DeviceOrientationData { 324 float scalar; 325 } DeviceOrientationData; 326 327 /** 328 * @brief Defines the orientation sensor data structure. Measures the angle value of the rotation of the device 329 * around all three physical axes (z, x, y), in rad. 330 */ 331 typedef struct OrientationData { 332 float alpha; /**< The device rotates at an angle around the Z axis */ 333 float beta; /**< The device rotates at an angle around the X axis */ 334 float gamma; /**< The device rotates at an angle around the Y axis */ 335 } OrientationData; 336 337 /** 338 * @brief Defines the rotation vector sensor data structure. Measuring device game rotation vector, composite sensor: 339 * synthesized by acceleration sensor, gyroscope sensor. 340 */ 341 typedef struct RotationVectorData { 342 float x; 343 float y; 344 float z; 345 float w; 346 } RotationVectorData; 347 348 /** 349 * @brief Defines the game rotation vector sensor data structure. Measuring device game rotation vector, composite sensor: 350 * synthesized by acceleration sensor, gyroscope sensor. 351 */ 352 typedef struct GameRotationVectorData { 353 float x; 354 float y; 355 float z; 356 float w; 357 } GameRotationVectorData; 358 359 /** 360 * @brief Defines the geomagnetic rotation vector sensor data structure. Measuring device geomagnetic rotation vector, composite 361 * sensor: synthesized by acceleration sensor and magnetic field sensor. 362 */ 363 typedef struct GeomagneticRotaVectorData { 364 float x; 365 float y; 366 float z; 367 float w; 368 } GeomagneticRotaVectorData; 369 370 /** 371 * @brief Defines the proximity light sensor data structure. Measures the proximity or distance of visible objects relative to 372 * the device display, where 0 indicates proximity and 1 indicates distance. 373 */ 374 typedef struct ProximityData { 375 float distance; 376 } ProximityData; 377 378 /** 379 * @brief Defines the ambient light sensor data structure. Measures the intensity of light around the device in lux. 380 */ 381 typedef struct AmbientLightData { 382 float intensity; 383 } AmbientLightData; 384 385 /** 386 * @brief Defines the hall sensor data structure. Measure whether there is magnetic attraction around the device, 387 * 0 means no magnet attraction, and 1 means there is magnet attraction. 388 */ 389 typedef struct HallData { 390 float status; 391 } HallData; 392 393 /** 394 * @brief Define the heart rate sensor data structure. Measures the user's heart rate, in bpm. 395 */ 396 typedef struct HeartRateData { 397 float heartRate; 398 } HeartRateData; 399 400 /** 401 * @brief Defines the wear detection sensor data structure. To detect whether the user is wearing it, 402 * 0 means not wearing it, while 1 means wearing it 403 */ 404 typedef struct WearDetectionData { 405 float value; 406 } WearDetectionData; 407 408 typedef struct SensorActiveInfo { 409 int32_t pid = -1; /**< PID */ 410 int32_t sensorId = -1; /**< Sensor ID */ 411 int64_t samplingPeriodNs = -1; /**< Sample period, in ns */ 412 int64_t maxReportDelayNs = -1; /**< Maximum Report Delay, in ns */ 413 } SensorActiveInfo; 414 415 typedef void (*SensorActiveInfoCB)(SensorActiveInfo &sensorActiveInfo); 416 417 #ifdef __cplusplus 418 #if __cplusplus 419 } 420 #endif 421 #endif 422 #endif /* SENSOR_AGENT_TYPE_H */ 423 /**< @} */