Skip to content
Merged
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
12 changes: 6 additions & 6 deletions Firmware/RTK_Everywhere/Bluetooth.ino
Original file line number Diff line number Diff line change
Expand Up @@ -292,17 +292,17 @@ void bluetoothStart()
if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_AND_BLE)
{
beginSuccess &=
bluetoothSerialBle->begin(deviceName, false, settings.sppRxQueueSize,
settings.sppTxQueueSize); // localName, isMaster, rxBufferSize, txBufferSize
bluetoothSerialBle->begin(deviceName, false, false, settings.sppRxQueueSize,
settings.sppTxQueueSize); // localName, isMaster, disableBLE, rxBufferSize, txBufferSize
beginSuccess &=
bluetoothSerialSpp->begin(deviceName, false, settings.sppRxQueueSize,
settings.sppTxQueueSize); // localName, isMaster, rxBufferSize, txBufferSize
bluetoothSerialSpp->begin(deviceName, false, false, settings.sppRxQueueSize,
settings.sppTxQueueSize); // localName, isMaster, disableBLE, rxBufferSize, txBufferSize
}
else
{
beginSuccess &=
bluetoothSerial->begin(deviceName, false, settings.sppRxQueueSize,
settings.sppTxQueueSize); // localName, isMaster, rxBufferSize, txBufferSize
bluetoothSerial->begin(deviceName, false, true, settings.sppRxQueueSize,
settings.sppTxQueueSize); // localName, isMaster, disableBLE, rxBufferSize, txBufferSize
}

if (beginSuccess == false)
Expand Down
10 changes: 5 additions & 5 deletions Firmware/RTK_Everywhere/bluetoothSelect.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
// We use a local copy of the BluetoothSerial library so that we can increase the RX buffer. See issues:
// https://github.com/sparkfun/SparkFun_RTK_Firmware/issues/23
// https://github.com/sparkfun/SparkFun_RTK_Firmware/issues/469
#include <BluetoothSerial.h>
#include "src/BluetoothSerial/BluetoothSerial.h"

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

