Skip to content

Commit f5b4c64

Browse files
committed
Pass rx/tx buffer size to BluetoothSerial library
See original mods at: sparkfun/SparkFun_RTK_Firmware@bc06787 Escalated the "RX Full!" log_d to a Serial.print.
1 parent f812e29 commit f5b4c64

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

Firmware/RTK_Everywhere/Bluetooth.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,17 @@ void bluetoothStart()
292292
if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_AND_BLE)
293293
{
294294
beginSuccess &=
295-
bluetoothSerialBle->begin(deviceName, false, settings.sppRxQueueSize,
296-
settings.sppTxQueueSize); // localName, isMaster, rxBufferSize, txBufferSize
295+
bluetoothSerialBle->begin(deviceName, false, false, settings.sppRxQueueSize,
296+
settings.sppTxQueueSize); // localName, isMaster, disableBLE, rxBufferSize, txBufferSize
297297
beginSuccess &=
298-
bluetoothSerialSpp->begin(deviceName, false, settings.sppRxQueueSize,
299-
settings.sppTxQueueSize); // localName, isMaster, rxBufferSize, txBufferSize
298+
bluetoothSerialSpp->begin(deviceName, false, false, settings.sppRxQueueSize,
299+
settings.sppTxQueueSize); // localName, isMaster, disableBLE, rxBufferSize, txBufferSize
300300
}
301301
else
302302
{
303303
beginSuccess &=
304-
bluetoothSerial->begin(deviceName, false, settings.sppRxQueueSize,
305-
settings.sppTxQueueSize); // localName, isMaster, rxBufferSize, txBufferSize
304+
bluetoothSerial->begin(deviceName, false, true, settings.sppRxQueueSize,
305+
settings.sppTxQueueSize); // localName, isMaster, disableBLE, rxBufferSize, txBufferSize
306306
}
307307

308308
if (beginSuccess == false)

Firmware/RTK_Everywhere/bluetoothSelect.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
// We use a local copy of the BluetoothSerial library so that we can increase the RX buffer. See issues:
44
// https://github.com/sparkfun/SparkFun_RTK_Firmware/issues/23
55
// https://github.com/sparkfun/SparkFun_RTK_Firmware/issues/469
6-
#include <BluetoothSerial.h>
6+
#include "src/BluetoothSerial/BluetoothSerial.h"
77

88
#include <BleSerial.h> //Click here to get the library: http://librarymanager/All#ESP32_BleSerial v1.0.4 by Avinab Malla
99

