Let MMTTY hold the text waiting to go out, behind a setting
MMTTY has a type-ahead buffer of its own: characters go into it, a backspace takes back one it has not transmitted, and TxBufLen says how many are left. Used that way it paces itself, so there is no gap between characters to tune and no baud rate to keep in step with the engine. EngineTypeAhead does that, and Config > Digital picks between it and the pump that is there now. Off is still the default: three things it rests on have never been seen with a real engine. tools/Nonemm.EngineProbe asks the engine those three questions and writes the answers to a file. It starts MMTTY through the bridge, pushes a message, polls TxBufLen while it goes out, backspaces over text that has and has not been transmitted, and logs what came back on the receive side and when. The bridge learns one verb for it: `buffer` reads TxBufLen and answers with the count, or -1 when the control will not say. A property the control does not know is a log line rather than an error, since it stops nothing. TypeAhead and EngineTypeAhead share the TransmitBuffer interface, which is what the digital window now works through, so the window does not know which one it has. docs/unfinished.md states what each buffer assumes and how to run the probe. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RtspmWmS7f8kUvcyaHpRWZ
This commit is contained in:
122
tools/Nonemm.EngineProbe/Program.cs
Normal file
122
tools/Nonemm.EngineProbe/Program.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using Nonemm.Digital;
|
||||
|
||||
namespace Nonemm.EngineProbe;
|
||||
|
||||
/// Starts MMTTY through the bridge, asks it the questions in `EngineProbe`, and
|
||||
/// writes what it answered to a file. It has to run where MMTTY runs: a sound
|
||||
/// card and a Wine prefix with XMMT.ocx registered.
|
||||
public static class Program
|
||||
{
|
||||
private const string Usage = """
|
||||
usage: engine probe --engine <path to MMTTY.EXE> [options]
|
||||
|
||||
--engine <path> the engine to start, as a Linux path
|
||||
--bridge <path> the bridge program (default bridge/nonemm-mmtty-bridge.exe)
|
||||
--prefix <path> WINEPREFIX to run in (default: Wine's own)
|
||||
--ptt <port> serial port to key (default: none, so no radio is keyed)
|
||||
--out <file> where to write the report (default engine-probe.log)
|
||||
|
||||
The probe transmits: MMTTY makes tones on the sound card for about half a
|
||||
minute. It keys no serial port unless --ptt says so, but a rig listening to
|
||||
that sound card through VOX will still go on the air.
|
||||
""";
|
||||
|
||||
public static async Task<int> Main(string[] arguments)
|
||||
{
|
||||
Dictionary<string, string> options;
|
||||
try
|
||||
{
|
||||
options = Read(arguments);
|
||||
}
|
||||
catch (ArgumentException problem)
|
||||
{
|
||||
Console.Error.WriteLine(problem.Message);
|
||||
Console.Error.WriteLine();
|
||||
Console.Error.WriteLine(Usage);
|
||||
return 1;
|
||||
}
|
||||
|
||||
using CancellationTokenSource stopping = new();
|
||||
Console.CancelKeyPress += (_, e) =>
|
||||
{
|
||||
e.Cancel = true;
|
||||
stopping.Cancel();
|
||||
};
|
||||
|
||||
using ProbeLog log = new(Option(options, "out", "engine-probe.log"));
|
||||
MmttyEngine engine = new(
|
||||
new WineBridgeChannel(
|
||||
Option(options, "bridge", Path.Combine("bridge", "nonemm-mmtty-bridge.exe")),
|
||||
options.GetValueOrDefault("prefix")),
|
||||
new MmttyOptions
|
||||
{
|
||||
EnginePath = options["engine"],
|
||||
PttPort = Option(options, "ptt", ""),
|
||||
});
|
||||
try
|
||||
{
|
||||
log.Write($"starting {options["engine"]}");
|
||||
await engine.StartAsync(stopping.Token).ConfigureAwait(false);
|
||||
log.Write($"MMTTY {engine.Version} is up");
|
||||
await new EngineProbe(engine, log).RunAsync(stopping.Token).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
log.Write("stopped");
|
||||
}
|
||||
catch (Exception problem)
|
||||
{
|
||||
log.Write($"failed: {problem.Message}");
|
||||
Console.Error.WriteLine(problem);
|
||||
return 1;
|
||||
}
|
||||
finally
|
||||
{
|
||||
await Shutdown(engine, log).ConfigureAwait(false);
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"the report is in {log.Path}");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// The engine is left keyed if the probe stopped partway through, so PTT is
|
||||
/// dropped before the engine is, whatever happened.
|
||||
private static async Task Shutdown(MmttyEngine engine, ProbeLog log)
|
||||
{
|
||||
try
|
||||
{
|
||||
await engine.SetPttAsync(false).ConfigureAwait(false);
|
||||
await engine.StopAsync().ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception problem)
|
||||
{
|
||||
log.Write($"the engine did not shut down cleanly: {problem.Message}");
|
||||
}
|
||||
engine.Dispose();
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> Read(string[] arguments)
|
||||
{
|
||||
Dictionary<string, string> options = [];
|
||||
for (int i = 0; i < arguments.Length; i += 2)
|
||||
{
|
||||
if (!arguments[i].StartsWith("--", StringComparison.Ordinal))
|
||||
{
|
||||
throw new ArgumentException($"expected an option, found {arguments[i]}");
|
||||
}
|
||||
if (i + 1 >= arguments.Length)
|
||||
{
|
||||
throw new ArgumentException($"{arguments[i]} needs a value");
|
||||
}
|
||||
options[arguments[i][2..]] = arguments[i + 1];
|
||||
}
|
||||
if (!options.ContainsKey("engine"))
|
||||
{
|
||||
throw new ArgumentException("--engine is required");
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
private static string Option(Dictionary<string, string> options, string name, string fallback) =>
|
||||
options.TryGetValue(name, out string? given) ? given : fallback;
|
||||
}
|
||||
Reference in New Issue
Block a user