mirror of
https://github.com/meshtastic/firmware.git
synced 2025-07-31 02:45:41 +00:00
BT sleep leak now down to about 200 bytes
This commit is contained in:
parent
621beadb5c
commit
419dd44ff6
@ -224,6 +224,14 @@ void deinitBLE()
|
|||||||
{
|
{
|
||||||
assert(pServer);
|
assert(pServer);
|
||||||
|
|
||||||
|
pServer->getAdvertising()->stop();
|
||||||
|
|
||||||
|
destroyUpdateService();
|
||||||
|
|
||||||
|
pUpdate->stop();
|
||||||
|
pDevInfo->stop();
|
||||||
|
pUpdate->stop(); // we delete them below
|
||||||
|
|
||||||
// First shutdown bluetooth
|
// First shutdown bluetooth
|
||||||
BLEDevice::deinit(false);
|
BLEDevice::deinit(false);
|
||||||
|
|
||||||
@ -235,7 +243,6 @@ void deinitBLE()
|
|||||||
delete pServer;
|
delete pServer;
|
||||||
|
|
||||||
batteryLevelC = NULL; // Don't let anyone generate bogus notifies
|
batteryLevelC = NULL; // Don't let anyone generate bogus notifies
|
||||||
destroyUpdateService();
|
|
||||||
|
|
||||||
for (int i = 0; i < numChars; i++)
|
for (int i = 0; i < numChars; i++)
|
||||||
delete chars[i];
|
delete chars[i];
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include "SimpleAllocator.h"
|
#include "SimpleAllocator.h"
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
|
|
||||||
SimpleAllocator *activeAllocator;
|
|
||||||
|
|
||||||
SimpleAllocator::SimpleAllocator() { reset(); }
|
SimpleAllocator::SimpleAllocator() { reset(); }
|
||||||
|
|
||||||
@ -22,6 +21,11 @@ void *operator new(size_t size, SimpleAllocator &p)
|
|||||||
return p.alloc(size);
|
return p.alloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// This was a dumb idea, turn off for now
|
||||||
|
|
||||||
|
SimpleAllocator *activeAllocator;
|
||||||
|
|
||||||
AllocatorScope::AllocatorScope(SimpleAllocator &a)
|
AllocatorScope::AllocatorScope(SimpleAllocator &a)
|
||||||
{
|
{
|
||||||
assert(!activeAllocator);
|
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
|
Serial.println("Warning: leaking an active allocator object"); // We don't properly handle this yet
|
||||||
else
|
else
|
||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -20,7 +20,8 @@ CustomRF95::CustomRF95(MemoryPool<MeshPacket> &_pool, PointerQueue<MeshPacket> &
|
|||||||
|
|
||||||
bool CustomRF95::canSleep()
|
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()
|
bool CustomRF95::sleep()
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
class CustomRF95 : public RH_RF95
|
class CustomRF95 : public RH_RF95
|
||||||
{
|
{
|
||||||
|
friend class MeshRadio; // for debugging we let that class touch pool
|
||||||
|
|
||||||
MemoryPool<MeshPacket> &pool;
|
MemoryPool<MeshPacket> &pool;
|
||||||
PointerQueue<MeshPacket> &rxDest;
|
PointerQueue<MeshPacket> &rxDest;
|
||||||
PointerQueue<MeshPacket> txQueue;
|
PointerQueue<MeshPacket> txQueue;
|
||||||
|
@ -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.
|
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)
|
MeshRadio::MeshRadio(MemoryPool<MeshPacket> &_pool, PointerQueue<MeshPacket> &_rxDest)
|
||||||
: rf95(_pool, _rxDest),
|
: rf95(_pool, _rxDest),
|
||||||
manager(rf95)
|
manager(rf95)
|
||||||
@ -45,6 +48,9 @@ MeshRadio::MeshRadio(MemoryPool<MeshPacket> &_pool, PointerQueue<MeshPacket> &_r
|
|||||||
|
|
||||||
bool MeshRadio::init()
|
bool MeshRadio::init()
|
||||||
{
|
{
|
||||||
|
if (!useHardware)
|
||||||
|
return true;
|
||||||
|
|
||||||
DEBUG_MSG("Starting meshradio init...\n");
|
DEBUG_MSG("Starting meshradio init...\n");
|
||||||
|
|
||||||
#ifdef RESET_GPIO
|
#ifdef RESET_GPIO
|
||||||
@ -109,14 +115,17 @@ void MeshRadio::reloadConfig()
|
|||||||
rf95.setModeRx();
|
rf95.setModeRx();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ErrorCode MeshRadio::send(MeshPacket *p)
|
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()
|
void MeshRadio::loop()
|
||||||
{
|
{
|
||||||
// Currently does nothing, since we do it all in ISRs now
|
// Currently does nothing, since we do it all in ISRs now
|
||||||
|
11
src/main.ino
11
src/main.ino
@ -201,6 +201,8 @@ const char *getDeviceName()
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
// Debug
|
// Debug
|
||||||
@ -284,15 +286,18 @@ void setBluetoothEnable(bool on)
|
|||||||
bluetoothOn = on;
|
bluetoothOn = on;
|
||||||
if (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();
|
initBluetooth();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// We have to totally teardown our bluetooth objects to prevent leaks
|
// We have to totally teardown our bluetooth objects to prevent leaks
|
||||||
destroyMeshBluetoothService();
|
|
||||||
deinitBLE();
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user