From ea86f763939bd8a1ed1994b109bbf7c965fc0b30 Mon Sep 17 00:00:00 2001 From: Sacha Weatherstone Date: Sat, 7 May 2022 13:34:06 +1000 Subject: [PATCH] Move LoRa config out of primary channel --- proto | 2 +- sdk-nrfxlib | 1 + src/graphics/Screen.cpp | 65 ++++++++++++++++++------------ src/mesh/Channels.cpp | 26 ++++++------ src/mesh/NodeDB.cpp | 1 + src/mesh/RadioInterface.cpp | 46 ++++++++++----------- src/mesh/generated/admin.pb.c | 1 + src/mesh/generated/channel.pb.c | 1 - src/mesh/generated/channel.pb.h | 58 +++----------------------- src/mesh/generated/config.pb.c | 1 + src/mesh/generated/config.pb.h | 46 +++++++++++++++++---- src/mesh/generated/deviceonly.pb.h | 2 +- src/mesh/generated/mesh.pb.c | 1 - src/modules/AdminModule.cpp | 14 +++---- 14 files changed, 130 insertions(+), 135 deletions(-) create mode 160000 sdk-nrfxlib diff --git a/proto b/proto index 521620ba1..cb8c31bdd 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 521620ba14862d541f85e1eee7445eccb6a6b92a +Subproject commit cb8c31bdd9ff17e3cbc904c86a6caf927b2021c5 diff --git a/sdk-nrfxlib b/sdk-nrfxlib new file mode 160000 index 000000000..e6e02cb83 --- /dev/null +++ b/sdk-nrfxlib @@ -0,0 +1 @@ +Subproject commit e6e02cb83d238fae2f54f084858bd5e49a31afa1 diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 136964006..ac0378ce3 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -31,8 +31,8 @@ along with this program. If not, see . #include "graphics/images.h" #include "main.h" #include "mesh-pb-constants.h" -#include "mesh/generated/deviceonly.pb.h" #include "mesh/Channels.h" +#include "mesh/generated/deviceonly.pb.h" #include "modules/TextMessageModule.h" #include "sleep.h" #include "target_specific.h" @@ -162,21 +162,22 @@ static void drawOEMIconScreen(const char *upperMsg, OLEDDisplay *display, OLEDDi // needs to be drawn relative to x and y // draw centered icon left to right and centered above the one line of app text - display->drawXbm(x + (SCREEN_WIDTH - oemStore.oem_icon_width) / 2, y + (SCREEN_HEIGHT - FONT_HEIGHT_MEDIUM - oemStore.oem_icon_height) / 2 + 2, - oemStore.oem_icon_width, oemStore.oem_icon_height, (const uint8_t *)oemStore.oem_icon_bits.bytes); + display->drawXbm(x + (SCREEN_WIDTH - oemStore.oem_icon_width) / 2, + y + (SCREEN_HEIGHT - FONT_HEIGHT_MEDIUM - oemStore.oem_icon_height) / 2 + 2, oemStore.oem_icon_width, + oemStore.oem_icon_height, (const uint8_t *)oemStore.oem_icon_bits.bytes); - switch(oemStore.oem_font){ - case 0: - display->setFont(FONT_SMALL); + switch (oemStore.oem_font) { + case 0: + display->setFont(FONT_SMALL); break; - case 2: - display->setFont(FONT_LARGE); + case 2: + display->setFont(FONT_LARGE); break; - default: - display->setFont(FONT_MEDIUM); + default: + display->setFont(FONT_MEDIUM); break; } - + display->setTextAlignment(TEXT_ALIGN_LEFT); const char *title = oemStore.oem_text; display->drawString(x + getStringCenteredX(title), y + SCREEN_HEIGHT - FONT_HEIGHT_MEDIUM, title); @@ -816,7 +817,8 @@ void _screen_header() #endif // #ifdef RAK4630 -// Screen::Screen(uint8_t address, int sda, int scl) : OSThread("Screen"), cmdQueue(32), dispdev(address, sda, scl), dispdev_oled(address, sda, scl), ui(&dispdev) +// Screen::Screen(uint8_t address, int sda, int scl) : OSThread("Screen"), cmdQueue(32), dispdev(address, sda, scl), +// dispdev_oled(address, sda, scl), ui(&dispdev) // { // address_found = address; // cmdQueue.setReader(this); @@ -976,7 +978,7 @@ int32_t Screen::runOnce() } // If we have an OEM Boot screen, toggle after 2,5 seconds - if(strlen(oemStore.oem_text) > 0){ + if (strlen(oemStore.oem_text) > 0) { static bool showingOEMBootScreen = true; if (showingOEMBootScreen && (millis() > (2500 + serialSinceMsec))) { DEBUG_MSG("Switch to OEM screen...\n"); @@ -1515,22 +1517,33 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat auto mode = ""; - if (channels.getPrimary().modem_config == 0) { - mode = "VLongSlow"; - } else if (channels.getPrimary().modem_config == 1) { - mode = "LongSlow"; - } else if (channels.getPrimary().modem_config == 2) { - mode = "LongFast"; - } else if (channels.getPrimary().modem_config == 3) { - mode = "MidSlow"; - } else if (channels.getPrimary().modem_config == 4) { - mode = "MidFast"; - } else if (channels.getPrimary().modem_config == 5) { + Config_LoRaConfig &loraConfig = config.payloadVariant.lora_config; + + switch (loraConfig.modem_config) { + case Config_LoRaConfig_ModemConfig_ShortSlow: mode = "ShortSlow"; - } else if (channels.getPrimary().modem_config == 6) { + break; + case Config_LoRaConfig_ModemConfig_ShortFast: mode = "ShortFast"; - } else { + break; + case Config_LoRaConfig_ModemConfig_MidSlow: + mode = "MediumSlow"; + break; + case Config_LoRaConfig_ModemConfig_MidFast: + mode = "MediumFast"; + break; + case Config_LoRaConfig_ModemConfig_LongFast: + mode = "LongFast"; + break; + case Config_LoRaConfig_ModemConfig_LongSlow: + mode = "LongSlow"; + break; + case Config_LoRaConfig_ModemConfig_VLongSlow: + mode = "VLongSlow"; + break; + default: mode = "Custom"; + break; } display->drawString(x + SCREEN_WIDTH - display->getStringWidth(mode), y, mode); diff --git a/src/mesh/Channels.cpp b/src/mesh/Channels.cpp index 2c6c6900d..2b33d7cc0 100644 --- a/src/mesh/Channels.cpp +++ b/src/mesh/Channels.cpp @@ -1,7 +1,7 @@ -#include "configuration.h" #include "Channels.h" #include "CryptoEngine.h" #include "NodeDB.h" +#include "configuration.h" #include @@ -83,10 +83,11 @@ void Channels::initDefaultChannel(ChannelIndex chIndex) { Channel &ch = getByIndex(chIndex); ChannelSettings &channelSettings = ch.settings; + Config_LoRaConfig &loraConfig = config.payloadVariant.lora_config; - channelSettings.modem_config = ChannelSettings_ModemConfig_LongFast; // Default to Long Range & Fast + loraConfig.modem_config = Config_LoRaConfig_ModemConfig_LongFast; // Default to Long Range & Fast - channelSettings.tx_power = 0; // default + loraConfig.tx_power = 0; // default uint8_t defaultpskIndex = 1; channelSettings.psk.bytes[0] = defaultpskIndex; channelSettings.psk.size = 1; @@ -202,6 +203,7 @@ void Channels::setChannel(const Channel &c) const char *Channels::getName(size_t chIndex) { + Config_LoRaConfig &loraConfig = config.payloadVariant.lora_config; // Convert the short "" representation for Default into a usable string const ChannelSettings &channelSettings = getByIndex(chIndex).settings; const char *channelName = channelSettings.name; @@ -209,29 +211,29 @@ const char *Channels::getName(size_t chIndex) // Per mesh.proto spec, if bandwidth is specified we must ignore modemConfig enum, we assume that in that case // the app fucked up and forgot to set channelSettings.name - if (channelSettings.bandwidth != 0) + if (loraConfig.bandwidth != 0) channelName = "Unset"; else - switch (channelSettings.modem_config) { - case ChannelSettings_ModemConfig_ShortSlow: + switch (loraConfig.modem_config) { + case Config_LoRaConfig_ModemConfig_ShortSlow: channelName = "ShortSlow"; break; - case ChannelSettings_ModemConfig_ShortFast: + case Config_LoRaConfig_ModemConfig_ShortFast: channelName = "ShortFast"; break; - case ChannelSettings_ModemConfig_MidSlow: + case Config_LoRaConfig_ModemConfig_MidSlow: channelName = "MediumSlow"; break; - case ChannelSettings_ModemConfig_MidFast: + case Config_LoRaConfig_ModemConfig_MidFast: channelName = "MediumFast"; break; - case ChannelSettings_ModemConfig_LongFast: + case Config_LoRaConfig_ModemConfig_LongFast: channelName = "LongFast"; break; - case ChannelSettings_ModemConfig_LongSlow: + case Config_LoRaConfig_ModemConfig_LongSlow: channelName = "LongSlow"; break; - case ChannelSettings_ModemConfig_VLongSlow: + case Config_LoRaConfig_ModemConfig_VLongSlow: channelName = "VLongSlow"; break; default: diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index a90c271a6..3546650e4 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -210,6 +210,7 @@ void NodeDB::installDefaultDeviceState() installDefaultChannels(); installDefaultRadioConfig(); + installDefaultConfig(); } void NodeDB::init() diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index e4b816b5b..03989bc41 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -76,15 +76,15 @@ const RegionInfo regions[] = { */ RDEF(IN, 865.0f, 867.0f, 100, 0, 30, true, false), - /* - https://rrf.rsm.govt.nz/smart-web/smart/page/-smart/domain/licence/LicenceSummary.wdk?id=219752 - https://iotalliance.org.nz/wp-content/uploads/sites/4/2019/05/IoT-Spectrum-in-NZ-Briefing-Paper.pdf - */ + /* + https://rrf.rsm.govt.nz/smart-web/smart/page/-smart/domain/licence/LicenceSummary.wdk?id=219752 + https://iotalliance.org.nz/wp-content/uploads/sites/4/2019/05/IoT-Spectrum-in-NZ-Briefing-Paper.pdf + */ RDEF(NZ865, 864.0f, 868.0f, 100, 0, 0, true, false), - /* - https://lora-alliance.org/wp-content/uploads/2020/11/lorawan_regional_parameters_v1.0.3reva_0.pdf - */ + /* + https://lora-alliance.org/wp-content/uploads/2020/11/lorawan_regional_parameters_v1.0.3reva_0.pdf + */ RDEF(TH, 920.0f, 925.0f, 100, 0, 16, true, false), /* @@ -183,7 +183,6 @@ uint32_t RadioInterface::getTxDelayMsec() return random((MIN_TX_WAIT_MSEC), (MIN_TX_WAIT_MSEC + shortPacketMsec)); } - /** The delay to use when we want to send something but the ether is busy */ uint32_t RadioInterface::getTxDelayMsecWeighted(float snr) { @@ -210,7 +209,6 @@ uint32_t RadioInterface::getTxDelayMsecWeighted(float snr) DEBUG_MSG("rx_snr found in packet. Setting tx delay:%d\n", delay); } - return delay; } @@ -351,41 +349,41 @@ void RadioInterface::applyModemConfig() { // Set up default configuration // No Sync Words in LORA mode - + Config_LoRaConfig &loraConfig = config.payloadVariant.lora_config; auto channelSettings = channels.getPrimary(); - if (channelSettings.spread_factor == 0) { - switch (channelSettings.modem_config) { - case ChannelSettings_ModemConfig_ShortFast: + if (loraConfig.spread_factor == 0) { + switch (loraConfig.modem_config) { + case Config_LoRaConfig_ModemConfig_ShortFast: bw = 250; cr = 8; sf = 7; break; - case ChannelSettings_ModemConfig_ShortSlow: + case Config_LoRaConfig_ModemConfig_ShortSlow: bw = 250; cr = 8; sf = 8; break; - case ChannelSettings_ModemConfig_MidFast: + case Config_LoRaConfig_ModemConfig_MidFast: bw = 250; cr = 8; sf = 9; break; - case ChannelSettings_ModemConfig_MidSlow: + case Config_LoRaConfig_ModemConfig_MidSlow: bw = 250; cr = 8; sf = 10; break; - case ChannelSettings_ModemConfig_LongFast: + case Config_LoRaConfig_ModemConfig_LongFast: bw = 250; cr = 8; sf = 11; break; - case ChannelSettings_ModemConfig_LongSlow: + case Config_LoRaConfig_ModemConfig_LongSlow: bw = 125; cr = 8; sf = 12; break; - case ChannelSettings_ModemConfig_VLongSlow: + case Config_LoRaConfig_ModemConfig_VLongSlow: bw = 31.25; cr = 8; sf = 12; @@ -394,9 +392,9 @@ void RadioInterface::applyModemConfig() assert(0); // Unknown enum } } else { - sf = channelSettings.spread_factor; - cr = channelSettings.coding_rate; - bw = channelSettings.bandwidth; + sf = loraConfig.spread_factor; + cr = loraConfig.coding_rate; + bw = loraConfig.bandwidth; if (bw == 31) // This parameter is not an integer bw = 31.25; @@ -404,7 +402,7 @@ void RadioInterface::applyModemConfig() bw = 62.5; } - power = channelSettings.tx_power; + power = loraConfig.tx_power; shortPacketMsec = getPacketTime(sizeof(PacketHeader)); assert(myRegion); // Should have been found in init @@ -419,7 +417,7 @@ void RadioInterface::applyModemConfig() saveChannelNum(channel_num); saveFreq(freq); - DEBUG_MSG("Set radio: name=%s, config=%u, ch=%d, power=%d\n", channelName, channelSettings.modem_config, channel_num, power); + DEBUG_MSG("Set radio: name=%s, config=%u, ch=%d, power=%d\n", channelName, loraConfig.modem_config, channel_num, power); DEBUG_MSG("Radio myRegion->freqStart / myRegion->freqEnd: %f -> %f (%f mhz)\n", myRegion->freqStart, myRegion->freqEnd, myRegion->freqEnd - myRegion->freqStart); DEBUG_MSG("Radio myRegion->numChannels: %d\n", numChannels); diff --git a/src/mesh/generated/admin.pb.c b/src/mesh/generated/admin.pb.c index aab68eb8f..954416bde 100644 --- a/src/mesh/generated/admin.pb.c +++ b/src/mesh/generated/admin.pb.c @@ -11,3 +11,4 @@ PB_BIND(AdminMessage, AdminMessage, 2) + diff --git a/src/mesh/generated/channel.pb.c b/src/mesh/generated/channel.pb.c index 6244818fb..0e1dc031d 100644 --- a/src/mesh/generated/channel.pb.c +++ b/src/mesh/generated/channel.pb.c @@ -14,4 +14,3 @@ PB_BIND(Channel, Channel, AUTO) - diff --git a/src/mesh/generated/channel.pb.h b/src/mesh/generated/channel.pb.h index 6a9bc8a20..559085a4a 100644 --- a/src/mesh/generated/channel.pb.h +++ b/src/mesh/generated/channel.pb.h @@ -10,16 +10,6 @@ #endif /* Enum definitions */ -typedef enum _ChannelSettings_ModemConfig { - ChannelSettings_ModemConfig_VLongSlow = 0, - ChannelSettings_ModemConfig_LongSlow = 1, - ChannelSettings_ModemConfig_LongFast = 2, - ChannelSettings_ModemConfig_MidSlow = 3, - ChannelSettings_ModemConfig_MidFast = 4, - ChannelSettings_ModemConfig_ShortSlow = 5, - ChannelSettings_ModemConfig_ShortFast = 6 -} ChannelSettings_ModemConfig; - typedef enum _Channel_Role { Channel_Role_DISABLED = 0, Channel_Role_PRIMARY = 1, @@ -48,28 +38,6 @@ typedef PB_BYTES_ARRAY_T(32) ChannelSettings_psk_t; FIXME: explain how apps use channels for security. explain how remote settings and remote gpio are managed as an example */ typedef struct _ChannelSettings { - /* If zero then, use default max legal continuous power (ie. something that won't - burn out the radio hardware) - In most cases you should use zero here. - Units are in dBm. */ - int8_t tx_power; - /* Note: This is the 'old' mechanism for specifying channel parameters. - Either modem_config or bandwidth/spreading/coding will be specified - NOT BOTH. - As a heuristic: If bandwidth is specified, do not use modem_config. - Because protobufs take ZERO space when the value is zero this works out nicely. - This value is replaced by bandwidth/spread_factor/coding_rate. - If you'd like to experiment with other options add them to MeshRadio.cpp in the device code. */ - ChannelSettings_ModemConfig modem_config; - /* Bandwidth in MHz - Certain bandwidth numbers are 'special' and will be converted to the - appropriate floating point value: 31 -> 31.25MHz */ - ChannelSettings_psk_t psk; - /* A number from 7 to 12. - Indicates number of chirps per symbol as 1<