2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 18:59:33 +00:00

integrated more OWServer/OWDevice nonblocking patches

git-svn-id: https://svn.fhem.de/fhem/trunk@4458 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
borisneubert 2013-12-25 12:33:00 +00:00
parent df465f23f5
commit 61f568a252
2 changed files with 54 additions and 40 deletions

View File

@ -244,7 +244,7 @@ OWServer_Read($@)
{
my ($hash,$path)= @_;
return undef unless(defined($hash->{fhem}{owserver}));
return undef unless(defined($hash->{fhem}{owserver}) || $hash->{LAST_READ_FAILED});
my $ret= undef;
@ -260,7 +260,7 @@ OWServer_Read($@)
return undef;
}
InternalTimer(gettimeofday()+10, "OWServer_TimeoutChild", $pid, 0);
InternalTimer(gettimeofday()+6, "OWServer_TimeoutChild", $pid, 0);
if($pid == 0) {
close READER;
$ret= OWNet::read($hash->{DEF},$path);
@ -286,16 +286,21 @@ OWServer_Read($@)
if( $nfound ) {
chomp($ret= <READER>);
RemoveInternalTimer($pid);
OWServer_OpenDev($hash) if( $hash->{LAST_READ_FAILED} );
$hash->{LAST_READ_FAILED} = 0;
} else {
Log3 undef, 1, "OWServer: read timeout for child $pid";
$hash->{READ_FAILED} = 0 if( !$hash->{READ_FAILED} );
$hash->{READ_FAILED}++;
$hash->{NR_READ_FAILED} = 0 if( !$hash->{NR_READ_FAILED} );
$hash->{NR_READ_FAILED}++;
OWServer_CloseDev($hash) if( !$hash->{LAST_READ_FAILED} );
$hash->{LAST_READ_FAILED} = 1;
}
close READER;
} else {
$ret= $hash->{fhem}{owserver}->read($path);
$ret =~ s/^\s+//g if(defined($ret));
$hash->{LAST_READ_FAILED} = 0;
}
# if a device does not exist, the server returns undef
@ -319,7 +324,10 @@ OWServer_Write($@)
{
my ($hash,$path,$value)= @_;
return undef if($hash->{LAST_READ_FAILED});
return undef unless(defined($hash->{fhem}{owserver}));
return $hash->{fhem}{owserver}->write($path,$value);
}
@ -329,7 +337,10 @@ OWServer_Dir($@)
{
my ($hash,$path)= @_;
return undef if($hash->{LAST_READ_FAILED});
return undef unless(defined($hash->{fhem}{owserver}));
$path= ($path) ? $path : "/";
return $hash->{fhem}{owserver}->dir($path);
}
@ -340,6 +351,8 @@ OWServer_Find($@)
{
my ($hash,$slave)= @_;
return undef if($hash->{LAST_READ_FAILED});
return undef unless(defined($hash->{fhem}{owserver}));
my $owserver= $hash->{fhem}{owserver};

View File

@ -416,6 +416,14 @@ OWDevice_ReadFromServer($$@)
$ret = &{$modules{$iohash->{TYPE}}{FindFn}}($iohash, @a);
}
use strict "refs";
if( $iohash->{LAST_READ_FAILED} ) {
$hash->{NR_READ_FAILED} = 0 if( !$hash->{NR_READ_FAILED} );
$hash->{NR_READ_FAILED}++;
$hash->{LAST_READ_FAILED} = 1;
} else {
$hash->{LAST_READ_FAILED} = 0;
}
return $ret;
}
@ -430,9 +438,9 @@ OWDevice_ReadValue($$) {
my $cache= (AttrVal($hash->{NAME},"uncached","")) ? "/uncached" : "";
my $path = "$cache/$address/$reading";
$path .= AttrVal($hash->{NAME},"resolution","") if( $reading eq "temperature" );
my ($seconds, $microseconds) = gettimeofday();
#my ($seconds, $microseconds) = gettimeofday();
my $value= OWDevice_ReadFromServer($hash,"read",$path);
my ($seconds2, $microseconds2) = gettimeofday();
#my ($seconds2, $microseconds2) = gettimeofday();
#my $msec = sprintf( "%03d msec", (($seconds2-$seconds)*1000000 + $microseconds2-$microseconds)/1000 );
#Debug "$path => $value; $msec";
if($interface ne "id") {
@ -471,47 +479,40 @@ OWDevice_UpdateValues($) {
my $state;
if($#polls>=0) {
my $address= $hash->{fhem}{address};
my $read_failed = 0;
readingsBeginUpdate($hash);
foreach my $reading (@polls) {
my $value= OWDevice_ReadValue($hash,$reading);
if(defined($value)) {
readingsBulkUpdate($hash,$reading,$value);
} else {
$read_failed = 1;
}
readingsBulkUpdate($hash,$reading,$value) if(defined($value));
}
if( !$read_failed ) {
if(@state) {
foreach my $reading (@state) {
my $value= ReadingsVal($hash->{NAME},$reading,undef);
if(defined($value)) {
$state .= "$reading: $value ";
} else {
$state .= "$reading: n/a ";
}
if(@state) {
foreach my $reading (@state) {
my $value= ReadingsVal($hash->{NAME},$reading,undef);
if(defined($value)) {
$state .= "$reading: $value ";
} else {
$state .= "$reading: n/a ";
}
}
if($alerting) {
my $dir= OWDevice_ReadFromServer($hash,"dir","/alarm/");
my $alarm= (defined($dir) && $dir =~ m/$address/) ? 1 :0;
readingsBulkUpdate($hash,"alarm",$alarm);
$state .= "alarm: $alarm";
}
if($interface eq "id") {
my $dir= OWDevice_ReadFromServer($hash,"dir","/");
my $present= (defined($dir) && $dir =~ m/$address/) ? 1 :0;
readingsBulkUpdate($hash,"present",$present);
$state .= "present: $present";
my $bus= OWDevice_ReadFromServer($hash,"find",$address);
my $location= (defined($bus)) ? $bus :"absent";
readingsBulkUpdate($hash,"location",$location);
}
$state =~ s/\s+$//;
readingsBulkUpdate($hash,"state",$state,0);
} else {
readingsBulkUpdate($hash,"state","read failed",0);
}
if($alerting
&& !$hash->{LAST_READ_FAILED}) {
my $dir= OWDevice_ReadFromServer($hash,"dir","/alarm/");
my $alarm= (defined($dir) && $dir =~ m/$address/) ? 1 :0;
readingsBulkUpdate($hash,"alarm",$alarm);
$state .= "alarm: $alarm";
}
if($interface eq "id"
&& !$hash->{LAST_READ_FAILED}) {
my $dir= OWDevice_ReadFromServer($hash,"dir","/");
my $present= (defined($dir) && $dir =~ m/$address/) ? 1 :0;
readingsBulkUpdate($hash,"present",$present);
$state .= "present: $present";
my $bus= OWDevice_ReadFromServer($hash,"find",$address);
my $location= (defined($bus)) ? $bus :"absent";
readingsBulkUpdate($hash,"location",$location);
}
$state =~ s/\s+$//;
readingsBulkUpdate($hash,"state",$state,0);
readingsEndUpdate($hash,1);
}
RemoveInternalTimer($hash);