This commit is contained in:
Jan Racek
2026-03-27 18:31:35 +01:00
parent 1c48b8b425
commit 24d0c1fa07
27 changed files with 779 additions and 609 deletions

View File

@@ -60,6 +60,7 @@ namespace SplashEdit.EditorCode
private const int FUNC_SEEK = 0x107;
public bool IsRunning => _listenTask != null && !_listenTask.IsCompleted;
public bool HasError { get; private set; }
public PCdrvSerialHost(string portName, int baudRate, string baseDir, Action<string> log, Action<string> psxLog = null)
{
@@ -157,6 +158,7 @@ namespace SplashEdit.EditorCode
bool lastByteWasEscape = false;
var textBuffer = new StringBuilder();
int totalBytesReceived = 0;
int consecutiveErrors = 0;
DateTime lastLogTime = DateTime.Now;
_log?.Invoke("PCdrv monitor: waiting for data from PS1...");
@@ -179,6 +181,7 @@ namespace SplashEdit.EditorCode
}
int b = _port.ReadByte();
consecutiveErrors = 0;
totalBytesReceived++;
// Log first bytes received to help diagnose protocol issues
@@ -256,8 +259,16 @@ namespace SplashEdit.EditorCode
catch (OperationCanceledException) { break; }
catch (Exception ex)
{
if (!ct.IsCancellationRequested)
_log?.Invoke($"PCdrv monitor error: {ex.Message}");
if (ct.IsCancellationRequested) break;
consecutiveErrors++;
_log?.Invoke($"PCdrv monitor error: {ex.Message}");
if (consecutiveErrors >= 3)
{
_log?.Invoke("PCdrv host: too many errors, connection lost. Stopping.");
HasError = true;
break;
}
Thread.Sleep(100); // Back off before retry
}
}
}