Skip to content
Closed
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
2 changes: 1 addition & 1 deletion Firmware/RTK_Surveyor/Begin.ino
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void pinUART2Task( void *pvParameters )
vTaskDelete( NULL ); //Delete task once it has run once
}

//Serial Read/Write tasks for the F9P must be started after BT is up and running otherwise SerialBT.available will cause reboot
//Serial Read/Write tasks for the F9P must be started after BT is up and running otherwise SerialBT->available will cause reboot
void startUART2Tasks()
{
//Start the tasks for handling incoming and outgoing BT bytes to/from ZED-F9P
Expand Down
3 changes: 3 additions & 0 deletions Firmware/RTK_Surveyor/NVM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ void recordSystemSettingsToFile(File * settingsFile)
settingsFile->printf("%s=%llu\n\r", F("lastKeyAttempt"), settings.lastKeyAttempt);
settingsFile->printf("%s=%d\n\r", F("updateZEDSettings"), settings.updateZEDSettings);
settingsFile->printf("%s=%d\n\r", F("LBandFreq"), settings.LBandFreq);
settingsFile->printf("%s=%d\n\r", F("enableBLE"), settings.enableBLE);

//Record constellation settings
for (int x = 0 ; x < MAX_CONSTELLATIONS ; x++)
Expand Down Expand Up @@ -733,6 +734,8 @@ bool parseLine(char* str, Settings *settings)
}
else if (strcmp(settingName, "LBandFreq") == 0)
settings->LBandFreq = d;
else if (strcmp(settingName, "enableBLE") == 0)
settings->enableBLE = d;

//Check for bulk settings (constellations and message rates)
//Must be last on else list
Expand Down
12 changes: 10 additions & 2 deletions Firmware/RTK_Surveyor/RTK_Surveyor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,17 @@ float battChangeRate = 0.0;
//Hardware serial and BT buffers
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#ifdef COMPILE_BT
// See btSelect.h for implemenation
#include "btSelect.h"
BTSerialInterface * SerialBT;

//We use a local copy of the BluetoothSerial library so that we can increase the RX buffer. See issue: https://github.com/sparkfun/SparkFun_RTK_Firmware/issues/23
#include "src/BluetoothSerial/BluetoothSerial.h"
BluetoothSerial SerialBT;
// #include "src/BluetoothSerial/BluetoothSerial.h"
// BluetoothSerial SerialBT;

// BLE Support originally from https://github.com/avinabmalla/ESP32_BleSerial/tree/bad5ff841800853a61e431ea751f8ea9d7a1df21
// #include "src/BleSerial/BleSerial.h"
// BleSerial SerialBLE;
#endif

char platformPrefix[40] = "Surveyor"; //Sets the prefix for broadcast names
Expand Down
22 changes: 15 additions & 7 deletions Firmware/RTK_Surveyor/System.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ void startBluetooth()

sprintf(deviceName, "%s %s-%02X%02X", platformPrefix, stateName, unitMACAddress[4], unitMACAddress[5]); //Base mode

if (SerialBT.begin(deviceName, false, settings.sppRxQueueSize, settings.sppTxQueueSize) == false) //localName, isMaster, rxBufferSize, txBufferSize
// BLE vs Bluetooth Classic
if (settings.enableBLE)
SerialBT = new BTLESerial();
else
{
SerialBT = new BTClassicSerial();
}

