Merge branch 'ble-servicechanged'

This commit is contained in:
Joe Finney 2016-01-25 21:19:22 +00:00
commit 98573c0328
5 changed files with 28 additions and 15 deletions

View File

@ -72,7 +72,7 @@ class MicroBitBLEManager
* uBit.init();
* @endcode
*/
void init(ManagedString deviceName, ManagedString serialNumber);
void init(ManagedString deviceName, ManagedString serialNumber, bool enableBonding);
/**
* Change the output power level of the transmitter to the given value.

View File

@ -16,10 +16,10 @@
"dependencies": {
"mbed-classic": "~0.0.4",
"ble": "lancaster-university/BLE_API#v2.5.0+mb",
"ble-nrf51822": "lancaster-university/nrf51822#v2.5.0+mb2",
"ble-nrf51822": "lancaster-university/nrf51822#v2.5.0+mb3",
"nrf51-sdk": "lancaster-university/nrf51-sdk#v2.2.0+mb"
},
"extraIncludes": [
"inc"
]
}
}

View File

@ -133,13 +133,6 @@ void MicroBit::init()
// Seed our random number generator
seedRandom();
#if CONFIG_ENABLED(MICROBIT_BLE_ENABLED)
// Start the BLE stack.
bleManager.init(this->getName(), this->getSerial());
ble = bleManager.ble;
#endif
// Start refreshing the Matrix Display
systemTicker.attach(this, &MicroBit::systemTick, MICROBIT_DISPLAY_REFRESH_PERIOD);

View File

@ -46,9 +46,12 @@ int main()
if (i == 10)
{
// Bring up the BLE stack if it isn't alredy done.
// Start the BLE stack, if it isn't already running.
if (!uBit.ble)
uBit.bleManager.init(uBit.getName(), uBit.getSerial());
{
uBit.bleManager.init(uBit.getName(), uBit.getSerial(), true);
uBit.ble = uBit.bleManager.ble;
}
// Enter pairing mode, using the LED matrix for any necessary pairing operations
uBit.bleManager.pairingMode(uBit.display);
@ -56,6 +59,15 @@ int main()
}
#endif
#if CONFIG_ENABLED(MICROBIT_BLE_ENABLED)
// Start the BLE stack, if it isn't already running.
if (!uBit.ble)
{
uBit.bleManager.init(uBit.getName(), uBit.getSerial(), false);
uBit.ble = uBit.bleManager.ble;
}
#endif
app_main();
// If app_main exits, there may still be other fibers running, registered event handlers etc.

View File

@ -52,7 +52,6 @@ static void bleDisconnectionCallback(const Gap::DisconnectionCallbackParams_t *r
if (manager)
manager->advertise();
}
/**
@ -60,7 +59,16 @@ static void bleDisconnectionCallback(const Gap::DisconnectionCallbackParams_t *r
*/
static void bleConnectionCallback(const Gap::ConnectionCallbackParams_t *reason)
{
// Ensure that there's no stale, cached information in the client... invalidate all characteristics.
uint16_t len = 8;
// Configure the ServiceChanged characteristic to receive service changed indications
// TODO: This is really a workaround as we can't maintain persistent state on the micro:bit across USB
// reprogramming flashes.... yet.
uint8_t data[] = {0x0B,0x00,0x02,0x00,0x02,0x00,0xB8,0x46};
sd_ble_gatts_sys_attr_set(reason->handle, data, len, BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS);
sd_ble_gatts_service_changed(reason->handle, 0x000c, 0xffff);
}
@ -119,7 +127,7 @@ void MicroBitBLEManager::advertise()
* uBit.init();
* @endcode
*/
void MicroBitBLEManager::init(ManagedString deviceName, ManagedString serialNumber)
void MicroBitBLEManager::init(ManagedString deviceName, ManagedString serialNumber, bool enableBonding)
{
ManagedString BLEName("BBC micro:bit");
@ -148,7 +156,7 @@ void MicroBitBLEManager::init(ManagedString deviceName, ManagedString serialNumb
// Setup our security requirements.
ble->securityManager().onPasskeyDisplay(passkeyDisplayCallback);
ble->securityManager().onSecuritySetupCompleted(securitySetupCompletedCallback);
ble->securityManager().init(MICROBIT_BLE_ENABLE_BONDING, MICROBIT_BLE_REQUIRE_MITM, SecurityManager::IO_CAPS_DISPLAY_ONLY);
ble->securityManager().init(enableBonding, MICROBIT_BLE_REQUIRE_MITM, SecurityManager::IO_CAPS_DISPLAY_ONLY);
#if CONFIG_ENABLED(MICROBIT_BLE_WHITELIST)
// Configure a whitelist to filter all connection requetss from unbonded devices.