mirror of
https://github.com/lora-aprs/LoRa_APRS_iGate.git
synced 2025-12-06 07:42:00 +01:00
Avoid collision after TX is done.
This commit is contained in:
parent
2a1475ec72
commit
ebe78ceaad
|
|
@ -38,7 +38,9 @@ bool RadiolibTask::setup(System &system) {
|
||||||
float freqMHz = (float)config.frequencyRx / 1000000;
|
float freqMHz = (float)config.frequencyRx / 1000000;
|
||||||
float BWkHz = (float)config.signalBandwidth / 1000;
|
float BWkHz = (float)config.signalBandwidth / 1000;
|
||||||
|
|
||||||
int16_t state = radio->begin(freqMHz, BWkHz, config.spreadingFactor, config.codingRate4, RADIOLIB_SX127X_SYNC_WORD, config.power /* 2-17 */, 8, config.gainRx);
|
const uint16_t preambleLength = 8;
|
||||||
|
|
||||||
|
int16_t state = radio->begin(freqMHz, BWkHz, config.spreadingFactor, config.codingRate4, RADIOLIB_SX127X_SYNC_WORD, config.power, preambleLength, config.gainRx);
|
||||||
if (state != RADIOLIB_ERR_NONE) {
|
if (state != RADIOLIB_ERR_NONE) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case RADIOLIB_ERR_INVALID_FREQUENCY:
|
case RADIOLIB_ERR_INVALID_FREQUENCY:
|
||||||
|
|
@ -97,6 +99,8 @@ bool RadiolibTask::setup(System &system) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
preambleDurationMilliSec = ((uint64_t)(preambleLength + 4) << (config.spreadingFactor + 10 /* to milli-sec */)) / config.signalBandwidth;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,6 +121,9 @@ bool RadiolibTask::loop(System &system) {
|
||||||
operationDone = false;
|
operationDone = false;
|
||||||
transmitFlag = false;
|
transmitFlag = false;
|
||||||
|
|
||||||
|
txWaitTimer.setTimeout(preambleDurationMilliSec * 2);
|
||||||
|
txWaitTimer.start();
|
||||||
|
|
||||||
} else { // received.
|
} else { // received.
|
||||||
String str;
|
String str;
|
||||||
int state = radio->readData(str);
|
int state = radio->readData(str);
|
||||||
|
|
@ -147,24 +154,27 @@ bool RadiolibTask::loop(System &system) {
|
||||||
|
|
||||||
enableInterrupt = true;
|
enableInterrupt = true;
|
||||||
} else { // not interrupt.
|
} else { // not interrupt.
|
||||||
if (!txEnable) {
|
if (!txWaitTimer.check()) {
|
||||||
// system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX is not enabled", timeString().c_str());
|
|
||||||
} else {
|
} else {
|
||||||
if (transmitFlag) {
|
if (!txEnable) {
|
||||||
// system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX signal detected. Waiting TX", timeString().c_str());
|
// system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX is not enabled", timeString().c_str());
|
||||||
} else {
|
} else {
|
||||||
if (!_toModem.empty()) {
|
if (transmitFlag) {
|
||||||
if (config.frequencyRx == config.frequencyTx && (radio->getModemStatus() & 0x01) == 0x01) {
|
// system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX signal detected. Waiting TX", timeString().c_str());
|
||||||
// system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] RX signal detected. Waiting TX", timeString().c_str());
|
} else {
|
||||||
} else {
|
if (!_toModem.empty()) {
|
||||||
std::shared_ptr<APRSMessage> msg = _toModem.getElement();
|
if (config.frequencyRx == config.frequencyTx && (radio->getModemStatus() & 0x01) == 0x01) {
|
||||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Transmitting packet '%s'", timeString().c_str(), msg->toString().c_str());
|
// system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] RX signal detected. Waiting TX", timeString().c_str());
|
||||||
|
} else {
|
||||||
|
std::shared_ptr<APRSMessage> msg = _toModem.getElement();
|
||||||
|
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Transmitting packet '%s'", timeString().c_str(), msg->toString().c_str());
|
||||||
|
|
||||||
int16_t state = startTX("<\xff\x01" + msg->encode());
|
int16_t state = startTX("<\xff\x01" + msg->encode());
|
||||||
if (state != RADIOLIB_ERR_NONE) {
|
if (state != RADIOLIB_ERR_NONE) {
|
||||||
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] startTX failed, code %d", timeString().c_str(), state);
|
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] startTX failed, code %d", timeString().c_str(), state);
|
||||||
txEnable = false;
|
txEnable = false;
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,9 @@ private:
|
||||||
|
|
||||||
int16_t startRX(uint8_t mode);
|
int16_t startRX(uint8_t mode);
|
||||||
int16_t startTX(String &str);
|
int16_t startTX(String &str);
|
||||||
|
|
||||||
|
uint32_t preambleDurationMilliSec;
|
||||||
|
Timer txWaitTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue