Commit eed126e2 authored by 18600395998's avatar 18600395998

添加 盘点,版本信息上报

parent 8d79fc34
......@@ -72,8 +72,12 @@ public class RfidPlugin implements FlutterPlugin, MethodChannel.MethodCallHandle
private List<Device> mList;
private Map<String, String> map;
private List<InventoryData> dataList;
private Device device;
private boolean isFirst = true;
// 事件派发对象
private EventChannel.EventSink _eventSink;
......@@ -96,6 +100,8 @@ public class RfidPlugin implements FlutterPlugin, MethodChannel.MethodCallHandle
connectManger = ConnectManger.from(getLinkage());
EasyBLE.getInstance().registerObserver(this);
mList = new ArrayList<>();
dataList = new ArrayList<>();
map = new HashMap<>();
_methodChannel = new MethodChannel(binding.getBinaryMessenger(), "flutter_rfid_plugin");
_methodChannel.setMethodCallHandler(this);
EventChannel channel = new EventChannel(binding.getBinaryMessenger(), "flutter_rfid_plugin/event");
......@@ -114,6 +120,13 @@ public class RfidPlugin implements FlutterPlugin, MethodChannel.MethodCallHandle
public void run() {
String rm70xxVersion = connectManger.getRm70xxVersion();
Log.e("lei", "getVersion: " + rm70xxVersion);
Map<String, String> rm70xx_version = new HashMap<>();
rm70xx_version.put("key", "get_version");
rm70xx_version.put("value_RM70XX_VERSION", ConnectManger.RM70XX_VERSION);
rm70xx_version.put("value_RM70XX_SERIAL_VERSION", ConnectManger.RM70XX_SERIAL_VERSION);
rm70xx_version.put("value_VERSION", ConnectManger.VERSION);
rm70xx_version.put("value_SERIAL_VERSION", ConnectManger.SERIAL_VERSION);
_eventSink.success(rm70xxVersion);
}
}).start();
}
......@@ -130,24 +143,27 @@ public class RfidPlugin implements FlutterPlugin, MethodChannel.MethodCallHandle
bleManagers.searchBleDevices(this);
} else if (call.method.equals("scan_stop")) {
bleManagers.cancelBLESearch();
}else if (call.method.equals("connect_device")) {
} else if (call.method.equals("connect_device")) {
//需要一个名字的参数
for (int i = 0; i < mList.size(); i++) {
if (mList.get(i).getName().equals(call.argument("name"))) {
device=mList.get(i);
device = mList.get(i);
bleManagers.connectBleDevice(device);
}
}
} else if (call.method.equals("disconnect_device")) {
bleManagers.disConnectBLE(device);
}else if (call.method.equals("start_inventory")) {
} else if (call.method.equals("start_inventory")) {
isFirst = false;
InventoryParams inventoryParams = new InventoryParams();
inventoryParams.address=0;
inventoryParams.inventoryArea=1;
inventoryParams.len=6;
inventoryParams.address = 0;
inventoryParams.inventoryArea = 1;
inventoryParams.len = 6;
getLinkage().Radio_SetInventoryParams(inventoryParams);
//TODO 无效果,加延时
getLinkage().startInventory(1, 0);
map.clear();
dataList.clear();
} else if (call.method.equals("stop_inventory")) {
getLinkage().stopInventory();
}
......@@ -171,14 +187,29 @@ public class RfidPlugin implements FlutterPlugin, MethodChannel.MethodCallHandle
@Override
public void getInventoryData(InventoryData inventoryData) {
if (inventoryData == null) return;
Map<String, String> result = new HashMap<>();
String epc = TextUtil.byteToHexString(inventoryData.getEPC_Data(), inventoryData.getEpcLength()).substring(1);
String tid = TextUtil.byteToHexString(inventoryData.getData(), inventoryData.getDataLength());
String tag = epc + tid;
if (!map.containsKey(tag)) {
map.put(tag, epc);
dataList.add(inventoryData);
}
if (!isFirst) {
getLinkage().stopInventory();
isFirst = true;
handler.post(new Runnable() {
@Override
public void run() {
result.put("key", "InventoryData");
result.put("value", epc + "," + tid);
result.put("value", TextUtil.byteToHexString(dataList.get(0).getEPC_Data(), dataList.get(0).getEpcLength()));
_eventSink.success(result);
}
});
}
}
@Override
public void onStartDiscovery() {
......@@ -217,13 +248,11 @@ public class RfidPlugin implements FlutterPlugin, MethodChannel.MethodCallHandle
//TODO
} else if (connectionState == ConnectionState.SERVICE_DISCOVERING) {
} else if (connectionState == ConnectionState.SERVICE_DISCOVERED) {
List<BluetoothGattService> services =
bleManagers.getConnection().getGatt().getServices();
List<BluetoothGattService> services = bleManagers.getConnection().getGatt().getServices();
for (BluetoothGattService service : services) {
if (!service.getUuid().toString().contains("0000180")) {
Configs.uuid_service = service.getUuid();
List<BluetoothGattCharacteristic> characteristics =
service.getCharacteristics();
List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics();
Log.e("uuid_service", Configs.uuid_service.toString());
for (BluetoothGattCharacteristic characteristic : characteristics) {
String characteristicType = getCharacteristicType(characteristic);
......@@ -244,8 +273,7 @@ public class RfidPlugin implements FlutterPlugin, MethodChannel.MethodCallHandle
}
//设置MTU
Connection connection = EasyBLE.getInstance().getConnection(device);
RequestBuilder<MtuChangeCallback> builder =
new RequestBuilderFactory().getChangeMtuBuilder(512);
RequestBuilder<MtuChangeCallback> builder = new RequestBuilderFactory().getChangeMtuBuilder(512);
Request request = builder.setCallback(new MtuChangeCallback() {
@Override
public void onMtuChanged(@NonNull Request request, int mtu) {
......@@ -265,14 +293,8 @@ public class RfidPlugin implements FlutterPlugin, MethodChannel.MethodCallHandle
private String getCharacteristicType(BluetoothGattCharacteristic characteristic) {
StringBuilder sb = new StringBuilder();
int[] properties = new int[]{BluetoothGattCharacteristic.PROPERTY_WRITE,
BluetoothGattCharacteristic.PROPERTY_INDICATE,
BluetoothGattCharacteristic.PROPERTY_NOTIFY,
BluetoothGattCharacteristic.PROPERTY_READ,
BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE,
BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE};
String[] propertyStrs = new String[]{"WRITE", "INDICATE", "NOTIFY", "READ",
"SIGNED_WRITE", "WRITE_NO_RESPONSE"};
int[] properties = new int[]{BluetoothGattCharacteristic.PROPERTY_WRITE, BluetoothGattCharacteristic.PROPERTY_INDICATE, BluetoothGattCharacteristic.PROPERTY_NOTIFY, BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE, BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE};
String[] propertyStrs = new String[]{"WRITE", "INDICATE", "NOTIFY", "READ", "SIGNED_WRITE", "WRITE_NO_RESPONSE"};
for (int i = 0; i < properties.length; i++) {
int property = properties[i];
if ((characteristic.getProperties() & property) != 0) {
......@@ -286,13 +308,9 @@ public class RfidPlugin implements FlutterPlugin, MethodChannel.MethodCallHandle
}
private void setNotification() {
boolean isEnabled =
bleManagers.getConnection().isNotificationOrIndicationEnabled(Configs.uuid_service,
Configs.uuid_notify);
boolean isEnabled = bleManagers.getConnection().isNotificationOrIndicationEnabled(Configs.uuid_service, Configs.uuid_notify);
RequestBuilder<NotificationChangeCallback> builder =
new RequestBuilderFactory().getSetNotificationBuilder(Configs.uuid_service,
Configs.uuid_notify, !isEnabled);
RequestBuilder<NotificationChangeCallback> builder = new RequestBuilderFactory().getSetNotificationBuilder(Configs.uuid_service, Configs.uuid_notify, !isEnabled);
builder.build().execute(bleManagers.getConnection());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment