Java 类android.hardware.usb.UsbConstants 实例源码

项目:buildAPKsSamples    文件:AdbDevice.java   
public AdbDevice(AdbTestActivity activity, UsbDeviceConnection connection,
        UsbInterface intf) {
    mActivity = activity;
    mDeviceConnection = connection;
    mSerial = connection.getSerial();

    UsbEndpoint epOut = null;
    UsbEndpoint epIn = null;
    // look for our bulk endpoints
    for (int i = 0; i < intf.getEndpointCount(); i++) {
        UsbEndpoint ep = intf.getEndpoint(i);
        if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
            if (ep.getDirection() == UsbConstants.USB_DIR_OUT) {
                epOut = ep;
            } else {
                epIn = ep;
            }
        }
    }
    if (epOut == null || epIn == null) {
        throw new IllegalArgumentException("not all endpoints found");
    }
    mEndpointOut = epOut;
    mEndpointIn = epIn;
}
项目:UsbHid    文件:UsbHidDevice.java   
private UsbHidDevice(UsbDevice usbDevice, UsbInterface usbInterface, UsbManager usbManager) {
    mUsbDevice = usbDevice;
    mUsbInterface = usbInterface;
    mUsbManager= usbManager;

    for (int i = 0; i < mUsbInterface.getEndpointCount(); i++) {
        UsbEndpoint endpoint = mUsbInterface.getEndpoint(i);
        int dir = endpoint.getDirection();
        int type = endpoint.getType();
        if (mInUsbEndpoint == null && dir == UsbConstants.USB_DIR_IN && type == UsbConstants.USB_ENDPOINT_XFER_INT) {
            mInUsbEndpoint = endpoint;
        }
        if (mOutUsbEndpoint == null && dir == UsbConstants.USB_DIR_OUT && type == UsbConstants.USB_ENDPOINT_XFER_INT) {
            mOutUsbEndpoint = endpoint;
        }
    }
}
项目:InstantUpload    文件:BaselineInitiator.java   
/**
 * Sends a USB level CLASS_DEVICE_RESET control message.
 * All PTP-over-USB devices support this operation.
 * This is documented to clear stalls and camera-specific suspends,
 * flush buffers, and close the current session.
 *
 */
public void reset() throws PTPException 
{
    if (mConnection == null) throw new PTPException("No Connection");

    mConnection.controlTransfer(
            (int) ( UsbConstants.USB_DIR_OUT      |
                    UsbConstants.USB_TYPE_CLASS        /* |
                    UsbConstants.RECIPIENT_INTERFACE */),
            CLASS_DEVICE_RESET,
            0,
            0,
            new byte[0],
            0,
            DEFAULT_TIMEOUT //,
            //false
        );

        session.close();
}
项目:365browser    文件:UsbMidiDeviceFactoryAndroid.java   
/**
 * Request a device access permission if there is a MIDI interface in the device.
 *
 * @param device a USB device
 */
private void requestDevicePermissionIfNecessary(UsbDevice device) {
    for (UsbDevice d : mRequestedDevices) {
        if (d.getDeviceId() == device.getDeviceId()) {
            // It is already requested.
            return;
        }
    }

    for (int i = 0; i < device.getInterfaceCount(); ++i) {
        UsbInterface iface = device.getInterface(i);
        if (iface.getInterfaceClass() == UsbConstants.USB_CLASS_AUDIO
                && iface.getInterfaceSubclass() == UsbMidiDeviceAndroid.MIDI_SUBCLASS) {
            // There is at least one interface supporting MIDI.
            mUsbManager.requestPermission(device,
                    PendingIntent.getBroadcast(ContextUtils.getApplicationContext(), 0,
                            new Intent(ACTION_USB_PERMISSION), 0));
            mRequestedDevices.add(device);
            break;
        }
    }
}
项目:365browser    文件:UsbMidiDeviceAndroid.java   
/**
 * Returns the string descriptor bytes for the given index
 * @param index index of the descriptor
 * @return the string descriptor bytes for the given index.
 */
