Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Fix slow handling of RX data #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
Scan Callback

This example scans for BLE peripherals and prints out their advertising details:
address, local name, adverised service UUIDs. Unlike the Scan example, it uses
the callback style APIs and disables filtering so the peripheral discovery is
reported for every single advertisement it makes.

The circuit:
- Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT,
Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board.

This example code is in the public domain.
*/

#include <ArduinoBLE.h>

unsigned long eventNow;
unsigned long eventInt = { 2000 } ;
const unsigned int eventStep = { 250 };
unsigned int eventDelay = { 1000 };
const unsigned int delayStep = { 100 };

unsigned int peripheralsCount = { 0 };

void setup() {
Serial.begin(9600);
while (!Serial);

// begin initialization
if (!BLE.begin()) {
Serial.println("starting BLE failed!");

while (1);
}

Serial.println("BLE Central scan callback");

// set the discovered event handle
BLE.setEventHandler(BLEDiscovered, bleCentralDiscoverHandler);

// start scanning for peripherals with duplicates
BLE.scan(true);
}

void loop() {
// poll the central for events
BLE.poll();

if (millis() > eventNow) {
Serial.print("Event 1 - ");
Serial.print("Peripherals: ");
Serial.print(peripheralsCount);
peripheralsCount = 0;

Serial.print(" Delay: ");
Serial.print(eventDelay);

Serial.print(" Interval: ");
Serial.print(eventInt);

delay(eventDelay);
eventDelay += delayStep;
eventNow = millis() + eventInt;
eventInt += eventStep;

Serial.print(" - Done.");
Serial.println();
}
}

void bleCentralDiscoverHandler(BLEDevice peripheral) {
BLE.stopScan();
peripheralsCount++;

digitalWrite(LED_BUILTIN, HIGH);
delay(5);
digitalWrite(LED_BUILTIN, LOW);
BLE.scan(true);
}
84 changes: 84 additions & 0 deletions examples/Central/ScanInterleaved/ScanInterleaved.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
Scan

This example scans for BLE peripherals and prints out their advertising details:
address, local name, adverised service UUID's.

The circuit:
- Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT,
Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board.

This example code is in the public domain.
*/

#include <ArduinoBLE.h>

unsigned long eventNow;
unsigned long eventInt = { 2000 } ;
const unsigned int eventStep = { 250 };
unsigned int eventDelay = { 1000 };
const unsigned int delayStep = { 100 };

unsigned int peripheralsCount = { 0 };


void setup() {
Serial.begin(9600);
while (!Serial);

delay(2000);

// BLE.debug(Serial);

// begin initialization
if (!BLE.begin()) {
Serial.println("starting BLE failed!");

while (1);
}

Serial.println("BLE Central scan");


// start scanning for peripheral
BLE.scan();

eventNow = millis() + eventInt;
}

void loop() {
// check if a peripheral has been discovered
BLEDevice peripheral = BLE.available();

if (peripheral) {
BLE.stopScan();
peripheralsCount++;

digitalWrite(LED_BUILTIN, HIGH);
delay(5);
digitalWrite(LED_BUILTIN, LOW);

BLE.scan();
}

if (millis() > eventNow) {
Serial.print("Event 1 - ");
Serial.print("Peripherals: ");
Serial.print(peripheralsCount);
peripheralsCount = 0;

Serial.print(" Delay: ");
Serial.print(eventDelay);

Serial.print(" Interval: ");
Serial.print(eventInt);

delay(eventDelay);
eventDelay += delayStep;
eventNow = millis() + eventInt;
eventInt += eventStep;

Serial.print(" - Done.");
Serial.println();
}
}
6 changes: 3 additions & 3 deletions src/utility/HCICordioTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ size_t HCICordioTransportClass::write(const uint8_t* data, size_t length)

void HCICordioTransportClass::handleRxData(uint8_t* data, uint8_t len)
{
if (_rxBuf.availableForStore() < len) {
// drop!
return;
while (_rxBuf.availableForStore() < len) {
// Wait for free space on RingBuffer
yield();
}

for (int i = 0; i < len; i++) {
Expand Down