Duplicate pool added

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@462 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2009-11-12 19:08:01 +00:00
parent c91ff0cd2e
commit a3d4ed78e5
15 changed files with 78 additions and 33 deletions

View File

@ -536,4 +536,5 @@
- bugfix: loosing data when sending FS20 messages in a group - bugfix: loosing data when sending FS20 messages in a group
- bugfix: better handling of disconnected CUN - bugfix: better handling of disconnected CUN
- feature: softfhtbuffer added to CUL - feature: softfhtbuffer added to CUL
- bugfix: pgm3: Pulldown-Menu without selected FHTDEV not possible any more - bugfix: pgm3: Pulldown-Menu without selected FHTDEV not possible any more
- feature: duplicate buffer added for multi-cul/-fhz setups

View File

@ -73,7 +73,7 @@ CUL_Initialize($)
$hash->{GetFn} = "CUL_Get"; $hash->{GetFn} = "CUL_Get";
$hash->{SetFn} = "CUL_Set"; $hash->{SetFn} = "CUL_Set";
$hash->{StateFn} = "CUL_SetState"; $hash->{StateFn} = "CUL_SetState";
$hash->{AttrList}= "do_not_notify:1,0 dummy:1,0 filtertimeout " . $hash->{AttrList}= "do_not_notify:1,0 dummy:1,0 " .
"showtime:1,0 model:CUL,CUR loglevel:0,1,2,3,4,5,6 " . "showtime:1,0 model:CUL,CUR loglevel:0,1,2,3,4,5,6 " .
"CUR_id_list fhtsoftbuffer:1,0"; "CUR_id_list fhtsoftbuffer:1,0";
$hash->{ShutdownFn} = "CUL_Shutdown"; $hash->{ShutdownFn} = "CUL_Shutdown";
@ -573,6 +573,8 @@ CUL_Write($$$)
} elsif($fn eq "04" && substr($msg,0,6) eq "010101") { # FS20 } elsif($fn eq "04" && substr($msg,0,6) eq "010101") { # FS20
$fn = "F"; $fn = "F";
AddDuplicate($hash->{NAME},
"0101a001" . substr($msg, 6, 6) . "00" . substr($msg, 12));
$msg = substr($msg,6); $msg = substr($msg,6);
} elsif($fn eq "04" && substr($msg,0,6) eq "020183") { # FHT } elsif($fn eq "04" && substr($msg,0,6) eq "020183") { # FHT
@ -759,8 +761,9 @@ CUL_Read($)
if($foundp) { if($foundp) {
foreach my $d (@{$foundp}) { foreach my $d (@{$foundp}) {
next if(!$defs{$d}); next if(!$defs{$d});
$defs{$d}{RSSI} = $rssi if($rssi); $defs{$d}{"RSSI_$name"} = $rssi if($rssi);
$defs{$d}{RAWMSG} = $rmsg; $defs{$d}{RAWMSG} = $rmsg;
$defs{$d}{"MSGCNT_$name"}++;
} }
} }

View File

@ -79,7 +79,7 @@ FHZ_Initialize($)
$hash->{GetFn} = "FHZ_Get"; $hash->{GetFn} = "FHZ_Get";
$hash->{SetFn} = "FHZ_Set"; $hash->{SetFn} = "FHZ_Set";
$hash->{StateFn} = "FHZ_SetState"; $hash->{StateFn} = "FHZ_SetState";
$hash->{AttrList}= "do_not_notify:1,0 dummy:1,0 filtertimeout repeater:1,0 " . $hash->{AttrList}= "do_not_notify:1,0 dummy:1,0 " .
"showtime:1,0 model:fhz1000,fhz1300 loglevel:0,1,2,3,4,5,6 ". "showtime:1,0 model:fhz1000,fhz1300 loglevel:0,1,2,3,4,5,6 ".
"fhtsoftbuffer:1,0"; "fhtsoftbuffer:1,0";
} }
@ -542,6 +542,16 @@ FHZ_Write($$$)
return; return;
} }
###############
# insert value into the msghist. At the moment this only makes sense for FS20
# devices. As the transmitted value differs from the received one, we have to
# recompute.
if($fn eq "04" && substr($msg,0,6) eq "010101") {
AddDuplicate($hash->{NAME},
"0101a001" . substr($msg, 6, 6) . "00" . substr($msg, 12));
}
my $bstring = FHZ_CompleteMsg($fn, $msg); my $bstring = FHZ_CompleteMsg($fn, $msg);
Log 5, "Sending " . unpack('H*', $bstring); Log 5, "Sending " . unpack('H*', $bstring);
@ -689,6 +699,7 @@ FHZ_Read($)
foreach my $d (@{$foundp}) { foreach my $d (@{$foundp}) {
next if(!$defs{$d}); next if(!$defs{$d});
$defs{$d}{RAWMSG} = $dmsg; $defs{$d}{RAWMSG} = $dmsg;
$defs{$d}{"MSGCNT_$name"}++;
} }
} }

