Created class for dealing with unknown HAN port of Kaifa meter

This commit is contained in:
Roar Fredriksen
2017-09-19 23:09:38 +02:00
parent d48d4493a2
commit 8df007689d
5 changed files with 9678 additions and 0 deletions

View File

@@ -44,6 +44,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Crc16.cs" />
<Compile Include="KaifaHanBeta.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Reader.cs" />

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HanDebugger
{
// As it seems Kaifa/Valider put some premature firmware on my AMS,
// there's need for some dirty hacks to get any information
public class KaifaHanBeta
{
public const byte ListUnknown = 0x00;
public const byte List1 = 0x01;
public const byte List2 = 0x0D;
public const byte List3 = 0x12;
public static byte GetPackageID(byte[] package, int start, int length)
{
switch (package[start + 23])
{
case List1:
case List2:
case List3:
return package[start + 23];
default:
return 0x00;
}
}
public static double GetPackageTime(byte[] package, int start, int length)
{
const int timeStart = 10;
int year = package[start + timeStart] << 8 |
package[start + timeStart + 1];
int month = package[start + timeStart + 2];
int day = package[start + timeStart + 3];
int hour = package[start + timeStart + 5];
int minute = package[start + timeStart + 6];
int second = package[start + timeStart + 7];
return new DateTime(year, month, day, hour, minute, second).Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds;
}
}
}