Nordic Bluetooth 切换到DFU Mode

  转义Nordic文档:关于如何切换BLE如何切换到DFU Mode。

  下面的流程图展示了如何将蓝牙切换到DFU Mode:

 

  如图所示,需要满足两个条件:

  1)打开中央设备的notificaton功能(即订阅notify的characteristic)

  2)给设备发送Start DFU命令:0x01xx(xx取值为01 SoftDevice/02 Bootloader/03 SoftDevice Bootloader/04 Application),一般使用0x0104就好。

  Xamarin.Form示例代码如下:

  

var notifyDFUCharacter = await DFUservice.GetCharacteristicAsync(Guid.Parse(Rlm1BleControlPointCharUuid));
                notifyDFUCharacter.ValueUpdated += ((o, args) =>
                {
                    var bytes = args.Characteristic.Value;
                    string text = "";
                    for (int i = 0; i < bytes.Length; i++)
                    {
                        text += ($"0x{bytes[i].ToString("X2")},");
                    }
                    Debug.WriteLine($"**********DFU {text.TrimEnd(',')} notify");

                    Rlm1DFUNotifyHandel(DFUservice, bytes);
                });
                await notifyDFUCharacter.StartUpdatesAsync();

                    //4 switch to DFU mode
                    await Task.Delay(5 * 100);
                    const byte opCodeStartDfu = 0x01;
                    const byte imageType = 0x04;

                    var writeDFUCharacter = await DFUservice.GetCharacteristicAsync(Guid.Parse(Rlm1BleControlPointCharUuid));
                    await writeDFUCharacter.WriteAsync(new byte[] { opCodeStartDfu, imageType });
                

  

posted @ 2021-09-26 16:32  醉梦ai天涯  阅读(226)  评论(0编辑  收藏  举报