Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API_modified_UARTService_for_IDB0XA1_nRF_UART BLE_Observer_Nucleo X_NUCLEO_IDB0XA1 mbed
Fork of BLE_Observer_Nucleo by
Revision 1:2d5632f16714, committed 2018-07-31
- Comitter:
- TianyouTong
- Date:
- Tue Jul 31 11:14:25 2018 +0000
- Parent:
- 0:39b311448c9e
- Commit message:
- Published new library
Changed in this revision
diff -r 39b311448c9e -r 2d5632f16714 BLE_API.lib --- a/BLE_API.lib Fri Dec 04 12:48:00 2015 +0000 +++ b/BLE_API.lib Tue Jul 31 11:14:25 2018 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#1a37289c954e +https://os.mbed.com/users/TianyouTong/code/BLE_API_modified_UARTService_for_IDB0XA1/#d4062baab746
diff -r 39b311448c9e -r 2d5632f16714 BLE_UART_IDB05A1.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BLE_UART_IDB05A1.lib Tue Jul 31 11:14:25 2018 +0000 @@ -0,0 +1,1 @@ +http://os.mbed.com/users/vcoubard/code/BLE_Observer_Nucleo/#39b311448c9e
diff -r 39b311448c9e -r 2d5632f16714 main.cpp --- a/main.cpp Fri Dec 04 12:48:00 2015 +0000 +++ b/main.cpp Tue Jul 31 11:14:25 2018 +0000 @@ -1,5 +1,5 @@ /* mbed Microcontroller Library - * Copyright (c) 2006-2015 ARM Limited + * Copyright (c) 2006-2013 ARM Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,42 +13,97 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + +#include <string.h> #include "mbed.h" #include "BLE.h" + +#include "UARTService.h" +#include "BatteryService.h" +#include "DeviceInformationService.h" +static const uint16_t uuid16_list[] = {GattService::UUID_BATTERY_SERVICE, + GattService::UUID_DEVICE_INFORMATION_SERVICE}; -BLE ble; -DigitalOut led1(LED1); +Serial pc(USBTX, USBRX); +BLEDevice ble; + +//Used to access the defined in main UARTService object globally. +UARTService *uart; +//Keeping a receive buffer to alter the data received. +uint8_t DatatoSend[1000]; + +void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) +{ + pc.printf("\n Disconnected.!!\n"); + pc.printf("\n Restarting the advertising process.\n"); + ble.startAdvertising(); +} + void periodicCallback(void) { - led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */ } -void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params) { - - printf("Adv peerAddr: [%02x %02x %02x %02x %02x %02x] rssi %d, ScanResp: %u, AdvType: %u\r\n", - params->peerAddr[5], params->peerAddr[4], params->peerAddr[3], params->peerAddr[2], params->peerAddr[1], params->peerAddr[0], - params->rssi, params->isScanResponse, params->type); -#if DUMP_ADV_DATA - for (unsigned index = 0; index < params->advertisingDataLen; index++) { - printf("%02x ", params->advertisingData[index]); +void onDataWritten(const GattWriteCallbackParams *params) +{ + /*if received something, print it out on PC screen*/ + if ((uart != NULL) && (params->handle == uart->getTXCharacteristicHandle())) { + uint16_t bytesRead = params->len; + + pc.printf("Data Received\n"); + /*for all received data, send a copy back to the BLE central(in this case the phone app)*/ + for(int j=0;j<bytesRead;j++) + { + pc.printf(" %x\n",*((params->data)+j)); + DatatoSend[j]=(*((params->data)+j)); + } + + wait(1); + ble.updateCharacteristicValue(uart->getRXCharacteristicHandle(), DatatoSend, bytesRead); + //Use the below statement for loopback. + //ble.updateCharacteristicValue(uart->getRXCharacteristicHandle(), params->data, bytesRead); + + /*print out what have just been sent*/ + pc.printf("Data Sent\n"); + for(int j=0;j<bytesRead;j++) + { + pc.printf(" %x\n",DatatoSend[j]); + } + wait(1); } - printf("\r\n"); -#endif /* DUMP_ADV_DATA */ } int main(void) { - led1 = 1; + + pc.baud(9600); + pc.printf("Hello, starting BlueNRG Serial Console Demo!\n"); Ticker ticker; ticker.attach(periodicCallback, 1); - + + pc.printf("Initialising the module\n\r"); ble.init(); - - ble.gap().setScanParams(500 /* scan interval */, 200 /* scan window */); - ble.gap().startScan(advertisementCallback); - + ble.onDisconnection(disconnectionCallback); + ble.onDataWritten(onDataWritten); + + UARTService uartService(ble); + uart = &uartService; + + BatteryService battery(ble); + DeviceInformationService deviceInfo(ble, "ARM", "Model1", "SN1", "hw-rev1", "fw-rev1", "soft-rev1"); + + /* setup advertising */ + ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); + ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); + ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, + (const uint8_t *)"BLE UART", sizeof("BLE UART") - 1); + ble.accumulateAdvertisingPayload(GapAdvertisingData::INCOMPLETE_LIST_128BIT_SERVICE_IDS, + (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed)); + ble.accumulateAdvertisingPayload(GapAdvertisingData::INCOMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); + ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */ + ble.startAdvertising(); + pc.printf("Start Advertising.\n"); + while (true) { ble.waitForEvent(); }
diff -r 39b311448c9e -r 2d5632f16714 mbed.bld --- a/mbed.bld Fri Dec 04 12:48:00 2015 +0000 +++ b/mbed.bld Tue Jul 31 11:14:25 2018 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/165afa46840b \ No newline at end of file +https://os.mbed.com/users/mbed_official/code/mbed/builds/a7c7b631e539 \ No newline at end of file