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_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 #define SENSOR_ERROR_UNKNOWN (-1) 49 #define SENSOR_ERROR_INVALID_ID (-2) 50 #define SENSOR_ERROR_INVALID_PARAM (-3) 51 #define SENSOR_OK 0 52 #ifndef SENSOR_NAME_MAX_LEN 53 /** Maximum length of the sensor name */ 54 #define SENSOR_NAME_MAX_LEN 16 55 #endif /* SENSOR_NAME_MAX_LEN */ 56 57 #ifndef SENSOR_USER_DATA_SIZE 58 /** Size of sensor data */ 59 #define SENSOR_USER_DATA_SIZE 104 60 #endif /* SENSOR_USER_DATA_SIZE */ 61 62 #ifndef VERSION_MAX_LEN 63 /** Maximum length of the sensor version */ 64 #define VERSION_MAX_LEN 16 65 #endif /* SENSOR_USER_DATA_SIZE */ 66 67 /** 68 * @brief Enumerates sensor types. 69 * 70 * @since 5 71 */ 72 typedef enum SensorTypeId { 73 SENSOR_TYPE_ID_NONE = 0, /**< None */ 74 SENSOR_TYPE_ID_ACCELEROMETER = 1, /**< Acceleration sensor */ 75 SENSOR_TYPE_ID_GYROSCOPE = 2, /**< Gyroscope sensor */ 76 SENSOR_TYPE_ID_PHOTOPLETHYSMOGRAPH = 3, /**< Photoplethysmography sensor */ 77 SENSOR_TYPE_ID_ELECTROCARDIOGRAPH = 4, /**< Electrocardiogram (ECG) sensor */ 78 SENSOR_TYPE_ID_AMBIENT_LIGHT = 5, /**< Ambient light sensor */ 79 SENSOR_TYPE_ID_MAGNETIC_FIELD = 6, /**< Magnetic field sensor */ 80 SENSOR_TYPE_ID_CAPACITIVE = 7, /**< Capacitive sensor */ 81 SENSOR_TYPE_ID_BAROMETER = 8, /**< Barometric pressure sensor */ 82 SENSOR_TYPE_ID_TEMPERATURE = 9, /**< Temperature sensor */ 83 SENSOR_TYPE_ID_HALL = 10, /**< Hall effect sensor */ 84 SENSOR_TYPE_ID_GESTURE = 11, /**< Gesture sensor */ 85 SENSOR_TYPE_ID_PROXIMITY = 12, /**< Proximity sensor */ 86 SENSOR_TYPE_ID_HUMIDITY = 13, /**< Humidity sensor */ 87 SENSOR_TYPE_ID_PHYSICAL_MAX = 0xFF, /**< Maximum type ID of a physical sensor */ 88 SENSOR_TYPE_ID_ORIENTATION = 256, /**< Orientation sensor */ 89 SENSOR_TYPE_ID_GRAVITY = 257, /**< Gravity sensor */ 90 SENSOR_TYPE_ID_LINEAR_ACCELERATION = 258, /**< Linear acceleration sensor */ 91 SENSOR_TYPE_ID_ROTATION_VECTOR = 259, /**< Rotation vector sensor */ 92 SENSOR_TYPE_ID_AMBIENT_TEMPERATURE = 260, /**< Ambient temperature sensor */ 93 SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED = 261, /**< Uncalibrated magnetic field sensor */ 94 SENSOR_TYPE_ID_GAME_ROTATION_VECTOR = 262, /**< Game rotation vector sensor */ 95 SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED = 263, /**< Uncalibrated gyroscope sensor */ 96 SENSOR_TYPE_ID_SIGNIFICANT_MOTION = 264, /**< Significant motion sensor */ 97 SENSOR_TYPE_ID_PEDOMETER_DETECTION = 265, /**< Pedometer detection sensor */ 98 SENSOR_TYPE_ID_PEDOMETER = 266, /**< Pedometer 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_MAX = 30, /**< Maximum number of sensor type IDs*/ 105 } SensorTypeId; 106 107 /** 108 * @brief Defines sensor information. 109 * 110 * @since 5 111 */ 112 typedef struct SensorInfo { 113 char sensorName[SENSOR_NAME_MAX_LEN]; /**< Sensor name */ 114 char vendorName[SENSOR_NAME_MAX_LEN]; /**< Sensor vendor */ 115 char firmwareVersion[VERSION_MAX_LEN]; /**< Sensor firmware version */ 116 char hardwareVersion[VERSION_MAX_LEN]; /**< Sensor hardware version */ 117 int32_t sensorTypeId; /**< Sensor type ID */ 118 int32_t sensorId; /**< Sensor ID */ 119 float maxRange; /**< Maximum measurement range of the sensor */ 120 float precision; /**< Sensor accuracy */ 121 float power; /**< Sensor power */ 122 } SensorInfo; 123 124 /** 125 * @brief Defines the data reported by the sensor. 126 * 127 * @since 5 128 */ 129 typedef struct SensorEvent { 130 int32_t sensorTypeId; /**< Sensor type ID */ 131 int32_t version; /**< Sensor algorithm version */ 132 int64_t timestamp; /**< Time when sensor data was reported */ 133 uint32_t option; /**< Sensor data options, including the measurement range and accuracy */ 134 int32_t mode; /**< Sensor data reporting mode (described in {@link SensorMode}) */ 135 uint8_t *data; /**< Sensor data */ 136 uint32_t dataLen; /**< Sensor data length */ 137 } SensorEvent; 138 139 /** 140 * @brief Defines the callback for data reporting by the sensor agent. 141 * 142 * @since 5 143 */ 144 typedef void (*RecordSensorCallback)(SensorEvent *event); 145 146 /** 147 * @brief Defines a reserved field for the sensor data subscriber. 148 * 149 * @since 5 150 */ 151 typedef struct UserData { 152 char userData[SENSOR_USER_DATA_SIZE]; /**< Reserved for the sensor data subscriber */ 153 } UserData; 154 155 /** 156 * @brief Defines information about the sensor data subscriber. 157 * 158 * @since 5 159 */ 160 typedef struct SensorUser { 161 char name[SENSOR_NAME_MAX_LEN]; /**< Name of the sensor data subscriber */ 162 RecordSensorCallback callback; /**< Callback for reporting sensor data */ 163 UserData *userData; /**< Reserved field for the sensor data subscriber */ 164 } SensorUser; 165 166 /** 167 * @brief Enumerates data reporting modes of sensors. 168 * 169 * @since 5 170 */ 171 typedef enum SensorMode { 172 SENSOR_DEFAULT_MODE = 0, /**< Default data reporting mode */ 173 SENSOR_REALTIME_MODE = 1, /**< Real-time data reporting mode to report a group of data each time */ 174 SENSOR_ON_CHANGE = 2, /**< Real-time data reporting mode to report data upon status changes */ 175 SENSOR_ONE_SHOT = 3, /**< Real-time data reporting mode to report data only once */ 176 SENSOR_FIFO_MODE = 4, /**< FIFO-based data reporting mode to report data based on the <b>BatchCnt</b> setting */ 177 SENSOR_MAX_MODE, /**< Maximum sensor data reporting mode */ 178 } SensorMode; 179 180 #ifdef __cplusplus 181 #if __cplusplus 182 } 183 #endif 184 #endif 185 #endif /* SENSOR_AGENT_TYPE_H */ 186 /** @} */