kopia lustrzana https://github.com/sh123/esp32_loraprs
Add support for FSK modulation
rodzic
4794ee4f61
commit
127ccbe072
|
@ -59,18 +59,30 @@
|
||||||
#define CFG_LORA_USE_CAD true // set to true to utilize carrier detection
|
#define CFG_LORA_USE_CAD true // set to true to utilize carrier detection
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// LoRa protocol default parameters (they need to match between devices!!!)
|
// modulation
|
||||||
|
#define CFG_MOD_TYPE_LORA 0
|
||||||
|
#define CFG_MOD_TYPE_FSK 1
|
||||||
|
#define CFG_MOD_TYPE CFG_MOD_TYPE_LORA
|
||||||
|
|
||||||
|
// general radio parameters
|
||||||
#define CFG_LORA_FREQ_RX 433.775e6 // RX frequency in MHz
|
#define CFG_LORA_FREQ_RX 433.775e6 // RX frequency in MHz
|
||||||
#define CFG_LORA_FREQ_TX 433.775e6 // TX frequency in MHz
|
#define CFG_LORA_FREQ_TX 433.775e6 // TX frequency in MHz
|
||||||
|
#define CFG_LORA_PWR 20 // output power in dBm
|
||||||
|
|
||||||
|
// LoRa protocol default parameters (they need to match between devices!!!)
|
||||||
#define CFG_LORA_BW 125e3 // bandwidth (from 7.8 kHz up to 500 kHz)
|
#define CFG_LORA_BW 125e3 // bandwidth (from 7.8 kHz up to 500 kHz)
|
||||||
#define CFG_LORA_SF 12 // spreading factor (6 - 12), 6 requires implicit header mode
|
#define CFG_LORA_SF 12 // spreading factor (6 - 12), 6 requires implicit header mode
|
||||||
#define CFG_LORA_CR 7 // coding rate (5 - 8)
|
#define CFG_LORA_CR 7 // coding rate (5 - 8)
|
||||||
#define CFG_LORA_CRC 1 // 0 - disabled, 1 - 1 byte, 2 - 2 bytes
|
#define CFG_LORA_CRC 1 // 0 - disabled, 1 - 1 byte, 2 - 2 bytes
|
||||||
#define CFG_LORA_EXPLICIT true // header mode, true - explicit, false - implicit
|
#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_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
|
#define CFG_LORA_PREAMBLE 8 // preamble length from 6 to 65535
|
||||||
|
|
||||||
|
// fsk modem default parameters (they need to match between devices!!!)
|
||||||
|
#define CFG_FSK_BIT_RATE 4.8 // bit rate in Kbps from 0.6 to 300.0
|
||||||
|
#define CFG_FSK_FREQ_DEV 1.2 // frequency deviation in kHz from 0.6 to 200.0
|
||||||
|
#define CFG_FSK_RX_BW 9.7 // rx bandwidth in kHz !!discrete!! from 4.8 to 467.0
|
||||||
|
|
||||||
// WiFi client and AP options
|
// WiFi client and AP options
|
||||||
#define CFG_WIFI_ENABLE_AP false // run as wifi access point (for CFG_KISS_TCP_IP mode)
|
#define CFG_WIFI_ENABLE_AP false // run as wifi access point (for CFG_KISS_TCP_IP mode)
|
||||||
#define CFG_WIFI_SSID "<ssid>" // connect to SSID or run as this SSID in AP mode
|
#define CFG_WIFI_SSID "<ssid>" // connect to SSID or run as this SSID in AP mode
|
||||||
|
|
|
@ -11,18 +11,28 @@ struct Config
|
||||||
DebugLogLevel LogLevel; // log level
|
DebugLogLevel LogLevel; // log level
|
||||||
bool IsClientMode; // false - server mode, true - client mode (disables wifi and aprsis)
|
bool IsClientMode; // false - server mode, true - client mode (disables wifi and aprsis)
|
||||||
|
|
||||||
// lora protocol parameters
|
// modulation type
|
||||||
|
int ModType; // 0 - lora, 1 - fsk
|
||||||
|
|
||||||
|
// general radio parameters
|
||||||
long LoraFreqRx; // lora RX frequency, e.g. 433.775e6
|
long LoraFreqRx; // lora RX frequency, e.g. 433.775e6
|
||||||
long LoraFreqTx; // lora TX frequency, e.g. 433.775e6
|
long LoraFreqTx; // lora TX frequency, e.g. 433.775e6
|
||||||
|
int LoraPower; // lora power level in dbm, 20
|
||||||
|
|
||||||
|
// lora protocol parameters
|
||||||
long LoraBw; // lora bandwidth, e.g. 125e3
|
long LoraBw; // lora bandwidth, e.g. 125e3
|
||||||
int LoraSf; // lora spreading factor, e.g. 12
|
int LoraSf; // lora spreading factor, e.g. 12
|
||||||
int LoraCodingRate; // lora coding rate, e.g. 7
|
int LoraCodingRate; // lora coding rate, e.g. 7
|
||||||
int LoraPower; // lora power level in dbm, 20
|
|
||||||
int LoraSync; // lora sync word/packet id, 0x34
|
int LoraSync; // lora sync word/packet id, 0x34
|
||||||
int LoraCrc; // lora crc mode, 0 - disabled, 1 - 1 byte, 2 - 2 bytes
|
int LoraCrc; // lora crc mode, 0 - disabled, 1 - 1 byte, 2 - 2 bytes
|
||||||
bool LoraExplicit; // lora header mode, true - explicit, false - implicit
|
bool LoraExplicit; // lora header mode, true - explicit, false - implicit
|
||||||
int LoraPreamble; // lora preamble length from 6 to 65535
|
int LoraPreamble; // lora preamble length from 6 to 65535
|
||||||
|
|
||||||
|
// fsk modulation parameters
|
||||||
|
float FskBitRate; // fsk bit rate, 0.6 - 300.0 Kbps
|
||||||
|
float FskFreqDev; // fsk frequency deviation 0.6 - 200 kHz
|
||||||
|
float FskRxBw; // fsk rx bandwidth, discrete from 4.8 to 467 kHz
|
||||||
|
|
||||||
// lora hardware pinouts and isr
|
// lora hardware pinouts and isr
|
||||||
byte LoraPinSs; // lora ss pin
|
byte LoraPinSs; // lora ss pin
|
||||||
byte LoraPinRst; // lora rst pin
|
byte LoraPinRst; // lora rst pin
|
||||||
|
|
|
@ -39,9 +39,11 @@ private:
|
||||||
|
|
||||||
void setupWifi(const String &wifiName, const String &wifiKey);
|
void setupWifi(const String &wifiName, const String &wifiKey);
|
||||||
void setupRig(long freq, long bw, int sf, int cr, int pwr, int sync, int crcBytes, bool isExplicit);
|
void setupRig(long freq, long bw, int sf, int cr, int pwr, int sync, int crcBytes, bool isExplicit);
|
||||||
void setFreq(long freq) const;
|
void setupRigFsk(long freq, float bitRate, float freqDev, float rxBw, int pwr);
|
||||||
void setupBt(const String &btName);
|
void setupBt(const String &btName);
|
||||||
|
|
||||||
|
void setFreq(long freq) const;
|
||||||
|
|
||||||
void reconnectWifi() const;
|
void reconnectWifi() const;
|
||||||
bool reconnectAprsis();
|
bool reconnectAprsis();
|
||||||
void attachKissNetworkClient();
|
void attachKissNetworkClient();
|
||||||
|
|
|
@ -61,9 +61,14 @@ void Service::setup(const Config &conf)
|
||||||
}
|
}
|
||||||
aprsLoginCommand_ += String("\n");
|
aprsLoginCommand_ += String("\n");
|
||||||
|
|
||||||
// peripherals, LoRa
|
// radio module, FSK/LoRa
|
||||||
setupRig(config_.LoraFreqRx, config_.LoraBw, config_.LoraSf,
|
if (config_.ModType == CFG_MOD_TYPE_FSK) {
|
||||||
config_.LoraCodingRate, config_.LoraPower, config_.LoraSync, config_.LoraCrc, config_.LoraExplicit);
|
setupRigFsk(config_.LoraFreqRx, config_.FskBitRate, config_.FskFreqDev, config_.FskRxBw, config_.LoraPower);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setupRig(config_.LoraFreqRx, config_.LoraBw, config_.LoraSf,
|
||||||
|
config_.LoraCodingRate, config_.LoraPower, config_.LoraSync, config_.LoraCrc, config_.LoraExplicit);
|
||||||
|
}
|
||||||
|
|
||||||
// start radio task
|
// start radio task
|
||||||
xTaskCreate(rigTask, "rigTask", 4096, this, 5, &rigTaskHandle_);
|
xTaskCreate(rigTask, "rigTask", 4096, this, 5, &rigTaskHandle_);
|
||||||
|
@ -269,6 +274,43 @@ void Service::setupRig(long loraFreq, long bw, int sf, int cr, int pwr, int sync
|
||||||
LOG_INFO("LoRa initialized");
|
LOG_INFO("LoRa initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Service::setupRigFsk(long freq, float bitRate, float freqDev, float rxBw, int pwr)
|
||||||
|
{
|
||||||
|
LOG_INFO("Initializing FSK");
|
||||||
|
LOG_INFO("Frequency:", freq, "Hz");
|
||||||
|
LOG_INFO("Bit rate:", bitRate, "kbps");
|
||||||
|
LOG_INFO("Deviation:", freqDev, "kHz");
|
||||||
|
LOG_INFO("Bandwidth:", rxBw, "kHz");
|
||||||
|
LOG_INFO("Power:", pwr, "dBm");
|
||||||
|
rig_ = std::make_shared<MODULE_NAME>(new Module(config_.LoraPinSs, config_.LoraPinA, config_.LoraPinRst, config_.LoraPinB));
|
||||||
|
int state = rig_->beginFSK((float)freq / 1e6, bitRate, freqDev, rxBw, pwr);
|
||||||
|
if (state != RADIOLIB_ERR_NONE) {
|
||||||
|
LOG_ERROR("Radio start error:", state);
|
||||||
|
}
|
||||||
|
rig_->disableAddressFiltering();
|
||||||
|
#ifdef USE_SX126X
|
||||||
|
#pragma message("Using SX126X")
|
||||||
|
LOG_INFO("Using SX126X module");
|
||||||
|
rig_->setRfSwitchPins(config_.LoraPinSwitchRx, config_.LoraPinSwitchTx);
|
||||||
|
if (isIsrInstalled_) rig_->clearDio1Action();
|
||||||
|
rig_->setDio1Action(onRigIsrRxPacket);
|
||||||
|
isIsrInstalled_ = true;
|
||||||
|
#else
|
||||||
|
#pragma message("Using SX127X")
|
||||||
|
LOG_INFO("Using SX127X module");
|
||||||
|
if (isIsrInstalled_) rig_->clearDio0Action();
|
||||||
|
rig_->setDio0Action(onRigIsrRxPacket);
|
||||||
|
isIsrInstalled_ = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
state = rig_->startReceive();
|
||||||
|
if (state != RADIOLIB_ERR_NONE) {
|
||||||
|
LOG_ERROR("Receive start error:", state);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_INFO("FSK initialized");
|
||||||
|
}
|
||||||
|
|
||||||
void Service::setupBt(const String &btName)
|
void Service::setupBt(const String &btName)
|
||||||
{
|
{
|
||||||
String btType = config_.BtEnableBle ? "BLE" : "BT";
|
String btType = config_.BtEnableBle ? "BLE" : "BT";
|
||||||
|
|
14
src/main.cpp
14
src/main.cpp
|
@ -31,18 +31,28 @@ void initializeConfig(LoraPrs::Config &cfg) {
|
||||||
// client/server mode switch
|
// client/server mode switch
|
||||||
cfg.IsClientMode = CFG_IS_CLIENT_MODE;
|
cfg.IsClientMode = CFG_IS_CLIENT_MODE;
|
||||||
|
|
||||||
// lora parameters, must match on devices
|
// modulation
|
||||||
|
cfg.ModType = CFG_MOD_TYPE;
|
||||||
|
|
||||||
|
// generic module parameters
|
||||||
cfg.LoraFreqRx = CFG_LORA_FREQ_RX;
|
cfg.LoraFreqRx = CFG_LORA_FREQ_RX;
|
||||||
cfg.LoraFreqTx = CFG_LORA_FREQ_TX;
|
cfg.LoraFreqTx = CFG_LORA_FREQ_TX;
|
||||||
|
cfg.LoraPower = CFG_LORA_PWR;
|
||||||
|
|
||||||
|
// lora parameters, must match on devices
|
||||||
cfg.LoraBw = CFG_LORA_BW;
|
cfg.LoraBw = CFG_LORA_BW;
|
||||||
cfg.LoraSf = CFG_LORA_SF;
|
cfg.LoraSf = CFG_LORA_SF;
|
||||||
cfg.LoraCodingRate = CFG_LORA_CR;
|
cfg.LoraCodingRate = CFG_LORA_CR;
|
||||||
cfg.LoraSync = CFG_LORA_SYNC;
|
cfg.LoraSync = CFG_LORA_SYNC;
|
||||||
cfg.LoraCrc = CFG_LORA_CRC; // set to 0 to disable
|
cfg.LoraCrc = CFG_LORA_CRC; // set to 0 to disable
|
||||||
cfg.LoraExplicit = CFG_LORA_EXPLICIT;
|
cfg.LoraExplicit = CFG_LORA_EXPLICIT;
|
||||||
cfg.LoraPower = CFG_LORA_PWR;
|
|
||||||
cfg.LoraPreamble = CFG_LORA_PREAMBLE;
|
cfg.LoraPreamble = CFG_LORA_PREAMBLE;
|
||||||
|
|
||||||
|
// fsk parameters
|
||||||
|
cfg.FskBitRate = CFG_FSK_BIT_RATE;
|
||||||
|
cfg.FskFreqDev = CFG_FSK_FREQ_DEV;
|
||||||
|
cfg.FskRxBw = CFG_FSK_RX_BW;
|
||||||
|
|
||||||
// lora pinouts
|
// lora pinouts
|
||||||
cfg.LoraPinSs = CFG_LORA_PIN_SS;
|
cfg.LoraPinSs = CFG_LORA_PIN_SS;
|
||||||
cfg.LoraPinRst = CFG_LORA_PIN_RST;
|
cfg.LoraPinRst = CFG_LORA_PIN_RST;
|
||||||
|
|
Ładowanie…
Reference in New Issue