diff --git a/Code/Arduino/KaifaTest/KaifaTest.ino b/Code/Arduino/KaifaTest/KaifaTest.ino new file mode 100644 index 00000000..d438659b --- /dev/null +++ b/Code/Arduino/KaifaTest/KaifaTest.ino @@ -0,0 +1,106 @@ +/* +* Simple sketch to simulate reading data from a Kamstrup +* AMS Meter. +* +* Created 24. October 2017 by Roar Fredriksen +*/ + +#include +#include + +// The HAN Port reader +HanReader hanReader; + +byte samples[] = +{ + // List #1 + 0x7E, 0xA0, 0x27, 0x01, 0x02, 0x01, 0x10, 0x5A, 0x87, 0xE6, 0xE7, 0x00, 0x0F, 0x40, 0x00, 0x00, 0x00, 0x09, 0x0C, 0x07, 0xE1, 0x09, 0x0E, 0x04, 0x13, 0x1F, 0x02, 0xFF, 0x80, 0x00, 0x00, 0x02, 0x01, 0x06, 0x00, 0x00, 0x03, 0x98, 0xAB, 0xAD, 0x7E, + + // List#2 + 0x7E, 0xA0, 0x79, 0x01, 0x02, 0x01, 0x10, 0x80, 0x93, 0xE6, 0xE7, 0x00, 0x0F, 0x40, 0x00, 0x00, 0x00, 0x09, 0x0C, 0x07, 0xE1, 0x09, 0x0E, 0x04, 0x13, 0x1F, 0x0A, 0xFF, 0x80, 0x00, 0x00, 0x02, 0x0D, 0x09, 0x07, 0x4B, 0x46, 0x4D, 0x5F, 0x30, 0x30, 0x31, 0x09, 0x10, 0x36, 0x39, 0x37, 0x30, 0x36, 0x33, 0x31, 0x34, 0x30, 0x31, 0x37, 0x35, 0x33, 0x39, 0x38, 0x35, 0x09, 0x08, 0x4D, 0x41, 0x33, 0x30, 0x34, 0x48, 0x33, 0x45, 0x06, 0x00, 0x00, 0x03, 0x96, 0x06, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x06, 0x00, 0x00, 0x05, 0x64, 0x06, 0x00, 0x00, 0x0C, 0x92, 0x06, 0x00, 0x00, 0x0C, 0x49, 0x06, 0x00, 0x00, 0x09, 0x46, 0x06, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x09, 0x4E, 0x1F, 0x85, 0x7E, + + // List#3 + 0x7E, 0xA0, 0x9B, 0x01, 0x02, 0x01, 0x10, 0xEE, 0xAE, 0xE6, 0xE7, 0x00, 0x0F, 0x40, 0x00, 0x00, 0x00, 0x09, 0x0C, 0x07, 0xE1, 0x09, 0x0E, 0x04, 0x14, 0x00, 0x0A, 0xFF, 0x80, 0x00, 0x00, 0x02, 0x12, 0x09, 0x07, 0x4B, 0x46, 0x4D, 0x5F, 0x30, 0x30, 0x31, 0x09, 0x10, 0x36, 0x39, 0x37, 0x30, 0x36, 0x33, 0x31, 0x34, 0x30, 0x31, 0x37, 0x35, 0x33, 0x39, 0x38, 0x35, 0x09, 0x08, 0x4D, 0x41, 0x33, 0x30, 0x34, 0x48, 0x33, 0x45, 0x06, 0x00, 0x00, 0x03, 0xFE, 0x06, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x40, 0x06, 0x00, 0x00, 0x07, 0x91, 0x06, 0x00, 0x00, 0x0C, 0x9D, 0x06, 0x00, 0x00, 0x0D, 0x66, 0x06, 0x00, 0x00, 0x09, 0x41, 0x06, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x09, 0x4C, 0x09, 0x0C, 0x07, 0xE1, 0x09, 0x0E, 0x04, 0x14, 0x00, 0x0A, 0xFF, 0x80, 0x00, 0x00, 0x06, 0x00, 0x02, 0xBF, 0x69, 0x06, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xF7, 0x06, 0x00, 0x00, 0x3F, 0xFC, 0x71, 0x71, 0x7E +}; +int sampleIndex = 0; + +void setup() { + setupDebugPort(); + + // initialize the HanReader + // (passing no han port, as we are feeding data manually, but provide Serial for debugging) + hanReader.setup(NULL, &Serial); +} + +void setupDebugPort() +{ + // Initialize the Serial port for debugging + Serial.begin(115200); + while (!Serial) {} + Serial.setDebugOutput(true); + Serial.println("Serial1"); + Serial.println("Serial debugging port initialized"); +} + +void loop() { + // Read one byte from the "port", and see if we got a full package + if (hanReader.read(samples[sampleIndex++])) + { + // Get the list identifier + int list = hanReader.getList(); + + Serial.println(""); + Serial.print("List #"); + Serial.print((byte)list, HEX); + Serial.print(": "); + + // Only care for the ACtive Power Imported, which is found in the first list + if (list == (int)Kaifa::List1 || list == (int)Kaifa::List2 || list == (int)Kaifa::List3) + { + String id = hanReader.getString((int)Kaifa_List1::ListID); + Serial.println(id); + + time_t time = hanReader.getPackageTime(); + Serial.print("Time of the package is: "); + Serial.println(time); + + if (list == (int)Kaifa::List1) + { + int power = hanReader.getInt((int)Kaifa_List1::ActivePowerImported); + Serial.print("Power consumtion is right now: "); + Serial.print(power); + Serial.println(" W"); + } + else + { + float current[3]; + current[0] = (float)hanReader.getInt((int)Kaifa_List2::CurrentL1) / 100.0; + current[1] = (float)hanReader.getInt((int)Kaifa_List2::CurrentL2) / 100.0; + current[2] = (float)hanReader.getInt((int)Kaifa_List2::CurrentL3) / 100.0; + + int voltage[3]; + voltage[0] = hanReader.getInt((int)Kaifa_List2::VoltageL1); + voltage[1] = hanReader.getInt((int)Kaifa_List2::VoltageL2); + voltage[2] = hanReader.getInt((int)Kaifa_List2::VoltageL3); + + for (int i = 0; i < 3; i++) + { + Serial.print("L"); + Serial.print(i + 1); + Serial.print(" is "); + Serial.print(voltage[i]); + Serial.print(" V ("); + Serial.print(current[i]); + Serial.println(" A)"); + } + } + } + } + + delay(10); + if (sampleIndex >= sizeof(samples)) + { + delay(2000); + sampleIndex = 0; + } +} \ No newline at end of file diff --git a/Code/Arduino/KaifaTest/KaifaTest.sln b/Code/Arduino/KaifaTest/KaifaTest.sln new file mode 100644 index 00000000..1f9698bb --- /dev/null +++ b/Code/Arduino/KaifaTest/KaifaTest.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26730.16 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KaifaTest", "KaifaTest.vcxproj", "{C5F80730-F44F-4478-BDAE-6634EFC2CA88}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Debug|x86.ActiveCfg = Debug|Win32 + {C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Debug|x86.Build.0 = Debug|Win32 + {C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Release|x86.ActiveCfg = Release|Win32 + {C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {35D8A583-E857-4E42-B780-543F324B8851} + EndGlobalSection +EndGlobal diff --git a/Code/Arduino/KaifaTest/KaifaTest.vcxproj b/Code/Arduino/KaifaTest/KaifaTest.vcxproj new file mode 100644 index 00000000..b76df73b --- /dev/null +++ b/Code/Arduino/KaifaTest/KaifaTest.vcxproj @@ -0,0 +1,87 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {C5F80730-F44F-4478-BDAE-6634EFC2CA88} + KaifaTest + KaifaTest + + + + Application + true + + + MultiByte + + + Application + false + + + true + MultiByte + + + + + + + + + + + + + + + Level3 + Disabled + true + %(AdditionalIncludeDirectories) + %(ForcedIncludeFiles) + true + %(PreprocessorDefinitions) + + + true + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + true + + + + + + + VisualMicroDebugger + + + + CppCode + + + + + + \ No newline at end of file diff --git a/Code/Arduino/KaifaTest/KaifaTest.vcxproj.filters b/Code/Arduino/KaifaTest/KaifaTest.vcxproj.filters new file mode 100644 index 00000000..07b13b0a --- /dev/null +++ b/Code/Arduino/KaifaTest/KaifaTest.vcxproj.filters @@ -0,0 +1,21 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + + + \ No newline at end of file