add BLEConnection requestConnectionParameter()

rename getConnInterval() to getConnectionInterval()
This commit is contained in:
hathach committed 2019-08-16 12:22:21 +07:00
1 parent 3093c146a7
commit 8ce3506904
7 files changed
+33 -10

No files matched your search

@@ -107,7 +107,7 @@ void Adafruit_USBD_CDC::flush(void)
size_t Adafruit_USBD_CDC::write(uint8_t ch)
{
return tud_cdc_write_char((char) ch);
return write(&ch, 1);
}
size_t Adafruit_USBD_CDC::write(const uint8_t *buffer, size_t size)
@@ -25,7 +25,7 @@ char test_data[256] = { 0 };
// Number of packet to sent
// actualy number of bytes depends on the MTU of the connection
#define PACKET_NUM 1024
#define PACKET_NUM 1000
BLEDis bledis;
BLEUart bleuart;
@@ -114,6 +114,9 @@ void connect_callback(uint16_t conn_handle)
// request mtu exchange
conn->requestMtuExchange(247);
// request connection interval of 7.5 ms
//conn->requestConnectionParameter(6); // in unit of 1.25
}
/**
@@ -144,7 +147,8 @@ void test_throughput(void)
Serial.print("Sending ");
Serial.print(remaining);
Serial.println(" bytes ...");
Serial.flush();
Serial.flush();
delay(1);
start = millis();
while ( (remaining > 0) && Bluefruit.connected() && bleuart.notifyEnabled() )
@@ -172,7 +176,7 @@ void loop(void)
if (Bluefruit.connected() && bleuart.notifyEnabled())
{
// Wait for user input before trying again
Serial.println("Connected. Send a key and press enter to start test");
Serial.println("Send a key and press enter to start test");
//getUserInput();
test_throughput();
+16 -2
View File
@@ -96,7 +96,7 @@ uint16_t BLEConnection::getMtu (void)
return _mtu;
}
uint16_t BLEConnection::getConnInterval(void)
uint16_t BLEConnection::getConnectionInterval(void)
{
return _conn_interval;
}
@@ -156,6 +156,20 @@ bool BLEConnection::requestDataLengthUpdate(ble_gap_data_length_params_t const *
return true;
}
bool BLEConnection::requestConnectionParameter(uint16_t conn_interval, uint16_t slave_latency, uint16_t sup_timeout)
{
ble_gap_conn_params_t const conn_params =
{
.min_conn_interval = conn_interval,
.max_conn_interval = conn_interval,
.slave_latency = slave_latency,
.conn_sup_timeout = sup_timeout
};
VERIFY_STATUS(sd_ble_gap_conn_param_update(_conn_hdl, &conn_params), false);
return true;
}
bool BLEConnection::requestPHY(uint8_t phy)
{
ble_gap_phys_t gap_phy = { .tx_phys = phy, .rx_phys = phy };
@@ -436,7 +450,7 @@ void BLEConnection::_eventHandler(ble_evt_t* evt)
ble_gap_conn_params_t* param = &evt->evt.gap_evt.params.conn_param_update.conn_params;
_conn_interval = param->max_conn_interval;
LOG_LV1("GAP", "Conn Interval= %f", _conn_interval*1.25f);
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);
}
break;
+4 -2
View File
@@ -78,7 +78,7 @@ class BLEConnection
uint8_t getRole(void);
uint16_t getMtu (void);
uint16_t getConnInterval(void);
uint16_t getConnectionInterval(void);
uint16_t getDataLength(void);
uint8_t getPHY(void);
@@ -88,9 +88,12 @@ class BLEConnection
bool disconnect(void);
bool setTxPower(int8_t power); // set power for this connection
bool requestDataLengthUpdate(ble_gap_data_length_params_t const *p_dl_params = NULL, ble_gap_data_length_limitation_t *p_dl_limitation = NULL);
bool requestMtuExchange(uint16_t mtu);
bool requestPHY(uint8_t phy = BLE_GAP_PHY_AUTO);
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);
bool requestPairing(void);
bool monitorRssi(uint8_t threshold = BLE_GAP_RSSI_THRESHOLD_INVALID);
int8_t getRssi(void);
@@ -100,7 +103,6 @@ class BLEConnection
bool getWriteCmdPacket(void);
bool waitForIndicateConfirm(void);
bool requestPairing(void);
bool storeCccd(void);
bool loadKeys(bond_keys_t* bkeys);
+1 -1
View File
@@ -54,7 +54,7 @@ uint16_t BLEGatt::readCharByUuid(uint16_t conn_hdl, BLEUuid bleuuid, void* buffe
while( _adamsg.isWaiting() )
{
delay( conn->getConnInterval() );
delay( conn->getConnectionInterval() );
}
_adamsg.begin(true);
+1 -1
View File
@@ -158,7 +158,7 @@ void BLEPeriph::printInfo(void)
Serial.println();
Serial.printf(title_fmt, "Conn Timeout");
Serial.printf("%.2f ms", _ppcp.conn_sup_timeout*10.0f);
Serial.printf("%d ms", _ppcp.conn_sup_timeout*10);
Serial.println();
}
@@ -794,6 +794,9 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt)
ble_gap_evt_connected_t const * para = &evt->evt.gap_evt.params.connected;
LOG_LV1("GAP", "Conn Interval= %.2f ms, Latency = %d, Supervisor Timeout = %d ms",
para->conn_params.max_conn_interval*1.25f, para->conn_params.slave_latency, 10*para->conn_params.conn_sup_timeout);
if ( _connection[conn_hdl] )
{
LOG_LV1("GAP", "Connection is already in used, something wrong !!");