Fixed infinite sending loop in strange cases

git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@1883 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
physikus
2012-09-22 17:34:17 +00:00
parent 8386b49f20
commit ec21f1950d
2 changed files with 50 additions and 37 deletions

View File

@@ -521,6 +521,7 @@ KM271_Read($)
if($buf eq "10") { if($buf eq "10") {
if($hash->{DATASENT}) { if($hash->{DATASENT}) {
delete($hash->{DATASENT}); delete($hash->{DATASENT});
delete($hash->{RETRYCOUNT});
# Delete the command from the list # Delete the command from the list
shift @{$hash->{SENDBUFFER}}; shift @{$hash->{SENDBUFFER}};
if ($hash->{NOTIFY}) { if ($hash->{NOTIFY}) {
@@ -529,8 +530,7 @@ KM271_Read($)
goto INTERNAL_NOTIFY; # Timer changes are not reflected by the heater goto INTERNAL_NOTIFY; # Timer changes are not reflected by the heater
} }
DevIo_SimpleWrite($hash, "02", 1) if(@{$hash->{SENDBUFFER}}); DevIo_SimpleWrite($hash, "02", 1) if(@{$hash->{SENDBUFFER}});
return; } else {
}
# Delete the command only after receiving ACK # Delete the command only after receiving ACK
$data = shift @{$hash->{SENDBUFFER}}; $data = shift @{$hash->{SENDBUFFER}};
unshift @{$hash->{SENDBUFFER}}, $data; unshift @{$hash->{SENDBUFFER}}, $data;
@@ -543,6 +543,7 @@ KM271_Read($)
$data .= $crc; $data .= $crc;
$hash->{DATASENT} = $data; $hash->{DATASENT} = $data;
$hash->{ERROR} = 0; $hash->{ERROR} = 0;
$hash->{RETRYCOUNT} = 0;
if (@dataList > 1) { if (@dataList > 1) {
# Set notify message # Set notify message
$hash->{NOTIFY} = $dataList[1]; $hash->{NOTIFY} = $dataList[1];
@@ -550,38 +551,50 @@ KM271_Read($)
delete($hash->{NOTIFY}); delete($hash->{NOTIFY});
} }
DevIo_SimpleWrite($hash, $data, 1); # Send the data DevIo_SimpleWrite($hash, $data, 1); # Send the data
}
} else { } else {
if($hash->{DATASENT}) { if($hash->{DATASENT}) {
my $newStart = 0;
if ($buf eq "15") { if ($buf eq "15") {
Log 1, "$name: NAK!"; # NACK from the KM271 Log 1, "$name: NAK!"; # NACK from the KM271
} else { if(++$hash->{ERROR} > 5) {
Log 1, "$name: Bogus data after sending packet ($buf)"; # Strange response from the KM271 $newStart = 1;
}
if($hash->{ERROR}++ > 5) {
Log 1, "$name: Sending ($hash->{DATASENT}) aborted!";
delete($hash->{DATASENT});
delete($hash->{NOTIFY});
DevIo_SimpleWrite($hash, "02", 1) if(@{$hash->{SENDBUFFER}});
} else { } else {
DevIo_SimpleWrite($hash, $hash->{DATASENT}, 1); DevIo_SimpleWrite($hash, $hash->{DATASENT}, 1);
} }
return; } else {
Log 1, "$name: Bogus data after sending packet ($buf)"; # Strange response from the KM271
$newStart = 1;
} }
if ($newStart) {
# Start all over again
Log 1, "$name: Sending attempt for ($hash->{DATASENT}) failed!";
if(++$hash->{RETRYCOUNT} > 3) {
# Abort sending the actual command
Log 1, "$name: Sending ($hash->{DATASENT}) not successful!";
shift @{$hash->{SENDBUFFER}};
delete($hash->{RETRYCOUNT});
}
delete($hash->{DATASENT});
delete($hash->{NOTIFY});
DevIo_SimpleWrite($hash, "02", 1) if(@{$hash->{SENDBUFFER}});
}
} else {
DevIo_SimpleWrite($hash, "02", 1); DevIo_SimpleWrite($hash, "02", 1);
} }
} }
elsif ($buf eq "02") { # KM271 Wants to send } else {
if ($buf eq "02") { # KM271 Wants to send
DevIo_SimpleWrite($hash, "10", 1); # We are ready DevIo_SimpleWrite($hash, "10", 1); # We are ready
$hash->{PARTIAL} = ""; $hash->{PARTIAL} = "";
$hash->{WAITING} = Time::HiRes::time; $hash->{WAITING} = time;
$hash->{ERROR} = 0; $hash->{ERROR} = 0;
} }
}
return; return;
} else { } else {
# After timeout get out of waiting mode # After timeout get out of waiting mode
delete($hash->{WAITING}) if(Time::HiRes::time - $hash->{WAITING} > 2); delete($hash->{WAITING}) if(time - $hash->{WAITING} > 2.5);
} }
$hash->{PARTIAL} .= $buf; $hash->{PARTIAL} .= $buf;
@@ -592,7 +605,7 @@ KM271_Read($)
if(KM271_crc($data . "1003") ne $crc) { if(KM271_crc($data . "1003") ne $crc) {
Log 1, "Wrong CRC in $name: $crc"; Log 1, "Wrong CRC in $name: $crc";
DevIo_SimpleWrite($hash, "15", 1); # NAK DevIo_SimpleWrite($hash, "15", 1); # NAK
if($hash->{ERROR}++ > 5) { if(++$hash->{ERROR} > 5) {
delete($hash->{WAITING}); delete($hash->{WAITING});
DevIo_SimpleWrite($hash, "02", 1) if(@{$hash->{SENDBUFFER}}); # Want to send DevIo_SimpleWrite($hash, "02", 1) if(@{$hash->{SENDBUFFER}}); # Want to send
} }

View File

@@ -4414,10 +4414,12 @@ A line ending with \ will be concatenated with the next one, so long lines
<li>Brenner_Laufzeit2_Minuten2 <li>Brenner_Laufzeit2_Minuten2
<li>Brenner_Laufzeit2_Minuten1 <li>Brenner_Laufzeit2_Minuten1
<li>Brenner_Laufzeit2_Minuten <li>Brenner_Laufzeit2_Minuten
<li>Brenner_Mod_Stellglied
<li>ERR_Fehlerspeicher1 <li>ERR_Fehlerspeicher1
<li>ERR_Fehlerspeicher2 <li>ERR_Fehlerspeicher2
<li>ERR_Fehlerspeicher3 <li>ERR_Fehlerspeicher3
<li>ERR_Fehlerspeicher4 <li>ERR_Fehlerspeicher4
<li>ERR_Letzter_Fehlerstatus
<li>HK1_Ausschaltoptimierung <li>HK1_Ausschaltoptimierung
<li>HK1_Betriebswerte1 <li>HK1_Betriebswerte1
<li>HK1_Betriebswerte2 <li>HK1_Betriebswerte2
@@ -4450,8 +4452,6 @@ A line ending with \ will be concatenated with the next one, so long lines
<li>Kessel_Integral1 <li>Kessel_Integral1
<li>Kessel_Vorlaufisttemperatur <li>Kessel_Vorlaufisttemperatur
<li>Kessel_Vorlaufsolltemperatur <li>Kessel_Vorlaufsolltemperatur
<li>Letzter_Fehlerstatus
<li>Mod_Brenner_Stellglied
<li>Modulkennung <li>Modulkennung
<li>NoData <li>NoData
<li>Versionsnummer_NK <li>Versionsnummer_NK