1 /*
2  * Copyright (c) 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 #ifndef LNN_DECISION_CENTER_H
17 #define LNN_DECISION_CENTER_H
18 
19 #include <stdint.h>
20 #include <stdbool.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 typedef enum {
27     STATE_TYPE_BLE_SWITCH_ON = 0,
28     STATE_TYPE_BLE_SWITCH_OFF,
29     STATE_TYPE_BLE_DISCOVERY,
30     STATE_TYPE_AR_MOVE_RIDING,
31     STATE_TYPE_AR_MOVE_RUN_FAST,
32     STATE_TYPE_AR_CLIMBING_MOUNT,
33     STATE_TYPE_AR_MOVE_RUN_FOR_HEALTH,
34     STATE_TYPE_AR_MOVE_WALK_FOR_HEALTH,
35     STATE_TYPE_AR_MOVE_VEHICLE,
36     STATE_TYPE_AR_MOVE_VE_TRAIN,
37     STATE_TYPE_AR_MOVE_VE_UNKNOWN,
38     STATE_TYPE_AR_MOVE_STATIONARY,
39     STATE_TYPE_AR_VE_BUS,
40     STATE_TYPE_AR_VE_CAR,
41     STATE_TYPE_AR_VE_METRO,
42     STATE_TYPE_AR_VE_HIGH_SPEED_RAIL,
43     STATE_TYPE_AR_VE_AUTO,
44     STATE_TYPE_AR_VE_RAIL,
45     STATE_TYPE_AR_MOVE_ON_FOOT,
46     STATE_TYPE_AR_MOVE_ELEVATOR,
47     STATE_TYPE_AR_MOVE_DRIVER,
48     STATE_TYPE_AR_FAST_WALK,
49     STATE_TYPE_AR_STOP_VEHICLE,
50     STATE_TYPE_AR_MOVE_WALK_SLOW,
51     STATE_TYPE_AR_MOVE_TILT,
52     STATE_TYPE_AR_MOVE_END,
53     STATE_TYPE_AR_MOVE_IN_OUT_DOOR,
54     STATE_TYPE_MOTION_SHAKE,
55     STATE_TYPE_MOTION_TAP,
56     STATE_TYPE_MOTION_TILT_LR,
57     STATE_TYPE_MOTION_ROTATION,
58     STATE_TYPE_MOTION_TAKE_OFF,
59     STATE_TYPE_MOTION_HEAD_DOWN,
60     STATE_TYPE_MOTION_PUT_DOWN,
61     STATE_TYPE_MOTION_SIDE_GRIP,
62     STATE_TYPE_MOTION_MOVE,
63     STATE_TYPE_MAX_NUM,
64 } StatePacks;
65 
66 typedef enum {
67     DC_VERSION_1_0 = 0,
68     DC_VERSION_MAX_NUM,
69 } DecisionCenterVersion;
70 
71 typedef enum {
72     DC_TARGET_ENERGY = 0x0001,
73     DC_TARGET_EFFICIENCY = 0x0010,
74     DC_TARGET_LATENCY = 0x0100,
75     DC_TARGET_ROBUSTNESS = 0x1000
76 } DcTargetType;
77 
78 typedef enum {
79     TASK_BLE_HEARTBEAT = 0,
80     TASK_BLE_LOW_LATENCY = 1,
81     TASK_NUM,
82 } SupportTaskType;
83 
84 typedef enum {
85     TASK_CONVEX_SYSTEM = 0,
86     TASK_RULE_SYSTEM = 1,
87     TASK_ML_SYSTEM = 2,
88     TASK_LOGIC_SYSTEM = 3,
89     TASK_SYSTEM_NUM,
90 } DcSupportTaskSystem;
91 
92 typedef struct {
93     int32_t serviceUuid;
94     uint8_t taskId;
95     uint8_t taskType;
96     uint8_t target;
97     uint8_t preferredSystem;
98     uint8_t limitType;
99     int32_t limitValue; // Unit: Milliseconds/Times/None
100     int32_t (*optimizeStrategy)(void *);
101 } DcTask;
102 
103 typedef struct {
104     int64_t timestamp;
105     int32_t stateType;
106     int32_t stateValue;
107 } DcEvent;
108 
109 typedef enum {
110     DC_LIMIT_PERSISTENT = 0,
111     DC_LIMIT_TIMES = 1,
112     DC_LIMIT_DURATION = 2,
113     DC_LIMIT_NUM
114 } DcLimitType;
115 
116 typedef struct {
117     uint32_t type;
118     union {
119         struct DcBleParam {
120             uint16_t advMinInterval;
121             uint16_t advMaxInterval;
122             uint16_t scanInterval;
123             uint16_t scanWindow;
124         } ble;
125     } info;
126     struct HeartbeatImplPolicy *next;
127 } BleHeartbeatConfig;
128 
129 int32_t LnnInitDecisionCenter(uint32_t version);
130 void LnnDeinitDecisionCenter(void);
131 int32_t LnnDcSubscribe(DcTask *task);
132 int32_t LnnDcUnsubscribe(DcTask *task);
133 void LnnDcDispatchEvent(DcEvent *dcEvnet);
134 
135 #ifdef __cplusplus
136 }
137 #endif
138 #endif
139