From c6d93d1a28518e06eeef7cd33ca69975a132cce3 Mon Sep 17 00:00:00 2001 From: geeksville Date: Tue, 15 Sep 2020 18:54:50 -0700 Subject: [PATCH] fix #346 limit tx power in japan --- src/mesh/RF95Interface.cpp | 2 ++ src/mesh/RadioInterface.cpp | 19 +++++++++++++++++++ src/mesh/RadioInterface.h | 6 ++++++ src/mesh/SX1262Interface.cpp | 3 +++ 4 files changed, 30 insertions(+) diff --git a/src/mesh/RF95Interface.cpp b/src/mesh/RF95Interface.cpp index 3d03e403bc..594cec91f3 100644 --- a/src/mesh/RF95Interface.cpp +++ b/src/mesh/RF95Interface.cpp @@ -41,6 +41,8 @@ bool RF95Interface::init() if (power > MAX_POWER) // This chip has lower power limits than some power = MAX_POWER; + limitPower(); + iface = lora = new RadioLibRF95(&module); #ifdef RF95_TCXO diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 0cdd4da683..4d43d22ff1 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -136,6 +136,25 @@ void RadioInterface::applyModemConfig() power); } +/** + * Some regulatory regions limit xmit power. + * This function should be called by subclasses after setting their desired power. It might lower it + */ +void RadioInterface::limitPower() +{ + uint8_t maxPower = 255; // No limit + +#ifdef HW_VERSION_JP + maxPower = 13; // See https://github.com/meshtastic/Meshtastic-device/issues/346 +#endif + if (power > maxPower) { + DEBUG_MSG("Lowering transmit power because of regulatory limits\n"); + power = maxPower; + } + + DEBUG_MSG("Set radio: final power level=%d\n", power); +} + ErrorCode SimRadio::send(MeshPacket *p) { DEBUG_MSG("SimRadio.send\n"); diff --git a/src/mesh/RadioInterface.h b/src/mesh/RadioInterface.h index b8cba208d2..645ee5c057 100644 --- a/src/mesh/RadioInterface.h +++ b/src/mesh/RadioInterface.h @@ -119,6 +119,12 @@ class RadioInterface : protected concurrency::NotifiedWorkerThread virtual void loop() {} // Idle processing + /** + * Some regulatory regions limit xmit power. + * This function should be called by subclasses after setting their desired power. It might lower it + */ + void limitPower(); + /** * Convert our modemConfig enum into wf, sf, etc... * diff --git a/src/mesh/SX1262Interface.cpp b/src/mesh/SX1262Interface.cpp index 75a84034dc..130f340c3b 100644 --- a/src/mesh/SX1262Interface.cpp +++ b/src/mesh/SX1262Interface.cpp @@ -43,6 +43,9 @@ bool SX1262Interface::init() if (power > 22) // This chip has lower power limits than some power = 22; + + limitPower(); + int res = lora.begin(freq, bw, sf, cr, syncWord, power, currentLimit, preambleLength, tcxoVoltage, useRegulatorLDO); DEBUG_MSG("SX1262 init result %d\n", res);