/// <summary>
        /// Constructs a Beacon instance and sets the properties based on the given data.
        /// </summary>
        /// <param name="dataSection">A data section containing beacon data.</param>
        /// <returns>A newly created Beacon instance or null in case of a failure.</returns>
        public static Beacon BeaconFromDataSection(BluetoothLEAdvertisementDataSection dataSection)
        {
            Beacon beacon = null;

            if (dataSection != null && dataSection.Data != null)
            {
                beacon = BeaconFromByteArray(dataSection.Data.ToArray());
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("BeaconFactory.BeaconFromDataSection(): The given data (section) is null");
            }

            return(beacon);
        }
        /// <summary>
        /// Constructs a Beacon instance and sets the properties based on the given data.
        /// </summary>
        /// <param name="args"></param>
        /// <returns>A newly created Beacon instance or null in case of a failure.</returns>
        public static Beacon BeaconFromBluetoothLEAdvertisementReceivedEventArgs(BluetoothLEAdvertisementReceivedEventArgs args)
        {
            Beacon beacon = null;

            if (args != null && args.Advertisement != null)
            {
                beacon = BeaconFromDataSectionList(args.Advertisement.DataSections);

                if (beacon != null)
                {
                    beacon.Timestamp = args.Timestamp;
                    beacon.RawSignalStrengthInDBm = args.RawSignalStrengthInDBm;
                    beacon.BluetoothAddress       = args.BluetoothAddress;
                    beacon.DiscoveryTestData      = new bool[100];
                }
            }

            return(beacon);
        }
示例#3
0
        /// <summary>
        /// Updates the beacon data, if the given beacon matches this one.
        /// </summary>
        /// <param name="beacon">The beacon with new data.</param>
        /// <returns>True, if the given beacon matches this one (and the data was updated). False otherwise.</returns>
        public bool Update(Beacon beacon)
        {
            bool matches = Matches(beacon);

            if (matches)
            {
                Timestamp = beacon.Timestamp;
                RawSignalStrengthInDBm = beacon.RawSignalStrengthInDBm;

                if (_lastSeenTimer != null)
                {
                    _lastSeenTimer.Dispose();
                    _lastSeenTimer = new Timer(LastSeenTimerCallbackAsync, null,
                                               LastSeenTimerTimeoutInMilliseconds, LastSeenTimerTimeoutInMilliseconds);
                }
            }

            return(matches);
        }
        /// <summary>
        /// Constructs a Beacon instance and sets the properties based on the given data.
        /// </summary>
        /// <param name="dataSection">A data section containing beacon data.</param>
        /// <returns>A newly created Beacon instance or null in case of a failure.</returns>
        public static Beacon BeaconFromDataSectionList(IList <BluetoothLEAdvertisementDataSection> dataSections)
        {
            Beacon beacon = null;

            if (dataSections != null && dataSections.Count > 0)
            {
                foreach (BluetoothLEAdvertisementDataSection dataSection in dataSections)
                {
                    if (dataSection != null)
                    {
                        if (dataSection.DataType == SecondBeaconDataSectionDataType)
                        {
                            beacon = BeaconFromDataSection(dataSection);
                        }
                    }
                }
            }

            return(beacon);
        }
示例#5
0
 /// <summary>
 /// Compares the given beacon to this.
 /// </summary>
 /// <param name="beacon">The beacon to compare to.</param>
 /// <returns>True, if the beacons match.</returns>
 public bool Matches(Beacon beacon)
 {
     return(beacon.Id1.Equals(Id1) &&
            beacon.Id2 == Id2 &&
            beacon.Id3 == Id3);
 }