Esempio n. 1
0
        public override void DidRangeBeacons(CLLocationManager manager, CLBeacon[] beacons, CLBeaconRegion region)
        {
            CLBeacon beacon;

            lock (_sync) {
                //we need uniq beacon which is close then 5sm
                beacon = beacons.FirstOrDefault(b => _beacons.All(eb => eb.Major != b.Major.Int32Value || eb.Minor != b.Minor.Int32Value) && b.Proximity == CLProximity.Immediate && b.Accuracy < NearestDistance);
                if (beacon == null)
                {
                    return;
                }

                System.Diagnostics.Debug.WriteLine("FindBeacon " + beacon);

                //We found one - no need to find again as we will find it again in some seconds
                StopFindNearest();
            }

            var nearestBeacon = new BeaconDevice {
                Uuid  = beacon.ProximityUuid.AsString(),
                Major = beacon.Major.Int32Value,
                Minor = beacon.Minor.Int32Value
            };

            NearestFound(this, new BeaconEventArgs {
                BeaconDevice = nearestBeacon
            });
        }
Esempio n. 2
0
		public void Set (BeaconDevice device)
		{
			IsConnected = device != null;
			if (IsConnected) {
				Uuid = device.Uuid;
				Minor = device.Minor;
				Major = device.Major;
			}
		}
Esempio n. 3
0
 public void Set(BeaconDevice device)
 {
     IsConnected = device != null;
     if (IsConnected)
     {
         Uuid  = device.Uuid;
         Minor = device.Minor;
         Major = device.Major;
     }
 }
Esempio n. 4
0
        public static IBluetoothBeacon CreateBeacon(IBluetoothAdvertisementPackage eventArgs)
        {
            var rssi      = eventArgs.RawSignalStrengthInDBm;
            var address   = eventArgs.BluetoothAddress;
            var timestamp = eventArgs.Timestamp;

            var beaconDevice = new BeaconDevice(address, rssi, timestamp);

            return(beaconDevice);
        }
Esempio n. 5
0
		public void RemoveBeaconFromMonitoring (BeaconDevice beacon)
		{
			lock (_sync) {
				var foundBeacon = _beacons.FirstOrDefault (b => b.DeviceId == beacon.DeviceId);
				if (foundBeacon != null)
					_beacons.Remove (foundBeacon);

				var foundBeaconRegion = _locationManager.MonitoredRegions.FirstOrDefault (br => (br as CLRegion)?.Identifier == beacon.DeviceId) as CLBeaconRegion;
				if (foundBeaconRegion != null)
					_locationManager.StopMonitoring (foundBeaconRegion);
			}
		}
Esempio n. 6
0
		public void AddBeaconToMonitoring (BeaconDevice beacon)
		{
			lock (_sync) {
				var monitored = _locationManager.MonitoredRegions;
				if (monitored.All (m => (m as CLBeaconRegion)?.Identifier != beacon.DeviceId)) {
					var beaconRegion = new CLBeaconRegion (new NSUuid (beacon.Uuid), (ushort)beacon.Major, (ushort)beacon.Minor, beacon.DeviceId);
					beaconRegion.NotifyOnEntry = true;
					beaconRegion.NotifyOnExit = true;

					_locationManager.StartMonitoring (beaconRegion);
				}
				_beacons.Add (beacon);
			}
		}
Esempio n. 7
0
        public void TestCopyMissedPackagesFromBeaconNoPackages()
        {
            var dateTimeOffset = new DateTimeOffset();

            var sourceBeacon = new BeaconDevice(0L, 0, dateTimeOffset);
            var targetBeacon = new BeaconDevice(0L, 0, dateTimeOffset);


            targetBeacon.CopyMissedPackagesFromBeacon(sourceBeacon);


            var targetBeaconCount = targetBeacon.NumberOfPackages();

            Assert.AreEqual(0, targetBeaconCount);
        }
Esempio n. 8
0
        public void AddBeaconToMonitoring(BeaconDevice beacon)
        {
            lock (_sync) {
                var monitored = _locationManager.MonitoredRegions;
                if (monitored.All(m => (m as CLBeaconRegion)?.Identifier != beacon.DeviceId))
                {
                    var beaconRegion = new CLBeaconRegion(new NSUuid(beacon.Uuid), (ushort)beacon.Major, (ushort)beacon.Minor, beacon.DeviceId);
                    beaconRegion.NotifyOnEntry = true;
                    beaconRegion.NotifyOnExit  = true;

                    _locationManager.StartMonitoring(beaconRegion);
                }
                _beacons.Add(beacon);
            }
        }