class BTSerialInterface
{
public:
virtual bool begin(String deviceName, bool isMaster, uint16_t rxQueueSize, uint16_t txQueueSize) = 0;
virtual bool begin(String deviceName, bool isMaster, bool disableBLE, uint16_t rxQueueSize, uint16_t txQueueSize) = 0;
virtual void disconnect() = 0;
virtual void end() = 0;
virtual esp_err_t register_callback(esp_spp_cb_t callback) = 0;
Expand All @@ -31,9 +31,9 @@ class BTClassicSerial : public virtual BTSerialInterface, public BluetoothSerial
// Everything is already implemented in BluetoothSerial since the code was
// originally written using that class
public:
bool begin(String deviceName, bool isMaster, uint16_t rxQueueSize, uint16_t txQueueSize)
bool begin(String deviceName, bool isMaster, bool disableBLE, uint16_t rxQueueSize, uint16_t txQueueSize)
{
return BluetoothSerial::begin(deviceName, isMaster); //, rxQueueSize, txQueueSize); v3.0.0 has no QueueSize parameters
return BluetoothSerial::begin(deviceName, isMaster, disableBLE, rxQueueSize, txQueueSize);
}

void disconnect()
Expand Down Expand Up @@ -91,7 +91,7 @@ class BTLESerial : public virtual BTSerialInterface, public BleSerial
{
public:
// Missing from BleSerial
bool begin(String deviceName, bool isMaster, uint16_t rxQueueSize, uint16_t txQueueSize)
bool begin(String deviceName, bool isMaster, bool disableBLE, uint16_t rxQueueSize, uint16_t txQueueSize)
{
BleSerial::begin(deviceName.c_str());
return true;
Expand Down
112 changes: 112 additions & 0 deletions Firmware/RTK_Everywhere/src/BluetoothSerial/BTAddress.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* BTAddress.cpp
*
* Created on: Jul 2, 2017
* Author: kolban
* Ported on: Feb 5, 2021
* Author: Thomas M. (ArcticSnowSky)
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BLUEDROID_ENABLED)

#include "BTAddress.h"
#include <string>
#include <sstream>
#include <iomanip>
#include <string.h>
#include <stdio.h>
#include <malloc.h>
#ifdef ARDUINO_ARCH_ESP32
#include "esp32-hal-log.h"
#endif

/**
* @brief Create an address from the native ESP32 representation.
* @param [in] address The native representation.
*/
BTAddress::BTAddress(esp_bd_addr_t address) {
memcpy(m_address, address, ESP_BD_ADDR_LEN);
} // BTAddress

BTAddress::BTAddress() {
bzero(m_address, ESP_BD_ADDR_LEN);
} // BTAddress

/**
* @brief Create an address from a hex string
*
* A hex string is of the format:
* ```
* 00:00:00:00:00:00
* ```
* which is 17 characters in length.
*
* @param [in] stringAddress The hex representation of the address.
*/
BTAddress::BTAddress(String stringAddress) {
if (stringAddress.length() != 17) {
return;
}

int data[6];
sscanf(stringAddress.c_str(), "%x:%x:%x:%x:%x:%x", &data[0], &data[1], &data[2], &data[3], &data[4], &data[5]);
m_address[0] = (uint8_t)data[0];
m_address[1] = (uint8_t)data[1];
m_address[2] = (uint8_t)data[2];
m_address[3] = (uint8_t)data[3];
m_address[4] = (uint8_t)data[4];
m_address[5] = (uint8_t)data[5];
} // BTAddress

/**
* @brief Determine if this address equals another.
* @param [in] otherAddress The other address to compare against.
* @return True if the addresses are equal.
*/
bool BTAddress::equals(BTAddress otherAddress) {
return memcmp(otherAddress.getNative(), m_address, 6) == 0;
} // equals

BTAddress::operator bool() const {
for (int i = 0; i < ESP_BD_ADDR_LEN; i++) {
if (this->m_address[i]) {
return true;
}
}
return false;
} // operator ()

/**
* @brief Return the native representation of the address.
* @return The native representation of the address.
*/
esp_bd_addr_t *BTAddress::getNative() const {
return const_cast<esp_bd_addr_t *>(&m_address);
} // getNative

/**
* @brief Convert a BT address to a string.
* @param [in] capital changes the letter size
* By default the parameter `capital` == false and the string representation of an address is in the format:
* ```
* xx:xx:xx:xx:xx:xx
* ```
* When the parameter `capital` == true the format uses capital letters:
* ```
* XX:XX:XX:XX:XX:XX
* ```
* @return The string representation of the address.
*/
String BTAddress::toString(bool capital) const {
auto size = 18;
char *res = (char *)malloc(size);
if (capital) {
snprintf(res, size, "%02X:%02X:%02X:%02X:%02X:%02X", m_address[0], m_address[1], m_address[2], m_address[3], m_address[4], m_address[5]);
} else {
snprintf(res, size, "%02x:%02x:%02x:%02x:%02x:%02x", m_address[0], m_address[1], m_address[2], m_address[3], m_address[4], m_address[5]);
}
String ret(res);
free(res);
return ret;
} // toString
#endif
38 changes: 38 additions & 0 deletions Firmware/RTK_Everywhere/src/BluetoothSerial/BTAddress.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* BTAddress.h
*
* Created on: Jul 2, 2017
* Author: kolban
* Ported on: Feb 5, 2021
* Author: Thomas M. (ArcticSnowSky)
*/

#ifndef COMPONENTS_CPP_UTILS_BTADDRESS_H_
#define COMPONENTS_CPP_UTILS_BTADDRESS_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BLUEDROID_ENABLED)
#include <esp_gap_bt_api.h> // ESP32 BT
#include <Arduino.h>

/**
* @brief A %BT device address.
*
* Every %BT device has a unique address which can be used to identify it and form connections.
*/
class BTAddress {
public:
BTAddress();
BTAddress(esp_bd_addr_t address);
BTAddress(String stringAddress);
bool equals(BTAddress otherAddress);
operator bool() const;

esp_bd_addr_t *getNative() const;
String toString(bool capital = false) const;

private:
esp_bd_addr_t m_address;
};

#endif /* CONFIG_BT_ENABLED */
#endif /* COMPONENTS_CPP_UTILS_BTADDRESS_H_ */
61 changes: 61 additions & 0 deletions Firmware/RTK_Everywhere/src/BluetoothSerial/BTAdvertisedDevice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* BTAdvertisedDevice.h
*
* Created on: Feb 5, 2021
* Author: Thomas M. (ArcticSnowSky)
*/

#ifndef __BTADVERTISEDDEVICE_H__
#define __BTADVERTISEDDEVICE_H__

#include "BTAddress.h"
#include <string>

class BTAdvertisedDevice {
public:
virtual ~BTAdvertisedDevice() = default;

virtual BTAddress getAddress() = 0;
virtual uint32_t getCOD() const = 0;
virtual std::string getName() const = 0;
virtual int8_t getRSSI() const = 0;

virtual bool haveCOD() const = 0;
virtual bool haveName() const = 0;
virtual bool haveRSSI() const = 0;

virtual std::string toString() = 0;
};

class BTAdvertisedDeviceSet : public virtual BTAdvertisedDevice {
public:
BTAdvertisedDeviceSet();
//~BTAdvertisedDeviceSet() = default;

BTAddress getAddress();
uint32_t getCOD() const;
std::string getName() const;
int8_t getRSSI() const;

bool haveCOD() const;
bool haveName() const;
bool haveRSSI() const;

std::string toString();

void setAddress(BTAddress address);
void setCOD(uint32_t cod);
void setName(std::string name);
void setRSSI(int8_t rssi);

bool m_haveCOD;
bool m_haveName;
bool m_haveRSSI;

BTAddress m_address = BTAddress((uint8_t *)"\0\0\0\0\0\0");
uint32_t m_cod;
std::string m_name;
int8_t m_rssi;
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* BTAdvertisedDeviceSet.cpp
*
* Created on: Feb 5, 2021
* Author: Thomas M. (ArcticSnowSky)
*/

#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BLUEDROID_ENABLED)

//#include <map>

#include "BTAdvertisedDevice.h"
//#include "BTScan.h"

BTAdvertisedDeviceSet::BTAdvertisedDeviceSet() {
m_cod = 0;
m_name = "";
m_rssi = 0;

m_haveCOD = false;
m_haveName = false;
m_haveRSSI = false;
} // BTAdvertisedDeviceSet

BTAddress BTAdvertisedDeviceSet::getAddress() {
return m_address;
}
uint32_t BTAdvertisedDeviceSet::getCOD() const {
return m_cod;
}
std::string BTAdvertisedDeviceSet::getName() const {
return m_name;
}
int8_t BTAdvertisedDeviceSet::getRSSI() const {
return m_rssi;
}

bool BTAdvertisedDeviceSet::haveCOD() const {
return m_haveCOD;
}
bool BTAdvertisedDeviceSet::haveName() const {
return m_haveName;
}
bool BTAdvertisedDeviceSet::haveRSSI() const {
return m_haveRSSI;
}

/**
* @brief Create a string representation of this device.
* @return A string representation of this device.
*/
std::string BTAdvertisedDeviceSet::toString() {
std::string res = "Name: " + getName() + ", Address: " + std::string(getAddress().toString().c_str(), getAddress().toString().length());
if (haveCOD()) {
char val[7]; //6 hex digits + null
snprintf(val, sizeof(val), "%06lx", getCOD() & 0xFFFFFF);
res += ", cod: 0x";
res += val;
}
if (haveRSSI()) {
char val[6];
snprintf(val, sizeof(val), "%d", (int8_t)getRSSI());
res += ", rssi: ";
res += val;
}
return res;
} // toString

void BTAdvertisedDeviceSet::setAddress(BTAddress address) {
m_address = address;
}

void BTAdvertisedDeviceSet::setCOD(uint32_t cod) {
m_cod = cod;
m_haveCOD = true;
}

void BTAdvertisedDeviceSet::setName(std::string name) {
m_name = name;
m_haveName = true;
}

void BTAdvertisedDeviceSet::setRSSI(int8_t rssi) {
m_rssi = rssi;
m_haveRSSI = true;
}

#endif /* CONFIG_BT_ENABLED */
Loading