private void didRangeBeacons(object s, CLRegionBeaconsRangedEventArgs e)
        {
            foreach (var detectedBeacon in e.Beacons)
            {
                string beaconIdentifier = iBeaconEventHolder.GenerateBeaconIdentifyStr(
                    new Guid(detectedBeacon.ProximityUuid.ToString()),
                    detectedBeacon.Major.UInt16Value,
                    detectedBeacon.Minor.UInt16Value);

                if (!_beaconEventHolderDict.ContainsKey(beaconIdentifier))
                {
                    return;
                }

                iBeaconEventHolder eventHolder = _beaconEventHolderDict[beaconIdentifier];
                foreach (iBeaconEventDetail eventDetail in eventHolder.EventList)
                {
                    if (eventDetail.ThresholdRssi < detectedBeacon.Rssi &&
                        eventDetail.LastTriggeredDateTime < DateTime.Now.AddMilliseconds(-1 * eventDetail.EventTriggerIntervalMilliSec))
                    {
                        eventDetail.LastTriggeredDateTime = DateTime.Now;
                        eventDetail.Function();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void AddObservableBeacon(Guid uuid)
        {
            iBeaconEventHolder eventHolder = new iBeaconEventHolder(uuid, null, null);

            if (!_beaconEventHolderDict.ContainsKey(eventHolder.BeaconIdentifyStr))
            {
                _beaconEventHolderDict.Add(eventHolder.BeaconIdentifyStr, eventHolder);
            }
        }
        public void AddEvent(Guid uuid, ushort major, ushort minor)
        {
            iBeaconEventHolder eventHolder = new iBeaconEventHolder(uuid, major, minor);

            if (!_beaconEventHolderDict.ContainsKey(eventHolder.BeaconIdentifyStr))
            {
                _beaconEventHolderDict.Add(eventHolder.BeaconIdentifyStr, eventHolder);
            }
        }
Ejemplo n.º 4
0
        public void AddObservableBeaconWithCallback(Guid uuid, short thresholdRssi, int intervalMilliSec, Action function)
        {
            iBeaconEventHolder eventHolder = new iBeaconEventHolder(uuid, null, null);

            if (!_beaconEventHolderDict.ContainsKey(eventHolder.BeaconIdentifyStr))
            {
                _beaconEventHolderDict.Add(eventHolder.BeaconIdentifyStr, eventHolder);
            }
            _beaconEventHolderDict[eventHolder.BeaconIdentifyStr].AddEvent(thresholdRssi, intervalMilliSec, function);
        }
        public void AddEvent(Guid uuid, ushort major, ushort minor, short thresholdRssi, int intervalMilliSec, Action function)
        {
            //TODO: 非同期メソッドや引数ありのメソッドもセットできるようにしたい
            iBeaconEventHolder eventHolder = new iBeaconEventHolder(uuid, major, minor);

            if (!_beaconEventHolderDict.ContainsKey(eventHolder.BeaconIdentifyStr))
            {
                _beaconEventHolderDict.Add(eventHolder.BeaconIdentifyStr, eventHolder);
            }
            _beaconEventHolderDict[eventHolder.BeaconIdentifyStr].AddEvent(thresholdRssi, intervalMilliSec, function);
        }
Ejemplo n.º 6
0
        private void didRangeBeacons(object s, CLRegionBeaconsRangedEventArgs e)
        {
            foreach (var detectedBeacon in e.Beacons)
            {
                string beaconIdentifier = iBeaconEventHolder.GenerateBeaconIdentifyStr(
                    new Guid(detectedBeacon.ProximityUuid.AsString().ToUpper()),
                    detectedBeacon.Major.UInt16Value,
                    detectedBeacon.Minor.UInt16Value);

                if (!_beaconEventHolderDict.ContainsKey(beaconIdentifier))
                {
                    return;
                }

                iBeaconEventHolder eventHolder = _beaconEventHolderDict[beaconIdentifier];

                if (_detectedBeaconDict.ContainsKey(beaconIdentifier))
                {
                    iBeacon detectedBeaconPrev = _detectedBeaconDict[beaconIdentifier];
                    short?  rssiPrev           = detectedBeaconPrev.Rssi;

                    if (rssiPrev == null || ((short)rssiPrev < detectedBeacon.Rssi))
                    {
                        eventHolder.ibeacon.Rssi = (short)detectedBeacon.Rssi;
                        eventHolder.ibeacon.EstimatedDistanceMeter = detectedBeacon.Accuracy;
                        _detectedBeaconDict[beaconIdentifier]      = eventHolder.ibeacon;
                    }
                }
                else
                {
                    eventHolder.ibeacon.Rssi = (short)detectedBeacon.Rssi;
                    if (detectedBeacon.Accuracy > 0)
                    {
                        eventHolder.ibeacon.EstimatedDistanceMeter = detectedBeacon.Accuracy;
                    }
                    _detectedBeaconDict.Add(beaconIdentifier, eventHolder.ibeacon);
                }

                foreach (iBeaconEventDetail eventDetail in eventHolder.EventList)
                {
                    if (eventDetail.ThresholdRssi < detectedBeacon.Rssi &&
                        eventDetail.LastTriggeredDateTime < DateTime.Now.AddMilliseconds(-1 * eventDetail.EventTriggerIntervalMilliSec))
                    {
                        eventDetail.LastTriggeredDateTime = DateTime.Now;
                        eventDetail.Function();
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public override void OnScanResult(ScanCallbackType callbackType, ScanResult result)
        {
            base.OnScanResult(callbackType, result);

            if (iBeaconDroidUtility.IsIBeacon(result.ScanRecord))
            {
                Guid   uuid  = iBeaconDroidUtility.GetUuidFromRecord(result.ScanRecord);
                ushort major = iBeaconDroidUtility.GetMajorFromRecord(result.ScanRecord);
                ushort minor = iBeaconDroidUtility.GetMinorFromRecord(result.ScanRecord);

                string beaconIdentifier = iBeaconEventHolder.GenerateBeaconIdentifyStr(uuid, major, minor);

                if (!BeaconEventHolderDict.ContainsKey(beaconIdentifier))
                {
                    return;
                }

                iBeaconEventHolder eventHolder = BeaconEventHolderDict[beaconIdentifier];

                if (DetectedBeaconDict.ContainsKey(beaconIdentifier))
                {
                    iBeacon detectedBeaconPrev = DetectedBeaconDict[beaconIdentifier];
                    short?  rssiPrev           = detectedBeaconPrev.Rssi;

                    if (rssiPrev == null || ((short)rssiPrev < result.Rssi))
                    {
                        eventHolder.ibeacon.Rssi             = (short)result.Rssi;
                        DetectedBeaconDict[beaconIdentifier] = eventHolder.ibeacon;
                    }
                }
                else
                {
                    eventHolder.ibeacon.Rssi    = (short)result.Rssi;
                    eventHolder.ibeacon.TxPower = iBeaconDroidUtility.GetTxPowerFromRecord(result.ScanRecord);
                    DetectedBeaconDict.Add(beaconIdentifier, eventHolder.ibeacon);
                }

                foreach (var eventDetail in eventHolder.EventList)
                {
                    if (eventDetail.ThresholdRssi < result.Rssi &&
                        eventDetail.LastTriggeredDateTime < DateTime.Now.AddMilliseconds(-1 * eventDetail.EventTriggerIntervalMilliSec))
                    {
                        eventDetail.LastTriggeredDateTime = DateTime.Now;
                        eventDetail.Function();
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public void AddEvent(Guid uuid, ushort major, ushort minor)
        {
            iBeaconEventHolder eventHolder = new iBeaconEventHolder(uuid, major, minor);

            if (!_beaconEventHolderDict.ContainsKey(eventHolder.BeaconIdentifyStr))
            {
                _beaconEventHolderDict.Add(eventHolder.BeaconIdentifyStr, eventHolder);
            }

            if (IsScanning)
            {
                var nsUuid       = new NSUuid(uuid.ToString());
                var beaconRegion = new CLBeaconRegion(nsUuid, major, minor, eventHolder.BeaconIdentifyStr);
                _locationManager.StartRangingBeacons(beaconRegion);
            }
        }
Ejemplo n.º 9
0
        public void AddObservableBeacon(Guid uuid)
        {
            iBeaconEventHolder eventHolder = new iBeaconEventHolder(uuid, null, null);

            if (!_beaconEventHolderDict.ContainsKey(eventHolder.BeaconIdentifyStr))
            {
                _beaconEventHolderDict.Add(eventHolder.BeaconIdentifyStr, eventHolder);
            }

            if (IsScanning)
            {
                var nsUuid       = new NSUuid(uuid.ToString());
                var beaconRegion = new CLBeaconRegion(nsUuid, eventHolder.BeaconIdentifyStr);
                _locationManager.StartRangingBeacons(beaconRegion);
            }
        }
        private void bleAdvWatcherReceived(BluetoothLEAdvertisementWatcher s, BluetoothLEAdvertisementReceivedEventArgs e)
        {
            iBeacon detectedBeacon = iBeaconUwpUtility.ConvertReceivedDataToBeacon(e);

            if (detectedBeacon == null || detectedBeacon.Rssi == null)
            {
                return;
            }

            string beaconIdentifier = iBeaconEventHolder.GenerateBeaconIdentifyStr(detectedBeacon.Uuid, detectedBeacon.Major, detectedBeacon.Minor);

            if (!_beaconEventHolderDict.ContainsKey(beaconIdentifier))
            {
                return;
            }

            iBeaconEventHolder eventHolder = _beaconEventHolderDict[beaconIdentifier];

            if (_detectedBeaconDict.ContainsKey(beaconIdentifier))
            {
                iBeacon detectedBeaconPrev = _detectedBeaconDict[beaconIdentifier];
                short?  rssiPrev           = detectedBeaconPrev.Rssi;

                if (rssiPrev == null || ((short)rssiPrev < detectedBeacon.Rssi))
                {
                    eventHolder.ibeacon.Rssi              = detectedBeacon.Rssi;
                    eventHolder.ibeacon.TxPower           = detectedBeacon.TxPower;
                    _detectedBeaconDict[beaconIdentifier] = eventHolder.ibeacon;
                }
            }
            else
            {
                eventHolder.ibeacon.Rssi    = detectedBeacon.Rssi;
                eventHolder.ibeacon.TxPower = detectedBeacon.TxPower;
                _detectedBeaconDict.Add(beaconIdentifier, eventHolder.ibeacon);
            }

            foreach (var eventDetail in eventHolder.EventList)
            {
                if (eventDetail.ThresholdRssi < detectedBeacon.Rssi &&
                    eventDetail.LastTriggeredDateTime < DateTime.Now.AddMilliseconds(-1 * eventDetail.EventTriggerIntervalMilliSec))
                {
                    eventDetail.LastTriggeredDateTime = DateTime.Now;
                    eventDetail.Function();
                }
            }
        }
Ejemplo n.º 11
0
        public void AddObservableBeaconWithCallback(Guid uuid, short thresholdRssi, int intervalMilliSec, Action func)
        {
            iBeaconEventHolder eventHolder = new iBeaconEventHolder(uuid, null, null);

            if (!_beaconEventHolderDict.ContainsKey(eventHolder.BeaconIdentifyStr))
            {
                _beaconEventHolderDict.Add(eventHolder.BeaconIdentifyStr, eventHolder);
            }

            _beaconEventHolderDict[eventHolder.BeaconIdentifyStr].AddEvent(thresholdRssi, intervalMilliSec, func);

            if (IsScanning)
            {
                var nsUuid       = new NSUuid(uuid.ToString());
                var beaconRegion = new CLBeaconRegion(nsUuid, eventHolder.BeaconIdentifyStr);
                _locationManager.StartRangingBeacons(beaconRegion);
            }
        }
Ejemplo n.º 12
0
        public void AddEvent(Guid uuid, ushort major, ushort minor, short thresholdRssi, int intervalMilliSec, Action func)
        {
            //TODO: 非同期メソッドや引数ありのメソッドもセットできるようにしたい
            iBeaconEventHolder eventHolder = new iBeaconEventHolder(uuid, major, minor);

            if (!_beaconEventHolderDict.ContainsKey(eventHolder.BeaconIdentifyStr))
            {
                _beaconEventHolderDict.Add(eventHolder.BeaconIdentifyStr, eventHolder);
            }

            _beaconEventHolderDict[eventHolder.BeaconIdentifyStr].AddEvent(thresholdRssi, intervalMilliSec, func);

            if (IsScanning)
            {
                var nsUuid       = new NSUuid(uuid.ToString());
                var beaconRegion = new CLBeaconRegion(nsUuid, major, minor, eventHolder.BeaconIdentifyStr);
                _locationManager.StartRangingBeacons(beaconRegion);
            }
        }
Ejemplo n.º 13
0
        public void AddEvent(Guid uuid, ushort major, ushort minor)
        {
            iBeaconEventHolder eventHolder = new iBeaconEventHolder(uuid, major, minor);

            if (OS_VER < BuildVersionCodes.Lollipop)
            {
                if (!_scanCallbackOld.BeaconEventHolderDict.ContainsKey(eventHolder.BeaconIdentifyStr))
                {
                    _scanCallbackOld.BeaconEventHolderDict.Add(eventHolder.BeaconIdentifyStr, eventHolder);
                }
            }
            else
            {
                if (!_scanCallbackNew.BeaconEventHolderDict.ContainsKey(eventHolder.BeaconIdentifyStr))
                {
                    _scanCallbackNew.BeaconEventHolderDict.Add(eventHolder.BeaconIdentifyStr, eventHolder);
                }
            }
        }
Ejemplo n.º 14
0
        public void AddObservableBeacon(Guid uuid)
        {
            iBeaconEventHolder eventHolder = new iBeaconEventHolder(uuid, null, null);

            if (OS_VER < BuildVersionCodes.Lollipop)
            {
                if (!_scanCallbackOld.BeaconEventHolderDict.ContainsKey(eventHolder.BeaconIdentifyStr))
                {
                    _scanCallbackOld.BeaconEventHolderDict.Add(eventHolder.BeaconIdentifyStr, eventHolder);
                }
            }
            else
            {
                if (!_scanCallbackNew.BeaconEventHolderDict.ContainsKey(eventHolder.BeaconIdentifyStr))
                {
                    _scanCallbackNew.BeaconEventHolderDict.Add(eventHolder.BeaconIdentifyStr, eventHolder);
                }
            }
        }
Ejemplo n.º 15
0
        public void AddEvent(Guid uuid, ushort major, ushort minor, short thresholdRssi, int intervalMilliSec, Action function)
        {
            iBeaconEventHolder eventHolder = new iBeaconEventHolder(uuid, major, minor);

            if (OS_VER < BuildVersionCodes.Lollipop)
            {
                if (!_scanCallbackOld.BeaconEventHolderDict.ContainsKey(eventHolder.BeaconIdentifyStr))
                {
                    _scanCallbackOld.BeaconEventHolderDict.Add(eventHolder.BeaconIdentifyStr, eventHolder);
                }
                _scanCallbackOld.BeaconEventHolderDict[eventHolder.BeaconIdentifyStr].AddEvent(thresholdRssi, intervalMilliSec, function);
            }
            else
            {
                if (!_scanCallbackNew.BeaconEventHolderDict.ContainsKey(eventHolder.BeaconIdentifyStr))
                {
                    _scanCallbackNew.BeaconEventHolderDict.Add(eventHolder.BeaconIdentifyStr, eventHolder);
                }
                _scanCallbackNew.BeaconEventHolderDict[eventHolder.BeaconIdentifyStr].AddEvent(thresholdRssi, intervalMilliSec, function);
            }
        }
Ejemplo n.º 16
0
        public override void OnScanResult(ScanCallbackType callbackType, ScanResult result)
        {
            base.OnScanResult(callbackType, result);

            if (iBeaconDroidUtility.IsIBeacon(result.ScanRecord))
            {
                Guid   uuid  = iBeaconDroidUtility.GetUuidFromRecord(result.ScanRecord);
                ushort major = iBeaconDroidUtility.GetMajorFromRecord(result.ScanRecord);
                ushort minor = iBeaconDroidUtility.GetMinorFromRecord(result.ScanRecord);

                string beaconIdentifier                = iBeaconEventHolder.GenerateBeaconIdentifyStr(uuid, major, minor);
                string beaconIdentifierForNoMinor      = iBeaconEventHolder.GenerateBeaconIdentifyStr(uuid, major, null);
                string beaconIdentifierForNoMajorMinor = iBeaconEventHolder.GenerateBeaconIdentifyStr(uuid, null, null);

                if (!BeaconEventHolderDict.ContainsKey(beaconIdentifier) &&
                    !BeaconEventHolderDict.ContainsKey(beaconIdentifierForNoMinor) &&
                    !BeaconEventHolderDict.ContainsKey(beaconIdentifierForNoMajorMinor))
                {
                    return;
                }

                string[] beaconIdentifierArray = { beaconIdentifier,
                                                   beaconIdentifierForNoMinor,
                                                   beaconIdentifierForNoMajorMinor };

                foreach (var beaconId in beaconIdentifierArray)
                {
                    iBeaconEventHolder eventHolder = null;
                    if (BeaconEventHolderDict.ContainsKey(beaconId))
                    {
                        eventHolder = BeaconEventHolderDict[beaconId];
                    }
                    else
                    {
                        continue;
                    }

                    iBeacon holdBeacon = eventHolder.ibeacon;

                    if (DetectedBeaconDictFromClosestApproachedInfo.ContainsKey(beaconIdentifier))
                    {
                        iBeacon detectedBeaconPrev = DetectedBeaconDictFromClosestApproachedInfo[beaconIdentifier];
                        short?  rssiPrev           = detectedBeaconPrev.Rssi;

                        if (rssiPrev == null || ((short)rssiPrev < result.Rssi))
                        {
                            holdBeacon.Rssi    = (short)result.Rssi;
                            holdBeacon.TxPower = iBeaconDroidUtility.GetTxPowerFromRecord(result.ScanRecord);
                            holdBeacon.EstimatedDistanceMeter = iBeaconDroidUtility.CalcDistanceMeterFromRssiAndTxPower(holdBeacon.Rssi, holdBeacon.TxPower);
                            DetectedBeaconDictFromClosestApproachedInfo[beaconIdentifier] = holdBeacon;
                        }
                    }
                    else
                    {
                        holdBeacon.Rssi    = (short)result.Rssi;
                        holdBeacon.TxPower = iBeaconDroidUtility.GetTxPowerFromRecord(result.ScanRecord);
                        holdBeacon.EstimatedDistanceMeter = iBeaconDroidUtility.CalcDistanceMeterFromRssiAndTxPower(holdBeacon.Rssi, holdBeacon.TxPower);
                        DetectedBeaconDictFromClosestApproachedInfo.Add(beaconIdentifier, holdBeacon);
                    }

                    if (DetectedBeaconDictFromLastApproachedInfo.ContainsKey(beaconIdentifier))
                    {
                        var thisBeacon = new iBeacon()
                        {
                            Uuid    = uuid,
                            Major   = major,
                            Minor   = minor,
                            Rssi    = (short)result.Rssi,
                            TxPower = iBeaconDroidUtility.GetTxPowerFromRecord(result.ScanRecord),
                            EstimatedDistanceMeter = iBeaconDroidUtility.CalcDistanceMeterFromRssiAndTxPower(
                                (short)result.Rssi,
                                iBeaconDroidUtility.GetTxPowerFromRecord(result.ScanRecord))
                        };
                        DetectedBeaconDictFromLastApproachedInfo[beaconIdentifier] = thisBeacon;
                    }
                    else
                    {
                        var thisBeacon = new iBeacon()
                        {
                            Uuid    = uuid,
                            Major   = major,
                            Minor   = minor,
                            Rssi    = (short)result.Rssi,
                            TxPower = iBeaconDroidUtility.GetTxPowerFromRecord(result.ScanRecord),
                            EstimatedDistanceMeter = iBeaconDroidUtility.CalcDistanceMeterFromRssiAndTxPower(
                                (short)result.Rssi,
                                iBeaconDroidUtility.GetTxPowerFromRecord(result.ScanRecord))
                        };
                        DetectedBeaconDictFromLastApproachedInfo.Add(beaconIdentifier, thisBeacon);
                    }

                    foreach (var eventDetail in eventHolder.EventList)
                    {
                        if (eventDetail.ThresholdRssi < result.Rssi &&
                            eventDetail.LastTriggeredDateTime < DateTime.Now.AddMilliseconds(-1 * eventDetail.EventTriggerIntervalMilliSec))
                        {
                            eventDetail.LastTriggeredDateTime = DateTime.Now;
                            eventDetail.Function();
                        }
                    }
                }
            }
        }
Ejemplo n.º 17
0
        private void didRangeBeacons(object s, CLRegionBeaconsRangedEventArgs e)
        {
            foreach (var detectedBeacon in e.Beacons)
            {
                string beaconIdentifier = iBeaconEventHolder.GenerateBeaconIdentifyStr(
                    new Guid(detectedBeacon.ProximityUuid.AsString().ToUpper()),
                    detectedBeacon.Major.UInt16Value,
                    detectedBeacon.Minor.UInt16Value);

                string beaconIdentifierForNoMinor = iBeaconEventHolder.GenerateBeaconIdentifyStr(
                    new Guid(detectedBeacon.ProximityUuid.AsString().ToUpper()),
                    detectedBeacon.Major.UInt16Value, null);

                string beaconIdentifierForNoMajorMinor = iBeaconEventHolder.GenerateBeaconIdentifyStr(
                    new Guid(detectedBeacon.ProximityUuid.AsString().ToUpper()), null, null);

                if (!_beaconEventHolderDict.ContainsKey(beaconIdentifier) &&
                    !_beaconEventHolderDict.ContainsKey(beaconIdentifierForNoMinor) &&
                    !_beaconEventHolderDict.ContainsKey(beaconIdentifierForNoMajorMinor))
                {
                    continue;
                }

                string[] beaconIdentifierArray = { beaconIdentifier,
                                                   beaconIdentifierForNoMinor,
                                                   beaconIdentifierForNoMajorMinor };

                foreach (var beaconId in beaconIdentifierArray)
                {
                    iBeaconEventHolder eventHolder = null;
                    if (_beaconEventHolderDict.ContainsKey(beaconId))
                    {
                        eventHolder = _beaconEventHolderDict[beaconId];
                    }
                    else
                    {
                        continue;
                    }

                    if (_detectedBeaconDictFromClosestApproachedInfo.ContainsKey(beaconIdentifier))
                    {
                        iBeacon detectedBeaconPrev = _detectedBeaconDictFromClosestApproachedInfo[beaconIdentifier];
                        short?  rssiPrev           = detectedBeaconPrev.Rssi;

                        if (rssiPrev == null || ((short)rssiPrev < detectedBeacon.Rssi))
                        {
                            eventHolder.ibeacon.Rssi = (short)detectedBeacon.Rssi;
                            if (detectedBeacon.Accuracy > 0.0)
                            {
                                eventHolder.ibeacon.EstimatedDistanceMeter = detectedBeacon.Accuracy;
                            }
                            _detectedBeaconDictFromClosestApproachedInfo[beaconIdentifier] = eventHolder.ibeacon;
                        }
                    }
                    else
                    {
                        eventHolder.ibeacon.Rssi = (short)detectedBeacon.Rssi;
                        if (detectedBeacon.Accuracy > 0.0)
                        {
                            eventHolder.ibeacon.EstimatedDistanceMeter = detectedBeacon.Accuracy;
                        }
                        _detectedBeaconDictFromClosestApproachedInfo.Add(beaconIdentifier, eventHolder.ibeacon);
                    }

                    if (_detectedBeaconDictFromLastApproachedInfo.ContainsKey(beaconIdentifier))
                    {
                        _detectedBeaconDictFromLastApproachedInfo[beaconIdentifier] = new iBeacon()
                        {
                            Uuid  = new Guid(detectedBeacon.ProximityUuid.AsString()),
                            Major = detectedBeacon.Major.UInt16Value,
                            Minor = detectedBeacon.Minor.UInt16Value,
                            Rssi  = (short)detectedBeacon.Rssi,
                            EstimatedDistanceMeter = detectedBeacon.Accuracy
                        };
                    }
                    else
                    {
                        _detectedBeaconDictFromLastApproachedInfo.Add(
                            beaconIdentifier,
                            new iBeacon()
                        {
                            Uuid  = new Guid(detectedBeacon.ProximityUuid.AsString()),
                            Major = detectedBeacon.Major.UInt16Value,
                            Minor = detectedBeacon.Minor.UInt16Value,
                            Rssi  = (short)detectedBeacon.Rssi,
                            EstimatedDistanceMeter = detectedBeacon.Accuracy
                        });
                    }

                    foreach (iBeaconEventDetail eventDetail in eventHolder.EventList)
                    {
                        if (eventDetail.ThresholdRssi < detectedBeacon.Rssi &&
                            eventDetail.LastTriggeredDateTime < DateTime.Now.AddMilliseconds(-1 * eventDetail.EventTriggerIntervalMilliSec))
                        {
                            eventDetail.LastTriggeredDateTime = DateTime.Now;
                            eventDetail.Function();
                        }
                    }
                }
            }
        }
Ejemplo n.º 18
0
        private void bleAdvWatcherReceived(BluetoothLEAdvertisementWatcher s, BluetoothLEAdvertisementReceivedEventArgs e)
        {
            iBeacon detectedBeacon = iBeaconUwpUtility.ConvertReceivedDataToBeacon(e);

            if (detectedBeacon == null || detectedBeacon.Rssi == null)
            {
                return;
            }

            string beaconIdentifier                = iBeaconEventHolder.GenerateBeaconIdentifyStr(detectedBeacon.Uuid, detectedBeacon.Major, detectedBeacon.Minor);
            string beaconIdentifierForNoMinor      = iBeaconEventHolder.GenerateBeaconIdentifyStr(detectedBeacon.Uuid, detectedBeacon.Major, null);
            string beaconIdentifierForNoMajorMinor = iBeaconEventHolder.GenerateBeaconIdentifyStr(detectedBeacon.Uuid, null, null);

            if (!_beaconEventHolderDict.ContainsKey(beaconIdentifier) &&
                !_beaconEventHolderDict.ContainsKey(beaconIdentifierForNoMinor) &&
                !_beaconEventHolderDict.ContainsKey(beaconIdentifierForNoMajorMinor))
            {
                return;
            }

            string[] beaconIdentifierArray = { beaconIdentifier,
                                               beaconIdentifierForNoMinor,
                                               beaconIdentifierForNoMajorMinor };

            foreach (var beaconId in beaconIdentifierArray)
            {
                iBeaconEventHolder eventHolder = null;
                if (_beaconEventHolderDict.ContainsKey(beaconId))
                {
                    eventHolder = _beaconEventHolderDict[beaconId];
                }
                else
                {
                    continue;
                }

                if (_detectedBeaconDictFromClosestApproachedInfo.ContainsKey(beaconIdentifier))
                {
                    iBeacon detectedBeaconPrev = _detectedBeaconDictFromClosestApproachedInfo[beaconIdentifier];
                    short?  rssiPrev           = detectedBeaconPrev.Rssi;

                    if (rssiPrev == null || ((short)rssiPrev < detectedBeacon.Rssi))
                    {
                        eventHolder.ibeacon.Rssi    = detectedBeacon.Rssi;
                        eventHolder.ibeacon.TxPower = detectedBeacon.TxPower;
                        eventHolder.ibeacon.EstimatedDistanceMeter = detectedBeacon.EstimatedDistanceMeter;
                        _detectedBeaconDictFromClosestApproachedInfo[beaconIdentifier] = eventHolder.ibeacon;
                    }
                }
                else
                {
                    eventHolder.ibeacon.Rssi    = detectedBeacon.Rssi;
                    eventHolder.ibeacon.TxPower = detectedBeacon.TxPower;
                    eventHolder.ibeacon.EstimatedDistanceMeter = detectedBeacon.EstimatedDistanceMeter;
                    _detectedBeaconDictFromClosestApproachedInfo.Add(beaconIdentifier, eventHolder.ibeacon);
                }

                if (_detectedBeaconDictFromLastApproachedInfo.ContainsKey(beaconIdentifier))
                {
                    _detectedBeaconDictFromLastApproachedInfo[beaconIdentifier] = detectedBeacon;
                }
                else
                {
                    _detectedBeaconDictFromLastApproachedInfo.Add(beaconIdentifier, detectedBeacon);
                }

                foreach (var eventDetail in eventHolder.EventList)
                {
                    if (eventDetail.ThresholdRssi < detectedBeacon.Rssi &&
                        eventDetail.LastTriggeredDateTime < DateTime.Now.AddMilliseconds(-1 * eventDetail.EventTriggerIntervalMilliSec))
                    {
                        eventDetail.LastTriggeredDateTime = DateTime.Now;
                        eventDetail.Function();
                    }
                }
            }
        }