From dd25845cfa39415598b51b203731feaf384aeb7c Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Mon, 15 Jul 2013 20:34:58 +0000 Subject: [PATCH] Dispatch tuning from justme1968 git-svn-id: https://svn.fhem.de/fhem/trunk@3430 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/00_CUL.pm | 12 +++++++++ fhem/FHEM/00_FHZ.pm | 12 +++++++++ fhem/fhem.pl | 60 +++++++++++++++++++++++++++++++-------------- 3 files changed, 65 insertions(+), 19 deletions(-) diff --git a/fhem/FHEM/00_CUL.pm b/fhem/FHEM/00_CUL.pm index 52bed7ff6..45d274003 100755 --- a/fhem/FHEM/00_CUL.pm +++ b/fhem/FHEM/00_CUL.pm @@ -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($$) diff --git a/fhem/FHEM/00_FHZ.pm b/fhem/FHEM/00_FHZ.pm index 8af4ad718..cadb7244a 100755 --- a/fhem/FHEM/00_FHZ.pm +++ b/fhem/FHEM/00_FHZ.pm @@ -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($) diff --git a/fhem/fhem.pl b/fhem/fhem.pl index ca13c03c0..ea73f5ff6 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -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($$) {