BT sleep leak now down to about 200 bytes

pull/6/head
geeksville 2020-02-23 18:09:40 -08:00
rodzic 621beadb5c
commit 419dd44ff6
6 zmienionych plików z 41 dodań i 11 usunięć

Wyświetl plik

@ -224,6 +224,14 @@ void deinitBLE()
{
assert(pServer);
pServer->getAdvertising()->stop();
destroyUpdateService();
pUpdate->stop();
pDevInfo->stop();
pUpdate->stop(); // we delete them below
// First shutdown bluetooth
BLEDevice::deinit(false);
@ -235,7 +243,6 @@ void deinitBLE()
delete pServer;
batteryLevelC = NULL; // Don't let anyone generate bogus notifies
destroyUpdateService();
for (int i = 0; i < numChars; i++)
delete chars[i];

Wyświetl plik

@ -1,7 +1,6 @@
#include "SimpleAllocator.h"
#include "assert.h"
SimpleAllocator *activeAllocator;
SimpleAllocator::SimpleAllocator() { reset(); }
@ -22,6 +21,11 @@ void *operator new(size_t size, SimpleAllocator &p)
return p.alloc(size);
}
#if 0
// This was a dumb idea, turn off for now
SimpleAllocator *activeAllocator;
AllocatorScope::AllocatorScope(SimpleAllocator &a)
{
assert(!activeAllocator);
@ -51,4 +55,6 @@ void operator delete(void *ptr) throw()
Serial.println("Warning: leaking an active allocator object"); // We don't properly handle this yet
else
free(ptr);
}
}
#endif

Wyświetl plik

@ -20,7 +20,8 @@ CustomRF95::CustomRF95(MemoryPool<MeshPacket> &_pool, PointerQueue<MeshPacket> &
bool CustomRF95::canSleep()
{
return (_mode == RHModeIdle || _mode == RHModeRx) && txQueue.isEmpty(); // FIXME - also check if we have started receiving
// We allow initializing mode, because sometimes while testing we don't ever call init() to turn on the hardware
return (_mode == RHModeInitialising || _mode == RHModeIdle || _mode == RHModeRx) && txQueue.isEmpty(); // FIXME - also check if we have started receiving
}
bool CustomRF95::sleep()

Wyświetl plik

@ -15,6 +15,8 @@
*/
class CustomRF95 : public RH_RF95
{
friend class MeshRadio; // for debugging we let that class touch pool
MemoryPool<MeshPacket> &pool;
PointerQueue<MeshPacket> &rxDest;
PointerQueue<MeshPacket> txQueue;

Wyświetl plik

@ -25,6 +25,9 @@ The band is from 902 to 928 MHz. It mentions channel number and its respective c
Channel zero starts at 903.08 MHz center frequency.
*/
/// Sometimes while debugging it is useful to set this false, to disable rf95 accesses
bool useHardware = true;
MeshRadio::MeshRadio(MemoryPool<MeshPacket> &_pool, PointerQueue<MeshPacket> &_rxDest)
: rf95(_pool, _rxDest),
manager(rf95)
@ -45,6 +48,9 @@ MeshRadio::MeshRadio(MemoryPool<MeshPacket> &_pool, PointerQueue<MeshPacket> &_r
bool MeshRadio::init()
{
if (!useHardware)
return true;
DEBUG_MSG("Starting meshradio init...\n");
#ifdef RESET_GPIO
@ -109,14 +115,17 @@ void MeshRadio::reloadConfig()
rf95.setModeRx();
}
ErrorCode MeshRadio::send(MeshPacket *p)
{
return rf95.send(p);
if (useHardware)
return rf95.send(p);
else
{
rf95.pool.release(p);
return ERRNO_OK;
}
}
void MeshRadio::loop()
{
// Currently does nothing, since we do it all in ISRs now

Wyświetl plik

@ -201,6 +201,8 @@ const char *getDeviceName()
return name;
}
void setup()
{
// Debug
@ -284,15 +286,18 @@ void setBluetoothEnable(bool on)
bluetoothOn = on;
if (on)
{
Serial.printf("Pre BT: %u heap size", ESP.getFreeHeap());
Serial.printf("Pre BT: %u heap size\n", ESP.getFreeHeap());
//ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) );
initBluetooth();
}
else
{
// We have to totally teardown our bluetooth objects to prevent leaks
destroyMeshBluetoothService();
deinitBLE();
Serial.printf("Shutdown BT: %u heap size", ESP.getFreeHeap());
destroyMeshBluetoothService(); // must do after deinit, because it frees our service
Serial.printf("Shutdown BT: %u heap size\n", ESP.getFreeHeap());
//ESP_ERROR_CHECK( heap_trace_stop() );
//heap_trace_dump();
}
}
}