mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-10 15:12:06 +00:00
Allow advanced users to set arbitrary spreadfactor/codingrate/bandwidth
This commit is contained in:
parent
fce8c16d52
commit
d7cf7e2eb4
2
proto
2
proto
@ -1 +1 @@
|
|||||||
Subproject commit 0523977d1f6c378cf78859044e2edbdba45150fa
|
Subproject commit c715e506df9ab1a76293d1c20dd5c904b009e1ea
|
@ -29,7 +29,7 @@ DeviceState versions used to be defined in the .proto file but really only this
|
|||||||
#define here.
|
#define here.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DEVICESTATE_CUR_VER 10
|
#define DEVICESTATE_CUR_VER 11
|
||||||
#define DEVICESTATE_MIN_VER DEVICESTATE_CUR_VER
|
#define DEVICESTATE_MIN_VER DEVICESTATE_CUR_VER
|
||||||
|
|
||||||
#ifndef NO_ESP32
|
#ifndef NO_ESP32
|
||||||
@ -93,7 +93,7 @@ void NodeDB::resetRadioConfig()
|
|||||||
// so incompatible radios can talk together
|
// so incompatible radios can talk together
|
||||||
channelSettings.modem_config = ChannelSettings_ModemConfig_Bw125Cr48Sf4096; // slow and long range
|
channelSettings.modem_config = ChannelSettings_ModemConfig_Bw125Cr48Sf4096; // slow and long range
|
||||||
|
|
||||||
channelSettings.tx_power = 23;
|
channelSettings.tx_power = 0; // default
|
||||||
memcpy(&channelSettings.psk.bytes, &defaultpsk, sizeof(channelSettings.psk));
|
memcpy(&channelSettings.psk.bytes, &defaultpsk, sizeof(channelSettings.psk));
|
||||||
channelSettings.psk.size = sizeof(defaultpsk);
|
channelSettings.psk.size = sizeof(defaultpsk);
|
||||||
strcpy(channelSettings.name, "Default");
|
strcpy(channelSettings.name, "Default");
|
||||||
|
@ -115,22 +115,26 @@ unsigned long hash(char *str)
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define POWER_DEFAULT 17
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pull our channel settings etc... from protobufs to the dumb interface settings
|
* Pull our channel settings etc... from protobufs to the dumb interface settings
|
||||||
*/
|
*/
|
||||||
void RadioInterface::applyModemConfig()
|
void RadioInterface::applyModemConfig()
|
||||||
{
|
{
|
||||||
// Set up default configuration
|
// Set up default configuration
|
||||||
// No Sync Words in LORA mode.
|
// No Sync Words in LORA mode
|
||||||
modemConfig = (ModemConfigChoice)channelSettings.modem_config;
|
|
||||||
|
power = channelSettings.tx_power;
|
||||||
|
if (power == 0)
|
||||||
|
power = POWER_DEFAULT;
|
||||||
|
|
||||||
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
|
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
|
||||||
int channel_num = hash(channelSettings.name) % NUM_CHANNELS;
|
int channel_num = hash(channelSettings.name) % NUM_CHANNELS;
|
||||||
freq = CH0 + CH_SPACING * channel_num;
|
freq = CH0 + CH_SPACING * channel_num;
|
||||||
power = channelSettings.tx_power;
|
|
||||||
|
|
||||||
DEBUG_MSG("Set radio: name=%s, config=%u, ch=%d, power=%d\n", channelSettings.name, channelSettings.modem_config, channel_num,
|
DEBUG_MSG("Set radio: name=%s, config=%u, ch=%d, power=%d\n", channelSettings.name, channelSettings.modem_config, channel_num,
|
||||||
channelSettings.tx_power);
|
power);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorCode SimRadio::send(MeshPacket *p)
|
ErrorCode SimRadio::send(MeshPacket *p)
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "../concurrency/NotifiedWorkerThread.h"
|
||||||
#include "MemoryPool.h"
|
#include "MemoryPool.h"
|
||||||
#include "MeshTypes.h"
|
#include "MeshTypes.h"
|
||||||
#include "Observer.h"
|
#include "Observer.h"
|
||||||
#include "PointerQueue.h"
|
#include "PointerQueue.h"
|
||||||
#include "../concurrency/NotifiedWorkerThread.h"
|
|
||||||
#include "mesh.pb.h"
|
#include "mesh.pb.h"
|
||||||
|
|
||||||
#define MAX_TX_QUEUE 16 // max number of packets which can be waiting for transmission
|
#define MAX_TX_QUEUE 16 // max number of packets which can be waiting for transmission
|
||||||
@ -31,13 +31,6 @@ typedef struct {
|
|||||||
uint8_t flags;
|
uint8_t flags;
|
||||||
} PacketHeader;
|
} PacketHeader;
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
Bw125Cr45Sf128 = 0, ///< Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Default medium range
|
|
||||||
Bw500Cr45Sf128, ///< Bw = 500 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Fast+short range
|
|
||||||
Bw31_25Cr48Sf512, ///< Bw = 31.25 kHz, Cr = 4/8, Sf = 512chips/symbol, CRC on. Slow+long range
|
|
||||||
Bw125Cr48Sf4096, ///< Bw = 125 kHz, Cr = 4/8, Sf = 4096chips/symbol, CRC on. Slow+long range
|
|
||||||
} ModemConfigChoice;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic operations all radio chipsets must implement.
|
* Basic operations all radio chipsets must implement.
|
||||||
*
|
*
|
||||||
@ -72,9 +65,7 @@ class RadioInterface : protected concurrency::NotifiedWorkerThread
|
|||||||
void deliverToReceiver(MeshPacket *p);
|
void deliverToReceiver(MeshPacket *p);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
float freq = 915.0; // FIXME, init all these params from user setings
|
float freq = 915.0;
|
||||||
int8_t power = 17;
|
|
||||||
ModemConfigChoice modemConfig;
|
|
||||||
|
|
||||||
/** pool is the pool we will alloc our rx packets from
|
/** 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
|
* rxDest is where we will send any rx packets, it becomes receivers responsibility to return packet to the pool
|
||||||
@ -116,6 +107,8 @@ class RadioInterface : protected concurrency::NotifiedWorkerThread
|
|||||||
virtual bool reconfigure() = 0;
|
virtual bool reconfigure() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
int8_t power = 17; // Set by applyModemConfig()
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* given a packet set sendingPacket and decode the protobufs into radiobuf. Returns # of bytes to send (including the
|
* given a packet set sendingPacket and decode the protobufs into radiobuf. Returns # of bytes to send (including the
|
||||||
* PacketHeader & payload).
|
* PacketHeader & payload).
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "RadioLibInterface.h"
|
#include "RadioLibInterface.h"
|
||||||
#include "MeshTypes.h"
|
#include "MeshTypes.h"
|
||||||
|
#include "NodeDB.h"
|
||||||
#include "mesh-pb-constants.h"
|
#include "mesh-pb-constants.h"
|
||||||
#include <configuration.h>
|
#include <configuration.h>
|
||||||
#include <pb_decode.h>
|
#include <pb_decode.h>
|
||||||
@ -64,29 +65,41 @@ void RadioLibInterface::applyModemConfig()
|
|||||||
{
|
{
|
||||||
RadioInterface::applyModemConfig();
|
RadioInterface::applyModemConfig();
|
||||||
|
|
||||||
switch (modemConfig) {
|
if (channelSettings.spread_factor == 0) {
|
||||||
case Bw125Cr45Sf128: ///< Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Default medium range
|
switch (channelSettings.modem_config) {
|
||||||
bw = 125;
|
case ChannelSettings_ModemConfig_Bw125Cr45Sf128: ///< Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Default medium
|
||||||
cr = 5;
|
///< range
|
||||||
sf = 7;
|
bw = 125;
|
||||||
break;
|
cr = 5;
|
||||||
case Bw500Cr45Sf128: ///< Bw = 500 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Fast+short range
|
sf = 7;
|
||||||
bw = 500;
|
break;
|
||||||
cr = 5;
|
case ChannelSettings_ModemConfig_Bw500Cr45Sf128: ///< Bw = 500 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Fast+short
|
||||||
sf = 7;
|
///< range
|
||||||
break;
|
bw = 500;
|
||||||
case Bw31_25Cr48Sf512: ///< Bw = 31.25 kHz, Cr = 4/8, Sf = 512chips/symbol, CRC on. Slow+long range
|
cr = 5;
|
||||||
bw = 31.25;
|
sf = 7;
|
||||||
cr = 8;
|
break;
|
||||||
sf = 9;
|
case ChannelSettings_ModemConfig_Bw31_25Cr48Sf512: ///< Bw = 31.25 kHz, Cr = 4/8, Sf = 512chips/symbol, CRC on. Slow+long
|
||||||
break;
|
///< range
|
||||||
case Bw125Cr48Sf4096:
|
bw = 31.25;
|
||||||
bw = 125;
|
cr = 8;
|
||||||
cr = 8;
|
sf = 9;
|
||||||
sf = 12;
|
break;
|
||||||
break;
|
case ChannelSettings_ModemConfig_Bw125Cr48Sf4096:
|
||||||
default:
|
bw = 125;
|
||||||
assert(0); // Unknown enum
|
cr = 8;
|
||||||
|
sf = 12;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0); // Unknown enum
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sf = channelSettings.spread_factor;
|
||||||
|
cr = channelSettings.coding_rate;
|
||||||
|
bw = channelSettings.bandwidth;
|
||||||
|
|
||||||
|
if (bw == 31) // This parameter is not an integer
|
||||||
|
bw = 31.25;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user