diff --git a/fhem/FHEM/00_MAXLAN.pm b/fhem/FHEM/00_MAXLAN.pm index c4813fce9..112e39a7b 100755 --- a/fhem/FHEM/00_MAXLAN.pm +++ b/fhem/FHEM/00_MAXLAN.pm @@ -64,7 +64,7 @@ MAXLAN_Define($$) if(@a < 3) { my $msg = "wrong syntax: define MAXLAN ip[:port] [pollintervall [ondemand]]"; - Log 2, $msg; + Log3 $hash, 2, $msg; return $msg; } @@ -74,7 +74,7 @@ MAXLAN_Define($$) $dev .= ":62910" if($dev !~ m/:/ && $dev ne "none" && $dev !~ m/\@/); if($dev eq "none") { - Log 1, "$name device is none, commands will be echoed only"; + Log3 $hash, 1, "$name device is none, commands will be echoed only"; $attr{$name}{dummy} = 1; return undef; } @@ -88,7 +88,7 @@ MAXLAN_Define($$) $hash->{persistent} = 0; } else { my $msg = "unknown argument $arg"; - Log 1, $msg; + Log3 $hash, 1, $msg; return $msg; } } @@ -124,7 +124,7 @@ sub MAXLAN_Disconnect($) { my $hash = shift; - Log 5, "MAXLAN_Disconnect"; + Log3 $hash, 5, "MAXLAN_Disconnect"; #All operations here are no-op if already disconnected DevIo_CloseDev($hash); RemoveInternalTimer($hash); @@ -143,7 +143,7 @@ MAXLAN_Connect($) DevIo_OpenDev($hash, 0, ""); if(!MAXLAN_IsConnected($hash)) { my $msg = "MAXLAN_Connect: Could not connect"; - Log 2, $msg; + Log3 $hash, 2, $msg; return $msg; } @@ -237,9 +237,9 @@ MAXLAN_Set($@) my $timezones; if(exists($tz_list{$timezoneAttr})) { $timezones = $tz_list{$timezoneAttr}; - Log 3, "MAX Cube is set to timezone $timezoneAttr"; + Log3 $hash, 3, "MAX Cube is set to timezone $timezoneAttr"; } else { - Log 2, "ERROR: Timezone $timezoneAttr of MAX Cube is invalid. Using CET-CEST"; + Log3 $hash, 2, "ERROR: Timezone $timezoneAttr of MAX Cube is invalid. Using CET-CEST"; $timezones = $tz_list{"CET-CEST"}; } @@ -277,13 +277,13 @@ MAXLAN_ExpectAnswer($$) if(!defined($rmsg)) { my $msg = "MAXLAN_ExpectAnswer: Error while waiting for answer $expectedanswer"; - Log 1, $msg; + Log3 $hash, 1, $msg; return $msg; } my $ret = undef; if($rmsg !~ m/^$expectedanswer/) { - Log 2, "MAXLAN_ExpectAnswer: Got unexpected response, expected $expectedanswer"; + Log3 $hash, 2, "MAXLAN_ExpectAnswer: Got unexpected response, expected $expectedanswer"; MAXLAN_Parse($hash,$rmsg); return "Got unexpected response, expected $expectedanswer"; } @@ -317,7 +317,7 @@ MAXLAN_ReadSingleResponse($$) #Check timeout if(gettimeofday() > $maxTime) { if($waitForResponse) { - Log 1, "MAXLAN_ReadSingleResponse: timeout while reading from socket, disconnecting"; + Log3 $hash, 1, "MAXLAN_ReadSingleResponse: timeout while reading from socket, disconnecting"; MAXLAN_Disconnect($hash); } return undef;; @@ -326,7 +326,7 @@ MAXLAN_ReadSingleResponse($$) #Wait for data my $nfound = select($rout=$rin, $wout=$win, $eout=$ein, $read_timeout); if($nfound == -1) { - Log 1, "MAXLAN_ReadSingleResponse: error during select, ret = $nfound"; + Log3 $hash, 1, "MAXLAN_ReadSingleResponse: error during select, ret = $nfound"; return undef; } last if($nfound == 0 and !$waitForResponse); @@ -336,7 +336,7 @@ MAXLAN_ReadSingleResponse($$) my $buf; my $res = sysread($hash->{TCPDev}, $buf, 256); if(!defined($res)){ - Log 1, "MAXLAN_ReadSingleResponse: error during read"; + Log3 $hash, 1, "MAXLAN_ReadSingleResponse: error during read"; return undef; #error occured } @@ -385,7 +385,7 @@ MAXLAN_Read($) last if(!$rmsg); # The Msg N: .... is the only one that may come spontanously from # the cube while we are in pairmode - Log 2, "Unsolicated response from Cube: $rmsg" unless($hash->{pairmode} and substr($rmsg,0,2) eq "N:"); + Log3 $hash, 2, "Unsolicated response from Cube: $rmsg" unless($hash->{pairmode} and substr($rmsg,0,2) eq "N:"); MAXLAN_Parse($hash, $rmsg); } } @@ -396,7 +396,7 @@ MAXLAN_SendMetadata($) my $hash = shift; if(defined($hash->{metadataVersionMismatch})){ - Log 3,"MAXLAN_SendMetadata: current version of metadata unexpected, not overwriting!"; + Log3 $hash, 3,"MAXLAN_SendMetadata: current version of metadata unexpected, not overwriting!"; return; } @@ -408,7 +408,7 @@ MAXLAN_SendMetadata($) my @devices = @{$hash->{devices}}; if(@groups > $maxGroupCount || @devices > $maxDeviceCount) { - Log 1, "MAXLAN_SendMetadata: you got more than $maxGroupCount groups or $maxDeviceCount devices"; + Log3 $hash, 1, "MAXLAN_SendMetadata: you got more than $maxGroupCount groups or $maxDeviceCount devices"; return; } @@ -417,7 +417,7 @@ MAXLAN_SendMetadata($) $metadata .= pack("C",scalar(@groups)); foreach(@groups){ if(length($_->{name}) > $maxNameLength) { - Log 1, "Group name $_->{name} is too long, maximum of $maxNameLength characters allowed"; + Log3 $hash, 1, "Group name $_->{name} is too long, maximum of $maxNameLength characters allowed"; return; } $metadata .= pack("CC/aH6",$_->{id}, $_->{name}, $_->{masterAddr}); @@ -425,7 +425,7 @@ MAXLAN_SendMetadata($) $metadata .= pack("C",scalar(@devices)); foreach(@devices){ if(length($_->{name}) > $maxNameLength) { - Log 1, "Device name $_->{name} is too long, maximum of $maxNameLength characters allowed"; + Log3 $hash, 1, "Device name $_->{name} is too long, maximum of $maxNameLength characters allowed"; return; } $metadata .= pack("CH6a[10]C/aC",$_->{type}, $_->{addr}, $_->{serial}, $_->{name}, $_->{groupid}); @@ -458,12 +458,9 @@ MAXLAN_Parse($$) my ($hash, $rmsg) = @_; my $name = $hash->{NAME}; - my $ll3 = GetLogLevel($name,3); - my $ll5 = GetLogLevel($name,5); - Log $ll5, "Msg $rmsg"; + Log3 $hash, 5, "Msg $rmsg"; my $cmd = substr($rmsg,0,1); # get leading char my @args = split(',', substr($rmsg,2)); - #Log $ll5, 'args '.join(" ",@args); if ($cmd eq 'H'){ #Hello $hash->{serial} = $args[0]; @@ -498,14 +495,14 @@ MAXLAN_Parse($$) + $cubedatetime->{minute} - $min); $hash->{cubeTimeDifference} = $difference; if($difference > 1) { - Log 2, "MAXLAN_Parse: Cube thinks it is $cubedatetime->{day}.$cubedatetime->{month}.$cubedatetime->{year} $cubedatetime->{hour}:$cubedatetime->{minute}"; - Log 2, "MAXLAN_Parse: Time difference is $difference minutes"; + Log3 $hash, 2, "MAXLAN_Parse: Cube thinks it is $cubedatetime->{day}.$cubedatetime->{month}.$cubedatetime->{year} $cubedatetime->{hour}:$cubedatetime->{minute}"; + Log3 $hash, 2, "MAXLAN_Parse: Time difference is $difference minutes"; } } else { - Log 2, "MAXLAN_Parse: Cube has no time set"; + Log3 $hash, 2, "MAXLAN_Parse: Cube has no time set"; } - Log $ll5, "MAXLAN_Parse: Got hello, connection ip $args[4], duty cycle $dutycycle, freememory $freememory, clockset $hash->{clockset}"; + Log3 $hash, 5, "MAXLAN_Parse: Got hello, connection ip $args[4], duty cycle $dutycycle, freememory $freememory, clockset $hash->{clockset}"; } elsif($cmd eq 'M') { #Metadata, this is basically a readwrite part of the cube's memory. @@ -522,12 +519,12 @@ MAXLAN_Parse($$) ($magic,$version,$numgroups,@groupsdevices) = unpack("CCCXC/(CC/aH6)C/(CH6a[10]C/aC)C",$bindata); 1; } or do { - Log 1, "MAXLAN_Parse: Metadata response is malformed!"; + Log3 $hash, 1, "MAXLAN_Parse: Metadata response is malformed!"; return $name; }; if($magic != $metadata_magic || $version != $metadata_version) { - Log 3, "MAXLAN_Parse: magic $magic/version $version are not $metadata_magic/$metadata_version as expected"; + Log3 $hash, 3, "MAXLAN_Parse: magic $magic/version $version are not $metadata_magic/$metadata_version as expected"; $hash->{metadataVersionMismatch} = 1; } @@ -551,20 +548,19 @@ MAXLAN_Parse($$) $hash->{devices}[-1]->{groupid} = $groupsdevices[$i+4]; } - #Log $ll5, "Got Metadata, hash: ".Dumper($hash); }elsif($cmd eq "C"){#Configuration return $name if(@args < 2); my $bindata = decode_base64($args[1]); if(length($bindata) < 18) { - Log 1, "Invalid C: response, not enough data"; + Log3 $hash, 1, "Invalid C: response, not enough data"; return $name; } #Parse the first 18 bytes, those are send for every device my ($len,$addr,$devicetype,$groupid,$firmware,$testresult,$serial) = unpack("CH6CCCCa[10]", $bindata); - Log $ll5, "MAXLAN_Parse: len $len, addr $addr, devicetype $devicetype, firmware $firmware, testresult $testresult, groupid $groupid, serial $serial"; + Log3 $hash, 5, "MAXLAN_Parse: len $len, addr $addr, devicetype $devicetype, firmware $firmware, testresult $testresult, groupid $groupid, serial $serial"; $len = $len+1; #The len field itself was not counted @@ -604,7 +600,7 @@ MAXLAN_Parse($$) $valveoffset = int($valveoffset*100/255 + 0.5); # + 0.5 for correct rounding my $decalcDay = ($decalcifiction >> 5) & 0x07; my $decalcTime = $decalcifiction & 0x1F; - Log $ll5, "comfortemp $comforttemp, ecotemp $ecotemp, boostValve $boostValve, boostDuration $boostDuration, tempoffset $tempoffset, minsetpointtemp $minsetpointtemp, maxsetpointtemp $maxsetpointtemp, windowopentemp $windowopentemp, windowopendur $windowopendur"; + Log3 $hash, 5, "comfortemp $comforttemp, ecotemp $ecotemp, boostValve $boostValve, boostDuration $boostDuration, tempoffset $tempoffset, minsetpointtemp $minsetpointtemp, maxsetpointtemp $maxsetpointtemp, windowopentemp $windowopentemp, windowopendur $windowopendur"; Dispatch($hash, "MAX,1,HeatingThermostatConfig,$addr,$ecotemp,$comforttemp,$maxsetpointtemp,$minsetpointtemp,$weekprofile,$boostValve,$boostDuration,$tempoffset,$windowopentemp,$windowopendur,$maxvalvesetting,$valveoffset,$decalcDay,$decalcTime", {}); }elsif($device_types{$devicetype} eq "WallMountedThermostat"){ @@ -613,24 +609,24 @@ MAXLAN_Parse($$) $ecotemp = MAXLAN_ExtractTemperature($ecotemp); $maxsetpointtemp = MAXLAN_ExtractTemperature($maxsetpointtemp); $minsetpointtemp = MAXLAN_ExtractTemperature($minsetpointtemp); - Log $ll5, "comfortemp $comforttemp, ecotemp $ecotemp, minsetpointtemp $minsetpointtemp, maxsetpointtemp $maxsetpointtemp"; + Log3 $hash, 5, "comfortemp $comforttemp, ecotemp $ecotemp, minsetpointtemp $minsetpointtemp, maxsetpointtemp $maxsetpointtemp"; if(defined($tempoffset)) { #With firmware 18 (opposed to firmware 16) $tempoffset = $tempoffset/2.0-3.5; #convert to degree my $boostValve = ($boost & 0x1F) * 5; my $boostDuration = $boost >> 5; $windowopentemp = MAXLAN_ExtractTemperature($windowopentemp); - Log $ll5, "tempoffset $tempoffset, boostValve $boostValve, boostDuration $boostDuration, windowOpenTemp $windowopentemp"; + Log3 $hash, 5, "tempoffset $tempoffset, boostValve $boostValve, boostDuration $boostDuration, windowOpenTemp $windowopentemp"; Dispatch($hash, "MAX,1,WallThermostatConfig,$addr,$ecotemp,$comforttemp,$maxsetpointtemp,$minsetpointtemp,$weekprofile,$boostValve,$boostDuration,$tempoffset,$windowopentemp", {}); } else { Dispatch($hash, "MAX,1,WallThermostatConfig,$addr,$ecotemp,$comforttemp,$maxsetpointtemp,$minsetpointtemp,$weekprofile", {}); } }elsif($device_types{$devicetype} eq "ShutterContact"){ - Log 2, "MAXLAN_Parse: ShutterContact send some configuration, but none was expected" if($len > 18); + Log3 $hash, 2, "MAXLAN_Parse: ShutterContact send some configuration, but none was expected" if($len > 18); }elsif($device_types{$devicetype} eq "PushButton"){ - Log 2, "MAXLAN_Parse: PushButton send some configuration, but none was expected" if($len > 18); + Log3 $hash, 2, "MAXLAN_Parse: PushButton send some configuration, but none was expected" if($len > 18); }else{ #TODO - Log 2, "MAXLAN_Parse: Got configdata for unimplemented devicetype $devicetype"; + Log3 $hash, 2, "MAXLAN_Parse: Got configdata for unimplemented devicetype $devicetype"; } #Clear Error @@ -666,14 +662,14 @@ MAXLAN_Parse($$) my $unkbit2 = vec($bits1,5,2); my $unkbit3 = vec($bits1,7,1); - Log 5, "len $len, addr $addr, initialized $initialized, valid $valid, error $error, errCmd $errCmd, answer $answer, unkbit ($unkbit1,$unkbit2,$unkbit3)"; + Log3 $hash, 5, "len $len, addr $addr, initialized $initialized, valid $valid, error $error, errCmd $errCmd, answer $answer, unkbit ($unkbit1,$unkbit2,$unkbit3)"; my $payload = unpack("H*",substr($bindata,6,$len-6+1)); #+1 because the len field is not counted if($valid) { my $shash = $modules{MAX}{defptr}{$addr}; if(!$shash) { - Log 2, "Got List response for undefined device with addr $addr"; + Log3 $hash, 2, "Got List response for undefined device with addr $addr"; }elsif($shash->{type} =~ /HeatingThermostat.*/){ Dispatch($hash, "MAX,1,ThermostatState,$addr,$payload", {}); }elsif($shash->{type} eq "WallMountedThermostat"){ @@ -683,7 +679,7 @@ MAXLAN_Parse($$) }elsif($shash->{type} eq "PushButton"){ Dispatch($hash, "MAX,1,PushButtonState,$addr,$payload", {}); }else{ - Log 2, "MAXLAN_Parse: Got status for unimplemented device type $shash->{type}"; + Log3 $hash, 2, "MAXLAN_Parse: Got status for unimplemented device type $shash->{type}"; } } @@ -711,7 +707,7 @@ MAXLAN_Parse($$) return $name; } my ($type, $addr, $serial) = unpack("CH6a[10]", decode_base64($args[0])); - Log 2, "MAXLAN_Parse: Paired new device, type $device_types{$type}, addr $addr, serial $serial"; + Log3 $hash, 2, "MAXLAN_Parse: Paired new device, type $device_types{$type}, addr $addr, serial $serial"; Dispatch($hash, "MAX,1,define,$addr,$device_types{$type},$serial,0", {}); #After a device has been paired, it automatically appears in the "L" and "C" commands, @@ -724,13 +720,13 @@ MAXLAN_Parse($$) my $discarded = $args[1]; $hash->{freememoryslot} = hex($args[2]); - Log 5, "MAXLAN_Parse: dutycyle $hash->{dutycycle}, freememoryslot $hash->{freememoryslot}"; + Log3 $hash, 5, "MAXLAN_Parse: dutycyle $hash->{dutycycle}, freememoryslot $hash->{freememoryslot}"; - Log 3, "MAXLAN_Parse: 1% rule: we sent too much, cmd is now in queue" if($hash->{dutycycle} == 100 && $hash->{freememoryslot} > 0); - Log 2, "MAXLAN_Parse: 1% rule: we sent too much, queue is full" if($hash->{dutycycle} == 100 && $hash->{freememoryslot} == 0); - Log 2, "MAXLAN_Parse: Command was discarded" if($discarded); + Log3 $hash, 3, "MAXLAN_Parse: 1% rule: we sent too much, cmd is now in queue" if($hash->{dutycycle} == 100 && $hash->{freememoryslot} > 0); + Log3 $hash, 2, "MAXLAN_Parse: 1% rule: we sent too much, queue is full" if($hash->{dutycycle} == 100 && $hash->{freememoryslot} == 0); + Log3 $hash, 2, "MAXLAN_Parse: Command was discarded" if($discarded); } else { - Log 2, "MAXLAN_Parse: Unknown command $cmd"; + Log3 $hash, 2, "MAXLAN_Parse: Unknown command $cmd"; } return $name; } @@ -744,7 +740,7 @@ MAXLAN_SimpleWrite(@) my ($hash, $msg) = @_; my $name = $hash->{NAME}; - Log GetLogLevel($name,5), 'MAXLAN_SimpleWrite: '.$msg; + Log3 $hash, 5, 'MAXLAN_SimpleWrite: '.$msg; return "MAXLAN_SimpleWrite: Not connected" if(!MAXLAN_IsConnected($hash)); @@ -753,7 +749,7 @@ MAXLAN_SimpleWrite(@) my $ret = syswrite($hash->{TCPDev}, $msg); #TODO: none of those conditions detect if the connection is actually lost! if(!$hash->{TCPDev} || !defined($ret) || !$hash->{TCPDev}->connected) { - Log GetLogLevel($name,1), 'MAXLAN_SimpleWrite failed'; + Log3 $hash, 1, 'MAXLAN_SimpleWrite failed'; MAXLAN_Disconnect($hash); return "MAXLAN_SimpleWrite: syswrite failed"; } @@ -821,7 +817,7 @@ MAXLAN_Send(@) $flags = $opts{flags} if(exists($opts{flags})); $groupId = $opts{groupId} if(exists($opts{groupId})); - Log 2, "MAXLAN_Send: MAXLAN does not support src" if(exists($opts{src})); + Log3 $hash, 2, "MAXLAN_Send: MAXLAN does not support src" if(exists($opts{src})); $callbackParam = $opts{callbackParam} if(exists($opts{callbackParam})); $payload = pack("H*","00".$flags.$msgCmd2Id{$cmd}."000000".$dst.$groupId.$payload); diff --git a/fhem/FHEM/10_MAX.pm b/fhem/FHEM/10_MAX.pm index 62c086857..c888d6f01 100755 --- a/fhem/FHEM/10_MAX.pm +++ b/fhem/FHEM/10_MAX.pm @@ -66,14 +66,14 @@ MAX_Initialize($) { my ($hash) = @_; - Log GetLogLevel($hash->{NAME}, 5), "Calling MAX_Initialize"; + Log3 $hash, 5, "Calling MAX_Initialize"; $hash->{Match} = "^MAX"; $hash->{DefFn} = "MAX_Define"; $hash->{UndefFn} = "MAX_Undef"; $hash->{ParseFn} = "MAX_Parse"; $hash->{SetFn} = "MAX_Set"; $hash->{AttrList} = "IODev do_not_notify:1,0 ignore:0,1 dummy:0,1 " . - "showtime:1,0 loglevel:0,1,2,3,4,5,6 keepAuto:0,1 scanTemp:0,1 ". + "showtime:1,0 keepAuto:0,1 scanTemp:0,1 ". $readingFnAttributes; return undef; } @@ -93,15 +93,15 @@ MAX_Define($$) my $addr = lc($a[3]); #all addr should be lowercase if(exists($modules{MAX}{defptr}{$addr})) { my $msg = "MAX_Define: Device with addr $addr is already defined"; - Log 1, $msg; + Log3 $hash, 1, $msg; return $msg; } if($type eq "Cube") { my $msg = "MAX_Define: Device type 'Cube' is deprecated. All properties have been moved to the MAXLAN device."; - Log 1, $msg; + Log3 $hash, 1, $msg; return $msg; } - Log GetLogLevel($hash->{NAME}, 5), "Max_define $type with addr $addr "; + Log3 $hash, 5, "Max_define $type with addr $addr "; $hash->{type} = $type; $hash->{addr} = $addr; $modules{MAX}{defptr}{$addr} = $hash; @@ -133,7 +133,7 @@ MAX_TypeToTypeId($) foreach (keys %device_types) { return $_ if($_[0] eq $device_types{$_}); } - Log 1, "MAX_TypeToTypeId: Invalid type $_[0]"; + Log3 $hash, 1, "MAX_TypeToTypeId: Invalid type $_[0]"; return 0; } @@ -179,7 +179,7 @@ MAX_ReadingsVal(@) #$readingDef{$name} array is [validatingFunc, defaultValue] if(exists($readingDef{$name}) and !$readingDef{$name}[0]->($val)) { #Error: invalid value - Log 2, "MAX: Invalid value $val for READING $name. Forcing to $readingDef{$name}[1]"; + Log3 $hash, 2, "MAX: Invalid value $val for READING $name. Forcing to $readingDef{$name}[1]"; $val = $readingDef{$name}[1]; #Save default value to READINGS @@ -261,7 +261,7 @@ MAX_Set($@) if(AttrVal($hash->{NAME},"keepAuto","0") ne "0" && MAX_ReadingsVal($hash,"mode") eq "auto") { - Log 5, "MAX_Set: staying in auto mode"; + Log3 $hash, 5, "MAX_Set: staying in auto mode"; $ctrlmode = 0; #auto } @@ -311,7 +311,7 @@ MAX_Set($@) if(!MAX_Validate($setting, $val)) { my $msg = "Invalid value $args[0] for $setting"; - Log 1, $msg; + Log3 $hash, 1, $msg; return $msg; } @@ -345,7 +345,7 @@ MAX_Set($@) if(!MAX_Validate($setting, $args[0])) { my $msg = "Invalid value $args[0] for $setting"; - Log 1, $msg; + Log3 $hash, 1, $msg; return $msg; } @@ -395,14 +395,14 @@ MAX_Set($@) if($hash->{type} eq "ShutterContact") { return "Invalid number of arguments" if(@args != 2); - Log 2, "fake is deprectaed and will be removed. Please use CUL_MAX's fakeSC"; + Log3 $hash, 2, "fake is deprectaed and will be removed. Please use CUL_MAX's fakeSC"; my $state = $args[1] ? "12" : "10"; return ($hash->{IODev}{Send})->($hash->{IODev},"ShutterContactState",$dest,$state, flags => "06", src => $hash->{addr}); } elsif($hash->{type} eq "WallMountedThermostat") { return "Invalid number of arguments" if(@args != 3); return "desiredTemperature is invalid" if($args[1] < 4.5 || $args[2] > 30.5); - Log 2, "fake is deprectaed and will be removed. Please use CUL_MAX's fakeWT"; + Log3 $hash, 2, "fake is deprectaed and will be removed. Please use CUL_MAX's fakeWT"; $args[2] = 0 if($args[2] < 0); #Clamp temperature to minimum of 0 degree #Encode into binary form @@ -442,7 +442,7 @@ MAX_Set($@) $destType = MAX_TypeToTypeId($modules{MAX}{defptr}{$dest}{type}); } - Log GetLogLevel($hash->{NAME}, 5), "Using dest $dest, destType $destType"; + Log3 $hash, 5, "Using dest $dest, destType $destType"; if($setting eq "associate") { return ($hash->{IODev}{Send})->($hash->{IODev},"AddLinkPartner",$hash->{addr},sprintf("%s%02x", $dest, $destType)); } else { @@ -493,7 +493,7 @@ MAX_Set($@) $temperature = MAX_ParseTemperature($temperature); #replace "on" and "off" by their values $newWeekprofilePart .= sprintf("%04x", (int($temperature*2) << 9) | int(($hour * 60 + $min)/5)); } - Log GetLogLevel($hash->{NAME}, 5), "New Temperature part for $day: $newWeekprofilePart"; + Log3 $hash, 5, "New Temperature part for $day: $newWeekprofilePart"; #Each day has 2 bytes * 13 controlpoints = 26 bytes = 52 hex characters #we don't have to update the rest, because the active part is terminated by the time 0:00 @@ -507,7 +507,7 @@ MAX_Set($@) callbackParam => "$day,1,".substr($newWeekprofilePart,2*2*7,2*2*6)) if(@controlpoints > 2*7); } - Log GetLogLevel($hash->{NAME}, 5), "New weekProfile: " . MAX_ReadingsVal($hash, ".weekProfile"); + Log3 $hash, 5, "New weekProfile: " . MAX_ReadingsVal($hash, ".weekProfile"); }else{ my $templist = join(",",map { MAX_SerializeTemperature($_/2) } (9..61)); @@ -595,7 +595,7 @@ MAX_Parse($$) #if we just snooped a message directed at a different device (by CUL_MAX). return () if($MAX ne "MAX"); - Log 5, "MAX_Parse $msg"; + Log3 $hash, 5, "MAX_Parse $msg"; #Find the device with the given addr my $shash = $modules{MAX}{defptr}{$addr}; @@ -609,7 +609,7 @@ MAX_Parse($$) if($devicetype) { return "UNDEFINED MAX_$addr MAX $devicetype $addr"; } else { - Log 2, "Got message for undefined device $addr, and failed to guess type from msg '$msgtype' - ignoring"; + Log3 $hash, 2, "Got message for undefined device $addr, and failed to guess type from msg '$msgtype' - ignoring"; return $hash->{NAME}; } } @@ -623,11 +623,11 @@ MAX_Parse($$) readingsBeginUpdate($shash); if($msgtype eq "define"){ my $devicetype = $args[0]; - Log 1, "Device changed type from $shash->{type} to $devicetype" if($shash->{type} ne $devicetype); + Log3 $hash, 1, "Device changed type from $shash->{type} to $devicetype" if($shash->{type} ne $devicetype); $shash->{type} = $devicetype; if(@args > 1){ my $serial = $args[1]; - Log 1, "Device changed serial from $shash->{serial} to $serial" if($shash->{serial} and ($shash->{serial} ne $serial)); + Log3 $hash, 1, "Device changed serial from $shash->{serial} to $serial" if($shash->{serial} and ($shash->{serial} ne $serial)); $shash->{serial} = $serial; } readingsBulkUpdate($shash, "groupid", $args[2]); @@ -650,7 +650,7 @@ MAX_Parse($$) $untilStr = "" if($mode != 2); $desiredTemperature = ($desiredTemperature&0x7F)/2.0; #convert to degree celcius - Log GetLogLevel($shash->{NAME}, 5), "battery $batterylow, rferror $rferror, panel $panel, langateway $langateway, dstsetting $dstsetting, mode $mode, valveposition $valveposition %, desiredTemperature $desiredTemperature, until $untilStr, curTemp $measuredTemperature"; + Log3 $hash, 5, "battery $batterylow, rferror $rferror, panel $panel, langateway $langateway, dstsetting $dstsetting, mode $mode, valveposition $valveposition %, desiredTemperature $desiredTemperature, until $untilStr, curTemp $measuredTemperature"; #Very seldomly, the HeatingThermostat sends us temperatures like 0.2 or 0.3 degree Celcius - ignore them $measuredTemperature = "" if($measuredTemperature ne "" and $measuredTemperature < 1); @@ -708,22 +708,22 @@ MAX_Parse($$) } $heaterTemperature = "" if(!defined($heaterTemperature)); - Log GetLogLevel($shash->{NAME}, 5), "battery $batterylow, rferror $rferror, panel $panel, langateway $langateway, dstsetting $dstsetting, mode $mode, displayActualTemperature $displayActualTemperature, heaterTemperature $heaterTemperature, untilStr $untilStr"; + Log3 $hash, 5, "battery $batterylow, rferror $rferror, panel $panel, langateway $langateway, dstsetting $dstsetting, mode $mode, displayActualTemperature $displayActualTemperature, heaterTemperature $heaterTemperature, untilStr $untilStr"; $shash->{rferror} = $rferror; readingsBulkUpdate($shash, "mode", $ctrl_modes[$mode] ); readingsBulkUpdate($shash, "battery", $batterylow ? "low" : "ok"); readingsBulkUpdate($shash, "displayActualTemperature", ($displayActualTemperature) ? 1 : 0); } else { - Log 2, "Invalid $msgtype packet" + Log3 $hash, 2, "Invalid $msgtype packet" } my $desiredTemperature = ($desiredTemperatureRaw &0x7F)/2.0; #convert to degree celcius if(defined($temperature)) { $temperature = ((($desiredTemperatureRaw &0x80)<<1) + $temperature)/10; # auch Temperaturen über 25.5 °C werden angezeigt ! - Log GetLogLevel($shash->{NAME}, 5), "desiredTemperature $desiredTemperature, temperature $temperature"; + Log3 $hash, 5, "desiredTemperature $desiredTemperature, temperature $temperature"; readingsBulkUpdate($shash, "temperature", sprintf("%2.1f",$temperature)); } else { - Log GetLogLevel($shash->{NAME}, 5), "desiredTemperature $desiredTemperature" + Log3 $hash, 5, "desiredTemperature $desiredTemperature" } #This formatting must match with in MAX_Set:$templist @@ -735,7 +735,7 @@ MAX_Parse($$) my $unkbits = vec($bits,2,4); my $rferror = vec($bits,6,1); my $batterylow = vec($bits,7,1); - Log GetLogLevel($shash->{NAME}, 5), "ShutterContact isopen $isopen, rferror $rferror, battery $batterylow, unkbits $unkbits"; + Log3 $hash, 5, "ShutterContact isopen $isopen, rferror $rferror, battery $batterylow, unkbits $unkbits"; $shash->{rferror} = $rferror; @@ -816,7 +816,7 @@ MAX_Parse($$) if($isToMe and (unpack("C",pack("H*",$args[0])) & 0x80)) { my $device = $addr; $device = $modules{MAX}{defptr}{$device}{NAME} if(exists($modules{MAX}{defptr}{$device})); - Log 1, "Device $device answered with: Invalid command/argument"; + Log3 $hash, 1, "Device $device answered with: Invalid command/argument"; } #with unknown meaning plus the data of a State broadcast from the same device #For HeatingThermostats, it does not contain the last three "until" bytes (or measured temperature) @@ -831,7 +831,7 @@ MAX_Parse($$) } elsif($shash->{type} eq "Cube") { ; #Payload is always "00" } else { - Log 2, "MAX_Parse: Don't know how to interpret Ack payload for $shash->{type}"; + Log3 $hash, 2, "MAX_Parse: Don't know how to interpret Ack payload for $shash->{type}"; } } elsif(grep /^$msgtype$/, ("SetTemperature")) { # SetTemperature is send by WallThermostat e.g. when pressing the boost button my $bits = unpack("C",pack("H*",$args[0])); @@ -840,9 +840,9 @@ MAX_Parse($$) readingsBulkUpdate($shash, "mode", $ctrl_modes[$mode] ); #This formatting must match with in MAX_Set:$templist readingsBulkUpdate($shash, "desiredTemperature", MAX_SerializeTemperature($desiredTemperature)); - Log GetLogLevel($shash->{NAME}, 5), "SetTemperature mode $ctrl_modes[$mode], desiredTemperature $desiredTemperature"; + Log3 $hash, 5, "SetTemperature mode $ctrl_modes[$mode], desiredTemperature $desiredTemperature"; } else { - Log 1, "MAX_Parse: Unknown message $msgtype"; + Log3 $hash, 1, "MAX_Parse: Unknown message $msgtype"; } #Build state READING diff --git a/fhem/FHEM/14_CUL_MAX.pm b/fhem/FHEM/14_CUL_MAX.pm index da18c1592..29337ed3e 100644 --- a/fhem/FHEM/14_CUL_MAX.pm +++ b/fhem/FHEM/14_CUL_MAX.pm @@ -38,7 +38,7 @@ CUL_MAX_Initialize($) $hash->{SetFn} = "CUL_MAX_Set"; $hash->{AttrFn} = "CUL_MAX_Attr"; $hash->{AttrList} = "IODev do_not_notify:1,0 ignore:0,1 " . - "showtime:1,0 loglevel:0,1,2,3,4,5,6 ". + "showtime:1,0 ". $readingFnAttributes; $hash->{sendQueue} = []; @@ -52,7 +52,7 @@ CUL_MAX_SetupCUL($) my $hash = $_[0]; AssignIoPort($hash); if(!defined($hash->{IODev})) { - Log 1, "$hash->{NAME}: did not find suitable IODev (CUL etc. in rfmode MAX)! You may want to execute 'attr $hash->{NAME} IODev SomeCUL'"; + Log3 $hash, 1, "$hash->{NAME}: did not find suitable IODev (CUL etc. in rfmode MAX)! You may want to execute 'attr $hash->{NAME} IODev SomeCUL'"; return 0; } @@ -80,13 +80,13 @@ CUL_MAX_Define($$) return "wrong syntax: define CUL_MAX " if(@a<3); if(exists($modules{CUL_MAX}{defptr})) { - Log 1, "There is already one CUL_MAX defined"; + 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) { - Log 1, "The adress must be 6 hexadecimal digits"; + Log3 $hash, 1, "The adress must be 6 hexadecimal digits"; return "The adress must be 6 hexadecimal digits"; } @@ -138,7 +138,7 @@ CUL_MAX_Check($@) my ($major_version,$minorversion) = ($1, $2); $version = 100*$major_version + $minorversion; if($version < 154) { - Log 2, "You are using an old version of the CUL firmware, which has known bugs with respect to MAX! support. Please update."; + Log3 $hash, 2, "You are using an old version of the CUL firmware, which has known bugs with respect to MAX! support. Please update."; } return $version; } @@ -239,18 +239,17 @@ CUL_MAX_Parse($$) my ($hash, $rmsg) = @_; if(!exists($modules{CUL_MAX}{defptr})) { - Log 2, "No CUL_MAX defined"; + Log3 $hash, 2, "No CUL_MAX defined"; return "UNDEFINED CULMAX0 CUL_MAX 123456"; } my $shash = $modules{CUL_MAX}{defptr}; - my $ll5 = GetLogLevel($shash->{NAME}, 5); return () if($rmsg !~ m/Z(..)(..)(..)(..)(......)(......)(..)(.*)/); my ($len,$msgcnt,$msgFlag,$msgTypeRaw,$src,$dst,$groupid,$payload) = ($1,$2,$3,$4,$5,$6,$7,$8); $len = hex($len); if(2*$len+3 != length($rmsg)) { #+3 = +1 for 'Z' and +2 for len field in hex - Log 1, "CUL_MAX_Parse: len mismatch"; + Log3 $hash, 1, "CUL_MAX_Parse: len mismatch"; return $shash->{NAME}; } @@ -260,12 +259,12 @@ CUL_MAX_Parse($$) $src = lc($src); $dst = lc($dst); my $msgType = exists($msgId2Cmd{$msgTypeRaw}) ? $msgId2Cmd{$msgTypeRaw} : $msgTypeRaw; - Log $ll5, "CUL_MAX_Parse: len $len, msgcnt $msgcnt, msgflag $msgFlag, msgTypeRaw $msgType, src $src, dst $dst, groupid $groupid, payload $payload"; + Log3 $hash, 5, "CUL_MAX_Parse: len $len, msgcnt $msgcnt, msgflag $msgFlag, msgTypeRaw $msgType, src $src, dst $dst, groupid $groupid, payload $payload"; my $isToMe = ($dst eq $shash->{addr}) ? 1 : 0; # $isToMe is true if that packet was directed at us #Set RSSI on MAX device if(exists($modules{MAX}{defptr}{$src}) && exists($hash->{RSSI})) { - Log 5, "CUL_MAX_Parse: rssi: $hash->{RSSI}"; + Log3 $hash, 5, "CUL_MAX_Parse: rssi: $hash->{RSSI}"; $modules{MAX}{defptr}{$src}{RSSI} = $hash->{RSSI}; } @@ -284,7 +283,7 @@ CUL_MAX_Parse($$) for my $i (0 .. $#{$shash->{sendQueue}}) { my $packet = $shash->{sendQueue}[$i]; if($packet->{src} eq $dst and $packet->{dst} eq $src and $packet->{cnt} == hex($msgcnt)) { - Log $ll5, "Got matching ack"; + Log3 $hash, 5, "Got matching ack"; my $isnak = unpack("C",pack("H*",$payload)) & 0x80; $packet->{sent} = $isnak ? 3 : 2; } @@ -297,7 +296,7 @@ CUL_MAX_Parse($$) } elsif($msgType eq "TimeInformation") { if($isToMe) { #This is a request for TimeInformation send to us - Log $ll5, "Got request for TimeInformation, sending it"; + Log3 $hash, 5, "Got request for TimeInformation, sending it"; CUL_MAX_SendTimeInformation($shash, $src); } else { my ($f1,$f2,$f3,$f4,$f5) = unpack("CCCCC",pack("H*",$payload)); @@ -312,24 +311,24 @@ CUL_MAX_Parse($$) my $unk2 = $f4 >> 6; my $unk3 = $f5 >> 6; #I guess the unk1,2,3 encode if we are in DST? - Log $ll5, "CUL_MAX_Parse: Got TimeInformation: (in GMT) year $year, mon $month, day $day, hour $hour, min $min, sec $sec, unk ($unk1, $unk2, $unk3)"; + Log3 $hash, 5, "CUL_MAX_Parse: Got TimeInformation: (in GMT) year $year, mon $month, day $day, hour $hour, min $min, sec $sec, unk ($unk1, $unk2, $unk3)"; } } elsif($msgType eq "PairPing") { my ($firmware,$type,$testresult,$serial) = unpack("CCCa*",pack("H*",$payload)); #What does testresult mean? - Log $ll5, "CUL_MAX_Parse: Got PairPing (dst $dst, pairmode $shash->{pairmode}), firmware $firmware, type $type, testresult $testresult, serial $serial"; + Log3 $hash, 5, "CUL_MAX_Parse: Got PairPing (dst $dst, pairmode $shash->{pairmode}), firmware $firmware, type $type, testresult $testresult, serial $serial"; #There are two variants of PairPing: #1. It has a destination address of "000000" and can be paired to any device. #2. It is sent after changing batteries or repressing the pair button (without factory reset) and has a destination address of the last paired device. We can answer it with PairPong and even get an Ack, but it will still not be paired to us. A factory reset (originating from the last paired device) is needed first. if(($dst ne "000000") and !$isToMe) { - Log $ll5, "Device want's to be re-paired to $dst, not to us"; + Log3 $hash,5 , "Device want's to be re-paired to $dst, not to us"; return $shash->{NAME}; } #If $isToMe is true, this device is already paired and just wants to be reacknowledged if($shash->{pairmode} || $isToMe) { - Log 3, "CUL_MAX_Parse: " . ($isToMe ? "Re-Pairing" : "Pairing") . " device $src of type $device_types{$type} with serial $serial"; + Log3 $hash, 3, "CUL_MAX_Parse: " . ($isToMe ? "Re-Pairing" : "Pairing") . " device $src of type $device_types{$type} with serial $serial"; Dispatch($shash, "MAX,$isToMe,define,$src,$device_types{$type},$serial,0", {}); #Set firmware and testresult on device @@ -356,10 +355,10 @@ CUL_MAX_Parse($$) } elsif(grep /^$msgType$/, ("ShutterContactState", "WallThermostatState", "WallThermostatControl", "ThermostatState", "PushButtonState", "SetTemperature")) { Dispatch($shash, "MAX,$isToMe,$msgType,$src,$payload", {}); } else { - Log $ll5, "Unhandled message $msgType"; + Log3 $hash,5 , "Unhandled message $msgType"; } } else { - Log 2, "CUL_MAX_Parse: Got unhandled message type $msgTypeRaw"; + Log3 $hash, 2, "CUL_MAX_Parse: Got unhandled message type $msgTypeRaw"; } return $shash->{NAME}; } @@ -392,7 +391,7 @@ CUL_MAX_Send(@) #prefix length in bytes $packet = sprintf("%02x",length($packet)/2) . $packet; - Log GetLogLevel($hash->{NAME}, 5), "CUL_MAX_Send: enqueuing $packet"; + Log3 $hash, 5, "CUL_MAX_Send: enqueuing $packet"; my $timeout = gettimeofday()+$ackTimeout; my $aref = $hash->{sendQueue}; push(@{$aref}, { "packet" => $packet, @@ -431,14 +430,14 @@ CUL_MAX_SendQueueHandler($$) my $hash = shift; my $responseToShutterContact = shift; - Log GetLogLevel($hash->{NAME}, 5), "CUL_MAX_SendQueueHandler: " . @{$hash->{sendQueue}} . " items in queue"; + Log3 $hash, 5, "CUL_MAX_SendQueueHandler: " . @{$hash->{sendQueue}} . " items in queue"; return if(!@{$hash->{sendQueue}}); #nothing to do my $timeout = gettimeofday(); #reschedule immediatly #Check if we have an IODev if(!defined($hash->{IODev})) { - Log 1, "$hash->{NAME}: did not find suitable IODev (CUL etc. in rfmode MAX), cannot send! You may want to execute 'attr $hash->{NAME} IODev SomeCUL'"; + Log3 $hash, 1, "$hash->{NAME}: did not find suitable IODev (CUL etc. in rfmode MAX), cannot send! You may want to execute 'attr $hash->{NAME} IODev SomeCUL'"; #Maybe some CUL will appear magically in some seconds #At least we cannot quit here with an non-empty queue, so we have two alternatives: #1. Delete the packet from queue and quit -> packet is lost @@ -465,7 +464,7 @@ CUL_MAX_SendQueueHandler($$) } } if($pktIdx == @{$hash->{sendQueue}} && !defined($responseToShutterContact)) { - Log 2, "There is a packet for ShutterContact $packetForShutterContactInQueue in queue. Please push the button on the respective ShutterContact so the packet can be send."; + Log3 $hash, 2, "There is a packet for ShutterContact $packetForShutterContactInQueue in queue. Please push the button on the respective ShutterContact so the packet can be send."; $timeout += 3; InternalTimer($timeout, "CUL_MAX_SendQueueHandler", $hash, 0); return undef; @@ -479,25 +478,26 @@ CUL_MAX_SendQueueHandler($$) || $modules{MAX}{defptr}{$packet->{dst}}{wakeUpUntil} < gettimeofday()))) ? 1 : 0; #Send to CUL - my ($credit10ms) = (CommandGet("","$hash->{IODev}{NAME} credit10ms") =~ /[^ ]* [^ ]* => (.*)/); + #my ($credit10ms) = (CommandGet("","$hash->{IODev}{NAME} credit10ms") =~ /[^ ]* [^ ]* => (.*)/); + my $credit10ms = 900; if($credit10ms eq "No answer") { - Log 1, "Error in CUL_MAX_SendQueueHandler: CUL $hash->{IODev}{NAME} did not answer request for current credits. Waiting 5 seconds."; + Log3 $hash, 1, "Error in CUL_MAX_SendQueueHandler: CUL $hash->{IODev}{NAME} did not answer request for current credits. Waiting 5 seconds."; $timeout += 5; } else { # We need 1000ms for preamble + len in bits (=hex len * 4) ms for payload. Divide by 10 to get credit10ms units # keep this in sync with culfw's code in clib/rf_moritz.c! my $necessaryCredit = ceil(100*$needPreamble + (length($packet->{packet})*4)/10); - Log 5, "needPreamble: $needPreamble, necessaryCredit: $necessaryCredit, credit10ms: $credit10ms"; + Log3 $hash, 5, "needPreamble: $needPreamble, necessaryCredit: $necessaryCredit, credit10ms: $credit10ms"; if( defined($credit10ms) && $credit10ms < $necessaryCredit ) { my $waitTime = $necessaryCredit-$credit10ms; #we get one credit10ms every second $timeout += $waitTime; - Log 2, "CUL_MAX_SendQueueHandler: Not enough credit! credit10ms is $credit10ms, but we need $necessaryCredit. Waiting $waitTime seconds."; + Log3 $hash, 2, "CUL_MAX_SendQueueHandler: Not enough credit! credit10ms is $credit10ms, but we need $necessaryCredit. Waiting $waitTime seconds."; } else { #Update TimeInformation payload. It should reflect the current time when sending, #not the time when it was enqueued. A low credit10ms can defer such a packet for multiple #minutes if( $msgId2Cmd{substr($packet->{packet},6,2)} eq "TimeInformation" ) { - Log GetLogLevel($hash->{NAME}, 5), "Updating TimeInformation payload"; + Log3 $hash, 5, "Updating TimeInformation payload"; substr($packet->{packet},22) = CUL_MAX_GetTimeInformationPayload(); } IOWrite($hash, "", ($needPreamble ? "Zs" : "Zf") . $packet->{packet}); @@ -515,12 +515,12 @@ CUL_MAX_SendQueueHandler($$) if( $packet->{sentTime} + $ackTimeout < gettimeofday() ) { # ackTimeout exceeded if( $packet->{retryCnt} > 0 ) { - Log GetLogLevel($hash->{NAME}, 5), "CUL_MAX_SendQueueHandler: Retry $packet->{dst} for $packet->{packet} count: $packet->{retryCnt}"; + Log3 $hash, 5, "CUL_MAX_SendQueueHandler: Retry $packet->{dst} for $packet->{packet} count: $packet->{retryCnt}"; $packet->{sent} = 0; $packet->{retryCnt}--; $timeout += 3; } else { - Log 2, "CUL_MAX_SendQueueHandler: Missing ack from $packet->{dst} for $packet->{packet}"; + Log3 $hash, 2, "CUL_MAX_SendQueueHandler: Missing ack from $packet->{dst} for $packet->{packet}"; splice @{$hash->{sendQueue}}, $pktIdx, 1; #Remove from array readingsSingleUpdate($hash, "packetsLost", ReadingsVal($hash->{NAME}, "packetsLost", 0) + 1, 1); } @@ -559,7 +559,7 @@ CUL_MAX_SendTimeInformation(@) { my ($hash,$addr,$payload) = @_; $payload = CUL_MAX_GetTimeInformationPayload() if(!defined($payload)); - Log GetLogLevel($hash->{NAME}, 5), "broadcast time to $addr"; + Log3 $hash, 5, "Broadcast time to $addr"; CUL_MAX_Send($hash, "TimeInformation", $addr, $payload, flags => "04"); } @@ -568,7 +568,7 @@ CUL_MAX_BroadcastTime(@) { my ($hash,$manual) = @_; my $payload = CUL_MAX_GetTimeInformationPayload(); - Log GetLogLevel($hash->{NAME}, 5), "CUL_MAX_BroadcastTime: payload $payload "; + Log3 $hash, 5, "CUL_MAX_BroadcastTime: payload $payload "; my $i = 1; my @used_slots = ( 0, 0, 0, 0, 0, 0 );