This is a modified "BLE_Default_App". It doesn't use retargetStdout() which allows it to work with online Libs available on 20150123 (nRF51822, BLE_API)
Dependencies: BLE_API mbed nRF51822
App for FOTA testing:
- IO:
- Blinks a LED on platform to show App alive
- LEDs also follow buttons to show immediate response.
- BLE UART has ping message, and also echos back any received bytes (Use with Android App: nRF UART 2.0).
- It compiles and runs as FOTA and non-FOTA platform which may assist debugging
- platform "Nordic nRF51822 FOTA" for FOTA Loading
- platform "Nordic nRF51822" for mbed drive loading
- Supports mbed and non-mbed PCBs (all compiled using platform "Nordic nRF51822 FOTA")
- Compile options available for:
- nRF51822-mkit (Includes USB Serial Debug)
- nRF51822-EK
- nRF51822-Beacon (nRFBeacon)
- Atomwear (Button and LED on main PCB only)
- *If anyone gets this working with other publicly available PCBs let me know and we can add it in
main.cpp
- Committer:
- prussell
- Date:
- 2015-01-24
- Revision:
- 1:832e6e27cc49
- Parent:
- 0:aa7314f3fa84
- Child:
- 2:0931d94f42a2
File content as of revision 1:832e6e27cc49:
/* mbed Microcontroller Library * 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. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "mbed.h" #include "BLEDevice.h" #include "DFUService.h" #include "UARTService.h" #include "DeviceInformationService.h" #define NEED_CONSOLE_OUTPUT 1 /* Set this if you need debug messages on the console; * it will have an impact on code-size and power consumption. */ #if NEED_CONSOLE_OUTPUT #define DEBUG(...) { printf(__VA_ARGS__); } #else #define DEBUG(...) /* nothing */ #endif /* #if NEED_CONSOLE_OUTPUT */ BLEDevice ble; UARTService *uartServicePtr; //const char *deviceName = "DefaultApp"; const char *pcDeviceName = "FOTA4"; const char *pcPing = "f4\n"; // Need "\n" to for BLE to Tx. void periodicCallback(void) { //DEBUG("ping\r\n"); DEBUG("p4\n"); ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), (const uint8_t *)pcPing, strlen(pcPing)); // BLE UART = Ping Message } void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) { //DEBUG("Disconnected!\n\r"); DEBUG("Disconnected!\n"); //DEBUG("Restarting the advertising process\n\r"); DEBUG("Restart Advertising\n"); ble.startAdvertising(); } void onDataWritten(const GattCharacteristicWriteCBParams *params) { //if ((uartServicePtr != NULL) && (params->charHandle == uartServicePtr->txCharacteristic.getValueAttribute().getHandle())) if ((uartServicePtr != NULL) && (params->charHandle == uartServicePtr->getTXCharacteristicHandle())) { uint16_t bytesRead = params->len; DEBUG("BLE-UART Echo Rx[%u]=[%*s]\n", bytesRead, params->len, params->data); ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), params->data, bytesRead); } else { DEBUG("Unknown Characteristic Written, Handle:%d\n", params->charHandle); } } int main(void) { Ticker ticker; ticker.attach(periodicCallback, 1); //DEBUG("Initialising BTLE transport\n\r"); DEBUG("BLE Init\n"); ble.init(); ble.onDisconnection(disconnectionCallback); ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); //ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, (const uint8_t *)deviceName, strlen(deviceName)); ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, (const uint8_t *)pcDeviceName, strlen(pcDeviceName)); ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); /* needs to be connectable to allow use of DFUService */ ble.setAdvertisingInterval(1600); /* 1s; in multiples of 0.625ms. */ ble.startAdvertising(); DeviceInformationService deviceInfo(ble, "ARM", "Model1", "SN1000", "hw-rev1", "fw-rev1"); /* Enable over-the-air firmware updates. Instantiating DFUSservice introduces a * control characteristic which can be used to trigger the application to * handover control to a resident bootloader. */ DFUService dfu(ble); /* Setup a BLE service for console output. Redirect stdout to BLE-UART. */ UARTService uartService(ble); uartServicePtr = &uartService; // uartService.retargetStdout(); //PR: Doesn't work with online libs BLE_API and nRF51822 updated 2015Jan23 for (;;) { ble.waitForEvent(); } }