Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework ConnectionSource property #288

Merged
merged 1 commit into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public async Task<bool> ConnectToNanoBooterAsync(CancellationToken cancellationT

if (DebugEngine != null)
{
if (DebugEngine.ConnectionSource == ConnectionSource.nanoBooter) return true;
if (DebugEngine.IsConnectedTonanoBooter) return true;

try
{
Expand Down Expand Up @@ -393,7 +393,7 @@ public async Task<bool> EraseAsync(EraseOptions options, CancellationToken cance

if (!IsClrDebuggerEnabled || 0 != (options & EraseOptions.Firmware))
{
fReset = DebugEngine.ConnectionSource == ConnectionSource.nanoCLR;
fReset = DebugEngine.IsConnectedTonanoCLR;

if (!await ConnectToNanoBooterAsync(cancellationToken))
{
Expand All @@ -418,7 +418,7 @@ public async Task<bool> EraseAsync(EraseOptions options, CancellationToken cance
long total = 0;
long value = 0;

if (DebugEngine.ConnectionSource == ConnectionSource.nanoCLR)
if (DebugEngine.IsConnectedTonanoCLR)
{
DebugEngine.PauseExecution();
}
Expand Down Expand Up @@ -534,7 +534,7 @@ public async Task<bool> EraseAsync(EraseOptions options, CancellationToken cance
}

// reboot if we are talking to the CLR
if (DebugEngine.ConnectionSource == ConnectionSource.nanoCLR)
if (DebugEngine.IsConnectedTonanoCLR)
{
progress?.Report("Rebooting...");

Expand All @@ -548,7 +548,7 @@ public async Task<bool> EraseAsync(EraseOptions options, CancellationToken cance

public async Task<bool> DeployUpdateAsync(StorageFile comprFilePath, CancellationToken cancellationToken, IProgress<string> progress = null)
{
if (DebugEngine.ConnectionSource == ConnectionSource.nanoCLR)
if (DebugEngine.IsConnectedTonanoCLR)
{
if (await DeployMFUpdateAsync(comprFilePath, cancellationToken, progress))
{
Expand Down Expand Up @@ -1435,7 +1435,7 @@ private async Task<bool> PrepareForDeployAsync(
if (updatesClr)
{
// if this is updating the CLR need to launch nanoBooter
if (DebugEngine.ConnectionSource != ConnectionSource.nanoBooter)
if (!DebugEngine.IsConnectedTonanoBooter)
{
progress?.Report("Need to launch nanoBooter before updating the firmware.");

Expand Down Expand Up @@ -1466,7 +1466,7 @@ private async Task<bool> PrepareForDeployAsync(
}
}

if (DebugEngine.ConnectionSource == ConnectionSource.nanoCLR)
if (DebugEngine.IsConnectedTonanoCLR)
{
DebugEngine.PauseExecution();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ private async Task<bool> CheckValidNanoFrameworkSerialDeviceAsync(NanoDevice<Nan
var targetReleaseInfoPolicy = Policy.Handle<NullReferenceException>().OrResult<ReleaseInfo>(r => r == null)
.WaitAndRetry(2, retryAttempt => TimeSpan.FromMilliseconds((retryAttempt + 1) * 200));

if (device.DebugEngine.ConnectionSource == ConnectionSource.nanoBooter)
if (device.DebugEngine.IsConnectedTonanoBooter)
{
// try first with new command
var targetInfo = targetInfoPolicy.Execute(() => device.DebugEngine.GetMonitorTargetInfo());
Expand Down
36 changes: 21 additions & 15 deletions nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,16 @@ public BinaryFormatter CreateBinaryFormatter()

public bool IsConnected { get; internal set; }

public ConnectionSource ConnectionSource { get; internal set; }
private ConnectionSource _connectionSource = ConnectionSource.Unknown;

public bool IsConnectedTonanoCLR { get { return ConnectionSource == ConnectionSource.nanoCLR; } }
[Obsolete("Please use IsConnectedTonanoCLR or IsConnectedTonanoBooter instead. This will be removed in a future version.")]
#pragma warning disable S2292 // Need to keep this here to allow transition period before remove it for good.
public ConnectionSource ConnectionSource { get => _connectionSource; set => _connectionSource = value; }
#pragma warning restore S2292 // Trivial properties should be auto-implemented

public bool IsConnectedTonanoCLR => _connectionSource == ConnectionSource.nanoCLR;

public bool IsConnectedTonanoBooter => _connectionSource == ConnectionSource.nanoBooter;

public bool IsTargetBigEndian { get; internal set; }

Expand Down Expand Up @@ -268,15 +275,15 @@ public async Task<bool> ConnectAsync(
switch (reply.Source)
{
case Commands.Monitor_Ping.c_Ping_Source_NanoCLR:
ConnectionSource = ConnectionSource.nanoCLR;
_connectionSource = ConnectionSource.nanoCLR;
break;

case Commands.Monitor_Ping.c_Ping_Source_NanoBooter:
ConnectionSource = ConnectionSource.nanoBooter;
_connectionSource = ConnectionSource.nanoBooter;
break;

default:
ConnectionSource = ConnectionSource.Unknown;
_connectionSource = ConnectionSource.Unknown;
break;
}

Expand All @@ -299,7 +306,7 @@ public async Task<bool> ConnectAsync(
var targetInfoPolicy = Policy.Handle<Exception>().OrResult<TargetInfo>(r => r == null)
.WaitAndRetry(2, retryAttempt => TimeSpan.FromMilliseconds((retryAttempt + 1) * timeout));

if (ConnectionSource == ConnectionSource.nanoCLR &&
if (IsConnectedTonanoCLR &&
requestCapabilities &&
(force || Capabilities.IsUnknown))
{
Expand Down Expand Up @@ -331,7 +338,7 @@ public async Task<bool> ConnectAsync(
}
}

if (ConnectionSource == ConnectionSource.nanoBooter &&
if (IsConnectedTonanoBooter &&
requestCapabilities &&
(force || TargetInfo == null))
{
Expand All @@ -342,7 +349,7 @@ public async Task<bool> ConnectAsync(
TargetInfo = targetInfoPolicy.Execute(() => GetMonitorTargetInfo());
}

if (requestedConnectionSource != ConnectionSource.Unknown && requestedConnectionSource != ConnectionSource)
if (requestedConnectionSource != ConnectionSource.Unknown && requestedConnectionSource != _connectionSource)
{
// update flag
IsConnected = false;
Expand Down Expand Up @@ -691,15 +698,15 @@ public Commands.Monitor_Ping.Reply GetConnectionSource()
switch (connectionSource.Source)
{
case Commands.Monitor_Ping.c_Ping_Source_NanoCLR:
ConnectionSource = ConnectionSource.nanoCLR;
_connectionSource = ConnectionSource.nanoCLR;
break;

case Commands.Monitor_Ping.c_Ping_Source_NanoBooter:
ConnectionSource = ConnectionSource.nanoBooter;
_connectionSource = ConnectionSource.nanoBooter;
break;

default:
ConnectionSource = ConnectionSource.Unknown;
_connectionSource = ConnectionSource.Unknown;
break;
}

Expand Down Expand Up @@ -880,7 +887,6 @@ public void Stop()

public bool IsRunning => _state.IsRunning;


#region RPC Support

// comment from original code REVIEW: Can this be refactored out of here to a separate class dedicated to RPC?
Expand Down Expand Up @@ -1637,7 +1643,7 @@ public void RebootDevice(RebootOptions options = RebootOptions.NormalReboot)
ThrowOnCommunicationFailure = false;

// check if device running nanoBooter or if it can handle soft reboot
if (ConnectionSource == ConnectionSource.nanoBooter ||
if (IsConnectedTonanoBooter ||
Capabilities.SoftReboot)
{
cmd.flags = (uint)options;
Expand Down Expand Up @@ -3832,8 +3838,8 @@ public bool UpdateDeviceConfiguration(DeviceConfiguration configuration)
// when running nanoBooter those are not available
// currently the only target that doesn't have nanoBooter is ESP32, so we are assuming that the remaining ones (being STM32 based) use internal flash for storing configuration blocks
// if that is not the case, then the flash map won't show any config blocks and this step will be skipped
if ((ConnectionSource == ConnectionSource.nanoCLR && Capabilities.ConfigBlockRequiresErase) ||
ConnectionSource == ConnectionSource.nanoBooter)
if ((IsConnectedTonanoCLR && Capabilities.ConfigBlockRequiresErase) ||
IsConnectedTonanoBooter)
{
// this devices probably requires flash erase before updating the configuration block

Expand Down