kidd3166 vor 1 Jahr
Ursprung
Commit
190c0255e7
20 geänderte Dateien mit 80 neuen und 10 gelöschten Zeilen
  1. 64 4
      lib/connector.dart
  2. BIN
      plugin/nordic_dfu-5.0.1/android/.gradle/5.6.2/fileChanges/last-build.bin
  3. BIN
      plugin/nordic_dfu-5.0.1/android/.gradle/5.6.2/fileHashes/fileHashes.lock
  4. 0 0
      plugin/nordic_dfu-5.0.1/android/.gradle/5.6.2/gc.properties
  5. BIN
      plugin/nordic_dfu-5.0.1/android/.gradle/6.7.1/fileHashes/fileHashes.lock
  6. BIN
      plugin/nordic_dfu-5.0.1/android/.gradle/6.7/executionHistory/executionHistory.lock
  7. BIN
      plugin/nordic_dfu-5.0.1/android/.gradle/6.7/fileChanges/last-build.bin
  8. BIN
      plugin/nordic_dfu-5.0.1/android/.gradle/6.7/fileHashes/fileHashes.bin
  9. BIN
      plugin/nordic_dfu-5.0.1/android/.gradle/6.7/fileHashes/fileHashes.lock
  10. 0 0
      plugin/nordic_dfu-5.0.1/android/.gradle/6.7/gc.properties
  11. BIN
      plugin/nordic_dfu-5.0.1/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock
  12. BIN
      plugin/nordic_dfu-5.0.1/android/.gradle/checksums/checksums.lock
  13. BIN
      plugin/nordic_dfu-5.0.1/android/.gradle/checksums/sha1-checksums.bin
  14. 1 1
      plugin/nordic_dfu-5.0.1/android/src/main/AndroidManifest.xml
  15. 0 1
      plugin/nordic_dfu-5.0.1/android/src/main/java/no/nordicsemi/android/dfu/BaseDfuImpl.java
  16. 1 1
      plugin/nordic_dfu-5.0.1/android/src/main/java/no/nordicsemi/android/dfu/DfuBaseService.java
  17. 5 0
      plugin/nordic_dfu-5.0.1/android/src/main/java/no/nordicsemi/android/dfu/LegacyDfuImpl.java
  18. 7 2
      plugin/nordic_dfu-5.0.1/android/src/main/java/no/nordicsemi/android/dfu/SecureDfuImpl.java
  19. 1 0
      plugin/nordic_dfu-5.0.1/android/src/main/kotlin/dev/steenbakker/nordicdfu/DfuService.kt
  20. 1 1
      pubspec.yaml

+ 64 - 4
lib/connector.dart

