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 }); }
public void Set (BeaconDevice device) { IsConnected = device != null; if (IsConnected) { Uuid = device.Uuid; Minor = device.Minor; Major = device.Major; } }
public void Set(BeaconDevice device) { IsConnected = device != null; if (IsConnected) { Uuid = device.Uuid; Minor = device.Minor; Major = device.Major; } }
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); }
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); } }
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); } }
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); }
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); } }
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); }
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); } } }
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); }
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); }
public void RemoveBeaconFromMonitoring(BeaconDevice beacon) { }
public void AddBeaconToMonitoring(BeaconDevice beacon) { }
public void AddBeaconToMonitoring (BeaconDevice beacon) { }
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 }); }
public void RemoveBeaconFromMonitoring (BeaconDevice beacon) { }