mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-22 02:32:23 +00:00
don't turn bluetooth back on every time we exit light sleep
This commit is contained in:
@@ -109,138 +109,15 @@ void MeshRadio::reloadConfig()
|
||||
rf95.setModeRx();
|
||||
}
|
||||
|
||||
void MeshRadio::sleep()
|
||||
{
|
||||
// we no longer care about interrupts from this device
|
||||
rf95.prepareDeepSleep();
|
||||
|
||||
// FIXME - leave the device state in rx mode instead
|
||||
rf95.sleep();
|
||||
}
|
||||
|
||||
ErrorCode MeshRadio::send(MeshPacket *p)
|
||||
{
|
||||
#if 1
|
||||
return rf95.send(p);
|
||||
#else
|
||||
DEBUG_MSG("enquing packet for send from=0x%x, to=0x%x\n", p->from, p->to);
|
||||
return txQueue.enqueue(p, 0); // nowait
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 0
|
||||
ErrorCode MeshRadio::sendTo(NodeNum dest, const uint8_t *buf, size_t len)
|
||||
{
|
||||
// We must do this before each send, because we might have just changed our nodenum
|
||||
manager.setThisAddress(nodeDB.getNodeNum()); // Note: we must do this here, because the nodenum isn't inited at constructor time.
|
||||
|
||||
assert(len <= 251); // Make sure we don't overflow the tiny max packet size
|
||||
|
||||
uint32_t start = millis();
|
||||
// Note: we don't use sendToWait here because we don't want to wait and for the time being don't require
|
||||
// reliable delivery
|
||||
// return manager.sendtoWait((uint8_t *) buf, len, dest);
|
||||
ErrorCode res = manager.sendto((uint8_t *)buf, len, dest) ? ERRNO_OK : ERRNO_UNKNOWN;
|
||||
|
||||
// FIXME, we have to wait for sending to complete before freeing the buffer, otherwise it might get wiped
|
||||
// instead just have the radiohead layer understand queues.
|
||||
if (res == ERRNO_OK)
|
||||
manager.waitPacketSent();
|
||||
|
||||
DEBUG_MSG("mesh sendTo %d bytes to 0x%x (%lu msecs)\n", len, dest, millis() - start);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/// enqueue a received packet in rxDest
|
||||
void MeshRadio::handleReceive(MeshPacket *mp)
|
||||
{
|
||||
int res = rxDest.enqueue(mp, 0); // NOWAIT - fixme, if queue is full, delete older messages
|
||||
assert(res == pdTRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
void MeshRadio::loop()
|
||||
{
|
||||
// FIXME read from radio with recvfromAckTimeout
|
||||
|
||||
#if 0
|
||||
static int16_t packetnum = 0; // packet counter, we increment per xmission
|
||||
|
||||
char radiopacket[20] = "Hello World # ";
|
||||
sprintf(radiopacket, "hello %d", packetnum++);
|
||||
|
||||
assert(sendTo(NODENUM_BROADCAST, (uint8_t *)radiopacket, sizeof(radiopacket)) == ERRNO_OK);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
/// A temporary buffer used for sending/receving packets, sized to hold the biggest buffer we might need
|
||||
#define MAX_RHPACKETLEN 251
|
||||
static uint8_t radiobuf[MAX_RHPACKETLEN];
|
||||
uint8_t rxlen;
|
||||
uint8_t srcaddr, destaddr, id, flags;
|
||||
|
||||
// Poll to see if we've received a packet
|
||||
// if (manager.recvfromAckTimeout(radiobuf, &rxlen, 0, &srcaddr, &destaddr, &id, &flags))
|
||||
// prefill rxlen with the max length we can accept - very important
|
||||
rxlen = (uint8_t) MAX_RHPACKETLEN;
|
||||
if (manager.recvfrom(radiobuf, &rxlen, &srcaddr, &destaddr, &id, &flags))
|
||||
{
|
||||
// We received a packet
|
||||
int32_t freqerr = rf95.frequencyError(), snr = rf95.lastSNR();
|
||||
DEBUG_MSG("Received packet from mesh src=0x%x,dest=0x%x,id=%d,len=%d rxGood=%d,rxBad=%d,freqErr=%d,snr=%d\n",
|
||||
srcaddr, destaddr, id, rxlen, rf95.rxGood(), rf95.rxBad(), freqerr, snr);
|
||||
|
||||
MeshPacket *mp = pool.allocZeroed();
|
||||
|
||||
SubPacket *p = &mp->payload;
|
||||
|
||||
mp->from = srcaddr;
|
||||
mp->to = destaddr;
|
||||
|
||||
// If we already have an entry in the DB for this nodenum, goahead and hide the snr/freqerr info there.
|
||||
// Note: we can't create it at this point, because it might be a bogus User node allocation. But odds are we will
|
||||
// already have a record we can hide this debugging info in.
|
||||
NodeInfo *info = nodeDB.getNode(mp->from);
|
||||
if (info)
|
||||
{
|
||||
info->snr = snr;
|
||||
info->frequency_error = freqerr;
|
||||
}
|
||||
|
||||
if (!pb_decode_from_bytes(radiobuf, rxlen, SubPacket_fields, p))
|
||||
{
|
||||
pool.release(mp);
|
||||
}
|
||||
else
|
||||
{
|
||||
// parsing was successful, queue for our recipient
|
||||
mp->has_payload = true;
|
||||
handleReceive(mp);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// Poll to see if we need to send any packets
|
||||
MeshPacket *txp = txQueue.dequeuePtr(0); // nowait
|
||||
if (txp)
|
||||
{
|
||||
DEBUG_MSG("sending queued packet on mesh (txGood=%d,rxGood=%d,rxBad=%d)\n", rf95.txGood(), rf95.rxGood(), rf95.rxBad());
|
||||
assert(txp->has_payload);
|
||||
|
||||
size_t numbytes = pb_encode_to_bytes(radiobuf, sizeof(radiobuf), SubPacket_fields, &txp->payload);
|
||||
|
||||
int res = sendTo(txp->to, radiobuf, numbytes);
|
||||
assert(res == ERRNO_OK);
|
||||
|
||||
bool loopbackTest = false; // if true we will pretend to receive any packets we just sent
|
||||
if (loopbackTest)
|
||||
handleReceive(txp);
|
||||
else
|
||||
pool.release(txp);
|
||||
|
||||
DEBUG_MSG("Done with send\n");
|
||||
}
|
||||
#endif
|
||||
// Currently does nothing, since we do it all in ISRs now
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user