Lizzy project

Dependencies:   aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT

Files at this revision

API Documentation at this revision

Comitter:
dbartolovic
Date:
Thu Sep 20 13:20:13 2018 +0000
Branch:
master
Parent:
25:d021d86568e5
Child:
27:724dc5ed4883
Commit message:
Added vodafone compatibility, it can be enabled or disabled with a macro

Changed in this revision

aconno_ble/aconno_ble.cpp Show annotated file Show diff for this revision Revisions of this file
aconno_ble/aconno_ble.h Show annotated file Show diff for this revision Revisions of this file
aconno_ble/lizzy_service.h Show annotated file Show diff for this revision Revisions of this file
aconno_ble/service_macros.h Show annotated file Show diff for this revision Revisions of this file
config/proj_config.h Show annotated file Show diff for this revision Revisions of this file
source/main.cpp Show annotated file Show diff for this revision Revisions of this file
tasks/tasks.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/aconno_ble/aconno_ble.cpp	Thu Sep 20 07:41:02 2018 +0000
+++ b/aconno_ble/aconno_ble.cpp	Thu Sep 20 13:20:13 2018 +0000
@@ -8,6 +8,7 @@
 #include "aconno_ble.h"
 #include "tasks.h"
 #include "lizzy_service.h"
+#include "proj_config.h"
 
 
 /* BLE event queue size */
@@ -53,15 +54,18 @@
 
 void onDataWrittenCallback(const GattWriteCallbackParams *params) 
 {
-    if ((params->handle == lizzy_service->get_buzz_handle()) &&
-        (params->len == 1))
+    if ((params->handle == lizzy_service->getBuzzHandle()))
     {
+#if VODAFONE_COMPATIBILITY == 1
+#else
         if ((uint8_t)true < *(params->data))
-            lizzy_service->set_buzz_state(true);
-            
+            lizzy_service->setBuzzState(true);
+#endif
         updateBuzzLedsT.signal_set(UPDATE_BUZZ_LEDS);
     }
-    else if ((params->handle == lizzy_service->get_red_handle()) &&
+#if VODAFONE_COMPATIBILITY == 1
+#else
+    else if ((params->handle == lizzy_service->getRedHandle()) &&
         (params->len == 1))
     {
         if ((uint8_t)true < *(params->data))
@@ -69,6 +73,7 @@
             
         updateBuzzLedsT.signal_set(UPDATE_BUZZ_LEDS);
     }
+#endif
     else if ((params->handle == lizzy_service->get_green_handle()) &&
         (params->len == 1))
     {
@@ -107,12 +112,18 @@
         return;
     }
     
-    
     lizzy_service = new LizzyService(ble, &init_lizzy);
     ble.gap().onDisconnection(disconnectionCallback);
     ble.gap().onConnection(onConnectionCallback);         
     ble.gattServer().onDataWritten(onDataWrittenCallback);
     
+#if VODAFONE_COMPATIBILITY == 1
+    uint8_t myMacAddress[6];
+    BLEProtocol::AddressType_t temp_address_type;
+    ble.gap().getAddress(&temp_address_type, myMacAddress);
+    lizzy_service->setMac(myMacAddress);    // Update MAC address
+#endif
+    
     // Setup event handling. This is needed only with services.
     ble.onEventsToProcess(scheduleBleEventsProcessing);
     
@@ -129,8 +140,12 @@
     advertisementPacket.magnetometer[2] = (int16_t)0;
     
     /* setup advertising */
+#if VODAFONE_COMPATIBILITY == 1
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::INCOMPLETE_LIST_128BIT_SERVICE_IDS  , (uint8_t*)UUID, sizeof(UUID));
+#else
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
-    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(uint8_t)*11);
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertisementPacket));
+#endif
     ble.gap().setAdvertisingInterval(ADV_INTERVAL_MS);
     //ble.gap().startAdvertising();
 }
--- a/aconno_ble/aconno_ble.h	Thu Sep 20 07:41:02 2018 +0000
+++ b/aconno_ble/aconno_ble.h	Thu Sep 20 13:20:13 2018 +0000
@@ -11,9 +11,12 @@
 #include "ble/BLE.h"
 #include "GapAdvertisingData.h"
 #include "lizzy_service.h"
+#include "proj_config.h"
 
-#define MSD_SIZE_b          (10)
-#define ADV_INTERVAL_MS     (100)
+#if VODAFONE_COMPATIBILITY == 1
+const uint8_t UUID[16] = {0xE1, 0x61, 0x35, 0xBA, 0xC0, 0xEC, 0x47, 0x2A, 0x98, 0x00, 0xAF, 0x18, 0x43, 0xFF, 0x05, 0x00};
+#endif
+
 #define APPLICATION_ID      (0xCF170059) //(0xCF170059)
 
 #define LSB_VALUE           (0xFFFF)    // this is divided by 2^16 in app