Esempio n. 9
0
        public void TestUpdatePackageCounterAndPeriodBetweenPackages()
        {
            var dateTimeOffset           = new DateTimeOffset();
            var dateTimeOffsetPlus40Secs = dateTimeOffset.AddSeconds(40);

            var sourceBeacon = new BeaconDevice(0L, 0, dateTimeOffset);
            var targetBeacon = new BeaconDevice(0L, 0, dateTimeOffsetPlus40Secs);


            targetBeacon.UpdatePackageCounterAndPeriodBetweenPackages(sourceBeacon);


            Assert.AreEqual(40UL, targetBeacon.TimeSinceLastPacketReceivedInSec);
            Assert.AreEqual(2UL, targetBeacon.ReceivedTimes);
        }
Esempio n. 10
0
        public void RemoveBeaconFromMonitoring(BeaconDevice beacon)
        {
            lock (_sync) {
                var foundBeacon = _beacons.FirstOrDefault(b => b.DeviceId == beacon.DeviceId);
                if (foundBeacon != null)
                {
                    _beacons.Remove(foundBeacon);
                }

                var foundBeaconRegion = _locationManager.MonitoredRegions.FirstOrDefault(br => (br as CLRegion)?.Identifier == beacon.DeviceId) as CLBeaconRegion;
                if (foundBeaconRegion != null)
                {
                    _locationManager.StopMonitoring(foundBeaconRegion);
                }
            }
        }
Esempio n. 11
0
        public void TestCopyMissedPackagesFromBeaconAddPackage()
        {
            var dateTimeOffset = new DateTimeOffset();

            var sourceBeacon = new BeaconDevice(0L, 0, dateTimeOffset);
            var targetBeacon = new BeaconDevice(0L, 0, dateTimeOffset);

            sourceBeacon.AddPackage(new EddystoneEID());

            targetBeacon.AddPackage(new ClassicBeaconPackage());


            targetBeacon.CopyMissedPackagesFromBeacon(sourceBeacon);


            var targetBeaconCount = targetBeacon.NumberOfPackages();

            Assert.AreEqual(2, targetBeaconCount);
        }
Esempio n. 12
0
        public void TestUpdateFromDevice()
        {
            var dateTimeOffset           = new DateTimeOffset();
            var dateTimeOffsetPlus40Secs = dateTimeOffset.AddSeconds(40);

            var existingBeacon = new BeaconDevice(0L, 0, dateTimeOffset);
            var newBeacon      = new BeaconDevice(0x88, -66, dateTimeOffsetPlus40Secs);


            existingBeacon.UpdateFromDevice(newBeacon);


            Assert.AreEqual(40UL, existingBeacon.TimeSinceLastPacketReceivedInSec);
            Assert.AreEqual(2UL, existingBeacon.ReceivedTimes);

            Assert.AreEqual(0x88UL, existingBeacon.BluetoothAddress);
            Assert.AreEqual(-66, existingBeacon.Rssi);
            Assert.AreEqual(dateTimeOffsetPlus40Secs, existingBeacon.Timestamp);
        }
Esempio n. 13
0
 public void RemoveBeaconFromMonitoring(BeaconDevice beacon)
 {
 }
Esempio n. 14
0
 public void AddBeaconToMonitoring(BeaconDevice beacon)
 {
 }
Esempio n. 15
0
		public void AddBeaconToMonitoring (BeaconDevice beacon)
		{
			
		}
Esempio n. 16
0
		public override void DidRangeBeacons (CLLocationManager manager, CLBeacon[] beacons, CLBeaconRegion region)
		{
			CLBeacon beacon;
			lock (_sync) {
				//we need uniq beacon which is close then 5sm
				beacon = beacons.FirstOrDefault (b => _beacons.All (eb => eb.Major != b.Major.Int32Value || eb.Minor != b.Minor.Int32Value) && b.Proximity == CLProximity.Immediate && b.Accuracy < NearestDistance);
				if (beacon == null)
					return;

				System.Diagnostics.Debug.WriteLine ("FindBeacon " + beacon);

				//We found one - no need to find again as we will find it again in some seconds
				StopFindNearest ();
			}

			var nearestBeacon = new BeaconDevice {
				Uuid = beacon.ProximityUuid.AsString (),
				Major = beacon.Major.Int32Value,
				Minor = beacon.Minor.Int32Value
			};
			NearestFound (this, new BeaconEventArgs { BeaconDevice = nearestBeacon });
		}
Esempio n. 17
0
		public void RemoveBeaconFromMonitoring (BeaconDevice beacon)
		{
			
		}