Skip to content

Commit

Permalink
Merge pull request #3836 from ndoo/regulatory-gain
Browse files Browse the repository at this point in the history
Add REGULATORY_GAIN configuration to remain within regulatory ERP limit
  • Loading branch information
caveman99 authored Jun 20, 2024
2 parents 9a80951 + f0a38a5 commit f145b5f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
12 changes: 9 additions & 3 deletions src/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif

// -----------------------------------------------------------------------------
// Regulatory overrides for producing regional builds
// Regulatory overrides
// -----------------------------------------------------------------------------

// Define if region should override user saved region
// #define LORA_REGIONCODE meshtastic_Config_LoRaConfig_RegionCode_SG_923
// Override user saved region, for producing region-locked builds
// #define REGULATORY_LORA_REGIONCODE meshtastic_Config_LoRaConfig_RegionCode_SG_923

// Total system gain in dBm to subtract from Tx power to remain within regulatory ERP limit for non-licensed operators
// This value should be set in variant.h and is PA gain + antenna gain (if system ships with an antenna)
#ifndef REGULATORY_GAIN_LORA
#define REGULATORY_GAIN_LORA 0
#endif

// -----------------------------------------------------------------------------
// Feature toggles
Expand Down
8 changes: 4 additions & 4 deletions src/mesh/RadioInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ static uint8_t bytes[MAX_RHPACKETLEN];
void initRegion()
{
const RegionInfo *r = regions;
#ifdef LORA_REGIONCODE
for (; r->code != meshtastic_Config_LoRaConfig_RegionCode_UNSET && r->code != LORA_REGIONCODE; r++)
#ifdef REGULATORY_LORA_REGIONCODE
for (; r->code != meshtastic_Config_LoRaConfig_RegionCode_UNSET && r->code != REGULATORY_LORA_REGIONCODE; r++)
;
LOG_INFO("Wanted region %d, regulatory override to %s\n", config.lora.region, r->name);
#else
Expand Down Expand Up @@ -478,8 +478,8 @@ void RadioInterface::applyModemConfig()

power = loraConfig.tx_power;

if ((power == 0) || ((power > myRegion->powerLimit) && !devicestate.owner.is_licensed))
power = myRegion->powerLimit;
if ((power == 0) || ((power + REGULATORY_GAIN_LORA > myRegion->powerLimit) && !devicestate.owner.is_licensed))
power = myRegion->powerLimit - REGULATORY_GAIN_LORA;

if (power == 0)
power = 17; // Default to this power level if we don't have a valid regional power limit (powerLimit of myRegion defaults
Expand Down
2 changes: 1 addition & 1 deletion variants/xiao_ble/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
extends = nrf52840_base
board = xiao_ble_sense
board_level = extra
build_flags = ${nrf52840_base.build_flags} -Ivariants/xiao_ble -Ivariants/xiao_ble/softdevice -Ivariants/xiao_ble/softdevice/nrf52 -D EBYTE_E22 -DPRIVATE_HW
build_flags = ${nrf52840_base.build_flags} -Ivariants/xiao_ble -Ivariants/xiao_ble/softdevice -Ivariants/xiao_ble/softdevice/nrf52 -D EBYTE_E22 -DEBYTE_E22_900M30S -DPRIVATE_HW
-L "${platformio.libdeps_dir}/${this.__env__}/bsec2/src/cortex-m4/fpv4-sp-d16-hard"
board_build.ldscript = variants/xiao_ble/nrf52840_s140_v7.ld
build_src_filter = ${nrf52_base.build_src_filter} +<../variants/xiao_ble>
Expand Down
10 changes: 10 additions & 0 deletions variants/xiao_ble/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ static const uint8_t SCK = PIN_SPI_SCK;
// (which is the default for the sx1262interface code)
#define SX126X_DIO2_AS_RF_SWITCH
#define SX126X_DIO3_TCXO_VOLTAGE 1.8
#ifdef EBYTE_E22_900M30S
// 10dB PA gain and 30dB rated output; based on PA output table from Ebyte Robin <[email protected]>
#define REGULATORY_GAIN_LORA 10
#define SX126X_MAX_POWER 20
#endif
#ifdef EBYTE_E22_900M33S
// 25dB PA gain and 33dB rated output; based on TX Power Curve from E22-900M33S_UserManual_EN_v1.0.pdf
#define REGULATORY_GAIN_LORA 25
#define SX126X_MAX_POWER 8
#endif
#endif

/*
Expand Down

0 comments on commit f145b5f

Please sign in to comment.