Skip to content

Commit 8ce393d

Browse files
committed
Fix Jira 672 BLE documentation in code needs to specify units
1. Change the scan and connection interval's unit to ms. 2. Delete some unused code.
1 parent b0d0b5b commit 8ce393d

File tree

8 files changed

+89
-38
lines changed

8 files changed

+89
-38
lines changed

libraries/CurieBLE/examples/IMUBleCentral/IMUBleCentral.ino

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626

2727
#define MAX_IMU_RECORD 1
2828

29-
struct bt_le_conn_param conn_param = {0x18, 0x28, 0, 400};
29+
ble_conn_param_t conn_param = {30.0, //ms
30+
50.0, //ms
31+
0,
32+
4000 //ms
33+
};
3034
typedef struct {
3135
int index;
3236
unsigned int slot[3];
@@ -87,10 +91,10 @@ bool adv_found(uint8_t type,
8791
Serial.println("AD malformed");
8892
return true;
8993
}
90-
struct bt_uuid * serviceuuid = bleImuService.uuid();
94+
bt_uuid_t* serviceuuid = bleImuService.uuid();
9195
for (i = 0; i < data_len; i += MAX_UUID_SIZE)
9296
{
93-
if (memcmp (((struct bt_uuid_128*)serviceuuid)->val, &data[i], MAX_UUID_SIZE) != 0)
97+
if (memcmp (((bt_uuid_128_t*)serviceuuid)->val, &data[i], MAX_UUID_SIZE) != 0)
9498
{
9599
continue;
96100
}

libraries/CurieBLE/examples/LEDCentral/LEDCentral.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
to show the profile read/write operation in central
2525
*/
2626

27-
struct bt_le_conn_param conn_param = {0x18, 0x28, 0, 400};
27+
ble_conn_param_t conn_param = {30.0, //ms
28+
50.0, //ms
29+
0,
30+
4000 //ms
31+
};
2832

2933
const int ledPin = 13; // set ledPin to use on-board LED
3034
BLECentral bleCentral; // create central instance

libraries/CurieBLE/src/BLECentral.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,32 @@ bool BLECentral::startScan()
2626
return BLECentralRole::instance()->startScan();
2727
}
2828

29-
bool BLECentral::startScan(const struct bt_le_scan_param &scan_param)
29+
bool BLECentral::startScan(float interval, float window)
3030
{
31-
return BLECentralRole::instance()->startScan(scan_param);
31+
setScanParam(interval, window);
32+
return BLECentralRole::instance()->startScan();
3233
}
3334

3435
bool BLECentral::stopScan()
3536
{
3637
return BLECentralRole::instance()->stopScan();
3738
}
3839

39-
bool BLECentral::connect(const bt_addr_le_t *addr, const struct bt_le_conn_param *param)
40+
bool BLECentral::connect(const bt_addr_le_t *addr, const ble_conn_param_t *param)
4041
{
41-
return BLECentralRole::instance()->connect(addr, param);
42+
struct bt_le_conn_param conn_param;
43+
44+
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;
48+
pr_debug(LOG_MODULE_BLE,"Latency-%d\r\nInterval min-%d, max-%d\r\ntimeout:%d",
49+
conn_param.latency,
50+
conn_param.interval_min,
51+
conn_param.interval_max,
52+
conn_param.timeout);
53+
54+
return BLECentralRole::instance()->connect(addr, &conn_param);
4255
}
4356

4457
void BLECentral::discover(BLEPeripheralHelper &peripheral)
@@ -56,8 +69,13 @@ void BLECentral::setAdvertiseHandler(ble_advertise_handle_cb_t advcb)
5669
BLECentralRole::instance()->setAdvertiseHandler(advcb);
5770
}
5871

