Skip to content

Commit

Permalink
Work on Generic Parameter
Browse files Browse the repository at this point in the history
Run Tests with a 500 RDM Device Grid  ^^
  • Loading branch information
patrick-dmxc committed Jan 27, 2024
1 parent 62a5d7a commit 589b150
Show file tree
Hide file tree
Showing 18 changed files with 391 additions and 9 deletions.
5 changes: 5 additions & 0 deletions RDMSharp/ParameterWrapper/AbstractRDMParameterWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -937,5 +937,10 @@ public override int GetHashCode()
{
return this.Parameter.GetHashCode();
}

public override string ToString()
{
return this.Name;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace RDMSharp.ParameterWrapper.Generic
{
public sealed class ASCIIParameterWrapper : AbstractGenericParameterWrapper<string, string>
{
public ASCIIParameterWrapper(in RDMParameterDescription parameterDescription) : base(parameterDescription)
{
}

protected override string getResponseParameterDataToValue(byte[] parameterData)
{
return Tools.DataToString(ref parameterData);
}

protected override byte[] getResponseValueToParameterData(string value)
{
return Tools.ValueToData(value);
}

protected override string setRequestParameterDataToValue(byte[] parameterData)
{
return Tools.DataToString(ref parameterData);
}

protected override byte[] setRequestValueToParameterData(string value)
{
return Tools.ValueToData(value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.ComponentModel;

namespace RDMSharp.ParameterWrapper.Generic
{
public abstract class AbstractGenericParameterWrapper<TGet, TSet> : AbstractRDMParameterWrapper<Empty, TGet, TSet, Empty>, IRDMGetParameterWrapperWithEmptyGetRequest
{
private readonly RDMParameterDescription parameterDescription;
public AbstractGenericParameterWrapper(in RDMParameterDescription parameterDescription) : base((ERDM_Parameter)parameterDescription.ParameterId)
{
this.parameterDescription = parameterDescription;
}
public sealed override string Name => this.parameterDescription.Description;
public sealed override string Description => null;
public Type GetResponseType => typeof(TGet);

public sealed override ERDM_CommandClass CommandClass => this.parameterDescription.CommandClass;

[EditorBrowsable(EditorBrowsableState.Never)]
protected sealed override byte[] getRequestValueToParameterData(Empty value)
{
throw new NotSupportedException();
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected sealed override Empty getRequestParameterDataToValue(byte[] parameterData)
{
throw new NotSupportedException();
}

[EditorBrowsable(EditorBrowsableState.Never)]
protected sealed override Empty setResponseParameterDataToValue(byte[] parameterData)
{
throw new NotSupportedException();
}

[EditorBrowsable(EditorBrowsableState.Never)]
protected sealed override byte[] setResponseValueToParameterData(Empty value)
{
throw new NotSupportedException();
}

public RDMMessage BuildGetRequestMessage()
{
return this.buildGetRequestMessage();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace RDMSharp.ParameterWrapper.Generic
{
public sealed class NotDefinedParameterWrapper : AbstractGenericParameterWrapper<byte[], byte[]>
{
public NotDefinedParameterWrapper(in RDMParameterDescription parameterDescription) : base(parameterDescription)
{
}
protected override byte[] getResponseParameterDataToValue(byte[] parameterData)
{
return parameterData;
}

protected override byte[] getResponseValueToParameterData(byte[] value)
{
return value;
}

protected override byte[] setRequestParameterDataToValue(byte[] parameterData)
{
return parameterData;
}

protected override byte[] setRequestValueToParameterData(byte[] value)
{
return value;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace RDMSharp.ParameterWrapper.Generic
{
public sealed class SignedByteParameterWrapper : AbstractGenericParameterWrapper<sbyte, sbyte>
{
public SignedByteParameterWrapper(in RDMParameterDescription parameterDescription) : base(parameterDescription)
{
}
protected override sbyte getResponseParameterDataToValue(byte[] parameterData)
{
return Tools.DataToSByte(ref parameterData);
}

protected override byte[] getResponseValueToParameterData(sbyte value)
{
return Tools.ValueToData(value);
}

protected override sbyte setRequestParameterDataToValue(byte[] parameterData)
{
return Tools.DataToSByte(ref parameterData);
}

protected override byte[] setRequestValueToParameterData(sbyte value)
{
return Tools.ValueToData(value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace RDMSharp.ParameterWrapper.Generic
{
public sealed class SignedDWordParameterWrapper : AbstractGenericParameterWrapper<int, int>
{
public SignedDWordParameterWrapper(in RDMParameterDescription parameterDescription) : base(parameterDescription)
{
}

protected override int getResponseParameterDataToValue(byte[] parameterData)
{
return Tools.DataToInt(ref parameterData);
}

protected override byte[] getResponseValueToParameterData(int value)
{
return Tools.ValueToData(value);
}

protected override int setRequestParameterDataToValue(byte[] parameterData)
{
return Tools.DataToInt(ref parameterData);
}

protected override byte[] setRequestValueToParameterData(int value)
{
return Tools.ValueToData(value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace RDMSharp.ParameterWrapper.Generic
{
public sealed class SignedWordParameterWrapper : AbstractGenericParameterWrapper<short, short>
{
public SignedWordParameterWrapper(in RDMParameterDescription parameterDescription) : base(parameterDescription)
{
}

protected override short getResponseParameterDataToValue(byte[] parameterData)
{
return Tools.DataToShort(ref parameterData);
}

protected override byte[] getResponseValueToParameterData(short value)
{
return Tools.ValueToData(value);
}

protected override short setRequestParameterDataToValue(byte[] parameterData)
{
return Tools.DataToShort(ref parameterData);
}

protected override byte[] setRequestValueToParameterData(short value)
{
return Tools.ValueToData(value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace RDMSharp.ParameterWrapper.Generic
{
public sealed class UnsignedByteParameterWrapper : AbstractGenericParameterWrapper<byte, byte>, IRDMGetParameterWrapperWithEmptyGetRequest
{
public UnsignedByteParameterWrapper(in RDMParameterDescription parameterDescription) : base(parameterDescription)
{
}
protected override byte getResponseParameterDataToValue(byte[] parameterData)
{
return Tools.DataToByte(ref parameterData);
}

protected override byte[] getResponseValueToParameterData(byte value)
{
return Tools.ValueToData(value);
}

protected override byte setRequestParameterDataToValue(byte[] parameterData)
{
return Tools.DataToByte(ref parameterData);
}

protected override byte[] setRequestValueToParameterData(byte value)
{
return Tools.ValueToData(value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace RDMSharp.ParameterWrapper.Generic
{
public sealed class UnsignedDWordParameterWrapper : AbstractGenericParameterWrapper<uint, uint>
{
public UnsignedDWordParameterWrapper(in RDMParameterDescription parameterDescription) : base(parameterDescription)
{
}
protected override uint getResponseParameterDataToValue(byte[] parameterData)
{
return Tools.DataToUInt(ref parameterData);
}

protected override byte[] getResponseValueToParameterData(uint value)
{
return Tools.ValueToData(value);
}

protected override uint setRequestParameterDataToValue(byte[] parameterData)
{
return Tools.DataToUInt(ref parameterData);
}

protected override byte[] setRequestValueToParameterData(uint value)
{
return Tools.ValueToData(value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace RDMSharp.ParameterWrapper.Generic
{
public sealed class UnsignedWordParameterWrapper : AbstractGenericParameterWrapper<ushort, ushort>
{
public UnsignedWordParameterWrapper(in RDMParameterDescription parameterDescription) : base(parameterDescription)
{
}


protected override ushort getResponseParameterDataToValue(byte[] parameterData)
{
return Tools.DataToUShort(ref parameterData);
}

protected override byte[] getResponseValueToParameterData(ushort value)
{
return Tools.ValueToData(value);
}

protected override ushort setRequestParameterDataToValue(byte[] parameterData)
{
return Tools.DataToUShort(ref parameterData);
}

protected override byte[] setRequestValueToParameterData(ushort value)
{
return Tools.ValueToData(value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public IRDMParameterWrapper GetRDMParameterWrapperByID(ERDM_Parameter parameter,

public void RegisterParameterWrapper(Type type)
{
if (type.GetConstructor(Type.EmptyTypes) == null)
return;
if (typeof(IRDMParameterWrapper).IsAssignableFrom(type))
this.parameterWrappers.Add((IRDMParameterWrapper)Activator.CreateInstance(type));
}
Expand Down
40 changes: 37 additions & 3 deletions RDMSharp/RDM/AbstractRDMDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,22 @@ private async Task processMessage(RDMMessage rdmMessage)
if (rdmMessage.Parameter != ERDM_Parameter.DEVICE_INFO && (this.DeviceModel?.SupportedBlueprintParameters.Contains(rdmMessage.Parameter) ?? false))
return;

if (rdmMessage.NackReason != null)
if (rdmMessage.NackReason.Length != 0)
return;

var pm = pmManager.GetRDMParameterWrapperByID(rdmMessage.Parameter);
object value = rdmMessage.Value;
object value = null;
try
{
value = rdmMessage.Value;
}
catch (Exception ex)
{
Logger.LogError(string.Empty, ex);
}
if (value == null)
return;
switch (pm)
{
case DeviceInfoParameterWrapper _deviceInfoParameterWrapper:
Expand Down Expand Up @@ -281,11 +295,20 @@ public async Task UpdateParameterValue(ERDM_Parameter parameterId)
}

var pm = pmManager.GetRDMParameterWrapperByID(parameterId);
if (!pm.CommandClass.HasFlag(ERDM_CommandClass.GET))
return;
if (pm == null && Enum.IsDefined(typeof(ERDM_Parameter), parameterId))
return;

if(pm==null)
pm = deviceModel.GetRDMParameterWrapperByID((ushort)parameterId);
if (pm == null)
{
Logger.LogDebug("Not Implemented Parameter");
return;
}

if (!pm.CommandClass.HasFlag(ERDM_CommandClass.GET))
return;

this.pendingParametersUpdateRequest.Add(parameterId);
try
{
Expand Down Expand Up @@ -329,6 +352,12 @@ public async Task UpdateParameterValue(ERDM_Parameter parameterId)
tasks.Add(processMessage(await requestParameter(@uintGetRequest.BuildGetRequestMessage(r))));

break;

case StatusMessageParameterWrapper statusMessageParameter:
tasks.Add(processMessage(await requestParameter(statusMessageParameter.BuildGetRequestMessage(ERDM_Status.ADVISORY))));
break;
default:
break;
}
await Task.WhenAny(Task.WhenAll(tasks), Task.Delay(TimeSpan.FromSeconds(10)));
}
Expand Down Expand Up @@ -503,5 +532,10 @@ protected virtual void OnDispose()
{

}

public override string ToString()
{
return $"[{UID}] {this.DeviceModel}";
}
}
}
Loading

0 comments on commit 589b150

Please sign in to comment.