Skip to content

Commit

Permalink
Merge pull request #68
Browse files Browse the repository at this point in the history
develop
  • Loading branch information
ksidirop-laerdal authored Nov 15, 2024
2 parents fcf291c + df785eb commit ea8201e
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 196 deletions.
1 change: 0 additions & 1 deletion Laerdal.Dfu.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_Misc", "_Misc", "{37EBD209
LICENSE = LICENSE
Laerdal.Scripts\Laerdal.Version.sh = Laerdal.Scripts\Laerdal.Version.sh
Laerdal.Scripts\Laerdal.Builder.targets = Laerdal.Scripts\Laerdal.Builder.targets
Laerdal.Scripts\Laerdal.Changelog.sh = Laerdal.Scripts\Laerdal.Changelog.sh
Laerdal.Scripts\Laerdal.CreateNewReleaseInGithub.sh = Laerdal.Scripts\Laerdal.CreateNewReleaseInGithub.sh
Laerdal.Scripts\Laerdal.SetupBuildEnvironment.sh = Laerdal.Scripts\Laerdal.SetupBuildEnvironment.sh
.github\workflows\github-actions.yml = .github\workflows\github-actions.yml
Expand Down
4 changes: 2 additions & 2 deletions Laerdal.Dfu/Laerdal.Dfu.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@
</ItemGroup>
<!-- iOS -->
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-ios'">
<PackageReference Include="Laerdal.Dfu.Bindings.iOS" Version="4.15.3.43972" />
<PackageReference Include="Laerdal.Dfu.Bindings.iOS" Version="4.15.3.43980" />
</ItemGroup>
<!-- MacCatalyst -->
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-maccatalyst'">
<PackageReference Include="Laerdal.Dfu.Bindings.iOS" Version="4.15.3.43972" />
<PackageReference Include="Laerdal.Dfu.Bindings.iOS" Version="4.15.3.43980" />
</ItemGroup>
<!-- =========================== PACKAGES ============================ -->

Expand Down
1 change: 1 addition & 0 deletions Laerdal.Dfu/Laerdal.Dfu.csproj.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=ios/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=platforms/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=platforms_002Eandroid/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=platforms_002Edroid/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=platforms_002Eios/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=platforms_002Eiosandmaccatalyst/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=platforms_002Enetx/@EntryIndexedValue">True</s:Boolean>
Expand Down
101 changes: 42 additions & 59 deletions Laerdal.Dfu/Platforms.Droid/DfuInstallation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,101 +13,83 @@ namespace Laerdal.Dfu
{
public partial class DfuInstallation
{
public Func<Laerdal.Dfu.Bindings.Android.DfuServiceInitiator, Laerdal.Dfu.Bindings.Android.DfuServiceInitiator> CustomDfuServiceInitiatorConfiguration { get; set; } = (dfuInitiator) => dfuInitiator;
public Func<Laerdal.Dfu.Bindings.Android.DfuServiceInitiator, Laerdal.Dfu.Bindings.Android.DfuServiceInitiator> CustomDfuServiceInitiatorConfiguration { get; set; } = dfuInitiator => dfuInitiator;

private void SetInitiator()
{
DfuProgressListener = new DfuProgressListener(this);
DfuLogger = new DfuLogger(DeviceId);
DfuProgressListener = new DfuProgressListener(this);

Initiator = new Laerdal.Dfu.Bindings.Android.DfuServiceInitiator(DeviceId).SetZip(FileUrl);

// PacketsReceiptNotifications
Initiator = Initiator.SetPacketsReceiptNotificationsEnabled(PacketReceiptNotificationParameter.HasValue);
Initiator = Initiator.SetPacketsReceiptNotificationsValue(PacketReceiptNotificationParameter ?? Laerdal.Dfu.Bindings.Android.DfuServiceInitiator.DefaultPrnValue);

// DataObjectPreparationDelay
Initiator = Initiator.SetPrepareDataObjectDelay((long) (DataObjectPreparationDelay ?? 0));
Initiator = new Laerdal.Dfu.Bindings.Android.DfuServiceInitiator(DeviceId).SetZip(FileUrl)!;
Initiator = Initiator.SetPacketsReceiptNotificationsEnabled(PacketReceiptNotificationParameter.HasValue)!; // PacketsReceiptNotifications
Initiator = Initiator.SetPacketsReceiptNotificationsValue(PacketReceiptNotificationParameter ?? Laerdal.Dfu.Bindings.Android.DfuServiceInitiator.DefaultPrnValue)!;
Initiator = Initiator.SetPrepareDataObjectDelay((long) (DataObjectPreparationDelay ?? 0))!; // DataObjectPreparationDelay

// DisableResume
if (DisableResume ?? false)
{
Initiator = Initiator.DisableResume();
Initiator = Initiator.DisableResume()!;
}

// AlternativeAdvertisingName
if (!string.IsNullOrEmpty(AlternativeAdvertisingName))
{
Initiator = Initiator.SetDeviceName(AlternativeAdvertisingName);
Initiator = Initiator.SetDeviceName(AlternativeAdvertisingName)!;
}

// ForceScanningForNewAddressInLegacyDfu
if (ForceScanningForNewAddressInLegacyDfu.HasValue)
{
Initiator = Initiator.SetForceScanningForNewAddressInLegacyDfu(ForceScanningForNewAddressInLegacyDfu.Value);
Initiator = Initiator.SetForceScanningForNewAddressInLegacyDfu(ForceScanningForNewAddressInLegacyDfu.Value)!;
}

// EnableUnsafeExperimentalButtonlessServiceInSecureDfu
if (EnableUnsafeExperimentalButtonlessServiceInSecureDfu.HasValue)
{
Initiator = Initiator.SetUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(EnableUnsafeExperimentalButtonlessServiceInSecureDfu.Value);
Initiator = Initiator.SetUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(EnableUnsafeExperimentalButtonlessServiceInSecureDfu.Value)!;
}

// ForceDfu

if (ForceDfu.HasValue)
{
Initiator = Initiator.SetForceDfu(ForceDfu.Value);
Initiator = Initiator.SetForceDfu(ForceDfu.Value)!;
}

// DisableMtuRequest
if (DisableMtuRequest ?? false)
{
Initiator = Initiator.DisableMtuRequest();
Initiator = Initiator.DisableMtuRequest()!;
}

// DisableNotification
if (DisableNotification.HasValue)
{
Initiator = Initiator.SetDisableNotification(DisableNotification.Value);
Initiator = Initiator.SetDisableNotification(DisableNotification.Value)!;
}

// MbrSize
Initiator = Initiator.SetMbrSize(MbrSize ?? Laerdal.Dfu.Bindings.Android.DfuServiceInitiator.DefaultMbrSize);
Initiator = Initiator.SetMbrSize(MbrSize ?? Laerdal.Dfu.Bindings.Android.DfuServiceInitiator.DefaultMbrSize)!;

// Scope
if (Scope.HasValue)
{
Initiator = Initiator.SetScope((int) Scope.Value);
Initiator = Initiator.SetScope((int) Scope.Value)!;
}

// Foreground
if (Foreground.HasValue)
{
Initiator = Initiator.SetForeground(Foreground.Value);
Initiator = Initiator.SetForeground(Foreground.Value)!;
}

// KeepBond

if (KeepBond.HasValue)
{
Initiator = Initiator.SetKeepBond(KeepBond.Value);
Initiator = Initiator.SetKeepBond(KeepBond.Value)!;
}

// RestoreBond
if (RestoreBond.HasValue)
{
Initiator = Initiator.SetRestoreBond(RestoreBond.Value);
Initiator = Initiator.SetRestoreBond(RestoreBond.Value)!;
}

// Mtu
if (Mtu.HasValue)
{
Initiator = Initiator.SetMtu(Mtu.Value);
Initiator = Initiator.SetMtu(Mtu.Value)!;
}

// NumberOfRetries

if (NumberOfRetries.HasValue)
{
Initiator = Initiator.SetNumberOfRetries(NumberOfRetries.Value);
Initiator = Initiator.SetNumberOfRetries(NumberOfRetries.Value)!;
}

// For Oreo progress
Expand All @@ -116,7 +98,7 @@ private void SetInitiator()
Laerdal.Dfu.Bindings.Android.DfuServiceInitiator.CreateDfuNotificationChannel(Android.App.Application.Context);
}

Initiator = CustomDfuServiceInitiatorConfiguration?.Invoke(Initiator);
Initiator = CustomDfuServiceInitiatorConfiguration?.Invoke(Initiator)!;

// public DfuServiceInitiator SetCurrentMtu(int mtu)
// public DfuServiceInitiator SetCustomUuidsForButtonlessDfuWithBondSharing(UUID buttonlessDfuServiceUuid, UUID buttonlessDfuControlPointUuid)
Expand All @@ -126,28 +108,24 @@ private void SetInitiator()
// public DfuServiceInitiator SetCustomUuidsForSecureDfu(UUID dfuServiceUuid, UUID dfuControlPointUuid, UUID dfuPacketUuid)
}

private DfuLogger DfuLogger { get; set;}
private DfuProgressListener DfuProgressListener { get; set;}

public Laerdal.Dfu.Bindings.Android.DfuServiceInitiator Initiator { get; private set; }

public Laerdal.Dfu.Bindings.Android.DfuServiceController Controller { get; private set; }

private DfuProgressListener DfuProgressListener { get; set;}

private DfuLogger DfuLogger { get; set;}

public DfuInstallation(string deviceId, string fileUrl) : base(deviceId, fileUrl)
{
}

public DfuInstallation() : base()
public DfuInstallation()
{
}

public override void Start()
{
if (Controller != null)
{
throw new System.Exception("Controller is already set.");
}

SetInitiator();
Controller = Initiator.Start(Android.App.Application.Context, Class.FromType(typeof(DfuService)));
Expand All @@ -170,26 +148,31 @@ public override void Abort()

protected override void Dispose(bool disposing)
{
if (!disposing)
return;

DfuProgressListener?.Dispose();
if (disposing)
{
Initiator?.Dispose();
Controller?.Dispose();
DfuLogger?.Dispose();
}
DfuProgressListener = null;

Initiator?.Dispose();
Initiator = null;

Controller?.Dispose();
Controller = null;

DfuLogger?.Dispose();
DfuLogger = null;
}

public bool CheckDeviceAddress(string deviceAddress)
{
if (deviceAddress == DeviceId)
{
return true;
}

var parsed = DeviceId.Split(':').Select(p => int.Parse(p, NumberStyles.HexNumber)).ToList();
parsed[^1] += 1;

var deviceAddressPlusOne = string.Join(":", parsed.Select(p => p.ToString("X2")));

if (deviceAddress == deviceAddressPlusOne)
{
return true;
Expand Down
2 changes: 1 addition & 1 deletion Laerdal.Dfu/Platforms.NetX/DfuInstallation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public DfuInstallation(string deviceId, string fileUrl) : base(deviceId, fileUrl
throw new NotImplementedException();
}

public DfuInstallation() : base()
public DfuInstallation()
{
throw new NotImplementedException();
}
Expand Down
Loading

0 comments on commit ea8201e

Please sign in to comment.