Geo beacon for VF.
Dependencies: MMA8452 aconno_bsp adc52832_common
Diff: main.cpp
- Revision:
- 15:934a04c958f5
- Parent:
- 14:d506c0679c0b
- Child:
- 16:a338d2417fd5
--- a/main.cpp Thu Jul 27 15:04:50 2017 +0000
+++ b/main.cpp Fri Jul 28 12:28:05 2017 +0000
@@ -22,6 +22,7 @@
#define AWAKE_TIME_S (ADV_TIMER_TIME_S+SCAN_TIMER_TIME_S+FREE_TIME_S) /* Was 0.15 */
#define SHORT_SLEEP_TIME_S (0.5) /* Shorter sleep time (s) */
#define SHORT_SLEEP_TIME_PERIOD_S (5) /* Time after a last scanned advertisment. In the period, sleep time is SHORT_SLEEP_TIME */
+#define MAC_SIZE_B (6)
/* Static constants for the BLE example */
@@ -29,7 +30,7 @@
#define MSD_SIZE (18)
#define MSD_ID (0xFF)
-#define BUZZ_TIME_S (0.25) /* Buzz time in s */
+#define BUZZ_TIME_S (0.25) /* 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)
@@ -137,13 +138,18 @@
uint8_t findMSDIndex(const Gap::AdvertisementCallbackParams_t *params){
uint8_t i=0;
uint8_t len;
+ uint8_t min = params->advertisingDataLen;
+ if((params->advertisingDataLen < (MAC_SIZE_B + 2)) || params->advertisingDataLen == 0){
+ // Empty advertisement or not long enough for MAX
+ return 0;
+ }
do{
len = params->advertisingData[i];
i++;
if(params->advertisingData[i] == MSD_ID) return i;
else i += (len-1);
- }while(i<MAX_BLE_PACKET_SIZE);
+ }while(i<min);
return 0;
}
@@ -155,7 +161,7 @@
return 0; // There's no MSD in BLE advertisement data
}
for(i=0; i<6; i++){
- if(!(params->advertisingData[msdOffset+i+3]) == *(myMacAddress+5-i)){
+ if((params->advertisingData[msdOffset+i+3]) != myMacAddress[5-i]){
return 0;
}
}
@@ -166,9 +172,10 @@
* Function is called when BLE radio discovers any kind of advertisment
*/
void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params){
- uint8_t msdOffset;
-
- msdOffset = findMSDIndex(params);
+ uint8_t msdOffset, i;
+
+ //msdOffset = findMSDIndex(params);
+ msdOffset = 4;
if(msdOffset == 0){
return; // There's no MSD in BLE advertisement data
}
@@ -176,7 +183,11 @@
// Follows Manufacturer Specific Data
if ((params->advertisingData[msdOffset+1]) == 0x59){
if ((params->advertisingData[msdOffset+2]) == 0x00){
- if(CheckMac(params, myMacAddress, msdOffset)){
+ for(i=0; i<6; i++){
+ if((params->advertisingData[msdOffset+i+3]) != myMacAddress[5-i]){
+ return;
+ }
+ //if(CheckMac(params, myMacAddress, msdOffset) || 1){
ble.gap().stopScan();
buzzer.write(0.5F);
WakeSleepT.detach();

