new receive code works a little better

This commit is contained in:
geeksville
2020-04-30 13:50:40 -07:00
parent 22720e9f63
commit a2ba9d3c44
6 changed files with 49 additions and 21 deletions

View File

@@ -30,7 +30,7 @@ bool SX1262Interface::init()
if (res == ERR_NONE)
startReceive(); // start receiving
return res;
return res == ERR_NONE;
}
bool SX1262Interface::reconfigure()
@@ -38,11 +38,10 @@ bool SX1262Interface::reconfigure()
applyModemConfig();
// set mode to standby
int err = lora.standby();
assert(err == ERR_NONE);
setStandby();
// configure publicly accessible settings
err = lora.setSpreadingFactor(sf);
int err = lora.setSpreadingFactor(sf);
assert(err == ERR_NONE);
err = lora.setBandwidth(bw);
@@ -73,11 +72,24 @@ bool SX1262Interface::reconfigure()
return ERR_NONE;
}
void SX1262Interface::setStandby()
{
int err = lora.standby();
assert(err == ERR_NONE);
isReceiving = false; // If we were receiving, not any more
completeSending(); // If we were sending, not anymore
disableInterrupt();
}
void SX1262Interface::startReceive()
{
setStandby();
int err = lora.startReceive();
assert(err == ERR_NONE);
isReceiving = true;
// Must be done AFTER, starting transmit, because startTransmit clears (possibly stale) interrupt pending register bits
enableInterrupt(isrRxLevel0);
}
@@ -85,15 +97,10 @@ void SX1262Interface::startReceive()
/** Could we send right now (i.e. either not actively receving or transmitting)? */
bool SX1262Interface::canSendImmediately()
{
return true; // FIXME
#if 0
// We wait _if_ we are partially though receiving a packet (rather than just merely waiting for one).
// To do otherwise would be doubly bad because not only would we drop the packet that was on the way in,
// we almost certainly guarantee no one outside will like the packet we are sending.
if (_mode == RHModeIdle || isReceiving()) {
// if the radio is idle, we can send right away
DEBUG_MSG("immediate send on mesh fr=0x%x,to=0x%x,id=%d\n (txGood=%d,rxGood=%d,rxBad=%d)\n", p->from, p->to, p->id,
txGood(), rxGood(), rxBad());
}
#endif
bool busy = sendingPacket != NULL || (isReceiving && lora.getPacketLength() > 0);
return !busy;
}