Avoid collision after TX is done.

This commit is contained in:
FUJIURA Toyonori 2022-04-02 18:50:54 +09:00
parent 2a1475ec72
commit ebe78ceaad
2 changed files with 29 additions and 16 deletions

View file

@ -38,7 +38,9 @@ bool RadiolibTask::setup(System &system) {
float freqMHz = (float)config.frequencyRx / 1000000;
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) {
switch (state) {
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;
}
@ -117,6 +121,9 @@ bool RadiolibTask::loop(System &system) {
operationDone = false;
transmitFlag = false;
txWaitTimer.setTimeout(preambleDurationMilliSec * 2);
txWaitTimer.start();
} else { // received.
String str;
int state = radio->readData(str);
@ -147,6 +154,8 @@ bool RadiolibTask::loop(System &system) {
enableInterrupt = true;
} else { // not interrupt.
if (!txWaitTimer.check()) {
} else {
if (!txEnable) {
// system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX is not enabled", timeString().c_str());
} else {
@ -171,6 +180,7 @@ bool RadiolibTask::loop(System &system) {
}
}
}
}
return true;
}

View file

@ -33,6 +33,9 @@ private:
int16_t startRX(uint8_t mode);
int16_t startTX(String &str);
uint32_t preambleDurationMilliSec;
Timer txWaitTimer;
};
#endif