本文整理汇总了Java中android.hardware.usb.UsbRequest.queue方法的典型用法代码示例。如果您正苦于以下问题:Java UsbRequest.queue方法的具体用法?Java UsbRequest.queue怎么用?Java UsbRequest.queue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.hardware.usb.UsbRequest
的用法示例。
在下文中一共展示了UsbRequest.queue方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import android.hardware.usb.UsbRequest; //导入方法依赖的package包/类
public boolean write(AdbDevice device) {
synchronized (device) {
UsbRequest request = device.getOutRequest();
request.setClientData(this);
if (request.queue(mMessageBuffer, 24)) {
int length = getDataLength();
if (length > 0) {
request = device.getOutRequest();
request.setClientData(this);
if (request.queue(mDataBuffer, length)) {
return true;
} else {
device.releaseOutRequest(request);
return false;
}
}
return true;
} else {
device.releaseOutRequest(request);
return false;
}
}
}
示例2: controlTransfer
import android.hardware.usb.UsbRequest; //导入方法依赖的package包/类
int controlTransfer(int requestType, int request, int value, int index,
byte[] transferBuffer, byte[] receiveBuffer, int timeout) {
UsbEndpoint ep = mDevice.getInterface(0).getEndpoint(0);
int result = -1;
if(ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT &&
ep.getDirection() == UsbConstants.USB_DIR_IN) {
ByteBuffer bb = ByteBuffer.wrap(receiveBuffer);
UsbRequest ur = new UsbRequest();
ur.initialize(mConnection, ep);
ur.queue(bb, receiveBuffer.length);
result = mConnection.controlTransfer(requestType, request, value, index,
transferBuffer, transferBuffer.length, timeout);
if(result >= 0) {
if (mConnection.requestWait() != ur) {
Log.e(TAG, "[controlTransfer] requestWait failed");
return -1;
}
} else {
Log.e(TAG, "[controlTransfer] Transfer failed");
}
} else {
result = mConnection.controlTransfer(requestType, request, value, index,
transferBuffer, transferBuffer.length, timeout);
receiveBuffer = transferBuffer.clone();
}
return result;
}
示例3: messageWrite
import android.hardware.usb.UsbRequest; //导入方法依赖的package包/类
private void messageWrite(Message msg) {
int msg_size = msg.getSerializedSize();
String msg_name = msg.getClass().getSimpleName();
int msg_id = MessageType.valueOf("MessageType_" + msg_name).getNumber();
Timber.i(TAG, String.format("messageWrite: Got message: %s (%d bytes)", msg_name, msg_size));
ByteBuffer data = ByteBuffer.allocate(msg_size + 1024); // 32768);
data.put((byte) '#');
data.put((byte) '#');
data.put((byte) ((msg_id >> 8) & 0xFF));
data.put((byte) (msg_id & 0xFF));
data.put((byte) ((msg_size >> 24) & 0xFF));
data.put((byte) ((msg_size >> 16) & 0xFF));
data.put((byte) ((msg_size >> 8) & 0xFF));
data.put((byte) (msg_size & 0xFF));
data.put(msg.toByteArray());
while (data.position() % 63 > 0) {
data.put((byte) 0);
}
UsbRequest request = new UsbRequest();
request.initialize(usbConnection, writeEndpoint);
int chunks = data.position() / 63;
Timber.i(TAG, String.format("messageWrite: Writing %d chunks", chunks));
data.rewind();
for (int i = 0; i < chunks; i++) {
byte[] buffer = new byte[64];
buffer[0] = (byte) '?';
data.get(buffer, 1, 63);
request.queue(ByteBuffer.wrap(buffer), 64);
usbConnection.requestWait();
}
}
示例4: read
import android.hardware.usb.UsbRequest; //导入方法依赖的package包/类
@Override
public int read(byte[] dest, int timeoutMillis) throws IOException {
if (mEnableAsyncReads) {
final UsbRequest request = new UsbRequest();
try {
request.initialize(mConnection, mReadEndpoint);
final ByteBuffer buf = ByteBuffer.wrap(dest);
if (!request.queue(buf, dest.length)) {
throw new IOException("Error queueing request.");
}
final UsbRequest response = mConnection.requestWait();
if (response == null) {
throw new IOException("Null response");
}
final int nread = buf.position();
if (nread > 0) {
//Log.d(TAG, HexDump.dumpHexString(dest, 0, Math.min(32, dest.length)));
return nread;
} else {
return 0;
}
} finally {
request.close();
}
}
final int numBytesRead;
synchronized (mReadBufferLock) {
int readAmt = Math.min(dest.length, mReadBuffer.length);
numBytesRead = mConnection.bulkTransfer(mReadEndpoint, mReadBuffer, readAmt,
timeoutMillis);
if (numBytesRead < 0) {
// This sucks: we get -1 on timeout, not 0 as preferred.
// We *should* use UsbRequest, except it has a bug/api oversight
// where there is no way to determine the number of bytes read
// in response :\ -- http://b.android.com/28023
if (timeoutMillis == Integer.MAX_VALUE) {
// Hack: Special case "~infinite timeout" as an error.
return -1;
}
return 0;
}
System.arraycopy(mReadBuffer, 0, dest, 0, numBytesRead);
}
return numBytesRead;
}
示例5: readCommand
import android.hardware.usb.UsbRequest; //导入方法依赖的package包/类
public boolean readCommand(UsbRequest request) {
request.setClientData(this);
return request.queue(mMessageBuffer, 24);
}
示例6: readData
import android.hardware.usb.UsbRequest; //导入方法依赖的package包/类
public boolean readData(UsbRequest request, int length) {
request.setClientData(this);
return request.queue(mDataBuffer, length);
}
示例7: read
import android.hardware.usb.UsbRequest; //导入方法依赖的package包/类
@Override
public int read(byte[] dest, int timeoutMillis) throws IOException {
if (mEnableAsyncReads) {
final UsbRequest request = new UsbRequest();
try {
request.initialize(mConnection, mReadEndpoint);
final ByteBuffer buf = ByteBuffer.wrap(dest);
if (!request.queue(buf, dest.length)) {
throw new IOException("Error queueing request.");
}
final UsbRequest response = mConnection.requestWait();
if (response == null) {
throw new IOException("Null response");
}
final int nread = buf.position();
if (nread > 0) {
//Log.d(TAG, HexDump.dumpHexString(dest, 0, Math.min(32, dest.length)));
return nread;
} else {
return 0;
}
} finally {
request.close();
}
}
final int numBytesRead;
synchronized (mReadBufferLock) {
int readAmt = Math.min(dest.length, mReadBuffer.length);
numBytesRead = mConnection.bulkTransfer(mReadEndpoint, mReadBuffer, readAmt,
timeoutMillis);
if (numBytesRead < 0) {
// This sucks: we get -1 on timeout, not 0 as preferred.
// We *should* use UsbRequest, except it has a bug/api oversight
// where there is no way to determine the number of bytes read
// in response :\ -- http://b.android.com/28023
if (timeoutMillis == Integer.MAX_VALUE) {
// Hack: Special case "~infinite timeout" as an error.
return -1;
}
return 0;
}
System.arraycopy(mReadBuffer, 0, dest, 0, numBytesRead);
}
return numBytesRead;
}
示例8: read
import android.hardware.usb.UsbRequest; //导入方法依赖的package包/类
@Override
public int read(byte[] dest, int timeoutMillis) throws IOException {
if (mEnableAsyncReads) {
final UsbRequest request = new UsbRequest();
try {
request.initialize(mConnection, mReadEndpoint);
final ByteBuffer buf = ByteBuffer.wrap(dest);
if (!request.queue(buf, dest.length)) {
throw new IOException("Error queueing request.");
}
final UsbRequest response = mConnection.requestWait();
if (response == null) {
throw new IOException("Null response");
}
final int nread = buf.position();
if (nread > 0) {
//Log.d(TAG, HexDump.dumpHexString(dest, 0, Math.min(32, dest.length)));
return nread;
} else {
return 0;
}
} finally {
request.close();
}
}
final int numBytesRead;
synchronized (mReadBufferLock) {
int readAmt = Math.min(dest.length, mReadBuffer.length);
numBytesRead = mConnection.bulkTransfer(mReadEndpoint, mReadBuffer, readAmt, timeoutMillis);
if (numBytesRead < 0) {
// This sucks: we get -1 on timeout, not 0 as preferred.
// We *should* use UsbRequest, except it has a bug/api oversight
// where there is no way to determine the number of bytes read
// in response :\ -- http://b.android.com/28023
if (timeoutMillis == Integer.MAX_VALUE) {
// Hack: Special case "~infinite timeout" as an error.
return -1;
}
return 0;
}
System.arraycopy(mReadBuffer, 0, dest, 0, numBytesRead);
}
return numBytesRead;
}
示例9: read
import android.hardware.usb.UsbRequest; //导入方法依赖的package包/类
public int read(byte[] dest, int timeoutMillis, UsbDeviceConnection connection) throws IOException {
if (false) {
final UsbRequest request = new UsbRequest();
try {
request.initialize(connection, null);
final ByteBuffer buf = ByteBuffer.wrap(dest);
if (!request.queue(buf, dest.length)) {
throw new IOException("Error queueing request.");
}
final UsbRequest response = connection.requestWait();
if (response == null) {
throw new IOException("Null response");
}
final int nread = buf.position();
if (nread > 0) {
//Log.d(TAG, HexDump.dumpHexString(dest, 0, Math.min(32, dest.length)));
return nread;
} else {
return 0;
}
} finally {
request.close();
}
}
final int numBytesRead;
synchronized (mReadBufferLock) {
int readAmt = Math.min(dest.length, mReadBuffer.length);
numBytesRead = connection.bulkTransfer(null, mReadBuffer, readAmt,
timeoutMillis);
if (numBytesRead < 0) {
// This sucks: we get -1 on timeout, not 0 as preferred.
// We *should* use UsbRequest, except it has a bug/api oversight
// where there is no way to determine the number of bytes read
// in response :\ -- http://b.android.com/28023
if (timeoutMillis == Integer.MAX_VALUE) {
// Hack: Special case "~infinite timeout" as an error.
return -1;
}
return 0;
}
System.arraycopy(mReadBuffer, 0, dest, 0, numBytesRead);
}
return numBytesRead;
}
示例10: read
import android.hardware.usb.UsbRequest; //导入方法依赖的package包/类
@Override
public int read(byte[] dest, int timeoutMillis, UsbDeviceConnection connection) throws IOException {
if (false) {
final UsbRequest request = new UsbRequest();
try {
request.initialize(connection, mReadEndpoint);
final ByteBuffer buf = ByteBuffer.wrap(dest);
if (!request.queue(buf, dest.length)) {
throw new IOException("Error queueing request.");
}
final UsbRequest response = connection.requestWait();
if (response == null) {
throw new IOException("Null response");
}
final int nread = buf.position();
if (nread > 0) {
//Log.d(TAG, HexDump.dumpHexString(dest, 0, Math.min(32, dest.length)));
return nread;
} else {
return 0;
}
} finally {
request.close();
}
}
final int numBytesRead;
synchronized (mReadBufferLock) {
int readAmt = Math.min(dest.length, mReadBuffer.length);
numBytesRead = connection.bulkTransfer(mReadEndpoint, mReadBuffer, readAmt,
timeoutMillis);
if (numBytesRead < 0) {
// This sucks: we get -1 on timeout, not 0 as preferred.
// We *should* use UsbRequest, except it has a bug/api oversight
// where there is no way to determine the number of bytes read
// in response :\ -- http://b.android.com/28023
if (timeoutMillis == Integer.MAX_VALUE) {
// Hack: Special case "~infinite timeout" as an error.
return -1;
}
return 0;
}
System.arraycopy(mReadBuffer, 0, dest, 0, numBytesRead);
}
return numBytesRead;
}
示例11: read
import android.hardware.usb.UsbRequest; //导入方法依赖的package包/类
public int read(byte[] dest, int timeoutMillis, UsbDeviceConnection connection) throws IOException {
if (false) {
final UsbRequest request = new UsbRequest();
try {
request.initialize(connection, mReadEndpoint);
final ByteBuffer buf = ByteBuffer.wrap(dest);
if (!request.queue(buf, dest.length)) {
throw new IOException("Error queueing request.");
}
final UsbRequest response = connection.requestWait();
if (response == null) {
throw new IOException("Null response");
}
final int nread = buf.position();
if (nread > 0) {
//Log.d(TAG, HexDump.dumpHexString(dest, 0, Math.min(32, dest.length)));
return nread;
} else {
return 0;
}
} finally {
request.close();
}
}
final int numBytesRead;
synchronized (mReadBufferLock) {
int readAmt = Math.min(dest.length, mReadBuffer.length);
numBytesRead = connection.bulkTransfer(mReadEndpoint, mReadBuffer, readAmt,
timeoutMillis);
if (numBytesRead < 0) {
// This sucks: we get -1 on timeout, not 0 as preferred.
// We *should* use UsbRequest, except it has a bug/api oversight
// where there is no way to determine the number of bytes read
// in response :\ -- http://b.android.com/28023
if (timeoutMillis == Integer.MAX_VALUE) {
// Hack: Special case "~infinite timeout" as an error.
return -1;
}
return 0;
}
System.arraycopy(mReadBuffer, 0, dest, 0, numBytesRead);
}
return numBytesRead;
}
示例12: exchange
import android.hardware.usb.UsbRequest; //导入方法依赖的package包/类
public byte[] exchange(byte tag, byte[] command) throws IOException {
ByteArrayOutputStream response = new ByteArrayOutputStream();
byte[] responseData = null;
int offset = 0;
int responseSize;
if (debug) {
Log.d(LOG_TAG, "=> " + Dump.dump(command));
}
command = helper.wrapCommandAPDU(tag, command, HID_BUFFER_SIZE);
UsbRequest requestWrite = new UsbRequest();
if (!requestWrite.initialize(connection, out)) {
throw new IOException();
}
while (offset != command.length) {
int blockSize = (command.length - offset > HID_BUFFER_SIZE ? HID_BUFFER_SIZE : command.length - offset);
System.arraycopy(command, offset, transferBuffer, 0, blockSize);
if (debug) {
Log.d(LOG_TAG, "wire => " + Dump.dump(transferBuffer));
}
if (!requestWrite.queue(ByteBuffer.wrap(transferBuffer), HID_BUFFER_SIZE)) {
requestWrite.close();
throw new IOException();
}
connection.requestWait();
offset += blockSize;
}
ByteBuffer responseBuffer = ByteBuffer.allocate(HID_BUFFER_SIZE);
UsbRequest requestRead = new UsbRequest();
if (!requestRead.initialize(connection, in)) {
requestRead.close();
requestWrite.close();
throw new IOException();
}
while ((responseData = helper.unwrapResponseAPDU(tag, response.toByteArray(), HID_BUFFER_SIZE)) == null) {
responseBuffer.clear();
if (!requestRead.queue(responseBuffer, HID_BUFFER_SIZE)) {
requestRead.close();
requestWrite.close();
throw new IOException();
}
connection.requestWait();
responseBuffer.rewind();
responseBuffer.get(transferBuffer, 0, HID_BUFFER_SIZE);
if (debug) {
Log.d(LOG_TAG, "wire <= " + Dump.dump(transferBuffer));
}
response.write(transferBuffer, 0, HID_BUFFER_SIZE);
}
if (debug) {
Log.d(LOG_TAG, "<= " + Dump.dump(responseData));
}
requestWrite.close();
requestRead.close();
return responseData;
}