@CalledByNative
byte[] getStringDescriptor(int index) {
    if (mConnection == null) {
        return new byte[0];
    }
    byte[] buffer = new byte[255];
    int type = UsbConstants.USB_DIR_IN | UsbConstants.USB_TYPE_STANDARD;
    int request = REQUEST_GET_DESCRIPTOR;
    int value = (STRING_DESCRIPTOR_TYPE << 8) | index;
    int read = mConnection.controlTransfer(type, request, value, 0, buffer, buffer.length, 0);
    if (read < 0) {
        return new byte[0];
    }
    return Arrays.copyOf(buffer, read);
}
项目:cordova-plugin-chrome-apps-usb    文件:ChromeUsb.java   
private void controlTransfer(CordovaArgs args, JSONObject params,
        final CallbackContext callbackContext) throws JSONException, UsbError {
    ConnectedDevice dev = getDevice(params);

    int direction = directionFromName(params.getString("direction"));
    int requestType = controlRequestTypeFromName(params.getString("requestType"));
    int recipient = recipientFromName(params.getString("recipient"));

    byte[] transferBuffer = getByteBufferForTransfer(args, params, UsbConstants.USB_DIR_OUT);
    byte[] receiveBuffer = getByteBufferForTransfer(args, params, UsbConstants.USB_DIR_IN);

    int ret = dev.controlTransfer(
            direction | requestType | recipient,
            params.getInt("request"),
            params.getInt("value"),
            params.getInt("index"),
            transferBuffer,
            receiveBuffer,
            params.getInt("timeout"));
    if (ret < 0) {
        throw new UsbError("Control transfer returned " + ret);
    }

    /* control transfer is bidirectional, buffer should alway be passed */
    callbackContext.success(Arrays.copyOf(receiveBuffer, receiveBuffer.length));
}
项目:cordova-plugin-chrome-apps-usb    文件:ChromeUsb.java   
private void bulkTransfer(CordovaArgs args, JSONObject params,
        final CallbackContext callbackContext) throws JSONException, UsbError {
    ConnectedDevice dev = getDevice(params);
    int endpointAddress = params.getInt("endpoint");
    int interfaceNumber = endpointAddress >> ENDPOINT_IF_SHIFT;
    int endpointNumber = endpointAddress & ((1 << ENDPOINT_IF_SHIFT) - 1);
    if (interfaceNumber >= dev.getInterfaceCount() ||
            endpointNumber >= dev.getEndpointCount(interfaceNumber)) {
        throw new UsbError("Enpoint not found: " + endpointAddress);
    }
    int direction = directionFromName(params.getString("direction"));
    byte[] buffer = getByteBufferForTransfer(args, params, direction);

    int ret = dev.bulkTransfer(interfaceNumber, endpointNumber, direction, buffer,
            params.getInt("timeout"));
    if (ret < 0) {
        throw new UsbError("Bulk transfer returned " + ret);
    }
    if (direction == UsbConstants.USB_DIR_IN) {
        callbackContext.success(Arrays.copyOf(buffer, ret));
    } else {
        callbackContext.success();
    }
}
项目:cordova-plugin-chrome-apps-usb    文件:ChromeUsb.java   
private void interruptTransfer(CordovaArgs args, JSONObject params,
                               final CallbackContext callbackContext) throws JSONException, UsbError {
    ConnectedDevice dev = getDevice(params);
    int endpointAddress = params.getInt("endpoint");
    int interfaceNumber = endpointAddress >> ENDPOINT_IF_SHIFT;
    int endpointNumber = endpointAddress & ((1 << ENDPOINT_IF_SHIFT) - 1);
    if (interfaceNumber >= dev.getInterfaceCount() ||
            endpointNumber >= dev.getEndpointCount(interfaceNumber)) {
        throw new UsbError("Enpoint not found: " + endpointAddress);
    }

    int direction = directionFromName(params.getString("direction"));
    byte[] buffer = getByteBufferForTransfer(args, params, direction);

    int ret = dev.interruptTransfer(interfaceNumber, endpointNumber, direction, buffer,
            params.getInt("timeout"));
    if (ret < 0) {
        throw new UsbError("Interrupt transfer returned " + ret);
    }
    if (direction == UsbConstants.USB_DIR_IN) {
        callbackContext.success(Arrays.copyOf(buffer, ret));
    } else {
        callbackContext.success();
    }
}
项目:cordova-plugin-chrome-apps-usb    文件:ChromeUsb.java   
int bulkTransfer(int interfaceNumber, int endpointNumber, int direction,
                 byte[] buffer, int timeout)
        throws UsbError {
    if (direction == UsbConstants.USB_DIR_OUT) {
        echoBytes = buffer;
        return echoBytes.length;
    }
    // IN transfer.
    if (echoBytes == null) {
        return 0;
    }
    int len = Math.min(echoBytes.length, buffer.length);
    System.arraycopy(echoBytes, 0, buffer, 0, len);
    echoBytes = null;
    return len;
}
项目:cordova-plugin-chrome-apps-usb    文件:ChromeUsb.java   
int interruptTransfer(int interfaceNumber, int endpointNumber, int direction,
                      byte[] buffer, int timeout)
        throws UsbError {
    if (direction == UsbConstants.USB_DIR_OUT) {
        echoBytes = buffer;
        return echoBytes.length;
    }
    // IN transfer.
    if (echoBytes == null) {
        return 0;
    }
    int len = Math.min(echoBytes.length, buffer.length);
    System.arraycopy(echoBytes, 0, buffer, 0, len);
    echoBytes = null;
    return len;
}
项目:eIDSuite    文件:EidService.java   
private String getProductName(UsbDevice device) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return getProductNameFromOs(device);
    } else {
        int deviceClass = device.getDeviceClass();
        if (deviceClass != UsbConstants.USB_CLASS_PER_INTERFACE) {
            return getClassName(deviceClass);
        } else {
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < device.getInterfaceCount(); i++) {
                deviceClass = device.getInterface(i).getInterfaceClass();
                if (builder.length() > 0) {
                    builder.append('/');
                }
                builder.append(getClassName(deviceClass));
            }
            return builder.toString();
        }
    }
}
项目:android-ambit    文件:AndroidAmbitDevice.java   
@Override
public boolean open() {
    iface = device.getInterface(0);
    Log.d(TAG, "Endpoint Count: " + iface.getEndpointCount());
    UsbEndpoint ep0 = iface.getEndpoint(0);
    UsbEndpoint ep1 = iface.getEndpoint(1);

    if (ep0.getDirection() == UsbConstants.USB_DIR_IN) {
        in = ep0;
        out = ep1;
    } else {
        in = ep1;
        out = ep0;
    }

    con = manager.openDevice(device);

    return con != null;
}
项目:hackrf_android    文件:Hackrf.java   
/**
 * Returns the Version String of the HackRF.
 * 
 * Note: This function interacts with the USB Hardware and
 * should not be called from a GUI Thread!
 * 
 * @return HackRF Version String
 * @throws HackrfUsbException
 */