59-
void BLECentral::setScanParam(const struct bt_le_scan_param &scan_param)
72+
void BLECentral::setScanParam(float interval, float window)
6073
{
74+
struct bt_le_scan_param scan_param;
75+
scan_param.type = BT_HCI_LE_SCAN_ACTIVE;
76+
scan_param.filter_dup = BT_HCI_LE_SCAN_FILTER_DUP_ENABLE;
77+
scan_param.interval = (uint16_t)((interval * 8) / 5);
78+
scan_param.window = (uint16_t)((window * 8) / 5);
6179
BLECentralRole::instance()->setScanParam(scan_param);
6280
}
6381

libraries/CurieBLE/src/BLECentral.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ class BLECentral{
4141
/**
4242
* @brief Start scan with scan parameter
4343
*
44-
* @param none
44+
* @param interval The scan interval in ms
45+
*
46+
* @param window The scan window in ms
4547
*
4648
* @return bool Indicate the success or error
4749
*
4850
* @note none
4951
*/
50-
bool startScan(const struct bt_le_scan_param &scan_param);
52+
bool startScan(float interval, float window);
5153

5254
/**
5355
* @brief Stop scan
@@ -71,7 +73,7 @@ class BLECentral{
7173
*
7274
* @note none
7375
*/
74-
bool connect(const bt_addr_le_t *addr, const struct bt_le_conn_param *param);
76+
bool connect(const bt_addr_le_t *addr, const ble_conn_param_t *param);
7577

7678
/**
7779
* @brief Discover the peripheral device profile
@@ -87,13 +89,22 @@ class BLECentral{
8789
/**
8890
* @brief Set the scan parameter
8991
*
90-
* @param scan_param The scan parameter want to be set
92+
* @param interval The scan interval in ms
93+
*
94+
* @param window The scan window in ms
9195
*
9296
* @return none
9397
*
94-
* @note none
98+
* @note 1. The scale of the interval and window are 2.5 - 10240ms
99+
* 2. The scan interval and window are like below.
100+
* The device can see the ADV packet in the window.
101+
* window
102+
* ---- ----
103+
* | | | |
104+
* --- ------- ----
105+
* |interval|
95106
*/
96-
void setScanParam(const struct bt_le_scan_param &scan_param);
107+
void setScanParam(float interval, float window);
97108

98109
/**
99110
* @brief Add an attribute to the BLE Central Device

libraries/CurieBLE/src/BLECentralRole.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ bool BLECentralRole::connect(const bt_addr_le_t *addr, const struct bt_le_conn_p
121121

122122
bool BLECentralRole::startScan()
123123
{
124-
int err = bt_le_scan_start(&_scan_param, ble_central_device_found);
125-
if (err)
124+
int err = bt_le_scan_start(&_scan_param, ble_central_device_found);
125+
if (err)
126126
{
127-
pr_info(LOG_MODULE_BLE, "Scanning failed to start (err %d)\n", err);
128-
return false;
129-
}
127+
pr_info(LOG_MODULE_BLE, "Scanning failed to start (err %d)\n", err);
128+
return false;
129+
}
130130
return true;
131131
}
132132

@@ -153,7 +153,7 @@ bool BLECentralRole::stopScan()
153153
if (err)
154154
{
155155
pr_info(LOG_MODULE_BLE, "Stop LE scan failed (err %d)\n", err);
156-
return false;
156+
return false;
157157
}
158158
return true;
159159
}

libraries/CurieBLE/src/BLECommon.h

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,20 @@
5454

5555
/** BLE response/event status codes. */
5656
enum BLE_STATUS {
57-
BLE_STATUS_SUCCESS = 0, /**< General BLE Success code */
58-
BLE_STATUS_PENDING, /**< Request received and execution started, response pending */
59-
BLE_STATUS_TIMEOUT, /**< Request timed out */
60-
BLE_STATUS_NOT_SUPPORTED, /**< Request/feature/parameter not supported */
61-
BLE_STATUS_NOT_ALLOWED, /**< Request not allowed */
62-
BLE_STATUS_LINK_TIMEOUT, /**< Link timeout (link loss) */
63-
BLE_STATUS_NOT_ENABLED, /**< BLE not enabled, @ref ble_enable */
64-
BLE_STATUS_ERROR, /**< Generic Error */
65-
BLE_STATUS_ALREADY_REGISTERED, /**< BLE service already registered */
66-
BLE_STATUS_WRONG_STATE, /**< Wrong state for request */
67-
BLE_STATUS_ERROR_PARAMETER, /**< Parameter in request is wrong */
68-
BLE_STATUS_NO_MEMORY, /**< System doesn't have memory */
69-
BLE_STATUS_GAP_BASE = 0x100, /**< GAP specific error base */
70-
BLE_STATUS_GATT_BASE = 0x200, /**< GATT specific Error base */
57+
BLE_STATUS_SUCCESS = 0, /**< General BLE Success code */
58+
BLE_STATUS_PENDING, /**< Request received and execution started, response pending */
59+
BLE_STATUS_TIMEOUT, /**< Request timed out */
60+
BLE_STATUS_NOT_SUPPORTED, /**< Request/feature/parameter not supported */
61+
BLE_STATUS_NOT_ALLOWED, /**< Request not allowed */
62+
BLE_STATUS_LINK_TIMEOUT, /**< Link timeout (link loss) */
63+
BLE_STATUS_NOT_ENABLED, /**< BLE not enabled, @ref ble_enable */
64+
BLE_STATUS_ERROR, /**< Generic Error */
65+
BLE_STATUS_ALREADY_REGISTERED, /**< BLE service already registered */
66+
BLE_STATUS_WRONG_STATE, /**< Wrong state for request */
67+
BLE_STATUS_ERROR_PARAMETER, /**< Parameter in request is wrong */
68+
BLE_STATUS_NO_MEMORY, /**< System doesn't have memory */
69+
BLE_STATUS_GAP_BASE = 0x100, /**< GAP specific error base */
70+
BLE_STATUS_GATT_BASE = 0x200, /**< GATT specific Error base */
7171
};
7272

7373
typedef uint16_t ble_status_t; /**< Response and event BLE service status type @ref BLE_STATUS */
@@ -77,6 +77,14 @@ typedef ble_status_t BleStatus;
7777
#define BLE_MAX_CONN_CFG 2
7878

7979
typedef bool (*ble_advertise_handle_cb_t)(uint8_t type, const uint8_t *data,
80-
uint8_t data_len, void *user_data);
80+
uint8_t data_len, void *user_data);
81+
82+
83+
typedef struct ble_conn_param {
84+
float interval_min; // 7.5 - 4000ms
85+
float interval_max; // 7.5 - 4000ms
86+
uint16_t latency; // 0x0000 - 0x01F4
87+
uint16_t timeout; // 100 - 32000ms
88+
}ble_conn_param_t;
8189

8290
#endif // _BLE_COMMON_H_INCLUDED

libraries/CurieBLE/src/BLEHelper.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ class BLEHelper {
6262
bool operator==(const BLEHelper& rhs) const;
6363
bool operator==(const bt_addr_le_t& rhs) const;
6464
bool operator!=(const BLEHelper& rhs) const;
65-
void operator=(const BLEHelper& rhs);
66-
void setConn(struct bt_conn *conn);
6765

6866
const struct bt_le_conn_param *getConnParams();
6967
void setConnParames(uint16_t intervalmin,

libraries/CurieBLE/src/internal/ble_client.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ void ble_client_get_factory_config(bt_addr_le_t *bda, char *name);
108108
void ble_gap_set_tx_power(int8_t tx_power);
109109
BleStatus errorno_to_ble_status(int err);
110110

111+
/// Define the structure for app
112+
typedef struct bt_uuid bt_uuid_t;
113+
typedef struct bt_uuid_16 bt_uuid_16_t;
114+
typedef struct bt_uuid_128 bt_uuid_128_t;
115+
116+
117+
118+
111119
#ifdef __cplusplus
112120
}
113121
#endif

0 commit comments

Comments
 (0)