2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-04 05:16:45 +00:00

THZ: bug fix for long messages in combination with serial cable connection

git-svn-id: https://svn.fhem.de/fhem/trunk@6363 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
immiimmi 2014-08-05 19:03:32 +00:00
parent 3404dc43ac
commit 448a479d5a

View File

@ -1,8 +1,8 @@
##############################################
# 00_THZ
# $Id$
# by immi 06/2014
my $thzversion = "0.108";
# by immi 08/2014
my $thzversion = "0.109";
# this code is based on the hard work of Robert; I just tried to port it
# http://robert.penz.name/heat-pump-lwz/
# http://heatpumpmonitor.penz.name/heatpumpmonitorwiki/
@ -715,27 +715,51 @@ sub THZ_ReadAnswer($)
if ((length($data) > 4) and ($data !~ m/1003$/m )) # sometimes the first read gets a trunkated buffer, third read makes sure all the buffer is read.
{ my $buf2 = DevIo_SimpleReadWithTimeout($hash, 0.005);
Log3($hash->{NAME}, 5, "triple read activated $data");
Log3($hash->{NAME}, 5, "3rd read activated $data");
if(defined($buf2))
{
$buf = ($buf . $buf2) ;
$data = uc(unpack('H*', $buf));
Log3($hash->{NAME}, 5, "triple read result with buf2 $data");
Log3($hash->{NAME}, 5, "3rd read result with buf2 $data");
}
}
if ((length($data) > 4) and ($data !~ m/1003$/m )) # sometimes the first read gets a trunkated buffer, fourth read makes sure all the buffer is read.
{ my $buf3 = DevIo_SimpleReadWithTimeout($hash, 0.005);
Log3($hash->{NAME}, 5, "quadruple read activated $data");
Log3($hash->{NAME}, 5, "4th read activated $data");
if(defined($buf3))
{
$buf = ($buf . $buf3) ;
$data = uc(unpack('H*', $buf));
Log3($hash->{NAME}, 5, "quadruple read result with buf3 $data");
Log3($hash->{NAME}, 5, "4th read result with buf3 $data");
}
}
if ((length($data) > 4) and ($data !~ m/1003$/m )) # sometimes the first read gets a trunkated buffer, fourth read makes sure all the buffer is read.
{ my $buf4 = DevIo_SimpleReadWithTimeout($hash, 0.005);
Log3($hash->{NAME}, 5, "5th read activated $data");
if(defined($buf4))
{
$buf = ($buf . $buf4) ;
$data = uc(unpack('H*', $buf));
Log3($hash->{NAME}, 5, "5th read result with buf4 $data");
}
}
if ((length($data) > 4) and ($data !~ m/1003$/m )) # sometimes the first read gets a trunkated buffer, fourth read makes sure all the buffer is read.
{ my $buf5 = DevIo_SimpleReadWithTimeout($hash, 0.005);
Log3($hash->{NAME}, 5, "6th read activated $data");
if(defined($buf5))
{
$buf = ($buf . $buf5) ;
$data = uc(unpack('H*', $buf));
Log3($hash->{NAME}, 5, "6th read result with buf5 $data");
}
}
Log3 $hash->{NAME}, 5, "THZ_ReadAnswer: uc unpack: '$data'";
return (undef, $data);