From 34d525beacb2f749df4fdf3572e8b9c53fe9886e Mon Sep 17 00:00:00 2001 From: martinp876 <> Date: Wed, 14 May 2014 18:18:34 +0000 Subject: [PATCH] prepare HMLAN for ID handling git-svn-id: https://svn.fhem.de/fhem/trunk@5860 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/00_HMLAN.pm | 46 +++++++++++++++++++++++++++++++++--------- fhem/FHEM/10_CUL_HM.pm | 1 - 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/fhem/FHEM/00_HMLAN.pm b/fhem/FHEM/00_HMLAN.pm index 0a6d9c518..ae4f4c4a0 100755 --- a/fhem/FHEM/00_HMLAN.pm +++ b/fhem/FHEM/00_HMLAN.pm @@ -401,7 +401,7 @@ sub HMLAN_Write($$$) {######################################################### substr($msg, 16, 6)); if ( $mtype eq "02" && $src eq $hash->{owner} && length($msg) == 24 - && $hash->{assignedIDs} =~ m/$dst/){ + && defined $hash->{assIDs}{$dst}){ # Acks are generally send by HMLAN autonomously # Special Log3 $hash, 5, "HMLAN: Skip ACK"; @@ -419,14 +419,34 @@ sub HMLAN_Write($$$) {######################################################### HMLAN_SimpleWrite($hash, $IDadd); $hash->{helper}{$dst}{name} = CUL_HM_id2Name($dst); $hash->{assIDs}{$dst} = 1; - $hash->{assignedIDs}=join(',',keys %{$hash->{assIDs}}); - $hash->{assignedIDsCnt}=scalar(keys %{$hash->{assIDs}}); + my @asId = HMLAN_noDup(keys %{$hash->{assIDs}}); + $hash->{assignedIDs}=join(',',@asId); + $hash->{assignedIDsCnt}=scalar(@asId); } } elsif($msg =~ m /init:(......)/){ - if ($modules{CUL_HM}{defptr}{$1} && - $modules{CUL_HM}{defptr}{$1}{helper}{io}{newChn} ){ - HMLAN_SimpleWrite($hash,$modules{CUL_HM}{defptr}{$1}{helper}{io}{newChn}); + my $dst = $1; + if ($modules{CUL_HM}{defptr}{$dst} && + $modules{CUL_HM}{defptr}{$dst}{helper}{io}{newChn} ){ + HMLAN_SimpleWrite($hash,$modules{CUL_HM}{defptr}{$dst}{helper}{io}{newChn}); + $hash->{helper}{$dst}{name} = CUL_HM_id2Name($dst); + $hash->{assIDs}{$dst} = 1; + my @asId = HMLAN_noDup(keys %{$hash->{assIDs}}); + $hash->{assignedIDs}=join(',',@asId); + $hash->{assignedIDsCnt}=scalar(@asId); + } + return; + } + elsif($msg =~ m /remove:(......)/){ + my $dst = $1; + if ($modules{CUL_HM}{defptr}{$dst} && + $modules{CUL_HM}{defptr}{$dst}{helper}{io}{newChn} ){ + HMLAN_SimpleWrite($hash,"-$dst"); + delete $hash->{helper}{$dst}; + delete $hash->{assIDs}{$dst}; + my @asId = HMLAN_noDup(keys %{$hash->{assIDs}}); + $hash->{assignedIDs}=join(',',@asId); + $hash->{assignedIDsCnt}=scalar(@asId); } return; } @@ -750,6 +770,7 @@ sub HMLAN_SimpleWrite(@) {##################################################### $msg .= "\r\n" unless($nonl); syswrite($hash->{TCPDev}, $msg) if($hash->{TCPDev}); } + sub HMLAN_DoInit($) {########################################################## my ($hash) = @_; my $name = $hash->{NAME}; @@ -758,7 +779,7 @@ sub HMLAN_DoInit($) {########################################################## delete $hash->{READINGS}{state}; HMLAN_SimpleWrite($hash, "A$id") if($id ne "999999"); - HMLAN_SimpleWrite($hash, "C"); + HMLAN_assignIDs($hash); HMLAN_writeAesKey($name); my $s2000 = sprintf("%02X", HMLAN_secSince2000()); HMLAN_SimpleWrite($hash, "T$s2000,04,00,00000000"); @@ -768,8 +789,6 @@ sub HMLAN_DoInit($) {########################################################## HMLAN_condUpdate($hash,255); $hash->{helper}{q}{cap}{$_}=0 foreach (keys %{$hash->{helper}{q}{cap}}); - foreach (keys %{$hash->{assIDs}}){delete ($hash->{assIDs}{$_})};# clear IDs - HMLAN might have a reset - delete ($hash->{assIDs}{$_}) foreach (keys %{$hash->{assIDs}});# clear IDs - HMLAN might have a reset $hash->{helper}{q}{keepAliveRec} = 1; # ok for first time $hash->{helper}{q}{keepAliveRpt} = 0; # ok for first time @@ -786,6 +805,15 @@ sub HMLAN_DoInit($) {########################################################## return undef; } +sub HMLAN_assignIDs($){ + # remove all assigned IDs and assign the ones from list + my ($hash) = @_; + HMLAN_SimpleWrite($hash, "C"); #clear all assigned IDs + + my @ids = split",",InternalVal($hash->{NAME},"assignedIDs",""); + HMLAN_Write($hash,"","init:$_") foreach(@ids); +} + sub HMLAN_writeAesKey($) {##################################################### my ($name) = @_; diff --git a/fhem/FHEM/10_CUL_HM.pm b/fhem/FHEM/10_CUL_HM.pm index f5f2bef99..62fdc693b 100755 --- a/fhem/FHEM/10_CUL_HM.pm +++ b/fhem/FHEM/10_CUL_HM.pm @@ -4905,7 +4905,6 @@ sub CUL_HM_FWupdateSteps($){#steps for FW update RemoveInternalTimer("fail:SpeedChangeFailed"); RemoveInternalTimer("fail:Block".($step-1)); if ($blocks < $step){#last block - CUL_HM_FWupdateSpeed($name,10); CUL_HM_FWupdateEnd("done"); Log3 $name,2,"CUL_HM fwUpdate completed"; }