From 099f6d97ee6d38ccf275c63d3bdf4dfaa8a8bfed Mon Sep 17 00:00:00 2001 From: mike3436 <> Date: Sun, 21 Aug 2016 12:46:31 +0000 Subject: [PATCH] 26_KM273.pm:2016-05-31 V0010 KM273_ReadElementList bugfix if expected readCounter isn't reached by read data; delete lists on module reload git-svn-id: https://svn.fhem.de/fhem/trunk@12036 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/26_KM273.pm | 49 ++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/fhem/FHEM/26_KM273.pm b/fhem/FHEM/26_KM273.pm index f54707a87..b6cd7545c 100755 --- a/fhem/FHEM/26_KM273.pm +++ b/fhem/FHEM/26_KM273.pm @@ -69,6 +69,7 @@ # 0007 01.02.2016 mike3436 KM273_Get,KM273_GetNextValue KM273_Get corrected, KM273_GetNextValue do nothing if attr doNotPoll=1 # 0008 30.05.2016 mike3436 KM273_ReadElementList complete element list is read from heatpump, default list is only used for deliver the 'read' flag # 0009 31.05.2016 mike3436 KM273_ReadElementList if expected readCounter isn't reached on second read, and read data has identical length, try to analyse +# 0010 31.05.2016 mike3436 KM273_ReadElementList bugfix if expected readCounter isn't reached by read data; delete lists on module reload package main; use strict; @@ -2001,6 +2002,21 @@ my %KM273_elements = (); my %KM273_ReadElementListStatus = ( done => 0, wait => 0, readCounter => 0, readIndex => 0, readIndexLast => 0, writeIndex => 0, KM200active => 0, KM200wait => 0, readData => ""); my %KM273_ReadElementListElements = (); + +sub KM273_ClearElementLists($) +{ + my ($hash) = @_; + my $name = $hash->{NAME} . ": KM273_ClearElementLists"; + Log 3, "$name"; + + %KM273_history = (); + @KM273_readingsRTR = (); + %KM273_writingsTXD = (); + %KM273_elements = (); + %KM273_ReadElementListStatus = ( done => 0, wait => 0, readCounter => 0, readIndex => 0, readIndexLast => 0, writeIndex => 0, KM200active => 0, KM200wait => 0, readData => ""); + %KM273_ReadElementListElements = (); +} + sub KM273_ReadElementList($) { my ($hash) = @_; @@ -2037,18 +2053,10 @@ sub KM273_ReadElementList($) } elsif (--$KM273_ReadElementListStatus{wait} <= 0) { - if (($KM273_ReadElementListStatus{readIndexLast} > 0) && ($KM273_ReadElementListStatus{readIndexLast} == $KM273_ReadElementListStatus{readIndex})) - { - #wenn readCounter auch beim 2. Lesen nicht erreicht wird, und gelesene Datenmenge gleich ist, dann readCounter = readIndex - $KM273_ReadElementListStatus{readCounter} = $KM273_ReadElementListStatus{readIndex}; - } - else - { - $KM273_ReadElementListStatus{readIndexLast} = $KM273_ReadElementListStatus{readIndex}; - $KM273_ReadElementListStatus{readIndex} = 0; - $KM273_ReadElementListStatus{writeIndex} = 0; - $KM273_ReadElementListStatus{readData} = ""; - } + $KM273_ReadElementListStatus{readIndexLast} = $KM273_ReadElementListStatus{readIndex}; + $KM273_ReadElementListStatus{readIndex} = 0; + $KM273_ReadElementListStatus{writeIndex} = 0; + $KM273_ReadElementListStatus{readData} = ""; } my $count = 1; @@ -2074,6 +2082,12 @@ sub KM273_ReadElementList($) $KM273_ReadElementListStatus{readData} .= pack("NN",$value1>>32,$value1&0xffffffff); } + if (($KM273_ReadElementListStatus{readIndexLast} > 0) && ($KM273_ReadElementListStatus{readIndexLast} == $KM273_ReadElementListStatus{readIndex})) + { + #wenn readCounter auch beim 2. Lesen nicht erreicht wird, und gelesene Datenmenge gleich ist, dann readCounter = readIndex + Log 3, "$name readCounter $KM273_ReadElementListStatus{readCounter} changed to $KM273_ReadElementListStatus{readIndex}"; + $KM273_ReadElementListStatus{readCounter} = $KM273_ReadElementListStatus{readIndex}; + } if (($KM273_ReadElementListStatus{readCounter} > 0) && ($KM273_ReadElementListStatus{readIndex} >= $KM273_ReadElementListStatus{readCounter})) { $KM273_ReadElementListStatus{done} = 1; @@ -2111,7 +2125,7 @@ sub KM273_ReadElementList($) } elsif (hex $canId == 0x09FD7FE0) { - my $readCounter = $value1 >> 24; + my $readCounter = ($value1 >> 24); # + 10; #+10=Test $KM273_ReadElementListStatus{readCounter} = $readCounter; Log 3, "$name read T09FD7FE0 len=$len1 value=$value1 readCounter=$readCounter"; } @@ -2160,7 +2174,7 @@ sub KM273_UpdateElements($) { my $text1 = (substr $text, 0, $pos) . (substr $text, $pos+1); $elem1 = $KM273_ReadElementListElements{$text1}; - Log 3, "$name change $text to $text1"; + Log 3, "$name change $text1 to $text"; last; } @@ -2188,6 +2202,7 @@ sub KM273_CreatePollingList($) my $name = $hash->{NAME} . ": KM273_CreatePollingList"; Log 3, "$name"; + @KM273_readingsRTR = (); foreach my $element (keys %KM273_elements) { push @KM273_readingsRTR, $KM273_elements{$element}{rtr} if $KM273_elements{$element}{read} == 1; @@ -2198,6 +2213,7 @@ sub KM273_CreatePollingList($) } $hash->{pollingIndex} = 0; + %KM273_writingsTXD = (); foreach my $element (keys %KM273_elements) { foreach my $get (keys %KM273_gets) @@ -2257,6 +2273,7 @@ sub KM273_Define($$) return undef; } + KM273_ClearElementLists($hash); #KM273_CreatePollingList($hash); #InternalTimer(gettimeofday()+10, "KM273_GetReadings", $hash, 0); @@ -2270,6 +2287,10 @@ sub KM273_Define($$) sub KM273_Undef($$) { my ($hash, $arg) = @_; + my $name = $hash->{NAME} . ": KM273_Undef"; + Log 3, "$name"; + + RemoveInternalTimer($hash); CAN_Close($hash); return undef; }