Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/WildernessLabs/Meadow.CLI
Browse files Browse the repository at this point in the history
…into develop
  • Loading branch information
adrianstevens committed Jan 6, 2025
2 parents 0f9c191 + 06fb8df commit 3fe6a6c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Source/v2/Meadow.Cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
},
"Firmware Write version": {
"commandName": "Project",
"commandLineArgs": "firmware write -v 2.0.0.2"
"commandLineArgs": "firmware write -v 2.0.0.3"
},
"Firmware Write runtime": {
"commandName": "Project",
Expand All @@ -169,7 +169,7 @@
},
"Firmware Write esp with file": {
"commandName": "Project",
"commandLineArgs": "firmware write esp -f C:\\Users\\ctack\\AppData\\Local\\WildernessLabs\\Firmware\\1.6.0.1\\MeadowComms.bin"
"commandLineArgs": "firmware write esp -f C:\\Users\\ctack\\AppData\\Local\\WildernessLabs\\Firmware\\2.0.0.3\\MeadowComms.bin"
},
"Firmware Write os DFU": {
"commandName": "Project",
Expand Down
13 changes: 10 additions & 3 deletions Source/v2/Meadow.HCom/Connections/SerialConnection.ListenerProc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async Task ReOpen() // local function
}
await Task.Delay(100);
}
}
}

while (!_isDisposed)
{
Expand All @@ -93,8 +93,12 @@ async Task ReOpen() // local function
receivedLength = _port.Read(readBuffer, 0, readBuffer.Length);
}
catch (InvalidOperationException)
{
if (AggressiveReconnectEnabled)
{
await ReOpen();
Debug.WriteLine("Aggressively re-connecting");
await ReOpen();
}
goto read;
}

Expand Down Expand Up @@ -341,7 +345,10 @@ async Task ReOpen() // local function
{
// this happens on disconnect - could be cable pulled, could be device reset
Debug.WriteLine($"Operation Cancelled. Port open: {_port.IsOpen}");
if (!_port.IsOpen) { await ReOpen();
if (AggressiveReconnectEnabled && !_port.IsOpen)
{
Debug.WriteLine("Aggressively re-connecting");
await ReOpen();
}
}
catch (Exception ex)
Expand Down
10 changes: 6 additions & 4 deletions Source/v2/Meadow.HCom/Connections/SerialConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public partial class SerialConnection : ConnectionBase, IDisposable

public override string Name { get; }

public bool AggressiveReconnectEnabled { get; set; } = false;

public SerialConnection(string port, ILogger? logger = default)
{
if (!SerialPort.GetPortNames().Contains(port, StringComparer.InvariantCultureIgnoreCase))
Expand Down Expand Up @@ -306,8 +308,6 @@ private void EncodeAndSendPacket(byte[] messageBytes, CancellationToken? cancell

private void EncodeAndSendPacket(byte[] messageBytes, int length, CancellationToken? cancellationToken = null)
{
//Debug.WriteLine($"+EncodeAndSendPacket({length} bytes)");

while (!_port.IsOpen)
{
_state = ConnectionState.Disconnected;
Expand Down Expand Up @@ -1249,12 +1249,14 @@ public override async Task<DebuggingServer> StartDebuggingSession(int port, ILog
throw new DeviceNotFoundException();
}

AggressiveReconnectEnabled = true;

var debuggingServer = new DebuggingServer(this, port, logger);

logger?.LogDebug("Tell the Debugging Server to Start Listening");
Debug.WriteLine("Tell the Debugging Server to Start Listening");
await debuggingServer.StartListening(cancellationToken);

logger?.LogDebug($"Start Debugging on port: {port}");
Debug.WriteLine($"Start Debugging on port: {port}");
await Device.StartDebugging(port, logger, cancellationToken);

return debuggingServer;
Expand Down
1 change: 0 additions & 1 deletion Source/v2/Meadow.HCom/Debugging/DebuggingServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public async Task StopListening()
_activeClient?.Dispose();
_activeClient = null;
}


var client = new ActiveClient(_connection, _logger, _cancellationTokenSource?.Token);
await client.Start(listener);
Expand Down

0 comments on commit 3fe6a6c

Please sign in to comment.