--- a/aconno_ble/lizzy_service.h	Thu Sep 20 07:41:02 2018 +0000
+++ b/aconno_ble/lizzy_service.h	Thu Sep 20 13:20:13 2018 +0000
@@ -3,6 +3,8 @@
 
 #include "mbed.h"
 #include "ble/BLE.h"
+#include "service_macros.h"
+#include "proj_config.h"
 
 #define NUM_LEDS        (3)
 #define NUM_AXIS        (3)
@@ -21,7 +23,7 @@
     public:
         const static uint16_t LIZZY_SERVICE_UUID = 0xA000;
         const static uint16_t BUZZ_UUID = 0xA001;
-        const static uint16_t RED_UUID = 0xA002;
+        const static uint16_t MAC_RED_UUID = 0xA002;
         const static uint16_t GREEN_UUID = 0xA003;
         const static uint16_t BLUE_UUID = 0xA004;
         const static uint16_t ACC_LSB_UUID = 0xA005;
@@ -29,14 +31,25 @@
 
         LizzyService(BLEDevice &_ble, init_lizzy_t *init) :
               ble(_ble),
+#if VODAFONE_COMPATIBILITY == 1
+              buzz(BUZZ_UUID, (uint8_t*)&(init->buzz)),
+              mac(MAC_RED_UUID, (uint8_t*)&(init->leds[0]), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
+#else
               buzz(BUZZ_UUID, &(init->buzz), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
-              red_led(RED_UUID, &(init->leds[0]), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
+              redLed(MAC_RED_UUID, &(init->leds[0]), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
+#endif
               green_led(GREEN_UUID, &(init->leds[1]), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
               blue_led(BLUE_UUID, &(init->leds[2]), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
               acc_lsb(ACC_LSB_UUID, &(init->acc_lsb), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
               acc_data(ACC_DATA_UUID, init->acc_data, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
         {
-            GattCharacteristic *charTable[] = {&buzz, &red_led, &green_led, &blue_led, &acc_lsb, &acc_data};     // Add characteristick in table
+            GattCharacteristic *charTable[] = {
+#if VODAFONE_COMPATIBILITY == 1
+                &buzz, &mac,
+#else
+                &buzz, &redLed,
+#endif
+                &green_led, &blue_led, &acc_lsb, &acc_data};     // Add characteristick in table
             GattService AckService(LIZZY_SERVICE_UUID, charTable, sizeof(charTable)/sizeof(GattCharacteristic *));   
             ble.gattServer().addService(AckService); // Add service in the BLE
         }
@@ -46,12 +59,13 @@
         }
         
         // Characteristic setters.
+/*
         inline void set_buzz_state(bool new_state){
             ble.gattServer().write(buzz.getValueHandle(), (uint8_t*)&new_state, sizeof(new_state));
         }
         inline void set_red_state(bool new_state){
             ble.gattServer().write(red_led.getValueHandle(), (uint8_t*)&new_state, sizeof(new_state));
-        }
+        }*/
         inline void set_green_state(bool new_state){
             ble.gattServer().write(green_led.getValueHandle(), (uint8_t*)&new_state, sizeof(new_state));
         }
@@ -67,6 +81,7 @@
         }
         
         // Characteristic getters.
+/*
         inline bool get_buzz_state(){
             bool tmp;
             uint16_t size = sizeof(tmp);
@@ -78,7 +93,7 @@
             uint16_t size = sizeof(tmp);
             ble.gattServer().read(red_led.getValueHandle(), (uint8_t*)&tmp, &size);
             return tmp;
-        }
+        }*/
         inline bool get_green_state(){
             bool tmp;
             uint16_t size = sizeof(tmp);
@@ -91,13 +106,14 @@
             ble.gattServer().read(blue_led.getValueHandle(), (uint8_t*)&tmp, &size);
             return tmp;
         }
-        
+
+/*
         inline GattAttribute::Handle_t get_buzz_handle(){
             return buzz.getValueHandle();
         }
         inline GattAttribute::Handle_t get_red_handle(){
             return red_led.getValueHandle();
-        }
+        }*/
         inline GattAttribute::Handle_t get_green_handle(){
             return green_led.getValueHandle();
         }
@@ -110,12 +126,21 @@
         }inline GattAttribute::Handle_t get_acc_data_handle(){
             return acc_data.getValueHandle();
         }
+
+#if VODAFONE_COMPATIBILITY == 1
+        CHARACTERISTIC_A(WriteOnly, uint8_t, 4, buzz, Buzz);
+        CHARACTERISTIC_A(ReadOnly, uint8_t, 6, mac, Mac);
+#else
+        CHARACTERISTIC_W(ReadWrite, bool, buzz, Buzz);
+        CHARACTERISTIC_W(ReadWrite, bool, redLed, RedLed);
+#endif
         
     private:
         BLEDevice &ble;
         // Create new characteristics
+/*
         ReadWriteGattCharacteristic<bool> buzz;
-        ReadWriteGattCharacteristic<bool> red_led;
+        ReadWriteGattCharacteristic<bool> red_led;*/
         ReadWriteGattCharacteristic<bool> green_led;
         ReadWriteGattCharacteristic<bool> blue_led;
         
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aconno_ble/service_macros.h	Thu Sep 20 13:20:13 2018 +0000
@@ -0,0 +1,85 @@
+/*
+ * Made by Dominik @ aconno
+ * All rights reserved
+ *
+ */
+
+#ifndef __SERVICE_MACROS_H__
+#define __SERVICE_MACROS_H__
+
+
+#define _SERVICE_INIT_T(serv_name)          Init##serv_name
+#define SERVICE_INIT_T(serv_name)           _SERVICE_INIT_T(serv_name)
+
+
+#define CHARACTERISTIC_W(charType, type, var, func)                            \
+                                                                               \
+public:                                                                        \
+                                                                               \
+inline GattAttribute::Handle_t get##func##Handle(){                            \
+    return var.getValueHandle();                                               \
+}                                                                              \
+                                                                               \
+inline void set##func(const type &new_state){                                  \
+    ble.gattServer().write(var.getValueHandle(),                               \
+                           (uint8_t*)&new_state,                               \
+                           sizeof(type));                                      \
+}                                                                              \
+                                                                               \
+inline void set##func(type *new_state){                                        \
+    ble.gattServer().write(var.getValueHandle(),                               \
+                           (uint8_t*)new_state,                                \
+                           sizeof(type));                                      \
+}                                                                              \
+                                                                               \
+inline type get##func(){                                                       \
+    type tmp;                                                                  \
+    uint16_t size = sizeof(tmp);                                               \
+    ble.gattServer().read(var.getValueHandle(), (uint8_t*)&tmp,                \
+                                                          &size);              \
+    return tmp;                                                                \
+}                                                                              \
+                                                                               \
+inline type *get##func(type &tmp){                                             \
+    uint16_t size = sizeof(type);                                              \
+    ble.gattServer().read(var.getValueHandle(), (uint8_t*)&tmp,                \
+                                                          &size);              \
+    return &tmp;                                                               \
+}                                                                              \
+                                                                               \
+inline type *get##func(type *tmp){                                             \
+    uint16_t size = sizeof(type);                                              \
+    ble.gattServer().read(var.getValueHandle(), (uint8_t*)tmp,                 \
+                                                          &size);              \
+    return tmp;                                                                \
+}                                                                              \
+                                                                               \
+private:                                                                       \
+charType##GattCharacteristic<type> var
+
+
+#define CHARACTERISTIC_A(charType, type, size_, var, func)                     \
+                                                                               \
+public:                                                                        \
+                                                                               \
+inline GattAttribute::Handle_t get##func##Handle(){                            \
+    return var.getValueHandle();                                               \
+}                                                                              \
+                                                                               \
+inline void set##func(type *new_state){                                        \
+    ble.gattServer().write(var.getValueHandle(),                               \
+                           (uint8_t*)new_state,                                \
+                           sizeof(type)*size_);                                \
+}                                                                              \
+                                                                               \
+inline type *get##func(type *tmp){                                             \
+    uint16_t size = sizeof(type)*size_;                                        \
+    ble.gattServer().read(var.getValueHandle(), (uint8_t*)tmp,                 \
+                                                          &size);              \
+    return tmp;                                                                \
+}                                                                              \
+                                                                               \
+private:                                                                       \
+charType##ArrayGattCharacteristic<type, size_> var
+
+#endif //__SERVICE_MACROS_H__
--- a/config/proj_config.h	Thu Sep 20 07:41:02 2018 +0000
+++ b/config/proj_config.h	Thu Sep 20 13:20:13 2018 +0000
@@ -7,15 +7,17 @@
 #define DEBUG_LED                       (0)
 #define NANO_MODULE                     (0)
 #define NORMAL_AXIS                     (1)
