kopia lustrzana https://github.com/sh123/esp32_loraprs
Add support for split operation
rodzic
6ecaaf93d5
commit
a3cde349c1
3
config.h
3
config.h
|
@ -58,7 +58,8 @@
|
|||
#endif
|
||||
|
||||
// LoRa protocol default parameters (they need to match between devices!!!)
|
||||
#define CFG_LORA_FREQ 433.775e6 // 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_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_CR 7 // coding rate (5 - 8)
|
||||
|
|
|
@ -30,8 +30,9 @@ void initializeConfig(LoraPrs::Config &cfg) {
|
|||
// client/server mode switch
|
||||
cfg.IsClientMode = CFG_IS_CLIENT_MODE;
|
||||
|
||||
// lora parameters, mus match on devices
|
||||
cfg.LoraFreq = CFG_LORA_FREQ;
|
||||
// lora parameters, must match on devices
|
||||
cfg.LoraFreqRx = CFG_LORA_FREQ_RX;
|
||||
cfg.LoraFreqTx = CFG_LORA_FREQ_TX;
|
||||
cfg.LoraBw = CFG_LORA_BW;
|
||||
cfg.LoraSf = CFG_LORA_SF;
|
||||
cfg.LoraCodingRate = CFG_LORA_CR;
|
||||
|
|
|
@ -12,7 +12,8 @@ struct Config
|
|||
bool IsClientMode; // false - server mode, true - client mode (disables wifi and aprsis)
|
||||
|
||||
// lora protocol parameters
|
||||
long LoraFreq; // lora frequency, e.g. 433.775e6
|
||||
long LoraFreqRx; // lora RX frequency, e.g. 433.775e6
|
||||
long LoraFreqTx; // lora TX frequency, e.g. 433.775e6
|
||||
long LoraBw; // lora bandwidth, e.g. 125e3
|
||||
int LoraSf; // lora spreading factor, e.g. 12
|
||||
int LoraCodingRate; // lora coding rate, e.g. 7
|
||||
|
|
|
@ -67,7 +67,7 @@ void Service::setup(const Config &conf)
|
|||
aprsLoginCommand_ += String("\n");
|
||||
|
||||
// peripherals, LoRa
|
||||
setupLora(config_.LoraFreq, config_.LoraBw, config_.LoraSf,
|
||||
setupLora(config_.LoraFreqRx, config_.LoraBw, config_.LoraSf,
|
||||
config_.LoraCodingRate, config_.LoraPower, config_.LoraSync, config_.LoraCrc, config_.LoraExplicit);
|
||||
|
||||
#ifdef USE_RADIOLIB
|
||||
|
@ -584,22 +584,26 @@ void Service::performFrequencyCorrection() {
|
|||
long frequencyErrorHz = LoRa.packetFrequencyError();
|
||||
#endif
|
||||
if (abs(frequencyErrorHz) > config_.AutoFreqCorrectionDeltaHz) {
|
||||
config_.LoraFreq -= frequencyErrorHz;
|
||||
config_.LoraFreqRx -= frequencyErrorHz;
|
||||
LOG_INFO("Correcting frequency:", frequencyErrorHz);
|
||||
#ifdef USE_RADIOLIB
|
||||
radio_->setFrequency((float)config_.LoraFreq / 1e6);
|
||||
setupFreq(config_.LoraFreqRx);
|
||||
}
|
||||
}
|
||||
|
||||
void Service::setupFreq(long loraFreq) const {
|
||||
#ifdef USE_RADIOLIB
|
||||
radio_->setFrequency((float)config_.LoraFreqRx / 1e6);
|
||||
int state = radio_->startReceive();
|
||||
if (state != ERR_NONE) {
|
||||
LOG_ERROR("Start receive error:", state);
|
||||
}
|
||||
#else
|
||||
LoRa.setFrequency(config_.LoraFreq);
|
||||
LoRa.setFrequency(config_.LoraFreqRx);
|
||||
if (config_.LoraUseIsr) {
|
||||
LoRa.idle();
|
||||
LoRa.receive();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef USE_RADIOLIB
|
||||
|
@ -676,6 +680,9 @@ void Service::processIncomingRawPacketAsServer(const byte *packet, int packetLen
|
|||
|
||||
bool Service::onRigTxBegin()
|
||||
{
|
||||
if (splitEnabled()) {
|
||||
setupFreq(config_.LoraFreqTx);
|
||||
}
|
||||
if (config_.PttEnable) {
|
||||
digitalWrite(config_.PttPin, HIGH);
|
||||
delay(config_.PttTxDelayMs);
|
||||
|
@ -728,6 +735,9 @@ void Service::onRigTxEnd()
|
|||
LoRa.endPacket(true);
|
||||
#endif
|
||||
}
|
||||
if (splitEnabled()) {
|
||||
setupFreq(config_.LoraFreqRx);
|
||||
}
|
||||
}
|
||||
|
||||
void Service::attachKissNetworkClient()
|
||||
|
@ -844,7 +854,7 @@ void Service::onRadioControlCommand(const std::vector<byte> &rawCommand) {
|
|||
LOG_INFO("Setting new radio parameters");
|
||||
const struct SetHardware * setHardware = reinterpret_cast<const struct SetHardware*>(rawCommand.data());
|
||||
|
||||
config_.LoraFreq = be32toh(setHardware->freq);
|
||||
config_.LoraFreqRx = be32toh(setHardware->freq);
|
||||
config_.LoraBw = be32toh(setHardware->bw);
|
||||
config_.LoraSf = be16toh(setHardware->sf);
|
||||
config_.LoraCodingRate = be16toh(setHardware->cr);
|
||||
|
@ -852,7 +862,7 @@ void Service::onRadioControlCommand(const std::vector<byte> &rawCommand) {
|
|||
config_.LoraSync = be16toh(setHardware->sync);
|
||||
int crcType = setHardware->crc ? config_.LoraCrc : 0;
|
||||
|
||||
setupLora(config_.LoraFreq, config_.LoraBw, config_.LoraSf,
|
||||
setupLora(config_.LoraFreqRx, config_.LoraBw, config_.LoraSf,
|
||||
config_.LoraCodingRate, config_.LoraPower, config_.LoraSync, crcType, config_.LoraExplicit);
|
||||
} else {
|
||||
LOG_ERROR("Radio control command of wrong size");
|
||||
|
|
|
@ -42,6 +42,7 @@ private:
|
|||
|
||||
void setupWifi(const String &wifiName, const String &wifiKey);
|
||||
void setupLora(long loraFreq, long bw, int sf, int cr, int pwr, int sync, int crcBytes, bool isExplicit);
|
||||
void setupFreq(long loraFreq) const;
|
||||
void setupBt(const String &btName);
|
||||
|
||||
void reconnectWifi() const;
|
||||
|
@ -84,6 +85,9 @@ private:
|
|||
return !config_.IsClientMode // beaconing only in apris gate / server mode
|
||||
&& config_.EnableBeacon; // beacon must be explicitly enabled
|
||||
}
|
||||
inline bool splitEnabled() const {
|
||||
return config_.LoraFreqRx != config_.LoraFreqTx;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual bool onRigTxBegin();
|
||||
|
|
Ładowanie…
Reference in New Issue