@@ -32,6 +32,7 @@ class _State extends State<Connector> with SubscriptionState {
 
   late TextEditingController _textEditingController;
   final ValueNotifier<Map> _infoNotifier = ValueNotifier({});
+  final ValueNotifier<Map> _electricityNotifier = ValueNotifier({});
 
   @override
   void initState() {
@@ -42,6 +43,15 @@ class _State extends State<Connector> with SubscriptionState {
 
   _connect() {
     cancel();
+    setState(() {
+      _writeData.clear();
+      _readData.clear();
+      _infoNotifier.value = {};
+      _electricityNotifier.value = {};
+      characteristicWrite = characteristicNotify = null;
+      _connectionStateUpdate = null;
+    });
+
     addSubscription(flutterReactiveBle
         .connectToDevice(
       id: widget.device.id,
@@ -78,7 +88,9 @@ class _State extends State<Connector> with SubscriptionState {
       if (characteristicNotify != null) {
         addSubscription(flutterReactiveBle.subscribeToCharacteristic(characteristicNotify!).listen((event) {
           _parse(event);
-        }));
+        })..onError((error){setState(() {
+          _connectError = error;
+        });}));
       }
       setState(() {});
     }).then((value) {
@@ -94,6 +106,7 @@ class _State extends State<Connector> with SubscriptionState {
   void _parse(List<int> event) {
     if (!mounted) return;
     if (event.isEmpty == true) return;
+    print("parse data $event");
     List<int> header = event.sublist(0, 4);
     List<int> content = event.sublist(4, event.length - 1);
     String headerStr = header.map((e) => e.toRadixString(16).padLeft(2, "0")).join(" ").toUpperCase();
@@ -155,6 +168,20 @@ class _State extends State<Connector> with SubscriptionState {
             _infoNotifier.value = info;
 
             break;
+          case 1:
+            Map<String, dynamic> info = {};
+            for (var i = 0; i < 2; i++) {
+              info['${i}_electricity'] = reader.readUint8();
+              info['${i}_temperature'] = reader.readUint8();
+              info['${i}_pressure'] = reader.readUint(4);
+              reader.readUint(4);
+            }
+            if (reader.remainingLength >= 4) {
+              info['0_adc'] = reader.readUint16();
+              info['1_adc'] = reader.readUint16();
+            }
+            _electricityNotifier.value = info;
+            break;
           default:
             break;
         }
@@ -214,6 +241,7 @@ class _State extends State<Connector> with SubscriptionState {
   Future _write(Uint8List data) async {
     if (!mounted) return;
     if (characteristicWrite == null) return;
+    if (_connectionStateUpdate?.connectionState != DeviceConnectionState.connected) return;
 
     int length = data.length + 4;
     ByteDataWriter writer = ByteDataWriter();
@@ -251,9 +279,10 @@ class _State extends State<Connector> with SubscriptionState {
           SliverToBoxAdapter(
             child: Column(
               children: [
-                Padding(
+                Container(
                   padding: const EdgeInsets.all(8.0),
-                  child: Text("连接状态: $_connectionStateUpdate"),
+                  child: Text("连接状态: $_connectionStateUpdate, $_connectError"),
+                  color: _connectionStateUpdate?.connectionState == DeviceConnectionState.connected ? Colors.green : Colors.grey,
                 ),
                 ValueListenableBuilder<Map>(
                   valueListenable: _infoNotifier,
@@ -403,14 +432,39 @@ class _State extends State<Connector> with SubscriptionState {
                             },
                             child: const Text("放电"),
                           ),
+                        if (characteristicWrite != null)
+                          ElevatedButton(
+                            onPressed: () async {
+                              _write(Uint8List.fromList([0xA1, 0x01]));
+                            },
+                            child: const Text("电量"),
+                          ),
+                        ElevatedButton(
+                          onPressed: () async {
+                            while (mounted) {
+                              cancel();
+                              await Future.delayed(const Duration(seconds: 3));
+                              _connect();
+                              await Future.delayed(const Duration(seconds: 5));
+                            }
+                          },
+                          child: const Text("测试10秒重新连接循化"),
+                        ),ElevatedButton(
+                          onPressed: () async {
+                            cancel();
+                            await Future.delayed(const Duration(seconds: 3));
+                            _connect();
+                          },
+                          child: const Text("重新连接"),
+                        ),
                       ],
                     ),
                   ),
                 if (characteristicWrite != null)
                   Container(
                     padding: const EdgeInsets.all(12.0),
-                    height: 100,
                     child: Column(
+                      mainAxisSize: MainAxisSize.min,
                       children: [
                         Row(
                           children: [
@@ -430,6 +484,12 @@ class _State extends State<Connector> with SubscriptionState {
                             ),
                           ],
                         ),
+                        ValueListenableBuilder(
+                          valueListenable: _electricityNotifier,
+                          builder: (BuildContext context, value, Widget? child) => Text(
+                            "电量: $value",
+                          ),
+                        ),
                       ],
                     ),
                   ),

BIN
plugin/nordic_dfu-5.0.1/android/.gradle/5.6.2/fileChanges/last-build.bin


BIN
plugin/nordic_dfu-5.0.1/android/.gradle/5.6.2/fileHashes/fileHashes.lock


+ 0 - 0
plugin/nordic_dfu-5.0.1/android/.gradle/5.6.2/gc.properties


BIN
plugin/nordic_dfu-5.0.1/android/.gradle/6.7.1/fileHashes/fileHashes.lock


BIN
plugin/nordic_dfu-5.0.1/android/.gradle/6.7/executionHistory/executionHistory.lock


BIN
plugin/nordic_dfu-5.0.1/android/.gradle/6.7/fileChanges/last-build.bin


BIN
plugin/nordic_dfu-5.0.1/android/.gradle/6.7/fileHashes/fileHashes.bin


BIN
plugin/nordic_dfu-5.0.1/android/.gradle/6.7/fileHashes/fileHashes.lock


+ 0 - 0
plugin/nordic_dfu-5.0.1/android/.gradle/6.7/gc.properties


BIN
plugin/nordic_dfu-5.0.1/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock


BIN
plugin/nordic_dfu-5.0.1/android/.gradle/checksums/checksums.lock


BIN
plugin/nordic_dfu-5.0.1/android/.gradle/checksums/sha1-checksums.bin


+ 1 - 1
plugin/nordic_dfu-5.0.1/android/src/main/AndroidManifest.xml

@@ -25,6 +25,6 @@
     <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
 
     <application>
-        <service android:name=".DfuService" />
+        <service android:name=".DfuService"  />
     </application>
 </manifest>

+ 0 - 1
plugin/nordic_dfu-5.0.1/android/src/main/java/no/nordicsemi/android/dfu/BaseDfuImpl.java

@@ -198,7 +198,6 @@ import no.nordicsemi.android.dfu.internal.scanner.BootloaderScannerFactory;
 				}
 			}
 			mRequestCompleted = true;
-			gatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
 			notifyLock();
 		}
 

+ 1 - 1
plugin/nordic_dfu-5.0.1/android/src/main/java/no/nordicsemi/android/dfu/DfuBaseService.java

@@ -1538,7 +1538,7 @@ public abstract class DfuBaseService extends IntentService implements DfuProgres
 			sendLogBroadcast(LOG_LEVEL_DEBUG, "gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, preferredPhy = LE_1M | LE_2M)");
 			gatt = device.connectGatt(this, false, mGattCallback,
 					BluetoothDevice.TRANSPORT_LE,
-					BluetoothDevice.PHY_LE_1M_MASK | BluetoothDevice.PHY_LE_2M_MASK);
+					BluetoothDevice.PHY_LE_1M_MASK);
 		} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
 			sendLogBroadcast(LOG_LEVEL_DEBUG, "gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE)");
 			gatt = device.connectGatt(this, false, mGattCallback,

+ 5 - 0
plugin/nordic_dfu-5.0.1/android/src/main/java/no/nordicsemi/android/dfu/LegacyDfuImpl.java

@@ -170,6 +170,11 @@ import no.nordicsemi.android.error.LegacyDfuError;
 		logw("Legacy DFU bootloader found");
 		mProgressInfo.setProgress(DfuBaseService.PROGRESS_STARTING);
 
+		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+			boolean request = mGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
+			logi("requestConnectionPriority result = " + request);
+		}
+
 		// Let's request the MTU requested by the user. It may be that a lower MTU will be used.
 		if (intent.hasExtra(DfuBaseService.EXTRA_MTU) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
 			final int requiredMtu = intent.getIntExtra(DfuBaseService.EXTRA_MTU, 517);

+ 7 - 2
plugin/nordic_dfu-5.0.1/android/src/main/java/no/nordicsemi/android/dfu/SecureDfuImpl.java

@@ -218,6 +218,11 @@ class SecureDfuImpl extends BaseCustomDfuImpl {
 
 		final BluetoothGatt gatt = mGatt;
 
+		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+			boolean request = gatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
+			logi("requestConnectionPriority result = " + request);
+		}
+
 		// Secure DFU since SDK 15 supports higher MTUs.
 		// Let's request the MTU requested by the user. It may be that a lower MTU will be used.
 		if (intent.hasExtra(DfuBaseService.EXTRA_MTU) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
@@ -610,11 +615,11 @@ class SecureDfuImpl extends BaseCustomDfuImpl {
 					writeCreateRequest(OBJECT_DATA, availableObjectSizeInBytes);
 					mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_APPLICATION,
                             "Data object (" + (currentChunk + 1) + "/" + chunkCount + ") created");
-					// Waiting until the device is ready to receive the data object.
+					// Waiting until the device is ready to receive the data object.o
 					// If prepare data object delay was set in the initiator, the delay will be used
 					// for all data objects.
 //					if (prepareObjectDelay > 0 || chunkCount == 0) {
-						if (chunkCount == 0) {
+					if (chunkCount == 0) {
 						mService.waitFor(prepareObjectDelay > 0 ? prepareObjectDelay : 400);
 						logi(prepareObjectDelay + ", " + (System.currentTimeMillis() - start));
 					}

+ 1 - 0
plugin/nordic_dfu-5.0.1/android/src/main/kotlin/dev/steenbakker/nordicdfu/DfuService.kt

@@ -14,4 +14,5 @@ class DfuService : DfuBaseService() {
         // your app package BuildConfig
         return true
     }
+
 }

+ 1 - 1
pubspec.yaml

@@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
 # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
 # Read more about iOS versioning at
 # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
-version: 1.0.0+1
+version: 1.0.1+1
 
 environment:
   sdk: ">=2.16.2 <3.0.0"