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>
|
|
|
|
|
|
|
|
#define NODENUM_BROADCAST 255
|
2020-02-02 02:45:27 +00:00
|
|
|
#define ERRNO_OK 0
|
|
|
|
#define ERRNO_UNKNOWN 32 // pick something that doesn't conflict with RH_ROUTER_ERROR_UNABLE_TO_DELIVER
|
2020-02-01 19:25:07 +00:00
|
|
|
|
|
|
|
typedef int ErrorCode;
|
|
|
|
typedef uint8_t NodeNum;
|
|
|
|
|
2020-02-02 17:59:00 +00:00
|
|
|
/// Callback for a receive packet, the callee must copy/queue the payload elsewhere before returning
|
|
|
|
typedef void (*MeshRXHandler)(NodeNum from, NodeNum to, const uint8_t *buf, size_t len);
|
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:
|
|
|
|
MeshRadio();
|
|
|
|
|
|
|
|
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
|
|
|
|
void sleep() { rf95.sleep(); }
|
|
|
|
|
2020-02-01 19:25:07 +00:00
|
|
|
/// Send a packet - the current implementation blocks for a while possibly (FIXME)
|
|
|
|
ErrorCode sendTo(NodeNum dest, const uint8_t *buf, size_t len);
|
|
|
|
|
|
|
|
/// 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-01 19:56:32 +00:00
|
|
|
void setRXHandler(MeshRXHandler h) { rxHandler = h; }
|
2020-02-01 19:25:07 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
RH_RF95 rf95; // the raw radio interface
|
|
|
|
RHMesh manager;
|
2020-02-01 19:56:32 +00:00
|
|
|
MeshRXHandler rxHandler;
|
2020-02-01 19:25:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern MeshRadio radio;
|
|
|
|
|
2020-02-01 16:59:16 +00:00
|
|
|
void mesh_init();
|
|
|
|
void mesh_loop();
|