Ejemplo n.º 1
0
        public void LoadConfig()
        {
            MetaData.Metadata.Init(jString);
            if (UsbConfiguration.USB_DeviceConnected())
            {
                //if()
                //{
                //}


                if (UsbConfiguration.Usb_FilesStatus())
                {
                    Dpath = UsbConfiguration.directory;
                    InitializeComponent();
                    Switcher.pageSwitcher = this;
                    Switcher.Switch(new UILevel());
                }
                else
                {
                    System.Windows.MessageBox.Show("Your Subsrciption has been Expired :D");
                    this.Close();
                }
            }
            else
            {
                System.Windows.MessageBox.Show("BaryeMeharbani Exambite ki Usb connect karain.");
                this.Close();
            }
        }
        public void AddDescriptor(ReadOnlySpan <byte> descriptor)
        {
            var offset = 0;
            UsbConfiguration?     configuration      = null;
            UsbAlternateInterface?alternateInterface = null;

            while (offset != descriptor.Length)
            {
                BytesToStruct(descriptor, offset, out UsbCommonDescriptor common);
                switch (common.bDescriptorType)
                {
                case UsbDescriptorType.USB_CONFIGURATION_DESCRIPTOR_TYPE:
                    if (configuration != null)
                    {
                        throw new ArgumentException("duplicate USB_CONFIGURATION_DESCRIPTOR_TYPE");
                    }
                    BytesToStruct(descriptor, offset, out UsbConfigurationDescriptor config);
                    configuration = new UsbConfiguration(config);
                    Configurations.Add(config.bConfigurationValue, configuration);
                    break;

                case UsbDescriptorType.USB_INTERFACE_DESCRIPTOR_TYPE:
                    if (configuration == null)
                    {
                        throw new ArgumentException("expected USB_CONFIGURATION_DESCRIPTOR_TYPE");
                    }
                    BytesToStruct(descriptor, offset, out UsbInterfaceDescriptor iface);
                    if (iface.bAlternateSetting == 0)
                    {
                        configuration.Interfaces[iface.bInterfaceNumber] = new UsbInterface();
                    }
                    alternateInterface = new UsbAlternateInterface(iface);
                    configuration.Interfaces[iface.bInterfaceNumber].Alternates[iface.bAlternateSetting] = alternateInterface;
                    break;

                case UsbDescriptorType.USB_ENDPOINT_DESCRIPTOR_TYPE:
                    if (alternateInterface == null)
                    {
                        throw new ArgumentException("expected USB_INTERFACE_DESCRIPTOR_TYPE");
                    }
                    BytesToStruct(descriptor, offset, out UsbEndpointDescriptor ep);
                    var endpoint = new UsbEndpoint(ep);
                    switch (endpoint.TransferType)
                    {
                    case UsbEndpointType.USB_ENDPOINT_TYPE_CONTROL:
                        alternateInterface.Endpoints.Add((byte)(ep.bEndpointAddress & 0x0f), endpoint);
                        break;

                    default:
                        alternateInterface.Endpoints.Add((byte)(ep.bEndpointAddress & 0x8f), endpoint);
                        break;
                    }
                    break;
                }
                offset += common.bLength;
            }
        }