mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
98_GAEBUS.pm: handling of timeouts in BlockingCall improved
git-svn-id: https://svn.fhem.de/fhem/trunk@9447 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
342f2bcfff
commit
2ecd611a08
@ -16,6 +16,9 @@
|
|||||||
# 15.09.2015 : A.Goebel : get rid of perl warnings when attribute value is empty
|
# 15.09.2015 : A.Goebel : get rid of perl warnings when attribute value is empty
|
||||||
# 16.09.2015 : A.Goebel : allow write to parameters protected by #install
|
# 16.09.2015 : A.Goebel : allow write to parameters protected by #install
|
||||||
# 21.09.2015 : A.Goebel : implement BlockingCall Interface
|
# 21.09.2015 : A.Goebel : implement BlockingCall Interface
|
||||||
|
# 07.10.2015 : A.Goebel : beautify and complete commandref
|
||||||
|
# 12.10.2015 : A.Goebel : fix handling of timeouts in BlockingCall Interface (additional parameter in doEbusCmd forces restart (no shutdown restart))
|
||||||
|
# timeout for reads increased
|
||||||
|
|
||||||
|
|
||||||
package main;
|
package main;
|
||||||
@ -36,7 +39,7 @@ sub GAEBUS_SimpleWrite(@);
|
|||||||
sub GAEBUS_Disconnected($);
|
sub GAEBUS_Disconnected($);
|
||||||
sub GAEBUS_Shutdown($);
|
sub GAEBUS_Shutdown($);
|
||||||
|
|
||||||
sub GAEBUS_doEbusCmd($$$$$$);
|
sub GAEBUS_doEbusCmd($$$$$$$);
|
||||||
sub GAEBUS_GetUpdates($);
|
sub GAEBUS_GetUpdates($);
|
||||||
|
|
||||||
sub GAEBUS_GetUpdatesDoit($);
|
sub GAEBUS_GetUpdatesDoit($);
|
||||||
@ -289,7 +292,7 @@ GAEBUS_Set($@)
|
|||||||
my $readingname = $attr{$name}{$oneattr};
|
my $readingname = $attr{$name}{$oneattr};
|
||||||
next if ($readingname ne $type);
|
next if ($readingname ne $type);
|
||||||
|
|
||||||
my $answer = GAEBUS_doEbusCmd ($hash, "w", $readingname, $oneattr, $arg, "");
|
my $answer = GAEBUS_doEbusCmd ($hash, "w", $readingname, $oneattr, $arg, "", 0);
|
||||||
return "$answer";
|
return "$answer";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -374,7 +377,7 @@ GAEBUS_Get($@)
|
|||||||
Log3 ($name, 4, "$name Get name $readingname");
|
Log3 ($name, 4, "$name Get name $readingname");
|
||||||
Log3 ($name, 4, "$name Get cmd r $readingcmdname");
|
Log3 ($name, 4, "$name Get cmd r $readingcmdname");
|
||||||
|
|
||||||
my $answer = GAEBUS_doEbusCmd ($hash, "r", $readingname, $readingcmdname, "", $cmdaddon);
|
my $answer = GAEBUS_doEbusCmd ($hash, "r", $readingname, $readingcmdname, "", $cmdaddon, 0);
|
||||||
|
|
||||||
#return "$answer";
|
#return "$answer";
|
||||||
return undef;
|
return undef;
|
||||||
@ -390,7 +393,7 @@ GAEBUS_Get($@)
|
|||||||
|
|
||||||
Log3 ($name, 3, "$name get cmd v $readingcmdname");
|
Log3 ($name, 3, "$name get cmd v $readingcmdname");
|
||||||
|
|
||||||
my $answer = GAEBUS_doEbusCmd ($hash, "v", $readingname, $readingcmdname, "", "");
|
my $answer = GAEBUS_doEbusCmd ($hash, "v", $readingname, $readingcmdname, "", "", 0);
|
||||||
#return (defined($answer ? $answer : ""));
|
#return (defined($answer ? $answer : ""));
|
||||||
return "$answer";
|
return "$answer";
|
||||||
|
|
||||||
@ -769,7 +772,44 @@ GAEBUS_ReadCSV($)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
GAEBUS_doEbusCmd($$$$$$)
|
GAEBUS_state($)
|
||||||
|
{
|
||||||
|
my $hash = shift;
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
my $answer = "";
|
||||||
|
my $actMessage = "";
|
||||||
|
|
||||||
|
if (($hash->{STATE} ne "Connected") or (!$hash->{TCPDev}->connected()) )
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
my $timeout = 10;
|
||||||
|
|
||||||
|
syswrite ($hash->{TCPDev}, "state\n");
|
||||||
|
if ($hash->{SELECTOR}->can_read($timeout))
|
||||||
|
{
|
||||||
|
sysread ($hash->{TCPDev}, $actMessage, 4096);
|
||||||
|
if ($actMessage =~ /^signal acquired/) {
|
||||||
|
$answer = "ok";
|
||||||
|
return "$answer";
|
||||||
|
} else {
|
||||||
|
chomp ($actMessage);
|
||||||
|
$answer = $actMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$answer = "no answer";
|
||||||
|
}
|
||||||
|
|
||||||
|
Log3 ($name, 2, "$name state $answer");
|
||||||
|
return "$answer";
|
||||||
|
}
|
||||||
|
|
||||||
|
sub
|
||||||
|
GAEBUS_doEbusCmd($$$$$$$)
|
||||||
{
|
{
|
||||||
my $hash = shift;
|
my $hash = shift;
|
||||||
my $action = shift; # "r" = set reading, "v" = verbose mode, "w" = write to ebus
|
my $action = shift; # "r" = set reading, "v" = verbose mode, "w" = write to ebus
|
||||||
@ -777,6 +817,7 @@ GAEBUS_doEbusCmd($$$$$$)
|
|||||||
my $readingcmdname = shift;
|
my $readingcmdname = shift;
|
||||||
my $writeValues = shift;
|
my $writeValues = shift;
|
||||||
my $cmdaddon = shift;
|
my $cmdaddon = shift;
|
||||||
|
my $inBlockingCall = shift;
|
||||||
my $actMessage;
|
my $actMessage;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
@ -786,11 +827,18 @@ GAEBUS_doEbusCmd($$$$$$)
|
|||||||
GAEBUS_CloseDev($hash);
|
GAEBUS_CloseDev($hash);
|
||||||
GAEBUS_OpenDev($hash,1);
|
GAEBUS_OpenDev($hash,1);
|
||||||
|
|
||||||
return undef unless ($hash->{STATE} eq "Connected");
|
if ($hash->{STATE} ne "Connected") {
|
||||||
|
if ($inBlockingCall) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#my $timeout = 1.8;
|
#my $timeout = 1.8;
|
||||||
my $timeout = 5.0;
|
my $timeout = 15.0;
|
||||||
$timeout = 10.0 if ($action eq "v");
|
$timeout = 10.0 if ($action eq "v");
|
||||||
$timeout = 10.0 if ($action eq "w");
|
$timeout = 10.0 if ($action eq "w");
|
||||||
|
|
||||||
@ -817,7 +865,7 @@ GAEBUS_doEbusCmd($$$$$$)
|
|||||||
|
|
||||||
Log3 ($name, 3, "$name execute $cmd");
|
Log3 ($name, 3, "$name execute $cmd");
|
||||||
|
|
||||||
if ($hash->{SELECTOR}->can_read(0))
|
if ($hash->{SELECTOR}->can_read(0.1))
|
||||||
{
|
{
|
||||||
sysread ($hash->{TCPDev}, $actMessage, 4096);
|
sysread ($hash->{TCPDev}, $actMessage, 4096);
|
||||||
$actMessage =~ s/\n//g;
|
$actMessage =~ s/\n//g;
|
||||||
@ -834,32 +882,38 @@ GAEBUS_doEbusCmd($$$$$$)
|
|||||||
|
|
||||||
Log3 ($name, 3, "$name answer $action $readingname $actMessage");
|
Log3 ($name, 3, "$name answer $action $readingname $actMessage");
|
||||||
|
|
||||||
unless ($actMessage =~ "Usage:") # pass Usage: directly
|
#unless ($actMessage =~ "Usage:") # pass Usage: directly
|
||||||
|
#{
|
||||||
|
# # no Usage: message
|
||||||
|
# unless ($actMessage =~ /^ERR:/) # pass ERR: message directly
|
||||||
|
# {
|
||||||
|
# # no ERR: message
|
||||||
|
# # = normal answer
|
||||||
|
# }
|
||||||
|
#}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
# no Usage: message
|
#return "timeout reading answer for ($readingname) $cmd";
|
||||||
unless ($actMessage =~ /^ERR:/) # pass ERR: message directly
|
|
||||||
{
|
$actMessage = "timeout reading answer for $cmd";
|
||||||
# no ERR: message
|
Log3 ($name, 2, "$name $actMessage");
|
||||||
# = normal answer
|
}
|
||||||
|
|
||||||
if ($action eq "r") {
|
if ($action eq "r") {
|
||||||
if (defined ($readingname)) {
|
if (defined ($readingname)) {
|
||||||
# BlockingCall changes
|
# BlockingCall changes
|
||||||
readingsSingleUpdate ($hash, $readingname, "$actMessage", 1);
|
readingsSingleUpdate ($hash, $readingname, "$actMessage", 1);
|
||||||
return $readingname."|".$actMessage;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($inBlockingCall) {
|
||||||
|
$actMessage = $readingname."|".$actMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
#return undef if ($action eq "r");
|
|
||||||
return $actMessage;
|
return $actMessage;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return "timeout reading answer for ($readingname) $cmd";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -901,6 +955,14 @@ GAEBUS_GetUpdatesDoit($)
|
|||||||
return "$name";
|
return "$name";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# syncronize with ebusd
|
||||||
|
|
||||||
|
my $state = GAEBUS_state($hash);
|
||||||
|
unless ($state eq "ok") {
|
||||||
|
Log3 ($name, 2, "$name: ebusd no signal ($state)");
|
||||||
|
return "$name";
|
||||||
|
}
|
||||||
|
|
||||||
foreach my $oneattr (keys %{$attr{$name}})
|
foreach my $oneattr (keys %{$attr{$name}})
|
||||||
{
|
{
|
||||||
# only for "r" commands
|
# only for "r" commands
|
||||||
@ -922,7 +984,7 @@ GAEBUS_GetUpdatesDoit($)
|
|||||||
#Log3 ($name, 2, "$name check modulo ".$hash->{UpdateCnt}." mod $doCntNo -> ".($hash->{UpdateCnt} % $doCntNo));
|
#Log3 ($name, 2, "$name check modulo ".$hash->{UpdateCnt}." mod $doCntNo -> ".($hash->{UpdateCnt} % $doCntNo));
|
||||||
if (($hash->{UpdateCnt} % $doCntNo) == 0)
|
if (($hash->{UpdateCnt} % $doCntNo) == 0)
|
||||||
{
|
{
|
||||||
$readingsToUpdate .= "|".GAEBUS_doEbusCmd ($hash, "r", $readingname, $oneattr, "", $cmdaddon);
|
$readingsToUpdate .= "|".GAEBUS_doEbusCmd ($hash, "r", $readingname, $oneattr, "", $cmdaddon, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
# limit number of reopens if ebusd cannot be reached
|
# limit number of reopens if ebusd cannot be reached
|
||||||
@ -999,8 +1061,6 @@ GAEBUS_GetUpdatesAborted($)
|
|||||||
The GAEBUS module is the representation of a Ebus connector in FHEM.
|
The GAEBUS module is the representation of a Ebus connector in FHEM.
|
||||||
The GAEBUS module is designed to connect to ebusd (ebus daemon) via a socket connection (default is port 8888) <br>
|
The GAEBUS module is designed to connect to ebusd (ebus daemon) via a socket connection (default is port 8888) <br>
|
||||||
|
|
||||||
</td><td>
|
|
||||||
<img src="IMG_0483.jpg" width="100%" height="100%"/>
|
|
||||||
</td></tr>
|
</td></tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
@ -1013,7 +1073,7 @@ GAEBUS_GetUpdatesAborted($)
|
|||||||
192.168.0.244:8888 or servername:8888. When using the standard port, the port can be omitted.
|
192.168.0.244:8888 or servername:8888. When using the standard port, the port can be omitted.
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
Example:<br>
|
Example:<br><br>
|
||||||
<code>define ebus1 GAEBUS localhost 300</code>
|
<code>define ebus1 GAEBUS localhost 300</code>
|
||||||
<br><br>
|
<br><br>
|
||||||
When initializing the object the configuration of the ebusd (.csv files from /etc/ebusd) are read.<br>
|
When initializing the object the configuration of the ebusd (.csv files from /etc/ebusd) are read.<br>
|
||||||
@ -1070,6 +1130,7 @@ GAEBUS_GetUpdatesAborted($)
|
|||||||
<li>ebusWritesEnabled 0,1<br>
|
<li>ebusWritesEnabled 0,1<br>
|
||||||
disable (0) or enable (1) that commands can be send to ebus devices<br>
|
disable (0) or enable (1) that commands can be send to ebus devices<br>
|
||||||
See also description for Set and Get<br>
|
See also description for Set and Get<br>
|
||||||
|
If Attribute is missing, default value is 0 (disable writes)<br>
|
||||||
</li><br>
|
</li><br>
|
||||||
<li>Attributes of the format<br>
|
<li>Attributes of the format<br>
|
||||||
<code>[r]~<class>~<variable-name>~<comment from csv></code><br>
|
<code>[r]~<class>~<variable-name>~<comment from csv></code><br>
|
||||||
@ -1078,6 +1139,8 @@ GAEBUS_GetUpdatesAborted($)
|
|||||||
The value assigned to an attribute specifies the name of the reading for this variable.<br>
|
The value assigned to an attribute specifies the name of the reading for this variable.<br>
|
||||||
The name of the reading can be suffixed by "<number>" which is a multiplicator for
|
The name of the reading can be suffixed by "<number>" which is a multiplicator for
|
||||||
the evaluation within the specified interval. (eg. OutsideTemp:3 will evaluate this reading every 3-th cycle)<br>
|
the evaluation within the specified interval. (eg. OutsideTemp:3 will evaluate this reading every 3-th cycle)<br>
|
||||||
|
All text followed the reading seperated by a blank is given as an additional parameter to ebusd.
|
||||||
|
This can be used to request a single value if more than one is retrieved from ebus.<br>
|
||||||
</li><br>
|
</li><br>
|
||||||
<li>Attributes of the format<br>
|
<li>Attributes of the format<br>
|
||||||
<code>[w]~<class>~<variable-name>~<comment from csv></code><br>
|
<code>[w]~<class>~<variable-name>~<comment from csv></code><br>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user