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_PROXIMITY1 = 18, /**< Secondary proximity sensor */ 93 SENSOR_TYPE_MEDICAL_BEGIN = 128, /**< The begin of medical sensorId enumeration value range */ 94 SENSOR_TYPE_MEDICAL_END = 160, /**< The end of medical sensorId enumeration value range */ 95 SENSOR_TYPE_PHYSICAL_MAX = 255, /**< Maximum type of a physical sensor */ 96 SENSOR_TYPE_ORIENTATION = 256, /**< Orientation sensor */ 97 SENSOR_TYPE_GRAVITY = 257, /**< Gravity sensor */ 98 SENSOR_TYPE_LINEAR_ACCELERATION = 258, /**< Linear acceleration sensor */ 99 SENSOR_TYPE_ROTATION_VECTOR = 259, /**< Rotation vector sensor */ 100 SENSOR_TYPE_AMBIENT_TEMPERATURE = 260, /**< Ambient temperature sensor */ 101 SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED = 261, /**< Uncalibrated magnetic field sensor */ 102 SENSOR_TYPE_GAME_ROTATION_VECTOR = 262, /**< Game rotation vector sensor */ 103 SENSOR_TYPE_GYROSCOPE_UNCALIBRATED = 263, /**< Uncalibrated gyroscope sensor */ 104 SENSOR_TYPE_SIGNIFICANT_MOTION = 264, /**< Significant motion sensor */ 105 SENSOR_TYPE_PEDOMETER_DETECTION = 265, /**< Pedometer detection sensor */ 106 SENSOR_TYPE_PEDOMETER = 266, /**< Pedometer sensor */ 107 SENSOR_TYPE_POSTURE = 267, /**< Posture sensor */ 108 SENSOR_TYPE_HEADPOSTURE = 268, /**< Headposture sensor */ 109 SENSOR_TYPE_DROP_DETECT = 269, /**< Drop detection sensor */ 110 SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR = 277, /**< Geomagnetic rotation vector sensor */ 111 SENSOR_TYPE_HEART_RATE = 278, /**< Heart rate sensor */ 112 SENSOR_TYPE_DEVICE_ORIENTATION = 279, /**< Device orientation sensor */ 113 SENSOR_TYPE_WEAR_DETECTION = 280, /**< Wear detection sensor */ 114 SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED = 281, /**< Uncalibrated acceleration sensor */ 115 SENSOR_TYPE_RPC = 282, /**< Radio Power Control */ 116 SENSOR_TYPE_FUSION_PRESSURE = 283, /**< Fusion pressure sensor*/ 117 SENSOR_TYPE_MAX, /**< Maximum number of sensor types */ 118 }; 119 120 /** 121 * @brief Enumerates accuracy types of sensors. 122 * 123 * @since 2.2 124 */ 125 enum SensorAccuracyType { 126 SENSOR_NO_ACCURACY = 0, /**< No accuracy */ 127 SENSOR_LOW_ACCURACY = 1, /**< Low accuracy */ 128 SENSOR_MEDIUM_ACCURACY = 2, /**< Medium accuracy */ 129 SENSOR_HIGH_ACCURACY = 3, /**< High accuracy */ 130 SENSOR_MAX_ACCURACY, /**< Maximum accuracy */ 131 }; 132 133 /** 134 * @brief Enumerates measurement ranges of sensors. 135 * 136 * @since 2.2 137 */ 138 enum SensorRangeType { 139 SENSOR_RANGE_LEVEL1 = 0, /**< Measurement range level 1 */ 140 SENSOR_RANGE_LEVEL2 = 1, /**< Measurement range level 2 */ 141 SENSOR_RANGE_LEVEL3 = 2, /**< Measurement range level 3 */ 142 SENSOR_RANGE_LEVEL_MAX, /**< Maximum measurement range level */ 143 }; 144 145 /** 146 * @brief Enumerates data reporting modes of sensors. 147 * 148 * @since 2.2 149 */ 150 enum SensorModeType { 151 SENSOR_MODE_DEFAULT = 0, /**< Default data reporting mode */ 152 SENSOR_MODE_REALTIME = 1, /**< Real-time data reporting mode to report a group of data each time */ 153 SENSOR_MODE_ON_CHANGE = 2, /**< Real-time data reporting mode to report data upon status changes */ 154 SENSOR_MODE_ONE_SHOT = 3, /**< Real-time data reporting mode to report data only once */ 155 SENSOR_MODE_FIFO_MODE = 4, /**< FIFO-based data reporting mode to report data based on the configured cache size */ 156 SENSOR_MODE_MAX, /**< Maximum sensor data reporting mode */ 157 }; 158 159 /** 160 * @brief Enumerates hardware service group for sensors 161 * 162 * @since 2.2 163 */ 164 enum SensorGroupType { 165 TRADITIONAL_SENSOR_TYPE = 0, /**< traditional sensor type, the sensorId enumeration value range is 128-160 */ 166 MEDICAL_SENSOR_TYPE = 1, /**< medical sensor type, the sensorId enumeration value range is not within 128-160 */ 167 SENSOR_GROUP_TYPE_MAX, /**< Maximum sensor type*/ 168 }; 169 170 /** 171 * @brief Defines basic sensor information. 172 * 173 * Information about a sensor includes the sensor name, vendor, firmware version, hardware version, sensor type ID, 174 * sensor ID, maximum measurement range, accuracy, and power. 175 * 176 * @since 2.2 177 */ 178 struct SensorInformation { 179 char sensorName[SENSOR_NAME_MAX_LEN]; /**< Sensor name */ 180 char vendorName[SENSOR_NAME_MAX_LEN]; /**< Sensor vendor */ 181 char firmwareVersion[SENSOR_VERSION_MAX_LEN]; /**< Sensor firmware version */ 182 char hardwareVersion[SENSOR_VERSION_MAX_LEN]; /**< Sensor hardware version */ 183 int32_t sensorTypeId; /**< Sensor type ID (described in {@link SensorTypeTag}) */ 184 int32_t sensorId; /**< Sensor ID, defined by the sensor driver developer */ 185 float maxRange; /**< Maximum measurement range of the sensor */ 186 float accuracy; /**< Sensor accuracy */ 187 float power; /**< Sensor power */ 188 int64_t minDelay; /**< Minimum sample period allowed in microseconds */ 189 int64_t maxDelay; /**< Maxmum sample period allowed in microseconds */ 190 uint32_t fifoMaxEventCount; /**< Maxmum number of events of this sensor that could be batched */ 191 uint32_t reserved; /**< Reserved fields */ 192 }; 193 194 /** 195 * @brief Defines the data reported by the sensor. 196 * 197 * The reported sensor data includes the sensor ID, sensor algorithm version, data generation time, 198 * data options (such as the measurement range and accuracy), data reporting mode, data address, and data length. 199 * 200 * @since 2.2 201 */ 202 struct SensorEvents { 203 int32_t sensorId; /**< Sensor ID */ 204 int32_t version; /**< Sensor algorithm version */ 205 int64_t timestamp; /**< Time when sensor data was generated */ 206 uint32_t option; /**< Sensor data options, including the measurement range and accuracy */ 207 int32_t mode; /**< Sensor data reporting mode */ 208 uint8_t *data; /**< Sensor data address */ 209 uint32_t dataLen; /**< Sensor data length */ 210 }; 211 212 /** 213 * @brief Defines SDC reports data object operations to the node. 214 * 215 * The reported sensor data includes the offset, type, ddrSize, minRateLevel, maxRateLevel, reserved, memAddr. 216 * 217 * @since 4.1 218 */ 219 struct SdcSensorInfo { 220 uint64_t offset; 221 int32_t sensorId; 222 int32_t ddrSize; 223 int32_t minRateLevel; 224 int32_t maxRateLevel; 225 uint64_t memAddr; 226 int32_t reserved; 227 }; 228 229 /** 230 * @brief Defines the callback for reporting sensor data. This callback needs to be registered when 231 * a sensor user subscribes to sensor data. Only after the sensor is enabled, the sensor data subscriber can receive 232 * sensor data. For details, see {@link SensorInterface}. 233 * 234 * @since 2.2 235 */ 236 typedef int32_t (*RecordDataCallback)(const struct SensorEvents*); 237 238 #ifdef __cplusplus 239 #if __cplusplus 240 } 241 #endif 242 #endif /* __cplusplus */ 243 244 #endif /* SENSOR_TYPE_H */ 245 /** @} */ 246