From 68afbe43067a30f99df43c222cf003f327157cc3 Mon Sep 17 00:00:00 2001 From: martinp876 <> Date: Tue, 8 Jan 2013 10:11:47 +0000 Subject: [PATCH] command resend and HMLAN performance improvement git-svn-id: https://svn.fhem.de/fhem/trunk@2454 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/00_HMLAN.pm | 16 ++++++++++--- fhem/FHEM/10_CUL_HM.pm | 51 ++++++++++++++++++++++++++++++++---------- 2 files changed, 52 insertions(+), 15 deletions(-) diff --git a/fhem/FHEM/00_HMLAN.pm b/fhem/FHEM/00_HMLAN.pm index 773afc6d2..152c480a8 100755 --- a/fhem/FHEM/00_HMLAN.pm +++ b/fhem/FHEM/00_HMLAN.pm @@ -317,6 +317,7 @@ HMLAN_Parse($$) # 0081=open # 0100=with 'E', not 'R'. # 0081=open + # 04xx=nothing will be sent anymore? try restart # HMLAN_SimpleWrite($hash, '+'.$src) if (($letter eq 'R') && $src ne AttrVal($name, "hmId", $mFld[4])); @@ -324,6 +325,16 @@ HMLAN_Parse($$) # HMLAN_SimpleWrite($hash, '-'.$src); # HMLAN_SimpleWrite($hash, '+'.$src); # } + if($mFld[1] =~ m/^04/){ + Log $ll5, 'HMLAN_Parse: problems detected - please restart HMLAN'; + #foreach (keys %lhash){delete ($lhash{$_})};# does not help + #DevIo_Disconnected($hash) ;# does not help + } + if($mFld[1] =~ m/^02/){ + Log $ll5, 'HMLAN_Parse: restart HMLAN might be necessary'; + HMLAN_SimpleWrite($hash, '-'.$src);# todo not proven how to get out of this situation + HMLAN_SimpleWrite($hash, '+'.$src); + } $dmsg .= ":NACK" if($mFld[1] !~ m/00(01|02|21)/ && $letter eq 'R'); $hash->{uptime} = HMLAN_uptime($mFld[2]); @@ -364,7 +375,6 @@ sub HMLAN_Ready($) { my ($hash) = @_; - return DevIo_OpenDev($hash, 1, "HMLAN_DoInit"); } @@ -384,11 +394,11 @@ HMLAN_SimpleWrite(@) # tested allowes no more then 2 byte/ms incl overhead # It is even slower if HMLAN waits for acks, acks are missing,... my $bytPend = $hash->{helper}{dPend} - - int(($tn - $hash->{helper}{lastSend})*2000); + int(($tn - $hash->{helper}{lastSend})*4000); $bytPend = 0 if ($bytPend < 0); $hash->{helper}{dPend} = $bytPend + length($msg); $hash->{helper}{lastSend} = $tn; - my $wait = $bytPend/2000; # HMLAN + my $wait = $bytPend/4000; # HMLAN # => wait time to protect HMLAN overload # my $wait = $bytPend>>11; # fast divide by 2048 diff --git a/fhem/FHEM/10_CUL_HM.pm b/fhem/FHEM/10_CUL_HM.pm index f3ddd64b2..085b5ba61 100755 --- a/fhem/FHEM/10_CUL_HM.pm +++ b/fhem/FHEM/10_CUL_HM.pm @@ -198,6 +198,7 @@ my %culHmModel=( "0092" => {name=>"Schueco_263-144" ,cyc=>'' ,rxt=>'c' ,lst=>'4' ,chn=>"",}, "0093" => {name=>"Schueco_263-158" ,cyc=>'' ,rxt=>'c:w' ,lst=>'' ,chn=>"",}, "0094" => {name=>"Schueco_263-157" ,cyc=>'' ,rxt=>'c:w' ,lst=>'' ,chn=>"",}, + "00A1" => {name=>"HM-LC-SW1-PL2" ,cyc=>'' ,rxt=>'' ,lst=>'3' ,chn=>"",}, ); sub CUL_HM_Initialize($) @@ -1749,6 +1750,7 @@ my %culHmSubTypeSets = ( virtual =>"",}, #redef necessary for virtual smokeDetector => { test => "", "alarmOn"=>"", "alarmOff"=>"", +# test1 => "", test2 => "", #General devicepair => " device ... single [set|unset] actor"}, winMatic =>{matic => "", read => "", @@ -2493,9 +2495,18 @@ CUL_HM_Set($@) $hash->{TESTNR} = $testnr; CUL_HM_SndCmd($hash, sprintf("++9440%s%s00%02X",$dst,$dst,$testnr)); } + elsif($cmd eq "test1") { ##################################################### General remove after test + my $testnr = $hash->{TESTNR} ? ($hash->{TESTNR} +1) : 1; + $hash->{TESTNR} = $testnr; + CUL_HM_SndCmd($hash, sprintf("++B440%s%s00%02X",$dst,$dst,$testnr)); + } + elsif($cmd eq "test2") { ##################################################### General remove after test + my $testnr = $hash->{TESTNR} ? ($hash->{TESTNR} +1) : 1; + $hash->{TESTNR} = $testnr; + CUL_HM_SndCmd($hash, sprintf("++9440%s%s00%02X",$id,$dst,$testnr)); + } elsif($cmd =~ m/alarm(.*)/) { ############################################### -# CUL_HM_SndCmd($hash, sprintf("++9441%s%s01%s", - CUL_HM_SndCmd($hash, sprintf("++B441%s%s01%s", + CUL_HM_SndCmd($hash, sprintf("++9441%s%s01%s", $dst,$dst, $1 eq "On" ? "0BC8" : "0C01")); } elsif($cmd eq "virtual") { ################################################## @@ -2818,9 +2829,9 @@ CUL_HM_SndCmd($$) $io->{HM_CMDNR} = $mn; $cmd = sprintf("As%02X%02X%s", length($cmd2)/2+1, $mn, $cmd2); IOWrite($hash, "", $cmd); + CUL_HM_responseSetup($hash,$cmd); $cmd =~ m/As(..)(..)(..)(..)(......)(......)(.*)/; CUL_HM_DumpProtocol("SND", $io, ($1,$2,$3,$4,$5,$6,$7)); - CUL_HM_responseSetup($hash,$cmd); } sub #--------------------------------- CUL_HM_responseSetup($$) @@ -2830,11 +2841,12 @@ CUL_HM_responseSetup($$) my ($msgId, $msgFlag,$msgType,$dst,$p) = ($2,hex($3),$4,$6,$7) if ($cmd =~ m/As(..)(..)(..)(..)(......)(......)(.*)/); my ($chn,$subType) = ($1,$2) if($p =~ m/^(..)(..)/); - my $rTo = 2; #default response timeout + my $rTo = rand(20)/10+2; #default response timeout if ($msgType eq "01" && $subType){ if ($subType eq "03"){ #PeerList------------- #--- remember request params in device level $hash->{helper}{respWait}{Pending} = "PeerList"; + $hash->{helper}{respWait}{PendCmd} = $cmd; $hash->{helper}{respWait}{forChn} = substr($p,0,2);#channel info we await # define timeout - holdup cmdStack until response complete or timeout @@ -2851,7 +2863,8 @@ CUL_HM_responseSetup($$) my ($peer, $list) = ($1,$2) if ($p =~ m/..04(........)(..)/); $peer = ($peer ne "00000000")?CUL_HM_peerChName($peer,$dst,""):""; #--- set messaging items - $hash->{helper}{respWait}{Pending} = "RegisterRead"; + $hash->{helper}{respWait}{Pending}= "RegisterRead"; + $hash->{helper}{respWait}{PendCmd}= $cmd; $hash->{helper}{respWait}{forChn} = $chn; $hash->{helper}{respWait}{forList}= $list; $hash->{helper}{respWait}{forPeer}= $peer; @@ -2871,6 +2884,7 @@ CUL_HM_responseSetup($$) # elsif($subType eq "0A"){ #Pair Serial---------- # #--- set messaging items # $hash->{helper}{respWait}{Pending} = "PairSerial"; +# $hash->{helper}{respWait}{PendCmd} = $cmd; # $hash->{helper}{respWait}{forChn} = substr($p,4,20); # # # define timeout - holdup cmdStack until response complete or timeout @@ -2879,7 +2893,8 @@ CUL_HM_responseSetup($$) # } elsif($subType eq "0E"){ #StatusReq---------- #--- set messaging items - $hash->{helper}{respWait}{Pending} = "StatusReq"; + $hash->{helper}{respWait}{Pending}= "StatusReq"; + $hash->{helper}{respWait}{PendCmd}= $cmd; $hash->{helper}{respWait}{forChn} = $chn; # define timeout - holdup cmdStack until response complete or timeout @@ -2943,12 +2958,24 @@ CUL_HM_respPendTout($) $HMid =~ s/.*://; #remove timer identifier my $hash = $modules{CUL_HM}{defptr}{$HMid}; if ($hash && $hash->{DEF} ne '000000'){ - CUL_HM_eventP($hash,"Tout") if ($hash->{helper}{respWait}{cmd}); - my $pendCmd = $hash->{helper}{respWait}{Pending};# save before remove - CUL_HM_eventP($hash,"ToutResp") if ($pendCmd); - CUL_HM_respPendRm($hash); - CUL_HM_ProcessCmdStack($hash); # continue processing commands - readingsSingleUpdate($hash,"state","RESPONSE TIMEOUT:".$pendCmd,1); + my $pendCmd = $hash->{helper}{respWait}{Pending};# secure before remove + + my $pendRsndCnt = $hash->{helper}{respWait}{PendingRsend}; + $pendRsndCnt = 1 if (!$pendRsndCnt); + if ($pendRsndCnt <7 && # some retries + (CUL_HM_getRxType($hash) & 0x03) != 0){# to slow for wakeup and config + my $name = $hash->{NAME}; + Log GetLogLevel($name,4),"CUL_HM_Resend: ".$name. " nr ".$pendRsndCnt; + $hash->{helper}{respWait}{PendingRsend} = $pendRsndCnt + 1; + CUL_HM_SndCmd($hash,substr($hash->{helper}{respWait}{PendCmd},4)); + CUL_HM_eventP($hash,"Resnd") if ($pendCmd); + } + else{ + CUL_HM_eventP($hash,"ResndFail") if ($pendCmd); + CUL_HM_respPendRm($hash); + CUL_HM_ProcessCmdStack($hash); # continue processing commands + readingsSingleUpdate($hash,"state","RESPONSE TIMEOUT:".$pendCmd,1); + } } } sub #---------------------------------