diff --git a/nanoFramework.Tools.DebugLibrary.Shared/NFDevice/NanoDeviceBase.cs b/nanoFramework.Tools.DebugLibrary.Shared/NFDevice/NanoDeviceBase.cs index 5ca77e07..a81854f4 100644 --- a/nanoFramework.Tools.DebugLibrary.Shared/NFDevice/NanoDeviceBase.cs +++ b/nanoFramework.Tools.DebugLibrary.Shared/NFDevice/NanoDeviceBase.cs @@ -289,7 +289,7 @@ public async Task ConnectToNanoBooterAsync(CancellationToken cancellationT if (DebugEngine != null) { - if (DebugEngine.ConnectionSource == ConnectionSource.nanoBooter) return true; + if (DebugEngine.IsConnectedTonanoBooter) return true; try { @@ -393,7 +393,7 @@ public async Task EraseAsync(EraseOptions options, CancellationToken cance if (!IsClrDebuggerEnabled || 0 != (options & EraseOptions.Firmware)) { - fReset = DebugEngine.ConnectionSource == ConnectionSource.nanoCLR; + fReset = DebugEngine.IsConnectedTonanoCLR; if (!await ConnectToNanoBooterAsync(cancellationToken)) { @@ -418,7 +418,7 @@ public async Task EraseAsync(EraseOptions options, CancellationToken cance long total = 0; long value = 0; - if (DebugEngine.ConnectionSource == ConnectionSource.nanoCLR) + if (DebugEngine.IsConnectedTonanoCLR) { DebugEngine.PauseExecution(); } @@ -534,7 +534,7 @@ public async Task EraseAsync(EraseOptions options, CancellationToken cance } // reboot if we are talking to the CLR - if (DebugEngine.ConnectionSource == ConnectionSource.nanoCLR) + if (DebugEngine.IsConnectedTonanoCLR) { progress?.Report("Rebooting..."); @@ -548,7 +548,7 @@ public async Task EraseAsync(EraseOptions options, CancellationToken cance public async Task DeployUpdateAsync(StorageFile comprFilePath, CancellationToken cancellationToken, IProgress progress = null) { - if (DebugEngine.ConnectionSource == ConnectionSource.nanoCLR) + if (DebugEngine.IsConnectedTonanoCLR) { if (await DeployMFUpdateAsync(comprFilePath, cancellationToken, progress)) { @@ -1435,7 +1435,7 @@ private async Task 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."); @@ -1466,7 +1466,7 @@ private async Task PrepareForDeployAsync( } } - if (DebugEngine.ConnectionSource == ConnectionSource.nanoCLR) + if (DebugEngine.IsConnectedTonanoCLR) { DebugEngine.PauseExecution(); } diff --git a/nanoFramework.Tools.DebugLibrary.Shared/PortSerial/SerialPortManager.cs b/nanoFramework.Tools.DebugLibrary.Shared/PortSerial/SerialPortManager.cs index 227522f3..2a890016 100644 --- a/nanoFramework.Tools.DebugLibrary.Shared/PortSerial/SerialPortManager.cs +++ b/nanoFramework.Tools.DebugLibrary.Shared/PortSerial/SerialPortManager.cs @@ -600,7 +600,7 @@ private async Task CheckValidNanoFrameworkSerialDeviceAsync(NanoDevice().OrResult(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()); diff --git a/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Engine.cs b/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Engine.cs index 375d651d..45e3293b 100644 --- a/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Engine.cs +++ b/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Engine.cs @@ -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; } @@ -268,15 +275,15 @@ public async Task 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; } @@ -299,7 +306,7 @@ public async Task ConnectAsync( var targetInfoPolicy = Policy.Handle().OrResult(r => r == null) .WaitAndRetry(2, retryAttempt => TimeSpan.FromMilliseconds((retryAttempt + 1) * timeout)); - if (ConnectionSource == ConnectionSource.nanoCLR && + if (IsConnectedTonanoCLR && requestCapabilities && (force || Capabilities.IsUnknown)) { @@ -331,7 +338,7 @@ public async Task ConnectAsync( } } - if (ConnectionSource == ConnectionSource.nanoBooter && + if (IsConnectedTonanoBooter && requestCapabilities && (force || TargetInfo == null)) { @@ -342,7 +349,7 @@ public async Task ConnectAsync( TargetInfo = targetInfoPolicy.Execute(() => GetMonitorTargetInfo()); } - if (requestedConnectionSource != ConnectionSource.Unknown && requestedConnectionSource != ConnectionSource) + if (requestedConnectionSource != ConnectionSource.Unknown && requestedConnectionSource != _connectionSource) { // update flag IsConnected = false; @@ -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; } @@ -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? @@ -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; @@ -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