From 3540ef3006efd5d6c84f0fb40c258d9ea11b09bf Mon Sep 17 00:00:00 2001 From: sh123 Date: Wed, 15 Mar 2023 08:26:07 +0200 Subject: [PATCH] Allow to specify preamble length and select modem type from platformio ini --- include/config.h | 3 ++- include/loraprs_config.h | 1 + platformio.ini | 27 ++++++++++++++++++++------- src/loraprs_service.cpp | 1 + src/main.cpp | 1 + 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/include/config.h b/include/config.h index 3c5810f..78e4935 100644 --- a/include/config.h +++ b/include/config.h @@ -2,7 +2,7 @@ #define CONFIG_H // Uncomment for SX126X module usage -#define USE_SX126X +// #define USE_SX126X // Check your module name at https://github.com/jgromes/RadioLib/wiki/Modules #ifdef USE_SX126X @@ -69,6 +69,7 @@ #define CFG_LORA_EXPLICIT true // header mode, true - explicit, false - implicit #define CFG_LORA_SYNC 0x12 // sync word (0x12 - private used by other trackers, 0x34 - public used by LoRaWAN) #define CFG_LORA_PWR 20 // output power in dBm +#define CFG_LORA_PREAMBLE 8 // preamble length from 6 to 65535 // WiFi client and AP options #define CFG_WIFI_ENABLE_AP false // run as wifi access point (for CFG_KISS_TCP_IP mode) diff --git a/include/loraprs_config.h b/include/loraprs_config.h index b8f67b4..7d9ea50 100644 --- a/include/loraprs_config.h +++ b/include/loraprs_config.h @@ -21,6 +21,7 @@ struct Config int LoraSync; // lora sync word/packet id, 0x34 int LoraCrc; // lora crc mode, 0 - disabled, 1 - 1 byte, 2 - 2 bytes bool LoraExplicit; // lora header mode, true - explicit, false - implicit + int LoraPreamble; // lora preamble length from 6 to 65535 // lora hardware pinouts and isr byte LoraPinSs; // lora ss pin diff --git a/platformio.ini b/platformio.ini index a4c0cd1..087dcb6 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1,6 +1,6 @@ [platformio] description = ESP32 LoRA APRS modem -default_envs = esp32dev +default_envs = esp32dev_sx126x_modem [env] platform = espressif32 @ 5.2.0 @@ -19,18 +19,31 @@ check_flags = cppcheck: --suppress=*:*.pio\* --inline-suppr -DCPPCHECK check_skip_packages = yes -[env:esp32dev] +[env:esp32dev_sx126x_modem] board = esp32dev build_flags = - '-D CFG_IS_CLIENT_MODE=true' + -D CFG_IS_CLIENT_MODE=true + -D USE_SX126X -[env:esp32dev_igate] +[env:esp32dev_sx126x_igate] board = esp32dev board_build.f_cpu = 240000000L build_flags = - '-D CFG_IS_CLIENT_MODE=false' + -D CFG_IS_CLIENT_MODE=false + -D USE_SX126X -[env:ttgo-lora32-v1] +[env:esp32dev_sx127x_modem] +board = esp32dev +build_flags = + -D CFG_IS_CLIENT_MODE=true + +[env:esp32dev_sx127x_igate] +board = esp32dev +board_build.f_cpu = 240000000L +build_flags = + -D CFG_IS_CLIENT_MODE=false + +[env:ttgo-lora32-v1_modem] board = ttgo-lora32-v1 build_flags = - '-D CFG_IS_CLIENT_MODE=true' + -D CFG_IS_CLIENT_MODE=true diff --git a/src/loraprs_service.cpp b/src/loraprs_service.cpp index 5d49593..b673fce 100644 --- a/src/loraprs_service.cpp +++ b/src/loraprs_service.cpp @@ -239,6 +239,7 @@ void Service::setupRig(long loraFreq, long bw, int sf, int cr, int pwr, int sync LOG_ERROR("Radio start error:", state); } rig_->setCRC(crcBytes); + rig_->setPreambleLength(config_.LoraPreamble); #ifdef USE_SX126X #pragma message("Using SX126X") LOG_INFO("Using SX126X module"); diff --git a/src/main.cpp b/src/main.cpp index 17fafa6..8c6b049 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -41,6 +41,7 @@ void initializeConfig(LoraPrs::Config &cfg) { cfg.LoraCrc = CFG_LORA_CRC; // set to 0 to disable cfg.LoraExplicit = CFG_LORA_EXPLICIT; cfg.LoraPower = CFG_LORA_PWR; + cfg.LoraPreamble = CFG_LORA_PREAMBLE; // lora pinouts cfg.LoraPinSs = CFG_LORA_PIN_SS;