Skip to content

Commit

Permalink
Merge pull request #114 from krusta4711/krusta4711-patch-xml-attribut…
Browse files Browse the repository at this point in the history
…e-se

set SE attribute
  • Loading branch information
zivillian authored Aug 10, 2024
2 parents 9a21b9a + 397674f commit 50b63d9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Buildlog-*\.txt
LaunchSettings.json

.vs/
.vscode
Nuget/
packages/

Expand Down
9 changes: 9 additions & 0 deletions src/ism7mqtt/ISM7/Ism7Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class Ism7Client
private int _nextBundleId = 0;
private short _lastKeepAlive = 0;
private Stream _sslStream;
private int _nextSequenceId = 1;

public int Interval { get; set; }

Expand Down Expand Up @@ -246,6 +247,7 @@ private async Task SubscribeAsync(string busAddress, CancellationToken cancellat
{
infoRead.BusAddress = busAddress;
infoRead.Intervall = Interval;
infoRead.Seq = NextSequenceId();
}
await SendAsync(new TelegramBundleReq
{
Expand Down Expand Up @@ -289,6 +291,7 @@ private async Task LoadInitialValuesAsync(CancellationToken cancellationToken)
foreach (var infoRead in infoReads)
{
infoRead.BusAddress = busAddress;
infoRead.Seq = NextSequenceId();
}
await SendAsync(new TelegramBundleReq
{
Expand Down Expand Up @@ -378,6 +381,12 @@ private string NextBundleId()
return id.ToString();
}

private string NextSequenceId()
{
var id = Interlocked.Increment(ref _nextSequenceId);
return $"A;{id}";
}

private IResponse Deserialize(PayloadType type, Stream data)
{
switch (type)
Expand Down
7 changes: 7 additions & 0 deletions src/ism7mqtt/ISM7/Protocol/Utf8StringWriter .cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System.IO;
using System.Text;

public sealed class Utf8StringWriter : StringWriter
{
public override Encoding Encoding => Encoding.UTF8;
}
2 changes: 1 addition & 1 deletion src/ism7mqtt/ISM7/Protocol/XmlPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class XmlPayload : IPayload

public byte[] Serialize()
{
using var sw = new StringWriter();
using var sw = new Utf8StringWriter();
var xmlWriter = XmlWriter.Create(sw, new XmlWriterSettings {Indent = false});

var serializer = _serializers.GetOrAdd(GetType(), x => new XmlSerializer(x));
Expand Down

0 comments on commit 50b63d9

Please sign in to comment.