Files
firmware/src/MeshRadio.h

63 lines
1.9 KiB
C
Raw Normal View History

2020-02-01 08:59:16 -08:00
#pragma once
2020-02-01 11:25:07 -08:00
#include <RH_RF95.h>
#include <RHMesh.h>
#include "MemoryPool.h"
#include "mesh.pb.h"
#include "PointerQueue.h"
2020-02-03 09:13:19 -08:00
#include "MeshTypes.h"
#include "configuration.h"
2020-02-01 11:25:07 -08:00
2020-02-02 13:55:44 -08:00
#define MAX_TX_QUEUE 8 // max number of packets which can be waiting for transmission
2020-02-01 11:25:07 -08:00
/**
* A raw low level interface to our mesh. Only understands nodenums and bytes (not protobufs or node ids)
*/
class MeshRadio {
public:
/** pool is the pool we will alloc our rx packets from
* rxDest is where we will send any rx packets, it becomes receivers responsibility to return packet to the pool
*/
MeshRadio(MemoryPool<MeshPacket> &pool, PointerQueue<MeshPacket> &rxDest);
2020-02-01 11:25:07 -08:00
bool init();
/// Prepare the radio to enter sleep mode, where it should draw only 0.2 uA
void sleep() { rf95.sleep(); }
/// Send a packet (possibly by enquing in a private fifo). This routine will
2020-02-02 13:29:53 -08:00
/// later free() the packet to pool. This routine is not allowed to stall because it is called from
/// bluetooth comms code. If the txmit queue is empty it might return an error
ErrorCode send(MeshPacket *p);
2020-02-01 11:25:07 -08:00
/// Do loop callback operations (we currently FIXME poll the receive mailbox here)
2020-02-01 11:56:32 -08:00
/// for received packets it will call the rx handler
2020-02-01 11:25:07 -08:00
void loop();
/// The radioConfig object just changed, call this to force the hw to change to the new settings
void reloadConfig() { DEBUG_MSG("FIXME add reloadConfig\n"); }
2020-02-01 11:25:07 -08:00
private:
RH_RF95 rf95; // the raw radio interface
2020-02-06 16:07:50 -08:00
RHDatagram manager;
// RHReliableDatagram manager; // don't use mesh yet
// RHMesh manager;
// MeshRXHandler rxHandler;
2020-02-01 11:25:07 -08:00
MemoryPool<MeshPacket> &pool;
PointerQueue<MeshPacket> &rxDest;
PointerQueue<MeshPacket> txQueue;
/// low level send, might block for mutiple seconds
ErrorCode sendTo(NodeNum dest, const uint8_t *buf, size_t len);
2020-02-02 19:08:04 -08:00
/// enqueue a received packet in rxDest
void handleReceive(MeshPacket *p);
};
2020-02-01 11:25:07 -08:00
2020-02-03 11:15:17 -08:00
extern RadioConfig radioConfig;