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:
@@ -6,26 +6,36 @@ namespace Nonemm.Digital;
|
||||
/// through the same expander, the same `{END}` handling and the same ESM as a
|
||||
/// CW message does.
|
||||
///
|
||||
/// A message is not handed to the engine whole. It goes into the type-ahead
|
||||
/// buffer, which keeps the engine a couple of characters ahead of the operator,
|
||||
/// so the rest can still be rewritten. `Finished` is raised when the buffer has
|
||||
/// run dry and the engine has transmitted what it was given.
|
||||
/// A message goes into the transmit buffer rather than to the engine whole, so
|
||||
/// the part that has not been transmitted can still be rewritten. `Finished` is
|
||||
/// raised when the buffer has run dry and the engine has transmitted what it
|
||||
/// was given.
|
||||
///
|
||||
/// Which buffer depends on `engineHoldsBuffer`: `EngineTypeAhead` pushes
|
||||
/// everything to the engine and takes it back with backspaces, `TypeAhead`
|
||||
/// holds it here and feeds the engine a couple of characters at a time. Only an
|
||||
/// engine that has a buffer of its own can hold one.
|
||||
public sealed class DigitalEngineSender : MessageSender
|
||||
{
|
||||
private readonly DigitalEngine engine;
|
||||
|
||||
public DigitalEngineSender(DigitalEngine engine, double baud = TypeAhead.DefaultBaud)
|
||||
public DigitalEngineSender(
|
||||
DigitalEngine engine,
|
||||
double baud = TypeAhead.DefaultBaud,
|
||||
bool engineHoldsBuffer = false)
|
||||
{
|
||||
this.engine = engine;
|
||||
TypeAhead = new TypeAhead(
|
||||
(character, cancellation) => engine.SendAsync(character.ToString(), cancellation),
|
||||
baud);
|
||||
TypeAhead.Drained += WhenDrained;
|
||||
Buffer = engineHoldsBuffer && engine is EngineBuffer holder
|
||||
? new EngineTypeAhead(holder)
|
||||
: new TypeAhead(
|
||||
(character, cancellation) => engine.SendAsync(character.ToString(), cancellation),
|
||||
baud);
|
||||
Buffer.Drained += WhenDrained;
|
||||
engine.TransmitChanged += WhenTransmitChanged;
|
||||
}
|
||||
|
||||
/// What is waiting to go out, which the digital window shows and edits.
|
||||
public TypeAhead TypeAhead { get; }
|
||||
public TransmitBuffer Buffer { get; }
|
||||
|
||||
public bool IsReady => engine.IsConnected;
|
||||
|
||||
@@ -37,7 +47,7 @@ public sealed class DigitalEngineSender : MessageSender
|
||||
|
||||
public Task SendAsync(string text, CancellationToken cancellation = default)
|
||||
{
|
||||
TypeAhead.Append(text);
|
||||
Buffer.Append(text);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -45,7 +55,7 @@ public sealed class DigitalEngineSender : MessageSender
|
||||
/// and the engine drops what it still holds.
|
||||
public Task AbortAsync(CancellationToken cancellation = default)
|
||||
{
|
||||
TypeAhead.Drop();
|
||||
Buffer.Drop();
|
||||
return engine.AbortAsync(cancellation);
|
||||
}
|
||||
|
||||
@@ -56,8 +66,8 @@ public sealed class DigitalEngineSender : MessageSender
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
TypeAhead.Drained -= WhenDrained;
|
||||
TypeAhead.Dispose();
|
||||
Buffer.Drained -= WhenDrained;
|
||||
Buffer.Dispose();
|
||||
engine.TransmitChanged -= WhenTransmitChanged;
|
||||
}
|
||||
|
||||
@@ -75,8 +85,8 @@ public sealed class DigitalEngineSender : MessageSender
|
||||
{
|
||||
return;
|
||||
}
|
||||
TypeAhead.EngineIdle();
|
||||
if (!TypeAhead.IsSending)
|
||||
Buffer.EngineIdle();
|
||||
if (!Buffer.IsSending)
|
||||
{
|
||||
Finished?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user