diff --git a/BACnet.csproj b/BACnet.csproj index 1d16323..df0694e 100644 --- a/BACnet.csproj +++ b/BACnet.csproj @@ -1,189 +1,41 @@ - - + - Debug - AnyCPU - 8.0.30703 - 2.0 - {66832876-01FC-4B7C-8D92-54195773FABF} - Library - Properties + net40;net462;netstandard2.0; + true + Ela-compil sp. z o. o. + BACnet + Morten Kvistgaard, Ela-compil + Copyright (c) 2019 Jakub Bartkowiak, MIT License + fce4c8e3-0d3a-4d90-9c26-349177129433 + https://github.com/ela-compil/BACnet + https://raw.githubusercontent.com/ela-compil/BACnet/master/logo.png + BACnet protocol library for .NET System.IO.BACnet - BACnet - v4.0 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - latest - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - latest + 7.3 + BACnet protocol library for .NET - - $(SolutionDir)\packages\Common.Logging.3.4.1\lib\net40\Common.Logging.dll - - - $(SolutionDir)\packages\Common.Logging.Core.3.4.1\lib\net40\Common.Logging.Core.dll - - - $(SolutionDir)\packages\PacketDotNet.0.13.0\lib\net\PacketDotNet.dll - - - $(SolutionDir)\packages\SharpPcap.4.2.0\lib\net\SharpPcap.dll - - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - + + + + + + + + + + + - - - \ No newline at end of file diff --git a/BACnet.nuspec b/BACnet.nuspec deleted file mode 100644 index 3e1ba31..0000000 --- a/BACnet.nuspec +++ /dev/null @@ -1,14 +0,0 @@ - - - - BACnet - $version$ - BACnet - Jakub Brtkowiak, Ela-compil - https://github.com/ela-compil/BACnet - https://raw.githubusercontent.com/ela-compil/BACnet/master/logo.png - BACnet protocol library for .NET - Copyright (c) 2017 Jakub Bartkowiak, MIT License - bacnet scada bvlc mstp - - \ No newline at end of file diff --git a/BacnetAsyncResult.cs b/BacnetAsyncResult.cs index 10c8cb3..1087bac 100644 --- a/BacnetAsyncResult.cs +++ b/BacnetAsyncResult.cs @@ -11,7 +11,7 @@ public class BacnetAsyncResult : IAsyncResult, IDisposable private readonly int _transmitLength; private readonly bool _waitForTransmit; private readonly TimeSpan _transmitTimeout; - private ManualResetEvent _waitHandle; + private ManualResetEvent _waitHandle = new ManualResetEvent(false); public bool Segmented { get; private set; } public byte[] Result { get; private set; } @@ -48,7 +48,6 @@ public BacnetAsyncResult(BacnetClient comm, BacnetAddress adr, byte invokeId, _comm.OnReject += OnReject; _comm.OnSimpleAck += OnSimpleAck; _comm.OnSegment += OnSegment; - _waitHandle = new ManualResetEvent(false); } public BacnetAsyncResult Send() diff --git a/Base/BacnetAddress.cs b/Base/BacnetAddress.cs index 6eac750..ffa6487 100644 --- a/Base/BacnetAddress.cs +++ b/Base/BacnetAddress.cs @@ -15,6 +15,10 @@ public class BacnetAddress : ASN1.IEncode // Modif FC public BacnetAddress RoutedSource = null; + public BacnetAddress() + { + } + public BacnetAddress(BacnetAddressTypes addressType, ushort network = 0, byte[] address = null) { type = addressType; diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs deleted file mode 100644 index 8f69c57..0000000 --- a/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("BACnet")] -[assembly: AssemblyDescription("BACnet protocol library for .NET")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Ela-compil sp. z o. o.")] -[assembly: AssemblyProduct("BACnet")] -[assembly: AssemblyCopyright("Copyright (c) 2017 Jakub Bartkowiak, MIT License")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("fce4c8e3-0d3a-4d90-9c26-349177129433")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Serialize/ASN1.cs b/Serialize/ASN1.cs index d67e94e..dc323d6 100644 --- a/Serialize/ASN1.cs +++ b/Serialize/ASN1.cs @@ -213,7 +213,7 @@ significant bit of the second octet is 1. */ buffer.Add((byte)(sbyte)value); else if (value >= -32768 && value < 32768) encode_signed16(buffer, (short)value); - else if (value > -8388608 && value < 8388608) + else if (value >= -8388608 && value < 8388608) encode_signed24(buffer, value); else encode_signed32(buffer, value); @@ -1176,6 +1176,7 @@ public static int decode_signed32(byte[] buffer, int offset, out int value) public static int decode_signed24(byte[] buffer, int offset, out int value) { value = (buffer[offset + 0] << 16) & 0x00ff0000; + value = (value & 0x80_00_00) != 0 ? /*2's complement*/ value | (0xff << 24) : value; value |= (buffer[offset + 1] << 8) & 0x0000ff00; value |= buffer[offset + 2] & 0x000000ff; return 3; @@ -1983,7 +1984,7 @@ public static int bacapp_decode_context_application_data(BacnetAddress address, { tagLen = decode_device_obj_property_ref(buffer, offset, maxOffset, out var v); if (tagLen < 0) return -1; - value.Tag = BacnetApplicationTags.BACNET_APPLICATION_TAG_OBJECT_PROPERTY_REFERENCE; + value.Tag = BacnetApplicationTags.BACNET_APPLICATION_TAG_DEVICE_OBJECT_PROPERTY_REFERENCE; value.Value = v; return tagLen; } diff --git a/Tests/BACnet.Tests.csproj b/Tests/BACnet.Tests.csproj index c194ae9..ff0c37d 100644 --- a/Tests/BACnet.Tests.csproj +++ b/Tests/BACnet.Tests.csproj @@ -21,6 +21,7 @@ DEBUG;TRACE prompt 4 + 7.3 pdbonly @@ -29,16 +30,11 @@ TRACE prompt 4 + 7.3 - - ..\packages\NUnit.3.9.0\lib\net40\nunit.framework.dll - - - ..\packages\System.ValueTuple.4.4.0\lib\portable-net40+sl4+win8+wp8\System.ValueTuple.dll - @@ -51,14 +47,19 @@ - - - {66832876-01FC-4B7C-8D92-54195773FABF} BACnet + + + 3.9.0 + + + 4.4.0 + + \ No newline at end of file diff --git a/Tests/Properties/AssemblyInfo.cs b/Tests/Properties/AssemblyInfo.cs index aa8c723..302d5b0 100644 --- a/Tests/Properties/AssemblyInfo.cs +++ b/Tests/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("BACnet.Tests")] -[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyCopyright("Copyright © 2019")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/Tests/Serialize/ASN1Tests.cs b/Tests/Serialize/ASN1Tests.cs index c9c18bc..399873c 100644 --- a/Tests/Serialize/ASN1Tests.cs +++ b/Tests/Serialize/ASN1Tests.cs @@ -6,6 +6,9 @@ namespace System.IO.BACnet.Tests.Serialize [TestFixture] public class ASN1Tests { + public const int INT24_MAX_VALUE = 8_388_607; + public const int INT24_MIN_VALUE = -8_388_608; + [TestCase("2018-02-26", 1)] [TestCase("2018-02-27", 2)] [TestCase("2018-02-28", 3)] @@ -25,5 +28,35 @@ public void should_encode_dayofweek_according_to_standard(DateTime value, byte e Assert.That(buffer.GetLength(), Is.EqualTo(4)); Assert.That(buffer.buffer[3], Is.EqualTo(expectedDayOfWeek)); } + + [TestCase(new byte[] { 0x00, 0x00, 0x00 }, ExpectedResult = 0)] + [TestCase(new byte[] { 0x00, 0x00, 0x01 }, ExpectedResult = 1)] + [TestCase(new byte[] { 0xFF, 0xFF, 0xFF }, ExpectedResult = -1)] + [TestCase(new byte[] { 0x7F, 0xFF, 0xFF }, ExpectedResult = INT24_MAX_VALUE)] + [TestCase(new byte[] { 0x80, 0x00, 0x00 }, ExpectedResult = INT24_MIN_VALUE)] + public int should_decode_signed24_value(byte[] buffer) + { + // act + ASN1.decode_signed24(buffer, 0, out var value); + return value; + } + + [TestCase(sbyte.MinValue, ExpectedResult = new byte[] { 0x80 })] + [TestCase(sbyte.MaxValue, ExpectedResult = new byte[] { 0x7F })] + [TestCase(short.MinValue, ExpectedResult = new byte[] { 0x80, 0x00 })] + [TestCase(short.MaxValue, ExpectedResult = new byte[] { 0x7F, 0xFF })] + [TestCase(INT24_MIN_VALUE, ExpectedResult = new byte[] { 0x80, 0x00, 0x00 })] + [TestCase(INT24_MAX_VALUE, ExpectedResult = new byte[] { 0x7F, 0xFF, 0xFF })] + [TestCase(int.MinValue, ExpectedResult = new byte[] { 0x80, 0x00, 0x00, 0x00 })] + [TestCase(int.MaxValue, ExpectedResult = new byte[] { 0x7F, 0xFF, 0xFF, 0xFF })] + public byte[] should_encode_signed_value(int value) + { + // arrange + var buffer = new EncodeBuffer(); + + // act + ASN1.encode_bacnet_signed(buffer, value); + return buffer.ToArray(); + } } } diff --git a/Tests/packages.config b/Tests/packages.config deleted file mode 100644 index 2e6209b..0000000 --- a/Tests/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/packages.config b/packages.config deleted file mode 100644 index 786375e..0000000 --- a/packages.config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file