FBDECT: Avoid perl warning on damaged packets

FHEM2FHEM: do not log if message is irrelevant


git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@6203 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig
2014-07-06 12:31:20 +00:00
parent d4f16777bb
commit 989e6fc872
3 changed files with 26 additions and 8 deletions

View File

@@ -57,6 +57,7 @@ FBAHA_Define($$)
DevIo_CloseDev($hash);
$hash->{DeviceName} = $dev;
return undef if($dev eq "none"); # DEBUGGING
my $ret = DevIo_OpenDev($hash, 0, "FBAHA_DoInit");
return $ret;
}
@@ -173,7 +174,6 @@ FBAHA_configInd($$)
{
my ($data, $onlyId) = @_;
my @answer;
while(length($data) >= 288) {
my $id = hex(substr($data, 0, 4));
@@ -202,7 +202,7 @@ FBAHA_configInd($$)
push @answer, " MANUF:$mnf";
push @answer, " UniqueID:$idf";
push @answer, " Firmware:$frm";
push @answer, substr($data, 288, $dlen);
push @answer, substr($data, 288+$dlen);
return @answer;
}
$data = substr($data, 288+$dlen); # rest

View File

@@ -131,6 +131,7 @@ FBDECT_Get($@)
my $state = "inactive" if($answ[0] =~ m/ inactive,/);
while($d) {
my ($ptyp, $plen, $pyld) = FBDECT_decodePayload($d);
last if($ptyp eq "");
if($ptyp eq "state" &&
ReadingsVal($hash->{NAME}, $ptyp, "") ne $pyld) {
readingsSingleUpdate($hash, $ptyp, ($state ? $state : $pyld), 1);
@@ -171,6 +172,7 @@ FBDECT_Parse($$@)
my $d = substr($msg, 32);
while($d) {
my ($ptyp, $plen, $pyld) = FBDECT_decodePayload($d);
last if($ptyp eq "");
readingsBulkUpdate($hash, $ptyp, $pyld);
$d = substr($d, 16+$plen*2);
}
@@ -184,20 +186,25 @@ FBDECT_Parse($$@)
} else {
my $d = pop @answ;
while($d) {
if(length($d) <= 16) {
push @answ, "FBDECT_DECODE_ERROR:short payload $d";
last;
}
my ($ptyp, $plen, $pyld) = FBDECT_decodePayload($d);
last if(!$plen);
last if($ptyp eq "");
push @answ, " $ptyp: $pyld";
$d = substr($d, 16+$plen*2);
}
Log 4, "FBDECT PARSED: ".join(" / ", @answ);
# Ignore the rest, is too confusing.
@answ = grep /state:/, @answ;
(undef, $state) = split(": ", $answ[0], 2);
(undef, $state) = split(": ", $answ[0], 2) if(@answ > 0);
}
readingsBulkUpdate($hash, "state", $state);
readingsBulkUpdate($hash, "state", $state) if($state);
}
readingsEndUpdate($hash, 1);
Log 5, "FBDECT_Parse for device $hash->{NAME} done";
return $hash->{NAME};
}
@@ -278,9 +285,19 @@ sub
FBDECT_decodePayload($)
{
my ($d) = @_;
if(length($d) < 12) {
Log 4, "FBDECT ignoring payload: data too short";
return ("", "", "");
}
my $ptyp = hex(substr($d, 0, 8));
my $plen = hex(substr($d, 8, 4));
if(length($d) < 16+$plen*2) {
Log 4, "FBDECT ignoring payload: data shorter than given length($plen)";
return ("", "", "");
}
my $pyld = substr($d, 16, $plen*2);
if($fbdect_payload{$ptyp}) {
$pyld = eval $fbdect_payload{$ptyp}{fmt} if($fbdect_payload{$ptyp}{fmt});
$ptyp = $fbdect_payload{$ptyp}{n};

View File

@@ -132,20 +132,20 @@ FHEM2FHEM_Read($)
return if(IsDisabled($name));
my $data = $hash->{PARTIAL};
Log3 $hash, 5, "FHEM2FHEM/RAW: $data/$buf";
#Log3 $hash, 5, "FHEM2FHEM/RAW: $data/$buf";
$data .= $buf;
while($data =~ m/\n/) {
my $rmsg;
($rmsg,$data) = split("\n", $data, 2);
$rmsg =~ s/\r//;
Log3 $name, 4, "$name: $rmsg";
if($hash->{informType} eq "LOG") {
my ($type, $name, $msg) = split(" ", $rmsg, 3);
next if(!defined($msg)); # Bogus data
my $re = $hash->{regexp};
next if($re && !($name =~ m/^$re$/ || "$name:$msg" =~ m/^$re$/));
Log3 $name, 4, "$name: $rmsg";
if(!$defs{$name}) {
#LoadModule($type); Why do we need this line?
@@ -166,6 +166,7 @@ FHEM2FHEM_Read($)
my ($type, $rname, $msg) = split(" ", $rmsg, 3);
my $rdev = $hash->{rawDevice};
next if($rname ne $rdev);
Log3 $name, 4, "$name: $rmsg";
Dispatch($defs{$rdev}, $msg, undef);
}