mhop / fhem-mirror

Branch 'master' is an unofficial read-only-mirror of https://svn.fhem.de/fhem/trunk which is updated once a day. (branch sf_old a mirror of the old repo: svn://svn.code.sf.net/p/fhem/code/trunk)
107 stars 126 forks source link

km271.pl does not parse the value 0x02 correctly #56

Open rhabacker opened 2 years ago

rhabacker commented 2 years ago

I am using https://github.com/mhop/fhem-mirror/blob/master/fhem/contrib/km271.pl to extract log data from a Buderus Logamatic 2107 and have discovered an error in the log data parser when a value is received as 0x02 as shown in the following example:

The data stream received from the device for the key Betriebswerte_1_HK1 4.

2022-04-17_05:47:24.891 DEV 02
2022-04-17_05:47:24.902 DEV 80  
2022-04-17_05:47:24.906 DEV 00   
2022-04-17_05:47:24.910 DEV 04
2022-04-17_05:47:24.913 DEV 10
2022-04-17_05:47:24.917 DEV 03
2022-04-17_05:47:24.922 DEV 97

is parsed correctly as

2022-04-17_05:47:24.923 Betriebswerte_1_HK1 4

The data stream received for the key Betriebswerte_2_HK1 2.

2022-04-17_05:47:25.139 DEV 02
2022-04-17_05:47:25.147 DEV 80
2022-04-17_05:47:25.153 DEV 01
2022-04-17_05:47:25.156 DEV 02
2022-04-17_05:47:25.160 DEV 10
2022-04-17_05:47:25.164 DEV 03
2022-04-17_05:47:25.169 DEV 90

results in

Wrong CRC in 100390 (90 vs. 13)

which is not correct.

The reason for this problem is that parsing the second '02' value deletes all previously added data in $tbuf at https://github.com/mhop/fhem-mirror/blob/28c1647cef9a267624c29ffcb83fd8c4001d8c39/fhem/contrib/km271.pl#L138.

rhabacker commented 2 years ago

For a related patch to fix this issue see below:

From 180b85f5e9db45e62b1a29d0078d7bd051188ec3 Mon Sep 17 00:00:00 2001
From: Ralf Habacker <ralf.habacker@freenet.de>
Date: Fri, 8 Jul 2022 21:57:15 +0000
Subject: [PATCH] Fix not parsing the value 0x02 correctly

https://github.com/mhop/fhem-mirror/issues/56
---
 km271.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/km271.pl b/km271.pl
index 5bbcfae..88b707a 100644
--- a/km271.pl
+++ b/km271.pl
@@ -134,7 +134,7 @@ for(;;) {

     $buf = unpack('H*', $buf);
     #printf("%s DEV %s\n", fmt_now(), $buf);
-    if($buf eq "02") {
+    if($buf eq "02" && $tbuf eq "") {
       $tbuf = "";
       $po->write($dle);
       next;
-- 
2.11.0