Esempio n. 1
0
        private CmdGetCapabilitiesDescriptorResponse GetFullDescriptor(int size, IUsbControlPipe controlPipe, ILogger logger)
        {
            var package = GetFullDescriptorRequest(size);

            try
            {
                var response = controlPipe.ControlTransferIn(
                    package.bmRequestType, package.bRequest, package.wValue, package.wIndex, package.wLength);

                var descriptor = response.ToInternalCapabilitiesDescriptor();

                return(new CmdGetCapabilitiesDescriptorResponse
                {
                    Succeeded = true,
                    CapabilitiesDescriptor = descriptor
                });
            }
            catch (Exception ex)
            {
                logger.LogError($"Error retrieving capabilities descriptor (requested {size} bytes)", ex);
                return(new CmdGetCapabilitiesDescriptorResponse
                {
                    Succeeded = false,
                    CapabilitiesDescriptor = null
                });
            }
        }
        public X20DeviceImplementation(ILogger logger, IUsbDataPipe usbDataPipe, IUsbControlPipe usbControlPipe, string serialNumber)
        {
            _logger         = logger;
            _usbDataPipe    = usbDataPipe;
            _usbControlPipe = usbControlPipe;
            _serialNumber   = serialNumber;

            _capabilities = RetrieveCapabilities();

            LogDeviceInformation(_logger, _capabilities);
        }
Esempio n. 3
0
        private int GetDescriptorSize(IUsbControlPipe controlPipe)
        {
            var package = GetPartialDescriptorRequest();

            try
            {
                var response = controlPipe.ControlTransferIn(
                    package.bmRequestType, package.bRequest, package.wValue, package.wIndex, package.wLength);

                return(response[0] + (response[1] << 8));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error retrieving the size of the capabilities descriptor");
                return(0);
            }
        }
Esempio n. 4
0
        public ICommandResponse Execute(IUsbControlPipe controlPipe)
        {
            if (controlPipe == null)
            {
                throw new ArgumentNullException(nameof(controlPipe));
            }

            var size = GetDescriptorSize(controlPipe);

            if (size < 14)
            {
                _logger.LogError($"The reported size of the capabilities descriptor is too small ({size} bytes)");
                return(new CmdGetCapabilitiesDescriptorResponse
                {
                    Succeeded = false,
                    CapabilitiesDescriptor = null
                });
            }
            return(GetFullDescriptor(size, controlPipe, _logger));
        }
Esempio n. 5
0
        public ICommandResponse Execute(IUsbControlPipe controlPipe)
        {
            if (controlPipe == null)
            {
                throw new ArgumentNullException(nameof(controlPipe));
            }

            var package = GetSetupPackage();

            if (package.wLength == 0)
            {
                try
                {
                    controlPipe.ControlTransfer(
                        package.bmRequestType, package.bRequest, package.wValue, package.wIndex);
                    return(ParseEmptyResponse());
                }
                catch (Exception ex)
                {
                    Logger.LogError($"Error executing command {GetType().Name}", ex);
                    return(ParseFailure(ex));
                }
            }
            else
            {
                try
                {
                    var response = controlPipe.ControlTransferIn(
                        package.bmRequestType, package.bRequest, package.wValue, package.wIndex, package.wLength);
                    return(ParseResponse(response));
                }
                catch (Exception ex)
                {
                    Logger.LogError($"Error executing command {GetType().Name}", ex);
                    return(ParseFailure(ex));
                }
            }
        }