From 859868c99bf709f11b3b963ed4d8628372618fc7 Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Thu, 21 Dec 2023 14:23:36 +0100 Subject: [PATCH] Use multipliers with DSMR --- src/IEC6205621.cpp | 28 +++++++++++++++++++++++++++- src/IEC6205621.h | 3 ++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/IEC6205621.cpp b/src/IEC6205621.cpp index 0d0c7851..2d059a55 100644 --- a/src/IEC6205621.cpp +++ b/src/IEC6205621.cpp @@ -1,7 +1,7 @@ #include "IEC6205621.h" #include "Uptime.h" -IEC6205621::IEC6205621(const char* p, Timezone* tz) { +IEC6205621::IEC6205621(const char* p, Timezone* tz, MeterConfig* meterConfig) { if(strlen(p) < 16) return; @@ -19,6 +19,9 @@ IEC6205621::IEC6205621(const char* p, Timezone* tz) { } else if(listId.startsWith(F("KMP"))) { meterType = AmsTypeKamstrup; listId = listId.substring(0,4); + } else if(listId.startsWith(F("KAM"))) { + meterType = AmsTypeKamstrup; + listId = listId.substring(0,4); } else if(listId.startsWith(F("ISk"))) { meterType = AmsTypeIskra; listId = listId.substring(0,5); @@ -130,6 +133,29 @@ IEC6205621::IEC6205621(const char* p, Timezone* tz) { if (l1activeImportPower > 0 || l2activeImportPower > 0 || l3activeImportPower > 0 || l1activeExportPower > 0 || l2activeExportPower > 0 || l3activeExportPower > 0) listType = 4; + if(meterConfig->wattageMultiplier > 0) { + activeImportPower = activeImportPower > 0 ? activeImportPower * (meterConfig->wattageMultiplier / 1000.0) : 0; + activeExportPower = activeExportPower > 0 ? activeExportPower * (meterConfig->wattageMultiplier / 1000.0) : 0; + reactiveImportPower = reactiveImportPower > 0 ? reactiveImportPower * (meterConfig->wattageMultiplier / 1000.0) : 0; + reactiveExportPower = reactiveExportPower > 0 ? reactiveExportPower * (meterConfig->wattageMultiplier / 1000.0) : 0; + } + if(meterConfig->voltageMultiplier > 0) { + l1voltage = l1voltage > 0 ? l1voltage * (meterConfig->voltageMultiplier / 1000.0) : 0; + l2voltage = l2voltage > 0 ? l2voltage * (meterConfig->voltageMultiplier / 1000.0) : 0; + l3voltage = l3voltage > 0 ? l3voltage * (meterConfig->voltageMultiplier / 1000.0) : 0; + } + if(meterConfig->amperageMultiplier > 0) { + l1current = l1current > 0 ? l1current * (meterConfig->amperageMultiplier / 1000.0) : 0; + l2current = l2current > 0 ? l2current * (meterConfig->amperageMultiplier / 1000.0) : 0; + l3current = l3current > 0 ? l3current * (meterConfig->amperageMultiplier / 1000.0) : 0; + } + if(meterConfig->accumulatedMultiplier > 0) { + activeImportCounter = activeImportCounter > 0 ? activeImportCounter * (meterConfig->accumulatedMultiplier / 1000.0) : 0; + activeExportCounter = activeExportCounter > 0 ? activeExportCounter * (meterConfig->accumulatedMultiplier / 1000.0) : 0; + reactiveImportCounter = reactiveImportCounter > 0 ? reactiveImportCounter * (meterConfig->accumulatedMultiplier / 1000.0) : 0; + reactiveExportCounter = reactiveExportCounter > 0 ? reactiveExportCounter * (meterConfig->accumulatedMultiplier / 1000.0) : 0; + } + threePhase = l1voltage > 0 && l2voltage > 0 && l3voltage > 0; twoPhase = (l1voltage > 0 && l2voltage > 0) || (l2voltage > 0 && l3voltage > 0) || (l3voltage > 0 && l1voltage > 0); } diff --git a/src/IEC6205621.h b/src/IEC6205621.h index 5ee1d7f7..6ecb341e 100644 --- a/src/IEC6205621.h +++ b/src/IEC6205621.h @@ -4,10 +4,11 @@ #include "Arduino.h" #include "AmsData.h" #include "Timezone.h" +#include "AmsConfiguration.h" class IEC6205621 : public AmsData { public: - IEC6205621(const char* payload, Timezone* tz); + IEC6205621(const char* payload, Timezone* tz, MeterConfig* meterConfig); private: String extract(String payload, String obis);