we now use 13 different channel numbers

This commit is contained in:
geeksville
2020-02-11 11:56:48 -08:00
parent 124c3e2edd
commit 5aaae9c4fe
12 changed files with 171 additions and 66 deletions

View File

@@ -9,8 +9,18 @@
#include "configuration.h"
#include "NodeDB.h"
// Change to 434.0 or other frequency, must match RX's freq! FIXME, choose a better default value
#define RF95_FREQ_US 902.0f
#define DEFAULT_CHANNEL_NUM 3 // we randomly pick one
/**
* ## LoRaWAN for North America
LoRaWAN defines 64, 125 kHz channels from 902.3 to 914.9 MHz increments.
The maximum output power for North America is +30 dBM.
The band is from 902 to 928 MHz. It mentions channel number and its respective channel frequency. All the 13 channels are separated by 2.16 MHz with respect to the adjacent channels.
Channel zero starts at 903.08 MHz center frequency.
*/
MeshRadio::MeshRadio(MemoryPool<MeshPacket> &_pool, PointerQueue<MeshPacket> &_rxDest)
: rf95(NSS_GPIO, DIO0_GPIO),
@@ -20,11 +30,11 @@ MeshRadio::MeshRadio(MemoryPool<MeshPacket> &_pool, PointerQueue<MeshPacket> &_r
txQueue(MAX_TX_QUEUE)
{
//radioConfig.modem_config = RadioConfig_ModemConfig_Bw125Cr45Sf128; // medium range and fast
radioConfig.modem_config = RadioConfig_ModemConfig_Bw500Cr45Sf128; // short range and fast, but wide bandwidth so incompatible radios can talk together
channelSettings.modem_config = ChannelSettings_ModemConfig_Bw500Cr45Sf128; // short range and fast, but wide bandwidth so incompatible radios can talk together
//radioConfig.modem_config = RadioConfig_ModemConfig_Bw125Cr48Sf4096; // slow and long range
radioConfig.tx_power = 23;
radioConfig.center_freq = RF95_FREQ_US; // FIXME, pull this config from flash
channelSettings.tx_power = 23;
channelSettings.channel_num = DEFAULT_CHANNEL_NUM;
}
bool MeshRadio::init()
@@ -63,12 +73,15 @@ void MeshRadio::reloadConfig()
// Set up default configuration
// No Sync Words in LORA mode.
rf95.setModemConfig((RH_RF95::ModemConfigChoice)radioConfig.modem_config); // Radio default
rf95.setModemConfig((RH_RF95::ModemConfigChoice)channelSettings.modem_config); // Radio default
// setModemConfig(Bw125Cr48Sf4096); // slow and reliable?
// rf95.setPreambleLength(8); // Default is 8
assert(channelSettings.channel_num < NUM_CHANNELS); // If the phone tries to tell us to use an illegal channel then panic
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
if (!rf95.setFrequency(radioConfig.center_freq))
float center_freq = CH0 + CH_SPACING * channelSettings.channel_num;
if (!rf95.setFrequency(center_freq))
{
DEBUG_MSG("setFrequency failed\n");
assert(0); // fixme panic
@@ -80,9 +93,9 @@ void MeshRadio::reloadConfig()
// If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
// you can set transmitter powers from 5 to 23 dBm:
// FIXME - can we do this? It seems to be in the Heltec board.
rf95.setTxPower(radioConfig.tx_power, false);
rf95.setTxPower(channelSettings.tx_power, false);
DEBUG_MSG("Set radio: config=%u, freq=%f, txpower=%d\n", radioConfig.modem_config, radioConfig.center_freq, radioConfig.tx_power);
DEBUG_MSG("Set radio: config=%u, ch=%d, txpower=%d\n", channelSettings.modem_config, channelSettings.channel_num, channelSettings.tx_power);
}
ErrorCode MeshRadio::send(MeshPacket *p)