diff --git a/fhem/CHANGED b/fhem/CHANGED
index 8ca05a6a2..8e9cb56a5 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -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
diff --git a/fhem/FHEM/66_ECMD.pm b/fhem/FHEM/66_ECMD.pm
index 7b4f7102a..c84e4fcf5 100644
--- a/fhem/FHEM/66_ECMD.pm
+++ b/fhem/FHEM/66_ECMD.pm
@@ -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.";
diff --git a/fhem/FHEM/67_ECMDDevice.pm b/fhem/FHEM/67_ECMDDevice.pm
index 406fb8a3b..e0537c125 100644
--- a/fhem/FHEM/67_ECMDDevice.pm
+++ b/fhem/FHEM/67_ECMDDevice.pm
@@ -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);
diff --git a/fhem/docs/commandref.html b/fhem/docs/commandref.html
index 9c2706336..d861810b7 100644
--- a/fhem/docs/commandref.html
+++ b/fhem/docs/commandref.html
@@ -4602,11 +4602,20 @@ Attributes:
set <name> params <parameter1> [<parameter2> [<parameter3> ... ]]
get <name> params <parameter1> [<parameter2> [<parameter3> ... ]]
+ set <commandname> postproc { <perl command> }
get <commandname> postproc { <perl command> }
+ <commandname>
.
+ set <commandname> params <parameter1> [<parameter2> [<parameter3> ... ]]
get <commandname> params <parameter1> [<parameter2> [<parameter3> ... ]]
<name>
. Be careful not to use a parameter name that
+ set or get command <commandname>
. Be careful not to use a parameter name that
is already used in the device definition (see params
above).
<perl command>
in the postprocessor definitions nor can it contain macros.
+ This is to avoid undesired side effects from e.g. doubling of semicolons.perl command
acts on $_
. The result of the perl command is the
+ final result of the get or set command.
+
params pinmask
set on cmd {"io set ddr 2 ff\nioset port 2 0%pinmask\nwait 1000\nio set port 2 00"}
+ set on postproc {s/OK;OK;OK;OK/success/; "$_" eq "success" ? "ok" : "error"; }
8
to yield
"io set ddr 2 ff\nioset port 2 08\nwait 1000\nio set port 2 00"
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.
- OK
. They are
+ concatenated and separated by semicolons. The postprocessor takes the result from $_
,
+ substitutes it by the string success
if it is OK;OK;OK;OK
, and then either
+ returns the string ok
or the string error
.