Skip to content

Commit

Permalink
Minor improvements to Logging Malformed Packages by Netron Obsidian R…
Browse files Browse the repository at this point in the history
…DM10 Devices.

Make ArtDmx deserializer resilient against to short Package
Wrote Test for RDM10 shorter ArtDMX Packages
Improve Loopback detection.
Bump v0.0.31
  • Loading branch information
patrick-dmxc committed Jun 5, 2024
1 parent 6012691 commit 317bb93
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ArtNetSharp/ArtNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ private void ProcessReceivedData(UdpReceiveResult result)
}
return;
}
Logger.LogWarning($"Can't deserialize Data to ArtNet-Packet");
Logger.LogWarning($"Can't deserialize Data to ArtNet-Packet from {sourceIp}");
}
catch (ObjectDisposedException ed) { Logger.LogTrace(ed); }
catch (SocketException se) { Logger.LogTrace(se); }
Expand Down
2 changes: 1 addition & 1 deletion ArtNetSharp/ArtNetSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Version>0.0.30</Version>
<Version>0.0.31</Version>
<RepositoryUrl>https://github.com/DMXControl/ArtNetSharp</RepositoryUrl>
<PackageProjectUrl>$(RepositoryUrl)</PackageProjectUrl>
<PackageTags>RDM; ArtNet; E1.20; E1.33; E1.37-1; E1.37-2; E1.37-7</PackageTags>
Expand Down
3 changes: 1 addition & 2 deletions ArtNetSharp/Communication/AbstractInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,6 @@ private void processArtPollReply(ArtPollReply artPollReply, IPv4Address localIp,
&& MinorVersion == artPollReply.MinorVersion
&& OEMProductCode == artPollReply.OemCode
&& ESTAManufacturerCode == artPollReply.ManufacturerCode
&& IPv4Address.Equals(sourceIp, localIp)
&& IPv4Address.Equals(artPollReply.OwnIp, localIp)
&& string.Equals(artPollReply.ShortName, ShortName)
&& string.Equals(artPollReply.LongName, Name))
Expand Down Expand Up @@ -1276,7 +1275,7 @@ private async void TimerSendPoll_Elapsed(object sender, EventArgs e)
if (remoteClients.TryRemove(rc.Key, out RemoteClient removed))
remoteClientsTimeouted.TryAdd(removed.ID, removed);
else
Logger.LogWarning($"Can't remove RemoteClient from ConcurrentDictionary");
Logger.LogWarning($"Can't remove RemoteClient({removed.ID}) from ConcurrentDictionary");

if (removed != null)
{
Expand Down
2 changes: 1 addition & 1 deletion ArtNetSharp/Communication/RemoteClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ private async void OnSendArtPoll(object sender, EventArgs e)
foreach (var port in timoutedPorts)
{
if (!ports.TryRemove(port.Key, out _))
Logger.LogWarning($"Can't remove RemoteClientPort from ConcurrentDictionary");
Logger.LogWarning($"Can't remove RemoteClientPort ({port.Key}) from ConcurrentDictionary");
_ = Task.Run(() => PortTimedOut?.InvokeFailSafe(this, port));
}
}
Expand Down
1 change: 1 addition & 0 deletions ArtNetSharp/Messages/ArtDMX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public ArtDMX(in byte[] packet) : base(packet)
ushort length = (ushort)((packet[16] << 8) | packet[17]);
if (length <= 512)
{
length = (ushort)(Math.Max(0, Math.Min(length, packet.Length - 18)));
Data = new byte[length];
Array.Copy(packet, 18, Data, 0, length);
return;
Expand Down
9 changes: 9 additions & 0 deletions ArtNetTests/PackagesSerializeDeserialize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public void Tools_TryDeserializePacket()
data = data.Take(22).ToArray();
Assert.That(ArtNetSharp.Tools.TryDeserializePacket(data, out _), Is.False);
}
[Test]
public void Tools_TryDeserializePacketFromRaw()
{
byte[]? data = new byte[] { 0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x50, 0x00, 0x0e, 0x1a, 0x01, 0x01, 0x00, 0x02, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x4d, 0x14, 0xff, 0xff, 0xff, 0x33, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x4d, 0x14, 0xff, 0xff, 0xff, 0x33, 0x80, 0x00, 0x00, 0x59, 0x14, 0xff, 0xff, 0xff, 0x33, 0x80, 0x00, 0x00, 0x1c, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x1c, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x59, 0x14, 0xff, 0xff, 0xff };
Assert.That(ArtNetSharp.Tools.TryDeserializePacket(data, out AbstractArtPacketCore packet), Is.True);

data = new byte[] { 0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x50, 0x00, 0x0e, 0x1a, 0x01, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x50, 0x6f, 0x72, 0x74, 0x20, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x4d, 0x14, 0xff, 0xff, 0xff, 0x33, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x02, 0x00, 0x01, 0x40, 0xff, 0xaa, 0x80, 0x80, 0x00, 0x02, 0x14, 0x00, 0xff, 0xff, 0xaa, 0x01, 0x00, 0x00, 0x02, 0x01, 0xff, 0xff, 0xff, 0x64, 0x80, 0x00, 0x00, 0x4d, 0x14, 0xff, 0xff, 0xff, 0x33, 0x80, 0x00, 0x00, 0x59, 0x14, 0xff, 0xff, 0x02, 0x33, 0xc0, 0x00, 0x00, 0x1c, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x1c, 0x14, 0xff, 0xff, 0xff, 0xaa, 0x80, 0x00, 0x00, 0x59, 0x14, 0xff, 0xff, 0xff };
Assert.That(ArtNetSharp.Tools.TryDeserializePacket(data, out packet), Is.True);
}

[Test]
public void ArtSync()
Expand Down

0 comments on commit 317bb93

Please sign in to comment.