diff --git a/.gitignore b/.gitignore index c08ee2f..94ec162 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ Buildlog-*\.txt LaunchSettings.json .vs/ +.vscode Nuget/ packages/ diff --git a/src/ism7mqtt/ISM7/Ism7Client.cs b/src/ism7mqtt/ISM7/Ism7Client.cs index 4963173..25c2b60 100644 --- a/src/ism7mqtt/ISM7/Ism7Client.cs +++ b/src/ism7mqtt/ISM7/Ism7Client.cs @@ -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; } @@ -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 { @@ -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 { @@ -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) diff --git a/src/ism7mqtt/ISM7/Protocol/Utf8StringWriter .cs b/src/ism7mqtt/ISM7/Protocol/Utf8StringWriter .cs new file mode 100644 index 0000000..54f3db4 --- /dev/null +++ b/src/ism7mqtt/ISM7/Protocol/Utf8StringWriter .cs @@ -0,0 +1,7 @@ +using System.IO; +using System.Text; + +public sealed class Utf8StringWriter : StringWriter +{ + public override Encoding Encoding => Encoding.UTF8; +} \ No newline at end of file diff --git a/src/ism7mqtt/ISM7/Protocol/XmlPayload.cs b/src/ism7mqtt/ISM7/Protocol/XmlPayload.cs index c7e9974..3d628c0 100644 --- a/src/ism7mqtt/ISM7/Protocol/XmlPayload.cs +++ b/src/ism7mqtt/ISM7/Protocol/XmlPayload.cs @@ -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));