From 37431d00fc75f315533cbe6df6427e4613fa00d1 Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Thu, 16 Oct 2025 14:06:39 +0200 Subject: [PATCH] Support for LNG2 with 11 data points instead of 14 --- lib/MeterCommunicators/include/LNG2.h | 17 +++++++++++++++- lib/MeterCommunicators/src/LNG2.cpp | 28 ++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/lib/MeterCommunicators/include/LNG2.h b/lib/MeterCommunicators/include/LNG2.h index 752a88d2..31651c4d 100644 --- a/lib/MeterCommunicators/include/LNG2.h +++ b/lib/MeterCommunicators/include/LNG2.h @@ -12,7 +12,22 @@ #include "DataParser.h" #include "Cosem.h" -struct Lng2Data_3p { +struct Lng2Data_3p_0b { + CosemBasic header; + CosemLongUnsigned u1; + CosemLongUnsigned u2; + CosemLongUnsigned u3; + CosemLongUnsigned i1; + CosemLongUnsigned i2; + CosemLongUnsigned i3; + CosemDLongUnsigned activeImport; + CosemDLongUnsigned activeExport; + CosemDLongUnsigned acumulatedImport; + CosemDLongUnsigned accumulatedExport; + CosemString meterId; +} __attribute__((packed)); + +struct Lng2Data_3p_0e { CosemBasic header; CosemLongUnsigned u1; CosemLongUnsigned u2; diff --git a/lib/MeterCommunicators/src/LNG2.cpp b/lib/MeterCommunicators/src/LNG2.cpp index 6b87a4b2..57ffd33d 100644 --- a/lib/MeterCommunicators/src/LNG2.cpp +++ b/lib/MeterCommunicators/src/LNG2.cpp @@ -14,7 +14,33 @@ LNG2::LNG2(AmsData& meterState, const char* payload, uint8_t useMeterType, Meter meterType = AmsTypeLandisGyr; this->packageTimestamp = ctx.timestamp; - Lng2Data_3p* d = (Lng2Data_3p*) payload; + Lng2Data_3p_0e* d = (Lng2Data_3p_0e*) payload; + this->l1voltage = ntohs(d->u1.data); + this->l2voltage = ntohs(d->u2.data); + this->l3voltage = ntohs(d->u3.data); + + this->l1current = ntohs(d->i1.data) / 100.0; + this->l2current = ntohs(d->i2.data) / 100.0; + this->l3current = ntohs(d->i3.data) / 100.0; + + this->activeImportPower = ntohl(d->activeImport.data); + this->activeExportPower = ntohl(d->activeExport.data); + this->activeImportCounter = ntohl(d->acumulatedImport.data) / 1000.0; + this->activeExportCounter = ntohl(d->accumulatedExport.data) / 1000.0; + + char str[64]; + uint8_t str_len = getString((CosemData*) &d->meterId, str); + if(str_len > 0) { + this->meterId = String(str); + } + listType = 3; + lastUpdateMillis = millis64(); + } else if(h->length == 0x0b) { + apply(meterState); + meterType = AmsTypeLandisGyr; + this->packageTimestamp = ctx.timestamp; + + Lng2Data_3p_0b* d = (Lng2Data_3p_0b*) payload; this->l1voltage = ntohs(d->u1.data); this->l2voltage = ntohs(d->u2.data); this->l3voltage = ntohs(d->u3.data);