attribute nonl (no newline) added for ECMD device
git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@2154 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
@@ -46,7 +46,7 @@ ECMD_Initialize($)
|
|||||||
$hash->{GetFn} = "ECMD_Get";
|
$hash->{GetFn} = "ECMD_Get";
|
||||||
$hash->{SetFn} = "ECMD_Set";
|
$hash->{SetFn} = "ECMD_Set";
|
||||||
$hash->{AttrFn} = "ECMD_Attr";
|
$hash->{AttrFn} = "ECMD_Attr";
|
||||||
$hash->{AttrList}= "classdefs loglevel:0,1,2,3,4,5";
|
$hash->{AttrList}= "classdefs nonl loglevel:0,1,2,3,4,5";
|
||||||
}
|
}
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
@@ -422,9 +422,10 @@ ECMD_Get($@)
|
|||||||
|
|
||||||
if($cmd eq "raw") {
|
if($cmd eq "raw") {
|
||||||
return "get raw needs an argument" if(@a< 3);
|
return "get raw needs an argument" if(@a< 3);
|
||||||
|
my $nonl= AttrVal($name, "nonl", 0);
|
||||||
my $ecmd= join " ", @args;
|
my $ecmd= join " ", @args;
|
||||||
Log 5, $ecmd;
|
Log 5, $ecmd;
|
||||||
ECMD_SimpleWrite($hash, $ecmd);
|
ECMD_SimpleWrite($hash, $ecmd, $nonl);
|
||||||
($err, $msg) = ECMD_ReadAnswer($hash, "raw");
|
($err, $msg) = ECMD_ReadAnswer($hash, "raw");
|
||||||
return $err if($err);
|
return $err if($err);
|
||||||
} else {
|
} else {
|
||||||
@@ -496,7 +497,11 @@ ECMD_EvalClassDef($$$)
|
|||||||
Log 5, "$name: evaluating >$line<";
|
Log 5, "$name: evaluating >$line<";
|
||||||
# split line into command and definition
|
# split line into command and definition
|
||||||
my ($cmd, $def)= split("[ \t]+", $line, 2);
|
my ($cmd, $def)= split("[ \t]+", $line, 2);
|
||||||
if($cmd eq "params") {
|
if($cmd eq "nonl") {
|
||||||
|
Log 5, "$name: no newline";
|
||||||
|
$hash->{fhem}{classDefs}{$classname}{nonl}= 1;
|
||||||
|
}
|
||||||
|
elsif($cmd eq "params") {
|
||||||
Log 5, "$name: parameters are $def";
|
Log 5, "$name: parameters are $def";
|
||||||
$hash->{fhem}{classDefs}{$classname}{params}= $def;
|
$hash->{fhem}{classDefs}{$classname}{params}= $def;
|
||||||
} elsif($cmd eq "set" || $cmd eq "get") {
|
} elsif($cmd eq "set" || $cmd eq "get") {
|
||||||
@@ -618,9 +623,10 @@ ECMD_Write($$)
|
|||||||
my $answer;
|
my $answer;
|
||||||
my @r;
|
my @r;
|
||||||
my @ecmds= split "\n", $msg;
|
my @ecmds= split "\n", $msg;
|
||||||
|
my $nonl= AttrVal($hash->{NAME}, "nonl", 0);
|
||||||
foreach my $ecmd (@ecmds) {
|
foreach my $ecmd (@ecmds) {
|
||||||
Log 5, "$hash->{NAME} sending $ecmd";
|
Log 5, "$hash->{NAME} sending $ecmd";
|
||||||
ECMD_SimpleWrite($hash, $ecmd);
|
ECMD_SimpleWrite($hash, $ecmd, $nonl);
|
||||||
$answer= ECMD_ReadAnswer($hash, "$ecmd");
|
$answer= ECMD_ReadAnswer($hash, "$ecmd");
|
||||||
push @r, $answer;
|
push @r, $answer;
|
||||||
Log 5, $answer;
|
Log 5, $answer;
|
||||||
@@ -727,6 +733,9 @@ ECMD_Write($$)
|
|||||||
<li>classdefs<br>A colon-separated list of <classname>=<filename>.
|
<li>classdefs<br>A colon-separated list of <classname>=<filename>.
|
||||||
The list is automatically updated if a class definition is added. You can
|
The list is automatically updated if a class definition is added. You can
|
||||||
directly set the attribute.</li>
|
directly set the attribute.</li>
|
||||||
|
<li>nonl<br>A newline (\n) is automatically appended to every command string sent to the device
|
||||||
|
unless this attribute is set. Please note that newlines (\n) in a command string are interpreted
|
||||||
|
as separators to split the command string into several commands and are never literally sent.</li>
|
||||||
</ul>
|
</ul>
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
@@ -809,7 +818,7 @@ ECMD_Write($$)
|
|||||||
This is to avoid undesired side effects from e.g. doubling of semicolons.<br><br>-->
|
This is to avoid undesired side effects from e.g. doubling of semicolons.<br><br>-->
|
||||||
The rules outlined in the <a href="#perl">documentation of perl specials</a>
|
The rules outlined in the <a href="#perl">documentation of perl specials</a>
|
||||||
for the <code><perl command></code> in the postprocessor definitions apply.
|
for the <code><perl command></code> in the postprocessor definitions apply.
|
||||||
<b>Note:</b> Beware of undesired side effects from e.g. doubling of semicolon!
|
<b>Note:</b> Beware of undesired side effects from e.g. doubling of semicolons!
|
||||||
|
|
||||||
The <code>perl command</code> acts on <code>$_</code>. The result of the perl command is the
|
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.
|
final result of the get or set command.
|
||||||
|
|||||||
@@ -402,8 +402,19 @@ ECMDDevice_Define($$)
|
|||||||
The set command is evaluated as follows: <code>%pinmask</code>
|
The set command is evaluated as follows: <code>%pinmask</code>
|
||||||
is replaced by <code>8</code> to yield
|
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
|
<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.
|
evaluates this to a literal string. This string is split into lines (without trailing newline characters)
|
||||||
<br>
|
<code>
|
||||||
|
<ul>
|
||||||
|
<li>io set ddr 2 ff</li>
|
||||||
|
<li>ioset port 2 08</li>
|
||||||
|
<li>wait 1000</li>
|
||||||
|
<li>io set port 2 00</li>
|
||||||
|
</ul>
|
||||||
|
</code>
|
||||||
|
These lines are sent as a plain ethersex commands to the AVR-NET-IO one by one. Each line is terminated with
|
||||||
|
a newline character unless <a href="#ECMDattr">the <code>nonl</code> attribute of the ECMDDevice</a> is set. After
|
||||||
|
each line the answer from the ECMDDevice is read back. They are concatenated with newlines and returned
|
||||||
|
for further processing, e.g. by the <code>postproc</code> command.
|
||||||
For any of the four plain ethersex commands, the AVR-NET-IO returns the string <code>OK</code>. They are
|
For any of the four plain ethersex commands, the AVR-NET-IO returns the string <code>OK</code>. They are
|
||||||
concatenated and separated by line breaks (\n). The postprocessor takes the result from <code>$_</code>,
|
concatenated and separated by line breaks (\n). The postprocessor takes the result from <code>$_</code>,
|
||||||
substitutes it by the string <code>success</code> if it is <code>OK\nOK\nOK\nOK</code>, and then either
|
substitutes it by the string <code>success</code> if it is <code>OK\nOK\nOK\nOK</code>, and then either
|
||||||
|
|||||||
Reference in New Issue
Block a user