1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-12 17:48:31 +00:00
RGB.NET/RGB.NET.Devices.DMX/E131/E131DeviceInfo.cs

86 lines
2.2 KiB
C#

using System;
using RGB.NET.Core;
namespace RGB.NET.Devices.DMX.E131
{
/// <inheritdoc />
/// <summary>
/// Represents device information for a <see cref="E131Device"/> />.
/// </summary>
public class E131DeviceInfo : IRGBDeviceInfo
{
#region Constants
/// <summary>
/// The length of the CID;
/// </summary>
// ReSharper disable once MemberCanBePrivate.Global
public const int CID_LENGTH = 16;
#endregion
#region Properties & Fields
/// <inheritdoc />
public RGBDeviceType DeviceType { get; }
/// <inheritdoc />
public string DeviceName { get; }
/// <inheritdoc />
public string Manufacturer { get; }
/// <inheritdoc />
public string Model { get; }
public object? LayoutMetadata { get; set; }
/// <summary>
/// The hostname of the device.
/// </summary>
public string Hostname { get; }
/// <summary>
/// The port of the device.
/// </summary>
public int Port { get; }
/// <summary>
/// The CID used to identify against the device.
/// </summary>
public byte[] CID { get; }
/// <summary>
/// The Universe this device belongs to.
/// </summary>
public short Universe { get; }
#endregion
#region Constructors
internal E131DeviceInfo(E131DMXDeviceDefinition deviceDefinition)
{
this.DeviceType = deviceDefinition.DeviceType;
this.Manufacturer = deviceDefinition.Manufacturer;
this.Model = deviceDefinition.Model;
this.Hostname = deviceDefinition.Hostname;
this.Port = deviceDefinition.Port;
this.Universe = deviceDefinition.Universe;
byte[]? cid = deviceDefinition.CID;
if ((CID == null) || (CID.Length != CID_LENGTH))
{
CID = new byte[CID_LENGTH];
new Random().NextBytes(CID);
}
CID = cid!;
DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model);
}
#endregion
}
}