DongKeun Kang / Mbed OS mbed-os-example-ble-UARTConsol
Revision:
1:2237580e56f1
Parent:
0:f046a5fadbe8
Child:
2:ce6be5c83dde
--- a/source/main.cpp	Thu May 10 14:09:22 2018 +0000
+++ b/source/main.cpp	Fri May 11 14:28:16 2018 +0000
@@ -18,15 +18,12 @@
 #include <mbed.h>
 #include "ble/BLE.h"
 #include "ble/Gap.h"
-#include "ble/services/BatteryService.h"
+#include "ble/services/UARTService.h"
 
 DigitalOut led1(LED1, 1);
+DigitalOut led2(LED2, 1);
 
-const static char     DEVICE_NAME[] = "BATTERY";
-static const uint16_t uuid16_list[] = {GattService::UUID_BATTERY_SERVICE};
-
-static uint8_t batteryLevel = 50;
-static BatteryService* batteryServicePtr;
+static UARTService* uartServicePtr;
 
 static EventQueue eventQueue(/* event count */ 16 * EVENTS_EVENT_SIZE);
 
@@ -35,14 +32,7 @@
     BLE::Instance().gap().startAdvertising();
 }
 
-void updateSensorValue() {
-    batteryLevel++;
-    if (batteryLevel > 100) {
-        batteryLevel = 20;
-    }
 
-    batteryServicePtr->updateBatteryLevel(batteryLevel);
-}
 
 void blinkCallback(void)
 {
@@ -50,7 +40,7 @@
 
     BLE &ble = BLE::Instance();
     if (ble.gap().getState().connected) {
-        eventQueue.call(updateSensorValue);
+       // eventQueue.call(updateSensorValue);
     }
 }
 
@@ -95,18 +85,32 @@
     }
 
     ble.gap().onDisconnection(disconnectionCallback);
+    ble.gap().onDataWritten( DataWriteCallback );
+    ble.gap().onDataRead( DataReadCallback );
 
     /* Setup primary service */
-    batteryServicePtr = new BatteryService(ble, batteryLevel);
+    uartServicePtr = new UARTService(ble);
 
     /* Setup advertising */
+  #if 0  
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *) uuid16_list, sizeof(uuid16_list));
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *) DEVICE_NAME, sizeof(DEVICE_NAME));
     ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
+  
+#else 
+
+    /* setup advertising */
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
+    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
+                                     (const uint8_t *)"BLE UART", sizeof("BLE UART") - 1);
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
+                                     (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
+ #endif  
     ble.gap().setAdvertisingInterval(1000); /* 1000ms */
     ble.gap().startAdvertising();
-
+                                       
     printMacAddress();
 }