public String getVersionString() throws HackrfUsbException
{
    byte[] buffer = new byte[255];
    int len = 0;

    len = this.sendUsbRequest(UsbConstants.USB_DIR_IN, HACKRF_VENDOR_REQUEST_VERSION_STRING_READ, 0, 0, buffer);

    if (len < 1)
    {
        Log.e(logTag, "getVersionString: USB Transfer failed!");
        throw(new HackrfUsbException("USB Transfer failed!"));
    }

    return new String(buffer);
}
项目:hackrf_android    文件:Hackrf.java   
/**
 * Returns the Part ID + Serial Number of the HackRF.
 * 
 * Note: This function interacts with the USB Hardware and
 * should not be called from a GUI Thread!
 * 
 * @return int[2+6] => int[0-1] is Part ID; int[2-5] is Serial No
 * @throws HackrfUsbException
 */
public int[] getPartIdAndSerialNo() throws HackrfUsbException
{
    byte[] buffer = new byte[8+16];
    int[] ret = new int[2+4];

    if(this.sendUsbRequest(UsbConstants.USB_DIR_IN, HACKRF_VENDOR_REQUEST_BOARD_PARTID_SERIALNO_READ, 
            0, 0, buffer) != 8+16)
    {
        Log.e(logTag, "getPartIdAndSerialNo: USB Transfer failed!");
        throw(new HackrfUsbException("USB Transfer failed!"));
    }

    for(int i = 0; i < 6; i++)
    {
        ret[i] = this.byteArrayToInt(buffer, 4*i);
    }

    return ret;
}
项目:hackrf_android    文件:Hackrf.java   
/**
 * Sets the Sample Rate of the HackRF.
 * 
 * Note: This function interacts with the USB Hardware and
 * should not be called from a GUI Thread!
 * 
 * @param   sampRate    Sample Rate in Hz
 * @param   divider     Divider
 * @return  true on success
 * @throws  HackrfUsbException
 */
public boolean setSampleRate(int sampRate, int divider) throws HackrfUsbException
{
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();

    try {
        byteOut.write(this.intToByteArray(sampRate));
        byteOut.write(this.intToByteArray(divider));
    } catch (IOException e) {
        Log.e(logTag,"setSampleRate: Error while converting arguments to byte buffer.");
        return false;
    }

    if(this.sendUsbRequest(UsbConstants.USB_DIR_OUT, HACKRF_VENDOR_REQUEST_SAMPLE_RATE_SET, 
            0, 0, byteOut.toByteArray()) != 8)
    {
        Log.e(logTag, "setSampleRate: USB Transfer failed!");
        throw(new HackrfUsbException("USB Transfer failed!"));
    }

    return true;
}
项目:hackrf_android    文件:Hackrf.java   
/**
 * Sets the TX VGA Gain of the HackRF.
 * 
 * Note: This function interacts with the USB Hardware and
 * should not be called from a GUI Thread!
 * 
 * @param   gain    TX VGA Gain (0-62)
 * @return  true on success
 * @throws  HackrfUsbException
 */
public boolean setTxVGAGain(int gain) throws HackrfUsbException
{
    byte[] retVal = new byte[1];

    if(gain > 47)
    {
        Log.e(logTag,"setTxVGAGain: TX VGA Gain must be within 0-47!");
        return false;
    }

    if(this.sendUsbRequest(UsbConstants.USB_DIR_IN, HACKRF_VENDOR_REQUEST_SET_TXVGA_GAIN, 
            0, gain, retVal) != 1)
    {
        Log.e(logTag, "setTxVGAGain: USB Transfer failed!");
        throw(new HackrfUsbException("USB Transfer failed!"));
    }

    if (retVal[0] == 0)
    {
        Log.e(logTag,"setTxVGAGain: HackRF returned with an error!");
        return false;
    }

    return true;
}
项目:hackrf_android    文件:Hackrf.java   
/**
 * Sets the Frequency of the HackRF.
 * 
 * Note: This function interacts with the USB Hardware and
 * should not be called from a GUI Thread!
 * 
 * @param   frequency   Frequency in Hz
 * @return  true on success
 * @throws  HackrfUsbException
 */
