From 32afea2817ce624e6c879992b22e2b1e812b7dc1 Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Tue, 4 Jun 2024 20:33:03 +0200 Subject: [PATCH] Iskra --- lib/AmsData/src/AmsData.cpp | 6 ++- src/IEC6205675.cpp | 91 +++++++++++++++++++++---------------- 2 files changed, 56 insertions(+), 41 deletions(-) diff --git a/lib/AmsData/src/AmsData.cpp b/lib/AmsData/src/AmsData.cpp index 273aae2f..cc001766 100644 --- a/lib/AmsData/src/AmsData.cpp +++ b/lib/AmsData/src/AmsData.cpp @@ -100,12 +100,16 @@ void AmsData::apply(AmsData& other) { } void AmsData::apply(OBIS_code_t obis, double value) { + if(obis.sensor == 0 && obis.gr == 0 && obis.tariff == 0) { + meterType = value; + } if(obis.gr == 1) { if(obis.sensor == 96) { if(obis.tariff == 0) { meterId = String((long) value, 10); + return; } else if(obis.tariff == 1) { - meterModel = String((long) value, 10); + return; } } } diff --git a/src/IEC6205675.cpp b/src/IEC6205675.cpp index f7edc113..f503c84c 100644 --- a/src/IEC6205675.cpp +++ b/src/IEC6205675.cpp @@ -208,6 +208,57 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, MeterConfig* meterCo lastUpdateMillis = millis64(); } + } else if(useMeterType == AmsTypeIskra && data->base.type == CosemTypeOctetString) { // Iskra special case + meterType = AmsTypeIskra; + uint8_t idx = 5; + + data = getCosemDataAt(idx++, ((char *) (d))); + if(data != NULL) { + activeImportCounter = ntohl(data->dlu.data) / 1000.0; + } + + data = getCosemDataAt(idx++, ((char *) (d))); + if(data != NULL) { + activeExportCounter = ntohl(data->dlu.data) / 1000.0; + } + + data = getCosemDataAt(idx++, ((char *) (d))); + if(data != NULL) { + reactiveImportCounter = ntohl(data->dlu.data) / 1000.0; + } + + data = getCosemDataAt(idx++, ((char *) (d))); + if(data != NULL) { + reactiveExportCounter = ntohl(data->dlu.data) / 1000.0; + } + + data = getCosemDataAt(idx++, ((char *) (d))); + if(data != NULL) { + activeImportPower = ntohl(data->dlu.data); + } + + data = getCosemDataAt(idx++, ((char *) (d))); + if(data != NULL) { + activeExportPower = ntohl(data->dlu.data); + } + + uint8_t str_len = 0; + str_len = getString(AMS_OBIS_UNKNOWN_1, sizeof(AMS_OBIS_UNKNOWN_1), ((char *) (d)), str); + if(str_len > 0) { + meterId = String(str); + } + + listType = 3; + lastUpdateMillis = millis64(); + } else if(useMeterType == AmsTypeUnknown) { + uint8_t str_len = 0; + str_len = getString(AMS_OBIS_UNKNOWN_1, sizeof(AMS_OBIS_UNKNOWN_1), ((char *) (d)), str); + if(str_len > 0) { + meterType = AmsTypeIskra; + meterId = String(str); + lastUpdateMillis = millis64(); + listType = 3; + } } } else if(useMeterType == AmsTypeKaifa && data->base.type == CosemTypeDLongUnsigned) { this->packageTimestamp = this->packageTimestamp > 0 ? tz.toUTC(this->packageTimestamp) : 0; @@ -215,46 +266,6 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, MeterConfig* meterCo meterType = AmsTypeKaifa; activeImportPower = ntohl(data->dlu.data); lastUpdateMillis = millis64(); - } else if(useMeterType == AmsTypeIskra && data->base.type == CosemTypeOctetString) { // Iskra special case - uint8_t idx = 5; - - data = getCosemDataAt(idx++, ((char *) (d))); - if(data != NULL) { - activeImportCounter = ntohl(data->dlu.data) / 1000.0; - } - - data = getCosemDataAt(idx++, ((char *) (d))); - if(data != NULL) { - activeExportCounter = ntohl(data->dlu.data) / 1000.0; - } - - data = getCosemDataAt(idx++, ((char *) (d))); - if(data != NULL) { - reactiveImportCounter = ntohl(data->dlu.data) / 1000.0; - } - - data = getCosemDataAt(idx++, ((char *) (d))); - if(data != NULL) { - reactiveExportCounter = ntohl(data->dlu.data) / 1000.0; - } - - data = getCosemDataAt(idx++, ((char *) (d))); - if(data != NULL) { - activeImportPower = ntohl(data->dlu.data); - } - - data = getCosemDataAt(idx++, ((char *) (d))); - if(data != NULL) { - activeExportPower = ntohl(data->dlu.data); - } - - listType = 3; - lastUpdateMillis = millis64(); - } else if(useMeterType == AmsTypeUnknown) { - CosemData* isk_tag = findObis(AMS_OBIS_UNKNOWN_1, sizeof(AMS_OBIS_UNKNOWN_1), d); // Not really correct, but who cares - if(isk_tag != NULL) { - meterType = AmsTypeIskra; - } } } else { listType = 1;