Adafruit_nRF8001 icon indicating copy to clipboard operation
Adafruit_nRF8001 copied to clipboard

print() with strings > 20 characters drops data

Open drinckes opened this issue 9 years ago • 2 comments

Sending strings longer than 20 characters causes chunks of the strings to be dropped and ACI errors to be output. I think this is because data_credit_available isn't checked anywhere before sending data. To reproduce, send some strings whose lengths are > 20 characters using print() one after the other. Some of them will be missing parts.

If I modify line 257 of Adafruit_BLE_UART.cpp to include a check that there is at least one data credit:

if(!lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX) || aci_state.data_credit_available == 0)

Then it will remain polling until the pipe is available and it has a data credit. (Line 281 needs a similar change.) The downside is this ends up wasting cycles, waiting for a data credit to become available. I also wrote the following function so I can check the pipe and data credit status, before I call print() or write():

bool Adafruit_BLE_UART::ready(void) {
  return lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX) && aci_state.data_credit_available > 0;
}

drinckes avatar Jan 05 '15 12:01 drinckes