public boolean setFrequency(long frequency) throws HackrfUsbException
{
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    int mhz = (int) (frequency/1000000l);
    int hz = (int) (frequency%1000000l);

    Log.d(logTag, "Tune HackRF to " + mhz + "." + hz + "MHz...");

    try {
        byteOut.write(this.intToByteArray(mhz));
        byteOut.write(this.intToByteArray(hz));
    } catch (IOException e) {
        Log.e(logTag,"setFrequency: Error while converting arguments to byte buffer.");
        return false;
    }

    if(this.sendUsbRequest(UsbConstants.USB_DIR_OUT, HACKRF_VENDOR_REQUEST_SET_FREQ, 
            0, 0, byteOut.toByteArray()) != 8)
    {
        Log.e(logTag, "setFrequency: USB Transfer failed!");
        throw(new HackrfUsbException("USB Transfer failed!"));
    }

    return true;
}
项目:hackrf_android    文件:Hackrf.java   
/**
 * Enables or Disables the Antenna Port Power of the HackRF.
 * 
 * Note: This function interacts with the USB Hardware and
 * should not be called from a GUI Thread!
 * 
 * @param   enable      true for enable or false for disable
 * @return  true on success
 * @throws  HackrfUsbException
 */
public boolean setAntennaPower(boolean enable) throws HackrfUsbException
{
    // The Jawbreaker doesn't support this command!
    if(this.getBoardID() == 1) {        // == Jawbreaker
        Log.w(logTag, "setAntennaPower: Antenna Power is not supported for HackRF Jawbreaker. Ignore.");
        return false;
    }
    // The rad1o doesn't support this command!
    if(this.getBoardID() == 3) {        // == rad1o
        Log.w(logTag, "setAntennaPower: Antenna Power is not supported for rad1o. Ignore.");
        return false;
    }
    if(this.sendUsbRequest(UsbConstants.USB_DIR_OUT, HACKRF_VENDOR_REQUEST_ANTENNA_ENABLE, 
            (enable ? 1 : 0) , 0, null) != 0)
    {
        Log.e(logTag, "setAntennaPower: USB Transfer failed!");
        throw(new HackrfUsbException("USB Transfer failed!"));
    }

    return true;
}
项目:hackrf_android    文件:Hackrf.java   
/**
 * Sets the Transceiver Mode of the HackRF (OFF,RX,TX)
 * 
 * Note: This function interacts with the USB Hardware and
 * should not be called from a GUI Thread!
 * 
 * @param   mode        HACKRF_TRANSCEIVER_MODE_OFF, *_RECEIVE or *_TRANSMIT
 * @return  true on success
 * @throws  HackrfUsbException
 */
public boolean setTransceiverMode(int mode) throws HackrfUsbException
{
    if (mode < 0 || mode > 2)
    {
        Log.e(logTag,"Invalid Transceiver Mode: " + mode);
        return false;
    }

    this.transceiverMode = mode;

    if(this.sendUsbRequest(UsbConstants.USB_DIR_OUT, HACKRF_VENDOR_REQUEST_SET_TRANSCEIVER_MODE, 
            mode , 0, null) != 0)
    {
        Log.e(logTag, "setTransceiverMode: USB Transfer failed!");
        throw(new HackrfUsbException("USB Transfer failed!"));
    }

    return true;
}
项目:android-weather-station    文件:ConnectedUsbDevice.java   
public ConnectedUsbDevice(UsbDeviceConnection connection, UsbInterface usbInterface) {
    this.connection = connection;
    this.usbInterface = usbInterface;
    initConnection(connection);
    int endPoints = usbInterface.getEndpointCount();
    int interfaceProtocol = usbInterface.getInterfaceProtocol();
    System.out.println("EndPoints: " + endPoints + " | interfaces: " + interfaceProtocol);
    out = usbInterface.getEndpoint(1);
    in = usbInterface.getEndpoint(2);
    for (int x = 0; x < endPoints; x++) {
        UsbEndpoint endpoint = usbInterface.getEndpoint(x);
        boolean bulk = endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK;
        boolean crtl = endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_CONTROL;
        boolean inDir = endpoint.getDirection() == UsbConstants.USB_DIR_IN;
        boolean outDir = endpoint.getDirection() == UsbConstants.USB_DIR_OUT;
        System.out.println("ID: " + x + " Bulk: " + bulk + " Ctrl: " + crtl + " Out: " + outDir + " In: " + inDir);
    }
}
项目:RHome    文件:FTDriver.java   
private boolean getCdcEndpoint() {
    UsbEndpoint ep;

    if (mInterface[0] == null) {
        return false;
    }
    for (int i = 0; i < 2; ++i) {
        ep = mInterface[0].getEndpoint(i);
        if (ep.getDirection() == UsbConstants.USB_DIR_IN) {
            mFTDIEndpointIN[0] = ep;
        } else {
            mFTDIEndpointOUT[0] = ep;
        }
    }
    if (mFTDIEndpointIN == null || mFTDIEndpointOUT == null) {
        return false;
    }
    return true;

}
项目:chromium_webview    文件:UsbMidiDeviceAndroid.java   
/**
 * Constructs a UsbMidiDeviceAndroid.
 * @param manager
 * @param device The USB device which this object is assocated with.
 */
