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 
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 };
42 
43 struct ExtraInfo {
44     int32_t sensorId;
45     int32_t type;    // type of payload data, see ExtraInfo
46     int32_t serial;  // sequence number of this frame for this type
47     union {
48         // for each frame, a single data type, either int32_t or float, should be used.
49         int32_t data_int32[EXTRA_INFO_DATA_LEN];
50         float data_float[EXTRA_INFO_DATA_LEN];
51     };
52 };
53 
54 struct ExtraSensorInfo {
55     ExtraInfo additional_info;
56 };
57 } // namespace Sensors
58 } // namespace OHOS
59 #endif // SENSOR_DATA_EVENT_H
60