1010
class BTSerialInterface
1111
{
1212
public:
13-
virtual bool begin(String deviceName, bool isMaster, uint16_t rxQueueSize, uint16_t txQueueSize) = 0;
13+
virtual bool begin(String deviceName, bool isMaster, bool disableBLE, uint16_t rxQueueSize, uint16_t txQueueSize) = 0;
1414
virtual void disconnect() = 0;
1515
virtual void end() = 0;
1616
virtual esp_err_t register_callback(esp_spp_cb_t callback) = 0;
@@ -31,9 +31,9 @@ class BTClassicSerial : public virtual BTSerialInterface, public BluetoothSerial
3131
// Everything is already implemented in BluetoothSerial since the code was
3232
// originally written using that class
3333
public:
34-
bool begin(String deviceName, bool isMaster, uint16_t rxQueueSize, uint16_t txQueueSize)
34+
bool begin(String deviceName, bool isMaster, bool disableBLE, uint16_t rxQueueSize, uint16_t txQueueSize)
3535
{
36-
return BluetoothSerial::begin(deviceName, isMaster); //, rxQueueSize, txQueueSize); v3.0.0 has no QueueSize parameters
36+
return BluetoothSerial::begin(deviceName, isMaster, disableBLE, rxQueueSize, txQueueSize);
3737
}
3838

3939
void disconnect()
@@ -91,7 +91,7 @@ class BTLESerial : public virtual BTSerialInterface, public BleSerial
9191
{
9292
public:
9393
// Missing from BleSerial
94-
bool begin(String deviceName, bool isMaster, uint16_t rxQueueSize, uint16_t txQueueSize)
94+
bool begin(String deviceName, bool isMaster, bool disableBLE, uint16_t rxQueueSize, uint16_t txQueueSize)
9595
{
9696
BleSerial::begin(deviceName.c_str());
9797
return true;

Firmware/RTK_Everywhere/src/BluetoothSerial/BluetoothSerial.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040

4141
const char *_spp_server_name = "ESP32SPP";
4242

43-
#define RX_QUEUE_SIZE 512
44-
#define TX_QUEUE_SIZE 32
43+
// #define RX_QUEUE_SIZE 512
44+
// #define TX_QUEUE_SIZE 32
4545
#define SPP_TX_QUEUE_TIMEOUT 1000
4646
#define SPP_TX_DONE_TIMEOUT 1000
4747
#define SPP_CONGESTED_TIMEOUT 1000
@@ -347,7 +347,7 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) {
347347
} else if (_spp_rx_queue != NULL) {
348348
for (int i = 0; i < param->data_ind.len; i++) {
349349
if (xQueueSend(_spp_rx_queue, param->data_ind.data + i, (TickType_t)0) != pdTRUE) {
350-
log_e("RX Full! Discarding %u bytes", param->data_ind.len - i);
350+
Serial.printf("RX Full! Discarding %u bytes\r\n", param->data_ind.len - i);
351351
break;
352352
}
353353
}
@@ -616,7 +616,7 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
616616
}
617617
}
618618

619-
static bool _init_bt(const char *deviceName, bt_mode mode) {
619+
static bool _init_bt(const char *deviceName, bt_mode mode, uint16_t rxQueueSize, uint16_t txQueueSize) {
620620
if (!_bt_event_group) {
621621
_bt_event_group = xEventGroupCreate();
622622
if (!_bt_event_group) {
@@ -637,14 +637,16 @@ static bool _init_bt(const char *deviceName, bt_mode mode) {
637637
xEventGroupSetBits(_spp_event_group, SPP_CLOSED);
638638
}
639639
if (_spp_rx_queue == NULL) {
640-
_spp_rx_queue = xQueueCreate(RX_QUEUE_SIZE, sizeof(uint8_t)); //initialize the queue
640+
//_spp_rx_queue = xQueueCreate(RX_QUEUE_SIZE, sizeof(uint8_t)); //initialize the queue
641+
_spp_rx_queue = xQueueCreate(rxQueueSize, sizeof(uint8_t)); //initialize the queue
641642
if (_spp_rx_queue == NULL) {
642643
log_e("RX Queue Create Failed");
643644
return false;
644645
}
645646
}
646647
if (_spp_tx_queue == NULL) {
647-
_spp_tx_queue = xQueueCreate(TX_QUEUE_SIZE, sizeof(spp_packet_t *)); //initialize the queue
648+
//_spp_tx_queue = xQueueCreate(TX_QUEUE_SIZE, sizeof(spp_packet_t *)); //initialize the queue
649+
_spp_tx_queue = xQueueCreate(txQueueSize, sizeof(spp_packet_t*)); //initialize the queue
648650
if (_spp_tx_queue == NULL) {
649651
log_e("TX Queue Create Failed");
650652
return false;
@@ -820,12 +822,13 @@ BluetoothSerial::~BluetoothSerial(void) {
820822
* @param isMaster set to true if you want to connect to an other device
821823
* @param disableBLE if BLE is not used, its ram can be freed to get +10kB free ram
822824
*/
823-
bool BluetoothSerial::begin(String localName, bool isMaster, bool disableBLE) {
825+
//bool BluetoothSerial::begin(String localName, bool isMaster, bool disableBLE) {
826+
bool BluetoothSerial::begin(String localName, bool isMaster, bool disableBLE, uint16_t rxQueueSize, uint16_t txQueueSize) {
824827
_isMaster = isMaster;
825828
if (localName.length()) {
826829
local_name = localName;
827830
}
828-
return _init_bt(local_name.c_str(), disableBLE ? BT_MODE_CLASSIC_BT : BT_MODE_BTDM);
831+
return _init_bt(local_name.c_str(), disableBLE ? BT_MODE_CLASSIC_BT : BT_MODE_BTDM, rxQueueSize, txQueueSize);
829832
}
830833

831834
int BluetoothSerial::available(void) {

Firmware/RTK_Everywhere/src/BluetoothSerial/BluetoothSerial.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class BluetoothSerial : public Stream {
3939
BluetoothSerial(void);
4040
~BluetoothSerial(void);
4141

42-
bool begin(String localName = String(), bool isMaster = false, bool disableBLE = false);
42+
bool begin(String localName = String(), bool isMaster = false, bool disableBLE = false, uint16_t rxQueueSize = 512 * 2, uint16_t txQueueSize = 512);
4343
bool begin(unsigned long baud) { //compatibility
4444
return begin();
4545
}

0 commit comments

Comments
 (0)