mcumgr_flutter,未移动到达到100%固件传输的成功状态

g9icjywg  于 2023-05-19  发布在  Flutter
关注(0)|答案(1)|浏览(616)

我试图从mcumgr插件转移到mcumgr_flutter,我遇到了一个问题,当达到100%传输固件时,我没有得到状态蒸汽观测器向我发送成功状态。它在向我发送Confirm状态后崩溃。
我能够发送固件数据,但当达到100%时,我得到事件确认,然后什么也没有发生。我在updateManager下没有看到任何确认方法或如何确认任何事情,因此我可以重置设备,并且我从未获得FirmwareUpgradeState.success事件。
我在终端中获得的日志:

flutter: A Upgrade started with 1 images using 'Confirm Only' mode
flutter: W Device capabilities not supported.
flutter: I Cancelling 'Erase App Settings' since device capabilities are not supported.
flutter: I Validation response: {"splitStatus" : 0, "images" : {{"version" : "0.0.10.6", "pending" : false, "active" : true, "bootable" : true, "hash" : 0x6A953AFF74B69E7DBFA84BCF4F44C04B907A5C417450152331D64F4A946E8B68, "permanent" : false, "slot" : 0, "confirmed" : true}, {"slot" : 1, "permanent" : false, "version" : "0.0.10.6", "confirmed" : false, "hash" : 0x6A953AFF74B69E7DBFA84BCF4F44C04B907A5C417450152331D64F4A946E8B68, "pending" : false, "active" : false, "bootable" : true}}}
flutter: E Request (Group: image, seq: 1) failed: Insufficient MTU: 249.)
flutter: I MTU set to 249
.....
.....
flutter: Confirm

以及我在www.example.com页面上阅读“文档”时使用的代码pub.dev。

final managerFactory = FirmwareUpdateManagerFactory();
// `deviceId` is a String with the device's MAC address (on Android) or UUID (on iOS)
    final updateManager = await managerFactory.getUpdateManager(_deviceID!);
// call `setup` before using the manager
    final updateStream = updateManager.setup();

    Uint8List content = loadFirmware();
   

    // `firmware` is a List of data and index pairs
    final List<Tuple2<int, Uint8List>> firmwareScheme = [Tuple2(1, content)];
    const configuration = FirmwareUpgradeConfiguration(
      estimatedSwapTime: Duration(seconds: 0),
      byteAlignment: ImageUploadAlignment.fourByte,
      eraseAppSettings: true,
      pipelineDepth: 1,
    );
// `configuration` is an optional parameter. If not provided, default values will be used.

    final logger = updateManager.logger;
    _loggerSub = logger.logMessageStream.listen((event) {
      for (var msg in event) {
        print("${msg.level.shortName} ${msg.message}");
      }
    });

    updateManager.update(firmwareScheme, configuration: configuration).catchError((e) {
      AlertDialog alert = const AlertDialog(
        title: Text('Firmware Upload Error'),
        content: Text('An error happened while uploading the firmware, please reset Egrid manually'),
      );
      showDialog(
          context: locator.get<NavigationService>().navigatorKey.currentContext!,
          builder: (ctx) {
            return alert;
          });
      return e;
    });

    _updateStateStreamSub = updateManager.updateStateStream?.listen((event) async {
      print(event);
      if (event == FirmwareUpgradeState.success) {
      //never gets called 
        await _updateStateStreamSub?.cancel();
        await _progressStreamSub?.cancel();
        await connection?.cancel();
      } else if (event == FirmwareUpgradeState.confirm) {
         // ????what do here 
      } else {}
    });

    _progressStreamSub = updateManager.progressStream.listen((event) {
      locator.get<BikeViewModel>().firmwareProgres = event.bytesSent / event.imageSize * 100;
      locator.get<BikeViewModel>().firmwareProgressUpdate =
          "${event.bytesSent.fileSize(round: 1)} / ${event.imageSize.fileSize(round: 1)} bytes sent";
    });
6tdlim6h

6tdlim6h1#

问题很简单。我忘记将updateManager设置为字段。所以一旦它做了它的事情,它得到了垃圾收集。

this._updateManager = updateManager;

相关问题