mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +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:
parent
1960873e04
commit
dd25845cfa
@ -95,6 +95,7 @@ CUL_Initialize($)
|
|||||||
|
|
||||||
# Normal devices
|
# Normal devices
|
||||||
$hash->{DefFn} = "CUL_Define";
|
$hash->{DefFn} = "CUL_Define";
|
||||||
|
$hash->{FingerprintFn} = "CUL_FingerprintFn";
|
||||||
$hash->{UndefFn} = "CUL_Undef";
|
$hash->{UndefFn} = "CUL_Undef";
|
||||||
$hash->{GetFn} = "CUL_Get";
|
$hash->{GetFn} = "CUL_Get";
|
||||||
$hash->{SetFn} = "CUL_Set";
|
$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
|
sub
|
||||||
CUL_Define($$)
|
CUL_Define($$)
|
||||||
|
@ -100,6 +100,7 @@ FHZ_Initialize($)
|
|||||||
|
|
||||||
# Normal devices
|
# Normal devices
|
||||||
$hash->{DefFn} = "FHZ_Define";
|
$hash->{DefFn} = "FHZ_Define";
|
||||||
|
$hash->{FingerprintFn} = "FHZ_FingerprintFn";
|
||||||
$hash->{UndefFn} = "FHZ_Undef";
|
$hash->{UndefFn} = "FHZ_Undef";
|
||||||
$hash->{GetFn} = "FHZ_Get";
|
$hash->{GetFn} = "FHZ_Get";
|
||||||
$hash->{SetFn} = "FHZ_Set";
|
$hash->{SetFn} = "FHZ_Set";
|
||||||
@ -108,6 +109,17 @@ FHZ_Initialize($)
|
|||||||
"fhtsoftbuffer:1,0 addvaltrigger";
|
"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
|
sub
|
||||||
FHZ_Ready($)
|
FHZ_Ready($)
|
||||||
|
60
fhem/fhem.pl
60
fhem/fhem.pl
@ -49,7 +49,8 @@ sub AnalyzePerlCommand($$);
|
|||||||
sub AssignIoPort($);
|
sub AssignIoPort($);
|
||||||
sub AttrVal($$$);
|
sub AttrVal($$$);
|
||||||
sub CallFn(@);
|
sub CallFn(@);
|
||||||
sub CheckDuplicate($$);
|
sub CheckDuplicate($$@);
|
||||||
|
sub rejectDuplicate($$$);
|
||||||
sub CommandChain($$);
|
sub CommandChain($$);
|
||||||
sub Dispatch($$$);
|
sub Dispatch($$$);
|
||||||
sub DoTrigger($$@);
|
sub DoTrigger($$@);
|
||||||
@ -2592,20 +2593,8 @@ Dispatch($$$)
|
|||||||
|
|
||||||
Log 5, "$name dispatch $dmsg";
|
Log 5, "$name dispatch $dmsg";
|
||||||
|
|
||||||
my ($isdup, $idx) = CheckDuplicate($name, $dmsg);
|
my ($isdup, $idx) = CheckDuplicate($name, $dmsg, $iohash->{FingerprintFn});
|
||||||
if($isdup) {
|
return rejectDuplicate($name,$idx,$addvals) 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 @found;
|
my @found;
|
||||||
|
|
||||||
@ -2616,6 +2605,11 @@ Dispatch($$$)
|
|||||||
# Module is not loaded or the message is not for this module
|
# Module is not loaded or the message is not for this module
|
||||||
next if($dmsg !~ m/$modules{$m}{Match}/i);
|
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;
|
no strict "refs"; $readingsUpdateDelayTrigger = 1;
|
||||||
@found = &{$modules{$m}{ParseFn}}($hash,$dmsg);
|
@found = &{$modules{$m}{ParseFn}}($hash,$dmsg);
|
||||||
use strict "refs"; $readingsUpdateDelayTrigger = 0;
|
use strict "refs"; $readingsUpdateDelayTrigger = 0;
|
||||||
@ -2703,12 +2697,17 @@ Dispatch($$$)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
CheckDuplicate($$)
|
CheckDuplicate($$@)
|
||||||
{
|
{
|
||||||
my ($ioname, $msg) = @_;
|
my ($ioname, $msg, $ffn) = @_;
|
||||||
|
|
||||||
# Store only the "relevant" part, as the CUL won't compute the checksum
|
if($ffn) {
|
||||||
$msg = substr($msg, 8) if($msg =~ m/^81/ && length($msg) > 8);
|
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 $now = gettimeofday();
|
||||||
my $lim = $now-AttrVal("global","dupTimeout", 0.5);
|
my $lim = $now-AttrVal("global","dupTimeout", 0.5);
|
||||||
@ -2717,12 +2716,17 @@ CheckDuplicate($$)
|
|||||||
if($duplicate{$oidx}{TIM} < $lim) {
|
if($duplicate{$oidx}{TIM} < $lim) {
|
||||||
delete($duplicate{$oidx});
|
delete($duplicate{$oidx});
|
||||||
|
|
||||||
|
} elsif($duplicate{$oidx}{MSG} eq $msg &&
|
||||||
|
$duplicate{$oidx}{ION} eq "") {
|
||||||
|
return (1, $oidx);
|
||||||
|
|
||||||
} elsif($duplicate{$oidx}{MSG} eq $msg &&
|
} elsif($duplicate{$oidx}{MSG} eq $msg &&
|
||||||
$duplicate{$oidx}{ION} ne $ioname) {
|
$duplicate{$oidx}{ION} ne $ioname) {
|
||||||
return (1, $oidx);
|
return (1, $oidx);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#Debug "is unique";
|
||||||
$duplicate{$duplidx}{ION} = $ioname;
|
$duplicate{$duplidx}{ION} = $ioname;
|
||||||
$duplicate{$duplidx}{MSG} = $msg;
|
$duplicate{$duplidx}{MSG} = $msg;
|
||||||
$duplicate{$duplidx}{TIM} = $now;
|
$duplicate{$duplidx}{TIM} = $now;
|
||||||
@ -2730,6 +2734,24 @@ CheckDuplicate($$)
|
|||||||
return (0, $duplidx-1);
|
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
|
sub
|
||||||
AddDuplicate($$)
|
AddDuplicate($$)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user