From f7c7c1706f4d7f696845bac07e176a1fbdf6f51e Mon Sep 17 00:00:00 2001 From: dancer0705 <> Date: Sun, 17 May 2015 11:29:35 +0000 Subject: [PATCH] 14_CUL_TCM97001: Fix some uninitialized vars, update docu git-svn-id: https://svn.fhem.de/fhem/trunk@8590 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/14_CUL_TCM97001.pm | 90 ++++++++++++++++++------------------ 2 files changed, 47 insertions(+), 44 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index f2e76e2be..7850949ab 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # 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. + - bugfix: 14_CUL_TCM97001: Fix some uninitialized vars, update docu - feature: 30_pilight_temp: attribut corrHumidity to correct humidity - feature: 76_MSGMail: Add attribute mailtype as suggested by Roger (forum #37206) diff --git a/fhem/FHEM/14_CUL_TCM97001.pm b/fhem/FHEM/14_CUL_TCM97001.pm index 17df3bc39..fdd6a0f39 100755 --- a/fhem/FHEM/14_CUL_TCM97001.pm +++ b/fhem/FHEM/14_CUL_TCM97001.pm @@ -149,7 +149,9 @@ sub checkCRC_GTWT02 { sub checkValues { my $temp = shift; my $humidy = shift; - + if (!defined($humidy)) { + $humidy = 50; + } if ($temp < 60 && $temp > -30 && $humidy > 0 && $humidy < 100) { return TRUE; @@ -185,11 +187,17 @@ CUL_TCM97001_Parse($$) my $rssi; my $l = length($msg); - $rssi = hex(substr($msg, $l-2, 2)); - $rssi = ($rssi>=128 ? (($rssi-256)/2-74) : ($rssi/2-74)); - - #Log3 $name, 4, "CUL_TCM97001 $name $id3 or $id4 ($msg) length:" . length($msg) . " RSSI: $rssi"; - Log3 $name, 4, "CUL_TCM97001 $name $id3 ($msg) length:" . length($msg) . " RSSI: $rssi"; + $rssi = substr($msg, $l-2, 2); + undef($rssi) if ($rssi eq "00"); + + if (defined($rssi)) + { + $rssi = hex($rssi); + $rssi = ($rssi>=128 ? (($rssi-256)/2-74) : ($rssi/2-74)) if defined($rssi); + Log3 $name, 4, "CUL_TCM97001 $name $id3 ($msg) length: $l RSSI: $rssi"; + } else { + Log3 $name, 4, "CUL_TCM97001 $name $id3 ($msg) length: $l"; + } my ($msgtype, $msgtypeH); @@ -253,7 +261,7 @@ CUL_TCM97001_Parse($$) if (checkValues($temp, 50)) { if(!$def) { Log3 $name, 2, "CUL_TCM97001 Unknown device $tcm97id, please define it"; - return "UNDEFINED CUL_TCM97001_$tcm97id CUL_TCM97001 $tcm97id" if(!$def); + return "UNDEFINED CUL_TCM97001_$tcm97id CUL_TCM97001 $tcm97id"; } $packageOK = TRUE; $hasbatcheck = TRUE; @@ -273,11 +281,11 @@ CUL_TCM97001_Parse($$) $temp = -$temp; } $batbit = ((hex($a[4]) & 0x8) != 0x8); - + $mode = (hex($a[4]) & 0x4) >> 2; if (checkValues($temp, 50)) { if(!$def) { Log3 $name, 2, "CUL_TCM97001 Unknown device $tcm97id, please define it"; - return "UNDEFINED CUL_TCM97001_$tcm97id CUL_TCM97001 $tcm97id" if(!$def); + return "UNDEFINED CUL_TCM97001_$tcm97id CUL_TCM97001 $tcm97id"; } $hasbatcheck = TRUE; $packageOK = TRUE; @@ -315,6 +323,7 @@ CUL_TCM97001_Parse($$) # C Bit 1 Battery # D+E+F Temp # G+H Hum + # I CRC $def = $modules{CUL_TCM97001}{defptr}{$idType1}; if($def) { $name = $def->{NAME}; @@ -331,12 +340,11 @@ CUL_TCM97001_Parse($$) #Split reversed a again my @aReverse = split("", $hexReverse); - my $CRC = (hex($aReverse[0])+hex($aReverse[1])+hex($aReverse[2])+hex($aReverse[3]) - +hex($aReverse[4])+hex($aReverse[5])+hex($aReverse[6])+hex($aReverse[7])) & 15; - if (hex($aReverse[5]) > 3) { # negative temp - $temp = ((-hex($aReverse[3]) + -hex($aReverse[4]) * 16 + -hex($aReverse[5]) * 256)+1+4096)/10; + $temp = ((hex($aReverse[3]) + hex($aReverse[4]) * 16 + hex($aReverse[5]) * 256)); + $temp = (~$temp & 0x03FF) + 1; + $temp = -$temp/10; } else { # positive temp $temp = (hex($aReverse[3]) + hex($aReverse[4]) * 16 + hex($aReverse[5]) * 256)/10; @@ -349,7 +357,7 @@ CUL_TCM97001_Parse($$) if (checkValues($temp, $humidity)) { if(!$def) { Log3 $name, 2, "CUL_TCM97001 Unknown device $idType1, please define it"; - return "UNDEFINED CUL_TCM97001_$idType1 CUL_TCM97001 $idType1" if(!$def); + return "UNDEFINED CUL_TCM97001_$idType1 CUL_TCM97001 $idType1"; } $hashumidity = TRUE; $packageOK = TRUE; @@ -387,12 +395,12 @@ CUL_TCM97001_Parse($$) if (checkValues($temp, $humidity)) { if(!$def) { - #Log3 $name, 2, "CUL_TCM97001 Unknown device $idType3, please define it"; - #return "UNDEFINED CUL_TCM97001_$idType3 CUL_TCM97001 $idType3" if(!$def); $name, 2, "CUL_TCM97001 Unknown device $idType1, please define it"; - return "UNDEFINED CUL_TCM97001_$idType1 CUL_TCM97001 $idType1" if(!$def); + return "UNDEFINED CUL_TCM97001_$idType1 CUL_TCM97001 $idType1"; + } + if ($humidity >= 20) { + $hashumidity = TRUE; } - $hashumidity = TRUE; $hasbatcheck = TRUE; $haschannel = TRUE; $packageOK = TRUE; @@ -428,7 +436,6 @@ CUL_TCM97001_Parse($$) $temp = $temp / 10; if (hex($a[7]) != 0xC && hex($a[8]) != 0xC) { - $hashumidity = TRUE; $humidity = hex($a[7].$a[8]); } @@ -438,11 +445,13 @@ CUL_TCM97001_Parse($$) if (checkValues($temp, $humidity)) { if(!$def) { Log3 $name, 2, "CUL_TCM97001 Unknown device $idType1, please define it"; - return "UNDEFINED CUL_TCM97001_$idType1 CUL_TCM97001 $idType1" if(!$def); -# Log3 $name, 2, "CUL_TCM97001 Unknown device $idType3, please define it"; -# return "UNDEFINED CUL_TCM97001_$idType3 CUL_TCM97001 $idType3" if(!$def); + return "UNDEFINED CUL_TCM97001_$idType1 CUL_TCM97001 $idType1"; } - $hashumidity = TRUE; + if (defined($humidity)) { + if ($humidity >= 20) { + $hashumidity = TRUE; + } + } $hasbatcheck = TRUE; $packageOK = TRUE; $haschannel = TRUE; @@ -592,26 +601,18 @@ CUL_TCM97001_Parse($$) my ($val, $valH, $state); $msgtype = "temperature"; $val = sprintf("%2.1f", ($temp) ); + $state="T: $val"; if ($hashumidity == TRUE) { $msgtypeH = "humidity"; $valH = $humidity; + $state="$state H: $valH"; Log3 $name, 4, "CUL_TCM97001 $msgtype $name $id3 T: $val H: $valH"; } else { Log3 $name, 4, "CUL_TCM97001 $msgtype $name $id3 T: $val"; } - #Log3 $name, 2, "xxxxxxxx $model ......... $name .......... $val .... $valH ... $def"; - my $t = ReadingsVal($name, "temperature", undef); - my $h = ReadingsVal($name, "humidity", undef); - if(defined($t) && defined($h)) { - $state="T: $t H: $h"; - } elsif(defined($t)) { - $state="T: $t"; - } elsif(defined($h)) { - $state="H: $h"; - } readingsBeginUpdate($def); - readingsBulkUpdate($def, "state", $state); + if($hastrend) { my $readTrend = ReadingsVal($name, "trend", "unknown"); @@ -630,17 +631,20 @@ CUL_TCM97001_Parse($$) } } if ($haschannel) { - my $readChannel = ReadingsVal($name, "channel", undef); - if ($readChannel ne $channel) { readingsBulkUpdate($def, "channel", $channel); } + my $readChannel = ReadingsVal($name, "channel", ""); + if (defined($readChannel) && $readChannel ne $channel) { readingsBulkUpdate($def, "channel", $channel); } } readingsBulkUpdate($def, $msgtype, $val); if ($hashumidity == TRUE) { readingsBulkUpdate($def, $msgtypeH, $valH); } + + readingsBulkUpdate($def, "state", $state); + readingsEndUpdate($def, 1); if(defined($rssi)) { $def->{RSSI} = $rssi; - } + } $attr{$name}{model} = $model; return $name; } else { @@ -648,7 +652,7 @@ CUL_TCM97001_Parse($$) if (!$defUnknown) { Log3 "Unknown", 2, "CUL_TCM97001 Unknown device Unknown, please define it"; - return "UNDEFINED CUL_TCM97001_Unknown CUL_TCM97001 Unknown" if(!$defUnknown); + return "UNDEFINED CUL_TCM97001_Unknown CUL_TCM97001 Unknown"; } $name = $defUnknown->{NAME}; Log3 $name, 4, "CUL_TCM97001 Device not implemented yet name Unknown msg $msg"; @@ -688,7 +692,7 @@ CUL_TCM97001_Parse($$)

CUL_TCM97001