UsbMidiDeviceAndroid(UsbManager manager, UsbDevice device) {
    mConnection = manager.openDevice(device);
    mEndpointMap = new HashMap<Integer, UsbEndpoint>();
    mRequestMap = new HashMap<UsbEndpoint, UsbRequest>();

    for (int i = 0; i < device.getInterfaceCount(); ++i) {
        UsbInterface iface = device.getInterface(i);
        if (iface.getInterfaceClass() != UsbConstants.USB_CLASS_AUDIO ||
            iface.getInterfaceSubclass() != MIDI_SUBCLASS) {
            continue;
        }
        mConnection.claimInterface(iface, true);
        for (int j = 0; j < iface.getEndpointCount(); ++j) {
            UsbEndpoint endpoint = iface.getEndpoint(j);
            if (endpoint.getDirection() == UsbConstants.USB_DIR_OUT) {
                mEndpointMap.put(endpoint.getEndpointNumber(), endpoint);
            }
        }
    }
}
项目:RtkGps    文件:UsbAcmController.java   
private boolean acmGetLineCoding(SerialLineConfiguration dst) {
    final byte response[];

    response = new byte[7];
    if (mUsbConnection.controlTransfer(
            0x21 | UsbConstants.USB_DIR_IN,
            UsbAcmController.PSTN_GET_LINE_CODING,
            0,
            0, /* bulk data interface number */
            response,
            response.length,
            1000
            ) < 7)
        return false;

    try {
        dst.set(UsbAcmController.unpackLineCodingResponse(response));
    }catch (IllegalArgumentException iae) {
        iae.printStackTrace();
        return false;
    }

    return true;
}
项目:RtkGps    文件:UsbPl2303Controller.java   
private boolean pl2303SetLineCoding() {
    final byte req[];

    Log.d(TAG, "SetLineCoding " + mSerialLineConfiguration.toString());

    req = UsbAcmController.packSetLineCodingRequest(mSerialLineConfiguration);

    if (mUsbConnection.controlTransfer(
            0x21 | UsbConstants.USB_DIR_OUT,
            UsbAcmController.PSTN_SET_LINE_CODING,
            0,
            0, /* bulk data interface number */
            req,
            req.length,
            1000
            ) < 0)
        return false;

    /* CRTSCTS=off */
    if (mUsbConnection.controlTransfer(
            UsbConstants.USB_DIR_OUT | UsbConstants.USB_TYPE_VENDOR,
            0x01, 0, 0, null, 0, 1000) < 0)
        return false;

    return true;
}
项目:RtkGps    文件:UsbPl2303Controller.java   
private boolean pl2303GetLineCoding(SerialLineConfiguration dst) {
    final byte response[];

    response = new byte[7];
    if (mUsbConnection.controlTransfer(
            0x21 | UsbConstants.USB_DIR_IN,
            UsbAcmController.PSTN_GET_LINE_CODING,
            0,
            0, /* bulk data interface number */
            response,
            response.length,
            1000
            ) < 7)
        return false;

    try {
        dst.set(UsbAcmController.unpackLineCodingResponse(response));
    }catch (IllegalArgumentException iae) {
        iae.printStackTrace();
        return false;
    }

    return true;
}
项目:easyfilemanager    文件:UsbUtils.java   
private static String nameForClass(UsbDevice usbDevice) {
    int classType = usbDevice.getDeviceClass();
    switch (classType) {
        case UsbConstants.USB_CLASS_AUDIO:
            return "Audio";
        case UsbConstants.USB_CLASS_CDC_DATA:
            return "CDC Control";
        case UsbConstants.USB_CLASS_COMM:
            return "Communications";
        case UsbConstants.USB_CLASS_CONTENT_SEC:
            return "Content Security";
        case UsbConstants.USB_CLASS_CSCID:
            return "Content Smart Card";
        case UsbConstants.USB_CLASS_HID:
            return "Human Interface Device";
        case UsbConstants.USB_CLASS_HUB:
            return "Hub";
        case UsbConstants.USB_CLASS_MASS_STORAGE:
            return "Mass Storage";
        case UsbConstants.USB_CLASS_MISC:
            return "Wireless Miscellaneous";
        case UsbConstants.USB_CLASS_PHYSICA:
            return "Physical";
        case UsbConstants.USB_CLASS_PRINTER:
            return "Printer";
        case UsbConstants.USB_CLASS_STILL_IMAGE:
            return "Still Image";
        case UsbConstants.USB_CLASS_VENDOR_SPEC:
            return String.format("Vendor Specific 0x%02x", classType);
        case UsbConstants.USB_CLASS_VIDEO:
            return "Video";
        case UsbConstants.USB_CLASS_WIRELESS_CONTROLLER:
            return "Wireless Controller";
        default:
            return "";
    }
}
项目:InstantUpload    文件:SonyInitiator.java   
/**
 * Constructs a class driver object, if the device supports
 * operations according to Annex D of the PTP specification.
 *
 * @param dev        the first PTP interface will be used
 * @param connection
 * @throws IllegalArgumentException if the device has no
 *                                  Digital Still Imaging Class or PTP interfaces
 */