View File

@ -89,8 +89,6 @@ BS_Parse($$)
my $name= $def->{NAME}; my $name= $def->{NAME};
return "" if($def->{IODev} && $def->{IODev}{NAME} ne $hash->{NAME});
my $t= TimeNow(); my $t= TimeNow();
my $flags= hex(substr($msg, 24, 1)) & 0xdc; my $flags= hex(substr($msg, 24, 1)) & 0xdc;

View File

@ -98,9 +98,6 @@ USF1000_Parse($$)
my $def= $defptr{$dev}; my $def= $defptr{$dev};
my $name= $def->{NAME}; my $name= $def->{NAME};
return "" if($def->{IODev} && $def->{IODev}{NAME} ne $hash->{NAME});
my $t= TimeNow(); my $t= TimeNow();
# Msg format: # Msg format:

View File

@ -354,7 +354,6 @@ FS20_Parse($$)
my @list; my @list;
foreach my $n (keys %{ $def }) { foreach my $n (keys %{ $def }) {
my $lh = $def->{$n}; my $lh = $def->{$n};
return "" if($lh->{IODev} && $lh->{IODev}{NAME} ne $hash->{NAME});
$lh->{CHANGED}[0] = $v; $lh->{CHANGED}[0] = $v;
$lh->{STATE} = $v; $lh->{STATE} = $v;
$lh->{READINGS}{state}{TIME} = TimeNow(); $lh->{READINGS}{state}{TIME} = TimeNow();

View File

@ -167,8 +167,6 @@ FHT_Set($@)
if($a[$i] eq "time") { if($a[$i] eq "time") {
my @t = localtime; my @t = localtime;
splice(@a,$i,1,("hour",$t[2],"minute",$t[1])); splice(@a,$i,1,("hour",$t[2],"minute",$t[1]));
IOWrite($hash, "", sprintf("T04%x", $t[0])) # CUL hack
if($hash->{IODev} && $hash->{IODev}->{TYPE} eq "CUL");
} }
} }
@ -348,8 +346,6 @@ FHT_Parse($$)
my $def = $defptr{$dev}; my $def = $defptr{$dev};
my $name = $def->{NAME}; my $name = $def->{NAME};
return "" if($def->{IODev} && $def->{IODev}{NAME} ne $hash->{NAME});
# Short message # Short message
if(length($msg) < 26) { if(length($msg) < 26) {
Log 4,"FHT Short message. Device $name, Message: $msg"; Log 4,"FHT Short message. Device $name, Message: $msg";

View File

@ -106,7 +106,6 @@ HMS_Parse($$)
} }
my $def = $defptr{$dev}; my $def = $defptr{$dev};
return "" if($def->{IODev} && $def->{IODev}{NAME} ne $hash->{NAME});
my (@v, @txt); my (@v, @txt);

View File

