Skip to content

Commit

Permalink
Grr
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-dmxc committed May 9, 2024
1 parent a5ed037 commit 44bec40
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
12 changes: 3 additions & 9 deletions ArtNetSharp/Communication/AbstractInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Reflection.Emit;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
Expand Down Expand Up @@ -211,11 +210,7 @@ protected AbstractInstance()
};
_timerSendPoll.Elapsed += _timerSendPoll_Elapsed;

sendDMXThread = new Thread(sendAllArtDMX);
sendDMXThread.Name = "Send DMX Thread";
sendDMXThread.IsBackground = true;
sendDMXThread.Priority = ThreadPriority.AboveNormal;
sendDMXThread.Start();
Task.Run(sendAllArtDMX);

KnownRDMUIDs = knownRDMUIDs.Values.ToList().AsReadOnly();
}
Expand Down Expand Up @@ -500,7 +495,7 @@ public async Task sendArtDMX(IPv4Address ipAddress, PortAddress portAddress, byt
await TrySendPacket(artDMX, ipAddress);
}
Stopwatch sw = Stopwatch.StartNew();
private async void sendAllArtDMX()
private async Task sendAllArtDMX()
{
const double dmxRefreshTime = 1000 / 44.0; // Spec 1.4dh page 56
const double dmxKeepAliveTime = 800; // Spec 1.4dh page 53
Expand All @@ -509,7 +504,6 @@ private async void sendAllArtDMX()
if (this.IsDeactivated)
continue;

await Task.Delay(5);
try
{
var ports = RemoteClientsPorts.Where(port => port.OutputPortAddress.HasValue && !port.Timouted()).ToList();
Expand All @@ -521,6 +515,7 @@ private async void sendAllArtDMX()
if (sendDMXBuffer.TryGetValue(port.OutputPortAddress.Value, out DMXSendBag bag))
if ((bag.Updated && (DateTime.UtcNow - bag.LastSended).TotalMilliseconds >= dmxRefreshTime) || (DateTime.UtcNow - bag.LastSended).TotalMilliseconds >= dmxKeepAliveTime)
{
bag.LastSended = DateTime.UtcNow;
PortConfig config = portConfigs.FirstOrDefault(pc => PortAddress.Equals(pc.PortAddress, port.OutputPortAddress));
byte sourcePort = config?.PortNumber ?? 0;
await sendArtDMX(port, sourcePort, bag.Data, bag.GetSequence(), config?.ForceBroadcast ?? false);
Expand All @@ -532,7 +527,6 @@ private async void sendAllArtDMX()
await sendArtDMX(ip, config.PortAddress, sourcePort, bag.Data, bag.GetSequence());
sended++;
}
bag.LastSended = DateTime.UtcNow;
}
}
catch (Exception e) { Logger.LogError(e); }
Expand Down
4 changes: 2 additions & 2 deletions ArtNetTests/LoopTests/ControllerToControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ public async Task TestSendDMXTiming()
{
Assert.That(syncFlag, Is.True);
Assert.That(receivedFlag, Is.True);
Assert.That(syncRate.Average(), Is.InRange(30, 60));
Assert.That(refreshRate.Average(), Is.InRange(30, 60));
Assert.That(syncRate.Average(), Is.InRange(44, 60));
Assert.That(refreshRate.Average(), Is.InRange(44, 60));
});
}
}
Expand Down

0 comments on commit 44bec40

Please sign in to comment.