2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-01 01:09:47 +00:00

suppress warnings on uninitialized values if device returns nothing

upgraded log function to log3

git-svn-id: https://svn.fhem.de/fhem/trunk@4426 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
borisneubert 2013-12-20 15:47:05 +00:00
parent 0da3c8c4be
commit 1edb1ece2d

View File

@ -89,7 +89,7 @@ ECMD_Undef($$)
$defs{$d}{IODev} == $hash) $defs{$d}{IODev} == $hash)
{ {
my $lev = ($reread_active ? 4 : 2); my $lev = ($reread_active ? 4 : 2);
Log GetLogLevel($name,$lev), "deleting port for $d"; Log3 $hash, $lev, "deleting port for $d";
delete $defs{$d}{IODev}; delete $defs{$d}{IODev};
} }
} }
@ -136,7 +136,7 @@ ECMD_OpenDev($$)
$hash->{PARTIAL} = ""; $hash->{PARTIAL} = "";
Log 3, "ECMD opening $name (protocol $protocol, device $devicename)" Log3 $hash, 3, "ECMD opening $name (protocol $protocol, device $devicename)"
if(!$reopen); if(!$reopen);
if($hash->{Protocol} eq "telnet") { if($hash->{Protocol} eq "telnet") {
@ -164,7 +164,7 @@ ECMD_OpenDev($$)
delete($hash->{NEXT_OPEN}) delete($hash->{NEXT_OPEN})
} else { } else {
Log(3, "Can't connect to $devicename: $!") if(!$reopen); Log3 $hash, 3, "Can't connect to $devicename: $!" if(!$reopen);
$readyfnlist{"$name.$devicename"} = $hash; $readyfnlist{"$name.$devicename"} = $hash;
$hash->{STATE} = "disconnected"; $hash->{STATE} = "disconnected";
$hash->{NEXT_OPEN} = time()+60; $hash->{NEXT_OPEN} = time()+60;
@ -192,7 +192,7 @@ ECMD_OpenDev($$)
if(!$po) { if(!$po) {
return undef if($reopen); return undef if($reopen);
Log(3, "Can't open $devicename: $!"); Log3 $hash, 3, "Can't open $devicename: $!";
$readyfnlist{"$name.$devicename"} = $hash; $readyfnlist{"$name.$devicename"} = $hash;
$hash->{STATE} = "disconnected"; $hash->{STATE} = "disconnected";
return ""; return "";
@ -209,7 +209,7 @@ ECMD_OpenDev($$)
if($baudrate) { if($baudrate) {
$po->reset_error(); $po->reset_error();
Log 3, "ECMD setting $name baudrate to $baudrate"; Log3 $hash, 3, "ECMD setting $name baudrate to $baudrate";
$po->baudrate($baudrate); $po->baudrate($baudrate);
$po->databits(8); $po->databits(8);
$po->parity('none'); $po->parity('none');
@ -240,18 +240,18 @@ ECMD_OpenDev($$)
} }
if($reopen) { if($reopen) {
Log 1, "ECMD $name ($devicename) reappeared"; Log3 $hash, 1, "ECMD $name ($devicename) reappeared";
} else { } else {
Log 3, "ECMD device opened"; Log3 $hash, 3, "ECMD device opened";
} }
$hash->{STATE}= ""; # Allow InitDev to set the state $hash->{STATE}= ""; # Allow InitDev to set the state
my $ret = ECMD_DoInit($hash); my $ret = ECMD_DoInit($hash);
if($ret) { if($ret) {
Log 1, "$ret"; Log3 $hash, 1, "$ret";
ECMD_CloseDev($hash); ECMD_CloseDev($hash);
Log 1, "Cannot init $name ($devicename), ignoring it"; Log3 $hash, 1, "Cannot init $name ($devicename), ignoring it";
} }
DoTrigger($name, "CONNECTED") if($reopen); DoTrigger($name, "CONNECTED") if($reopen);
@ -352,10 +352,10 @@ ECMD_ReadAnswer($$)
if($buf) { if($buf) {
chomp $buf; # remove line break chomp $buf; # remove line break
Log 5, "ECMD (ReadAnswer): $buf"; Log3 $hash, 5, "ECMD (ReadAnswer): $buf";
$data .= $buf; $data .= $buf;
} }
return (undef, $data) return (undef, $data)
} }
} }
@ -392,7 +392,7 @@ ECMD_Disconnected($)
return if(!defined($hash->{FD})); # Already deleted o return if(!defined($hash->{FD})); # Already deleted o
Log 1, "$dev disconnected, waiting to reappear"; Log3 $hash, 1, "$dev disconnected, waiting to reappear";
ECMD_CloseDev($hash); ECMD_CloseDev($hash);
$readyfnlist{"$name.$dev"} = $hash; # Start polling $readyfnlist{"$name.$dev"} = $hash; # Start polling
$hash->{STATE} = "disconnected"; $hash->{STATE} = "disconnected";
@ -424,7 +424,7 @@ ECMD_Get($@)
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 $nonl= AttrVal($name, "nonl", 0);
my $ecmd= join " ", @args; my $ecmd= join " ", @args;
Log 5, $ecmd; Log3 $hash, 5, $ecmd;
ECMD_SimpleWrite($hash, $ecmd, $nonl); 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);
@ -448,21 +448,21 @@ ECMD_EvalClassDef($$$)
# refuse overwriting existing definitions # refuse overwriting existing definitions
if(defined($hash->{fhem}{classDefs}{$classname})) { if(defined($hash->{fhem}{classDefs}{$classname})) {
my $err= "$name: class $classname is already defined."; my $err= "$name: class $classname is already defined.";
Log 1, $err; Log3 $hash, 1, $err;
return $err; return $err;
} }
# try and open the class definition file # try and open the class definition file
if(!open(CLASSDEF, $filename)) { if(!open(CLASSDEF, $filename)) {
my $err= "$name: cannot open file $filename for class $classname."; my $err= "$name: cannot open file $filename for class $classname.";
Log 1, $err; Log3 $hash, 1, $err;
return $err; return $err;
} }
my @classdef= <CLASSDEF>; my @classdef= <CLASSDEF>;
close(CLASSDEF); close(CLASSDEF);
# add the class definition # add the class definition
Log 5, "$name: adding new class $classname from file $filename"; Log3 $hash, 5, "$name: adding new class $classname from file $filename";
$hash->{fhem}{classDefs}{$classname}{filename}= $filename; $hash->{fhem}{classDefs}{$classname}{filename}= $filename;
# format of the class definition: # format of the class definition:
@ -494,57 +494,57 @@ ECMD_EvalClassDef($$$)
if($line=~ s/\\$//) { $cont= $line; undef $line; } if($line=~ s/\\$//) { $cont= $line; undef $line; }
next unless($line); next unless($line);
$cont= ""; $cont= "";
Log 5, "$name: evaluating >$line<"; Log3 $hash, 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 "nonl") { if($cmd eq "nonl") {
Log 5, "$name: no newline"; Log3 $hash, 5, "$name: no newline";
$hash->{fhem}{classDefs}{$classname}{nonl}= 1; $hash->{fhem}{classDefs}{$classname}{nonl}= 1;
} }
elsif($cmd eq "params") { elsif($cmd eq "params") {
Log 5, "$name: parameters are $def"; Log3 $hash, 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") {
my ($cmdname, $spec, $arg)= split("[ \t]+", $def, 3); my ($cmdname, $spec, $arg)= split("[ \t]+", $def, 3);
if($spec eq "params") { if($spec eq "params") {
if($cmd eq "set") { if($cmd eq "set") {
Log 5, "$name: set $cmdname has parameters $arg"; Log3 $hash, 5, "$name: set $cmdname has parameters $arg";
$hash->{fhem}{classDefs}{$classname}{sets}{$cmdname}{params}= $arg; $hash->{fhem}{classDefs}{$classname}{sets}{$cmdname}{params}= $arg;
} elsif($cmd eq "get") { } elsif($cmd eq "get") {
Log 5, "$name: get $cmdname has parameters $arg"; Log3 $hash, 5, "$name: get $cmdname has parameters $arg";
$hash->{fhem}{classDefs}{$classname}{gets}{$cmdname}{params}= $arg; $hash->{fhem}{classDefs}{$classname}{gets}{$cmdname}{params}= $arg;
} }
} elsif($spec eq "cmd") { } elsif($spec eq "cmd") {
if($arg !~ m/^{.*}$/s) { if($arg !~ m/^{.*}$/s) {
Log 1, "$name: command for $cmd $cmdname is not a perl command."; Log3 $hash, 1, "$name: command for $cmd $cmdname is not a perl command.";
next; next;
} }
$arg =~ s/^(\\\n|[ \t])*//; # Strip space or \\n at the beginning $arg =~ s/^(\\\n|[ \t])*//; # Strip space or \\n at the beginning
$arg =~ s/[ \t]*$//; $arg =~ s/[ \t]*$//;
if($cmd eq "set") { if($cmd eq "set") {
Log 5, "$name: set $cmdname command defined as $arg"; Log3 $hash, 5, "$name: set $cmdname command defined as $arg";
$hash->{fhem}{classDefs}{$classname}{sets}{$cmdname}{cmd}= $arg; $hash->{fhem}{classDefs}{$classname}{sets}{$cmdname}{cmd}= $arg;
} elsif($cmd eq "get") { } elsif($cmd eq "get") {
Log 5, "$name: get $cmdname command defined as $arg"; Log3 $hash, 5, "$name: get $cmdname command defined as $arg";
$hash->{fhem}{classDefs}{$classname}{gets}{$cmdname}{cmd}= $arg; $hash->{fhem}{classDefs}{$classname}{gets}{$cmdname}{cmd}= $arg;
} }
} elsif($spec eq "postproc") { } elsif($spec eq "postproc") {
if($arg !~ m/^{.*}$/s) { if($arg !~ m/^{.*}$/s) {
Log 1, "$name: postproc command for $cmd $cmdname is not a perl command."; Log3 $hash, 1, "$name: postproc command for $cmd $cmdname is not a perl command.";
next; next;
} }
$arg =~ s/^(\\\n|[ \t])*//; # Strip space or \\n at the beginning $arg =~ s/^(\\\n|[ \t])*//; # Strip space or \\n at the beginning
$arg =~ s/[ \t]*$//; $arg =~ s/[ \t]*$//;
if($cmd eq "set") { if($cmd eq "set") {
Log 5, "$name: set $cmdname postprocessor defined as $arg"; Log3 $hash, 5, "$name: set $cmdname postprocessor defined as $arg";
$hash->{fhem}{classDefs}{$classname}{sets}{$cmdname}{postproc}= $arg; $hash->{fhem}{classDefs}{$classname}{sets}{$cmdname}{postproc}= $arg;
} elsif($cmd eq "get") { } elsif($cmd eq "get") {
Log 5, "$name: get $cmdname postprocessor defined as $arg"; Log3 $hash, 5, "$name: get $cmdname postprocessor defined as $arg";
$hash->{fhem}{classDefs}{$classname}{gets}{$cmdname}{postproc}= $arg; $hash->{fhem}{classDefs}{$classname}{gets}{$cmdname}{postproc}= $arg;
} }
} }
} else { } else {
Log 1, "$name: illegal tag $cmd for class $classname in file $filename."; Log3 $hash, 1, "$name: illegal tag $cmd for class $classname in file $filename.";
} }
} }
@ -626,13 +626,19 @@ ECMD_Write($$)
my @ecmds= split "\n", $msg; my @ecmds= split "\n", $msg;
my $nonl= AttrVal($hash->{NAME}, "nonl", 0); my $nonl= AttrVal($hash->{NAME}, "nonl", 0);
foreach my $ecmd (@ecmds) { foreach my $ecmd (@ecmds) {
Log 5, "$hash->{NAME} sending $ecmd"; Log3 $hash, 5, "$hash->{NAME} sending $ecmd";
ECMD_SimpleWrite($hash, $ecmd, $nonl); ECMD_SimpleWrite($hash, $ecmd, $nonl);
$answer= ECMD_ReadAnswer($hash, "$ecmd"); $answer= ECMD_ReadAnswer($hash, "$ecmd");
push @r, $answer; if(defined($answer)) {
Log 5, $answer; push @r, $answer;
Log3 $hash, 5, $answer;
} else {
Log3 $hash, 5, "no answer received";
}
} }
return join("\n", @r);
return join("\n", @r) unless($#r<0);
return undef;
} }
##################################### #####################################