From eb312bbe38651e0dcaefc46264015a9d9c3aa8cb Mon Sep 17 00:00:00 2001 From: Martin Williams Date: Sat, 5 Jun 2021 14:04:34 +0100 Subject: [PATCH] BLE - make Device Info Service Model Number String sensitive to board ID --- inc/bluetooth/MicroBitBLEManager.h | 2 +- model/MicroBit.cpp | 8 ++++++-- source/bluetooth/MicroBitBLEManager.cpp | 15 ++++++++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/inc/bluetooth/MicroBitBLEManager.h b/inc/bluetooth/MicroBitBLEManager.h index aa62c34e..3f035fa2 100644 --- a/inc/bluetooth/MicroBitBLEManager.h +++ b/inc/bluetooth/MicroBitBLEManager.h @@ -123,7 +123,7 @@ class MicroBitBLEManager : public CodalComponent * bleManager.init(uBit.getName(), uBit.getSerial(), uBit.messageBus, true); * @endcode */ - void init(ManagedString deviceName, ManagedString serialNumber, EventModel &messageBus, MicroBitStorage &keyValuestorage, bool enableBonding); + void init(ManagedString deviceName, ManagedString serialNumber, EventModel &messageBus, MicroBitStorage &keyValuestorage, bool enableBonding, uint16_t board = 0x9904); /** * Change the output power level of the transmitter to the given value. diff --git a/model/MicroBit.cpp b/model/MicroBit.cpp index 92435733..422316b9 100644 --- a/model/MicroBit.cpp +++ b/model/MicroBit.cpp @@ -207,6 +207,10 @@ int MicroBit::init() NVIC_SetPriority(UARTE0_UART0_IRQn, 2); // Serial port NVIC_SetPriority(GPIOTE_IRQn, 2); // Pin interrupt events +#if CONFIG_ENABLED(DEVICE_BLE) && ( CONFIG_ENABLED(MICROBIT_BLE_PAIRING_MODE) || CONFIG_ENABLED(MICROBIT_BLE_ENABLED)) + MicroBitVersion version = power.getVersion(); +#endif + #if CONFIG_ENABLED(DEVICE_BLE) && CONFIG_ENABLED(MICROBIT_BLE_PAIRING_MODE) int i=0; // Test if we need to enter BLE pairing mode @@ -237,7 +241,7 @@ int MicroBit::init() delete flashIncomplete; // Start the BLE stack, if it isn't already running. - bleManager.init( ManagedString( microbit_friendly_name()), getSerial(), messageBus, storage, true); + bleManager.init( ManagedString( microbit_friendly_name()), getSerial(), messageBus, storage, true, version.board); // Enter pairing mode, using the LED matrix for any necessary pairing operations bleManager.pairingMode(display, buttonA); @@ -247,7 +251,7 @@ int MicroBit::init() #if CONFIG_ENABLED(DEVICE_BLE) && CONFIG_ENABLED(MICROBIT_BLE_ENABLED) // Start the BLE stack, if it isn't already running. - bleManager.init( ManagedString( microbit_friendly_name()), getSerial(), messageBus, storage, false); + bleManager.init( ManagedString( microbit_friendly_name()), getSerial(), messageBus, storage, false, version.board); #endif // Deschedule for a little while, just to allow for any components that finialise initialisation diff --git a/source/bluetooth/MicroBitBLEManager.cpp b/source/bluetooth/MicroBitBLEManager.cpp index 69d32622..6c7fe9e6 100644 --- a/source/bluetooth/MicroBitBLEManager.cpp +++ b/source/bluetooth/MicroBitBLEManager.cpp @@ -111,6 +111,7 @@ DEALINGS IN THE SOFTWARE. const char *MICROBIT_BLE_MANUFACTURER = NULL; const char *MICROBIT_BLE_MODEL = "BBC micro:bit"; +const char *MICROBIT_BLE_VERSION[2] = { "2.0", "2.X" }; const char *MICROBIT_BLE_HARDWARE_VERSION = NULL; const char *MICROBIT_BLE_FIRMWARE_VERSION = MICROBIT_DAL_VERSION; const char *MICROBIT_BLE_SOFTWARE_VERSION = NULL; @@ -228,7 +229,7 @@ MicroBitBLEManager *MicroBitBLEManager::getInstance() * bleManager.init(uBit.getName(), uBit.getSerial(), uBit.messageBus, true); * @endcode */ -void MicroBitBLEManager::init( ManagedString deviceName, ManagedString serialNumber, EventModel &messageBus, MicroBitStorage &keyValueStorage, bool enableBonding) +void MicroBitBLEManager::init( ManagedString deviceName, ManagedString serialNumber, EventModel &messageBus, MicroBitStorage &keyValueStorage, bool enableBonding, uint16_t board) { if ( this->status & DEVICE_COMPONENT_RUNNING) return; @@ -436,9 +437,17 @@ void MicroBitBLEManager::init( ManagedString deviceName, ManagedString serialNum #if CONFIG_ENABLED(MICROBIT_BLE_DEVICE_INFORMATION_SERVICE) MICROBIT_DEBUG_DMESG( "DEVICE_INFORMATION_SERVICE"); - ManagedString modelVersion("V2.0"); // TODO use a calculated version + int versionIdx = 0; + switch ( board) + { + case 0x9903: + case 0x9904: break; + default: versionIdx = 1; break; + } + + ManagedString modelVersion( MICROBIT_BLE_VERSION[versionIdx]); ManagedString disName( MICROBIT_BLE_MODEL); - disName = disName + " " + modelVersion; + disName = disName + " V" + modelVersion; ble_dis_init_t disi; memset( &disi, 0, sizeof(disi));