diff --git a/Source/v2/Meadow.CLI/Commands/Current/Nsh/NshDisableCommand.cs b/Source/v2/Meadow.CLI/Commands/Current/Nsh/NshDisableCommand.cs new file mode 100644 index 00000000..3050459d --- /dev/null +++ b/Source/v2/Meadow.CLI/Commands/Current/Nsh/NshDisableCommand.cs @@ -0,0 +1,25 @@ +using CliFx.Attributes; +using Microsoft.Extensions.Logging; + +namespace Meadow.CLI.Commands.DeviceManagement; + +[Command("nsh disable", Description = "Disables the Nuttx shell on the Meadow device")] +public class NshDisableCommand : BaseDeviceCommand +{ + public NshDisableCommand(MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory) + : base(connectionManager, loggerFactory) + { } + + protected override async ValueTask ExecuteCommand() + { + var device = await GetCurrentDevice(); + + Logger?.LogInformation("Disabling NSH..."); + + var state = await device.IsRuntimeEnabled(CancellationToken); + + await device.NshDisable(CancellationToken); + + Logger?.LogInformation("NSH disabled"); + } +} \ No newline at end of file diff --git a/Source/v2/Meadow.CLI/Commands/Current/Nsh/NshEnableCommand.cs b/Source/v2/Meadow.CLI/Commands/Current/Nsh/NshEnableCommand.cs new file mode 100644 index 00000000..20b0f2f3 --- /dev/null +++ b/Source/v2/Meadow.CLI/Commands/Current/Nsh/NshEnableCommand.cs @@ -0,0 +1,25 @@ +using CliFx.Attributes; +using Microsoft.Extensions.Logging; + +namespace Meadow.CLI.Commands.DeviceManagement; + +[Command("nsh enable", Description = "Enables the Nuttx shell on the Meadow device")] +public class NshEnableCommand : BaseDeviceCommand +{ + public NshEnableCommand(MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory) + : base(connectionManager, loggerFactory) + { } + + protected override async ValueTask ExecuteCommand() + { + var device = await GetCurrentDevice(); + + Logger?.LogInformation("Enabling NSH..."); + + var state = await device.IsRuntimeEnabled(CancellationToken); + + await device.NshEnable(CancellationToken); + + Logger?.LogInformation("NSH enabled"); + } +} \ No newline at end of file diff --git a/Source/v2/Meadow.Cli/Commands/Current/App/AppRunCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/App/AppRunCommand.cs index bd511a39..356ff0c0 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/App/AppRunCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/App/AppRunCommand.cs @@ -11,8 +11,8 @@ public class AppRunCommand : BaseDeviceCommand { private readonly IPackageManager _packageManager; - [CommandOption("no-prefix", 'n', Description = "When set, the message source prefix (e.g. 'stdout>') is suppressed during 'listen'", IsRequired = false)] - public bool NoPrefix { get; init; } + [CommandOption("prefix", 'p', Description = "When set, the message source prefix (e.g. 'stdout>') is shown during 'listen'", IsRequired = false)] + public bool Prefix { get; init; } = false; [CommandOption('c', Description = Strings.BuildConfiguration, IsRequired = false)] public string? Configuration { get; private set; } @@ -136,13 +136,13 @@ private void OnFileWriteProgress(object? sender, (string fileName, long complete private void OnDeviceMessageReceived(object? sender, (string message, string? source) e) { - if (NoPrefix) + if (Prefix) { - Logger?.LogInformation($"{e.message.TrimEnd('\n', '\r')}"); + Logger?.LogInformation($"{e.source}> {e.message.TrimEnd('\n', '\r')}"); } else { - Logger?.LogInformation($"{e.source}> {e.message.TrimEnd('\n', '\r')}"); + Logger?.LogInformation($"{e.message.TrimEnd('\n', '\r')}"); } } } \ No newline at end of file diff --git a/Source/v2/Meadow.Cli/Commands/Current/ListenCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/ListenCommand.cs index d8087eae..8a60fa1e 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/ListenCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/ListenCommand.cs @@ -6,8 +6,8 @@ namespace Meadow.CLI.Commands.DeviceManagement; [Command("listen", Description = "Listen for console output from Meadow")] public class ListenCommand : BaseDeviceCommand { - [CommandOption("no-prefix", 'n', Description = "When set, the message source prefix (e.g. 'stdout>') is suppressed", IsRequired = false)] - public bool NoPrefix { get; init; } + [CommandOption("prefix", 'p', Description = "When set, the message source prefix (e.g. 'stdout>') is shown", IsRequired = false)] + public bool Prefix { get; init; } = false; public ListenCommand(MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory) : base(connectionManager, loggerFactory) @@ -20,13 +20,13 @@ private void Connection_ConnectionMessage(object? sender, string e) private void OnDeviceMessageReceived(object? sender, (string message, string? source) e) { - if (NoPrefix) + if (Prefix) { - Logger?.LogInformation($"{e.message.TrimEnd('\n', '\r')}"); + Logger?.LogInformation($"{e.source}> {e.message.TrimEnd('\n', '\r')}"); } else { - Logger?.LogInformation($"{e.source}> {e.message.TrimEnd('\n', '\r')}"); + Logger?.LogInformation($"{e.message.TrimEnd('\n', '\r')}"); } } diff --git a/Source/v2/Meadow.Hcom/Connections/ConnectionBase.cs b/Source/v2/Meadow.Hcom/Connections/ConnectionBase.cs index 5b411c58..6e9bbd42 100755 --- a/Source/v2/Meadow.Hcom/Connections/ConnectionBase.cs +++ b/Source/v2/Meadow.Hcom/Connections/ConnectionBase.cs @@ -50,6 +50,9 @@ public abstract class ConnectionBase : IMeadowConnection, IDisposable public abstract Task SendDebuggerData(byte[] debuggerData, uint userData, CancellationToken? cancellationToken); + public abstract Task NshDisable(CancellationToken? cancellationToken = null); + public abstract Task NshEnable(CancellationToken? cancellationToken = null); + public ConnectionBase() { } diff --git a/Source/v2/Meadow.Hcom/Connections/LocalConnection.cs b/Source/v2/Meadow.Hcom/Connections/LocalConnection.cs index b42a62b5..4d37b796 100755 --- a/Source/v2/Meadow.Hcom/Connections/LocalConnection.cs +++ b/Source/v2/Meadow.Hcom/Connections/LocalConnection.cs @@ -285,4 +285,14 @@ public override void Detach() { throw new NotImplementedException(); } + + public override Task NshDisable(CancellationToken? cancellationToken = null) + { + throw new NotImplementedException(); + } + + public override Task NshEnable(CancellationToken? cancellationToken = null) + { + throw new NotImplementedException(); + } } diff --git a/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs b/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs index 3c094aa4..76730f6f 100755 --- a/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs +++ b/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs @@ -246,7 +246,8 @@ private void CommandManager() { while (!_isDisposed) { - _commandEvent.WaitOne(); + _commandEvent.WaitOne(1000); + while (_pendingCommands.Count > 0) { Debug.WriteLine($"There are {_pendingCommands.Count} pending commands"); @@ -711,6 +712,32 @@ public override async Task RuntimeDisable(CancellationToken? cancellationToken = await WaitForConcluded(null, cancellationToken); } + public override async Task NshEnable(CancellationToken? cancellationToken = null) + { + var command = RequestBuilder.Build(1); + + InfoMessages.Clear(); + + _lastRequestConcluded = null; + + EnqueueRequest(command); + + await WaitForConcluded(null, cancellationToken); + } + + public override async Task NshDisable(CancellationToken? cancellationToken = null) + { + var command = RequestBuilder.Build(0); + + InfoMessages.Clear(); + + _lastRequestConcluded = null; + + EnqueueRequest(command); + + await WaitForConcluded(null, cancellationToken); + } + public override async Task TraceEnable(CancellationToken? cancellationToken = null) { var command = RequestBuilder.Build(); diff --git a/Source/v2/Meadow.Hcom/Connections/SimulatorConnection.cs b/Source/v2/Meadow.Hcom/Connections/SimulatorConnection.cs index 77fb9b2f..e581f3ae 100755 --- a/Source/v2/Meadow.Hcom/Connections/SimulatorConnection.cs +++ b/Source/v2/Meadow.Hcom/Connections/SimulatorConnection.cs @@ -159,4 +159,14 @@ public override void Detach() { throw new NotImplementedException(); } + + public override Task NshDisable(CancellationToken? cancellationToken = null) + { + throw new NotImplementedException(); + } + + public override Task NshEnable(CancellationToken? cancellationToken = null) + { + throw new NotImplementedException(); + } } diff --git a/Source/v2/Meadow.Hcom/Connections/TcpConnection.cs b/Source/v2/Meadow.Hcom/Connections/TcpConnection.cs index e6964cb8..183a5ed5 100755 --- a/Source/v2/Meadow.Hcom/Connections/TcpConnection.cs +++ b/Source/v2/Meadow.Hcom/Connections/TcpConnection.cs @@ -200,4 +200,14 @@ public override void Detach() { throw new NotImplementedException(); } + + public override Task NshDisable(CancellationToken? cancellationToken = null) + { + throw new NotImplementedException(); + } + + public override Task NshEnable(CancellationToken? cancellationToken = null) + { + throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/Source/v2/Meadow.Hcom/Debugging/DebuggingServer.ActiveClient.cs b/Source/v2/Meadow.Hcom/Debugging/DebuggingServer.ActiveClient.cs index 5849ab1c..2708217a 100644 --- a/Source/v2/Meadow.Hcom/Debugging/DebuggingServer.ActiveClient.cs +++ b/Source/v2/Meadow.Hcom/Debugging/DebuggingServer.ActiveClient.cs @@ -115,7 +115,7 @@ private async Task SendToVisualStudio() { if (_networkStream != null && _networkStream.CanWrite) { - _vsDebugDataReady.WaitOne(); + _vsDebugDataReady.WaitOne(1000); while (_debuggerMessages.Count > 0) { diff --git a/Source/v2/Meadow.Hcom/IMeadowConnection.cs b/Source/v2/Meadow.Hcom/IMeadowConnection.cs index d835ffc0..69a868b8 100755 --- a/Source/v2/Meadow.Hcom/IMeadowConnection.cs +++ b/Source/v2/Meadow.Hcom/IMeadowConnection.cs @@ -51,4 +51,7 @@ public interface IMeadowConnection : IDisposable Task StartDebuggingSession(int port, ILogger? logger, CancellationToken cancellationToken); Task StartDebugging(int port, ILogger? logger, CancellationToken? cancellationToken); Task SendDebuggerData(byte[] debuggerData, uint userData, CancellationToken? cancellationToken); + + Task NshDisable(CancellationToken? cancellationToken = null); + Task NshEnable(CancellationToken? cancellationToken = null); } \ No newline at end of file diff --git a/Source/v2/Meadow.Hcom/IMeadowDevice.cs b/Source/v2/Meadow.Hcom/IMeadowDevice.cs index 25eed90a..515017e3 100755 --- a/Source/v2/Meadow.Hcom/IMeadowDevice.cs +++ b/Source/v2/Meadow.Hcom/IMeadowDevice.cs @@ -28,4 +28,6 @@ public interface IMeadowDevice Task GetPublicKey(CancellationToken? cancellationToken = null); Task StartDebugging(int port, ILogger? logger, CancellationToken? cancellationToken); Task SendDebuggerData(byte[] debuggerData, uint userData, CancellationToken? cancellationToken); + Task NshDisable(CancellationToken? cancellationToken = null); + Task NshEnable(CancellationToken? cancellationToken = null); } \ No newline at end of file diff --git a/Source/v2/Meadow.Hcom/MeadowDevice.cs b/Source/v2/Meadow.Hcom/MeadowDevice.cs index bb51e176..1487e127 100755 --- a/Source/v2/Meadow.Hcom/MeadowDevice.cs +++ b/Source/v2/Meadow.Hcom/MeadowDevice.cs @@ -169,4 +169,14 @@ public async Task SendDebuggerData(byte[] debuggerData, uint userData, Cancellat { await _connection.SendDebuggerData(debuggerData, userData, cancellationToken); } + + public async Task NshDisable(CancellationToken? cancellationToken = null) + { + await _connection.NshDisable(cancellationToken); + } + + public async Task NshEnable(CancellationToken? cancellationToken = null) + { + await _connection.NshEnable(cancellationToken); + } } \ No newline at end of file diff --git a/Source/v2/Meadow.Hcom/SerialRequests/NshEnableDisableRequest.cs b/Source/v2/Meadow.Hcom/SerialRequests/NshEnableDisableRequest.cs new file mode 100644 index 00000000..ebafaa6a --- /dev/null +++ b/Source/v2/Meadow.Hcom/SerialRequests/NshEnableDisableRequest.cs @@ -0,0 +1,6 @@ +namespace Meadow.Hcom; + +internal class NshEnableDisableRequest : Request +{ + public override RequestType RequestType => RequestType.HCOM_MDOW_REQUEST_ENABLE_DISABLE_NSH; +} \ No newline at end of file