From 16b1e44d68920e9d5d70dfcedcda5a149ca92330 Mon Sep 17 00:00:00 2001 From: martinp876 <> Date: Sat, 4 Jan 2014 11:43:45 +0000 Subject: [PATCH] VD simulation git-svn-id: https://svn.fhem.de/fhem/trunk@4558 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/10_CUL_HM.pm | 64 +++++++++++++++++++++++++++--------------- fhem/FHEM/HMConfig.pm | 31 ++------------------ 2 files changed, 43 insertions(+), 52 deletions(-) diff --git a/fhem/FHEM/10_CUL_HM.pm b/fhem/FHEM/10_CUL_HM.pm index 559eb04dd..e3721acbe 100755 --- a/fhem/FHEM/10_CUL_HM.pm +++ b/fhem/FHEM/10_CUL_HM.pm @@ -3096,7 +3096,18 @@ sub CUL_HM_Set($@) { } else { my $vp = $a[2]; + foreach my $peer (split(',',AttrVal($name,"peerIDs",""))) { + next if (length($peer) != 8); + my $ph = CUL_HM_id2Hash($peer); + CUL_HM_UpdtReadBulk($ph,1, + "state:set_$vp %", + "ValveDesired:$vp %") + if ($ph); + } readingsSingleUpdate($hash,"valvePosTC","$vp %",0); + $hash->{helper}{vd}{idh} = hex(substr($dst,2,2))*20077; + $hash->{helper}{vd}{idl} = hex(substr($dst,4,2))*256; + $hash->{helper}{vd}{msgCnt} = 1; CUL_HM_valvePosUpdt("valvePos:$dst$chn") if (!$hash->{helper}{virtTC}); $hash->{helper}{virtTC} = "03"; $state = "ValveAdjust:$vp %"; @@ -3402,24 +3413,24 @@ sub CUL_HM_valvePosUpdt(@) {#update valve position periodically to please valve my(undef,$vId) = split(':',$in); my $hash = CUL_HM_id2Hash($vId); my $vDevId = substr($vId,0,6); - my $nextTimer = 150; - -# if ($updtValveCnt++ %2){ -# $nextTimer = 20; -# CUL_HM_PushCmdStack($hash,"++8670".$vDevId."00000000D036");# some weather event - -# } -# else{ - my $name = $hash->{NAME}; - my $vp = ReadingsVal($name,"valvePosTC","15 %"); - $vp =~ s/ %//; - $vp *=2.56; - foreach my $peer (sort(split(',',AttrVal($name,"peerIDs","")))) { - next if (length($peer) != 8); - $peer = substr($peer,0,6); - CUL_HM_PushCmdStack($hash,sprintf("++A258%s%s%s%02X",$vDevId - ,$peer,$hash->{helper}{virtTC},$vp)); - } -# } + my $msgCnt = ($hash->{helper}{vd}{msgCnt} + 1)%255; + + my $idl = $hash->{helper}{vd}{idl}+$msgCnt; + my $lo = int(($idl*20077+12345)/65536)&0xff; + my $hi = ($hash->{helper}{vd}{idh}+$idl*198)&0xff; + my $nextTimer = (($lo+$hi)&0xff)/4 +120; + + my $name = $hash->{NAME}; + my $vp = ReadingsVal($name,"valvePosTC","15 %"); + $vp =~ s/ %//; + $vp *=2.56; + foreach my $peer (sort(split(',',AttrVal($name,"peerIDs","")))) { + next if (length($peer) != 8); + $peer = substr($peer,0,6); + CUL_HM_PushCmdStack($hash,sprintf("%02XA258%s%s%s%02X",$msgCnt,$vDevId + ,$peer,$hash->{helper}{virtTC},$vp)); + } + $hash->{helper}{vd}{msgCnt} = $msgCnt; $hash->{helper}{virtTC} = "00"; CUL_HM_ProcessCmdStack($hash); InternalTimer(gettimeofday()+$nextTimer,"CUL_HM_valvePosUpdt","valvePos:$vId",0); @@ -4148,12 +4159,16 @@ sub CUL_HM_ID2PeerList ($$$) { my $st = AttrVal($dHash->{NAME},"subType",""); if ($st eq "virtual"){ #if any of the peers is an SD we are team master - my $tMstr = 0; + my ($tMstr,$tcSim) = (0,0); foreach (split(",",$peerNames)){ $tMstr = 1 if(AttrVal($_,"subType","") eq "smokeDetector"); + $tcSim = 1 if(AttrVal($_,"model","") eq "HM-CC-VD"); } - if($tMstr){$hash->{sdTeam}="sdLead";$hash->{helper}{fkt}="sdLead";} - else {delete $hash->{sdTeam}; delete $hash->{helper}{fkt};} + if ($tMstr){$hash->{helper}{fkt}="sdLead";$hash->{sdTeam}="sdLead";} + elsif($tcSim){$hash->{helper}{fkt}="vdCtrl";} + else {delete $hash->{helper}{fkt};} + + if(!$tMstr) {delete $hash->{sdTeam};} } elsif ($st eq "smokeDetector"){ foreach (split(",",$peerNames)){ @@ -5316,10 +5331,13 @@ sub CUL_HM_autoReadReady($){# capacity for autoread available? sub CUL_HM_getAttrInt($@){#return attrValue as integer my ($name,$attrName,$default) = @_; - my $val = $attr{$name}{$attrName}?$attr{$name}{$attrName}:""; + $default = 0 if (!defined $default); + my $val = ($attr{$name} && + $attr{$name}{$attrName}) + ?$attr{$name}{$attrName} + :""; no warnings 'numeric'; my $devN = $defs{$name}{device}?$defs{$name}{device}:$name; - $default = 0 if (!defined $default); $val = int($attr{$devN}{$attrName}?$attr{$devN}{$attrName}:$default)+0 if($val eq ""); use warnings 'numeric'; diff --git a/fhem/FHEM/HMConfig.pm b/fhem/FHEM/HMConfig.pm index a57dcaa41..372f62634 100644 --- a/fhem/FHEM/HMConfig.pm +++ b/fhem/FHEM/HMConfig.pm @@ -1122,7 +1122,6 @@ $culHmRegChan{"HM-TC-IT-WM-W-EU06"}= $culHmRegType{"HM-CC-RT-DN06"}; ,press =>"[long|short]..." ,postEvent =>"" ,postWeather =>"" -# ,valvePos =>"" }, smokeDetector =>{ peerChan =>" ... single [set|unset] actor"}, winMatic =>{ matic =>"" @@ -1259,6 +1258,8 @@ $culHmChanSets{"HM-ES-PMSw1-Pl06"} = $culHmChanSets{"HM-ES-PMSw1-Pl03"}; sdLead =>{ alarmOn =>"" ,alarmOff =>"" ,teamCall =>"" + }, + vdCtrl =>{ valvePos =>"" } ); @@ -1463,32 +1464,4 @@ $culHmChanSets{"HM-ES-PMSw1-Pl06"} = $culHmChanSets{"HM-ES-PMSw1-Pl03"}; HUM => '04,2,$val=(hex($val))', } }, ); -#sub HMConfig_getHash($){ -# my $hn = shift; -# return %culHmModel if($hn eq "culHmModel" ); -# return %culHmRegDefShLg if($hn eq "culHmRegDefShLg" ); -# return %culHmRegDefine if($hn eq "culHmRegDefine" ); -# return %culHmRegGeneral if($hn eq "culHmRegGeneral" ); -# return %culHmRegType if($hn eq "culHmRegType" ); -# return %culHmRegModel if($hn eq "culHmRegModel" ); -# return %culHmRegChan if($hn eq "culHmRegChan" ); -# -# return %culHmGlobalGets if($hn eq "culHmGlobalGets" ); -# return %culHmSubTypeGets if($hn eq "culHmSubTypeGets" ); -# return %culHmModelGets if($hn eq "culHmModelGets" ); -# -# return %culHmGlobalSetsDevice if($hn eq "culHmGlobalSetsDevice"); -# return %culHmSubTypeDevSets if($hn eq "culHmSubTypeDevSets" ); -# return %culHmGlobalSetsChn if($hn eq "culHmGlobalSetsChn" ); -# return %culHmGlobalSets if($hn eq "culHmGlobalSets" ); -# return %culHmGlobalSetsVrtDev if($hn eq "culHmGlobalSetsVrtDev"); -# return %culHmSubTypeSets if($hn eq "culHmSubTypeSets" ); -# return %culHmModelSets if($hn eq "culHmModelSets" ); -# return %culHmChanSets if($hn eq "culHmChanSets" ); -# return %culHmFunctSets if($hn eq "culHmFunctSets" ); -# -# return %culHmBits if($hn eq "culHmBits" ); -# return @culHmCmdFlags if($hn eq "culHmCmdFlags" ); -# return $K_actDetID if($hn eq "K_actDetID" ); -#} 1;