From 5aa28519a735ca629540444e583f18680ae9d211 Mon Sep 17 00:00:00 2001 From: mgehre <> Date: Sun, 13 Dec 2015 22:55:58 +0000 Subject: [PATCH] CUL_MAX: allow multiple instances Make sure that you set attr IODev on each MAX device (pointing to its CUL_MAX) and set attr IODev on each CUL_MAX (pointing to its CUL). git-svn-id: https://svn.fhem.de/fhem/trunk@10168 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 4 ++++ fhem/FHEM/14_CUL_MAX.pm | 26 +++++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 41b7baad2..ded6cb1c6 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,9 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: CUL_MAX: allow multiple instances + Make sure that you set attr IODev on each MAX device + (pointing to its CUL_MAX) and set attr IODev on each CUL_MAX + (pointing to its CUL). - feature: YAMAHA_AVR: several new features: - new set command navigateMenuList for automatic menu navigation - new set command/reading partyMode diff --git a/fhem/FHEM/14_CUL_MAX.pm b/fhem/FHEM/14_CUL_MAX.pm index 45c1c9cc1..d660532bf 100644 --- a/fhem/FHEM/14_CUL_MAX.pm +++ b/fhem/FHEM/14_CUL_MAX.pm @@ -81,12 +81,6 @@ CUL_MAX_Define($$) return "wrong syntax: define CUL_MAX " if(@a<3); - if(exists($modules{CUL_MAX}{defptr})) { - Log3 $hash, 1, "There is already one CUL_MAX defined"; - return "There is already one CUL_MAX defined"; - } - $modules{CUL_MAX}{defptr} = $hash; - if (length($a[2]) != 6) { Log3 $hash, 1, "The adress must be 6 hexadecimal digits"; return "The adress must be 6 hexadecimal digits"; @@ -114,7 +108,6 @@ CUL_MAX_Undef($$) { my ($hash, $name) = @_; RemoveInternalTimer($hash); - delete($modules{CUL_MAX}{defptr}); return undef; } @@ -253,13 +246,24 @@ sub CUL_MAX_Parse($$) { #Attention: there is a limit in the culfw firmware: It only receives messages shorter than 30 bytes (see rf_moritz.h) + # $hash is for the CUL instance my ($hash, $rmsg) = @_; - if(!exists($modules{CUL_MAX}{defptr})) { - Log3 $hash, 2, "No CUL_MAX defined"; - return "UNDEFINED CULMAX0 CUL_MAX 123456"; + my $shash = undef; #shash is for the CUL_MAX instance + + #Find a CUL_MAX that has the CUL $hash as its IODev; + #if no matching is found, just use the last encountered CUL_MAX. + foreach my $d (keys %defs) { + if($defs{$d}{TYPE} eq "CUL_MAX") { + $shash = $defs{$d}; + last if($defs{$d}{IODev} == $hash); + } + } + + if(!defined($shash)) { + Log3 $hash, 2, "No CUL_MAX defined"; + return "UNDEFINED CULMAX0 CUL_MAX 123456"; } - my $shash = $modules{CUL_MAX}{defptr}; return () if($rmsg !~ m/Z(..)(..)(..)(..)(......)(......)(..)(.*)/);