⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hubdescriptor.java

📁 纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统
💻 JAVA
字号:
/*
 * $Id: HubDescriptor.java,v 1.1 2003/11/25 11:42:24 epr Exp $
 */
package org.jnode.driver.usb.hub;

import org.jnode.driver.usb.AbstractDescriptor;
import org.jnode.util.NumberUtils;

/**
 * @author Ewout Prangsma (epr@users.sourceforge.net)
 */
public class HubDescriptor extends AbstractDescriptor implements USBHubConstants {

	/**
	 * Initialize this instance.
	 */
	public HubDescriptor() {
		super(USB_DT_HUB_NONVAR_SIZE + (256 / 8) * 2);
	}

	/**
	 * Gets the number of downstream ports
	 */
	public final int getNumPorts() {
		return getByte(2);
	}

	/**
	 * Gets the HUB characteristics
	 */
	public final int getCharacteristics() {
		return getShort(3);
	}

	/**
	 * Gets the logical power switching mode.
	 * @return 0=all at once, 1=individual ports, 2=3=reserved
	 */
	public final int getLogicalPowerSwitchingMode() {
		return getShort(3) & HUB_CHAR_LPSM;
	}
	
	/**
	 * Gets the number of milliseconds between a power on and a power good situation on a port. The
	 * HUB descriptor gives this number in 2ms intervals, the value returned is in ms, which
	 * implies that the descriptor value has already been multiplied by 2.
	 */
	public final int getPowerOn2PowerGood() {
		return getByte(5) << 1;
	}

	/**
	 * Gets the maximum current requirements of the HUB controller in mA.
	 */
	public final int getHubControllerCurrent() {
		return getByte(6);
	}

	/**
	 * Is the device connected to the given port removable.
	 * 
	 * @param port
	 */
	public final boolean isRemovableDevice(int port) {
		return ((getByte(7 + (port + 1) / 8) & (1 << ((port + 1) % 8))) == 0);
	}

	/**
	 * Convert to a String representation.
	 * 
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		final StringBuffer b = new StringBuffer();
		final int ports = getNumPorts();
		final int chars = getCharacteristics();
		b.append("HUB[");
		b.append("length:");
		b.append(getLength());
		b.append(", #ports:");
		b.append(ports);
		b.append(", char:0x");
		b.append(NumberUtils.hex(chars, 4));
		b.append(", pon2pg:");
		b.append(getPowerOn2PowerGood());
		b.append("maxCtrlCur:");
		b.append(getHubControllerCurrent());
		if ((chars & HUB_CHAR_COMPOUND) != 0) {
			b.append(", devs:");
			for (int i = 0; i < ports; i++) {
				b.append(isRemovableDevice(i) ? 'R' : 'F');
			}
		}
		return b.toString();
	}
}

⌨️ 快捷键说明

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