2020-02-01 16:59:16 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-02-01 19:25:07 +00:00
|
|
|
#include <RH_RF95.h>
|
|
|
|
#include <RHMesh.h>
|
2020-02-02 20:45:32 +00:00
|
|
|
#include "MemoryPool.h"
|
|
|
|
#include "mesh.pb.h"
|
|
|
|
#include "PointerQueue.h"
|
2020-02-03 17:13:19 +00:00
|
|
|
#include "MeshTypes.h"
|
2020-02-04 16:17:44 +00:00
|
|
|
#include "configuration.h"
|
2020-02-01 19:25:07 +00:00
|
|
|
|
2020-02-11 19:56:48 +00:00
|
|
|
// US channel settings
|
|
|
|
#define CH0_US 903.08f // MHz
|
|
|
|
#define CH_SPACING_US 2.16f // MHz
|
|
|
|
#define NUM_CHANNELS_US 13
|
|
|
|
|
|
|
|
// FIXME add defs for other regions and use them here
|
|
|
|
#define CH0 CH0_US
|
|
|
|
#define CH_SPACING CH_SPACING_US
|
|
|
|
#define NUM_CHANNELS NUM_CHANNELS_US
|
2020-02-01 19:25:07 +00:00
|
|
|
|
|
|
|
|
2020-02-02 21:55:44 +00:00
|
|
|
#define MAX_TX_QUEUE 8 // max number of packets which can be waiting for transmission
|
2020-02-02 20:45:32 +00:00
|
|
|
|
2020-02-01 19:25:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A raw low level interface to our mesh. Only understands nodenums and bytes (not protobufs or node ids)
|
|
|
|
*/
|
|
|
|
class MeshRadio {
|
|
|
|
public:
|
2020-02-02 20:45:32 +00:00
|
|
|
/** 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 19:25:07 +00:00
|
|
|
|
|
|
|
bool init();
|
|
|
|
|
2020-02-02 03:09:17 +00:00
|
|
|
/// Prepare the radio to enter sleep mode, where it should draw only 0.2 uA
|
2020-02-12 16:44:31 +00:00
|
|
|
void sleep();
|
2020-02-02 03:09:17 +00:00
|
|
|
|
2020-02-02 20:45:32 +00:00
|
|
|
/// Send a packet (possibly by enquing in a private fifo). This routine will
|
2020-02-02 21:29:53 +00: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
|
2020-02-02 20:45:32 +00:00
|
|
|
ErrorCode send(MeshPacket *p);
|
2020-02-01 19:25:07 +00:00
|
|
|
|
|
|
|
/// Do loop callback operations (we currently FIXME poll the receive mailbox here)
|
2020-02-01 19:56:32 +00:00
|
|
|
/// for received packets it will call the rx handler
|
2020-02-01 19:25:07 +00:00
|
|
|
void loop();
|
|
|
|
|
2020-02-04 05:17:35 +00:00
|
|
|
/// The radioConfig object just changed, call this to force the hw to change to the new settings
|
2020-02-07 06:57:58 +00:00
|
|
|
void reloadConfig();
|
2020-02-04 05:17:35 +00:00
|
|
|
|
2020-02-01 19:25:07 +00:00
|
|
|
private:
|
|
|
|
RH_RF95 rf95; // the raw radio interface
|
2020-02-07 00:07:50 +00:00
|
|
|
|
2020-02-07 05:47:22 +00:00
|
|
|
// RHDatagram manager;
|
2020-02-07 00:07:50 +00:00
|
|
|
// RHReliableDatagram manager; // don't use mesh yet
|
2020-02-07 05:47:22 +00:00
|
|
|
RHMesh manager;
|
2020-02-02 20:45:32 +00:00
|
|
|
// MeshRXHandler rxHandler;
|
2020-02-01 19:25:07 +00:00
|
|
|
|
2020-02-02 20:45:32 +00: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-03 03:08:04 +00:00
|
|
|
|
|
|
|
/// enqueue a received packet in rxDest
|
|
|
|
void handleReceive(MeshPacket *p);
|
2020-02-02 20:45:32 +00:00
|
|
|
};
|
2020-02-01 19:25:07 +00:00
|
|
|
|
2020-02-07 17:36:15 +00:00
|
|
|
|