public SonyInitiator(UsbDevice dev, UsbDeviceConnection connection) throws PTPException {

    super();

    this.mConnection = connection;
    if (dev == null) {
        throw new PTPException ("dev = null");//IllegalArgumentException();
    }
    session = new Session();
    this.device = dev;
    intf = findUsbInterface (dev);

    if (intf == null) {
        //if (usbInterface == null) {
        throw new PTPException("No PTP interfaces associated to the device");
    }

    for (int i = 0; i < intf.getEndpointCount(); i++) {
        UsbEndpoint ep = intf.getEndpoint(i);
        if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
            if (ep.getDirection() == UsbConstants.USB_DIR_OUT) {
                epOut = ep;
            } else {
                epIn = ep;
            }
        }
        if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT){
            epEv = ep;
        }
    }
    endpointSanityCheck();
    inMaxPS = epOut.getMaxPacketSize();
    intrMaxPS = epIn.getMaxPacketSize();

    // clear epOut any previous state
    reset();
}
项目:InstantUpload    文件:BaselineInitiator.java   
protected int getDeviceStatus(Buffer buf)
    throws PTPException {
//        try {
        if (mConnection == null) throw new PTPException("No Connection");

            byte[] data = new byte[33];

            mConnection.controlTransfer(
//            device.controlMsg(
                (int) (UsbConstants.USB_DIR_IN        |
                        UsbConstants.USB_TYPE_CLASS    /*     |
                        UsbConstants.RECIPIENT_INTERFACE*/),
                CLASS_GET_DEVICE_STATUS,
                0,
                0,
                data,
                data.length, // force short reads
                DEFAULT_TIMEOUT //,
                //false
            );

            if (buf == null) {
                buf = new Buffer(data);
            } else {
                buf.data = data;
            }
            buf.offset = 4;
            buf.length = buf.getU16(0);
            if (buf.length != buf.data.length) {
                //throw new PTPException("DeviceStatus error, Buffer length wrong!");
            }

            return buf.getU16(2);
//        }  catch (USBException e) {
//            throw new PTPException(
//                "Error initializing the communication with the camera (" +
//                e.getMessage()
//                + ")" , e);
//        }
    }
