Merge branch 'release_hyx' into release

This commit is contained in:
anfe 2024-05-20 18:18:42 +08:00
commit 8fe14976cd
3 changed files with 21 additions and 105 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -179,18 +179,27 @@ class BlueManage {
///
Future<void> startScanSingle(String deviceName, int timeout,
ScanDevicesCallBack scanDevicesCallBack) async {
final DateTime start = DateTime.now();
FlutterBluePlus.isSupported.then((bool isAvailable) async {
if (isAvailable) {
if (_adapterState == BluetoothAdapterState.on) {
try {
FlutterBluePlus.startScan(timeout: Duration(seconds: timeout));
//android 8
final int divisor = Platform.isAndroid ? 8 : 1;
FlutterBluePlus.startScan(
continuousDivisor: divisor,
continuousUpdates: true,
timeout: Duration(seconds: timeout));
final Completer<dynamic> completer = Completer<dynamic>();
final StreamSubscription<List<ScanResult>> subscription =
FlutterBluePlus.scanResults.listen((List<ScanResult> results) {
final bool isExit = results.any((ScanResult element) =>
(element.device.platformName == deviceName) ||
(element.advertisementData.advName == deviceName));
AppLog.log('扫描到的设备数:${results.length} 是否查找到 $isExit');
final int milliseconds = DateTime.now().millisecondsSinceEpoch -
start.millisecondsSinceEpoch;
AppLog.log(
'扫描到的设备数:${results.length} 是否查找到 $isExit 以查找$milliseconds毫秒');
if (isExit) {
for (final ScanResult scanResult in results) {
if (((scanResult.advertisementData.serviceUuids.isNotEmpty
@ -214,6 +223,7 @@ class BlueManage {
}
}
}
completer.complete();
}
}, onError: (e) {
@ -332,7 +342,8 @@ class BlueManage {
{bool isAddEquipment = false}) async {
FlutterBluePlus.isSupported.then((bool isAvailable) async {
if (isAvailable) {
AppLog.log('蓝牙状态 系统蓝牙状态:$_adapterState 蓝牙连接状态:$bluetoothConnectionState');
AppLog.log(
'蓝牙状态 系统蓝牙状态:$_adapterState 蓝牙连接状态:$bluetoothConnectionState');
if (_adapterState == BluetoothAdapterState.on) {
//
if (bluetoothConnectionState != BluetoothConnectionState.connected) {
@ -367,7 +378,7 @@ class BlueManage {
element.device.platformName == connectDeviceName ||
element.advertisementData.advName == connectDeviceName);
if (isAddEquipment == false || isExistDevice == false) {
if (isAddEquipment == false && isExistDevice == false) {
//使
startScanSingle(deviceName, 10, (List<ScanResult> scanDevices) {
_connectDevice(scanDevices, deviceName, connectStateCallBack,
@ -421,7 +432,7 @@ class BlueManage {
}
//
final int maxAttempts = 3;
const int maxAttempts = 3;
int attempt = 0;
while (attempt < maxAttempts) {
try {
@ -487,7 +498,8 @@ class BlueManage {
List<int> lastTimeData = <int>[];
int? dataLen;
_subScribeToCharacteristic(BluetoothCharacteristic characteristic) async {
Future<void> _subScribeToCharacteristic(
BluetoothCharacteristic characteristic) async {
final StreamSubscription<List<int>> subscription =
characteristic.onValueReceived.listen((List<int> data) {
// AppLog.log("订阅获取的数据:$data");
@ -530,56 +542,8 @@ class BlueManage {
}
}
});
// cleanup: cancel subscription when disconnected
bluetoothConnectDevice!.cancelWhenDisconnected(subscription);
// enable notifications
await characteristic.setNotifyValue(true);
// characteristic.setNotifyValue(true).then((_) {
// AppLog.log("启动对特性的通知。当特性的值发生变化时,设备会发送一个通知");
// characteristic.lastValueStream.listen((data) {
// AppLog.log("订阅获取的数据:$data");
// // do something with new value
// if(data == lastTimeData || data.isEmpty){
// return;
// }else{
// lastTimeData = data;
// }
// // code to handle incoming data
// // AppLog.log("subscribeToCharacteristic: deviceId = ${characteristic.deviceId} characteristicId =${characteristic.characteristicId}---上报来的数据data = $data");
// if ((data[0] == 0xEF) && (data[1] == 0x01) && (data[2] == 0xEE) && (data[3] == 0x02)) {
// //
// //
// dataLen = data[8] * 256 + data[9]; // 16
// // AppLog.log("dataLen1111:$dataLen getDataLength:${data.length}");
// if (dataLen! + 12 > data.length) {
// //
// allData.addAll(data);
// } else {
// //
// allData.addAll(data);
// // AppLog.log("dataLen2222:$dataLen getDataLength:${data.length}");
// CommandReciverManager.appDataReceive(allData);
// //
// allData = <int>[];
// }
// } else {
// //
// allData.addAll(data);
// // var len = allData[8] * 256 + allData[9];
// // AppLog.log("dataLen3333:$dataLen");
// if ((dataLen! + 14) <= allData.length) {
// // AppLog.log("44444数据被解析了");
// //
// CommandReciverManager.appDataReceive(allData);
// //
// allData = <int>[];
// }
// }
// });
// });
}
//
@ -662,56 +626,6 @@ class BlueManage {
// }
}
//
Future<void> writeNull() async {
final List<BluetoothService> services =
await bluetoothConnectDevice!.discoverServices();
for (final BluetoothService service in services) {
if (service.uuid == _serviceIdConnect) {
for (final BluetoothCharacteristic characteristic
in service.characteristics) {
if (characteristic.characteristicUuid == _characteristicIdWrite) {
try {
final List<int> valueList = <int>[1];
AppLog.log('APP写入 writeNull ');
await characteristic.write(valueList);
} on Exception catch (e, s) {
AppLog.log('APP写入失败 writeNull : $e $s');
rethrow;
}
}
}
}
}
}
//
// Future<List<int>> _readCharacteristic(QualifiedCharacteristic characteristic) async {
// try {
// final result =
// await _flutterReactiveBle!.readCharacteristic(characteristic);
// AppLog.log("readListresult$result");
// return result;
// } on Exception catch (e, s) {
// AppLog.log(
// 'Error occurred when reading ${characteristic.characteristicId} : $e',
// );
// rethrow;
// }
// }
// Future<void> writeCharacteristicWithoutResponse(
// QualifiedCharacteristic characteristic, List<int> value) async {
// try {
// await _flutterReactiveBle!
// .writeCharacteristicWithoutResponse(characteristic, value: value);
// } on Exception catch (e, s) {
// // ignore: avoid_print
// AppLog.log(s);
// rethrow;
// }
// }
//
Future<void> stopScan() async {
try {

View File

@ -50,8 +50,10 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# 1.0.40+2024051704打包给欧阳回归测试
# 1.0.41+2024051705打包给公司测试
# 1.0.42+2024051801打包给欧阳回归测试
# 1.0.43+2024052001打包给公司测试
# 1.0.44+2024052002打包给公司测试
version: 1.0.42+2024051801
version: 1.0.44+2024052002
environment:
sdk: '>=2.12.0 <3.0.0'