Skip to content

Commit 6fcf750

Browse files
committed
Unify the advertising interval unit
1. Update the interval unit as millisecon. 2. Update the comments and API Fix build error
1 parent ab7f5cb commit 6fcf750

File tree

7 files changed

+122
-48
lines changed

7 files changed

+122
-48
lines changed

libraries/CurieBLE/src/BLECentral.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "BLECentralRole.h"
2121

2222
#include "BLECentral.h"
23+
#include "internal/ble_client.h"
2324

2425
bool BLECentral::startScan()
2526
{
@@ -42,9 +43,10 @@ bool BLECentral::connect(const bt_addr_le_t *addr, const ble_conn_param_t *param
4243
struct bt_le_conn_param conn_param;
4344

4445
conn_param.latency = param->latency;
45-
conn_param.interval_max = (uint16_t)(param->interval_max / 1.25);
46-
conn_param.interval_min = (uint16_t)(param->interval_min / 1.25);
47-
conn_param.timeout = param->timeout / 10;
46+
conn_param.interval_max = (uint16_t)MSEC_TO_UNITS(param->interval_max, UNIT_1_25_MS);
47+
conn_param.interval_min = (uint16_t)MSEC_TO_UNITS(param->interval_min, UNIT_1_25_MS);
48+
conn_param.timeout = MSEC_TO_UNITS(param->timeout, UNIT_10_MS);
49+
4850
pr_debug(LOG_MODULE_BLE,"Latency-%d\r\nInterval min-%d, max-%d\r\ntimeout:%d",
4951
conn_param.latency,
5052
conn_param.interval_min,

libraries/CurieBLE/src/BLECommon.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ typedef bool (*ble_advertise_handle_cb_t)(uint8_t type, const uint8_t *data,
8181

8282

8383
typedef struct ble_conn_param {
84-
float interval_min; // 7.5 - 4000ms
85-
float interval_max; // 7.5 - 4000ms
84+
float interval_min; // millisecond 7.5 - 4000ms
85+
float interval_max; // millisecond 7.5 - 4000ms
8686
uint16_t latency; // 0x0000 - 0x01F4
87-
uint16_t timeout; // 100 - 32000ms
87+
uint16_t timeout; // millisecond 100 - 32000ms
8888
}ble_conn_param_t;
8989

9090
#endif // _BLE_COMMON_H_INCLUDED

libraries/CurieBLE/src/BLEPeripheral.cpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ BLEPeripheral::BLEPeripheral(void) :
3030
memset(_adv_data, 0x00, sizeof(_adv_data));
3131

3232
// Default Advertising parameter
33-
setAdvertisingParam(BT_LE_ADV_IND ,
34-
0xA0,
35-
0xF0);
33+
setConnectable(true);
3634
}
3735

3836
BLEPeripheral::~BLEPeripheral(void)
@@ -91,13 +89,30 @@ BLEPeripheral::setAdvertisedServiceData(const struct bt_uuid* serviceDataUuid,
9189
_service_data_length = serviceDataLength;
9290
}
9391

94-
void BLEPeripheral::setAdvertisingParam(uint8_t type,
95-
uint16_t interval_min,
96-
uint16_t interval_max)
92+
void
93+
BLEPeripheral::setAdvertisingInterval(float interval_min,
94+
float interval_max)
9795
{
98-
BLEPeripheralRole::instance()->setAdvertisingParam(type,
99-
interval_min,
100-
interval_max);
96+
uint16_t max = (uint16_t) MSEC_TO_UNITS(interval_max, UNIT_0_625_MS);
97+
uint16_t min = (uint16_t) MSEC_TO_UNITS(interval_min, UNIT_0_625_MS);
98+
BLEPeripheralRole::instance()->setAdvertisingInterval(min, max);
99+
}
100+
101+
void
102+
BLEPeripheral::setAdvertisingInterval(float advertisingInterval)
103+
{
104+
setAdvertisingInterval(advertisingInterval, advertisingInterval);
105+
}
106+
107+
void
108+
BLEPeripheral::setConnectable(bool connectable)
109+
{
110+
uint8_t type = BT_LE_ADV_IND;
111+
if (connectable == false)
112+
{
113+
type = BT_LE_ADV_NONCONN_IND;
114+
}
115+
BLEPeripheralRole::instance()->setAdvertisingType(type);
101116
}
102117

103118
void

libraries/CurieBLE/src/BLEPeripheral.h

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,26 +88,50 @@ class BLEPeripheral{
8888
void setAdvertisedServiceData(const struct bt_uuid* serviceDataUuid,
8989
uint8_t* serviceData,
9090
uint8_t serviceDataLength);
91+
9192
/**
92-
* Set the ADV parameters about the ADV-Type and interval
93+
* @brief Set advertising interval
9394
*
94-
* @param type Advertising types
95+
* @param[in] advertisingInterval Advertising Interval (N * 0.625)
9596
*
96-
* @param interval_min Minimum Advertising Interval (N * 0.625)
97+
* @return none
9798
*
98-
* @param interval_max Maximum Advertising Interval (N * 0.625)
99+
* @note none
100+
*/
101+
void setAdvertisingInterval(float advertisingInterval);
102+
103+
/**
104+
* @brief Set advertising interval
99105
*
100-
* @note none
106+
* @param[in] interval_min Minimum Advertising Interval (millisecond)
107+
*
108+
* @param[in] interval_max Maximum Advertising Interval (millisecond)
109+
*
110+
* @return none
111+
*
112+
* @note none
101113
*/
102-
void setAdvertisingParam(uint8_t type,
103-
uint16_t interval_min,
104-
uint16_t interval_max);
114+
void setAdvertisingInterval(float interval_min,
115+
float interval_max);
116+
117+
/**
118+
* @brief Set advertising type as connectable/non-connectable
119+
*
120+
* @param[in] connectable true - The device connectable
121+
* false - The device non-connectable
122+
*
123+
* @return none
124+
*
125+
* @note none
126+
*/
127+
void setConnectable(bool connectable);
128+
105129
/**
106130
* Set the device name for the BLE Peripheral Device
107131
*
108132
* If device name is not set, a default name will be used instead
109133
*
110-
* @param device User-defined name string for this device. Truncated if
134+
* @param[in] device User-defined name string for this device. Truncated if
111135
* more than maximum allowed string length (20 bytes).
112136
*
113137
* @note This method must be called before the begin method

libraries/CurieBLE/src/BLEPeripheralRole.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ BLEPeripheralRole::BLEPeripheralRole(void) :
4343
{
4444
memset(_event_handlers, 0x00, sizeof(_event_handlers));
4545
_peripheral.setAddress(_local_bda);
46+
47+
_adv_param.type = BT_LE_ADV_IND;
48+
_adv_param.addr_type = _local_bda.type;
49+
_adv_param.interval_min = 0xA0;
50+
_adv_param.interval_max = 0xF0;
4651
}
4752

4853
BLEPeripheralRole::~BLEPeripheralRole(void)
@@ -207,16 +212,24 @@ BLEPeripheralRole::startAdvertising(const struct bt_data *ad,
207212
return BLE_STATUS_SUCCESS;
208213
}
209214

210-
void BLEPeripheralRole::setAdvertisingParam(uint8_t type,
211-
uint16_t interval_min,
212-
uint16_t interval_max)
215+
void BLEPeripheralRole::setAdvertisingInterval(uint16_t advertisingInterval)
216+
{
217+
setAdvertisingInterval(advertisingInterval, advertisingInterval);
218+
}
219+
220+
void BLEPeripheralRole::setAdvertisingInterval(uint16_t interval_min,
221+
uint16_t interval_max)
213222
{
214-
_adv_param.addr_type = _local_bda.type;
215-
_adv_param.type = type;
216223
_adv_param.interval_min = interval_min;
217224
_adv_param.interval_max = interval_max;
218225
}
219226

227+
void
228+
BLEPeripheralRole::setAdvertisingType(uint8_t type)
229+
{
230+
_adv_param.type = type;
231+
}
232+
220233
BleStatus
221234
BLEPeripheralRole::stop(void)
222235
{

libraries/CurieBLE/src/BLEPeripheralRole.h

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class BLEPeripheralRole: public BLERoleBase{
5757
* Set the min and max connection interval BLE Peripheral Device
5858
*
5959
* @param minConnInterval Minimum connection interval (1.25 ms units), minimum 0x0006 (7.5ms)
60-
* @param maxConnInterval Maximum connection interval (1.25 ms units), maximum 0x095f (2998.75ms)
60+
* @param maxConnInterval Maximum connection interval (1.25 ms units), maximum 0x0C80 (4000ms)
6161
*
6262
* @note This method must be called before the begin method
6363
*/
@@ -139,34 +139,54 @@ class BLEPeripheralRole: public BLERoleBase{
139139
size_t ad_len,
140140
const struct bt_data *sd,
141141
size_t sd_len);
142-
143-
/**
144-
* @brief Stop send advertisement
145-
*
146-
* @param none
147-
*
148-
* @return none
149-
*
150-
* @note none
151-
*/
142+
143+
/**
144+
* @brief Stop send advertisement
145+
*
146+
* @param none
147+
*
148+
* @return none
149+
*
150+
* @note none
151+
*/
152152
BleStatus stopAdvertising();
153-
153+
154+
/**
155+
* @brief Set advertising parameter
156+
*
157+
* @param[in] advertisingInterval Advertising Interval (N * 0.625)
158+
*
159+
* @return none
160+
*
161+
* @note none
162+
*/
163+
void setAdvertisingInterval(uint16_t advertisingInterval);
164+
154165
/**
155166
* @brief Set advertising parameter
156167
*
157-
* @param type Advertising type
168+
* @param[in] interval_min Minimum Advertising Interval (N * 0.625)
169+
*
170+
* @param[in] interval_max Maximum Advertising Interval (N * 0.625)
158171
*
159-
* @param interval_min Minimum Advertising Interval (N * 0.625)
172+
* @return none
173+
*
174+
* @note none
175+
*/
176+
void setAdvertisingInterval(uint16_t interval_min,
177+
uint16_t interval_max);
178+
179+
/**
180+
* @brief Set advertising type
160181
*
161-
* @param interval_max Maximum Advertising Interval (N * 0.625)
182+
* @param type Advertising type
183+
* BT_LE_ADV_IND, BT_LE_ADV_NONCONN_IND
162184
*
163185
* @return none
164186
*
165187
* @note none
166188
*/
167-
void setAdvertisingParam(uint8_t type,
168-
uint16_t interval_min,
169-
uint16_t interval_max);
189+
void setAdvertisingType(uint8_t type);
170190

171191
/**
172192
* @brief Get BLE Peripheral instance.

libraries/CurieBLE/src/internal/ble_client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ enum {
4545
#define DEFAULT_MIN_CONN_INTERVAL MSEC_TO_UNITS(80, UNIT_1_25_MS)
4646
#define DEFAULT_MAX_CONN_INTERVAL MSEC_TO_UNITS(150, UNIT_1_25_MS)
4747
#define MIN_CONN_INTERVAL 0x0006
48-
#define MAX_CONN_INTERVAL 0x095f
48+
#define MAX_CONN_INTERVAL 0x0C80
4949
#define SLAVE_LATENCY 0
5050
#define CONN_SUP_TIMEOUT MSEC_TO_UNITS(6000, UNIT_10_MS)
5151

0 commit comments

Comments
 (0)