Updated to latest online libraries (See also mbed Apps: HelloBlue, FOTA4)

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_Default_APP by Yihui Xiong

Revision:
2:97f1622aef50
Parent:
0:29068834cf22
--- a/main.cpp	Fri Oct 10 03:36:28 2014 +0000
+++ b/main.cpp	Fri Jan 30 11:39:58 2015 +0000
@@ -1,5 +1,5 @@
 /* mbed Microcontroller Library
- * Copyright (c) 2006-2013 ARM Limited
+ * Copyright (c) 2006-2015 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,66 +13,72 @@
  * 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;
-
-const char *deviceName = "DefaultApp";
-
+UARTService *uartServicePtr;
+ 
+const char *deviceName = "DefaultAppR2";
+const char *ping = "ping";
+ 
 void periodicCallback(void)
 {
     DEBUG("ping\r\n");
+    if (uartServicePtr != NULL) { 
+        ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), (const uint8_t *) ping, strlen(ping));
+    }
 }
-
+ 
 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
 {
     DEBUG("Disconnected!\n\r");
     DEBUG("Restarting the advertising process\n\r");
     ble.startAdvertising();
 }
-
+ 
 int main(void)
 {
     Ticker ticker;
     ticker.attach(periodicCallback, 1);
-
-    DEBUG("Initialising BTLE transport\n\r");
+ 
+    DEBUG("Initialising BTLE transport.\n\r");
     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.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");
-
+ 
+    //DeviceInformationService deviceInfo(ble, "ARM", "Model1", "SN1000", "hw-rev1", "fw-rev1");
+    DeviceInformationService deviceInfo(ble, "ARM", deviceName, "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);
-    uartService.retargetStdout();
-
+    uartServicePtr = &uartService;
+ 
     for (;;) {
         ble.waitForEvent();
     }