From 830283e4e085aa2bbaf430bc8f3f546a6e9f7b07 Mon Sep 17 00:00:00 2001 From: martinp876 Date: Sat, 13 Jul 2013 14:32:46 +0000 Subject: [PATCH] Correct TC peering and burst mode, introduce HMinfo templates git-svn-id: https://svn.fhem.de/fhem/trunk@3415 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/10_CUL_HM.pm | 44 +++-- fhem/FHEM/98_HMinfo.pm | 422 ++++++++++++++++++++++++++++++++--------- 2 files changed, 361 insertions(+), 105 deletions(-) diff --git a/fhem/FHEM/10_CUL_HM.pm b/fhem/FHEM/10_CUL_HM.pm index d5d5422a6..d27c7e628 100755 --- a/fhem/FHEM/10_CUL_HM.pm +++ b/fhem/FHEM/10_CUL_HM.pm @@ -62,7 +62,7 @@ sub CUL_HM_respPendTout($); sub CUL_HM_respPendToutProlong($); sub CUL_HM_PushCmdStack($$); sub CUL_HM_ProcessCmdStack($); -sub CUL_HM_pushConfig($$$$$$$$); +sub CUL_HM_pushConfig($$$$$$$$@); sub CUL_HM_Resend($); sub CUL_HM_ID2PeerList ($$$); sub CUL_HM_peerChId($$$); @@ -1350,7 +1350,7 @@ sub CUL_HM_parseCommon(@){##################################################### # TC wakes up with 8270, not with A258 # VD wakes up with 8202 # 9610 - if( $shash->{cmdStack} && + if( $shash->{cmdStack} && ((hex($mFlg) & 0xA2) == 0x82) && (CUL_HM_getRxType($shash) & 0x08)){ #wakeup ##### #send wakeup and process command stack @@ -1946,9 +1946,8 @@ sub CUL_HM_Set($@) { $state = ""; } elsif($cmd eq "getConfig") { ################################################ - my $chFound = 0; CUL_HM_PushCmdStack($hash,'++'.$flag.'01'.$id.$dst.'00040000000000') - if (!$isChannel); + if ($roleD); my @chnIdList = CUL_HM_getAssChnIds($name); foreach my $channel (@chnIdList){ my $chnHash = CUL_HM_id2Hash($channel); @@ -2031,8 +2030,10 @@ sub CUL_HM_Set($@) { } } elsif($cmd eq "regSet") { ############################################### reg - #set regSet - my ($regName,$data,$peerChnIn) = ($a[2],$a[3],$a[4]); + #set regSet [] [prep] + #prep is internal use only. It allowes to prepare shadowreg only but supress + #writing. Application necessarily needs to execute writing subsequent. + my (undef,undef,$regName,$data,$peerChnIn,$prep) = @a; $state = ""; if (!$culHmRegType{$st}{$regName} && !$culHmRegGeneral{$regName} && @@ -2047,9 +2048,9 @@ sub CUL_HM_Set($@) { my $reg = $culHmRegDefine{$regName}; return $st." - ".$regName # give some help - .($reg->{lit}? " liternal:".join(",",keys%{$reg->{lit}})." " + .($reg->{lit}? " literal:".join(",",keys%{$reg->{lit}})." " : " range:". $reg->{min}." to ".$reg->{max}.$reg->{u} - ) + ) .(($reg->{l} == 3)?" peer required":"")." : ".$reg->{t}."\n" if ($data eq "?"); return "value:".$data." out of range for Reg \"".$regName."\"" @@ -2116,8 +2117,9 @@ sub CUL_HM_Set($@) { } my $cHash = CUL_HM_id2Hash($dst.($chn eq '00'?"":$chn)); $cHash = $hash if (!$cHash); - CUL_HM_pushConfig($cHash,$id,$dst,$lChn,$peerId,hex($peerChn),$list,$addrData); - } + CUL_HM_pushConfig($cHash,$id,$dst,$lChn,$peerId,hex($peerChn),$list + ,$addrData,$prep); + } elsif($cmd eq "level") { #################################################### #level =>" ..." my (undef,undef,$lvl,$rLocDly,$speed) = @a; @@ -2557,7 +2559,7 @@ sub CUL_HM_Set($@) { my $cmdB = ($set)?"01":"02";# do we set or remove? # First the remote (one loop for on, one for off) - my $pSt = AttrVal($peerHash->{NAME}, "subType", "");#peer SubType + my $pSt = CUL_HM_Get($peerHash,$peerHash->{NAME},"param","subType"); if (!$target || $target =~ m/^(remote|both)$/){ my $burst = ($pSt eq "thermostat"?"0101":"0100");#set burst for target for(my $i = 1; $i <= $nrCh2Pair; $i++) { @@ -2571,10 +2573,11 @@ sub CUL_HM_Set($@) { else{ my $bStr = sprintf("%02X",$b); CUL_HM_PushCmdStack($hash, - "++".$flag."01${id}${dst}${bStr}$cmdB${peerDst}${peerChn}00"); + "++".$flag."01${id}${dst}${bStr}$cmdB${peerDst}${peerChn}00"); CUL_HM_pushConfig($hash,$id, $dst,$b,$peerDst,hex($peerChn),4,$burst) if($md ne "HM-CC-TC"); - CUL_HM_queueAutoRead($name) if (2 < CUL_HM_getAttrInt($name,"autoReadReg")); + CUL_HM_queueAutoRead($name) + if (2 < CUL_HM_getAttrInt($name,"autoReadReg")); } } } @@ -2716,8 +2719,8 @@ sub CUL_HM_Pair(@) { sub CUL_HM_getConfig($$$$$){ my ($hash,$chnhash,$id,$dst,$chn) = @_; my $flag = CUL_HM_getFlag($hash); - foreach my $readEntry (keys %{$chnhash->{READINGS}}){ - delete $chnhash->{READINGS}{$readEntry} if ($readEntry =~ m/^[\.]?(RegL_|R-)/); + foreach my $readEntry (grep /^[\.]?(RegL_|R-)/,keys %{$chnhash->{READINGS}}){ + delete $chnhash->{READINGS}{$readEntry}; } my $lstAr = $culHmModel{CUL_HM_getMId($hash)}{lst}; if($lstAr){ @@ -2984,8 +2987,8 @@ sub CUL_HM_ProcessCmdStack($) { } return; } -sub CUL_HM_pushConfig($$$$$$$$) {#generate messages to cnfig data to register - my ($hash,$src,$dst,$chn,$peerAddr,$peerChn,$list,$content) = @_; +sub CUL_HM_pushConfig($$$$$$$$@) {#generate messages to config data to register + my ($hash,$src,$dst,$chn,$peerAddr,$peerChn,$list,$content,$prep) = @_; my $flag = CUL_HM_getFlag($hash); my $tl = length($content); @@ -3018,6 +3021,8 @@ sub CUL_HM_pushConfig($$$$$$$$) {#generate messages to cnfig data to register } } $chnhash->{helper}{shadowReg}{$regLN} = $regs; + return if ($prep);#prepare shadowreg only. More data to come. + #Application takes care about execution CUL_HM_updtRegDisp($hash,$list,$peerAddr.$peerChn); CUL_HM_PushCmdStack($hash, "++".$flag.'01'.$src.$dst.$chn.'05'. $peerAddr.$peerChn.$list); @@ -3029,6 +3034,7 @@ sub CUL_HM_pushConfig($$$$$$$$) {#generate messages to cnfig data to register CUL_HM_PushCmdStack($hash,"++A001".$src.$dst.$chn."06"); CUL_HM_queueAutoRead($hash->{NAME}) if (2 < CUL_HM_getAttrInt($hash->{NAME},"autoReadReg")); + } sub CUL_HM_Resend($) {#resend a message if there is no answer my $hash = shift; @@ -3734,7 +3740,7 @@ sub CUL_HM_ActAdd($$) {# add an HMid to list for activity supervision next if (!$rName || $rName eq "PairedTo" || # derived $rName eq "peerList" || # derived - $rName eq "Activity:"|| # derived + $rName eq "Activity" || # derived $rName =~ m/^[.]?R-/ || # no Regs - those are derived from Reg ReadingsVal($eName,$rName,"") =~ m/^set_/); # ignore setting my $ts = ReadingsTimestamp($eName,$rName,""); @@ -3825,7 +3831,7 @@ sub CUL_HM_ActCheck() {# perform supervision } } if ($oldState ne $state){ - readingsSingleUpdate($devHash,"Activity:",$state,1); + readingsSingleUpdate($devHash,"Activity",$state,1); $attr{$devName}{actStatus} = $state; Log 4,"Device ".$devName." is ".$state; } diff --git a/fhem/FHEM/98_HMinfo.pm b/fhem/FHEM/98_HMinfo.pm index af0693771..8f3f6a608 100644 --- a/fhem/FHEM/98_HMinfo.pm +++ b/fhem/FHEM/98_HMinfo.pm @@ -399,8 +399,20 @@ sub HMinfo_SetFn($$) {######################################################### ) .join"\n ",grep(/$filter/,sort @model); } - elsif($cmd eq "template") {##template set of register --------------------- - return HMinfo_template(@a); + elsif($cmd eq "templateSet"){##template: set of register -------------------- + return HMinfo_templateSet(@a); + } + elsif($cmd eq "templateChk"){##template: see if it applies ------------------ + return HMinfo_templateChk(@a); + } + elsif($cmd eq "templateList"){##template: list templates -------------------- + return HMinfo_templateList($a[0]); + } + elsif($cmd eq "templateDef"){##template: define one ------------------------- + return HMinfo_templateDef(@a); + } + elsif($cmd eq "cpRegs") {##copy register -------------------- + return HMinfo_cpRegs(@a); } elsif($cmd eq "update") {##update hm counts ----------------------------- return HMinfo_status($hash); @@ -437,6 +449,14 @@ sub HMinfo_SetFn($$) {######################################################### ."\n [] : only matiching names are processed - partial names are possible" ."\n [] : any match in the output are searched. " ."\n" + ."\n templateChk [ ...] " + ."\n compare whether register match the template values" + ."\n templateDef ...] : [:] ... " + ."\n define a template" + ."\n templateList [] # gives a list of templates or a description of the named template" + ."\n list all currently defined templates or the structure of a given template" + ."\n templateSet [ ...] " + ."\n write register according to a given template" ."\n ======= typeFilter options: supress class of devices ====" ."\n set [-dcasev] [-f ] [params]" ."\n entities according to list will be processed" @@ -524,7 +544,8 @@ sub HMinfo_status($){########################################################## my @Anames; # devices with ActionDetector events my %rssiMin; my %rssiMinCnt = ("99>"=>0,"80<"=>0,"60>"=>0,"59<"=>0); - my @rssiNames; + my @rssiNames; #entities with ciritcal RSSI + my @shdwNames; #entites with shadowRegs, i.e. unconfirmed register ->W_unconfRegs foreach my $id (keys%{$modules{CUL_HM}{defptr}}){#search/count for parameter my $ehash = $modules{CUL_HM}{defptr}{$id}; @@ -532,7 +553,8 @@ sub HMinfo_status($){########################################################## $nbrE++; $nbrC++ if ($ehash->{helper}{role}{chn}); $nbrV++ if ($ehash->{helper}{role}{vrt}); - foreach my $read (grep {$ehash->{READINGS}{$_}} @crit){ #---- count critical readings + push @shdwNames,$eName if (keys %{$ehash->{helper}{shadowReg}}); + foreach my $read (grep {$ehash->{READINGS}{$_}} @crit){ #---- count critical readings my $val = $ehash->{READINGS}{$read}{VAL}; $sum{$read}{$val} =0 if (!$sum{$read}{$val}); $sum{$read}{$val}++; @@ -560,11 +582,11 @@ sub HMinfo_status($){########################################################## } } #====== collection finished - start data preparation====== - delete $hash->{$_} foreach (grep(/^(ERR|sum_)/,keys%{$hash}));# remove old + delete $hash->{$_} foreach (grep(/^(ERR|W_sum_)/,keys%{$hash}));# remove old foreach my $read(grep {defined $sum{$_}} @crit){ #--- disp crt count - $hash->{"sum_".$read} = ""; - $hash->{"sum_".$read} .= "$_:$sum{$read}{$_};"foreach(keys %{$sum{$read}}); + $hash->{"W_sum_".$read} = ""; + $hash->{"W_sum_".$read} .= "$_:$sum{$read}{$_};"foreach(keys %{$sum{$read}}); } foreach my $read(grep {defined $err{$_}} keys %errFlt){#--- disp err count $hash->{"ERR_".$read} = ""; @@ -576,9 +598,9 @@ sub HMinfo_status($){########################################################## @errNames = sort keys %allE; $hash->{ERR_names} = join",",@errNames if(@errNames);# and name entities - $hash->{sumDefined} = "entities:$nbrE device:$nbrD channel:$nbrC virtual:$nbrV"; + $hash->{C_sumDefined} = "entities:$nbrE device:$nbrD channel:$nbrC virtual:$nbrV"; # ------- display status of action detector ------ - $hash->{actTotal} = $modules{CUL_HM}{defptr}{"000000"}{STATE}; + $hash->{I_actTotal} = $modules{CUL_HM}{defptr}{"000000"}{STATE}; $hash->{ERRactNames} = join",",@Anames; # ------- what about IO devices??? ------ @@ -589,7 +611,7 @@ sub HMinfo_status($){########################################################## foreach (grep {$defs{$_}{READINGS}{cond}} @IOdev){ $_ .= ":".$defs{$_}{READINGS}{cond}{VAL}; } - $hash->{HM_IOdevices}= join",",@IOdev; + $hash->{I_HM_IOdevices}= join",",@IOdev; # ------- what about protocol events ------ # Current Events are Rcv,NACK,IOerr,Resend,ResendFail,Snd @@ -603,11 +625,11 @@ sub HMinfo_status($){########################################################## @protNames = sort keys %all; $hash->{ERR__protoNames} = join",",@protNames if(@protNames); - if ($modules{CUL_HM}{helper}{autoRdCfgLst}){ - $hash->{autoReadPend} = join ",",@{$modules{CUL_HM}{helper}{autoRdCfgLst}}; + if (@{$modules{CUL_HM}{helper}{autoRdCfgLst}}>0){ + $hash->{I_autoReadPend} = join ",",@{$modules{CUL_HM}{helper}{autoRdCfgLst}}; } else{ - delete $hash->{autoReadPend}; + delete $hash->{I_autoReadPend}; } # ------- what about rssi low readings ------ @@ -619,10 +641,11 @@ sub HMinfo_status($){########################################################## else {$rssiMinCnt{"80<"}++;} } - $hash->{rssiMinLevel} = ""; - $hash->{rssiMinLevel} .= "$_:$rssiMinCnt{$_} " foreach (sort keys %rssiMinCnt); + $hash->{I_rssiMinLevel} = ""; + $hash->{I_rssiMinLevel} .= "$_:$rssiMinCnt{$_} " foreach (sort keys %rssiMinCnt); $hash->{ERR___rssiCrit} = join(",",@rssiNames) if (@rssiNames); - + # ------- what about others ------ + $hash->{W_unConfRegs} = join(",",@shdwNames) if (@shdwNames > 0); # ------- update own status ------ $hash->{STATE} = "updated:".TimeNow(); return; @@ -630,24 +653,18 @@ sub HMinfo_status($){########################################################## my %tpl = ( - autoOff => {p=>"time" ,t=>"staircase - auto off after