2020-02-01 08:59:16 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-02-18 20:06:01 -08:00
|
|
|
#include "CustomRF95.h"
|
2020-02-01 11:25:07 -08:00
|
|
|
#include <RHMesh.h>
|
2020-02-02 12:45:32 -08:00
|
|
|
#include "MemoryPool.h"
|
|
|
|
|
#include "mesh.pb.h"
|
|
|
|
|
#include "PointerQueue.h"
|
2020-02-03 09:13:19 -08:00
|
|
|
#include "MeshTypes.h"
|
2020-02-04 08:17:44 -08:00
|
|
|
#include "configuration.h"
|
2020-02-01 11:25:07 -08:00
|
|
|
|
2020-02-11 11:56:48 -08:00
|
|
|
// US channel settings
|
|
|
|
|
#define CH0_US 903.08f // MHz
|
|
|
|
|
#define CH_SPACING_US 2.16f // MHz
|
2020-02-18 16:18:01 -08:00
|
|
|
#define NUM_CHANNELS_US 13
|
|
|
|
|
|
2020-03-12 06:05:11 +00:00
|
|
|
// EU433 channel settings
|
|
|
|
|
#define CH0_EU433 433.175f // MHz
|
|
|
|
|
#define CH_SPACING_EU433 0.2f // MHz
|
|
|
|
|
#define NUM_CHANNELS_EU433 8
|
|
|
|
|
|
|
|
|
|
// EU865 channel settings
|
|
|
|
|
#define CH0_EU865 865.2f // MHz
|
|
|
|
|
#define CH_SPACING_EU865 0.3f // MHz
|
|
|
|
|
#define NUM_CHANNELS_EU865 10
|
2020-02-18 16:18:01 -08:00
|
|
|
|
|
|
|
|
// CN channel settings
|
2020-02-20 12:49:34 -08:00
|
|
|
#define CH0_CN 470.0f // MHz
|
2020-02-18 16:18:01 -08:00
|
|
|
#define CH_SPACING_CN 2.0f // MHz FIXME, this is just a guess for 470-510
|
|
|
|
|
#define NUM_CHANNELS_CN 20
|
|
|
|
|
|
2020-03-10 19:33:16 -07:00
|
|
|
// JP channel settings
|
2020-02-20 12:49:34 -08:00
|
|
|
#define CH0_JP 920.0f // MHz
|
2020-02-18 16:18:01 -08:00
|
|
|
#define CH_SPACING_JP 0.5f // MHz FIXME, this is just a guess for 920-925
|
|
|
|
|
#define NUM_CHANNELS_JP 10
|
2020-02-11 11:56:48 -08:00
|
|
|
|
|
|
|
|
// FIXME add defs for other regions and use them here
|
2020-02-18 16:18:01 -08:00
|
|
|
#ifdef HW_VERSION_US
|
2020-02-11 11:56:48 -08:00
|
|
|
#define CH0 CH0_US
|
|
|
|
|
#define CH_SPACING CH_SPACING_US
|
2020-02-18 16:18:01 -08:00
|
|
|
#define NUM_CHANNELS NUM_CHANNELS_US
|
2020-03-12 06:05:11 +00:00
|
|
|
#elif defined(HW_VERSION_EU433)
|
|
|
|
|
#define CH0 CH0_EU433
|
|
|
|
|
#define CH_SPACING CH_SPACING_EU433
|
|
|
|
|
#define NUM_CHANNELS NUM_CHANNELS_EU433
|
|
|
|
|
#elif defined(HW_VERSION_EU865)
|
|
|
|
|
#define CH0 CH0_EU865
|
|
|
|
|
#define CH_SPACING CH_SPACING_EU865
|
|
|
|
|
#define NUM_CHANNELS NUM_CHANNELS_EU865
|
2020-02-18 16:18:01 -08:00
|
|
|
#elif defined(HW_VERSION_CN)
|
|
|
|
|
#define CH0 CH0_CN
|
|
|
|
|
#define CH_SPACING CH_SPACING_CN
|
|
|
|
|
#define NUM_CHANNELS NUM_CHANNELS_CN
|
|
|
|
|
#elif defined(HW_VERSION_JP)
|
|
|
|
|
#define CH0 CH0_JP
|
|
|
|
|
#define CH_SPACING CH_SPACING_JP
|
|
|
|
|
#define NUM_CHANNELS NUM_CHANNELS_JP
|
|
|
|
|
#else
|
|
|
|
|
#error "HW_VERSION not set"
|
|
|
|
|
#endif
|
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:
|
2020-02-21 08:09:07 -08:00
|
|
|
CustomRF95 rf95; // the raw radio interface - for now I'm leaving public - because this class is shrinking to be almost nothing
|
|
|
|
|
|
2020-02-02 12:45:32 -08: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 11:25:07 -08:00
|
|
|
|
|
|
|
|
bool init();
|
|
|
|
|
|
2020-02-02 12:45:32 -08:00
|
|
|
/// 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
|
2020-02-02 12:45:32 -08:00
|
|
|
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();
|
|
|
|
|
|
2020-02-03 21:17:35 -08:00
|
|
|
/// The radioConfig object just changed, call this to force the hw to change to the new settings
|
2020-02-06 22:57:58 -08:00
|
|
|
void reloadConfig();
|
2020-02-03 21:17:35 -08:00
|
|
|
|
2020-02-01 11:25:07 -08:00
|
|
|
private:
|
2020-02-06 16:07:50 -08:00
|
|
|
|
2020-02-06 21:47:22 -08:00
|
|
|
// RHDatagram manager;
|
2020-02-06 16:07:50 -08:00
|
|
|
// RHReliableDatagram manager; // don't use mesh yet
|
2020-02-06 21:47:22 -08:00
|
|
|
RHMesh manager;
|
2020-02-02 12:45:32 -08:00
|
|
|
// MeshRXHandler rxHandler;
|
2020-02-01 11:25:07 -08:00
|
|
|
|
2020-02-02 12:45:32 -08:00
|
|
|
/// 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-02 12:45:32 -08:00
|
|
|
};
|
2020-02-01 11:25:07 -08:00
|
|
|
|
2020-02-07 09:36:15 -08:00
|
|
|
|