Skip to content

Commit

Permalink
fixing 5.001 feedback translation and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsilva committed May 16, 2017
1 parent 680539c commit e5d9b9d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/KNXLib/DPT/DataPoint8BitNoSignScaledScaling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ public override object FromDataPoint(string data)

public override object FromDataPoint(byte[] data)
{
if (data == null || data.Length != 1)
if (data == null)
return 0;
if (data.Length == 2)
data = data.Skip(1).ToArray();
else if (data.Length != 1)
return 0;

var value = (int) data[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ public void DataPoint8BitNoSignScaledScalingTest()
string dptType = "5.001";

int scale0 = 0;
byte[] scale0Bytes = {0x00};
byte[] scale0Bytes = { 0x00, 0x00 };
int scale20 = 20;
byte[] scale20Bytes = {0x33};
byte[] scale20Bytes = { 0x00, 0x33 };
int scale60 = 60;
byte[] scale60Bytes = {0x99};
byte[] scale60Bytes = { 0x00, 0x99 };
int scale80 = 80;
byte[] scale80Bytes = {0xCC};
byte[] scale80Bytes = { 0x00, 0xCC };
int scale100 = 100;
byte[] scale100Bytes = {0xFF};
byte[] scale100Bytes = { 0x00, 0xFF };

Assert.AreEqual(scale0, ((int) (decimal) DataPointTranslator.Instance.FromDataPoint(dptType, scale0Bytes)));
Assert.AreEqual(scale20, ((int) (decimal) DataPointTranslator.Instance.FromDataPoint(dptType, scale20Bytes)));
Expand Down

0 comments on commit e5d9b9d

Please sign in to comment.