• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 SoftBus
18  * @{
19  *
20  * @brief Provides data level of distributed database transport by DSoftBus ble heratbeat.
21  *
22  * This module implements unified distributed communication management of nearby devices and provides link-independent
23  * device discovery and transmission interfaces to support service publishing and data transmission.
24  * @since 1.0
25  * @version 1.0
26  */
27 /** @} */
28 
29 #ifndef BLE_RANGE_H
30 #define BLE_RANGE_H
31 
32 #include <stdint.h>
33 #include "softbus_common.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 /**
40  * @brief Defines a ble range infomation, see {@link BleRangeInfo}.
41  *
42  * @since 1.0
43  * @version 1.0
44  */
45 typedef struct {
46     int32_t range;                      /**< The range between two devices */
47     int32_t subRange;                   /**< The subRange between two devices */
48     float distance;                     /**< The distance between two devices */
49     double confidence;                  /**< The confidence of range result */
50     char networkId[NETWORK_ID_BUF_LEN]; /**< The networkId value */
51 } BleRangeInfo;
52 
53 typedef struct {
54     /**
55      * @brief Called when the devices receive ble range result.
56      *
57      * @param info Indicates the ble range result.
58      *
59      * @since 1.0
60      * @version 1.0
61      */
62     void (*onBleRangeInfoReceived)(const BleRangeInfo *info);
63 } IBleRangeCb;
64 
65 /**
66  * @brief Registers a callback for ble range result.
67  *
68  * @param pkgName Indicates the package name of the caller.
69  * @param callback Indicates the function callback to be registered. For details, see {@link IBleRangeCb}.
70  * @return Returns <b>0</b> if the registeration is successful; returns any other value otherwise.
71  *
72  * @since 1.0
73  * @version 1.0
74  */
75 int32_t RegBleRangeCb(const char *pkgName, IBleRangeCb *callback);
76 
77 /**
78  * @brief Unregisters a callback for ble range result.
79  *
80  * @param pkgName Indicates the package name of the caller.
81  * @return Returns <b>0</b> if the registeration is successful; returns any other value otherwise.
82  *
83  * @since 1.0
84  * @version 1.0
85  */
86 int32_t UnregBleRangeCb(const char *pkgName);
87 
88 /**
89  * @brief Defines heartbeat mode parameter, see{@link HbMode}.
90  *
91  * @since 1.0
92  * @version 1.0
93  */
94 typedef struct {
95     int32_t duration; /** Heartbeat for range duration, unit is seconds */
96     bool connFlag;    /** Heartbeat could connect or not */
97     bool replyFlag;   /** Heartbeat need reply or not, set this parameter to true if need reply */
98 } HbMode;
99 
100 /**
101  * @brief Modify heartbeat parameters and trigger a temporary heartbeat.
102  *
103  * @param pkgName Indicates the pointer to the caller ID, for example, the package name.
104  * @param callerId The id of the caller, whitch cannot be <b>NULL</b>, and maxium length is {@link CALLER_ID_MAX_LEN}.
105  *
106  * @return Returns <b>0</b> if the call is success; returns any other value if it fails.
107  *
108  * @since 1.0
109  * @version 1.0
110  */
111 int32_t TriggerHbForMeasureDistance(const char *pkgName, const char *callerId, const HbMode *mode);
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 #endif