示例#1
0
 /// <summary>
 /// Enable advertising as a beacon.
 /// </summary>
 /// <param name="beacon">The beacon to emulate.</param>
 public void EnableAdvertising(Beacon beacon)
 {
     if (controller == null)
         throw new ObjectDisposedException("controller");
     if (beacon == null)
         throw new ArgumentNullException("beacon");
     controller.EnableAdvertising(beacon.ToAdvertisingData());
 }
示例#2
0
        /// <summary>
        /// Gets the calculated range in meters using a curve that approximates the iOS ranging.
        /// </summary>
        /// <param name="beacon">The beacon instance.</param>
        /// <returns>The calculated range in meters.</returns>
        public static double GetApproximateIosRange(this Beacon beacon)
        {
            if (beacon.Rssi == 0)
            {
                return(-1);
            }
            var ratio = (double)beacon.Rssi / (double)beacon.CalibratedTxPower;

            if (ratio < 1.0)
            {
                return(Math.Pow(ratio, 10));
            }
            return(0.89979 * Math.Pow(ratio, 7.7095) + 0.111);
        }
示例#3
0
        /// <summary>
        /// Enable advertising as a beacon.
        /// </summary>
        /// <param name="beacon">The beacon to emulate.</param>
        /// <param name="advertisingInterval">The advertising interval. Interval should be between 20 ms and 10.24 seconds. Defaults to 1.28 seconds.</param>
        public void EnableAdvertising(Beacon beacon, TimeSpan?advertisingInterval = null)
        {
            if (controller == null)
            {
                throw new ObjectDisposedException("controller");
            }
            if (beacon == null)
            {
                throw new ArgumentNullException("beacon");
            }

            if (advertisingInterval.HasValue)
            {
                if (advertisingInterval.Value.TotalMilliseconds < 20 || advertisingInterval.Value.TotalMilliseconds > 10240)
                {
                    throw new ArgumentOutOfRangeException("advertisingInterval", "Interval should be between 20 ms and 10.24 seconds");
                }
                controller.EnableAdvertising(beacon.ToAdvertisingData(), (ushort)advertisingInterval.Value.TotalMilliseconds);
            }
            else
            {
                controller.EnableAdvertising(beacon.ToAdvertisingData());
            }
        }
示例#4
0
        private void controller_LeMetaEventReceived(object sender, LeMetaEventReceivedEventArgs e)
        {
            if (e.LeMetaEvent == null)
            {
                return;
            }
            if (e.LeMetaEvent.SubEvent != LeMetaEvent.LeMetaSubEvent.AdvertisingReport)
            {
                return;
            }
            if (e.LeMetaEvent.AdvertisingEvents == null)
            {
                return;
            }

            foreach (var advertisingEvent in e.LeMetaEvent.AdvertisingEvents)
            {
                var beacon = Beacon.Parse(advertisingEvent);
                if (beacon != null)
                {
                    OnBeaconDetected(beacon);
                }
            }
        }
示例#5
0
 internal BeaconEventArgs(Beacon beacon)
 {
     Beacon = beacon;
 }
示例#6
0
 private void OnBeaconDetected(Beacon beacon)
 {
     if (BeaconDetected != null)
         BeaconDetected(this, new BeaconEventArgs(beacon));
 }
 internal BeaconEventArgs(Beacon beacon)
 {
     Beacon = beacon;
 }
 internal BeaconDetectedEventArgs(Beacon beacon)
 {
     Beacon = beacon;
 }
 internal BeaconDetectedEventArgs(Beacon beacon)
 {
     Beacon = beacon;
 }