Merge branch 'post1' into nimble

# Conflicts:
#	docs/software/TODO.md
#	docs/software/nrf52-TODO.md
#	platformio.ini
#	src/esp32/MeshBluetoothService.cpp
This commit is contained in:
geeksville
2020-07-21 11:20:09 -07:00
44 changed files with 16941 additions and 345 deletions

View File

@@ -2,6 +2,7 @@
#include <Arduino.h>
#include <assert.h>
#include "BluetoothCommon.h"
#include "GPS.h"
#include "MeshService.h"
#include "NodeDB.h"
@@ -43,26 +44,20 @@ class BluetoothPhoneAPI : public PhoneAPI
}
};
BluetoothPhoneAPI *bluetoothPhoneAPI;
static BluetoothPhoneAPI *bluetoothPhoneAPI;
class ToRadioCharacteristic : public CallbackCharacteristic
{
public:
ToRadioCharacteristic() : CallbackCharacteristic("f75c76d2-129e-4dad-a1dd-7866124401e7", BLECharacteristic::PROPERTY_WRITE) {}
ToRadioCharacteristic() : CallbackCharacteristic(TORADIO_UUID, BLECharacteristic::PROPERTY_WRITE) {}
void onWrite(BLECharacteristic *c)
{
bluetoothPhoneAPI->handleToRadio(c->getData(), c->getValue().length());
}
void onWrite(BLECharacteristic *c) { bluetoothPhoneAPI->handleToRadio(c->getData(), c->getValue().length()); }
};
class FromRadioCharacteristic : public CallbackCharacteristic
{
public:
FromRadioCharacteristic() : CallbackCharacteristic("8ba2bcc2-ee02-4a55-a531-c525c5e454d5", BLECharacteristic::PROPERTY_READ)
{
}
FromRadioCharacteristic() : CallbackCharacteristic(FROMRADIO_UUID, BLECharacteristic::PROPERTY_READ) {}
void onRead(BLECharacteristic *c)
{
@@ -82,9 +77,8 @@ class FromNumCharacteristic : public CallbackCharacteristic
{
public:
FromNumCharacteristic()
: CallbackCharacteristic("ed9da18c-a800-4f66-a670-aa7547e34453", BLECharacteristic::PROPERTY_WRITE |
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_NOTIFY)
: CallbackCharacteristic(FROMNUM_UUID, BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_NOTIFY)
{
// observe(&service.fromNumChanged);
}
@@ -104,7 +98,7 @@ BLEService *createMeshBluetoothService(BLEServer *server)
}
// Create the BLE Service, we need more than the default of 15 handles
BLEService *service = server->createService(BLEUUID("6ba1b218-15a8-461f-9fa8-5dcae273eafd"), 30, 0);
BLEService *service = server->createService(BLEUUID(MESH_SERVICE_UUID), 30, 0);
assert(!meshFromNumCharacteristic);
meshFromNumCharacteristic = new FromNumCharacteristic;

View File

@@ -0,0 +1,57 @@
#include "WiFiServerAPI.h"
#include "PowerFSM.h"
#include "configuration.h"
#include <Arduino.h>
WiFiServerAPI::WiFiServerAPI(WiFiClient &_client) : StreamAPI(&client), client(_client)
{
DEBUG_MSG("Incoming connection from %s\n", client.remoteIP().toString().c_str());
}
WiFiServerAPI::~WiFiServerAPI()
{
client.stop();
// FIXME - delete this if the client dropps the connection!
}
/// Hookable to find out when connection changes
void WiFiServerAPI::onConnectionChanged(bool connected)
{
// FIXME - we really should be doing global reference counting to see if anyone is currently using serial or wifi and if so,
// block sleep
if (connected) { // To prevent user confusion, turn off bluetooth while using the serial port api
powerFSM.trigger(EVENT_SERIAL_CONNECTED);
} else {
powerFSM.trigger(EVENT_SERIAL_DISCONNECTED);
}
}
void WiFiServerAPI::loop()
{
if (client.connected()) {
StreamAPI::loop();
} else {
DEBUG_MSG("Client dropped connection, closing UDP server\n");
delete this;
}
}
#define MESHTASTIC_PORTNUM 4403
WiFiServerPort::WiFiServerPort() : WiFiServer(MESHTASTIC_PORTNUM) {}
void WiFiServerPort::init()
{
DEBUG_MSG("Listening on TCP port %d\n", MESHTASTIC_PORTNUM);
begin();
}
void WiFiServerPort::loop()
{
auto client = available();
if (client) {
new WiFiServerAPI(client);
}
}

38
src/esp32/WiFiServerAPI.h Normal file
View File

@@ -0,0 +1,38 @@
#pragma once
#include "StreamAPI.h"
#include <WiFi.h>
/**
* Provides both debug printing and, if the client starts sending protobufs to us, switches to send/receive protobufs
* (and starts dropping debug printing - FIXME, eventually those prints should be encapsulated in protobufs).
*/
class WiFiServerAPI : public StreamAPI
{
private:
WiFiClient client;
public:
WiFiServerAPI(WiFiClient &_client);
virtual ~WiFiServerAPI();
virtual void loop(); // Check for dropped client connections
protected:
/// Hookable to find out when connection changes
virtual void onConnectionChanged(bool connected);
};
/**
* Listens for incoming connections and does accepts and creates instances of WiFiServerAPI as needed
*/
class WiFiServerPort : public WiFiServer
{
public:
WiFiServerPort();
void init();
void loop();
};