Skip to content

Commit

Permalink
skip inforead for NumericConverter16Template without a TelegramNr
Browse files Browse the repository at this point in the history
  • Loading branch information
zivillian committed Aug 25, 2024
1 parent 69cde0e commit 90a9f42
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/ism7mqtt/ISM7/Xml/BM2DateConverterTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ public override JsonValue GetValue()

public override IEnumerable<InfoWrite> GetWrite(string value)
{
if (!TelegramNr.HasValue) yield break;
var date = DateOnly.Parse(value);
var bytes = date.Day - 1;
bytes |= (date.Month - 1) << 5;
bytes |= (date.Year - 2000) << 9;
var low = (byte)(bytes & 0xff);
var high = (byte)(bytes >> 8);
yield return new InfoWrite{InfoNumber = TelegramNr, DBLow = $"0x{low:X2}", DBHigh = $"0x{high:X2}"};
yield return new InfoWrite{InfoNumber = TelegramNr.Value, DBLow = $"0x{low:X2}", DBHigh = $"0x{high:X2}"};
}

public override ConverterTemplateBase Clone()
Expand Down
3 changes: 2 additions & 1 deletion src/ism7mqtt/ISM7/Xml/BM2TimeConverterTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ public override JsonValue GetValue()

public override IEnumerable<InfoWrite> GetWrite(string value)
{
if (!TelegramNr.HasValue) yield break;
var time = TimeSpan.Parse(value);
var high = time.Hours;
var low = time.Minutes;
yield return new InfoWrite{InfoNumber = TelegramNr, DBLow = $"0x{low:X2}", DBHigh = $"0x{high:X2}"};
yield return new InfoWrite{InfoNumber = TelegramNr.Value, DBLow = $"0x{low:X2}", DBHigh = $"0x{high:X2}"};
}

public override ConverterTemplateBase Clone()
Expand Down
3 changes: 2 additions & 1 deletion src/ism7mqtt/ISM7/Xml/NumericConverter16Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public override JsonValue GetValue()

public override IEnumerable<InfoWrite> GetWrite(string value)
{
if (!TelegramNr.HasValue) yield break;
ushort data;
switch (Type)
{
Expand Down Expand Up @@ -94,7 +95,7 @@ public override IEnumerable<InfoWrite> GetWrite(string value)
default:
throw new NotImplementedException($"type '{Type}' for CTID '{CTID}' is not yet implemented");
}
yield return new InfoWrite{InfoNumber = TelegramNr, DBLow = $"0x{(data & 0xff):X2}", DBHigh = $"0x{(data >> 8):X2}"};
yield return new InfoWrite{InfoNumber = TelegramNr.Value, DBLow = $"0x{(data & 0xff):X2}", DBHigh = $"0x{(data >> 8):X2}"};
}

public override ConverterTemplateBase Clone()
Expand Down
16 changes: 10 additions & 6 deletions src/ism7mqtt/ISM7/Xml/SingleTelegramConverterTemplateBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ namespace ism7mqtt.ISM7.Xml
public abstract class SingleTelegramConverterTemplateBase : ConverterTemplateBase
{
[XmlElement("TelegramNr")]
public ushort TelegramNr { get; set; }
public ushort? TelegramNr { get; set; }

public override IEnumerable<InfoRead> InfoReads => new[]
public override IEnumerable<InfoRead> InfoReads
{
new InfoRead
get
{
InfoNumber = TelegramNr,
ServiceNumber = ServiceReadNumber ?? -1
if (!TelegramNr.HasValue) yield break;
yield return new InfoRead
{
InfoNumber = TelegramNr.Value,
ServiceNumber = ServiceReadNumber ?? -1
};
}
};
}

public override void AddTelegram(ushort telegram, byte low, byte high)
{
Expand Down

0 comments on commit 90a9f42

Please sign in to comment.