Exemplo n.º 1
0
        private void CreateDebugTree()
        {
            BLE_ServiceDataModel service1 = new BLE_ServiceDataModel();

            service1.DisplayName = "Hogwarts 1 service";
            service1.Characteristics.Add(new BLE_CharacteristicDataModel());
            service1.Characteristics[0].CharName = "George Characteristic";
            service1.Characteristics[0].Descriptors.Add(new BLE_DescriptorDataModel());
            service1.Characteristics[0].Descriptors[0].DisplayName = "Output descriptor";
            service1.Characteristics.Add(new BLE_CharacteristicDataModel());
            service1.Characteristics[1].CharName = "Fred Characteristic";
            service1.Characteristics[1].Descriptors.Add(new BLE_DescriptorDataModel());
            service1.Characteristics[1].Descriptors[0].DisplayName = "Input descriptor";
            service1.Characteristics[1].Descriptors.Add(new BLE_DescriptorDataModel());
            service1.Characteristics[1].Descriptors[1].DisplayName = "Name of stuff";
            this.treeDict.Add("1", service1);

            BLE_ServiceDataModel service2 = new BLE_ServiceDataModel();

            service2.DisplayName = "Hogwarts 2 service";
            service2.Characteristics.Add(new BLE_CharacteristicDataModel());
            service2.Characteristics[0].CharName = "Hermioni characteristic";
            service2.Characteristics.Add(new BLE_CharacteristicDataModel());
            service2.Characteristics[1].CharName = "Ginny characteristic";
            this.treeDict.Add("2", service2);

            // Just pass list of Values to avoid headach in XAML
            this.treeServices.ItemsSource = this.treeDict.Values;
        }
Exemplo n.º 2
0
        ///////////////////////////

        private void Expand3()
        {
            foreach (var service in this.treeServices.Items)
            {
                BLE_ServiceDataModel s = service as BLE_ServiceDataModel;
                if (s != null)
                {
                    TreeViewItem tviS = treeServices.ItemContainerGenerator.ContainerFromItem(s) as TreeViewItem;
                    if (tviS != null)
                    {
                        // This expands the characteristics held in the service tree object. A List
                        tviS.IsExpanded = true;
                        foreach (object xxx in tviS.Items)
                        {
                            LogUtils.Net.Log.Info("----------------", "------------------", () => string.Format("Type name:{0}", xxx.GetType().Name));
                        }



                        //foreach(var ch in s.Characteristics) {
                        //    TreeViewItem tviC = tviS.ItemContainerGenerator.ContainerFromItem(ch.Value) as TreeViewItem;
                        //    if (tviC != null) {
                        //        tviC.IsExpanded = true;
                        //        foreach (var d in ch.Value.Descriptors) {
                        //            TreeViewItem tviD = tviC.ItemContainerGenerator.ContainerFromItem(d.Value) as TreeViewItem;
                        //            if (tviD != null) {
                        //                tviD.IsExpanded = true;
                        //            }
                        //        }
                        //    }
                        //}
                    }
                }
            }
        }
 private void Translate(BLE_ServiceDataModel dataModel)
 {
     dataModel.DisplayHeader = this.GetText(MsgCode.Service);
     dataModel.DisplayName   = this.Translate(dataModel.ServiceTypeEnum, dataModel.DisplayName);
     foreach (BLE_CharacteristicDataModel d in dataModel.Characteristics)
     {
         this.Translate(d);
     }
 }
Exemplo n.º 4
0
        /// <summary>Build the GATT service data model</summary>
        /// <param name="service">The OS GATT service object</param>
        /// <param name="deviceDataModel">The portable GATT session data model</param>
        /// <returns>The async task</returns>
        public async Task BuildServiceDataModel(GattDeviceService service, BluetoothLEDeviceInfo deviceDataModel)
        {
            this.log.Info("BuildServiceDataModel", () => string.Format("Gatt Service:{0}  Uid:{1}",
                                                                       BLE_DisplayHelpers.GetServiceName(service), service.Uuid.ToString()));

            // New service data model to add to device info
            BLE_ServiceDataModel serviceDataModel = new BLE_ServiceDataModel()
            {
                Characteristics = new Dictionary <string, BLE_CharacteristicDataModel>(),
                AttributeHandle = service.AttributeHandle,
                DeviceId        = deviceDataModel.Id,
                DisplayName     = BLE_DisplayHelpers.GetServiceName(service),
                Uuid            = service.Uuid,
                SharingMode     = (BLE_SharingMode)service.SharingMode,
            };

            if (service.DeviceAccessInformation != null)
            {
                serviceDataModel.DeviceAccess = (BLE_DeviceAccessStatus)service.DeviceAccessInformation.CurrentStatus;
            }
            this.BuildSessionDataModel(service.Session, serviceDataModel.Session);

            // TODO
            //service.ParentServices

            // Get the characteristics for the service
            GattCharacteristicsResult characteristics = await service.GetCharacteristicsAsync();

            if (characteristics.Status == GattCommunicationStatus.Success)
            {
                if (characteristics.Characteristics != null)
                {
                    if (characteristics.Characteristics.Count > 0)
                    {
                        foreach (GattCharacteristic ch in characteristics.Characteristics)
                        {
                            await this.BuildCharacteristicDataModel(ch, serviceDataModel);
                        }
                    }
                    else
                    {
                        this.log.Info("ConnectToDevice", () => string.Format("No characteristics"));
                    }
                }
            }
            else
            {
                this.log.Error(9999, "HarvestDeviceInfo", () => string.Format("Failed to get Characteristics result {0}", characteristics.Status.ToString()));
            }

            // Add the service data model to the device info data model
            deviceDataModel.Services.Add(serviceDataModel.Uuid.ToString(), serviceDataModel);
        }
