devicedescriptor.java

来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 170 行

JAVA
170
字号
/*
 * $Id: DeviceDescriptor.java,v 1.1 2003/11/25 11:41:20 epr Exp $
 */
package org.jnode.driver.usb;

import org.jnode.util.NumberUtils;

/**
 * @author Ewout Prangsma (epr@users.sourceforge.net)
 */
public final class DeviceDescriptor extends AbstractDescriptor {

	private String manufacturer;
	private String product;
	private String serialNumber;
	
	/**
	 * Create a new instance
	 */
	public DeviceDescriptor() {
		super(USB_DT_DEVICE_SIZE);
	}
	
	/**
	 * Gets the USB version as BCD encoded value.
	 * E.g. 0x210 = 2.10.
	 */
	public final int getUSBVersion() {
		return getShort(2);
	}
	
	/**
	 * Gets the device class.
	 */
	public final int getDeviceClass() {
		return getByte(4);
	}
		
	/**
	 * Gets the device subclass.
	 */
	public final int getDeviceSubClass() {
		return getByte(5);
	}
	
	/**
	 * Gets the device protocol.
	 */
	public final int getDeviceProtocol() {
		return getByte(6);
	}
	
	/**
	 * Gets the maximum packet size for endpoint 0.
	 */
	public final int getMaxPacketSize0() {
		return getByte(7);
	}
	
	/**
	 * Gets the vendor ID
	 */
	public final int getVendorID() {
		return getShort(8);
	}
	
	/**
	 * Gets the product ID
	 */
	public final int getProductID() {
		return getShort(10);
	}
	
	/**
	 * Gets the device release number as BCD encoded value.
	 */
	public final int getDeviceRelease() {
		return getShort(12);
	}
	
	/**
	 * Gets the index of string descriptor describing manufacturer.
	 */
	public final int getManufacturerStringIndex() {
		return getByte(14);
	}
	
	/**
	 * Gets the index of string descriptor describing product.
	 */
	public final int getProductStringIndex() {
		return getByte(15);
	}
	
	/**
	 * Gets the index of string descriptor describing serial number.
	 */
	public final int getSerialNumberStringIndex() {
		return getByte(16);
	}
	
	/**
	 * Gets the number of configurations
	 */
	public final int getNumConfigurations() {
		return getByte(17);
	}
	
	/**
	 * @return Returns the manufacturer.
	 */
	public final String getManufacturerName() {
		return this.manufacturer;
	}

	/**
	 * @return Returns the product.
	 */
	public final String getProductName() {
		return this.product;
	}

	/**
	 * @return Returns the serialNumber.
	 */
	public final String getSerialNumber() {
		return this.serialNumber;
	}

	/**
	 * Load all strings with the default Language ID.
	 * @param dev
	 */
	final void loadStrings(USBDevice dev) 
	throws USBException {
		final int manIdx = getManufacturerStringIndex();
		if (manIdx > 0) {
			manufacturer = dev.getString(manIdx, 0);
		} 
		final int prodIdx = getProductStringIndex();
		if (prodIdx > 0) {
			product = dev.getString(prodIdx, 0);
		}
		final int snIdx = getSerialNumberStringIndex();
		if (snIdx > 0) {
			serialNumber = dev.getString(snIdx, 0);
		}
	}
	
	/**
	 * Convert to a String representation 
	 * @see java.lang.Object#toString()
	 */
	public final String toString() {
		return "DEV[usb:0x" + NumberUtils.hex(getUSBVersion(), 4) +
			", dclass:" + getDeviceClass() + 
			", dsubcls:" + getDeviceSubClass() +
			", dprot:" + getDeviceProtocol() +
			", maxps0:" + getMaxPacketSize0() +
			", vendor:0x" + NumberUtils.hex(getVendorID(), 4) +
			", prod:0x" + NumberUtils.hex(getProductID(), 4) +
			", devrel:0x" + NumberUtils.hex(getDeviceRelease(), 4) +
			", manu:" + ((manufacturer != null) ? manufacturer : ("%" + getManufacturerStringIndex())) +
			", prod:" + ((product != null) ? product : ("%" + getProductStringIndex())) +
			", sernr:" + ((serialNumber != null) ? serialNumber : ("%" + getSerialNumberStringIndex())) +
			", #cnf:" + getNumConfigurations() + "]";
	}
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?