From b346b69b6d7ca47554a5f15d966b5d31c1a4e8ff Mon Sep 17 00:00:00 2001 From: mgehre Date: Sat, 12 Jan 2013 15:14:22 +0000 Subject: [PATCH] MAX: make internal MAXLAN/CUL_MAX interface nicer git-svn-id: https://svn.fhem.de/fhem/trunk@2488 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/00_MAXLAN.pm | 12 ++---------- fhem/FHEM/10_MAX.pm | 36 +++++++++++------------------------- fhem/FHEM/14_CUL_MAX.pm | 38 -------------------------------------- 3 files changed, 13 insertions(+), 73 deletions(-) diff --git a/fhem/FHEM/00_MAXLAN.pm b/fhem/FHEM/00_MAXLAN.pm index 9357fbc8d..bae1d92fe 100755 --- a/fhem/FHEM/00_MAXLAN.pm +++ b/fhem/FHEM/00_MAXLAN.pm @@ -19,7 +19,6 @@ sub MAXLAN_ReadSingleResponse($$); sub MAXLAN_SimpleWrite(@); sub MAXLAN_Poll($); sub MAXLAN_Send(@); -sub MAXLAN_SendDeviceCmd($$); sub MAXLAN_RequestConfiguration($$); sub MAXLAN_RemoveDevice($$); @@ -104,7 +103,6 @@ MAXLAN_Define($$) $hash->{PARTIAL} = ""; $hash->{DeviceName} = $dev; #This interface is shared with 14_CUL_MAX.pm - $hash->{SendDeviceCmd} = \&MAXLAN_SendDeviceCmd; $hash->{Send} = \&MAXLAN_Send; $hash->{RemoveDevice} = \&MAXLAN_RemoveDevice; @@ -716,20 +714,14 @@ MAXLAN_Send(@) { my ($hash, $cmd, $dst, $payload, $flags, $groupId, $msgcnt) = @_; - $flags = "0"x8 if(!$flags); + $flags = "00" if(!$flags); $groupId = "00" if(!defined($groupId)); if(defined($msgcnt)) { Log 2, "MAXLAN_Send: MAXLAN does not support msgcnt"; } - return MAXLAN_SendDeviceCmd($hash, pack("H2B8H*","00",$flags,$msgCmd2Id{$cmd}."000000".$dst.$groupId.$payload)); -} + my $payload = pack("H*","00".$flags.$msgCmd2Id{$cmd}."000000".$dst.$groupId.$payload); -#Sends command to a device and waits for acknowledgment -sub -MAXLAN_SendDeviceCmd($$) -{ - my ($hash,$payload) = @_; my $ret = MAXLAN_Write($hash,"s:".encode_base64($payload,""), "S:"); #Reschedule a poll in the near future after the cube will #have gotten an answer diff --git a/fhem/FHEM/10_MAX.pm b/fhem/FHEM/10_MAX.pm index ea1ff6c19..f811b6806 100755 --- a/fhem/FHEM/10_MAX.pm +++ b/fhem/FHEM/10_MAX.pm @@ -56,6 +56,7 @@ my %readingDef = ( #min/max/default "21" => "RemoveLinkPartner", "22" => "SetGroupId", "23" => "RemoveGroupId", + "82" => "SetDisplayActualTemperature", "F1" => "WakeUp", "F0" => "Reset", ); @@ -214,22 +215,14 @@ MAX_Set($@) $until = sprintf("%06x",MAX_DateTime2Internal($args[2]." ".$args[3])); } - my $groupid = $hash->{groupid}; - $groupid = 0; #comment this line to control the whole group, no only one device - - $temperature = int($temperature*2.0) | ($ctrlmode << 6); #convert to internal representation - my $payload; - if(defined($until)) { - $payload = pack("CCCCCCH6CCH6",0x00,$groupid?0x04:0,0x40,0x00,0x00,0x00,$hash->{addr},$groupid,$temperature,$until); - }else{ - $payload = pack("CCCCCCH6CC" ,0x00,$groupid?0x04:0,0x40,0x00,0x00,0x00,$hash->{addr},$groupid,$temperature); - } - return ($hash->{IODev}{SendDeviceCmd})->($hash->{IODev},$payload); + my $payload = sprintf("%02x",int($temperature*2.0) | ($ctrlmode << 6)); + $payload .= $until if(defined($until)); + return ($hash->{IODev}{Send})->($hash->{IODev},"SetTemperature",$hash->{addr},$payload); }elsif($setting eq "groupid"){ return "argument needed" if(@args == 0); - return ($hash->{IODev}{SendDeviceCmd})->($hash->{IODev},pack("CCCCCCH6CC",0x00,0x00,0x22,0x00,0x00,0x00,$hash->{addr},0x00,$args[0])); + return ($hash->{IODev}{Send})->($hash->{IODev},"SetGroupId",$hash->{addr}, sprintf("%02x",$args[0]) ); }elsif( $setting ~~ ["ecoTemperature", "comfortTemperature", "measurementOffset", "maximumTemperature", "minimumTemperature", "windowOpenTemperature", "windowOpenDuration" ] and ($hash->{type} eq "HeatingThermostat" or $hash->{type} eq "WallMountedThermostat")) { return "Cannot set without IODev" if(!exists($hash->{IODev})); @@ -242,8 +235,6 @@ MAX_Set($@) my $windowOpenDuration = MAX_ReadingsVal($hash,"windowOpenDuration"); my $measurementOffset = MAX_ReadingsVal($hash,"measurementOffset"); - readingsSingleUpdate($hash, $setting, $args[0], 0); - my $comfort = int(MAX_ParseTemperature($comfortTemperature)*2); my $eco = int(MAX_ParseTemperature($ecoTemperature)*2); my $max = int(MAX_ParseTemperature($maximumTemperature)*2); @@ -252,16 +243,14 @@ MAX_Set($@) my $windowOpenTemp = int(MAX_ParseTemperature($windowOpenTemperature)*2); my $windowOpenTime = int($windowOpenDuration/5); - my $payload = pack("CCCCCCH6C"."CCCCCCC",0x00,0x00,0x11,0x00,0x00,0x00,$hash->{addr},0x00, - $comfort,$eco,$max,$min,$offset,$windowOpenTemp,$windowOpenTime); - return ($hash->{IODev}{SendDeviceCmd})->($hash->{IODev},$payload); + my $payload = sprintf("%02x%02x%02x%02x%02x%02x%02x",$comfort,$eco,$max,$min,$offset,$windowOpenTemp,$windowOpenTime); + return ($hash->{IODev}{Send})->($hash->{IODev},"ConfigTemperatures",$hash->{addr},$payload) } elsif($setting eq "displayActualTemperature" and $hash->{type} eq "WallMountedThermostat") { return "Invalid arg" if($args[0] ne "0" and $args[0] ne "1"); readingsSingleUpdate($hash, $setting, $args[0], 0); - my $payload = pack("CCCCCCH6CC",0x00,0x00,0x82,0x00,0x00,0x00,$hash->{addr},0x00, $args[0] ? 4 : 0); - return ($hash->{IODev}{SendDeviceCmd})->($hash->{IODev},$payload); + return ($hash->{IODev}{Send})->($hash->{IODev},"SetDisplayActualTemperature",$hash->{addr},sprintf("%02x",$args[0] ? 4 : 0)); } elsif($setting eq "associate") { my $dest = $args[0]; @@ -275,8 +264,7 @@ MAX_Set($@) my $destType = MAX_TypeToTypeId($modules{MAX}{defptr}{$dest}{type}); Log 2, "Warning: Device do not have same groupid" if($hash->{groupid} != $modules{MAX}{defptr}{groupid}); Log 5, "Using dest $dest, destType $destType"; - my $payload = pack("CCCCCCH6CH6C",0x00,0x00,0x20,0x00,0x00,0x00,$hash->{addr}, $hash->{groupid}, $dest, $destType); - return ($hash->{IODev}{SendDeviceCmd})->($hash->{IODev},$payload); + return ($hash->{IODev}{Send})->($hash->{IODev},"AddLinkPartner",$hash->{addr},sprintf("%02x%s%02x",$hash->{groupid}, $dest, $destType)); } elsif($setting eq "factoryReset") { @@ -285,13 +273,11 @@ MAX_Set($@) return ($hash->{IODev}{RemoveDevice})->($hash->{IODev},$hash->{addr}); } else { #CUL_MAX - my $payload = pack("CCCCCCH6C",0x00,0x00,0xF0,0x00,0x00,0x00,$hash->{addr}, 0); - return ($hash->{IODev}{SendDeviceCmd})->($hash->{IODev},$payload); + return ($hash->{IODev}{Send})->($hash->{IODev},"Reset",$hash->{addr}); } } elsif($setting eq "wakeUp") { - my $payload = pack("CCCCCCH6CC",0x00,0x00,0xF1,0x00,0x00,0x00,$hash->{addr}, 0, 0x3F); - return ($hash->{IODev}{SendDeviceCmd})->($hash->{IODev},$payload); + return ($hash->{IODev}{Send})->($hash->{IODev},"WakeUp",$hash->{addr}, 0x3F); }else{ my $templist = "off,".join(",",map { sprintf("%2.1f",$_/2) } (10..60)) . ",on"; diff --git a/fhem/FHEM/14_CUL_MAX.pm b/fhem/FHEM/14_CUL_MAX.pm index c50e182b4..f46360aef 100644 --- a/fhem/FHEM/14_CUL_MAX.pm +++ b/fhem/FHEM/14_CUL_MAX.pm @@ -11,7 +11,6 @@ our %msgId2Cmd; our %msgCmd2Id; our %device_types; -sub CUL_MAX_SendDeviceCmd($$); sub CUL_MAX_Send(@); sub CUL_MAX_BroadcastTime(@); sub CUL_MAX_Set($@); @@ -76,7 +75,6 @@ CUL_MAX_Define($$) } #This interface is shared with 00_MAXLAN.pm - $hash->{SendDeviceCmd} = \&CUL_MAX_SendDeviceCmd; $hash->{Send} = \&CUL_MAX_Send; CUL_MAX_BroadcastTime($hash); @@ -332,42 +330,6 @@ CUL_MAX_Resend($) InternalTimer($resendTime, "CUL_MAX_Resend", $hash, 0); } -#This is deprecated as part of the MAX backend interface -sub -CUL_MAX_SendDeviceCmd($$) -{ - my ($hash,$payload) = @_; - - CUL_MAX_Check($hash); - - my $dstaddr = unpack("H6",substr($payload,6,3)); - my $dhash = CUL_MAX_DeviceHash($dstaddr); - - my $cnt = unpack("C",substr($payload,0,1)); - if($cnt == 0) { - #replace message counter if not already set - $cnt = ($dhash->{READINGS}{msgcnt}{VAL} + 1) & 0xFF; - $dhash->{READINGS}{msgcnt}{VAL} = $cnt; - substr($payload,0,1) = pack("C",$cnt); - } - #replace source address - substr($payload,3,3) = pack("H6",$hash->{addr}); - #Prefix length byte - $payload = pack("C",length($payload)) . $payload; - - $payload = unpack("H*",$payload); #convert to hex - Log 5, "CUL_MAX_SendDeviceCmd: ". $payload; - IOWrite($hash, "", "Zs". $payload); - my $timeout = gettimeofday()+$ackTimeout; - $waitForAck[@waitForAck] = { "packet" => $payload, - "dest" => $dstaddr, - "cnt" => $cnt, - "time" => $timeout, - "resends" => "0" }; - InternalTimer($timeout, "CUL_MAX_Resend", $hash, 0); - return undef; -} - sub CUL_MAX_GetTimeInformationPayload() {