Exemplo n.º 5
0
        public DeviceInfo_BLESerial(Window parent)
        {
            this.parent = parent;
            InitializeComponent();
            this.SizeToContent = SizeToContent.WidthAndHeight;
            this.borderInput.MouseLeftButtonDown  += this.BorderInput_MouseLeftButtonDown;
            this.borderOutput.MouseLeftButtonDown += this.BorderOutput_MouseLeftButtonDown;
            this.widthManager = new ButtonGroupSizeSyncManager(this.btnExit, this.btnSave);
            this.widthManager.PrepForChange();

            #region Test data for info display
            // ---------------------------------------------
            BLE_ServiceDataModel service1 = new BLE_ServiceDataModel();
            service1.DisplayName = "Hogwarts 1 service";
            service1.Characteristics.Add(new BLE_CharacteristicDataModel());
            service1.Characteristics[0].CharName = "George Characteristic";
            service1.Characteristics[0].Descriptors.Add(new BLE_DescriptorDataModel());
            service1.Characteristics[0].Descriptors[0].DisplayName = "Output descriptor";
            service1.Characteristics.Add(new BLE_CharacteristicDataModel());
            service1.Characteristics[1].CharName = "Fred Characteristic";
            service1.Characteristics[1].Descriptors.Add(new BLE_DescriptorDataModel());
            service1.Characteristics[1].Descriptors[0].DisplayName = "Input descriptor";
            service1.Characteristics[1].Descriptors.Add(new BLE_DescriptorDataModel());
            service1.Characteristics[1].Descriptors[1].DisplayName = "Name of stuff";
            this.treeDict.Add("1", service1);
            // ---------------------------------------------

            // ---------------------------------------------
            BLE_ServiceDataModel service2 = new BLE_ServiceDataModel();
            service2.DisplayName = "Hogwarts 2 service";
            service2.Characteristics.Add(new BLE_CharacteristicDataModel());
            service2.Characteristics[0].CharName = "Hermioni characteristic";
            service2.Characteristics.Add(new BLE_CharacteristicDataModel());
            service2.Characteristics[1].CharName = "Ginny characteristic";
            this.treeDict.Add("2", service2);

            // Just pass list of Values to avoid headach in XAML
            this.treeServices.ItemsSource = this.treeDict.Values;
            #endregion

            // Set the input as the active
            this.borderInput.BorderThickness = new Thickness(2);
        }
        private async Task BuildCharacteristicDataModel(GattCharacteristic ch, BLE_ServiceDataModel service)
        {
            try {
                BLE_CharacteristicDataModel characteristic = new BLE_CharacteristicDataModel();
                characteristic.Uuid                = ch.Uuid;
                characteristic.UserDescription     = ch.UserDescription;
                characteristic.AttributeHandle     = ch.AttributeHandle;
                characteristic.Service             = service;
                characteristic.CharName            = BLE_DisplayHelpers.GetCharacteristicName(ch);
                characteristic.PropertiesFlags     = ch.CharacteristicProperties.ToUInt().ToEnum <CharacteristicProperties>();
                characteristic.ProtectionLevel     = (BLE_ProtectionLevel)ch.ProtectionLevel;
                characteristic.PresentationFormats = this.BuildPresentationFormats(ch);
                await this.BuildDescriptors(ch, characteristic);

                service.Characteristics.Add(characteristic.Uuid.ToString(), characteristic);
            }
            catch (Exception e) {
                this.log.Exception(9999, "Failed during build of characteristic", e);
            }
        }
Exemplo n.º 7
0
        private async Task BuildCharacteristicDataModel(GattCharacteristic ch, BLE_ServiceDataModel service)
        {
            try {
                this.log.InfoEntry("BuildCharacteristicDataModel");
                BLE_CharacteristicDataModel characteristic = new BLE_CharacteristicDataModel();
                // Build descriptors first to allow them to be used to build unknown Characteristic values
                await this.BuildDescriptors(ch, characteristic);

                characteristic.Uuid            = ch.Uuid;
                characteristic.GattType        = BLE_DisplayHelpers.GetCharacteristicEnum(ch);
                characteristic.UserDescription = ch.UserDescription;
                characteristic.AttributeHandle = ch.AttributeHandle;
                characteristic.Service         = service;
                characteristic.CharName        = BLE_DisplayHelpers.GetCharacteristicName(ch);
                // Must put this before the properties for indicate or Notify to work
                // TODO - notify value is no longer showing properly. But notification itself working
                bool subscribe = await this.EnableNotifyIndicate(ch);

                characteristic.PropertiesFlags     = ch.CharacteristicProperties.ToUInt().ToEnum <CharacteristicProperties>();
                characteristic.ProtectionLevel     = (BLE_ProtectionLevel)ch.ProtectionLevel;
                characteristic.PresentationFormats = this.BuildPresentationFormats(ch);

                // Do this after all else is defined
                characteristic.Parser = this.charParserFactory.GetParser(ch.Uuid, ch.AttributeHandle);
                this.RaiseIfError(characteristic.SetDescriptorParsers());
                characteristic.CharValue = await this.ReadValue(ch, characteristic);

                // Associate the UWP and data model characteristic for 2 way events to set and get
                this.binderSet.Add(new BLE_CharacteristicBinder(ch, characteristic, subscribe));

                service.Characteristics.Add(characteristic);

                // This also sends and receives dummy data to Arduino
                //await this.DumpCharacteristic(ch);
            }
            catch (Exception e) {
                this.log.Exception(9999, "Failed during build of characteristic", e);
            }
        }