From 509d8b7f7fe006625a7a0c4c5403f2ebd8bf112f Mon Sep 17 00:00:00 2001 From: eisler Date: Tue, 2 Aug 2016 11:10:12 +0000 Subject: [PATCH] 44_TEK603: added usable level in percent git-svn-id: https://svn.fhem.de/fhem/trunk@11877 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/44_TEK603.pm | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index b9625a487..994978855 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. + - feature: 44_TEK603: added usable level in percent - added: 38_netatmo: exchanged for completely new module - feature: 98_DLNARenderer: Support players which require DIDL-Lite - bugfix: 73_km200: Bugfix for double and triple downloads diff --git a/fhem/FHEM/44_TEK603.pm b/fhem/FHEM/44_TEK603.pm index 9926fd45b..35014b596 100644 --- a/fhem/FHEM/44_TEK603.pm +++ b/fhem/FHEM/44_TEK603.pm @@ -127,7 +127,7 @@ sub TEK603_undef($$) { DevIo_CloseDev($hash); $hash->{PORTSTATE} = $hash->{STATE}; - + return undef; } @@ -151,7 +151,7 @@ sub TEK603_read($) { return '' if(!defined($buf)); # convert to hex string - $hash->{buffer} = unpack ('H*', $buf); + $hash->{buffer} = unpack ('H*', $buf); my $lenght = hex(substr($hash->{buffer},4,4))*2; #my $cmd = substr($hash->{buffer},8,2); @@ -169,21 +169,25 @@ sub TEK603_read($) { return '' if($crc ne $digest); # payload - my $temp = sprintf '%.2f', ((hex(substr($payload, 0,2)) - 40 - 32) / 1.8); - my $Ullage = hex(substr($payload,2,2)) * 256 + hex(substr($payload,4,2)); - my $RemainingUsableLevel= hex(substr($payload,6,2)) * 256 + hex(substr($payload,8,2)); - my $TotalUsableCapacity = hex(substr($payload,10,2)) * 256 + hex(substr($payload,12,2)); + my $temp = sprintf '%.2f', ((hex(substr($payload, 0,2)) - 40 - 32) / 1.8); + my $Ullage = hex(substr($payload,2,2)) * 256 + hex(substr($payload,4,2)); + my $RemainingUsableLevel = hex(substr($payload,6,2)) * 256 + hex(substr($payload,8,2)); + my $TotalUsableCapacity = hex(substr($payload,10,2)) * 256 + hex(substr($payload,12,2)); return '' if($temp eq "-40.00" && $Ullage eq "0"); # TankLevel=NO_DATA + # Calculations + my $RemainingUsablePercent = round($RemainingUsableLevel / $TotalUsableCapacity * 100,01); + #Log3 $name, 5, $hash->{buffer}; - Log3 $name, 5, "Time:$time Temp:$temp Ullage:$Ullage RemainingUsableLevel:$RemainingUsableLevel TotalUsableCapacity:$TotalUsableCapacity"; + Log3 $name, 5, "Time:$time Temp:$temp Ullage:$Ullage RemainingUsableLevel:$RemainingUsableLevel RemainingUsablePercent:$RemainingUsablePercent TotalUsableCapacity:$TotalUsableCapacity"; readingsBeginUpdate($hash); readingsBulkUpdate($hash, "Time", $time); readingsBulkUpdate($hash, "Temperature", $temp); readingsBulkUpdate($hash, "Ullage", $Ullage); readingsBulkUpdate($hash, "RemainingUsableLevel", $RemainingUsableLevel); + readingsBulkUpdate($hash, "RemainingUsablePercent", $RemainingUsablePercent); readingsBulkUpdate($hash, "TotalUsableCapacity", $TotalUsableCapacity); readingsEndUpdate($hash, 1); } @@ -192,10 +196,10 @@ sub TEK603_read($) { sub TEK603_reconnect($) { my ($hash) = @_; my $name = $hash->{NAME}; - + Log3 $name, 3, "Wrong Data received. We reconnect Device"; - # Sometime the device sends a lot of waste and we must reconnect. + # Sometime the device sends a lot of waste and we must reconnect. DevIo_CloseDev($hash); $hash->{PORTSTATE} = $hash->{STATE}; @@ -212,7 +216,7 @@ sub TEK603_reconnect($) {

TEK603