Skip to content

Commit

Permalink
Merge pull request #7 from space928/dev-thomas
Browse files Browse the repository at this point in the history
Bugfixes:
  • Loading branch information
space928 authored Jul 19, 2024
2 parents 7c8f9c5 + a909d54 commit 8173d33
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 78 deletions.
4 changes: 4 additions & 0 deletions WirelessMicSuiteServer/IWirelessMicReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ public struct RFScanData
/// The current state of the RF scan operation.
/// </summary>
public Status State { get; internal set; }
/// <summary>
/// The error message related to the state of the RF scan operation.
/// </summary>
public string? StatusMessage { get; internal set; }

/// <summary>
/// An RF spectrum sample.
Expand Down
5 changes: 3 additions & 2 deletions WirelessMicSuiteServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static void Main(string[] args)

WirelessMicManager micManager = new([
new ShureUHFRManager() { PollingPeriodMS = meterInterval },
new SennheiserSSCManager() { PollingPeriodMS = meterInterval }
new SennheiserSSCManager((string?)cli.ParsedArgs.GetValueOrDefault("--nic-address")) { PollingPeriodMS = meterInterval }
]);
WebSocketAPIManager wsAPIManager = new(micManager, meterInterval);
if (cli.ParsedArgs.ContainsKey("--meters"))
Expand All @@ -45,7 +45,8 @@ private static CommandLineOptions CreateCommandLineArgs(string[] args)
return new CommandLineOptions([
new("--meters", "-m", help: "Displays ASCII-art meters in the terminal for the connected wireless mics. Don't use this in production."),
new("--meter-interval", "-i", argType: CommandLineArgType.Uint, defaultValue: 50u, help:"Sets the interval at which metering information should be polled from the wireless receivers. This is specified in milli-seconds."),
new("--save-dir", "-s", argType: CommandLineArgType.String, defaultValue: "save", help:"Specifies a directory to save.")
new("--save-dir", "-s", argType: CommandLineArgType.String, defaultValue: "save", help:"Specifies a directory to save."),
new("--nic-address", "-a", argType: CommandLineArgType.String, defaultValue: null, help:"Specifies the IP address of the network adapter to use.")
], args);
}

Expand Down
17 changes: 14 additions & 3 deletions WirelessMicSuiteServer/SennheiserSSC/MDNSClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class MDNSClient : IDisposable

public event Action<MDNSMessage>? OnMDNSMessage;

public MDNSClient()
public MDNSClient(string? preferredIp = null)
{
cancellationTokenSource = new();
cancellationToken = cancellationTokenSource.Token;
Expand All @@ -50,11 +50,22 @@ public MDNSClient()
Log("List network interfaces: ");
List<IPAddress> addresses = [];
IPAddress? addr = null;
IPAddress? prefferedIpAddr = null;
if (!string.IsNullOrEmpty(preferredIp))
if (!IPAddress.TryParse(preferredIp, out prefferedIpAddr))
Log($"Couldn't parse '{preferredIp}' as an IP address!", LogSeverity.Warning);
foreach (var nic in NetworkInterface.GetAllNetworkInterfaces())
{
var nicAddr = nic.GetIPProperties().UnicastAddresses.Select(x => x.Address);
var ipProps = nic.GetIPProperties();
var nicAddr = ipProps.UnicastAddresses.Select(x => x.Address);
addresses.AddRange(nicAddr);
if (nicAddr.FirstOrDefault(x => x.AddressFamily == AddressFamily.InterNetwork) is IPAddress naddr)
if (prefferedIpAddr != null && nicAddr.Contains(prefferedIpAddr))
{
addr = prefferedIpAddr;
break;
}
if (nicAddr.FirstOrDefault(x => x.AddressFamily == AddressFamily.InterNetwork) is IPAddress naddr
&& ipProps.GatewayAddresses.Count > 0)
addr ??= naddr;
Log($"\t{nic.Name}: {string.Join(", ", nicAddr)}");
}
Expand Down
4 changes: 2 additions & 2 deletions WirelessMicSuiteServer/SennheiserSSC/SennheiserSSCManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class SennheiserSSCManager : IWirelessMicReceiverManager
public int PollingPeriodMS { get; set; } = 100;
public ObservableCollection<IWirelessMicReceiver> Receivers { get; init; }

public SennheiserSSCManager()
public SennheiserSSCManager(string? preferredNicAddress)
{
Receivers = [];
receiversDict = [];
Expand All @@ -61,7 +61,7 @@ public SennheiserSSCManager()
socket.Bind(new IPEndPoint(IPAddress.Any, 0));
rxTask = Task.Run(RXTask);
txTask = Task.Run(TXTask);
mDNSClient = new MDNSClient();
mDNSClient = new MDNSClient(preferredNicAddress);
mDNSClient.OnMDNSMessage += OnMDNSMessage;
discoveryTask = new Timer(_ =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class SennheiserSSCWirelessMic : IWirelessMic
private float? batteryLevel;

private bool isTXConnected = false;
private ulong? lastFrequency;
private bool isCollectingRFSamples;
private Task<RFScanData>? rfScanInProgress;
private MeteringData? lastMeterData;
Expand Down Expand Up @@ -184,6 +185,7 @@ public Task<RFScanData> StartRFScan(FrequencyRange range, ulong stepSize)
rfScanData.StepSize = stepSize;
rfScanData.Samples = [];
rfSamples.Clear();
lastFrequency = frequency;

isCollectingRFSamples = true;
stepSize = Math.Min((stepSize / 25000) * 25000, stepSize);
Expand All @@ -194,7 +196,7 @@ public Task<RFScanData> StartRFScan(FrequencyRange range, ulong stepSize)
for (ulong freq = range.StartFrequency; freq < range.EndFrequency + 1; freq += stepSize)
{
Frequency = freq;
Thread.Sleep(100);
Thread.Sleep(120);
rfScanData.Progress = ++i/(float)nsteps;
}
}
Expand All @@ -206,6 +208,7 @@ public Task<RFScanData> StartRFScan(FrequencyRange range, ulong stepSize)
rfScanData.Samples.Add(new(sample.Key, sample.Value.sample / sample.Value.n));
}

Frequency = lastFrequency;
rfScanData.State = RFScanData.Status.Completed;

return rfScanData;
Expand Down
Loading

0 comments on commit 8173d33

Please sign in to comment.