Add the digital interface, running MMTTY under Wine
MMTTY and 2Tone have no socket or pipe interface: N1MM hosts XMMT.ocx and exchanges window messages with the engine. A Linux process cannot load that control, so bridge/nonemm-mmtty-bridge.exe hosts it under Wine and passes lines over its standard input and output. docs/digital-bridge.md states the protocol and what the control needs. The window is N1MM's: receive pane with coloured callsigns, grab list, call stacking, twenty-four macro buttons and the engine controls. One left click copies what is under it — a callsign to the callsign box, anything else to the exchange box the contest keeps for that kind of value. Config > Digital registers XMMT.ocx in the Wine prefix on its own, making the prefix first if it is not there. The engine, the bridge and the control start at the copies shipped beside the program. The bridge reads the control's own events. OnTranslateMessage carries only the messages the control has no event for, so nothing was ever decoded through it. hamlib's data mode names read as digital modes now, and a mode typed into the callsign box changes mode the way a frequency changes band, so a station with no radio can reach RTTY at all. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RoGtneMQaz4M9w7Kk49AVD
This commit is contained in:
36
tests/Nonemm.Digital.Tests/BridgeLineTests.cs
Normal file
36
tests/Nonemm.Digital.Tests/BridgeLineTests.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Nonemm.Digital;
|
||||
|
||||
namespace Nonemm.Digital.Tests;
|
||||
|
||||
public class BridgeLineTests
|
||||
{
|
||||
[Fact]
|
||||
public void AFieldWithATabInItStaysOneField()
|
||||
{
|
||||
string line = BridgeLine.Write("send", "CQ\tTEST");
|
||||
|
||||
(string verb, string[] fields) = BridgeLine.Read(line);
|
||||
|
||||
Assert.Equal("send", verb);
|
||||
Assert.Equal(["CQ\tTEST"], fields);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ABackslashSurvivesTheTrip()
|
||||
{
|
||||
string line = BridgeLine.Write("open", "RTTY Engine 1", "", @"""C:\mmtty\mmtty.exe"" -r -Z");
|
||||
|
||||
(_, string[] fields) = BridgeLine.Read(line);
|
||||
|
||||
Assert.Equal(@"""C:\mmtty\mmtty.exe"" -r -Z", fields[2]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AShortLineIsNotAnError()
|
||||
{
|
||||
(string verb, string[] fields) = BridgeLine.Read("ready");
|
||||
|
||||
Assert.Equal("ready", verb);
|
||||
Assert.Empty(fields);
|
||||
}
|
||||
}
|
||||
54
tests/Nonemm.Digital.Tests/FakeBridge.cs
Normal file
54
tests/Nonemm.Digital.Tests/FakeBridge.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Nonemm.Digital;
|
||||
|
||||
namespace Nonemm.Digital.Tests;
|
||||
|
||||
/// A bridge that goes nowhere: the test reads what was sent to it and says what
|
||||
/// comes back.
|
||||
public sealed class FakeBridge : BridgeChannel
|
||||
{
|
||||
private readonly List<string> sent = [];
|
||||
|
||||
public bool IsStarted { get; private set; }
|
||||
|
||||
public IReadOnlyList<string> Sent
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (sent)
|
||||
{
|
||||
return sent.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler<string>? LineReceived;
|
||||
|
||||
public event EventHandler<string>? Failed;
|
||||
|
||||
public Task StartAsync(CancellationToken cancellation = default)
|
||||
{
|
||||
IsStarted = true;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task SendAsync(string line, CancellationToken cancellation = default)
|
||||
{
|
||||
lock (sent)
|
||||
{
|
||||
sent.Add(line);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<string> ToWindowsPathAsync(string path, CancellationToken cancellation = default) =>
|
||||
Task.FromResult("Z:" + path.Replace('/', '\\'));
|
||||
|
||||
public void Say(string verb, params string[] fields) =>
|
||||
LineReceived?.Invoke(this, BridgeLine.Write(verb, fields));
|
||||
|
||||
public void Stop(string why) => Failed?.Invoke(this, why);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
153
tests/Nonemm.Digital.Tests/MmttyEngineTests.cs
Normal file
153
tests/Nonemm.Digital.Tests/MmttyEngineTests.cs
Normal file
@@ -0,0 +1,153 @@
|
||||
using Nonemm.Digital;
|
||||
|
||||
namespace Nonemm.Digital.Tests;
|
||||
|
||||
/// The engine driven through a bridge that goes nowhere.
|
||||
public class MmttyEngineTests
|
||||
{
|
||||
private static readonly TimeSpan Patience = TimeSpan.FromSeconds(5);
|
||||
|
||||
private static MmttyEngine Engine(FakeBridge bridge) =>
|
||||
new(bridge, new MmttyOptions { EnginePath = "/opt/mmtty/mmtty.exe" }, Patience);
|
||||
|
||||
private static async Task StartAsync(MmttyEngine engine, FakeBridge bridge)
|
||||
{
|
||||
Task starting = engine.StartAsync();
|
||||
await WaitForAsync(() => bridge.Sent.Count > 0);
|
||||
bridge.Say("connected", "Ver1.70");
|
||||
await starting.WaitAsync(Patience);
|
||||
}
|
||||
|
||||
private static async Task WaitForAsync(Func<bool> ready)
|
||||
{
|
||||
DateTime giveUp = DateTime.UtcNow + Patience;
|
||||
while (!ready() && DateTime.UtcNow < giveUp)
|
||||
{
|
||||
await Task.Delay(5);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TheEngineIsOpenedWithTitlePortAndCommandLine()
|
||||
{
|
||||
using FakeBridge bridge = new();
|
||||
using MmttyEngine engine = Engine(bridge);
|
||||
|
||||
await StartAsync(engine, bridge);
|
||||
|
||||
(string verb, string[] fields) = BridgeLine.Read(bridge.Sent[0]);
|
||||
Assert.Equal("open", verb);
|
||||
Assert.Equal("RTTY Engine 1", fields[0]);
|
||||
Assert.Equal(@"""Z:\opt\mmtty\mmtty.exe"" -r -Z", fields[2]);
|
||||
Assert.True(engine.IsConnected);
|
||||
Assert.Equal("Ver1.70", engine.Version);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AnEngineThatFailsToStartIsStartedAgain()
|
||||
{
|
||||
using FakeBridge bridge = new();
|
||||
using MmttyEngine engine = Engine(bridge);
|
||||
Task starting = engine.StartAsync();
|
||||
await WaitForAsync(() => bridge.Sent.Count > 0);
|
||||
|
||||
bridge.Say("disconnected", "2");
|
||||
await WaitForAsync(() => bridge.Sent.Count > 1);
|
||||
bridge.Say("connected", "Ver1.70");
|
||||
await starting.WaitAsync(Patience);
|
||||
|
||||
Assert.Equal(2, bridge.Sent.Count);
|
||||
Assert.All(bridge.Sent, line => Assert.StartsWith("open\t", line));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AnEngineThatNeverStartsGivesUpRatherThanHanging()
|
||||
{
|
||||
using FakeBridge bridge = new();
|
||||
using MmttyEngine engine = Engine(bridge);
|
||||
Task starting = engine.StartAsync();
|
||||
|
||||
for (int tries = 0; tries < 12; tries++)
|
||||
{
|
||||
await WaitForAsync(() => bridge.Sent.Count > tries);
|
||||
bridge.Say("disconnected", "2");
|
||||
}
|
||||
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() => starting.WaitAsync(Patience));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DecodedCharactersArriveAsText()
|
||||
{
|
||||
using FakeBridge bridge = new();
|
||||
using MmttyEngine engine = Engine(bridge);
|
||||
List<string> heard = [];
|
||||
engine.Received += (_, text) => heard.Add(text);
|
||||
await StartAsync(engine, bridge);
|
||||
|
||||
bridge.Say("rx", "79");
|
||||
bridge.Say("rx", "77");
|
||||
await WaitForAsync(() => heard.Count == 2);
|
||||
|
||||
Assert.Equal("OM", string.Concat(heard));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TransmitIsReportedBothWays()
|
||||
{
|
||||
using FakeBridge bridge = new();
|
||||
using MmttyEngine engine = Engine(bridge);
|
||||
List<bool> changes = [];
|
||||
engine.TransmitChanged += (_, sending) => changes.Add(sending);
|
||||
await StartAsync(engine, bridge);
|
||||
|
||||
bridge.Say("tx", "1");
|
||||
await WaitForAsync(() => changes.Count == 1);
|
||||
Assert.True(engine.IsTransmitting);
|
||||
|
||||
bridge.Say("tx", "0");
|
||||
await WaitForAsync(() => changes.Count == 2);
|
||||
Assert.False(engine.IsTransmitting);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TuningKeepsTheShiftTheEngineReported()
|
||||
{
|
||||
using FakeBridge bridge = new();
|
||||
using MmttyEngine engine = Engine(bridge);
|
||||
await StartAsync(engine, bridge);
|
||||
bridge.Say("mark", "2125");
|
||||
bridge.Say("space", "2295");
|
||||
await WaitForAsync(() => engine.SpaceHertz == 2295);
|
||||
|
||||
await engine.TuneAsync(1500);
|
||||
|
||||
Assert.Equal("post\t9\t1500", bridge.Sent[^2]);
|
||||
Assert.Equal("post\t10\t1670", bridge.Sent[^1]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AbortDropsPtt()
|
||||
{
|
||||
using FakeBridge bridge = new();
|
||||
using MmttyEngine engine = Engine(bridge);
|
||||
await StartAsync(engine, bridge);
|
||||
|
||||
await engine.AbortAsync();
|
||||
|
||||
Assert.Equal("ptt\t0", bridge.Sent[^1]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ABridgeThatDiesWhileStartingFailsTheStart()
|
||||
{
|
||||
using FakeBridge bridge = new();
|
||||
using MmttyEngine engine = Engine(bridge);
|
||||
Task starting = engine.StartAsync();
|
||||
await WaitForAsync(() => bridge.Sent.Count > 0);
|
||||
|
||||
bridge.Stop("the bridge exited with code 1");
|
||||
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() => starting.WaitAsync(Patience));
|
||||
}
|
||||
}
|
||||
40
tests/Nonemm.Digital.Tests/MmttyOptionsTests.cs
Normal file
40
tests/Nonemm.Digital.Tests/MmttyOptionsTests.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Nonemm.Digital;
|
||||
|
||||
namespace Nonemm.Digital.Tests;
|
||||
|
||||
/// The command line N1MM builds, checked switch by switch.
|
||||
public class MmttyOptionsTests
|
||||
{
|
||||
[Fact]
|
||||
public void MmttyIsStartedTheWayN1mmStartsIt()
|
||||
{
|
||||
MmttyOptions options = new() { EnginePath = "/opt/mmtty/mmtty.exe" };
|
||||
|
||||
Assert.Equal(@"""C:\mmtty\mmtty.exe"" -r -Z", options.CommandLine(@"C:\mmtty\mmtty.exe"));
|
||||
Assert.Equal("RTTY Engine 1", options.Title);
|
||||
Assert.False(options.IsTwoTone);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AWindowThatIsNotOnTopAsksForIt()
|
||||
{
|
||||
MmttyOptions options = new()
|
||||
{
|
||||
EnginePath = "/opt/mmtty/mmtty.exe",
|
||||
Window = EngineWindow.Small,
|
||||
OnTop = false,
|
||||
};
|
||||
|
||||
Assert.Equal(@"""C:\m\mmtty.exe"" -t -a -Z", options.CommandLine(@"C:\m\mmtty.exe"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TwoToneTakesNoneOfMmttysSwitchesAndNamesItsOwnWindow()
|
||||
{
|
||||
MmttyOptions options = new() { EnginePath = "/opt/2tone/2Tone.exe", Number = 2 };
|
||||
|
||||
Assert.True(options.IsTwoTone);
|
||||
Assert.Equal(@"""C:\2Tone.exe"" -r", options.CommandLine(@"C:\2Tone.exe"));
|
||||
Assert.Equal("DI2 G3YYD 2Tone", options.WindowTitle);
|
||||
}
|
||||
}
|
||||
30
tests/Nonemm.Digital.Tests/MmttySettingsTests.cs
Normal file
30
tests/Nonemm.Digital.Tests/MmttySettingsTests.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Nonemm.Digital;
|
||||
|
||||
namespace Nonemm.Digital.Tests;
|
||||
|
||||
public class MmttySettingsTests
|
||||
{
|
||||
[Fact]
|
||||
public void TheSwitchWordIsBuiltFromWhatMmttyWroteDown()
|
||||
{
|
||||
string path = Path.GetTempFileName();
|
||||
File.WriteAllText(path, "[Sound]\nRev=1\n[Define]\nPTT=COM3\nAFC=1\nTxNet=0\nRev=1\n");
|
||||
|
||||
MmttySettings settings = MmttySettings.Read(path);
|
||||
File.Delete(path);
|
||||
|
||||
Assert.Equal("COM3", settings.PttPort);
|
||||
Assert.True(settings.IsAfcOn);
|
||||
Assert.False(settings.IsNetOn);
|
||||
Assert.Equal(MmttySettings.AfcBit | MmttySettings.ReverseBit, settings.Switches);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AnInstallationThatHasNotRunYetHasNoFile()
|
||||
{
|
||||
MmttySettings settings = MmttySettings.Read("/nowhere/Mmtty.INI");
|
||||
|
||||
Assert.Equal("", settings.PttPort);
|
||||
Assert.Equal(0, settings.Switches);
|
||||
}
|
||||
}
|
||||
25
tests/Nonemm.Digital.Tests/Nonemm.Digital.Tests.csproj
Normal file
25
tests/Nonemm.Digital.Tests/Nonemm.Digital.Tests.csproj
Normal file
@@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Nonemm.Digital\Nonemm.Digital.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
36
tests/Nonemm.Digital.Tests/WinePrefixSetupTests.cs
Normal file
36
tests/Nonemm.Digital.Tests/WinePrefixSetupTests.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Nonemm.Digital;
|
||||
|
||||
namespace Nonemm.Digital.Tests;
|
||||
|
||||
/// Where the control is put in each kind of prefix.
|
||||
public class WinePrefixSetupTests
|
||||
{
|
||||
[Fact]
|
||||
public void AThirtyTwoBitPrefixTakesTheControlInSystem32()
|
||||
{
|
||||
(string folder, string regsvr32) = WinePrefixSetup.Places(isSixtyFourBit: false);
|
||||
|
||||
Assert.Equal(@"C:\windows\system32", folder);
|
||||
Assert.Equal(@"C:\windows\system32\regsvr32.exe", regsvr32);
|
||||
}
|
||||
|
||||
/// The 64-bit regsvr32 cannot load a 32-bit control, so a 64-bit prefix is
|
||||
/// registered with the one in syswow64.
|
||||
[Fact]
|
||||
public void ASixtyFourBitPrefixTakesItInSyswow64()
|
||||
{
|
||||
(string folder, string regsvr32) = WinePrefixSetup.Places(isSixtyFourBit: true);
|
||||
|
||||
Assert.Equal(@"C:\windows\syswow64", folder);
|
||||
Assert.Equal(@"C:\windows\syswow64\regsvr32.exe", regsvr32);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AControlThatIsNotThereIsSaidSo()
|
||||
{
|
||||
WinePrefixSetup setup = new("/nowhere");
|
||||
|
||||
await Assert.ThrowsAsync<FileNotFoundException>(
|
||||
() => setup.RegisterAsync("/nowhere/XMMT.ocx"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user