2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-16 10:46:03 +00:00

Dispatch tuning from justme1968

git-svn-id: https://svn.fhem.de/fhem/trunk@3430 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2013-07-15 20:34:58 +00:00
parent 1960873e04
commit dd25845cfa
3 changed files with 65 additions and 19 deletions

View File

@ -95,6 +95,7 @@ CUL_Initialize($)
# Normal devices
$hash->{DefFn} = "CUL_Define";
$hash->{FingerprintFn} = "CUL_FingerprintFn";
$hash->{UndefFn} = "CUL_Undef";
$hash->{GetFn} = "CUL_Get";
$hash->{SetFn} = "CUL_Set";
@ -109,6 +110,17 @@ CUL_Initialize($)
}
sub
CUL_FingerprintFn($$)
{
my ($name, $msg) = @_;
# Store only the "relevant" part, as the CUL won't compute the checksum
$msg = substr($msg, 8) if($msg =~ m/^81/ && length($msg) > 8);
return ($name, $msg);
}
#####################################
sub
CUL_Define($$)

View File

@ -100,6 +100,7 @@ FHZ_Initialize($)
# Normal devices
$hash->{DefFn} = "FHZ_Define";
$hash->{FingerprintFn} = "FHZ_FingerprintFn";
$hash->{UndefFn} = "FHZ_Undef";
$hash->{GetFn} = "FHZ_Get";
$hash->{SetFn} = "FHZ_Set";
@ -108,6 +109,17 @@ FHZ_Initialize($)
"fhtsoftbuffer:1,0 addvaltrigger";
}
sub
FHZ_FingerprintFn($$)
{
my ($name, $msg) = @_;
# Store only the "relevant" part, as the CUL won't compute the checksum
$msg = substr($msg, 8) if($msg =~ m/^81/ && length($msg) > 8);
return ($name, $msg);
}
#####################################
sub
FHZ_Ready($)

View File

@ -49,7 +49,8 @@ sub AnalyzePerlCommand($$);
sub AssignIoPort($);
sub AttrVal($$$);
sub CallFn(@);
sub CheckDuplicate($$);
sub CheckDuplicate($$@);
sub rejectDuplicate($$$);
sub CommandChain($$);
sub Dispatch($$$);
sub DoTrigger($$@);
@ -2592,20 +2593,8 @@ Dispatch($$$)
Log 5, "$name dispatch $dmsg";
my ($isdup, $idx) = CheckDuplicate($name, $dmsg);
if($isdup) {
my $found = $duplicate{$idx}{FND};
foreach my $found (@{$found}) {
if($addvals) {
foreach my $av (keys %{$addvals}) {
$defs{$found}{"${name}_$av"} = $addvals->{$av};
}
}
$defs{$found}{"${name}_MSGCNT"}++;
$defs{$found}{"${name}_TIME"} = TimeNow();
}
return $duplicate{$idx}{FND};
}
my ($isdup, $idx) = CheckDuplicate($name, $dmsg, $iohash->{FingerprintFn});
return rejectDuplicate($name,$idx,$addvals) if($isdup);
my @found;
@ -2616,6 +2605,11 @@ Dispatch($$$)
# Module is not loaded or the message is not for this module
next if($dmsg !~ m/$modules{$m}{Match}/i);
if( my $ffn = $modules{$m}{FingerprintFn} ) {
(my $isdup, $idx) = CheckDuplicate($name, $dmsg, $ffn);
return rejectDuplicate($name,$idx,$addvals) if($isdup);
}
no strict "refs"; $readingsUpdateDelayTrigger = 1;
@found = &{$modules{$m}{ParseFn}}($hash,$dmsg);
use strict "refs"; $readingsUpdateDelayTrigger = 0;
@ -2703,12 +2697,17 @@ Dispatch($$$)
}
sub
CheckDuplicate($$)
CheckDuplicate($$@)
{
my ($ioname, $msg) = @_;
my ($ioname, $msg, $ffn) = @_;
# Store only the "relevant" part, as the CUL won't compute the checksum
$msg = substr($msg, 8) if($msg =~ m/^81/ && length($msg) > 8);
if($ffn) {
no strict "refs";
($ioname,$msg) = &{$ffn}($ioname,$msg);
use strict "refs";
return (0, undef) if( !defined($msg) );
#Debug "got $ffn ". $ioname .":". $msg;
}
my $now = gettimeofday();
my $lim = $now-AttrVal("global","dupTimeout", 0.5);
@ -2717,12 +2716,17 @@ CheckDuplicate($$)
if($duplicate{$oidx}{TIM} < $lim) {
delete($duplicate{$oidx});
} elsif($duplicate{$oidx}{MSG} eq $msg &&
$duplicate{$oidx}{ION} eq "") {
return (1, $oidx);
} elsif($duplicate{$oidx}{MSG} eq $msg &&
$duplicate{$oidx}{ION} ne $ioname) {
return (1, $oidx);
}
}
#Debug "is unique";
$duplicate{$duplidx}{ION} = $ioname;
$duplicate{$duplidx}{MSG} = $msg;
$duplicate{$duplidx}{TIM} = $now;
@ -2730,6 +2734,24 @@ CheckDuplicate($$)
return (0, $duplidx-1);
}
sub
rejectDuplicate($$$)
{
#Debug "is duplicate";
my ($name,$idx,$addvals) = @_;
my $found = $duplicate{$idx}{FND};
foreach my $found (@{$found}) {
if($addvals) {
foreach my $av (keys %{$addvals}) {
$defs{$found}{"${name}_$av"} = $addvals->{$av};
}
}
$defs{$found}{"${name}_MSGCNT"}++;
$defs{$found}{"${name}_TIME"} = TimeNow();
}
return $duplicate{$idx}{FND};
}
sub
AddDuplicate($$)
{