/** @brief : call when tag infos are recieved
         */
        private async void Tag_Received(BluetoothLEAdvertisementWatcher received, BluetoothLEAdvertisementReceivedEventArgs args)
        {
            //show only connectable tags
            if (args.AdvertisementType == BluetoothLEAdvertisementType.ConnectableDirected || args.AdvertisementType == BluetoothLEAdvertisementType.ConnectableUndirected)
            {
                //get tag infos
                Taginfo taginfo = new Taginfo();
                taginfo.TagMac  = args.BluetoothAddress.ToString("X");
                taginfo.TagName = args.Advertisement.LocalName;
                taginfo.TagRssi = args.RawSignalStrengthInDBm;

                //get tag datas
                string datasection = String.Empty;
                foreach (BluetoothLEAdvertisementDataSection section in args.Advertisement.DataSections)
                {
                    var data = new byte[section.Data.Length];
                    using (var reader = DataReader.FromBuffer(section.Data))
                    {
                        reader.ReadBytes(data);
                        datasection = String.Format("{0}", BitConverter.ToString(data));
                        taginfo.TagDataRaw.Add(datasection);
                    }
                }
                taginfo.getData();

                if (taginfo.TagName.Equals(String.Empty) == false)
                {
                    //add new tag
                    if (this.tagList.ContainsKey(taginfo.TagMac) == false)
                    {
                        this.tagList.Add(taginfo.TagMac, taginfo);
                        if (Filter(taginfo))
                        {
                            await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                            {
                                tagColl.Add(taginfo);
                            });
                        }
                    }
                    //update existing tag infos
                    else if (tagList.ContainsValue(taginfo) == false)
                    {
                        await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                        {
                            IEnumerable <Taginfo> existing = tagColl.Where(x => x.TagMac == taginfo.TagMac);
                            int a = tagColl.IndexOf(existing.FirstOrDefault());
                            if (Filter(taginfo))
                            {
                                if (a >= 0 && a < tagColl.Count())
                                {
                                    tagColl[a].update(taginfo);
                                }
                            }
                            this.tagList[taginfo.TagMac].update(taginfo);
                        });
                    }
                }
            }
        }
 /** @brief : filter tag mac adress or name
  * @return : true if tag matches false otherwise
  */
 private bool Filter(Taginfo taginfo)
 {
     if (taginfo.TagMac.ToLower().Contains(filter.ToLower()) || taginfo.TagName.ToLower().Contains(filter.ToLower()))
     {
         return(true);
     }
     return(false);
 }
        /** @brief : update filter for the search
         * update shown tags depending on the search
         */
        private void TxtSearch_TextChanged(object sender, TextChangedEventArgs e)
        {
            filter = txtSearch.Text;
            this.tagColl.Clear();

            //update shown tags corresponding to search text
            foreach (KeyValuePair <string, Taginfo> pair in this.tagList)
            {
                Taginfo taginfo = new Taginfo();
                taginfo = pair.Value;
                if (Filter(taginfo))
                {
                    this.tagColl.Add(taginfo);
                }
            }
        }
Esempio n. 4
0
 /** @brief : update showned values
  * @param [in] taginfo : Taginfo with updated values
  */
 public void update(Taginfo taginfo)
 {
     this.TagName = taginfo.TagName;
     this.TagRssi = taginfo.TagRssi;
     this.TagData = taginfo.TagData;
 }