mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-05-01 14:06:41 +00:00
Created method to get int from data (not quite safe yet)
This commit is contained in:
@@ -43,5 +43,28 @@ namespace HanDebugger
|
|||||||
|
|
||||||
return new DateTime(year, month, day, hour, minute, second).Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds;
|
return new DateTime(year, month, day, hour, minute, second).Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int GetInt(int dataPosition, byte[] buffer, int start, int length)
|
||||||
|
{
|
||||||
|
const int dataStart = 24;
|
||||||
|
int value = 0;
|
||||||
|
int foundPosition = 0;
|
||||||
|
for (int i = start + dataStart; i < start + length; i++)
|
||||||
|
{
|
||||||
|
if (foundPosition == 0)
|
||||||
|
{
|
||||||
|
if (buffer[i] == 0x06)
|
||||||
|
foundPosition = i;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
value = value << 8 |
|
||||||
|
buffer[i];
|
||||||
|
if (i == foundPosition + 4)
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,5 +45,21 @@ namespace HanDebuggerTest
|
|||||||
double actualList1To2Ratio = (double)packageCount[KaifaHanBeta.List1] / (double)packageCount[KaifaHanBeta.List2];
|
double actualList1To2Ratio = (double)packageCount[KaifaHanBeta.List1] / (double)packageCount[KaifaHanBeta.List2];
|
||||||
Assert.AreEqual(targetList1To2Ratio, actualList1To2Ratio, 0.01, "There should be a ratio of List1:List2 of 4");
|
Assert.AreEqual(targetList1To2Ratio, actualList1To2Ratio, 0.01, "There should be a ratio of List1:List2 of 4");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TestGetConsumption()
|
||||||
|
{
|
||||||
|
List<int> consumption = new List<int>();
|
||||||
|
var packages = File.ReadAllLines("ESP 20170918 Raw.txt");
|
||||||
|
var lines = packages.Select(line => line.Trim().Split(' ').Select(v => (byte)int.Parse(v, System.Globalization.NumberStyles.HexNumber)).ToArray()).ToArray();
|
||||||
|
foreach (var line in lines)
|
||||||
|
{
|
||||||
|
if (KaifaHanBeta.GetPackageID(line, 0, line.Length) == KaifaHanBeta.List1)
|
||||||
|
{
|
||||||
|
consumption.Add(KaifaHanBeta.GetInt(0, line, 0, line.Length));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Assert.AreEqual(1500.0, consumption.Average(), 500.0, "Consumption should be between 1000 and 2000 watts");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user