2020-02-01 16:59:16 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-02-19 04:06:01 +00:00
|
|
|
#include "CustomRF95.h"
|
2020-02-02 20:45:32 +00:00
|
|
|
#include "MemoryPool.h"
|
2020-02-03 17:13:19 +00:00
|
|
|
#include "MeshTypes.h"
|
2020-04-14 18:40:49 +00:00
|
|
|
#include "Observer.h"
|
2020-03-19 02:15:51 +00:00
|
|
|
#include "PointerQueue.h"
|
2020-02-04 16:17:44 +00:00
|
|
|
#include "configuration.h"
|
2020-03-19 02:15:51 +00:00
|
|
|
#include "mesh.pb.h"
|
2020-02-01 19:25:07 +00:00
|
|
|
|
2020-02-11 19:56:48 +00:00
|
|
|
// US channel settings
|
2020-03-19 02:15:51 +00:00
|
|
|
#define CH0_US 903.08f // MHz
|
|
|
|
#define CH_SPACING_US 2.16f // MHz
|
2020-02-19 00:18:01 +00:00
|
|
|
#define NUM_CHANNELS_US 13
|
|
|
|
|
2020-03-12 06:05:11 +00:00
|
|
|
// EU433 channel settings
|
2020-03-19 02:15:51 +00:00
|
|
|
#define CH0_EU433 433.175f // MHz
|
|
|
|
#define CH_SPACING_EU433 0.2f // MHz
|
2020-03-12 06:05:11 +00:00
|
|
|
#define NUM_CHANNELS_EU433 8
|
|
|
|
|
|
|
|
// EU865 channel settings
|
2020-03-19 02:15:51 +00:00
|
|
|
#define CH0_EU865 865.2f // MHz
|
|
|
|
#define CH_SPACING_EU865 0.3f // MHz
|
2020-03-12 06:05:11 +00:00
|
|
|
#define NUM_CHANNELS_EU865 10
|
2020-02-19 00:18:01 +00:00
|
|
|
|
|
|
|
// CN channel settings
|
2020-03-19 02:15:51 +00:00
|
|
|
#define CH0_CN 470.0f // MHz
|
|
|
|
#define CH_SPACING_CN 2.0f // MHz FIXME, this is just a guess for 470-510
|
2020-02-19 00:18:01 +00:00
|
|
|
#define NUM_CHANNELS_CN 20
|
|
|
|
|
2020-03-11 02:33:16 +00:00
|
|
|
// JP channel settings
|
2020-03-19 02:15:51 +00:00
|
|
|
#define CH0_JP 920.0f // MHz
|
|
|
|
#define CH_SPACING_JP 0.5f // MHz FIXME, this is just a guess for 920-925
|
2020-02-19 00:18:01 +00:00
|
|
|
#define NUM_CHANNELS_JP 10
|
2020-02-11 19:56:48 +00:00
|
|
|
|
|
|
|
// FIXME add defs for other regions and use them here
|
2020-02-19 00:18:01 +00:00
|
|
|
#ifdef HW_VERSION_US
|
2020-02-11 19:56:48 +00:00
|
|
|
#define CH0 CH0_US
|
|
|
|
#define CH_SPACING CH_SPACING_US
|
2020-02-19 00:18:01 +00: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-19 00:18:01 +00: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"
|
2020-03-19 02:15:51 +00:00
|
|
|
#endif
|
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)
|
|
|
|
*/
|
2020-03-19 02:15:51 +00:00
|
|
|
class MeshRadio
|
|
|
|
{
|
|
|
|
public:
|
2020-04-01 04:56:35 +00:00
|
|
|
// Kinda ugly way of selecting different radio implementations, but soon this MeshRadio class will be going away
|
|
|
|
// entirely. At that point we can make things pretty.
|
|
|
|
#ifdef RF95_IRQ_GPIO
|
2020-03-19 02:15:51 +00:00
|
|
|
CustomRF95
|
2020-04-01 04:56:35 +00:00
|
|
|
radioIf; // the raw radio interface - for now I'm leaving public - because this class is shrinking to be almost nothing
|
|
|
|
#else
|
|
|
|
SimRadio radioIf;
|
|
|
|
#endif
|
2020-02-21 16:09:07 +00:00
|
|
|
|
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();
|
|
|
|
|
|
|
|
/// 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-03-19 02:15:51 +00:00
|
|
|
private:
|
2020-03-24 20:04:28 +00:00
|
|
|
/// Used for the tx timer watchdog, to check for bugs in our transmit code, msec of last time we did a send
|
|
|
|
uint32_t lastTxStart = 0;
|
2020-04-14 18:40:49 +00:00
|
|
|
|
|
|
|
CallbackObserver<MeshRadio, void *> configChangedObserver =
|
|
|
|
CallbackObserver<MeshRadio, void *>(this, &MeshRadio::reloadConfig);
|
|
|
|
|
|
|
|
CallbackObserver<MeshRadio, void *> preflightSleepObserver =
|
|
|
|
CallbackObserver<MeshRadio, void *>(this, &MeshRadio::preflightSleepCb);
|
|
|
|
|
|
|
|
CallbackObserver<MeshRadio, void *> notifyDeepSleepObserver =
|
|
|
|
CallbackObserver<MeshRadio, void *>(this, &MeshRadio::notifyDeepSleepDb);
|
|
|
|
|
|
|
|
CallbackObserver<MeshRadio, MeshPacket *> sendPacketObserver; /* =
|
|
|
|
CallbackObserver<MeshRadio, MeshPacket *>(this, &MeshRadio::send); */
|
|
|
|
|
|
|
|
/// Send a packet (possibly by enquing in a private fifo). This routine will
|
|
|
|
/// 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.
|
|
|
|
///
|
|
|
|
/// Returns 1 for success or 0 for failure (and if we fail it is the _callers_ responsibility to free the packet)
|
|
|
|
int send(MeshPacket *p);
|
|
|
|
|
|
|
|
/// The radioConfig object just changed, call this to force the hw to change to the new settings
|
|
|
|
int reloadConfig(void *unused = NULL);
|
|
|
|
|
|
|
|
/// Return 0 if sleep is okay
|
|
|
|
int preflightSleepCb(void *unused = NULL) { return radioIf.canSleep() ? 0 : 1; }
|
|
|
|
|
|
|
|
int notifyDeepSleepDb(void *unused = NULL)
|
|
|
|
{
|
|
|
|
radioIf.sleep();
|
|
|
|
return 0;
|
|
|
|
}
|
2020-02-02 20:45:32 +00:00
|
|
|
};
|