• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef SENSOR_DATA_EVENT_H
17 #define SENSOR_DATA_EVENT_H
18 #include <string>
19 namespace OHOS {
20 namespace Sensors {
21 constexpr int32_t RESERVED_DATA_LEN = 3;
22 constexpr int32_t EXTRA_INFO_DATA_LEN = 14;
23 constexpr int32_t DEFAULT_SENSOR_DATA_DIMS = 16;
24 constexpr int32_t SENSOR_MAX_LENGTH = 64;
25 
26 enum {
27     WAKE_UP_SENSOR = 1u,
28     CONTINUOUS_SENSOR = 0u,
29     ON_CHANGE_SENSOR = 2u,
30     ONE_SHOT_SENSOR = 4u,
31 };
32 
33 struct SensorData {
34     int32_t sensorTypeId;  /**< Sensor type ID */
35     int32_t version;       /**< Sensor algorithm version */
36     int64_t timestamp;     /**< Time when sensor data was reported */
37     int32_t option;       /**< Sensor data options, including the measurement range and accuracy */
38     int32_t mode;          /**< Sensor data reporting mode (described in {@link SensorMode}) */
39     uint8_t data[SENSOR_MAX_LENGTH];         /**< Sensor data */
40     uint32_t dataLen;      /**< Sensor data length */
41     int32_t deviceId;      /**< Device ID */
42     int32_t sensorId;      /**< Sensor ID */
43     int32_t location;      /**< Is the device a local device or an external device */
44 };
45 
46 struct ExtraInfo {
47     int32_t sensorId;
48     int32_t type;    // type of payload data, see ExtraInfo
49     int32_t serial;  // sequence number of this frame for this type
50     union {
51         // for each frame, a single data type, either int32_t or float, should be used.
52         int32_t data_int32[EXTRA_INFO_DATA_LEN];
53         float data_float[EXTRA_INFO_DATA_LEN];
54     };
55 };
56 
57 struct ExtraSensorInfo {
58     ExtraInfo additional_info;
59 };
60 
61 struct SensorPlugData {
62     int32_t deviceId = -1;          /**< Device ID */
63     int32_t sensorTypeId = -1;      /**< Sensor type ID */
64     int32_t sensorId = -1;          /**< Sensor ID */
65     int32_t location = -1;          /**< Is the device a local device or an external device */
66     std::string deviceName = "";    /**< Device name */
67     int32_t status = -1;            /**< Device on or out status */
68     int32_t reserved = -1;          /**< Reserved */
69     int64_t timestamp = -1;         /**< Time when sensor plug data was reported */
70 };
71 } // namespace Sensors
72 } // namespace OHOS
73 #endif // SENSOR_DATA_EVENT_H
74