• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 SOFTBUS_ADAPTER_RANGE_H
17 #define SOFTBUS_ADAPTER_RANGE_H
18 
19 #include <stdint.h>
20 
21 #include "softbus_utils.h"
22 
23 #ifdef __cplusplus
24 #if __cplusplus
25 extern "C" {
26 #endif
27 #endif
28 
29 #define SOFTBUS_DEV_IDENTITY_LEN 96
30 // valid value of power is [-128, 10], 11 is considered to be illegal.
31 #define SOFTBUS_ILLEGAL_BLE_POWER 11
32 #define SOFTBUS_MODEL_ID_LEN (HEXIFY_LEN(3))
33 #define SOFTBUS_SUB_MODEL_ID_LEN (HEXIFY_LEN(1))
34 #define SOFTBUS_NEW_MODEL_ID_LEN (HEXIFY_LEN(4))
35 #define SOFTBUS_MODEL_NAME_LEN (HEXIFY_LEN(8))
36 
37 typedef enum {
38     MODULE_BLE_DISCOVERY = 1,
39     MODULE_BLE_HEARTBEAT,
40     MODULE_BLE_APPROACH,
41     MODULE_SLE_CONNECTION,
42     MODULE_UWB,
43 } SoftBusRangeModule;
44 
45 typedef enum {
46     RANGE_SERVICE_DEFAULT = 0,
47     RANGE_SERVICE_TOUCH,
48     RANGE_SERVICE_VLINK,
49     RANGE_SERVICE_BUTT,
50 } SoftBusRangeBusinessType;
51 
52 typedef struct {
53     int8_t power;
54     bool isCycle;
55     bool isSupportNearLink;
56     char identity[SOFTBUS_DEV_IDENTITY_LEN];
57     char modelId[SOFTBUS_MODEL_ID_LEN];
58     char subModelId[SOFTBUS_SUB_MODEL_ID_LEN];
59     char newModelId[SOFTBUS_NEW_MODEL_ID_LEN];
60     char modelName[SOFTBUS_MODEL_NAME_LEN];
61     int32_t rssi;
62     SoftBusRangeBusinessType serviceType;
63 } SoftBusRangeParam;
64 
65 typedef struct {
66     SoftBusRangeModule module;
67 } SoftBusRangeHandle;
68 
69 typedef struct {
70     int32_t rank;
71     int32_t subrank;
72     float distance;
73     double confidence;
74     char identity[SOFTBUS_DEV_IDENTITY_LEN];
75 } SoftBusRankResult;
76 
77 typedef struct {
78     void (*onRangeDone)(SoftBusRangeHandle handle, const SoftBusRankResult *result);
79 } SoftBusRangeCallback;
80 
81 int SoftBusBleRange(SoftBusRangeParam *param, int32_t *range);
82 int SoftBusGetBlePower(int8_t *power);
83 int32_t SoftBusGetAdvPower(int8_t *power);
84 
85 int32_t SoftBusBleRangeAsync(const SoftBusRangeParam *param);
86 int32_t SoftBusRegRangeCb(SoftBusRangeModule module, const SoftBusRangeCallback *callback);
87 void SoftBusUnregRangeCb(SoftBusRangeModule module);
88 
89 #ifdef __cplusplus
90 #if __cplusplus
91 }
92 #endif /* __cplusplus */
93 #endif /* __cplusplus */
94 
95 #endif /* SOFTBUS_ADAPTER_RANGE_H */
96