Skip to content

Commit

Permalink
14_SD_WS_Maverick.pm - Plausibilitätsprüfungen ergänzt
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf9 committed Mar 6, 2018
1 parent ab76f92 commit 215ac20
Showing 1 changed file with 41 additions and 16 deletions.
57 changes: 41 additions & 16 deletions FHEM/14_SD_WS_Maverick.pm
@@ -1,5 +1,5 @@
##############################################
# $Id: 14_SD_WS_Maverick.pm 9346 2018-03-04 12:00:00Z v3.3-dev $
# $Id: 14_SD_WS_Maverick.pm 9346 2018-03-06 19:00:00Z v3.3-dev $
#
# The purpose of this module is to support Maverick sensors
# Sidey79 & Cruizer 2016
Expand Down Expand Up @@ -80,7 +80,7 @@ SD_WS_Maverick_Parse($$)
#my $blen = $hlen * 4;
#my $bitData = unpack("B$blen", pack("H$hlen", $rawData));

Log3 $name, 4, "SD_WS_Maverick_Parse $model ($msg) length: $hlen";
Log3 $name, 4, "$name SD_WS_Maverick_Parse $model ($msg) length: $hlen";

# https://hackaday.io/project/4690-reverse-engineering-the-maverick-et-732/
# https://forums.adafruit.com/viewtopic.php?f=8&t=25414&sid=e1775df908194d56692c6ad9650fdfb2&start=15#p322178
Expand Down Expand Up @@ -108,41 +108,59 @@ SD_WS_Maverick_Parse($$)
my $temp_str2 = substr($rawData,7,5);
my $unknown = substr($rawData,12);

Log3 $iohash, 4, "$model decoded protocolid: 47 sensor startup=$startup, temp1=$temp_str1, temp2=$temp_str2, unknown=$unknown";
Log3 $iohash, 4, "$name $model decoded protocolid: 47 sensor startup=$startup, temp1=$temp_str1, temp2=$temp_str2, unknown=$unknown";

# Convert
$temp_str1 =~ tr/569A/0123/;
$temp_str2 =~ tr/569A/0123/;
if ($startup ne '59' && $startup ne '6A') {
Log3 $iohash, 4, "$name $model ERROR: wrong startup=$startup (must be 59 or 6A)";
return '';
}

# Calculate temp from data
my $c;
my $temp1=-532;
my $temp1=-532;
my $temp2=-532;

if ($temp_str1 ne '55555') {
$temp_str1 =~ tr/569A/0123/;
for ( my $i = 0; $i < length($temp_str1); $i++ ) {
$c = substr( $temp_str1, $i, 1);
$temp1 += $c*4**(4-$i);
}
if ($temp1 <= 0 || $temp1 > 300) {
Log3 $iohash, 4, "$name $model ERROR: wrong temp1=$temp1";
$temp1 = "";
}
} else {
$temp1 = "";
}

my $temp2=-532;
if ($temp_str2 ne '55555') {
$temp_str2 =~ tr/569A/0123/;
for ( my $i = 0; $i < length($temp_str2); $i++ ) {
$c = substr( $temp_str2, $i, 1);
$temp2 += $c*4**(4-$i);
}
if ($temp2 <= 0 || $temp2 > 300) {
Log3 $iohash, 4, "$name $model ERROR: wrong temp2=$temp2";
$temp2 = "";
}
} else {
$temp2 = "";
}

if ($temp1 eq "" && $temp2 eq "") {
return '';
}

Log3 $iohash, 4, "$model decoded protocolid: temp1=$temp1, temp2=$temp2;";





Log3 $iohash, 4, "$name $model decoded protocolid: temp1=$temp1, temp2=$temp2;";

#print Dumper($modules{SD_WS_Maverick}{defptr});

my $def = $modules{SD_WS_Maverick}{defptr}{$iohash->{NAME} };
$def = $modules{SD_WS_Maverick}{defptr}{$model} if(!$def);

if(!$def) {
Log3 $iohash, 1, 'SD_WS_Maverick: UNDEFINED sensor ' . $model;
Log3 $iohash, 1, "$name SD_WS_Maverick: UNDEFINED sensor $model";
return "UNDEFINED $model SD_WS_Maverick $model";
}
#Log3 $iohash, 3, 'SD_WS_Maverick: ' . $def->{NAME} . ' ' . $id;
Expand All @@ -164,7 +182,14 @@ SD_WS_Maverick_Parse($$)
$hash->{lastMSG} = $rawData;
#$hash->{bitMSG} = $bitData2;

my $state = "T1: $temp1 T2: $temp2 S: $startup";
my $state = "";
if ($temp1 ne "") {
$state = "T1: $temp1 ";
}
if ($temp2 ne "") {
$state .= "T2: $temp2 ";
}
$state .= "S: $startup";

readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "state", $state);
Expand Down

0 comments on commit 215ac20

Please sign in to comment.