mirror of
https://github.com/RfidResearchGroup/RFIDtools.git
synced 2026-05-12 11:19:59 -07:00
Communication rebuild(worked).
This commit is contained in:
@@ -9,6 +9,7 @@ import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||
|
||||
import cn.dxl.com.LocalComBridgeAdapter;
|
||||
import cn.dxl.common.util.DisplayUtil;
|
||||
import cn.dxl.common.util.FragmentUtil;
|
||||
import cn.rrg.rdv.R;
|
||||
@@ -89,4 +90,10 @@ public class AppMain extends BaseActivity {
|
||||
// back event dispatch!
|
||||
appMainDevicesFragment.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
LocalComBridgeAdapter.getInstance().stop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,10 @@ import androidx.annotation.Nullable;
|
||||
import com.proxgrind.pm3flasher.Proxmark3Flasher;
|
||||
import com.proxgrind.pm3flasher.Target;
|
||||
|
||||
import cn.dxl.com.ComBridgeAdapter;
|
||||
import cn.dxl.com.LocalComBridgeAdapter;
|
||||
import cn.dxl.common.widget.ToastUtil;
|
||||
import cn.rrg.com.DevCallback;
|
||||
import cn.rrg.com.UsbSerialControl;
|
||||
import cn.rrg.devices.EmptyDeivce;
|
||||
import cn.rrg.rdv.R;
|
||||
import cn.rrg.rdv.util.Paths;
|
||||
|
||||
@@ -42,9 +41,12 @@ public class PM3FlasherMainActivity extends BaseActivity implements DevCallback<
|
||||
|
||||
// init and try to connect.
|
||||
control.register(this);
|
||||
ComBridgeAdapter.getInstance()
|
||||
|
||||
// start communication forward!
|
||||
LocalComBridgeAdapter.getInstance()
|
||||
.setInputStream(control.getInput())
|
||||
.setOutputStream(control.getOutput());
|
||||
.setOutputStream(control.getOutput())
|
||||
.start();
|
||||
|
||||
initViews();
|
||||
initActions();
|
||||
@@ -141,6 +143,8 @@ public class PM3FlasherMainActivity extends BaseActivity implements DevCallback<
|
||||
mDialogWorkingState.dismiss();
|
||||
control.unregister();
|
||||
closeClient();
|
||||
LocalComBridgeAdapter.getInstance()
|
||||
.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-2
@@ -1,10 +1,9 @@
|
||||
package cn.rrg.bulkio;
|
||||
package cn.dxl.bulkio;
|
||||
|
||||
import android.hardware.usb.UsbDeviceConnection;
|
||||
import android.hardware.usb.UsbEndpoint;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package cn.rrg.bulkio;
|
||||
package cn.dxl.bulkio;
|
||||
|
||||
import android.hardware.usb.UsbDeviceConnection;
|
||||
import android.hardware.usb.UsbEndpoint;
|
||||
@@ -15,14 +15,14 @@ public abstract class DeviceChecker implements Serializable, Closeable {
|
||||
|
||||
public DeviceChecker(Communication communication) {
|
||||
this.communication = communication;
|
||||
initCom();
|
||||
}
|
||||
|
||||
private void initCom(){
|
||||
private void initCom() {
|
||||
// Auto init communication to mapper.
|
||||
ComBridgeAdapter.getInstance()
|
||||
LocalComBridgeAdapter.getInstance()
|
||||
.setInputStream(communication.getInput())
|
||||
.setOutputStream(communication.getOutput());
|
||||
.setOutputStream(communication.getOutput())
|
||||
.start();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+63
-32
@@ -4,19 +4,18 @@ import android.net.LocalServerSocket;
|
||||
import android.net.LocalSocket;
|
||||
import android.util.Log;
|
||||
|
||||
import com.felhr.utils.HexData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author DXL
|
||||
* Created by DXL on 2017/8/21.
|
||||
* 通信控制映射类,直接实现进程间通信!
|
||||
*/
|
||||
public final class ComBridgeAdapter implements Serializable {
|
||||
public final class LocalComBridgeAdapter implements Serializable {
|
||||
/*
|
||||
* Warning!!!
|
||||
* If your implementation does not need to be mapped to the c/c++ (only Java exists), please do not use this tool class!
|
||||
@@ -32,7 +31,7 @@ public final class ComBridgeAdapter implements Serializable {
|
||||
// 本地套接字服务!
|
||||
private LocalServerSocket serverSocket;
|
||||
// 单例!
|
||||
private static ComBridgeAdapter instance;
|
||||
private static LocalComBridgeAdapter instance;
|
||||
// 输入流!
|
||||
private InputStream mInputStream;
|
||||
// 输出流!
|
||||
@@ -42,16 +41,8 @@ public final class ComBridgeAdapter implements Serializable {
|
||||
// 暂停转发!
|
||||
private boolean pause = false;
|
||||
|
||||
// No instantiation is required
|
||||
private ComBridgeAdapter() {
|
||||
synchronized (ComBridgeAdapter.class) {
|
||||
try {
|
||||
serverSocket = new LocalServerSocket(NAMESPACE);
|
||||
new WorkThread().start();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private LocalComBridgeAdapter() {
|
||||
// No instantiation is required
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,8 +61,8 @@ public final class ComBridgeAdapter implements Serializable {
|
||||
continue;
|
||||
}
|
||||
isHasClient = true;
|
||||
new DataThread(mOutputStream, socket.getInputStream()).start();
|
||||
new DataThread(socket.getOutputStream(), mInputStream).start();
|
||||
new DataThread(socket, mOutputStream, socket.getInputStream()).start();
|
||||
new DataThread(socket, socket.getOutputStream(), mInputStream).start();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
isHasClient = false;
|
||||
@@ -81,18 +72,16 @@ public final class ComBridgeAdapter implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() {
|
||||
isHasClient = false;
|
||||
}
|
||||
|
||||
class DataThread extends Thread {
|
||||
private LocalSocket socket;
|
||||
private OutputStream os;
|
||||
private InputStream is;
|
||||
private byte[] buffer = new byte[1024];
|
||||
|
||||
DataThread(OutputStream os, InputStream is) {
|
||||
DataThread(LocalSocket socket, OutputStream os, InputStream is) {
|
||||
this.os = os;
|
||||
this.is = is;
|
||||
this.socket = socket;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,26 +89,40 @@ public final class ComBridgeAdapter implements Serializable {
|
||||
while (isHasClient) {
|
||||
try {
|
||||
if (pause) {
|
||||
Log.e(LOG_TAG, "暂停中!");
|
||||
Log.e(LOG_TAG, "pausing!");
|
||||
continue;
|
||||
}
|
||||
if (os != null && is != null) {
|
||||
Log.d(LOG_TAG, "接收中");
|
||||
byte b = (byte) is.read();
|
||||
os.write(b);
|
||||
os.flush();
|
||||
Log.e(LOG_TAG, "数据: " + HexData.hexToString(new byte[]{b}));
|
||||
int len = is.read(buffer);
|
||||
if (len != -1) {
|
||||
os.write(Arrays.copyOf(buffer, len));
|
||||
os.flush();
|
||||
}
|
||||
} else {
|
||||
throw new IOException("IO closed.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
isHasClient = false;
|
||||
try {
|
||||
socket.shutdownInput();
|
||||
socket.shutdownOutput();
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
isHasClient = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static ComBridgeAdapter getInstance() {
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
stop();
|
||||
}
|
||||
|
||||
public static LocalComBridgeAdapter getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -127,7 +130,7 @@ public final class ComBridgeAdapter implements Serializable {
|
||||
return mInputStream;
|
||||
}
|
||||
|
||||
public ComBridgeAdapter setInputStream(InputStream mInputStream) {
|
||||
public LocalComBridgeAdapter setInputStream(InputStream mInputStream) {
|
||||
this.mInputStream = mInputStream;
|
||||
return this;
|
||||
}
|
||||
@@ -136,16 +139,44 @@ public final class ComBridgeAdapter implements Serializable {
|
||||
return mOutputStream;
|
||||
}
|
||||
|
||||
public ComBridgeAdapter setOutputStream(OutputStream mOutputStream) {
|
||||
public LocalComBridgeAdapter setOutputStream(OutputStream mOutputStream) {
|
||||
this.mOutputStream = mOutputStream;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
pause = true;
|
||||
Log.d(LOG_TAG, "ComBridgeAdapter pause!");
|
||||
}
|
||||
|
||||
public LocalComBridgeAdapter start() {
|
||||
synchronized (LocalComBridgeAdapter.class) {
|
||||
try {
|
||||
if (serverSocket != null) stop();
|
||||
serverSocket = new LocalServerSocket(NAMESPACE);
|
||||
new WorkThread().start();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(LOG_TAG, "If you see an error message like \"Address already in use\", check that you call the stop function");
|
||||
Log.e(LOG_TAG, "如果你看到了类似Address already in use的错误消息,请检查你是否调用停止函数");
|
||||
}
|
||||
}
|
||||
Log.d(LOG_TAG, "ComBridgeAdapter start!");
|
||||
return this;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
isHasClient = false;
|
||||
try {
|
||||
if (serverSocket != null)
|
||||
serverSocket.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Log.d(LOG_TAG, "ComBridgeAdapter stop!");
|
||||
}
|
||||
|
||||
static {
|
||||
instance = new ComBridgeAdapter();
|
||||
instance = new LocalComBridgeAdapter();
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -20,6 +21,12 @@ public class ContextContentProvider extends ContentProvider {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
super.shutdown();
|
||||
Log.d("LOG", "关闭内容提供者!");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) {
|
||||
|
||||
@@ -20,8 +20,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import cn.dxl.utils.ContextContentProvider;
|
||||
import cn.rrg.bulkio.BulkInputStream;
|
||||
import cn.rrg.bulkio.BulkOutputStream;
|
||||
import cn.dxl.bulkio.BulkInputStream;
|
||||
import cn.dxl.bulkio.BulkOutputStream;
|
||||
|
||||
public abstract class UsbBulkTransferRaw implements DriverInterface<String, UsbManager> {
|
||||
|
||||
|
||||
Submodule pm3rdv4rrg/src/main/cpp/proxmark3 updated: 8aab887436...0fe8a71a90
Reference in New Issue
Block a user