Indoor positioning. Central unit.

Dependencies:   aconno_SEGGER_RTT

Committer:
dbartolovic
Date:
Tue Mar 06 15:45:34 2018 +0000
Revision:
1:2bdc506d8baa
Parent:
0:07a75b2fae14
Child:
2:1b85a28b1e68
Added advertisement of peripheral modules MACs and RSSI values

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jurica238814 0:07a75b2fae14 1 /*
jurica238814 0:07a75b2fae14 2 *
jurica238814 0:07a75b2fae14 3 *
jurica238814 0:07a75b2fae14 4 */
jurica238814 0:07a75b2fae14 5
jurica238814 0:07a75b2fae14 6 #include "tasks.h"
jurica238814 0:07a75b2fae14 7 #include "aconno_ble.h"
jurica238814 0:07a75b2fae14 8
jurica238814 0:07a75b2fae14 9 #if DEBUG_LED
jurica238814 0:07a75b2fae14 10 extern DigitalOut advLed;
jurica238814 0:07a75b2fae14 11 extern DigitalOut scanLed;
jurica238814 0:07a75b2fae14 12 extern DigitalOut periodicLed;
jurica238814 0:07a75b2fae14 13 #endif
jurica238814 0:07a75b2fae14 14
dbartolovic 1:2bdc506d8baa 15
dbartolovic 1:2bdc506d8baa 16 // BLE global data
dbartolovic 1:2bdc506d8baa 17 GapAdvertisingData adv_data = GapAdvertisingData();
dbartolovic 1:2bdc506d8baa 18
dbartolovic 1:2bdc506d8baa 19
jurica238814 0:07a75b2fae14 20 void periodicCallback(BLE *ble)
jurica238814 0:07a75b2fae14 21 {
jurica238814 0:07a75b2fae14 22 while(true)
jurica238814 0:07a75b2fae14 23 {
jurica238814 0:07a75b2fae14 24 ble->waitForEvent();
jurica238814 0:07a75b2fae14 25 #if DEBUG_LED
jurica238814 0:07a75b2fae14 26 periodicLed = !periodicLed;
jurica238814 0:07a75b2fae14 27 #endif
jurica238814 0:07a75b2fae14 28 wait(PERIODIC_CALLBACK_S);
jurica238814 0:07a75b2fae14 29 }
jurica238814 0:07a75b2fae14 30 }
jurica238814 0:07a75b2fae14 31
jurica238814 0:07a75b2fae14 32 void bleStartAdvertising(BLE *ble)
jurica238814 0:07a75b2fae14 33 {
jurica238814 0:07a75b2fae14 34 while(true)
jurica238814 0:07a75b2fae14 35 {
dbartolovic 1:2bdc506d8baa 36 adv_data = ble->getAdvertisingData();
dbartolovic 1:2bdc506d8baa 37 adv_data.updateData(adv_data.MANUFACTURER_SPECIFIC_DATA, (uint8_t*)MSD, MSD_SIZE_b);
dbartolovic 1:2bdc506d8baa 38 ble->setAdvertisingData(adv_data);
dbartolovic 1:2bdc506d8baa 39
jurica238814 0:07a75b2fae14 40 ble->gap().startAdvertising();
jurica238814 0:07a75b2fae14 41 printf("Advertisement started.\r\n");
jurica238814 0:07a75b2fae14 42 #if DEBUG_LED
jurica238814 0:07a75b2fae14 43 advLed = 0;
jurica238814 0:07a75b2fae14 44 #endif
jurica238814 0:07a75b2fae14 45 wait(ADVERTISING_DURATION_S);
jurica238814 0:07a75b2fae14 46 wait_ms(1000);
jurica238814 0:07a75b2fae14 47 ble->gap().stopAdvertising();
jurica238814 0:07a75b2fae14 48 printf("Advertisement stopped.\r\n");
jurica238814 0:07a75b2fae14 49 #if DEBUG_LED
jurica238814 0:07a75b2fae14 50 advLed = 1;
jurica238814 0:07a75b2fae14 51 #endif
jurica238814 0:07a75b2fae14 52 wait(BLE_SLEEP_DURATION_S);
jurica238814 0:07a75b2fae14 53 wait_ms(1000);
jurica238814 0:07a75b2fae14 54 }
jurica238814 0:07a75b2fae14 55 }
jurica238814 0:07a75b2fae14 56
jurica238814 0:07a75b2fae14 57 void bleStartScanning(BLE *ble)
jurica238814 0:07a75b2fae14 58 {
jurica238814 0:07a75b2fae14 59 while(true)
jurica238814 0:07a75b2fae14 60 {
jurica238814 0:07a75b2fae14 61 ble->gap().setScanParams(1500, 400);
jurica238814 0:07a75b2fae14 62 ble->gap().startScan(advertisementCallback);
jurica238814 0:07a75b2fae14 63 Thread::signal_wait(0x00023456);
jurica238814 0:07a75b2fae14 64 //Thread::signal_clr(ACC_INT_SIG);
jurica238814 0:07a75b2fae14 65 //bleT.signal_set(DISABLE_BLE_SIG);
jurica238814 0:07a75b2fae14 66 }
jurica238814 0:07a75b2fae14 67 }