+#define VODAFONE_COMPATIBILITY          (1)
 #define TEST_LEDS_BUZZ                  (0)
 
+#define ADV_INTERVAL_MS                 (100)
 #define POWER_UP_DELAY_MS               (200)
 #define MEASURE_INTERVAL_MS             (500)
-#define ACTIVE_PERIOD_MS                (5000)
+#define ACTIVE_PERIOD_MS                (50000)
 
 #define LONG_SLEEP_S                    (300)
 
-#define INT1_THRESHOLD                  (15)
+#define INT1_THRESHOLD                  (16)
 #define INT1_DUR                        (5)
 #define ACC_ODR_MODE                    (ODR_25Hz)
 
--- a/source/main.cpp	Thu Sep 20 07:41:02 2018 +0000
+++ b/source/main.cpp	Thu Sep 20 13:20:13 2018 +0000
@@ -32,7 +32,7 @@
     __disable_irq();
     
     mems.clearIntFlag();
-    //redLed = !redLed;
+    redLed = !redLed;
     
     measureT.signal_set(START_MEAS);
     
--- a/tasks/tasks.cpp	Thu Sep 20 07:41:02 2018 +0000
+++ b/tasks/tasks.cpp	Thu Sep 20 13:20:13 2018 +0000
@@ -170,27 +170,44 @@
 
 void updateBuzzLedsF()
 {
+#if VODAFONE_COMPATIBILITY == 1
+    const uint8_t startBuzz = 0xBA;
+#endif    
+    
     while (1)
     {
         Thread::signal_wait(UPDATE_BUZZ_LEDS);
         updateBuzzLedsT.signal_clr(UPDATE_BUZZ_LEDS);
-        
-        if (buzzer.get_state() != (lizzy_service->get_buzz_state()))
+
+#if VODAFONE_COMPATIBILITY == 1
+        uint8_t tmpBuzzState[4];
+        if( buzzer.get_state() != 
+            (lizzy_service->getBuzz(tmpBuzzState)[0] == startBuzz) )
+#else
+        if( buzzer.get_state() != (lizzy_service->getBuzz()) )
+#endif
         {
-            if (lizzy_service->get_buzz_state())
+#if VODAFONE_COMPATIBILITY == 1
+            if( tmpBuzzState[0] == startBuzz )
+#else
+            if( lizzy_service->getBuzz() )
+#endif
                 buzzer.enable();
             else
                 buzzer.disable();
         }
-        if (!redLed != (lizzy_service->get_red_state()))
+#if VODAFONE_COMPATIBILITY == 1
+#else
+        if( !redLed != (lizzy_service->getRedLed()) )
         {
-            redLed = !(lizzy_service->get_red_state());
+            redLed = !(lizzy_service->getRedLed());
         }
-        if (!greenLed != (lizzy_service->get_green_state()))
+#endif
+        if( !greenLed != (lizzy_service->get_green_state()) )
         {
             greenLed = !(lizzy_service->get_green_state());
         }
-        if (!blueLed != (lizzy_service->get_blue_state()))
+        if( !blueLed != (lizzy_service->get_blue_state()) )
         {
             blueLed = !(lizzy_service->get_blue_state());
         }
@@ -203,51 +220,14 @@
     {
         Thread::signal_wait(MEAS_DONE);
         bleT.signal_clr(MEAS_DONE);
-        
-        /*
-        printf("%6d\t", advertisementPacket.accelerometer[0]);
-        printf("%6d\t", advertisementPacket.accelerometer[1]);
-        printf("%6d\r\n", advertisementPacket.accelerometer[2]);
-        */
 
-        
-        /* setup advertising */
-        
-        
-        /*
-        GapAdvertisingData advetisementData = GapAdvertisingData();
-        advetisementData = ble->getAdvertisingData();
-        advetisementData.updateData(advetisementData.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertising_packet));
-        ble->setAdvertisingData(advetisementData);
-        */
+#if VODAFONE_COMPATIBILITY == 1
+#else
         adv_data = ble->getAdvertisingData();
         adv_data.updateData(adv_data.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertisementPacket));
         ble->setAdvertisingData(adv_data);
-        
-        
-        //printf("Ble advertisement is ON.\r\n");
-        
-        #if DEBUG_LED
-            redLed = 0;
-        #endif
-        //ble->gap().startAdvertising();
-        //wait_ms(1000);
-        
-        //wait_ms(MEASURE_INTERVAL_MS);
-        //wait_ms(1000);
-        
-        //printf("Ble advertisement is OFF.\r\n\r\n");
-        #if DEBUG_LED
-            redLed = 1;
-        #endif
-        //ble->gap().stopAdvertising();
-        /*
-        GapAdvertisingData advetisementData = GapAdvertisingData();
-        advetisementData = ble->getAdvertisingData();
-        advetisementData.updateData(advetisementData.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertising_packet));
-        ble->setAdvertisingData(advetisementData);
-        */
-        //wait_ms(100);
+#endif
+
     }
 }