From 26d7b6d4200ebecc41fc6feddaa67f6c104d1195 Mon Sep 17 00:00:00 2001 From: Sam Kent Date: Wed, 29 Aug 2018 19:14:08 +0100 Subject: [PATCH 1/2] Partial Flashing disabled by default. Enabled for MakeCode builds --- inc/core/MicroBitConfig.h | 8 ++++++++ inc/platform/yotta_cfg_mappings.h | 4 ++++ source/bluetooth/MicroBitPartialFlashingService.cpp | 10 ++++++++++ 3 files changed, 22 insertions(+) diff --git a/inc/core/MicroBitConfig.h b/inc/core/MicroBitConfig.h index e6df68cc..fd584ade 100644 --- a/inc/core/MicroBitConfig.h +++ b/inc/core/MicroBitConfig.h @@ -298,6 +298,14 @@ extern uint32_t __etext; #define MICROBIT_BLE_DEVICE_INFORMATION_SERVICE 1 #endif +// Enable/Disable BLE Service: MicroBitPartialFlashingService +// This enables the flashing part of the partial flashing service. +// Partial flashing is currently only possible for programs built using MakeCode +// and is disabled by default. +#ifndef MICROBIT_BLE_PARTIAL_FLASHING +#define MICROBIT_BLE_PARTIAL_FLASHING 0 +#endif + // // Accelerometer options // diff --git a/inc/platform/yotta_cfg_mappings.h b/inc/platform/yotta_cfg_mappings.h index d5f7c604..54c93e6a 100644 --- a/inc/platform/yotta_cfg_mappings.h +++ b/inc/platform/yotta_cfg_mappings.h @@ -117,6 +117,10 @@ #define MICROBIT_BLE_ADVERTISING_INTERVAL YOTTA_CFG_MICROBIT_DAL_BLUETOOTH_ADVERTISING_INTERVAL #endif +#ifdef YOTTA_CFG_MICROBIT_DAL_BLUETOOTH_PARTIAL_FLASHING +#define MICROBIT_BLE_PARTIAL_FLASHING YOTTA_CFG_MICROBIT_DAL_BLUETOOTH_PARTIAL_FLASHING +#endif + //we check if the user has requested open mode, otherwise we will double def! #if (YOTTA_CFG_MICROBIT_DAL_BLUETOOTH_OPEN == 0) diff --git a/source/bluetooth/MicroBitPartialFlashingService.cpp b/source/bluetooth/MicroBitPartialFlashingService.cpp index f0d1b3f0..81b62c3a 100644 --- a/source/bluetooth/MicroBitPartialFlashingService.cpp +++ b/source/bluetooth/MicroBitPartialFlashingService.cpp @@ -113,6 +113,7 @@ void MicroBitPartialFlashingService::onDataWritten(const GattWriteCallbackParams break; } +#if CONFIG_ENABLED(MICROBIT_BLE_PARTIAL_FLASHING) case FLASH_DATA: { // Process FLASH data packet @@ -129,6 +130,7 @@ void MicroBitPartialFlashingService::onDataWritten(const GattWriteCallbackParams MicroBitEvent evt(MICROBIT_ID_PARTIAL_FLASHING, END_OF_TRANSMISSION); break; } +#endif case MICROBIT_STATUS: { /* @@ -157,6 +159,14 @@ void MicroBitPartialFlashingService::onDataWritten(const GattWriteCallbackParams } break; } + default: + { + /* Return command unknown + */ + uint8_t unknownCommandBuffer[] = {data[0], 0xAB, 0xCD, 0xEF}; + ble.gattServer().notify(partialFlashCharacteristicHandle, (const uint8_t *)unknownCommandBuffer, sizeof(unknownCommandBuffer)); + break; + } } } } From e08535a647063aa24b4e7ab9ddd9fc2187f8e9fb Mon Sep 17 00:00:00 2001 From: Sam Kent Date: Fri, 7 Sep 2018 13:33:16 +0100 Subject: [PATCH 2/2] if def for entire PF service --- source/bluetooth/MicroBitBLEManager.cpp | 3 +++ source/bluetooth/MicroBitPartialFlashingService.cpp | 10 ---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/source/bluetooth/MicroBitBLEManager.cpp b/source/bluetooth/MicroBitBLEManager.cpp index 2d5f0bbf..f007733d 100644 --- a/source/bluetooth/MicroBitBLEManager.cpp +++ b/source/bluetooth/MicroBitBLEManager.cpp @@ -383,6 +383,9 @@ void MicroBitBLEManager::init(ManagedString deviceName, ManagedString serialNumb // Bring up core BLE services. #if CONFIG_ENABLED(MICROBIT_BLE_DFU_SERVICE) new MicroBitDFUService(*ble); +#endif + +#if CONFIG_ENABLED(MICROBIT_BLE_PARTIAL_FLASHING) new MicroBitPartialFlashingService(*ble, messageBus); #endif diff --git a/source/bluetooth/MicroBitPartialFlashingService.cpp b/source/bluetooth/MicroBitPartialFlashingService.cpp index 81b62c3a..f0d1b3f0 100644 --- a/source/bluetooth/MicroBitPartialFlashingService.cpp +++ b/source/bluetooth/MicroBitPartialFlashingService.cpp @@ -113,7 +113,6 @@ void MicroBitPartialFlashingService::onDataWritten(const GattWriteCallbackParams break; } -#if CONFIG_ENABLED(MICROBIT_BLE_PARTIAL_FLASHING) case FLASH_DATA: { // Process FLASH data packet @@ -130,7 +129,6 @@ void MicroBitPartialFlashingService::onDataWritten(const GattWriteCallbackParams MicroBitEvent evt(MICROBIT_ID_PARTIAL_FLASHING, END_OF_TRANSMISSION); break; } -#endif case MICROBIT_STATUS: { /* @@ -159,14 +157,6 @@ void MicroBitPartialFlashingService::onDataWritten(const GattWriteCallbackParams } break; } - default: - { - /* Return command unknown - */ - uint8_t unknownCommandBuffer[] = {data[0], 0xAB, 0xCD, 0xEF}; - ble.gattServer().notify(partialFlashCharacteristicHandle, (const uint8_t *)unknownCommandBuffer, sizeof(unknownCommandBuffer)); - break; - } } } }