@ -89,8 +89,6 @@ KS300_Parse($$)
my $haverain = 0; my $haverain = 0;
my $name= $def->{NAME}; my $name= $def->{NAME};
return "" if($def->{IODev} && $def->{IODev}{NAME} ne $hash->{NAME});
my @v; my @v;
my @txt = ( "rain_raw", "rain", "wind", "humidity", "temperature", my @txt = ( "rain_raw", "rain", "wind", "humidity", "temperature",
"israining", "unknown1", "unknown2", "unknown3"); "israining", "unknown1", "unknown2", "unknown3");

View File

@ -95,10 +95,6 @@ CUL_WS_Parse($$)
return "UNDEFINED CUL_WS: $cde"; return "UNDEFINED CUL_WS: $cde";
} }
# It's not our device
return "" if($def->{IODev} && $def->{IODev}{NAME} ne $hash->{NAME});
my $tm=TimeNow(); my $tm=TimeNow();
$hash = $def; $hash = $def;

View File

@ -107,7 +107,6 @@ CUL_EM_Parse($$)
if($defptr{$cde}) { if($defptr{$cde}) {
my $def = $defptr{$cde}; my $def = $defptr{$cde};
return "" if($def->{IODev} && $def->{IODev}{NAME} ne $hash->{NAME});
$hash = $defptr{$cde}; $hash = $defptr{$cde};

View File

@ -348,7 +348,6 @@ X10_Parse($$)
foreach my $unitcode (@unitcodes) { foreach my $unitcode (@unitcodes) {
my $h= $devices{$housecode}{$unitcode}; my $h= $devices{$housecode}{$unitcode};
if($h) { if($h) {
return "" if($h->{IODev} && $h->{IODev}{NAME} ne $hash->{NAME});
my $name= $h->{NAME}; my $name= $h->{NAME};
$h->{CHANGED}[0] = $value; $h->{CHANGED}[0] = $value;
$h->{STATE} = $value; $h->{STATE} = $value;

14
HISTORY
View File

@ -431,8 +431,16 @@
- bugfix: missing blank in attribute list for FHT; exclude report from lazy - bugfix: missing blank in attribute list for FHT; exclude report from lazy
- typos and anchors in documentation corrected - typos and anchors in documentation corrected
- Sun Oct11 2009 (Boris) - Sun Oct 11 2009 (Boris)
- finalized 09_BS.pm and documentation - finalized 09_BS.pm and documentation
- Tue Nov10 2009 (Martin Haas) - Tue Nov 10 2009 (Martin Haas)
- Bugfix: pgm3: Pulldown-Menu without selected FHTDEV not possible any more - Bugfix: pgm3: Pulldown-Menu without selected FHTDEV not possible any more
- Thu Nov 12 2009 (Rudi)
- The duplicate pool added. The check routine is called from the Dispatch
routine (so it will affecc CUL/FHZ and CM11), and for FS20 calls from
the CUL and FHZ Write function.
Duplicates within 0.5 seconds are filtered if they are not reported by the
same IO Unit. Existing check for IODev removed from BS USF1000 FS20 FHT HMS
KS300 CUL_WS CUL_EM X10.

5
TODO
View File

@ -1,11 +1,6 @@
FHEM: FHEM:
- RAWTIME
- Remote serial device via IP (for the FHZ1300 WLAN)
- Common buffer for parallel use of two devices: CUL+FHZ, (WS300/EM1000PC?)
- fhem-to-fhem module - fhem-to-fhem module
- CUR built-in MENU creation support - CUR built-in MENU creation support
- Remove or reimplement repeater attribute (cul/fhz/doc)
Webpgm2 Webpgm2
- plot data from multiple files in a single picture - plot data from multiple files in a single picture

50
fhem.pl
View File

@ -39,12 +39,14 @@ use Time::HiRes qw(gettimeofday);
################################################## ##################################################
# Forward declarations # Forward declarations
# #
sub AddDuplicate($$);
sub AnalyzeCommand($$); sub AnalyzeCommand($$);
sub AnalyzeCommandChain($$); sub AnalyzeCommandChain($$);
sub AnalyzeInput($); sub AnalyzeInput($);
sub AssignIoPort($); sub AssignIoPort($);
sub CallFn(@); sub CallFn(@);
sub CommandChain($$); sub CommandChain($$);
sub CheckDuplicate($$);
sub DoClose($); sub DoClose($);
sub Dispatch($$); sub Dispatch($$);
sub FmtDateTime($); sub FmtDateTime($);
@ -151,7 +153,9 @@ my %defaultattr; # Default attributes
my %intAt; # Internal at timer hash. my %intAt; # Internal at timer hash.
my $nextat; # Time when next timer will be triggered. my $nextat; # Time when next timer will be triggered.
my $intAtCnt=0; my $intAtCnt=0;
my $cvsid = '$Id: fhem.pl,v 1.81 2009-11-08 14:18:06 rudolfkoenig Exp $'; my %duplicate; # Pool of received msg for multi-fhz/cul setups
my $duplidx=0; # helper for the above pool
my $cvsid = '$Id: fhem.pl,v 1.82 2009-11-12 19:08:00 rudolfkoenig Exp $';
my $namedef = my $namedef =
"where <name> is either:\n" . "where <name> is either:\n" .
"- a single device name\n" . "- a single device name\n" .
@ -175,7 +179,7 @@ $modules{_internal_}{AttrFn} = "GlobalAttr";
"?" => { Fn=>"CommandHelp", "?" => { Fn=>"CommandHelp",
Hlp=>",get this help" }, Hlp=>",get this help" },
"attr" => { Fn=>"CommandAttr", "attr" => { Fn=>"CommandAttr",
Hlp=>"<devspec> <attrname> [<attrval>],set attribute for <devspec>" }, Hlp=>"<devspec> <attrname> [<attrval>],set attribute for <devspec>"},
"define" => { Fn=>"CommandDefine", "define" => { Fn=>"CommandDefine",
Hlp=>"<name> <type> <options>,define a device/at/notify entity" }, Hlp=>"<name> <type> <options>,define a device/at/notify entity" },
"deleteattr" => { Fn=>"CommandDeleteAttr", "deleteattr" => { Fn=>"CommandDeleteAttr",
@ -2041,6 +2045,9 @@ Dispatch($$)
Log 5, "$name dispatch $dmsg"; Log 5, "$name dispatch $dmsg";
my ($isdup, $idx) = CheckDuplicate($name, $dmsg);
return $duplicate{$idx}{FND} if($isdup);
my @found; my @found;
my $last_module; my $last_module;
foreach my $m (sort { $modules{$a}{ORDER} cmp $modules{$b}{ORDER} } foreach my $m (sort { $modules{$a}{ORDER} cmp $modules{$b}{ORDER} }
@ -2056,6 +2063,7 @@ Dispatch($$)
$last_module = $m; $last_module = $m;
last if(int(@found)); last if(int(@found));
} }
if(!int(@found)) { if(!int(@found)) {
my $h = $iohash->{MatchList}; my $h = $iohash->{MatchList};
if(defined($h)) { if(defined($h)) {
@ -2088,6 +2096,44 @@ Dispatch($$)
DoTrigger($found, undef); DoTrigger($found, undef);
} }
} }
$duplicate{$idx}{FND} = \@found;
return \@found; return \@found;
} }
sub
CheckDuplicate($$)
{
my ($ioname, $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);
my $now = gettimeofday();
my $lim = $now-0.5;
foreach my $oidx (keys %duplicate) {
if($duplicate{$oidx}{TIM} < $lim) {
delete($duplicate{$oidx});
} elsif($duplicate{$oidx}{MSG} eq $msg &&
$duplicate{$oidx}{ION} ne $ioname) {
return (1, $oidx);
}
}
$duplicate{$duplidx}{ION} = $ioname;
$duplicate{$duplidx}{MSG} = $msg;
$duplicate{$duplidx}{TIM} = $now;
$duplidx++;
return (0, $duplidx-1);
}
sub
AddDuplicate($$)
{
$duplicate{$duplidx}{ION} = shift;
$duplicate{$duplidx}{MSG} = shift;
$duplicate{$duplidx}{TIM} = gettimeofday();
$duplidx++;
}