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