From 9a1e0aa007985f3038126de1e187711a8c10beac Mon Sep 17 00:00:00 2001 From: mgehre <> Date: Sun, 9 Dec 2012 14:59:22 +0000 Subject: [PATCH] MAX: unify duplicate definitions git-svn-id: https://svn.fhem.de/fhem/trunk@2289 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/00_MAXLAN.pm | 13 ++++-------- fhem/FHEM/10_MAX.pm | 25 ++++++++++++++++++++++- fhem/FHEM/14_CUL_MAX.pm | 45 +++++++---------------------------------- 3 files changed, 35 insertions(+), 48 deletions(-) diff --git a/fhem/FHEM/00_MAXLAN.pm b/fhem/FHEM/00_MAXLAN.pm index a20a2016a..0b4b7e68f 100755 --- a/fhem/FHEM/00_MAXLAN.pm +++ b/fhem/FHEM/00_MAXLAN.pm @@ -8,6 +8,10 @@ use warnings; use MIME::Base64; use POSIX; +require "10_MAX.pm"; +our %msgCmd2Id; +our %device_types; + sub MAXLAN_Parse($$); sub MAXLAN_Read($); sub MAXLAN_Write(@); @@ -18,15 +22,6 @@ sub MAXLAN_SendDeviceCmd($$); sub MAXLAN_RequestConfiguration($$); sub MAXLAN_RemoveDevice($$); -my %device_types = ( - 0 => "Cube", - 1 => "HeatingThermostat", - 2 => "HeatingThermostatPlus", - 3 => "WallMountedThermostat", - 4 => "ShutterContact", - 5 => "PushButton" -); - my @boost_durations = (0, 5, 10, 15, 20, 25, 30, 60); my $reconnect_interval = 2; #seconds diff --git a/fhem/FHEM/10_MAX.pm b/fhem/FHEM/10_MAX.pm index 75f1b314e..edbe7c160 100755 --- a/fhem/FHEM/10_MAX.pm +++ b/fhem/FHEM/10_MAX.pm @@ -17,7 +17,11 @@ sub MAX_DateTime2Internal($); my @ctrl_modes = ( "auto", "manual", "temporary", "boost" ); -my %device_types = ( +use vars qw(%device_types); +use vars qw(%msgId2Cmd); +use vars qw(%msgCmd2Id); + +%device_types = ( 0 => "Cube", 1 => "HeatingThermostat", 2 => "HeatingThermostatPlus", @@ -26,6 +30,25 @@ my %device_types = ( 5 => "PushButton" ); +%msgId2Cmd = ( + "00" => "PairPing", + "01" => "PairPong", + "02" => "Ack", + "03" => "TimeInformation", + "11" => "ConfigTemperatures", #like boost/eco/comfort etc + "30" => "ShutterContactState", + "42" => "WallThermostatState", #by WallMountedThermostat + "60" => "ThermostatState", #by HeatingThermostat + "40" => "SetTemperature", #to thermostat + "20" => "AddLinkPartner", + "21" => "RemoveLinkPartner", + "22" => "SetGroupId", + "23" => "RemoveGroupId", + "F1" => "WakeUp", + "F0" => "Reset", + ); +%msgCmd2Id = reverse %msgId2Cmd; + my %interfaces = ( "Cube" => undef, "HeatingThermostat" => "thermostat;battery;temperature", diff --git a/fhem/FHEM/14_CUL_MAX.pm b/fhem/FHEM/14_CUL_MAX.pm index b1f61c8a5..57d439c04 100644 --- a/fhem/FHEM/14_CUL_MAX.pm +++ b/fhem/FHEM/14_CUL_MAX.pm @@ -5,6 +5,11 @@ package main; use strict; use warnings; +require "10_MAX.pm"; + +our %msgId2Cmd; +our %msgCmd2Id; +our %device_types; sub CUL_MAX_SendDeviceCmd($$); sub CUL_MAX_Send(@); @@ -20,16 +25,6 @@ my $timeBroadcastInterval = 6*60*60; #= 6 hours, the same time that the cube use my $resendRetries = 10; #how often resend before giving up? -#TODO: this is duplicated in MAXLAN -my %device_types = ( - 0 => "Cube", - 1 => "HeatingThermostat", - 2 => "HeatingThermostatPlus", - 3 => "WallMountedThermostat", - 4 => "ShutterContact", - 5 => "PushButton" -); - sub CUL_MAX_Initialize($) { @@ -112,32 +107,6 @@ CUL_MAX_Set($@) return undef; } -################################### -my %msgTypes = ( #Receiving: - "00" => "PairPing", - "01" => "PairPong", - "02" => "Ack", - "03" => "TimeInformation", - "11" => "ConfigTemperatures", #like boost/eco/comfort etc - "30" => "ShutterContactState", - "42" => "WallThermostatState", #by WallMountedThermostat - "60" => "ThermostatState", #by HeatingThermostat - "40" => "SetTemperature", #to thermostat - "20" => "AddLinkPartner", - "21" => "RemoveLinkPartner", - "22" => "SetGroupId", - "23" => "RemoveGroupId", - "F1" => "WakeUp", - "F0" => "Reset", - ); -my %sendTypes = (#Sending: - "PairPong" => "01", - "TimeInformation" => "03", - #"40" => "SetTemperature", - #"11" => "SetConfiguration", - #"F1" => "WakeUp", - ); - #Array of all packet that we wait to be ack'ed my @waitForAck = (); @@ -163,9 +132,9 @@ CUL_MAX_Parse($$) #convert adresses to lower case $src = lc($src); $dst = lc($dst); - my $msgType = exists($msgTypes{$msgTypeRaw}) ? $msgTypes{$msgTypeRaw} : $msgTypeRaw; + my $msgType = exists($msgId2Cmd{$msgTypeRaw}) ? $msgId2Cmd{$msgTypeRaw} : $msgTypeRaw; Log 5, "CUL_MAX_Parse: len $len, msgcnt $msgcnt, msgflag $msgFlag, msgTypeRaw $msgType, src $src, dst $dst, groupid $groupid, payload $payload"; - if(exists($msgTypes{$msgTypeRaw})) { + if(exists($msgId2Cmd{$msgTypeRaw})) { if($msgType eq "Ack") { Dispatch($shash, "MAX,Ack,$src,$payload", {RAWMSG => $rmsg}); my $i = 0;