we now BLE notify for the arrival of new messages

This commit is contained in:
geeksville
2020-02-02 20:54:40 -08:00
parent 882b6bd655
commit e6535f5504
7 changed files with 50 additions and 10 deletions

View File

@@ -14,6 +14,14 @@ static BLECharacteristic meshFromRadioCharacteristic("8ba2bcc2-ee02-4a55-a531-c5
static BLECharacteristic meshToRadioCharacteristic("f75c76d2-129e-4dad-a1dd-7866124401e7", BLECharacteristic::PROPERTY_WRITE);
static BLECharacteristic meshFromNumCharacteristic("ed9da18c-a800-4f66-a670-aa7547e34453", BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY);
/**
* Tell any bluetooth clients that the number of rx packets has changed
*/
void bluetoothNotifyFromNum(uint32_t newValue) {
meshFromNumCharacteristic.setValue(newValue);
meshFromNumCharacteristic.notify();
}
class BluetoothMeshCallbacks : public BLECharacteristicCallbacks
{
void onRead(BLECharacteristic *c)

View File

@@ -1,6 +1,12 @@
#pragma once
#include <BLEService.h>
#include <BLEServer.h>
#include <Arduino.h>
BLEService *createMeshBluetoothService(BLEServer* server);
/**
* Tell any bluetooth clients that the number of rx packets has changed
*/
void bluetoothNotifyFromNum(uint32_t newValue);

View File

@@ -6,6 +6,7 @@
#include <pb_decode.h>
#include "mesh.pb.h"
#include "MeshService.h"
#include "MeshBluetoothService.h"
/*
receivedPacketQueue - this is a queue of messages we've received from the mesh, which we are keeping to deliver to the phone.
@@ -50,8 +51,14 @@ MeshService service;
#define MAX_PACKETS 32 // max number of packets which can be in flight (either queued from reception or queued for sending)
#define MAX_RX_TOPHONE 16 // max number of packets which can be waiting for delivery to android
#define MAX_RX_FROMRADIO 4 // max number of packets destined to our queue, we dispatch packets quickly so it doesn't need to be big
MeshService::MeshService() : packetPool(MAX_PACKETS), toPhoneQueue(MAX_RX_TOPHONE), radio(packetPool, toPhoneQueue)
MeshService::MeshService()
: packetPool(MAX_PACKETS),
toPhoneQueue(MAX_RX_TOPHONE),
fromRadioQueue(MAX_RX_FROMRADIO),
fromNum(0),
radio(packetPool, fromRadioQueue)
{
}
@@ -65,6 +72,19 @@ void MeshService::init()
void MeshService::loop()
{
radio.loop(); // FIXME, possibly move radio interaction to own thread
MeshPacket *mp;
uint32_t oldFromNum = fromNum;
while((mp = fromRadioQueue.dequeuePtr(0)) != NULL) {
// FIXME, process the packet locally to update our node DB, update the LCD screen etc...
Serial.printf("FIXME, skipping local processing of fromRadio\n");
fromNum++;
assert(toPhoneQueue.enqueue(mp , 0) == pdTRUE); // FIXME, instead of failing for full queue, delete the oldest mssages
}
if(oldFromNum != fromNum) // We don't want to generate extra notifies for multiple new packets
bluetoothNotifyFromNum(fromNum);
}
/// Given a ToRadio buffer parse it and properly handle it (setup radio, owner or send packet into the mesh)

View File

@@ -19,11 +19,15 @@ class MeshService
/// received packets waiting for the phone to process them
/// FIXME, change to a DropOldestQueue and keep a count of the number of dropped packets to ensure
/// we never hang because android hasn't been there in a while
/// FIXME - save this to flash on deep sleep
PointerQueue<MeshPacket> toPhoneQueue;
/// Packets which have just arrived from the radio, ready to be processed by this service and possibly
/// forwarded to the phone. Note: not using yet - seeing if I can just handle everything asap in handleFromRadio
// PointerQueue<MeshPacket> fromRadioQueue;
/// forwarded to the phone.
PointerQueue<MeshPacket> fromRadioQueue;
/// The current nonce for the newest packet which has been queued for the phone
uint32_t fromNum;
public: