61 lines
1.7 KiB
C#
61 lines
1.7 KiB
C#
|
using System;
|
|||
|
using System.ComponentModel;
|
|||
|
using System.Reflection;
|
|||
|
|
|||
|
namespace BlubbFish.Utils.IoT.Interfaces.Language {
|
|||
|
public abstract class Senml {
|
|||
|
#pragma warning disable IDE1006 // Benennungsstile
|
|||
|
public String n { get; }
|
|||
|
public String u { get; }
|
|||
|
public Int32 t { get; }
|
|||
|
#pragma warning restore IDE1006 // Benennungsstile
|
|||
|
|
|||
|
public enum Units {
|
|||
|
[Description("%")]
|
|||
|
Percent,
|
|||
|
[Description("count")]
|
|||
|
CounterValue,
|
|||
|
[Description("W")]
|
|||
|
Watt,
|
|||
|
[Description("J")]
|
|||
|
Joule,
|
|||
|
[Description("Cel")]
|
|||
|
Celsius
|
|||
|
}
|
|||
|
|
|||
|
public Senml(String name, Units unit) {
|
|||
|
this.n = name;
|
|||
|
this.u = this.GetEnumDescription(unit);
|
|||
|
this.t = 0;
|
|||
|
}
|
|||
|
|
|||
|
private String GetEnumDescription(Enum value) {
|
|||
|
FieldInfo fi = value.GetType().GetField(value.ToString());
|
|||
|
|
|||
|
DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
|||
|
|
|||
|
if (attributes != null && attributes.Length > 0) {
|
|||
|
return attributes[0].Description;
|
|||
|
} else {
|
|||
|
return value.ToString();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
public class SenmlBool : Senml {
|
|||
|
#pragma warning disable IDE1006 // Benennungsstile
|
|||
|
public Boolean bv { get; }
|
|||
|
#pragma warning restore IDE1006 // Benennungsstile
|
|||
|
public SenmlBool(String name, Units unit, Boolean level) : base(name, unit) {
|
|||
|
this.bv = level;
|
|||
|
}
|
|||
|
}
|
|||
|
public class SenmlDouble : Senml {
|
|||
|
#pragma warning disable IDE1006 // Benennungsstile
|
|||
|
public Double v { get; }
|
|||
|
#pragma warning restore IDE1006 // Benennungsstile
|
|||
|
public SenmlDouble(String name, Units unit, Double level) : base(name, unit) {
|
|||
|
this.v = level;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|