From 0044641de1442dce9e7513e7a9aa01dc07cfb19d Mon Sep 17 00:00:00 2001 From: martinp876 Date: Sun, 29 Dec 2013 08:24:01 +0000 Subject: [PATCH] timing calculation for multiple HM-IOs, HMinfo improve configCheck, powermeter state git-svn-id: https://svn.fhem.de/fhem/trunk@4496 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/00_HMLAN.pm | 25 ++++++++++++++------- fhem/FHEM/10_CUL_HM.pm | 16 ++++++-------- fhem/FHEM/98_HMinfo.pm | 49 ++++++++++++++++++++++++++++++++---------- 3 files changed, 62 insertions(+), 28 deletions(-) diff --git a/fhem/FHEM/00_HMLAN.pm b/fhem/FHEM/00_HMLAN.pm index 28f210cbd..9cc95cd75 100755 --- a/fhem/FHEM/00_HMLAN.pm +++ b/fhem/FHEM/00_HMLAN.pm @@ -509,7 +509,6 @@ sub HMLAN_Parse($$) {########################################################## my ($mNo,$flg,$type,$src,$dst,$p) = unpack('A2A2A2A6A6A*',$mFld[5]); my $CULinfo = ""; - my @logIds = ("150B94","172A85"); Log3 $hash, HMLAN_getVerbLvl ($hash,$src,$dst,"5") , "HMLAN_Parse: $name R:".$mFld[0] .(($mFld[0] =~ m/^E/)?' ':'') @@ -609,15 +608,22 @@ sub HMLAN_Parse($$) {########################################################## ." max:" .$dlyP->{max} ." last:".$dlyP->{lst} ." cnt:" .$dlyP->{cnt}; + ################# debugind help + #my $st = $sysC - $dly;#time send + #my $stms = sprintf("%03d",$st%1000); + #my @slt = localtime(int($st/1000)); + #Log 1,"HMLAN dlyTime st:$slt[2]:$slt[1]:$slt[0].".$stms." dly:$dly"; + ################# $dly = 0 if ($dly<0); } # HMLAN sends ACK for flag 'A0' but not for 'A4'(config mode)- # we ack ourself an long as logic is uncertain - also possible is 'A6' for RHS - if (hex($flg)&0x22){#not sure: 4 oder 2 ? 0x.2 works for VD! - my $wait = 0.100 - $dly/1000; - $hash->{helper}{$src}{nextSend} = gettimeofday() + $wait if ($wait > 0); - } + + my $wait = 0.100 - $dly/1000; + $modules{CUL_HM}{defptr}{$src}{helper}{io}{nextSend} = gettimeofday()+$wait + if ($modules{CUL_HM}{defptr}{$src} && $wait > 0); + if (hex($flg)&0xA4 == 0xA4 && $hash->{owner} eq $dst){ Log3 $hash, HMLAN_getVerbLvl ($hash,$src,$dst,"5") , "HMLAN_Parse: $name ACK config"; @@ -694,11 +700,14 @@ sub HMLAN_SimpleWrite(@) {##################################################### my $hmId = AttrVal($name,"hmId",""); my $hDst = $hash->{helper}{$dst};# shortcut my $tn = gettimeofday(); - if ($hDst->{nextSend}){ - my $DevDelay = $hDst->{nextSend} - $tn; + + if($modules{CUL_HM}{defptr}{$dst} && + $modules{CUL_HM}{defptr}{$dst}{helper}{io} && + $modules{CUL_HM}{defptr}{$dst}{helper}{io}{nextSend} + ){ + my $DevDelay = $modules{CUL_HM}{defptr}{$dst}{helper}{io}{nextSend} - $tn; select(undef, undef, undef, (($DevDelay > 0.1)?0.1:$DevDelay)) if ($DevDelay > 0.01); - delete $hDst->{nextSend}; } if ($dst ne $hmId){ #delay send if answer is pending if ( $hDst->{flg} && #HMLAN's ack pending diff --git a/fhem/FHEM/10_CUL_HM.pm b/fhem/FHEM/10_CUL_HM.pm index 5ad9a9a00..2a2780f74 100755 --- a/fhem/FHEM/10_CUL_HM.pm +++ b/fhem/FHEM/10_CUL_HM.pm @@ -1202,9 +1202,8 @@ sub CUL_HM_Parse($$) {############################## push @event,"level:$val %"; push @event,"pct:$val"; # duplicate to level - necessary for "slider" push @event,"deviceMsg:$vs$target" if($chn ne "00"); - my $eventName = "switch"; - my $action; #determine action - push @event, "timedOn:".(($err&0x40)?"running":"off"); + push @event,"state:$vs"; + push @event,"timedOn:".(($err&0x40)?"running":"off"); } elsif ($mTp eq "5E" ||$mTp eq "5F" ) { # POWER_EVENT_CYCLIC $shash = $modules{CUL_HM}{defptr}{$src."02"} @@ -1697,12 +1696,12 @@ sub CUL_HM_parseCommon(@){##################################################### } elsif($mTp eq "00"){###################################### my $paired = 0; #internal flag + CUL_HM_infoUpdtDevData($shash->{NAME}, $shash,$p) + if (!$modules{CUL_HM}{helper}{hmManualOper}); if ( $ioHash->{hmPair} ||( $ioHash->{hmPairSerial} && $ioHash->{hmPairSerial} eq $attr{$shash->{NAME}}{serialNr})){ # pairing requested - shall we? - CUL_HM_infoUpdtDevData($shash->{NAME}, $shash,$p) - if (!$modules{CUL_HM}{helper}{hmManualOper}); my $oldIoId = CUL_HM_Id($shash->{IODev}); my $ioId = CUL_HM_Id($ioHash); if( $mFlg.$mTp ne "0400") { @@ -3419,15 +3418,14 @@ sub CUL_HM_weather(@) {#periodically send weather data } sub CUL_HM_infoUpdtDevData($$$) {#autoread config my($name,$hash,$p) = @_; - my($fw,$mId,$serNo,$stc,$devInfo) = ($1,$2,$3,$4,$5) - if($p =~ m/(..)(.{4})(.{20})(.{2})(.*)/); + my($fw1,$fw2,$mId,$serNo,$stc,$devInfo) = unpack('A1A1A4A20A2A*', $p); + my $md = $culHmModel{$mId}{name} ? $culHmModel{$mId}{name}:"unknown"; $attr{$name}{model} = $md; $attr{$name}{subType} = $culHmModel{$mId}{st}; $attr{$name}{serialNr} = pack('H*',$serNo); #expert level attributes - $attr{$name}{firmware} = - sprintf("%d.%d", hex(substr($p,0,1)),hex(substr($p,1,1))); + $attr{$name}{firmware} = sprintf("%d.%d", hex($fw1),hex($fw2)); $attr{$name}{".devInfo"} = $devInfo; $attr{$name}{".stc"} = $stc; diff --git a/fhem/FHEM/98_HMinfo.pm b/fhem/FHEM/98_HMinfo.pm index 4c8254f8f..606cd7f1a 100644 --- a/fhem/FHEM/98_HMinfo.pm +++ b/fhem/FHEM/98_HMinfo.pm @@ -156,9 +156,10 @@ sub HMinfo_regCheck(@) { ###################################################### push @regMissing,$eName.":\t".join(",",@mReg) if (scalar @mReg); push @regIncompl,$eName.":\t".join(",",@iReg) if (scalar @iReg); } - return "\n\n missing register list\n " .(join "\n ",sort @regMissing) - ."\n\n incomplete register list\n ".(join "\n ",sort @regIncompl) - ; + my $ret = ""; + $ret .="\n\n missing register list\n " .(join "\n ",sort @regMissing) if(@regMissing); + $ret .="\n\n incomplete register list\n ".(join "\n ",sort @regIncompl) if(@regIncompl); + return $ret; } sub HMinfo_peerCheck(@) { ##################################################### my @entities = @_; @@ -198,10 +199,11 @@ sub HMinfo_peerCheck(@) { ##################################################### } } } - return "\n\n peer list not read" ."\n ".(join "\n ",sort @peerIDsEmpty) - ."\n\n peer list incomplete"."\n ".(join "\n ",sort @peerIDsFail) - ."\n\n peer not verified " ."\n ".(join "\n ",sort @peerIDsNoPeer) - ; + my $ret = ""; + $ret .="\n\n peer list not read" ."\n ".(join "\n ",sort @peerIDsEmpty) if(@peerIDsEmpty); + $ret .="\n\n peer list incomplete"."\n ".(join "\n ",sort @peerIDsFail) if(@peerIDsEmpty); + $ret .="\n\n peer not verified " ."\n ".(join "\n ",sort @peerIDsNoPeer)if(@peerIDsEmpty); + return $ret; } sub HMinfo_burstCheck(@) { #################################################### my @entities = @_; @@ -231,9 +233,33 @@ sub HMinfo_burstCheck(@) { #################################################### } } } - return "\n\n peerNeedsBurst not set" ."\n ".(join "\n ",sort @peerIDsNeed) - ."\n\n conditionalBurst not set"."\n ".(join "\n ",sort @peerIDsCond) - ; + my $ret = ""; + $ret .="\n\n peerNeedsBurst not set" ."\n ".(join "\n ",sort @peerIDsNeed) if(@peerIDsNeed); + $ret .="\n\n conditionalBurst not set"."\n ".(join "\n ",sort @peerIDsCond) if(@peerIDsCond); + return $ret; +} +sub HMinfo_paramCheck(@) { #################################################### + my @entities = @_; + my @noIoDev; + my @noID; + my @idMismatch; + my %th = CUL_HM_putHash("culHmModel"); + foreach my $eName (@entities){ + next if (!$defs{$eName}{helper}{role}{dev}); + my $ehash = $defs{$eName}; + my $pairId = CUL_HM_Get($ehash,$eName,"param","PairedTo"); + my $IoDev = $ehash->{IODev} if ($ehash->{IODev}); + my $ioHmId = AttrVal($IoDev->{NAME},"hmId","-"); + if (!$IoDev) { push @noIoDev,$eName;} + elsif ($pairId eq "undefined"){ push @noID,$eName;} + elsif ($pairId !~ m /$ioHmId/){ push @idMismatch,"$eName paired:$pairId IO attr: $ioHmId";} + } + + my $ret = ""; + $ret .="\n\n no IO device assigned" ."\n ".(join "\n ",sort @noIoDev) if (@noIoDev); + $ret .="\n\n PairedTo missing/unknown" ."\n ".(join "\n ",sort @noID) if (@noID); + $ret .="\n\n PairedTo missmatch to IODev"."\n ".(join "\n ",sort @idMismatch) if (@idMismatch); + return $ret; } sub HMinfo_getEntities(@) { ################################################### @@ -538,7 +564,8 @@ sub HMinfo_SetFn($@) {######################################################### my @entities = HMinfo_getEntities($opt."v",$filter); $ret = $cmd." done:" .HMinfo_regCheck(@entities) .HMinfo_peerCheck(@entities) - .HMinfo_burstCheck(@entities); + .HMinfo_burstCheck(@entities) + .HMinfo_paramCheck(@entities); } elsif($cmd eq "peerXref") {##print cross-references------------------------ my @peerPairs;