remove requestPHY() from 1MB to 2MB, old Mac may not support 2MB. Leave it to central to switch
also add hci str debug
This commit is contained in:
1 parent
d2445967ba
commit
df6a459a10
5 files changed
+50
-84
No files matched your search
@@ -438,6 +438,53 @@ const char* dbg_err_str(int32_t err_id)
|
||||
return str;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// HCI STATUS
|
||||
//--------------------------------------------------------------------+
|
||||
static lookup_entry_t const _strhci_lookup[] =
|
||||
{
|
||||
{ .key = BLE_HCI_STATUS_CODE_SUCCESS , .data = "STATUS_CODE_SUCCESS" },
|
||||
{ .key = BLE_HCI_STATUS_CODE_UNKNOWN_BTLE_COMMAND , .data = "STATUS_CODE_UNKNOWN_BTLE_COMMAND " },
|
||||
{ .key = BLE_HCI_STATUS_CODE_UNKNOWN_CONNECTION_IDENTIFIER , .data = "STATUS_CODE_UNKNOWN_CONNECTION_IDENTIFIER" },
|
||||
{ .key = BLE_HCI_AUTHENTICATION_FAILURE , .data = "AUTHENTICATION_FAILURE " },
|
||||
{ .key = BLE_HCI_STATUS_CODE_PIN_OR_KEY_MISSING , .data = "STATUS_CODE_PIN_OR_KEY_MISSING " },
|
||||
{ .key = BLE_HCI_MEMORY_CAPACITY_EXCEEDED , .data = "MEMORY_CAPACITY_EXCEEDED " },
|
||||
{ .key = BLE_HCI_CONNECTION_TIMEOUT , .data = "CONNECTION_TIMEOUT " },
|
||||
{ .key = BLE_HCI_STATUS_CODE_COMMAND_DISALLOWED , .data = "STATUS_CODE_COMMAND_DISALLOWED " },
|
||||
{ .key = BLE_HCI_STATUS_CODE_INVALID_BTLE_COMMAND_PARAMETERS , .data = "STATUS_CODE_INVALID_BTLE_COMMAND_PARAMETERS" },
|
||||
{ .key = BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION , .data = "REMOTE_USER_TERMINATED_CONNECTION" },
|
||||
{ .key = BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES , .data = "REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES" },
|
||||
{ .key = BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF , .data = "REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF" },
|
||||
{ .key = BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION , .data = "LOCAL_HOST_TERMINATED_CONNECTION " },
|
||||
{ .key = BLE_HCI_UNSUPPORTED_REMOTE_FEATURE , .data = "UNSUPPORTED_REMOTE_FEATURE" },
|
||||
{ .key = BLE_HCI_STATUS_CODE_INVALID_LMP_PARAMETERS , .data = "STATUS_CODE_INVALID_LMP_PARAMETERS " },
|
||||
{ .key = BLE_HCI_STATUS_CODE_UNSPECIFIED_ERROR , .data = "STATUS_CODE_UNSPECIFIED_ERROR" },
|
||||
{ .key = BLE_HCI_STATUS_CODE_LMP_RESPONSE_TIMEOUT , .data = "STATUS_CODE_LMP_RESPONSE_TIMEOUT " },
|
||||
{ .key = BLE_HCI_STATUS_CODE_LMP_ERROR_TRANSACTION_COLLISION , .data = "STATUS_CODE_LMP_ERROR_TRANSACTION_COLLISION" },
|
||||
{ .key = BLE_HCI_STATUS_CODE_LMP_PDU_NOT_ALLOWED , .data = "STATUS_CODE_LMP_PDU_NOT_ALLOWED" },
|
||||
{ .key = BLE_HCI_INSTANT_PASSED , .data = "INSTANT_PASSED " },
|
||||
{ .key = BLE_HCI_PAIRING_WITH_UNIT_KEY_UNSUPPORTED , .data = "PAIRING_WITH_UNIT_KEY_UNSUPPORTED" },
|
||||
{ .key = BLE_HCI_DIFFERENT_TRANSACTION_COLLISION , .data = "DIFFERENT_TRANSACTION_COLLISION" },
|
||||
{ .key = BLE_HCI_PARAMETER_OUT_OF_MANDATORY_RANGE , .data = "PARAMETER_OUT_OF_MANDATORY_RANGE " },
|
||||
{ .key = BLE_HCI_CONTROLLER_BUSY , .data = "CONTROLLER_BUSY" },
|
||||
{ .key = BLE_HCI_CONN_INTERVAL_UNACCEPTABLE , .data = "CONN_INTERVAL_UNACCEPTABLE " },
|
||||
{ .key = BLE_HCI_DIRECTED_ADVERTISER_TIMEOUT , .data = "DIRECTED_ADVERTISER_TIMEOUT" },
|
||||
{ .key = BLE_HCI_CONN_TERMINATED_DUE_TO_MIC_FAILURE , .data = "CONN_TERMINATED_DUE_TO_MIC_FAILURE " },
|
||||
{ .key = BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED , .data = "CONN_FAILED_TO_BE_ESTABLISHED" }
|
||||
};
|
||||
|
||||
lookup_table_t const _strhci_table =
|
||||
{
|
||||
.count = arrcount(_strhci_lookup),
|
||||
.items = _strhci_lookup
|
||||
};
|
||||
|
||||
|
||||
const char* dbg_hci_str(uint8_t id)
|
||||
{
|
||||
return (const char *) lookup_find(&_strhci_table, id);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -46,6 +46,7 @@
|
||||
#if CFG_DEBUG
|
||||
const char* dbg_ble_event_str(uint16_t evt_id);
|
||||
const char* dbg_err_str(int32_t err_id);
|
||||
const char* dbg_hci_str(uint8_t id);
|
||||
#endif
|
||||
|
||||
int dbgHeapTotal(void);
|
||||
|
||||
@@ -61,9 +61,6 @@ uint32_t totalPixel = 0; // received pixel
|
||||
// pixel line buffer, should be large enough to hold an image width
|
||||
uint16_t pixel_buf[512];
|
||||
|
||||
// Use software timer to schedule bandwidth negotiation a few seconds after connection
|
||||
SoftwareTimer negoTimer;
|
||||
|
||||
// Statistics for speed testing
|
||||
uint32_t rxStartTime = 0;
|
||||
uint32_t rxLastTime = 0;
|
||||
@@ -112,9 +109,6 @@ void setup()
|
||||
|
||||
bleuart.setRxOverflowCallback(bleuart_overflow_callback);
|
||||
|
||||
// one-shot (non-repeating) 2 seconds timer
|
||||
negoTimer.begin(2000, negotiate_bandwidth, NULL, false);
|
||||
|
||||
// Set up and start advertising
|
||||
startAdv();
|
||||
|
||||
@@ -260,43 +254,8 @@ void bleuart_rx_callback(uint16_t conn_hdl)
|
||||
}
|
||||
}
|
||||
|
||||
void negotiate_bandwidth(TimerHandle_t xTimer)
|
||||
{
|
||||
(void) xTimer;
|
||||
|
||||
uint16_t conn_hdl = (uint16_t) ((uint32_t) negoTimer.getID());
|
||||
BLEConnection* conn = Bluefruit.Connection(conn_hdl);
|
||||
|
||||
// Switching from 1 Mb to 2 Mb PHY if needed
|
||||
if ( conn->connected() )
|
||||
{
|
||||
// Requesting to Switching to 2MB PHY, larger data length and bigger MTU
|
||||
// will increase the throughput on supported central. This should already
|
||||
// be done with latest Bluefruit app.
|
||||
//
|
||||
// However, some Android devices require 2Mb PHY switching must be initiated
|
||||
// from nRF side
|
||||
if ( conn->getPHY() == BLE_GAP_PHY_1MBPS )
|
||||
{
|
||||
Serial.println("Requesting PHY change from 1 Mb to 2Mb");
|
||||
conn->requestPHY();
|
||||
|
||||
// Data Length and MTU should already be done by Bluefruit app
|
||||
// conn->requestDataLengthUpdate();
|
||||
// conn->requestMtuExchange(247);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void connect_callback(uint16_t conn_handle)
|
||||
{
|
||||
// Set connection handle as timer ID
|
||||
// Then schedule negotiation after a few seconds, we should not
|
||||
// negotiate here since it increases chance to conflict with other
|
||||
// on-going negotiation from central after connection
|
||||
negoTimer.setID((void*) conn_handle);
|
||||
negoTimer.start();
|
||||
|
||||
Serial.println("Connected");
|
||||
Serial.println("Ready to receive new image");
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
#define TFT_24_FEATHERWING 2
|
||||
|
||||
// [Configurable] For other boards please select which external display to match your hardware setup
|
||||
#define TFT_IN_USE TFT_35_FEATHERWING
|
||||
#define TFT_IN_USE TFT_24_FEATHERWING
|
||||
|
||||
#if defined(ARDUINO_NRF52832_FEATHER)
|
||||
// Feather nRF52832 pin map is different from others
|
||||
@@ -97,9 +97,6 @@ uint32_t totalPixel = 0; // received pixel
|
||||
// pixel line buffer, should be large enough to hold an image width
|
||||
uint16_t pixel_buf[512];
|
||||
|
||||
// Use software timer to schedule bandwidth negotiation a few seconds after connection
|
||||
SoftwareTimer negoTimer;
|
||||
|
||||
// Statistics for speed testing
|
||||
uint32_t rxStartTime = 0;
|
||||
uint32_t rxLastTime = 0;
|
||||
@@ -173,9 +170,6 @@ void setup()
|
||||
|
||||
bleuart.setRxOverflowCallback(bleuart_overflow_callback);
|
||||
|
||||
// one-shot (non-repeating) 2 seconds timer
|
||||
negoTimer.begin(2000, negotiate_bandwidth, NULL, false);
|
||||
|
||||
// Set up and start advertising
|
||||
startAdv();
|
||||
|
||||
@@ -296,43 +290,8 @@ void bleuart_rx_callback(uint16_t conn_hdl)
|
||||
}
|
||||
}
|
||||
|
||||
void negotiate_bandwidth(TimerHandle_t xTimer)
|
||||
{
|
||||
(void) xTimer;
|
||||
|
||||
uint16_t conn_hdl = (uint16_t) ((uint32_t) negoTimer.getID());
|
||||
BLEConnection* conn = Bluefruit.Connection(conn_hdl);
|
||||
|
||||
// Switching from 1 Mb to 2 Mb PHY if needed
|
||||
if ( conn->connected() )
|
||||
{
|
||||
// Requesting to Switching to 2MB PHY, larger data length and bigger MTU
|
||||
// will increase the throughput on supported central. This should already
|
||||
// be done with latest Bluefruit app.
|
||||
//
|
||||
// However, some Android devices require 2Mb PHY switching must be initiated
|
||||
// from nRF side
|
||||
if ( conn->getPHY() == BLE_GAP_PHY_1MBPS )
|
||||
{
|
||||
Serial.println("Requesting PHY change from 1 Mb to 2Mb");
|
||||
conn->requestPHY();
|
||||
|
||||
// Data Length and MTU should already be done by Bluefruit app
|
||||
// conn->requestDataLengthUpdate();
|
||||
// conn->requestMtuExchange(247);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void connect_callback(uint16_t conn_handle)
|
||||
{
|
||||
// Set connection handle as timer ID
|
||||
// Then schedule negotiation after a few seconds, we should not
|
||||
// negotiate here since it increases chance to conflict with other
|
||||
// on-going negotiation from central after connection
|
||||
negoTimer.setID((void*) ((uint32_t)conn_handle));
|
||||
negoTimer.start();
|
||||
|
||||
tft.println("Connected");
|
||||
tft.setTextColor(COLOR_GREEN);
|
||||
tft.println("Ready to receive new image");
|
||||
|
||||
@@ -823,7 +823,7 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt)
|
||||
{
|
||||
ble_gap_evt_disconnected_t const* para = &evt->evt.gap_evt.params.disconnected;
|
||||
|
||||
LOG_LV2("GAP", "Disconnect Reason 0x%02X", evt->evt.gap_evt.params.disconnected.reason);
|
||||
LOG_LV2("GAP", "Disconnect Reason: %s", dbg_hci_str(evt->evt.gap_evt.params.disconnected.reason));
|
||||
|
||||
// Turn off Conn LED If not connected at all
|
||||
if ( !this->connected() ) _setConnLed(false);
|
||||
|
||||
Reference in new issue
Block a user