Пример #1
0
 /// <summary>
 ///     Creates a new instance of <see cref="PCIAddress" /> class.
 /// </summary>
 /// <param name="vendorId">The device vendor identification number.</param>
 /// <param name="deviceId">The device identification number.</param>
 /// <param name="subSystem">The PCI address subsystem information.</param>
 /// <param name="addressClass">The PCI address class information.</param>
 // ReSharper disable once TooManyDependencies
 public PCIAddress(
     ushort vendorId,
     ushort deviceId,
     PCIAddressSubSystem subSystem,
     PCIAddressClass addressClass) : this(
         vendorId, deviceId, subSystem, addressClass, null, null)
 {
 }
Пример #2
0
 /// <summary>
 ///     Creates a new instance of <see cref="PCIAddress" /> class.
 /// </summary>
 /// <param name="vendorId">The device vendor identification number.</param>
 /// <param name="deviceId">The device identification number.</param>
 /// <param name="subSystem">The PCI address subsystem information.</param>
 /// <param name="addressClass">The PCI address class information.</param>
 /// <param name="revision">The device revision.</param>
 /// <param name="deviceType">The device type.</param>
 // ReSharper disable once TooManyDependencies
 public PCIAddress(
     ushort vendorId,
     ushort deviceId,
     PCIAddressSubSystem subSystem,
     PCIAddressClass addressClass,
     byte?revision,
     ushort?deviceType)
 {
     VendorId   = vendorId;
     DeviceId   = deviceId;
     SubSystem  = subSystem;
     Class      = addressClass;
     Revision   = revision;
     DeviceType = deviceType;
 }
Пример #3
0
 /// <summary>
 ///     Creates a new instance of <see cref="PCIAddress" /> class.
 /// </summary>
 /// <param name="vendorId">The device vendor identification number.</param>
 /// <param name="deviceId">The device identification number.</param>
 /// <param name="addressClass">The PCI address class information.</param>
 public PCIAddress(ushort vendorId, ushort deviceId, PCIAddressClass addressClass) : this(vendorId, deviceId,
                                                                                          null, addressClass)
 {
 }
Пример #4
0
        /// <summary>
        ///     Parses an string representing a PCI address and return a new instance of <see cref="PCIAddress" /> class.
        /// </summary>
        /// <param name="address">The PCI address represented as an string.</param>
        /// <returns>The newly created instance of <see cref="PCIAddress" />.</returns>
        // ReSharper disable once ExcessiveIndentation
        public static PCIAddress Parse(string address)
        {
            ushort?vendorId = null;
            ushort?deviceId = null;
            PCIAddressSubSystem subSystem    = null;
            PCIAddressClass     addressClass = null;
            byte?  revision   = null;
            ushort?deviceType = null;

            var parts = address.ToUpper().Split(new[] { "&", "\\", "/" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var part in parts)
            {
                if (part.StartsWith(VendorIdentifier))
                {
                    var vendorParts = part.Split('_');

                    if (vendorParts.Length == 2 && vendorParts[1].Length == 4)
                    {
                        vendorId = Convert.ToUInt16(vendorParts[1], 16);
                    }
                }
                else if (part.StartsWith(DeviceIdentifier))
                {
                    var deviceParts = part.Split('_');

                    if (deviceParts.Length == 2 && deviceParts[1].Length == 4)
                    {
                        deviceId = Convert.ToUInt16(deviceParts[1], 16);
                    }
                }
                else if (part.StartsWith(PCIAddressSubSystem.SubSystemIdentifier))
                {
                    var subSystemParts = part.Split('_');

                    if (subSystemParts.Length == 2 && subSystemParts[1].Length == 8)
                    {
                        var subSystemDeviceId = Convert.ToUInt16(subSystemParts[1].Substring(0, 4), 16);
                        var subSystemVendorId = Convert.ToUInt16(subSystemParts[1].Substring(4), 16);
                        subSystem = new PCIAddressSubSystem(subSystemVendorId, subSystemDeviceId);
                    }
                }
                else if (part.StartsWith(PCIAddressClass.ClassIdentifier))
                {
                    var classParts = part.Split('_');

                    if (classParts.Length == 2 && classParts[1].Length >= 4)
                    {
                        var baseClassCode = Convert.ToByte(classParts[1].Substring(0, 2), 16);
                        var subClassCode  = Convert.ToByte(classParts[1].Substring(2), 16);

                        if (classParts[1].Length == 6)
                        {
                            var interfaceCode = Convert.ToByte(classParts[1].Substring(4), 16);
                            addressClass = new PCIAddressClass(baseClassCode, subClassCode, interfaceCode);
                        }
                        else
                        {
                            addressClass = new PCIAddressClass(baseClassCode, subClassCode);
                        }
                    }
                }
                else if (part.StartsWith(RevisionIdentifier))
                {
                    var revisionParts = part.Split('_');

                    if (revisionParts.Length == 2 && revisionParts[1].Length == 2)
                    {
                        revision = Convert.ToByte(revisionParts[1], 16);
                    }
                }
                else if (part.StartsWith(DeviceTypeIdentifier))
                {
                    var deviceTypeParts = part.Split('_');

                    if (deviceTypeParts.Length == 2 && deviceTypeParts[1].Length == 4)
                    {
                        deviceType = Convert.ToUInt16(deviceTypeParts[1], 16);
                    }
                }
            }

            if (vendorId == null || deviceId == null)
            {
                throw new FormatException("Invalid address format provided.");
            }

            return(new PCIAddress(vendorId.Value, deviceId.Value, subSystem, addressClass, revision, deviceType));
        }
Пример #5
0
 /// <summary>
 ///     Searches for a device subclass based on the passed <see cref="PCIAddressClass" /> instance.
 /// </summary>
 /// <param name="addressClass">
 ///     An instance of <see cref="PCIAddressClass" /> class containing information required to
 ///     search for a device subclass.
 /// </param>
 /// <returns>An instance of <see cref="PCIDeviceSubClass" /> class if a subclass is found; otherwise null.</returns>
 public static PCIDeviceSubClass GetDeviceSubClass(PCIAddressClass addressClass)
 {
     return(GetDeviceSubClass(addressClass.BaseClassId, addressClass.SubClassId));
 }
Пример #6
0
        /// <summary>
        ///     Searches for a device subclass programing interface based on the passed <see cref="PCIAddressClass" /> instance.
        /// </summary>
        /// <param name="addressClass">
        ///     An instance of <see cref="PCIAddressClass" /> class containing information required to
        ///     search for a device subclass programing interface.
        /// </param>
        /// <returns>
        ///     An instance of <see cref="PCIDeviceClassProgramingInterface" /> class if a sub class programing interface is
        ///     found; otherwise null.
        /// </returns>
        public static PCIDeviceClassProgramingInterface GetDeviceClassProgramingInterface(PCIAddressClass addressClass)
        {
            if (addressClass == null)
            {
                throw new ArgumentNullException(nameof(addressClass));
            }

            if (addressClass.ProgramingInterfaceId == null)
            {
                return(null);
            }

            return(GetDeviceClassProgramingInterface(addressClass.BaseClassId, addressClass.SubClassId,
                                                     addressClass.ProgramingInterfaceId.Value));
        }