Skip to content

Commit

Permalink
fix for DPT 3 bit with control, version 1.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsilva committed Jun 28, 2015
1 parent 0595930 commit 113ac4c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 22 deletions.
46 changes: 35 additions & 11 deletions src/KNXLib/DPT/DataPoint3BitControl.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Globalization;
using System.Linq;
using System.Globalization;
using KNXLib.Log;

namespace KNXLib.DPT
Expand All @@ -9,14 +7,17 @@ internal sealed class DataPoint3BitControl : DataPoint
{
public override string[] Ids
{
get { return new[] { "3.008", "3.007" }; }
get
{
return new[] {"3.008", "3.007"};
}
}

public override object FromDataPoint(string data)
{
var dataConverted = new byte[data.Length];
for (var i = 0; i < data.Length; i++)
dataConverted[i] = (byte)data[i];
dataConverted[i] = (byte) data[i];

return FromDataPoint(dataConverted);
}
Expand All @@ -31,7 +32,22 @@ public override object FromDataPoint(byte[] data)
bool direction = (input >> 3) == 1;
int step = input & 0x07;

return direction ? step : (step * -1);
if (step != 0)
{
if (direction)
{
step = step*-1;
step = step + 8;
}
else
{
step = step*-1;
step = step + 8;
step = step*-1;
}
}

return step;
}

public override byte[] ToDataPoint(string value)
Expand All @@ -43,8 +59,8 @@ public override byte[] ToDataPoint(object val)
{
var dataPoint = new byte[1];
dataPoint[0] = 0x00;
int input = 0;

var input = 0;
if (val is int)
input = ((int) val);
else if (val is float)
Expand All @@ -69,17 +85,25 @@ public override byte[] ToDataPoint(object val)

var direction = 8; // binary 1000


if (input <= 0)
{
direction = 0;
input = input * -1;
input = input*-1;
input = input - 8;
input = input*-1;
}
else
{
input = input*-1;
input = input + 8;
}

int step = (input & 7);

dataPoint[0] = (byte)(step | direction);
dataPoint[0] = (byte) (step | direction);

return dataPoint;
}
}
}
}
2 changes: 1 addition & 1 deletion src/KNXLib/KNXLib.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<projectUrl>http://lifeemotions.github.io/knx.net/</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>Added datapoints 5.xxx and 6.xxx. Updated documentation. Fixed issues with 9.001 datapoint.</releaseNotes>
<releaseNotes>Bugfix for DPT 3 bit with control (3.007 and 3.008).</releaseNotes>
<copyright>Copyright 2012</copyright>
<tags>knx .net c#</tags>
</metadata>
Expand Down
6 changes: 3 additions & 3 deletions src/KNXLib/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.2")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyInformationalVersion("1.1.2")]
[assembly: AssemblyVersion("1.1.3")]
[assembly: AssemblyFileVersion("1.1.3.0")]
[assembly: AssemblyInformationalVersion("1.1.3")]
14 changes: 7 additions & 7 deletions tests/KNXLibTests/Unit/DataPoint/DataPoint3BitControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public void DataPoint3BitControlDimmingTest()
var incr4 = 4;
var incr4Bytes = new byte[] { 0x0C };
var incr1 = 1;
var incr1Bytes = new byte[] { 0x09 };
var incr1Bytes = new byte[] { 0x0F };
var stop = 0;
var stopBytes = new byte[] { 0x00 };
var decr3 = -3;
var decr3Bytes = new byte[] { 0x03 };
var decr3Bytes = new byte[] { 0x05 };
var decr7 = -7;
var decr7Bytes = new byte[] { 0x07 };
var decr7Bytes = new byte[] { 0x01 };

Assert.AreEqual(incr4, DataPointTranslator.Instance.FromDataPoint(dptType, incr4Bytes));
Assert.AreEqual(incr1, DataPointTranslator.Instance.FromDataPoint(dptType, incr1Bytes));
Expand All @@ -51,15 +51,15 @@ public void DataPoint3BitControlBlindsTest()
var dptType = "3.008";

var incr7 = 7;
var incr7Bytes = new byte[] { 0x0F };
var incr7Bytes = new byte[] { 0x09 };
var incr2 = 2;
var incr2Bytes = new byte[] { 0x0A };
var incr2Bytes = new byte[] { 0x0E };
var stop = 0;
var stopBytes = new byte[] { 0x00 };
var decr5 = -5;
var decr5Bytes = new byte[] { 0x05 };
var decr5Bytes = new byte[] { 0x03 };
var decr6 = -6;
var decr6Bytes = new byte[] { 0x06 };
var decr6Bytes = new byte[] { 0x02 };

Assert.AreEqual(incr7, DataPointTranslator.Instance.FromDataPoint(dptType, incr7Bytes));
Assert.AreEqual(incr2, DataPointTranslator.Instance.FromDataPoint(dptType, incr2Bytes));
Expand Down

0 comments on commit 113ac4c

Please sign in to comment.