From fe7be81f1e0b25485afb238b20cf8cc5e2b13035 Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Sat, 1 Oct 2022 12:11:46 +0200 Subject: [PATCH] Rudimentary detection for L&G data. Probably change this in the future --- src/AmsToMqttBridge.ino | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/AmsToMqttBridge.ino b/src/AmsToMqttBridge.ino index fbc706fe..20ee5ee5 100644 --- a/src/AmsToMqttBridge.ino +++ b/src/AmsToMqttBridge.ino @@ -850,21 +850,26 @@ bool readHanPort() { } AmsData data; + char* payload = ((char *) (hanBuffer)) + pos; if(ctx.type == DATA_TAG_DLMS) { // If MQTT bytestream payload is selected (mqttHandler == NULL), send the payload to MQTT if(mqttEnabled && mqtt != NULL && mqttHandler == NULL) { - mqtt->publish(topic.c_str(), toHex(hanBuffer+pos, ctx.length)); + mqtt->publish(topic.c_str(), toHex((byte*) payload, ctx.length)); mqtt->loop(); } debugV("Using application data:"); - if(Debug.isActive(RemoteDebug::VERBOSE)) debugPrint(hanBuffer+pos, 0, ctx.length); + if(Debug.isActive(RemoteDebug::VERBOSE)) debugPrint((byte*) payload, 0, ctx.length); - // TODO: Split IEC6205675 into DataParserKaifa and DataParserObis. This way we can add other means of parsing, for those other proprietary formats - //data = IEC6205675(((char *) (hanBuffer)) + pos, meterState.getMeterType(), &meterConfig, ctx); - data = LNG(((char *) (hanBuffer)) + pos, meterState.getMeterType(), &meterConfig, ctx, &Debug); + // Rudimentary detector for L&G proprietary format + if(payload[0] == CosemTypeStructure && payload[2] == CosemTypeArray && payload[1] == payload[3]) { + data = LNG(payload, meterState.getMeterType(), &meterConfig, ctx, &Debug); + } else { + // TODO: Split IEC6205675 into DataParserKaifa and DataParserObis. This way we can add other means of parsing, for those other proprietary formats + data = IEC6205675(payload, meterState.getMeterType(), &meterConfig, ctx); + } } else if(ctx.type == DATA_TAG_DSMR) { - data = IEC6205621(((char *) (hanBuffer)) + pos); + data = IEC6205621(payload); } len = 0;