mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-12 16:46:35 +00:00
feature: added postproc ability to classdef in 66_ECMD.pm (Boris, Heinz)
git-svn-id: https://svn.fhem.de/fhem/trunk@1100 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
68228ee099
commit
5ec1ea64af
@ -1,4 +1,4 @@
|
||||
- CVS
|
||||
- SVN
|
||||
- bugfix: applying smallscreen attributes to firefox/opera
|
||||
- feature: CUL_TX added (thanks to Peterp)
|
||||
- feature: TCM120/TCM310 + EnOcean parser added
|
||||
@ -11,6 +11,7 @@
|
||||
- feature: CUL directio mode (No Device::SerialPort needed)
|
||||
- feature: FritzBox 7270 ZIP file
|
||||
- buxgfix: prevent fhem from stalling if telnet times out in 66_ECMD.pm
|
||||
- feature: added postproc ability to classdef in 66_ECMD.pm (Boris, Heinz)
|
||||
- feature: FHEMWEB longpoll mode, small fixes, tuned smallscreen mode
|
||||
- feature: average module added
|
||||
- change: moved the berliOS CVS repository to a sourceforge SVN repository
|
||||
|
@ -510,15 +510,29 @@ ECMD_EvalClassDef($$$)
|
||||
Log 1, "$name: command for $cmd $cmdname is not a perl command.";
|
||||
next;
|
||||
}
|
||||
$arg =~ s/^(\\\n|[ \t])*//; # Strip space or \\n at the begginning
|
||||
$arg =~ s/^(\\\n|[ \t])*//; # Strip space or \\n at the beginning
|
||||
$arg =~ s/[ \t]*$//;
|
||||
if($cmd eq "set") {
|
||||
Log 5, "$name: set $cmdname defined as $arg";
|
||||
Log 5, "$name: set $cmdname command defined as $arg";
|
||||
$hash->{fhem}{classDefs}{$classname}{sets}{$cmdname}{cmd}= $arg;
|
||||
} elsif($cmd eq "get") {
|
||||
Log 5, "$name: get $cmdname defined as $arg";
|
||||
Log 5, "$name: get $cmdname command defined as $arg";
|
||||
$hash->{fhem}{classDefs}{$classname}{gets}{$cmdname}{cmd}= $arg;
|
||||
}
|
||||
} elsif($spec eq "postproc") {
|
||||
if($arg !~ m/^{.*}$/s) {
|
||||
Log 1, "$name: postproc command for $cmd $cmdname is not a perl command.";
|
||||
next;
|
||||
}
|
||||
$arg =~ s/^(\\\n|[ \t])*//; # Strip space or \\n at the beginning
|
||||
$arg =~ s/[ \t]*$//;
|
||||
if($cmd eq "set") {
|
||||
Log 5, "$name: set $cmdname postprocessor defined as $arg";
|
||||
$hash->{fhem}{classDefs}{$classname}{sets}{$cmdname}{postproc}= $arg;
|
||||
} elsif($cmd eq "get") {
|
||||
Log 5, "$name: get $cmdname postprocessor defined as $arg";
|
||||
$hash->{fhem}{classDefs}{$classname}{gets}{$cmdname}{postproc}= $arg;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Log 1, "$name: illegal tag $cmd for class $classname in file $filename.";
|
||||
|
@ -35,6 +35,7 @@ ECMDDevice_Initialize($)
|
||||
$hash->{AttrList} = "loglevel 0,1,2,3,4,5";
|
||||
}
|
||||
|
||||
###################################
|
||||
sub
|
||||
ECMDDevice_AnalyzeCommand($)
|
||||
{
|
||||
@ -95,6 +96,29 @@ ECMDDevice_Changed($$$)
|
||||
}
|
||||
|
||||
###################################
|
||||
sub
|
||||
ECMDDevice_PostProc($$$)
|
||||
{
|
||||
my ($hash, $postproc, $value)= @_;
|
||||
|
||||
# the following lines are commented out because we do not want specials to be evaluated
|
||||
# this is mainly due to the unwanted substitution of single semicolons by double semicolons
|
||||
#my %specials= ECMDDevice_DeviceParams2Specials($hash);
|
||||
#my $command= EvalSpecials($postproc, %specials);
|
||||
# we pass the command verbatim instead
|
||||
my $command= $postproc;
|
||||
|
||||
if($postproc) {
|
||||
$_= $value;
|
||||
Log 5, "Postprocessing $value with perl command $command.";
|
||||
$value= AnalyzePerlCommand(undef, $command);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
###################################
|
||||
|
||||
sub
|
||||
ECMDDevice_Get($@)
|
||||
{
|
||||
@ -113,6 +137,7 @@ ECMDDevice_Get($@)
|
||||
|
||||
my $ecmd= $IOhash->{fhem}{classDefs}{$classname}{gets}{$cmdname}{cmd};
|
||||
my $params= $IOhash->{fhem}{classDefs}{$classname}{gets}{$cmdname}{params};
|
||||
my $postproc= $IOhash->{fhem}{classDefs}{$classname}{gets}{$cmdname}{postproc};
|
||||
|
||||
my %specials= ECMDDevice_DeviceParams2Specials($hash);
|
||||
# add specials for command
|
||||
@ -133,6 +158,8 @@ ECMDDevice_Get($@)
|
||||
|
||||
my $v= IOWrite($hash, $r);
|
||||
|
||||
$v= ECMDDevice_PostProc($hash, $postproc, $v);
|
||||
|
||||
return ECMDDevice_Changed($hash, $cmdname, $v);
|
||||
}
|
||||
|
||||
@ -157,6 +184,7 @@ ECMDDevice_Set($@)
|
||||
|
||||
my $ecmd= $IOhash->{fhem}{classDefs}{$classname}{sets}{$cmdname}{cmd};
|
||||
my $params= $IOhash->{fhem}{classDefs}{$classname}{sets}{$cmdname}{params};
|
||||
my $postproc= $IOhash->{fhem}{classDefs}{$classname}{sets}{$cmdname}{postproc};
|
||||
|
||||
my %specials= ECMDDevice_DeviceParams2Specials($hash);
|
||||
# add specials for command
|
||||
@ -175,7 +203,10 @@ ECMDDevice_Set($@)
|
||||
my $r = ECMDDevice_AnalyzeCommand($ecmd);
|
||||
|
||||
my $v= IOWrite($hash, $r);
|
||||
$v= join(" ", @a) if($params);
|
||||
|
||||
$v= ECMDDevice_PostProc($hash, $postproc, $v);
|
||||
|
||||
# $v= join(" ", @a) if($params);
|
||||
|
||||
return ECMDDevice_Changed($hash, $cmdname, $v);
|
||||
|
||||
|
@ -4602,11 +4602,20 @@ Attributes:<br>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<code>set <name> params <parameter1> [<parameter2> [<parameter3> ... ]]</code><br>
|
||||
<code>get <name> params <parameter1> [<parameter2> [<parameter3> ... ]]</code>
|
||||
<code>set <commandname> postproc { <perl command> }</code><br>
|
||||
<code>get <commandname> postproc { <perl command> }</code>
|
||||
<br><br>
|
||||
Declares a postprocessor for the command <code><commandname></code>.
|
||||
<br><br>
|
||||
</li>
|
||||
|
||||
|
||||
<li>
|
||||
<code>set <commandname> params <parameter1> [<parameter2> [<parameter3> ... ]]</code><br>
|
||||
<code>get <commandname> params <parameter1> [<parameter2> [<parameter3> ... ]]</code>
|
||||
<br><br>
|
||||
Declares the names of the named parameters that must be present in the
|
||||
set or get command <code><name></code></a>. Be careful not to use a parameter name that
|
||||
set or get command <code><commandname></code></a>. Be careful not to use a parameter name that
|
||||
is already used in the device definition (see <code>params</code> above).
|
||||
<br><br>
|
||||
</li>
|
||||
@ -4634,9 +4643,15 @@ Attributes:<br>
|
||||
|
||||
<li>If in doubt what happens, run the commands with loglevel 5 and
|
||||
observe the log file.</li>
|
||||
</ul><br><br>
|
||||
|
||||
</ul>
|
||||
</ul>
|
||||
Neither apply the rules outlined in the <a href="#perl">documentation of perl specials</a>
|
||||
for the <code><perl command></code> in the postprocessor definitions nor can it contain macros.
|
||||
This is to avoid undesired side effects from e.g. doubling of semicolons.<br><br>
|
||||
|
||||
The <code>perl command</code> acts on <code>$_</code>. The result of the perl command is the
|
||||
final result of the get or set command.
|
||||
</ul>
|
||||
|
||||
<a name="ECMDDevice"></a>
|
||||
<h3>ECMDDevice</h3>
|
||||
@ -4731,7 +4746,7 @@ Attributes:<br>
|
||||
|
||||
<b>Example 2</b>
|
||||
<br><br>
|
||||
<ul>
|
||||
<ul>
|
||||
The following example shows how to switch a relais driven by pin 3 (bit mask 0x08) of I/O port 2 on for
|
||||
one second and then off again.<br><br>
|
||||
|
||||
@ -4739,6 +4754,7 @@ Attributes:<br>
|
||||
<code>
|
||||
params pinmask<br>
|
||||
set on cmd {"io set ddr 2 ff\nioset port 2 0%pinmask\nwait 1000\nio set port 2 00"}<br>
|
||||
set on postproc {s/OK;OK;OK;OK/success/; "$_" eq "success" ? "ok" : "error"; }<br>
|
||||
</code>
|
||||
<br>
|
||||
In the fhem configuration file or on the fhem command line we do the following:<br><br>
|
||||
@ -4753,7 +4769,11 @@ Attributes:<br>
|
||||
is replaced by <code>8</code> to yield
|
||||
<code>"io set ddr 2 ff\nioset port 2 08\nwait 1000\nio set port 2 00"</code> after macro substitution. Perl
|
||||
evaluates this to a literal string which is send as a plain ethersex command to the AVR-NET-IO line by line.
|
||||
<br><br>
|
||||
<br>
|
||||
For any of the four plain ethersex commands, the AVR-NET-IO returns the string <code>OK</code>. They are
|
||||
concatenated and separated by semicolons. The postprocessor takes the result from <code>$_</code>,
|
||||
substitutes it by the string <code>success</code> if it is <code>OK;OK;OK;OK</code>, and then either
|
||||
returns the string <code>ok</code> or the string <code>error</code>.
|
||||
|
||||
</ul>
|
||||
</ul>
|
||||
|
Loading…
x
Reference in New Issue
Block a user