Mirror a radio from another computer's broadcast data
Listen for Radio broadcast data from another Nonemm or N1MM computer and record its frequency, mode and split as this computer's own radio. No radio is controlled. The settings are in the Configure Radios dialog. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -47,6 +47,32 @@ public class BroadcastTests
|
||||
Assert.Equal("RUN-PC", root.Element("StationName")!.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_radio_message_is_read_back_in_hertz()
|
||||
{
|
||||
string xml = BroadcastMessages.Radio(
|
||||
new RadioReport(2, 14_025_500, 14_030_000, "USB", "OK1ABC", "OK1ABC", true, 2, true, 2, false, "", true),
|
||||
"RUN-PC");
|
||||
|
||||
RadioBroadcast? read = BroadcastMessages.ReadRadio(xml);
|
||||
|
||||
Assert.Equal("RUN-PC", read!.StationName);
|
||||
Assert.Equal(2, read.Radio.RadioNumber);
|
||||
Assert.Equal(14_025_500, read.Radio.Frequency);
|
||||
Assert.Equal(14_030_000, read.Radio.TransmitFrequency);
|
||||
Assert.Equal("USB", read.Radio.Mode);
|
||||
Assert.True(read.Radio.IsSplit);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("not xml")]
|
||||
[InlineData("<spot><dxcall>DL1ABC</dxcall></spot>")]
|
||||
[InlineData("<RadioInfo><RadioNr>1</RadioNr></RadioInfo>")]
|
||||
public void Anything_but_a_radio_message_is_passed_over(string text)
|
||||
{
|
||||
Assert.Null(BroadcastMessages.ReadRadio(text));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_deleted_spot_carries_no_comment_or_status()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
|
||||
namespace Nonemm.Network.Tests;
|
||||
|
||||
public class RadioMirrorTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task A_radio_message_sent_to_the_port_is_raised_and_other_data_is_not()
|
||||
{
|
||||
int port = FreePort();
|
||||
using RadioMirror mirror = new(port);
|
||||
TaskCompletionSource<RadioBroadcast> received = new();
|
||||
mirror.Received += (_, message) => received.TrySetResult(message);
|
||||
using UdpClient sender = new();
|
||||
IPEndPoint target = new(IPAddress.Loopback, port);
|
||||
|
||||
byte[] other = Encoding.UTF8.GetBytes("<spot><dxcall>DL1ABC</dxcall></spot>");
|
||||
await sender.SendAsync(other, target);
|
||||
byte[] radio = Encoding.UTF8.GetBytes(BroadcastMessages.Radio(
|
||||
new RadioReport(1, 7_012_300, 7_012_300, "CW", "OK1ABC", "OK1ABC", false, 1, false, 1, false, "", true),
|
||||
"RUN-PC"));
|
||||
await sender.SendAsync(radio, target);
|
||||
|
||||
RadioBroadcast message = await received.Task.WaitAsync(TimeSpan.FromSeconds(5));
|
||||
Assert.Equal("RUN-PC", message.StationName);
|
||||
Assert.Equal(7_012_300, message.Radio.Frequency);
|
||||
}
|
||||
|
||||
private static int FreePort()
|
||||
{
|
||||
using UdpClient probe = new(new IPEndPoint(IPAddress.Loopback, 0));
|
||||
return ((IPEndPoint)probe.Client.LocalEndPoint!).Port;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user