diff --git a/BLE_LEDBlinker/mbed-os.lib b/BLE_LEDBlinker/mbed-os.lib index 426d1dd0..0ea5e6ea 100644 --- a/BLE_LEDBlinker/mbed-os.lib +++ b/BLE_LEDBlinker/mbed-os.lib @@ -1 +1,3 @@ -https://github.com/ARMmbed/mbed-os/#a6207cadad0acd1876f436dc6baeddf46c42af06 +https://github.com/micgur01/mbed-os/#56c3b98a25da17bc9d5d594575297d7297dc7896 + + diff --git a/BLE_LEDBlinker/mbed_app.json b/BLE_LEDBlinker/mbed_app.json index 205b8cd4..0ed12142 100644 --- a/BLE_LEDBlinker/mbed_app.json +++ b/BLE_LEDBlinker/mbed_app.json @@ -1,5 +1,9 @@ { "target_overrides": { + + "*": { + "platform.stdio-baud-rate" : 115200 + }, "K64F": { "target.components_add": ["BlueNRG_MS"], "target.features_add": ["BLE"], diff --git a/BLE_LEDBlinker/source/main.cpp b/BLE_LEDBlinker/source/main.cpp index 1d43da22..6394f37a 100644 --- a/BLE_LEDBlinker/source/main.cpp +++ b/BLE_LEDBlinker/source/main.cpp @@ -22,6 +22,9 @@ #include "ble/gap/Gap.h" #include "ble/gap/AdvertisingDataParser.h" #include "pretty_printer.h" +#include "shci.h" +#include "app_conf.h" + const static char PEER_NAME[] = "LED"; @@ -30,6 +33,11 @@ static EventQueue event_queue(/* event count */ 10 * EVENTS_EVENT_SIZE); static DiscoveredCharacteristic led_characteristic; static bool trigger_led_characteristic = false; + +extern "C" int handle_ready_event; +static bool startBLEbyExample = false; +static bool startFUSbyExample = false; + void service_discovery(const DiscoveredService *service) { if (service->getUUID().shortOrLong() == UUID::UUID_TYPE_SHORT) { printf("S UUID-%x attrs[%u %u]\r\n", service->getUUID().getShortUUID(), service->getStartHandle(), service->getEndHandle()); @@ -84,6 +92,9 @@ void trigger_read(const GattWriteCallbackParams *response) { } } +volatile int _fus_option = 0; + + class LEDBlinkerDemo : ble::Gap::EventHandler { public: LEDBlinkerDemo(BLE &ble, events::EventQueue &event_queue) : @@ -91,40 +102,63 @@ class LEDBlinkerDemo : ble::Gap::EventHandler { _event_queue(event_queue), _alive_led(LED1, 1), _actuated_led(LED2, 0), - _is_connecting(false) { } + _is_connecting(false){ } ~LEDBlinkerDemo() { } void start() { - _ble.gap().setEventHandler(this); + _ble.gap().setEventHandler(this); + printf("ble.init\n"); _ble.init(this, &LEDBlinkerDemo::on_init_complete); + printf("ble.init done\n"); + + if( startBLEbyExample && startFUSbyExample) + printf("startBLEbyExample && startFUSbyExample are true, please choose one\n"); + - _event_queue.call_every(500, this, &LEDBlinkerDemo::blink); + if ( startBLEbyExample ) { + printf("start BLE\n"); + SHCI_C2_FUS_StartWs(); + } - _event_queue.dispatch_forever(); + if ( startFUSbyExample ) { + printf("start FUS\n"); + SHCI_C2_FUS_GetState( NULL ); + SHCI_C2_FUS_GetState( NULL ); + } + + printf("handle_ready_event @start %d\n", handle_ready_event); + //_event_queue.call_every(5000, this, &LEDBlinkerDemo::blink); + + _event_queue.dispatch_forever(); } private: + /** Callback triggered when the ble initialization process has finished */ void on_init_complete(BLE::InitializationCompleteCallbackContext *params) { - if (params->error != BLE_ERROR_NONE) { - printf("Ble initialization failed."); - return; - } - print_mac_address(); + printf("handle_ready_event @on_init_complete %d\n", handle_ready_event); - _ble.gattClient().onDataRead(trigger_toggled_write); - _ble.gattClient().onDataWritten(trigger_read); + if( handle_ready_event == 1) { + if (params->error != BLE_ERROR_NONE) { + printf("Ble initialization failed.\n"); + return; + } + + print_mac_address(); + _ble.gattClient().onDataRead(trigger_toggled_write); + _ble.gattClient().onDataWritten(trigger_read); - ble::ScanParameters scan_params; - _ble.gap().setScanParameters(scan_params); - _ble.gap().startScan(); + ble::ScanParameters scan_params; + _ble.gap().setScanParameters(scan_params); + _ble.gap().startScan(); + } } void blink() { - _alive_led = !_alive_led; + _alive_led = !_alive_led; } private: @@ -216,13 +250,19 @@ void schedule_ble_events(BLE::OnEventsToProcessCallbackContext *context) { event_queue.call(Callback(&context->ble, &BLE::processEvents)); } + int main() { + printf("Start Example\n"); + + printf("CFG_OTA_REBOOT_VAL_MSG %d\n", CFG_OTA_REBOOT_VAL_MSG); + CFG_OTA_REBOOT_VAL_MSG = CFG_REBOOT_ON_FW_APP; + BLE &ble = BLE::Instance(); - ble.onEventsToProcess(schedule_ble_events); + //ble.onEventsToProcess(schedule_ble_events); LEDBlinkerDemo demo(ble, event_queue); demo.start(); - + return 0; }