项目:sample-usbenum    文件:UsbHelper.java   
public static String nameForClass(int classType) {
    switch (classType) {
        case UsbConstants.USB_CLASS_APP_SPEC:
            return String.format("Application Specific 0x%02x", classType);
        case UsbConstants.USB_CLASS_AUDIO:
            return "Audio";
        case UsbConstants.USB_CLASS_CDC_DATA:
            return "CDC Control";
        case UsbConstants.USB_CLASS_COMM:
            return "Communications";
        case UsbConstants.USB_CLASS_CONTENT_SEC:
            return "Content Security";
        case UsbConstants.USB_CLASS_CSCID:
            return "Content Smart Card";
        case UsbConstants.USB_CLASS_HID:
            return "Human Interface Device";
        case UsbConstants.USB_CLASS_HUB:
            return "Hub";
        case UsbConstants.USB_CLASS_MASS_STORAGE:
            return "Mass Storage";
        case UsbConstants.USB_CLASS_MISC:
            return "Wireless Miscellaneous";
        case UsbConstants.USB_CLASS_PER_INTERFACE:
            return "(Defined Per Interface)";
        case UsbConstants.USB_CLASS_PHYSICA:
            return "Physical";
        case UsbConstants.USB_CLASS_PRINTER:
            return "Printer";
        case UsbConstants.USB_CLASS_STILL_IMAGE:
            return "Still Image";
        case UsbConstants.USB_CLASS_VENDOR_SPEC:
            return String.format("Vendor Specific 0x%02x", classType);
        case UsbConstants.USB_CLASS_VIDEO:
            return "Video";
        case UsbConstants.USB_CLASS_WIRELESS_CONTROLLER:
            return "Wireless Controller";
        default:
            return String.format("0x%02x", classType);
    }
}
项目:sample-usbenum    文件:UsbHelper.java   
public static String nameForEndpointType(int type) {
    switch (type) {
        case UsbConstants.USB_ENDPOINT_XFER_BULK:
            return "Bulk";
        case UsbConstants.USB_ENDPOINT_XFER_CONTROL:
            return "Control";
        case UsbConstants.USB_ENDPOINT_XFER_INT:
            return "Interrupt";
        case UsbConstants.USB_ENDPOINT_XFER_ISOC:
            return "Isochronous";
        default:
            return "Unknown Type";
    }
}
项目:sample-usbenum    文件:UsbHelper.java   
public static String nameForDirection(int direction) {
    switch (direction) {
        case UsbConstants.USB_DIR_IN:
            return "IN";
        case UsbConstants.USB_DIR_OUT:
            return "OUT";
        default:
            return "Unknown Direction";
    }
}
项目:FireFiles    文件:UsbUtils.java   
private static String nameForClass(UsbDevice usbDevice) {
    int classType = usbDevice.getDeviceClass();
    switch (classType) {
        case UsbConstants.USB_CLASS_AUDIO:
            return "Audio";
        case UsbConstants.USB_CLASS_CDC_DATA:
            return "CDC Control";
        case UsbConstants.USB_CLASS_COMM:
            return "Communications";
        case UsbConstants.USB_CLASS_CONTENT_SEC:
            return "Content Security";
        case UsbConstants.USB_CLASS_CSCID:
            return "Content Smart Card";
        case UsbConstants.USB_CLASS_HID:
            return "Human Interface Device";
        case UsbConstants.USB_CLASS_HUB:
            return "Hub";
        case UsbConstants.USB_CLASS_MASS_STORAGE:
            return "Mass Storage";
        case UsbConstants.USB_CLASS_MISC:
            return "Wireless Miscellaneous";
        case UsbConstants.USB_CLASS_PHYSICA:
            return "Physical";
        case UsbConstants.USB_CLASS_PRINTER:
            return "Printer";
        case UsbConstants.USB_CLASS_STILL_IMAGE:
            return "Still Image";
        case UsbConstants.USB_CLASS_VENDOR_SPEC:
            return String.format("Vendor Specific 0x%02x", classType);
        case UsbConstants.USB_CLASS_VIDEO:
            return "Video";
        case UsbConstants.USB_CLASS_WIRELESS_CONTROLLER:
            return "Wireless Controller";
        default:
            return "";
    }
}
项目:can4eve    文件:CH34xSerialDevice.java   
private boolean openCH34X()
{
    if(connection.claimInterface(mInterface, true))
    {
        Log.i(CLASS_ID, "Interface succesfully claimed");
    }else
    {
        Log.i(CLASS_ID, "Interface could not be claimed");
        return false;
    }

    // Assign endpoints
    int numberEndpoints = mInterface.getEndpointCount();
    for(int i=0;i<=numberEndpoints-1;i++)
    {
        UsbEndpoint endpoint = mInterface.getEndpoint(i);
        if(endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK
                && endpoint.getDirection() == UsbConstants.USB_DIR_IN)
        {
            inEndpoint = endpoint;
        }else if(endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK
                && endpoint.getDirection() == UsbConstants.USB_DIR_OUT)
        {
            outEndpoint = endpoint;
        }
    }

    return init() == 0;
}
项目:can4eve    文件:UsbSerialDevice.java   
public static boolean isCdcDevice(UsbDevice device)
{
    int iIndex = device.getInterfaceCount();
    for(int i=0;i<=iIndex-1;i++)
    {
        UsbInterface iface = device.getInterface(i);
        if(iface.getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA)
            return true;
    }
    return false;
}
项目:can4eve    文件:UsbSerialDevice.java   
@Override
public void run()
{
    while(working.get())
    {
        UsbRequest request = connection.requestWait();
        if(request != null && request.getEndpoint().getType() == UsbConstants.USB_ENDPOINT_XFER_BULK
                && request.getEndpoint().getDirection() == UsbConstants.USB_DIR_IN)
        {
            byte[] data = serialBuffer.getDataReceived();

            // FTDI devices reserves two first bytes of an IN endpoint with info about
            // modem and Line.
            if(isFTDIDevice())
            {
                ((FTDISerialDevice) usbSerialDevice).ftdiUtilities.checkModemStatus(data); //Check the Modem status
                serialBuffer.clearReadBuffer();

                if(data.length > 2)
                {
                    data = ((FTDISerialDevice) usbSerialDevice).ftdiUtilities.adaptArray(data);
                    onReceivedData(data);
                }
            }else
            {
                // Clear buffer, execute the callback
                serialBuffer.clearReadBuffer();
                onReceivedData(data);
            }
            // Queue a new request
            requestIN.queue(serialBuffer.getReadBuffer(), serialBuffer.getReadBufferSize());
        }
    }
}
项目:can4eve    文件:CP2102SerialDevice.java   
private boolean openCP2102()
{
    if(connection.claimInterface(mInterface, true))
    {
        Log.i(CLASS_ID, "Interface succesfully claimed");
    }else
    {
        Log.i(CLASS_ID, "Interface could not be claimed");
        return false;
    }

    // Assign endpoints
    int numberEndpoints = mInterface.getEndpointCount();
    for(int i=0;i<=numberEndpoints-1;i++)
    {
        UsbEndpoint endpoint = mInterface.getEndpoint(i);
        if(endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK
                && endpoint.getDirection() == UsbConstants.USB_DIR_IN)
        {
            inEndpoint = endpoint;
        }else
        {
            outEndpoint = endpoint;
        }
    }


    // Default Setup
    if(setControlCommand(CP210x_IFC_ENABLE, CP210x_UART_ENABLE, null) < 0)
        return false;
    setBaudRate(DEFAULT_BAUDRATE);
    if(setControlCommand(CP210x_SET_LINE_CTL, CP210x_LINE_CTL_DEFAULT,null) < 0)
        return false;
    setFlowControl(UsbSerialInterface.FLOW_CONTROL_OFF);
    if(setControlCommand(CP210x_SET_MHS, CP210x_MHS_DEFAULT, null) < 0)
        return false;

    return true;
}
项目:can4eve    文件:CDCSerialDevice.java   
private boolean openCDC()
{
    if(connection.claimInterface(mInterface, true))
    {
        Log.i(CLASS_ID, "Interface succesfully claimed");
    }else
    {
        Log.i(CLASS_ID, "Interface could not be claimed");
        return false;
    }

    // Assign endpoints
    int numberEndpoints = mInterface.getEndpointCount();
    for(int i=0;i<=numberEndpoints-1;i++)
    {
        UsbEndpoint endpoint = mInterface.getEndpoint(i);
        if(endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK
                && endpoint.getDirection() == UsbConstants.USB_DIR_IN)
        {
            inEndpoint = endpoint;
        }else if(endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK
                && endpoint.getDirection() == UsbConstants.USB_DIR_OUT)
        {
            outEndpoint = endpoint;
        }
    }

    if(outEndpoint == null || inEndpoint == null)
    {
        Log.i(CLASS_ID, "Interface does not have an IN or OUT interface");
        return false;
    }

    // Default Setup
    setControlCommand(CDC_SET_LINE_CODING, 0, getInitialLineCoding());
    setControlCommand(CDC_SET_CONTROL_LINE_STATE, CDC_CONTROL_LINE_ON, null);

    return true;
}
项目:can4eve    文件:CDCSerialDevice.java   
private static int findFirstCDC(UsbDevice device)
{
    int interfaceCount = device.getInterfaceCount();

    for (int iIndex = 0; iIndex < interfaceCount; ++iIndex)
    {
        if (device.getInterface(iIndex).getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA)
        {
            return iIndex;
        }
    }

    Log.i(CLASS_ID, "There is no CDC class interface");
    return -1;
}
项目:can4eve    文件:CP2130SpiDevice.java   
private boolean openCP2130()
{
    if(connection.claimInterface(mInterface, true))
    {
        Log.i(CLASS_ID, "Interface succesfully claimed");
    }else
    {
        Log.i(CLASS_ID, "Interface could not be claimed");
        return false;
    }

    // Assign endpoints
    int numberEndpoints = mInterface.getEndpointCount();
    for(int i=0;i<=numberEndpoints-1;i++)
    {
        UsbEndpoint endpoint = mInterface.getEndpoint(i);
        if(endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK
                && endpoint.getDirection() == UsbConstants.USB_DIR_IN)
        {
            inEndpoint = endpoint;
        }else
        {
            outEndpoint = endpoint;
        }
    }

    return true;
}
项目:simple-share-android    文件:UsbUtils.java   
private static String nameForClass(UsbDevice usbDevice) {
    int classType = usbDevice.getDeviceClass();
    switch (classType) {
        case UsbConstants.USB_CLASS_AUDIO:
            return "Audio";
        case UsbConstants.USB_CLASS_CDC_DATA:
            return "CDC Control";
        case UsbConstants.USB_CLASS_COMM:
            return "Communications";
        case UsbConstants.USB_CLASS_CONTENT_SEC:
            return "Content Security";
        case UsbConstants.USB_CLASS_CSCID:
            return "Content Smart Card";
        case UsbConstants.USB_CLASS_HID:
            return "Human Interface Device";
        case UsbConstants.USB_CLASS_HUB:
            return "Hub";
        case UsbConstants.USB_CLASS_MASS_STORAGE:
            return "Mass Storage";
        case UsbConstants.USB_CLASS_MISC:
            return "Wireless Miscellaneous";
        case UsbConstants.USB_CLASS_PHYSICA:
            return "Physical";
        case UsbConstants.USB_CLASS_PRINTER:
            return "Printer";
        case UsbConstants.USB_CLASS_STILL_IMAGE:
            return "Still Image";
        case UsbConstants.USB_CLASS_VENDOR_SPEC:
            return String.format("Vendor Specific 0x%02x", classType);
        case UsbConstants.USB_CLASS_VIDEO:
            return "Video";
        case UsbConstants.USB_CLASS_WIRELESS_CONTROLLER:
            return "Wireless Controller";
        default:
            return "";
    }
}