Dmitry Vilesov / Mbed 2 deprecated power_switch

Dependencies:   mbed BLE_API nRF51822

Files at this revision

API Documentation at this revision

Comitter:
vilesovds
Date:
Thu Oct 22 19:52:59 2015 +0000
Parent:
2:ed001667a2b6
Child:
4:adfb32273577
Commit message:
added: ServicePower src

Changed in this revision

bleservices/ServicePower.cpp Show annotated file Show diff for this revision Revisions of this file
bleservices/ServicePower.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bleservices/ServicePower.cpp	Thu Oct 22 19:52:59 2015 +0000
@@ -0,0 +1,9 @@
+#include "ServicePower.h"
+#define UUID_POWER(FIRST, SECOND) {\
+0xd4, 0x9f, FIRST, SECOND, 0xce,0xb2, 0x4c, 0x39, 0xa4, 0xea,\
+0x85, 0xfa, 0xfa, 0xae, 0x22, 0xbf\
+}
+
+const uint8_t Power_service_UUID[UUID::LENGTH_OF_LONG_UUID]    = UUID_POWER(0x20, 0x80);
+const uint8_t Power_value_char_UUID[UUID::LENGTH_OF_LONG_UUID] = UUID_POWER(0x20, 0x81);
+const uint8_t Power_state_char_UUID[UUID::LENGTH_OF_LONG_UUID] = UUID_POWER(0x20, 0x82);
--- a/bleservices/ServicePower.h	Thu Oct 22 09:08:15 2015 +0000
+++ b/bleservices/ServicePower.h	Thu Oct 22 19:52:59 2015 +0000
@@ -6,14 +6,9 @@
 #include "Light.h"
 #include "FlashStore.h"
 
-#define UUID_POWER(FIRST, SECOND) {\
-0xd4, 0x9f, FIRST, SECOND, 0xce,0xb2, 0x4c, 0x39, 0xa4, 0xea,\
-0x85, 0xfa, 0xfa, 0xae, 0x22, 0xbf\
-}
-
-static const uint8_t UUID_power_service[]    = UUID_POWER(0x20, 0x80);
-static const uint8_t UUID_power_value_char[] = UUID_POWER(0x20, 0x81);
-static const uint8_t UUID_power_state_char[] = UUID_POWER(0x20, 0x82);
+extern const uint8_t Power_service_UUID[UUID::LENGTH_OF_LONG_UUID];
+extern const uint8_t Power_value_char_UUID[UUID::LENGTH_OF_LONG_UUID];
+extern const uint8_t Power_state_char_UUID[UUID::LENGTH_OF_LONG_UUID];
 
 class ServicePower {
    
@@ -24,8 +19,8 @@
         Power(_Power),
         dayLight(_dayLight),
         Store(_Store),        
-        valueCharacteristic(UUID_power_value_char, &powerValue, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
-        stateCharacteristic(UUID_power_state_char, &powerState)
+        valueCharacteristic(Power_value_char_UUID, &powerValue, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
+        stateCharacteristic(Power_state_char_UUID, &powerState)
     {
         setupService();
     }
@@ -44,7 +39,7 @@
 protected:
     void setupService(void) {
         GattCharacteristic *characteristics[] = {&stateCharacteristic, &valueCharacteristic};
-        GattService powerService(UUID_power_service, characteristics, sizeof(characteristics) / sizeof(GattCharacteristic *));
+        GattService powerService(Power_service_UUID, characteristics, sizeof(characteristics) / sizeof(GattCharacteristic *));
 
         powerState = false;
         powerValue = 0.0;
--- a/main.cpp	Thu Oct 22 09:08:15 2015 +0000
+++ b/main.cpp	Thu Oct 22 19:52:59 2015 +0000
@@ -35,11 +35,13 @@
     //ServiceDeviceInformation deviceService(ble, "Seed", "AEAB00", "AEAB00-010000001", NULL, "1.0.0-alfa", NULL);
     ServicePower    powerService(ble, serial, power, light, store);  
     
-    static const uint16_t bleservices_uuid16_list[] = {GattService::UUID_DEVICE_INFORMATION_SERVICE, GattService::UUID_SCAN_PARAMETERS_SERVICE};
-    
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)bleservices_uuid16_list, sizeof(bleservices_uuid16_list));
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);    
-    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
+
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
+                                     (const uint8_t *)"POWER SWITCH", sizeof("POWER SWITCH") - 1);
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
+                                     (const uint8_t *)Power_service_UUID, sizeof(Power_service_UUID));
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);    
+    ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
 
     ble.gap().setAdvertisingInterval(1000); 
     ble.gap().startAdvertising();