some chinese comments removed

This commit is contained in:
dxl
2020-07-21 11:44:41 +08:00
parent 6b437998bb
commit 777c802806
@@ -28,37 +28,23 @@ public abstract class AbsUsbBulkTransfer implements DriverInterface<String, UsbM
// Application context, is global. cant cache activity context!
private Context mContext = ContextContentProvider.mContext;
//日志特征
private static final String LOG_TAG = AbsUsbBulkTransfer.class.getSimpleName();
private DevCallback<String> mCallback = null;
//广播接收器,在设备插入和移除时使用
private BroadcastReceiver mReceiver;
//主页状态!
private boolean isRegister = false;
//广播过滤器!
private IntentFilter filter = new IntentFilter();
//缓存设备管理器
private UsbManager mUsbManger = null;
//缓存插入的设备
private UsbDevice mDevice = null;
//缓存设备链接(实际上等同于串口port)
private UsbDeviceConnection mCon = null;
//USB接口
private UsbInterface mUi = null;
//USB读端点
private UsbEndpoint mEpIn = null;
//USB写端点
private UsbEndpoint mEpOut = null;
// 流实现!
private BulkOutputStream outputStream;
private BulkInputStream inputStream;
//私有构造方法,避免被直接调用
protected AbsUsbBulkTransfer() {
final String act = getDeviceDiscoveryAction();
final String name = getDeviceNameOnFound();
//建立意图过滤数组
filter.addAction(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);
filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
@@ -73,7 +59,6 @@ public abstract class AbsUsbBulkTransfer implements DriverInterface<String, UsbM
return;
}
switch (_action) {
//在设备插入的时候初始化
case UsbManager.ACTION_USB_DEVICE_ATTACHED:
initAndCall(name);
break;
@@ -97,10 +82,8 @@ public abstract class AbsUsbBulkTransfer implements DriverInterface<String, UsbM
private void register1() {
unRegister();
try {
//注册广播事件
mContext.registerReceiver(mReceiver, filter);
isRegister = true;
Log.d(LOG_TAG, "注册广播成功!");
} catch (Exception ignored) {
}
}
@@ -108,7 +91,6 @@ public abstract class AbsUsbBulkTransfer implements DriverInterface<String, UsbM
private void unRegister() {
try {
if (isRegister) {
//注册广播事件
mContext.unregisterReceiver(mReceiver);
isRegister = false;
}
@@ -132,31 +114,22 @@ public abstract class AbsUsbBulkTransfer implements DriverInterface<String, UsbM
Log.d(LOG_TAG, "USB管理器为空!");
return false;
}
//得到设备集
HashMap<String, UsbDevice> _hmDevs = mUsbManger.getDeviceList();
if (_hmDevs == null || _hmDevs.size() <= 0) return false;
List<UsbDevice> _devs = new ArrayList<>(_hmDevs.values());
//判断插入的设备集是否存在设备
if (_devs.size() <= 0) return false;
//判断是否是ACR122
mDevice = _devs.get(0);
if (mDevice == null) return false;
//判断设备厂商和设备型号
if (isRawDevice(mDevice.getProductId(), mDevice.getVendorId())) {
if (!mUsbManger.hasPermission(mDevice)) {
//如果没有权限,则需要申请!
mCon = mUsbManger.openDevice(mDevice);
//空链接,可能需要申请权限!
if (mCon == null) {
//发送广播申请权限
PendingIntent intent = PendingIntent.getBroadcast(mContext, 0, new Intent(getDeviceDiscoveryAction()), 0);
Log.d(LOG_TAG, "trying get usb permission!");
mUsbManger.requestPermission(mDevice, intent);
//当没有权限的时候应当直接返回
return false;
}
} else {
//如果有权限,可以直接打开!
mCon = mUsbManger.openDevice(mDevice);
}
} else {
@@ -169,7 +142,6 @@ public abstract class AbsUsbBulkTransfer implements DriverInterface<String, UsbM
@Override
public void register(final DevCallback<String> callback) {
mCallback = callback;
//初始化USB管理器资源
mUsbManger = (UsbManager) mContext.getSystemService(Context.USB_SERVICE);
// register driver
register1();
@@ -181,7 +153,6 @@ public abstract class AbsUsbBulkTransfer implements DriverInterface<String, UsbM
Log.e(LOG_TAG, "devices is null!");
return false;
}
//再一次判断设备正确性
if (isRawDevice(mDevice.getProductId(), mDevice.getVendorId())) {
for (int iIndex = 0; iIndex < mDevice.getInterfaceCount(); ++iIndex) {
UsbInterface tmpUi = mDevice.getInterface(iIndex);
@@ -200,11 +171,9 @@ public abstract class AbsUsbBulkTransfer implements DriverInterface<String, UsbM
return false;
}
}
//端点初始化
Log.d(LOG_TAG, "connect: Endpoint count: " + mUi.getEndpointCount());
for (int i = 0; i < mUi.getEndpointCount(); ++i) {
UsbEndpoint _ue = mUi.getEndpoint(i);
//判断端点的类型
if (_ue.getType() == UsbConstants.USB_ENDPOINT_XFER_INT) {
Log.d(LOG_TAG, "connect: Found interrupt endpoint: " + i);
continue;
@@ -224,7 +193,6 @@ public abstract class AbsUsbBulkTransfer implements DriverInterface<String, UsbM
Log.d(LOG_TAG, "Invalid endpoint!");
return false;
}
//全部链接初始化成功,返回TRUE告诉调用者可以开始尝试通信
inputStream = new BulkInputStream(mCon, mEpIn);
outputStream = new BulkOutputStream(mCon, mEpOut);
return true;