begin adding rx from radio handling

This commit is contained in:
geeksville
2020-02-02 09:59:00 -08:00
parent 5dca838ba3
commit 4051bf8465
14 changed files with 155 additions and 34 deletions

View File

@@ -9,6 +9,8 @@
#include <pb_decode.h>
#include "mesh.pb.h"
#include "MeshRadio.h"
#include "TypedQueue.h"
#include "MemoryPool.h"
/*
receivedPacketQueue - this is a queue of messages we've received from the mesh, which we are keeping to deliver to the phone.
@@ -53,6 +55,9 @@ public:
*/
#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
/// A temporary buffer used for sending packets, sized to hold the biggest buffer we might need
static uint8_t outbuf[MeshPacket_size];
@@ -62,7 +67,45 @@ static uint8_t outbuf[MeshPacket_size];
*/
class MeshService
{
MemoryPool<MeshPacket> packetPool;
/// 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
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;
public:
MeshService() : packetPool(MAX_PACKETS), toPhoneQueue(MAX_RX_TOPHONE) {
}
/// Do idle processing (mostly processing messages which have been queued from the radio)
// void loop() { }
/**
* handle an incoming MeshPacket from the radio, update DB state and queue it for the phone
*/
void handleFromRadio(NodeNum from, NodeNum to, const uint8_t *buf, size_t len) {
MeshPacket *p = packetPool.allocZeroed();
assert(p);
pb_istream_t stream = pb_istream_from_buffer(buf, len);
if (!pb_decode(&stream, MeshPacket_fields, p) || !p->has_payload)
{
Serial.printf("Error: can't decode MeshPacket %s\n", PB_GET_ERROR(&stream));
}
else
{
// FIXME - update DB state based on payload and show recevied texts
toPhoneQueue.enqueue(p);
}
}
/// Given a ToRadio buffer parse it and properly handle it (setup radio, owner or send packet into the mesh)
void handleToRadio(std::string s)
{