mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-24 09:26:52 +00:00
still leaking in the BT stack but better
This commit is contained in:
parent
f9ce6a53e1
commit
a45d7be922
@ -189,12 +189,27 @@ class MySecurity : public BLESecurityCallbacks
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BLEServer *pServer;
|
||||||
|
|
||||||
|
BLEService *pDevInfo, *pUpdate;
|
||||||
|
|
||||||
void deinitBLE()
|
void deinitBLE()
|
||||||
{
|
{
|
||||||
|
assert(pServer);
|
||||||
|
|
||||||
|
// First shutdown bluetooth
|
||||||
|
BLEDevice::deinit(false);
|
||||||
|
|
||||||
|
// do not delete this - it is dynamically allocated, but only once - statically in BLEDevice
|
||||||
|
// delete pServer->getAdvertising();
|
||||||
|
|
||||||
|
delete pUpdate;
|
||||||
|
delete pDevInfo;
|
||||||
|
delete pServer;
|
||||||
|
|
||||||
batteryLevelC = NULL; // Don't let anyone generate bogus notifies
|
batteryLevelC = NULL; // Don't let anyone generate bogus notifies
|
||||||
destroyUpdateService();
|
destroyUpdateService();
|
||||||
|
|
||||||
BLEDevice::deinit(false);
|
|
||||||
btPool.reset();
|
btPool.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,16 +225,16 @@ BLEServer *initBLE(std::string deviceName, std::string hwVendor, std::string swV
|
|||||||
BLEDevice::setSecurityCallbacks(&mySecurity);
|
BLEDevice::setSecurityCallbacks(&mySecurity);
|
||||||
|
|
||||||
// Create the BLE Server
|
// Create the BLE Server
|
||||||
BLEServer *pServer = BLEDevice::createServer();
|
pServer = BLEDevice::createServer();
|
||||||
static MyServerCallbacks myCallbacks;
|
static MyServerCallbacks myCallbacks;
|
||||||
pServer->setCallbacks(&myCallbacks);
|
pServer->setCallbacks(&myCallbacks);
|
||||||
|
|
||||||
BLEService *pDevInfo = createDeviceInfomationService(pServer, hwVendor, swVersion, hwVersion);
|
pDevInfo = createDeviceInfomationService(pServer, hwVendor, swVersion, hwVersion);
|
||||||
|
|
||||||
// We now let users create the battery service only if they really want (not all devices have a battery)
|
// We now let users create the battery service only if they really want (not all devices have a battery)
|
||||||
// BLEService *pBattery = createBatteryService(pServer);
|
// BLEService *pBattery = createBatteryService(pServer);
|
||||||
|
|
||||||
BLEService *pUpdate = createUpdateService(pServer); // We need to advertise this so our android ble scan operation can see it
|
pUpdate = createUpdateService(pServer); // We need to advertise this so our android ble scan operation can see it
|
||||||
|
|
||||||
// It seems only one service can be advertised - so for now don't advertise our updater
|
// It seems only one service can be advertised - so for now don't advertise our updater
|
||||||
// pServer->getAdvertising()->addServiceUUID(pUpdate->getUUID());
|
// pServer->getAdvertising()->addServiceUUID(pUpdate->getUUID());
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#define POOL_SIZE 32768
|
#define POOL_SIZE 16384
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An allocator (and placement new operator) that allocates storage from a fixed sized buffer.
|
* An allocator (and placement new operator) that allocates storage from a fixed sized buffer.
|
||||||
|
@ -236,6 +236,8 @@ void bluetoothNotifyFromNum(uint32_t newValue)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BLEService *meshService;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MeshBluetoothService UUID 6ba1b218-15a8-461f-9fa8-5dcae273eafd
|
MeshBluetoothService UUID 6ba1b218-15a8-461f-9fa8-5dcae273eafd
|
||||||
|
|
||||||
@ -317,9 +319,13 @@ BLEService *createMeshBluetoothService(BLEServer *server)
|
|||||||
DEBUG_MSG("*** Mesh service:\n");
|
DEBUG_MSG("*** Mesh service:\n");
|
||||||
service->dump();
|
service->dump();
|
||||||
|
|
||||||
|
meshService = service;
|
||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroyMeshBluetoothService() {
|
void destroyMeshBluetoothService() {
|
||||||
|
assert(meshService);
|
||||||
|
delete meshService;
|
||||||
|
|
||||||
meshFromNumCharacteristic = NULL;
|
meshFromNumCharacteristic = NULL;
|
||||||
}
|
}
|
@ -284,6 +284,7 @@ void setBluetoothEnable(bool on)
|
|||||||
bluetoothOn = on;
|
bluetoothOn = on;
|
||||||
if (on)
|
if (on)
|
||||||
{
|
{
|
||||||
|
Serial.printf("Pre BT: %u heap size", ESP.getFreeHeap());
|
||||||
initBluetooth();
|
initBluetooth();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -291,6 +292,7 @@ void setBluetoothEnable(bool on)
|
|||||||
// We have to totally teardown our bluetooth objects to prevent leaks
|
// We have to totally teardown our bluetooth objects to prevent leaks
|
||||||
destroyMeshBluetoothService();
|
destroyMeshBluetoothService();
|
||||||
deinitBLE();
|
deinitBLE();
|
||||||
|
Serial.printf("Shutdown BT: %u heap size", ESP.getFreeHeap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user