if (SerialBT->begin(deviceName, false, settings.sppRxQueueSize, settings.sppTxQueueSize) == false) //localName, isMaster, rxBufferSize, txBufferSize
{
Serial.println(F("An error occurred initializing Bluetooth"));

Expand Down Expand Up @@ -43,8 +51,8 @@ void startBluetooth()
esp_bt_gap_set_pin(pin_type, 4, pin_code);
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

SerialBT.register_callback(btCallback); //Controls BT Status LED on Surveyor
SerialBT.setTimeout(250);
SerialBT->register_callback(btCallback); //Controls BT Status LED on Surveyor
SerialBT->setTimeout(250);

Serial.print(F("Bluetooth broadcasting as: "));
Serial.println(deviceName);
Expand All @@ -71,10 +79,10 @@ void stopBluetooth()
if (btState == BT_NOTCONNECTED || btState == BT_CONNECTED)
{
#ifdef COMPILE_BT
SerialBT.register_callback(NULL);
SerialBT.flush(); //Complete any transfers
SerialBT.disconnect(); //Drop any clients
SerialBT.end(); //SerialBT.end() will release significant RAM (~100k!) but a SerialBT.start will crash.
SerialBT->register_callback(NULL);
SerialBT->flush(); //Complete any transfers
SerialBT->disconnect(); //Drop any clients
SerialBT->end(); //SerialBT->end() will release significant RAM (~100k!) but a SerialBT->start will crash.
#endif

log_d("Bluetooth turned off");
Expand Down
10 changes: 5 additions & 5 deletions Firmware/RTK_Surveyor/Tasks.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ void F9PSerialWriteTask(void *e)
//Receive RTCM corrections or UBX config messages over bluetooth and pass along to ZED
if (btState == BT_CONNECTED)
{
while (SerialBT.available())
while (SerialBT->available())
{
//Pass bytes to GNSS receiver
auto s = SerialBT.readBytes(wBuffer, sizeof(wBuffer));
auto s = SerialBT->readBytes(wBuffer, sizeof(wBuffer));
serialGNSS.write(wBuffer, s);

if (settings.enableTaskReports == true)
Expand Down Expand Up @@ -49,13 +49,13 @@ void F9PSerialReadTask(void *e)
#ifdef COMPILE_BT
else if (btState == BT_CONNECTED)
{
if (SerialBT.isCongested() == false)
if (SerialBT->isCongested() == false)
{
SerialBT.write(rBuffer, s); //Push new data to BT SPP
SerialBT->write(rBuffer, s); //Push new data to BT SPP
}
else if (settings.throttleDuringSPPCongestion == false)
{
SerialBT.write(rBuffer, s); //Push new data to SPP regardless of congestion
SerialBT->write(rBuffer, s); //Push new data to SPP regardless of congestion
}
else
{
Expand Down
161 changes: 161 additions & 0 deletions Firmware/RTK_Surveyor/btSelect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#ifdef COMPILE_BT

#include "src/BluetoothSerial/BluetoothSerial.h"
#include "src/BleSerial/BleSerial.h"

class BTSerialInterface
{
public:
virtual bool begin(String deviceName, bool isMaster, 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;
virtual void setTimeout(unsigned long timeout) = 0;

virtual int available() = 0;
virtual size_t readBytes(uint8_t *buffer, size_t bufferSize) = 0;

virtual bool isCongested() = 0;
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
virtual void flush() = 0;
};


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)
{
return BluetoothSerial::begin(deviceName, isMaster, rxQueueSize, txQueueSize);
}

void disconnect()
{
BluetoothSerial::disconnect();
}

void end()
{
BluetoothSerial::end();
}

esp_err_t register_callback(esp_spp_cb_t * callback)
{
return BluetoothSerial::register_callback(callback);
}

void setTimeout(unsigned long timeout)
{
BluetoothSerial::setTimeout(timeout);
}

int available()
{
return BluetoothSerial::available();
}

size_t readBytes(uint8_t *buffer, size_t bufferSize)
{
return BluetoothSerial::readBytes(buffer, bufferSize);
}

bool isCongested()
{
return BluetoothSerial::isCongested();
}

size_t write(const uint8_t *buffer, size_t size)
{
return BluetoothSerial::write(buffer, size);
}

void flush()
{
BluetoothSerial::flush();
}
};


class BTLESerial: public virtual BTSerialInterface, public BleSerial
{
public:
// Missing from BleSerial
bool begin(String deviceName, bool isMaster, uint16_t rxQueueSuze, uint16_t txQueueSize)
{
// Curretnly ignoring rxQueueSize
// transmitBufferLength = txQueueSize;
BleSerial::begin(deviceName.c_str());
return true;
}

void disconnect()
{
Server->disconnect(Server->getConnId());
}

void end()
{
BleSerial::end();
}

esp_err_t register_callback(esp_spp_cb_t * callback)
{
connectionCallback = callback;
return ESP_OK;
}

void setTimeout(unsigned long timeout)
{
BleSerial::setTimeout(timeout);
}

int available()
{
return BleSerial::available();
}

size_t readBytes(uint8_t *buffer, size_t bufferSize)
{
return BleSerial::readBytes(buffer, bufferSize);
}

bool isCongested()
{
// not currently supported in this implementation
return false;
}

size_t write(const uint8_t *buffer, size_t size)
{
return BleSerial::write(buffer, size);
}

void flush()
{
BleSerial::flush();
}

// override BLEServerCallbacks
void onConnect(BLEServer *pServer)
{
bleConnected = true;
connectionCallback(ESP_SPP_SRV_OPEN_EVT, nullptr);
}

void onDisconnect(BLEServer *pServer)
{
bleConnected = false;
connectionCallback(ESP_SPP_CLOSE_EVT, nullptr);
Server->startAdvertising();
}

private:
esp_spp_cb_t * connectionCallback;

};



#endif
45 changes: 45 additions & 0 deletions Firmware/RTK_Surveyor/menuBluetooth.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
void menuBluetooth()
{
while (1)
{
Serial.println();
Serial.println(F("Menu: Blueooth Menu"));

Serial.println();
Serial.print(F("Current Bluetooth Mode: "));
if (settings.enableBLE == true)
Serial.println(F("BLE"));
else
Serial.println(F("Classic"));

Serial.println();
Serial.println(F("1) Set Bluetooth Mode to Classic"));
Serial.println(F("2) Set Bluetooth Mode to BLE"));
Serial.println(F("x) Exit"));

byte incoming = getByteChoice(menuTimeout);
if (incoming == '1')
{
// Restart Bluetooth
stopBluetooth();
settings.enableBLE = false;
startBluetooth();
}
else if (incoming == '2')
{
// restart Bluetooth
stopBluetooth();
settings.enableBLE = true;
startBluetooth();
}
else if (incoming == 'x')
break;
else if (incoming == STATUS_GETBYTE_TIMEOUT)
break;
else
printUnknown(incoming);
}

while (Serial.available()) Serial.read();
}

4 changes: 4 additions & 0 deletions Firmware/RTK_Surveyor/menuMain.ino
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ void menuMain()

Serial.println(F("5) Configure Logging"));

Serial.println(F("6) Configure Bluetooth"));

Serial.println(F("p) Configure Profiles"));

if (online.lband == true)
Expand All @@ -72,6 +74,8 @@ void menuMain()
menuPorts();
else if (incoming == '5')
menuLog();
else if (incoming == '6')
menuBluetooth();
else if (incoming == 's')
menuSystem();
else if (incoming == 'p')
Expand Down
2 changes: 2 additions & 0 deletions Firmware/RTK_Surveyor/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ typedef struct {
pulseEdgeType_e externalPulsePolarity = PULSE_RISING_EDGE; //Pulse rises for pulse length, then falls
bool enableExternalHardwareEventLogging = false; //Log when INT/TM2 pin goes low

bool enableBLE = false;

ubxMsg ubxMessages[MAX_UBX_MSG] = //Report rates for all known messages
{
//NMEA
Expand Down
Loading