2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-03 23:06:37 +00:00

attribute nonl (no newline) added for ECMD device

git-svn-id: https://svn.fhem.de/fhem/trunk@2154 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
borisneubert 2012-11-22 05:44:20 +00:00
parent 4ae8d769ee
commit af7b60ee77
2 changed files with 27 additions and 7 deletions

View File

@ -46,7 +46,7 @@ ECMD_Initialize($)
$hash->{GetFn} = "ECMD_Get";
$hash->{SetFn} = "ECMD_Set";
$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") {
return "get raw needs an argument" if(@a< 3);
my $nonl= AttrVal($name, "nonl", 0);
my $ecmd= join " ", @args;
Log 5, $ecmd;
ECMD_SimpleWrite($hash, $ecmd);
ECMD_SimpleWrite($hash, $ecmd, $nonl);
($err, $msg) = ECMD_ReadAnswer($hash, "raw");
return $err if($err);
} else {
@ -496,7 +497,11 @@ ECMD_EvalClassDef($$$)
Log 5, "$name: evaluating >$line<";
# split line into command and definition
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";
$hash->{fhem}{classDefs}{$classname}{params}= $def;
} elsif($cmd eq "set" || $cmd eq "get") {
@ -618,9 +623,10 @@ ECMD_Write($$)
my $answer;
my @r;
my @ecmds= split "\n", $msg;
my $nonl= AttrVal($hash->{NAME}, "nonl", 0);
foreach my $ecmd (@ecmds) {
Log 5, "$hash->{NAME} sending $ecmd";
ECMD_SimpleWrite($hash, $ecmd);
ECMD_SimpleWrite($hash, $ecmd, $nonl);
$answer= ECMD_ReadAnswer($hash, "$ecmd");
push @r, $answer;
Log 5, $answer;
@ -727,6 +733,9 @@ ECMD_Write($$)
<li>classdefs<br>A colon-separated list of &lt;classname&gt;=&lt;filename&gt;.
The list is automatically updated if a class definition is added. You can
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>
<br><br>
@ -809,7 +818,7 @@ ECMD_Write($$)
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>
for the <code>&lt;perl command&gt</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
final result of the get or set command.

View File

@ -402,8 +402,19 @@ ECMDDevice_Define($$)
The set command is evaluated as follows: <code>%pinmask</code>
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>
evaluates this to a literal string. This string is split into lines (without trailing newline characters)
<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
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