2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-08 19:32:42 +00:00

THZ: fix2 old tecalor from joerg with fast nuc

git-svn-id: https://svn.fhem.de/fhem/trunk@26120 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
immi 2022-06-05 13:13:44 +00:00
parent 24bfe8a933
commit 9dc5b23558

View File

@ -2,7 +2,7 @@
# 00_THZ
# $Id$
# by immi 05/2022
my $thzversion = "0.201";
my $thzversion = "0.202";
# this code is based on the hard work of Robert; I just tried to port it
# http://robert.penz.name/heat-pump-lwz/
########################################################################################
@ -986,7 +986,7 @@ sub THZ_Refresh_all_gets($) {
# my %par = (hash => $hash, command => $cmdhash, NAME => $hash->{NAME} ); #does not group in apptime
InternalTimer((gettimeofday() + $timedelay), "THZ_GetRefresh", \%par, 0); #increment 0.6 $timedelay++
$timedelay += 2; #0.6 seconds were ok but considering winter 2017/2018 I prefer to increase
$timedelay += 2 if (AttrVal($hash->{NAME}, "firmware" , "4.39") =~ /^2/); # I added 2 more seconds for joerg 05/2022
$timedelay += 5 if (AttrVal($hash->{NAME}, "firmware" , "4.39") =~ /^2/); # I added 5 more seconds for joerg 05/2022
}
}
@ -999,18 +999,23 @@ sub THZ_Refresh_all_gets($) {
# it get the intervall directly from a attribute; the register with interval_command ne 0 will keep on refreshing
########################################################################################
sub THZ_GetRefresh($) {
my ($par)=@_;
my $hash=$par->{hash};
my $command=$par->{command};
my ($par)=@_;
my $hash=$par->{hash};
my $command=$par->{command};
my $name =$hash->{NAME};
if (ReadingsAge($name ,'z_Last_fhem_err', 100) < 100) {
Log3 $hash, 5, "[$name] THZ_GetRefresh($command) rescheduled (stop 100s after one error)";
if (ReadingsAge($name ,'z_Last_fhem_err', 120) < 120) {
Log3 $hash, 5, "[$name] THZ_GetRefresh($command) rescheduled (stop 120s after one error)";
InternalTimer(gettimeofday() + 200, "THZ_GetRefresh", $par, 1);
return;
}
if (ReadingsAge($name ,$command, 41) < 41) {
Log3 $hash, 5, "[$name] THZ_GetRefresh($command) rescheduled (the reading has been updated in the last 40s)";
InternalTimer(gettimeofday() + 300, "THZ_GetRefresh", $par, 1);
return;
}
if (AttrVal($name, "nonblocking" , "0") =~ /1/ ) {
if (AttrVal($name, "nonblocking" , "0") =~ /1/ ) {
if (!(exists($hash->{helper}{RUNNING_PID}))) {
DevIo_CloseDev($hash); #close device in parent process
#$hash->{STATE}="disconnected";
@ -1446,7 +1451,7 @@ sub THZ_Get($@) {
my ($seconds, $microseconds) = gettimeofday();
$seconds= abs($seconds - time_str2num(ReadingsTimestamp($name, $parent, "1970-01-01 01:00:00")));
my $risultato=ReadingsVal($name, $parent, 0);
$risultato=THZ_Get($hash, $name, $parent) if ($seconds > 20 ); #update of the parent: if under 20sec use the current value
$risultato=THZ_Get($hash, $name, $parent) if ($seconds > 29 ); #update of the parent: if under 29sec use the current value
#$risultato=THZ_Parse1($hash,"B81700C800BE00A001C20190006402010000E601D602");
my $parenthash=$gets{$parent}; my $parsingrule = $parsinghash{$parenthash->{type}};
my $i=0;
@ -1513,7 +1518,7 @@ sub THZ_Get_Comunication($$) {
($err, $msg) = THZ_ReadAnswer($hash);
if (defined($err)) {$err .= " THZ_Get_Com: error found at step1 "; select(undef, undef, undef, 0.1); return($err, $msg) ;}
# Expectedanswer1 is "1002", DLE data link escape -- STX start of text
if ($msg eq "10") {($err, $msg) = THZ_ReadAnswer($hash);} # read again sometimes "10" pause "02"
if ($msg eq "10") {select(undef, undef, undef, 0.01) if (AttrVal($hash->{NAME}, "firmware" , "4.39") =~ /^2/); ($err, $msg) = THZ_ReadAnswer($hash);} # read again sometimes "10" pause "02"
if ($msg ne "1002" and $msg ne "02") {$err .= " THZ_Get_Com: error found at step1 $msg"; $err .=" NAK!!" if ($msg eq "15"); select(undef, undef, undef, 0.1); return($err, $msg) ;}
# ---------step2 send DLE data link escape
@ -1542,16 +1547,16 @@ sub THZ_ReadAnswer($) {
my $rtimeout = (AttrVal($name, "simpleReadTimeout", "0.8"));
$rtimeout +=1 if (AttrVal($hash->{NAME}, "firmware" , "4.39") =~ /^2/);
$rtimeout = minNum($rtimeout,1.8) if (AttrVal($name, "nonblocking", "0") eq 0); # set to max 1.8s if nonblocking disabled
my $count = 0; my $countmax = 40;
my $count = 0; my $countmax = 300;
while ((!defined($buf)) and ($count <= $countmax)) {
if ($^O =~ /Win/){
select(undef, undef, undef, 0.005); ###delay of 5 ms for windows-OS, because SimpleReadWithTimeout does not wait
select(undef, undef, undef, 0.02) if (AttrVal($hash->{NAME}, "firmware" , "4.39") =~ /^2/); # possible fix for joerg may2022, add 20ms wait time to the above -----
select(undef, undef, undef, 0.002); ###delay of 2 ms for windows-OS, because SimpleReadWithTimeout does not wait
select(undef, undef, undef, 0.005) if (AttrVal($hash->{NAME}, "firmware" , "4.39") =~ /^2/); # possible fix for joerg may2022, add 5ms wait time to the above -----
$buf = DevIo_DoSimpleRead($hash);
$buf = undef if (length($buf)==0);
}
else {
select(undef, undef, undef, 0.02) if (AttrVal($hash->{NAME}, "firmware" , "4.39") =~ /^2/); # possible fix for joerg may2022, add 20ms wait time to the above -----
select(undef, undef, undef, 0.005) if (AttrVal($hash->{NAME}, "firmware" , "4.39") =~ /^2/); # possible fix for joerg may2022, add 5ms wait time to the above -----
$buf = DevIo_SimpleReadWithTimeout($hash, (minNum($count,1)*$rtimeout/$countmax + 0.001)); ##pay attention with DevIo_SimpleRead: it closes the connection if no answe given; DevIo_SimpleReadWithTimeout does not close
}
$count ++;