Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-dmxc committed Jan 27, 2024
1 parent e8ab8f9 commit 0422761
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 22 deletions.
12 changes: 10 additions & 2 deletions RDMSharp/ParameterWrapper/EManufacturer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ public enum EManufacturer : ushort
{
[Description("DMXControl-Projects e.V.")]
DMXControlProjects_eV = 0x02b0,
[Description("Martin Professional A/S")]
Martin_Professional_AS = 0x4D50,
[Description("SGM Technology For Lighting SPA")]
SGM_Technology_For_Lighting_SPA = 5347,
SGM_Technology_For_Lighting_SPA = 0x5347,
[Description("Wireless Solution Sweden AB")]
Wireless_Solution_Sweden_AB = 5753,
Wireless_Solution_Sweden_AB = 0x5753,
[Description("Robe Show Lighting s.r.o.")]
Robe_Show_Lighting_sro = 0x5253,
[Description("Swisson AG")]
Swisson_AG = 0x5777,
[Description("GLP German Light Products GmbH")]
GLP_German_Light_Products_GmbH = 0x676C,
[Description("Steinigke Showtechnic GmbH")]
Steinigke_Showtechnic_GmbH = 0x29aa,
}
Expand Down
46 changes: 28 additions & 18 deletions RDMSharp/RDM/AsyncRDMRequestHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -7,6 +8,7 @@ namespace RDMSharp
{
public class AsyncRDMRequestHelper
{
private static ILogger Logger = null;
private static Random random = new Random();
ConcurrentDictionary<RDMMessage, RDMMessage> buffer = new ConcurrentDictionary<RDMMessage, RDMMessage>();
Func<RDMMessage, Task> _sendMethode;
Expand All @@ -30,27 +32,35 @@ public bool ReceiveMethode(RDMMessage rdmMessage)

public async Task<RequestResult> RequestParameter(RDMMessage requerst)
{
buffer.TryAdd(requerst, null);
RDMMessage resopnse = null;
await _sendMethode.Invoke(requerst);
int count = 0;
do
try
{
buffer.TryGetValue(requerst, out resopnse);
await Task.Delay(10);
count++;
if (count % 300 == 299)
buffer.TryAdd(requerst, null);
RDMMessage resopnse = null;
await _sendMethode.Invoke(requerst);
int count = 0;
do
{
await Task.Delay(TimeSpan.FromTicks(random.Next(33,777)));
await _sendMethode.Invoke(requerst);
await Task.Delay(TimeSpan.FromTicks(random.Next(33, 777)));
buffer.TryGetValue(requerst, out resopnse);
await Task.Delay(10);
count++;
if (count % 300 == 299)
{
await Task.Delay(TimeSpan.FromTicks(random.Next(33, 777)));
await _sendMethode.Invoke(requerst);
await Task.Delay(TimeSpan.FromTicks(random.Next(33, 777)));
}
if (count == 3000)
return new RequestResult(requerst);
}
if (count == 3000)
return new RequestResult(requerst);
while (resopnse == null);
buffer.TryRemove(requerst, out resopnse);
return new RequestResult(requerst, resopnse);
}
while (resopnse == null);
buffer.TryRemove(requerst, out resopnse);
return new RequestResult(requerst, resopnse);
catch( Exception ex)
{
Logger?.LogError(string.Empty, ex);
}
return new RequestResult(requerst);
}
}
}
52 changes: 50 additions & 2 deletions RDMSharp/RDM/RDMMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace RDMSharp
{
public class RDMMessage
public class RDMMessage : IEquatable<RDMMessage>
{
private byte[] _parameterData = new byte[0];

Expand Down Expand Up @@ -185,6 +185,54 @@ public override string ToString()
//Add More if required

return b.ToString();
}
}

public override bool Equals(object obj)
{
return Equals(obj as RDMMessage);
}

public bool Equals(RDMMessage other)
{
return other is not null &&
MessageLength == other.MessageLength &&
SourceUID.Equals(other.SourceUID) &&
DestUID.Equals(other.DestUID) &&
TransactionCounter == other.TransactionCounter &&
PortID_or_Responsetype == other.PortID_or_Responsetype &&
MessageCounter == other.MessageCounter &&
SubDevice.Equals(other.SubDevice) &&
Command == other.Command &&
Parameter == other.Parameter &&
EqualityComparer<ERDM_NackReason[]>.Default.Equals(NackReason, other.NackReason) &&
PDL == other.PDL &&
EqualityComparer<byte[]>.Default.Equals(ParameterData, other.ParameterData) &&
Checksum == other.Checksum &&
ResponseType == other.ResponseType &&
IsAck == other.IsAck &&
EqualityComparer<object>.Default.Equals(Value, other.Value);
}

public override int GetHashCode()
{
int hashCode = 1518318531;
hashCode = hashCode * -1521134295 + MessageLength.GetHashCode();
hashCode = hashCode * -1521134295 + SourceUID.GetHashCode();
hashCode = hashCode * -1521134295 + DestUID.GetHashCode();
hashCode = hashCode * -1521134295 + TransactionCounter.GetHashCode();
hashCode = hashCode * -1521134295 + PortID_or_Responsetype.GetHashCode();
hashCode = hashCode * -1521134295 + MessageCounter.GetHashCode();
hashCode = hashCode * -1521134295 + SubDevice.GetHashCode();
hashCode = hashCode * -1521134295 + Command.GetHashCode();
hashCode = hashCode * -1521134295 + Parameter.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<ERDM_NackReason[]>.Default.GetHashCode(NackReason);
hashCode = hashCode * -1521134295 + PDL.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<byte[]>.Default.GetHashCode(ParameterData);
hashCode = hashCode * -1521134295 + Checksum.GetHashCode();
hashCode = hashCode * -1521134295 + ResponseType.GetHashCode();
hashCode = hashCode * -1521134295 + IsAck.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<object>.Default.GetHashCode(Value);
return hashCode;
}
}
}

0 comments on commit 0422761

Please sign in to comment.