From aa8f1fd5d4802de8a6591f62ceb3d41bb02f6ebc Mon Sep 17 00:00:00 2001 From: eisler Date: Sat, 30 Jan 2016 10:31:14 +0000 Subject: [PATCH] 44_TEK603.pm: added crc check to fix wrong values git-svn-id: https://svn.fhem.de/fhem/trunk@10663 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/44_TEK603.pm | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index cbe2b6b0d..9c3d24a61 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: 44_TEK603: fixed wrong values. - bugfix: 49_SSCam: fixed the problem a recording may still stay active if fhem will be restarted after a recording was triggered and the recordtime wasn't be over, diff --git a/fhem/FHEM/44_TEK603.pm b/fhem/FHEM/44_TEK603.pm index b8e8fd65c..e8e5d08ef 100644 --- a/fhem/FHEM/44_TEK603.pm +++ b/fhem/FHEM/44_TEK603.pm @@ -28,6 +28,8 @@ package main; use strict; use warnings; +use Digest::CRC; # libdigest-crc-perl + sub TEK603_Initialize($); sub TEK603_define($$); sub TEK603_doInit($); @@ -159,7 +161,12 @@ sub TEK603_read($) { #my $epromEnd = hex(substr($hash->{buffer},22,4)); my $payloadlenght = $lenght - 26 - 4; my $payload = substr($hash->{buffer},26,$payloadlenght); - #my $crc = substr($hash->{buffer},26 + $payloadlenght,4); + my $crc = substr($hash->{buffer},26 + $payloadlenght,4); + + my $ctx = Digest::CRC->new(width=>16, init=>0x0, poly=>0x1021, refout=>0, xorout=>0); + $ctx->add(pack 'H*',(substr($hash->{buffer},0,26 + $payloadlenght))); + my $digest = $ctx->hexdigest; + return '' if($crc ne $digest); # payload my $temp = sprintf '%.2f', ((hex(substr($payload, 0,2)) - 40 - 32) / 1.8); @@ -170,7 +177,6 @@ sub TEK603_read($) { #Log3 $name, 5, $hash->{buffer}; Log3 $name, 5, "Time:$time Temp:$temp Ullage:$Ullage RemainingUsableLevel:$RemainingUsableLevel TotalUsableCapacity:$TotalUsableCapacity"; - readingsBeginUpdate($hash); readingsBulkUpdate($hash, "Time", $time); readingsBulkUpdate($hash, "Temperature", $temp); @@ -195,6 +201,7 @@ sub TEK603_reconnect($) { DevIo_OpenDev($hash, 0, 'TEK603_doInit'); } + 1; =pod @@ -208,6 +215,14 @@ sub TEK603_reconnect($) {
+ Prerequisites
+ The module requires the perl module Digest::CRC
+ On a debian based system the module can be installed with
+ + sudo apt-get install libdigest-crc-perl
+
+

+ Define