Skip to content

Commit 8ce3506

Browse files
committed
add BLEConnection requestConnectionParameter()
rename getConnInterval() to getConnectionInterval()
1 parent 3093c14 commit 8ce3506

File tree

7 files changed

+33
-10
lines changed

7 files changed

+33
-10
lines changed

cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void Adafruit_USBD_CDC::flush(void)
107107

108108
size_t Adafruit_USBD_CDC::write(uint8_t ch)
109109
{
110-
return tud_cdc_write_char((char) ch);
110+
return write(&ch, 1);
111111
}
112112

113113
size_t Adafruit_USBD_CDC::write(const uint8_t *buffer, size_t size)

libraries/Bluefruit52Lib/examples/Peripheral/throughput/throughput.ino

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ char test_data[256] = { 0 };
2525

2626
// Number of packet to sent
2727
// actualy number of bytes depends on the MTU of the connection
28-
#define PACKET_NUM 1024
28+
#define PACKET_NUM 1000
2929

3030
BLEDis bledis;
3131
BLEUart bleuart;
@@ -114,6 +114,9 @@ void connect_callback(uint16_t conn_handle)
114114

115115
// request mtu exchange
116116
conn->requestMtuExchange(247);
117+
118+
// request connection interval of 7.5 ms
119+
//conn->requestConnectionParameter(6); // in unit of 1.25
117120
}
118121

119122
/**
@@ -144,7 +147,8 @@ void test_throughput(void)
144147
Serial.print("Sending ");
145148
Serial.print(remaining);
146149
Serial.println(" bytes ...");
147-
Serial.flush();
150+
Serial.flush();
151+
delay(1);
148152

149153
start = millis();
150154
while ( (remaining > 0) && Bluefruit.connected() && bleuart.notifyEnabled() )
@@ -172,7 +176,7 @@ void loop(void)
172176
if (Bluefruit.connected() && bleuart.notifyEnabled())
173177
{
174178
// Wait for user input before trying again
175-
Serial.println("Connected. Send a key and press enter to start test");
179+
Serial.println("Send a key and press enter to start test");
176180
//getUserInput();
177181

178182
test_throughput();

libraries/Bluefruit52Lib/src/BLEConnection.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ uint16_t BLEConnection::getMtu (void)
9696
return _mtu;
9797
}
9898

99-
uint16_t BLEConnection::getConnInterval(void)
99+
uint16_t BLEConnection::getConnectionInterval(void)
100100
{
101101
return _conn_interval;
102102
}
@@ -156,6 +156,20 @@ bool BLEConnection::requestDataLengthUpdate(ble_gap_data_length_params_t const *
156156
return true;
157157
}
158158

159+
bool BLEConnection::requestConnectionParameter(uint16_t conn_interval, uint16_t slave_latency, uint16_t sup_timeout)
160+
{
161+
ble_gap_conn_params_t const conn_params =
162+
{
163+
.min_conn_interval = conn_interval,
164+
.max_conn_interval = conn_interval,
165+
.slave_latency = slave_latency,
166+
.conn_sup_timeout = sup_timeout
167+
};
168+
VERIFY_STATUS(sd_ble_gap_conn_param_update(_conn_hdl, &conn_params), false);
169+
170+
return true;
171+
}
172+
159173
bool BLEConnection::requestPHY(uint8_t phy)
160174
{
161175
ble_gap_phys_t gap_phy = { .tx_phys = phy, .rx_phys = phy };
@@ -436,7 +450,7 @@ void BLEConnection::_eventHandler(ble_evt_t* evt)
436450
ble_gap_conn_params_t* param = &evt->evt.gap_evt.params.conn_param_update.conn_params;
437451
_conn_interval = param->max_conn_interval;
438452

439-
LOG_LV1("GAP", "Conn Interval= %f", _conn_interval*1.25f);
453+
LOG_LV1("GAP", "Conn Interval= %.2f ms, Latency = %d, Supervisor Timeout = %d ms", _conn_interval*1.25f, param->slave_latency, 10*param->conn_sup_timeout);
440454
}
441455
break;
442456

libraries/Bluefruit52Lib/src/BLEConnection.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class BLEConnection
7878

7979
uint8_t getRole(void);
8080
uint16_t getMtu (void);
81-
uint16_t getConnInterval(void);
81+
uint16_t getConnectionInterval(void);
8282
uint16_t getDataLength(void);
8383
uint8_t getPHY(void);
8484

@@ -88,9 +88,12 @@ class BLEConnection
8888
bool disconnect(void);
8989

9090
bool setTxPower(int8_t power); // set power for this connection
91+
9192
bool requestDataLengthUpdate(ble_gap_data_length_params_t const *p_dl_params = NULL, ble_gap_data_length_limitation_t *p_dl_limitation = NULL);
9293
bool requestMtuExchange(uint16_t mtu);
9394
bool requestPHY(uint8_t phy = BLE_GAP_PHY_AUTO);
95+
bool requestConnectionParameter(uint16_t conn_interval, uint16_t slave_latency = BLE_GAP_CONN_SLAVE_LATENCY, uint16_t sup_timeout = BLE_GAP_CONN_SUPERVISION_TIMEOUT_MS/10);
96+
bool requestPairing(void);
9497

9598
bool monitorRssi(uint8_t threshold = BLE_GAP_RSSI_THRESHOLD_INVALID);
9699
int8_t getRssi(void);
@@ -100,7 +103,6 @@ class BLEConnection
100103
bool getWriteCmdPacket(void);
101104
bool waitForIndicateConfirm(void);
102105

103-
bool requestPairing(void);
104106
bool storeCccd(void);
105107
bool loadKeys(bond_keys_t* bkeys);
106108

libraries/Bluefruit52Lib/src/BLEGatt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ uint16_t BLEGatt::readCharByUuid(uint16_t conn_hdl, BLEUuid bleuuid, void* buffe
5454

5555
while( _adamsg.isWaiting() )
5656
{
57-
delay( conn->getConnInterval() );
57+
delay( conn->getConnectionInterval() );
5858
}
5959

6060
_adamsg.begin(true);

libraries/Bluefruit52Lib/src/BLEPeriph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void BLEPeriph::printInfo(void)
158158
Serial.println();
159159

160160
Serial.printf(title_fmt, "Conn Timeout");
161-
Serial.printf("%.2f ms", _ppcp.conn_sup_timeout*10.0f);
161+
Serial.printf("%d ms", _ppcp.conn_sup_timeout*10);
162162
Serial.println();
163163
}
164164

libraries/Bluefruit52Lib/src/bluefruit.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,9 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt)
794794

795795
ble_gap_evt_connected_t const * para = &evt->evt.gap_evt.params.connected;
796796

797+
LOG_LV1("GAP", "Conn Interval= %.2f ms, Latency = %d, Supervisor Timeout = %d ms",
798+
para->conn_params.max_conn_interval*1.25f, para->conn_params.slave_latency, 10*para->conn_params.conn_sup_timeout);
799+
797800
if ( _connection[conn_hdl] )
798801
{
799802
LOG_LV1("GAP", "Connection is already in used, something wrong !!");

0 commit comments

Comments
 (0)