Geo beacon for VF.

Dependencies:   MMA8452 aconno_bsp adc52832_common

Files at this revision

API Documentation at this revision

Comitter:
jurica238814
Date:
Wed Sep 06 10:41:09 2017 +0000
Parent:
23:729717272b31
Child:
26:148aa2e2460c
Commit message:
Before implementing our pwm driver.

Changed in this revision

AckService.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
--- a/AckService.h	Wed Aug 30 08:10:53 2017 +0000
+++ b/AckService.h	Wed Sep 06 10:41:09 2017 +0000
@@ -15,9 +15,13 @@
                 GattService AckService(ACK_SERVICE_UUID, charTable, sizeof(charTable)/sizeof(GattCharacteristic *));   
                 ble.addService(AckService); // Add service in the BLE
         }
-        void updateMacAddress(uint8_t  *MacAddress){
+        inline void updateMacAddress(uint8_t  *MacAddress){
             ble.gattServer().write(MAC.getValueHandle(), MacAddress, MAC_ADDR_SIZE_B);
         }
+        
+        inline GattAttribute::Handle_t getACKCharacteristicHandle(){
+            return ACK.getValueHandle();
+        }
     private:
         BLEDevice &ble;
         // Create new characteristic
--- a/main.cpp	Wed Aug 30 08:10:53 2017 +0000
+++ b/main.cpp	Wed Sep 06 10:41:09 2017 +0000
@@ -15,15 +15,15 @@
 #include "nrf52_uart.h"
 #include "nrf52_digital.h"
 
-#define DEBUG               (1)
+#define DEBUG               (0)
 #define DEBUG_ACC           (0)
 #define PRINT               (0)
 #define DEBUG_MAC           (0)
 #define DEBUG_CONNECTION    (0)
 #define USE_ACC             (0)
 
-#define SLEEP_TIME_S              (6.0)           /* Sleep time (in s)          */
-#define ADV_TIMER_TIME_S          (0.25)           /* Advertising time (in s)    */
+#define SLEEP_TIME_S              (8.00)           /* Sleep time (in s)          */
+#define ADV_TIMER_TIME_S          (0.50)           /* Advertising time (in s)    */
 #define SCAN_TIMER_TIME_S         (0.25)           /* Scanning time (in s)       */
 #define FREE_TIME_S               (0.1)           /* Time between end of a scanning and sleep mode */
 #define AWAKE_TIME_S              (ADV_TIMER_TIME_S+SCAN_TIMER_TIME_S+FREE_TIME_S)      /* Was 0.15 */
@@ -38,8 +38,8 @@
 #define MSD_SIZE            (18)
 #define MSD_ID              (0xFF)
 
-#define BUZZ_TIME_S         (1)   /* Buzz time in s */
-#define ADV_INTERVAL        (200)   /* Advertising interval (in ms) */
+#define BUZZ_TIME_S         (1)    /* Buzz time in s */
+#define ADV_INTERVAL        (100)   /* Advertising interval (in ms) */
 #define SCAN_INTERVAL       (SCAN_TIMER_TIME_S)   /* Scan interval (in ms) */
 #define SCAN_WINDOW         (SCAN_TIMER_TIME_S)
 
@@ -68,6 +68,8 @@
 uint8_t sleepFlag = false;
 uint8_t tempSleepTime = SLEEP_TIME_S;
 uint8_t msd[MSD_SIZE] = {0x59, 0x00, 0xE1, 0x61, 0x35, 0xBA, 0xC0, 0xEC, 0x47, 0x2A, 0x98, 0x00, 0xAF, 0x18, 0x43, 0xFF, 0x05, 0x00};
+uint8_t startBuzz[2] = {0xBA, 0xBE};
+uint8_t stopBuzz[2] = {0xDE, 0xAD};
 uint8_t myMacAddress[6] = {};   
 uint8_t buzzer_flag = 0;
 
@@ -160,10 +162,10 @@
 }
 
 void onDataWrittenCallback(const GattWriteCallbackParams *params) {
-    if(params->handle == ACK_CHARA_UUID || 1){
+    if(params->handle == ackServicePtr->getACKCharacteristicHandle()){
         // Something is written into AckCharacteristic
-        if(params->data[0] == 0xBA)
-            if(params->data[1] == 0xBE){
+        if(params->data[0] == startBuzz[0]){
+            if(params->data[1] == startBuzz[1]){
                 #if DEBUG_CONNECTION
                     connectedLED = !connectedLED;       // BLUE
                     wait_ms(100);
@@ -179,17 +181,20 @@
                     wait_ms(100);
                 #endif    
                 buzz(BUZZ_PERIOD_US,BUZZ_DURATION_MS);
-                WakeSleepT.detach();
-                WakeSleepT.attach(WakeMeUp, FREE_TIME_S);
-                /*
-                    This function should make advertiser stop
-                */
-                ble.disconnect(Gap::LOCAL_HOST_TERMINATED_CONNECTION);
                 return;
             }
+        }
+     else if(params->data[0] == stopBuzz[0]){
+        if(params->data[1] == stopBuzz[1]){
+            WakeSleepT.detach();
+            WakeSleepT.attach(WakeMeUp, FREE_TIME_S);
+            ble.disconnect(Gap::LOCAL_HOST_TERMINATED_CONNECTION);
+            }
+        }
     }
     else{
-        // Execute this for wrong data written into characteristic   
+        // Execute this for wrong data written into characteristic
+        return;
     }
 }
 
@@ -382,7 +387,7 @@
     sleepFlag = 0;
     switch(radioState){
         case OFF:{
-                radioState = ADVERTISING;
+                radioState = SCANNING;
                 startAdvertising();
                 break;
             }