14_CUL_TCM97001: Add Unknown TCM device for unknown decoded packages, for future decode.

git-svn-id: https://svn.fhem.de/fhem/trunk@8328 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
dancer0705 2015-03-29 15:29:31 +00:00
parent 5e760f9e03
commit 45ceab5d88

View File

@ -1,6 +1,6 @@
############################################## ##############################################
# From dancer0705 # From dancer0705
# Receive TCM 97001 like temperature sensor # Receive TCM 97xxx, TCM 21xxxx, GT-WT-xx and Rubicson like temperature sensor
# #
# Copyright (C) 2015 Bjoern Hempel # Copyright (C) 2015 Bjoern Hempel
# #
@ -35,8 +35,9 @@ use constant { TRUE => 1, FALSE => 0 };
my %models = ( my %models = (
"TCM97..." => 'TCM97...', "TCM97..." => 'TCM97...',
"TCM21...." => 'TCM21....', "TCM21...." => 'TCM21....',
"GT-WT-.." => 'GT-WT-..', "Prologue" => 'Prologue',
"Rubicson" => 'Rubicson', "Rubicson" => 'Rubicson',
"Unknown" => 'Unknown',
); );
sub sub
@ -122,18 +123,25 @@ CUL_TCM97001_Parse($$)
my $def = $modules{CUL_TCM97001}{defptr}{$id3}; my $def = $modules{CUL_TCM97001}{defptr}{$id3};
my $def2 = $modules{CUL_TCM97001}{defptr}{$id4}; my $def2 = $modules{CUL_TCM97001}{defptr}{$id4};
my $defUnknown = $modules{CUL_TCM97001}{defptr}{"Unknown"};
my $now = time(); my $now = time();
my $name = "UNKNOWN"; my $name = "Unknown";
if($def) { if($def) {
$name = $def->{NAME}; $name = $def->{NAME};
} elsif($def2) { } elsif($def2) {
$name = $def2->{NAME}; $name = $def2->{NAME};
} elsif($defUnknown) {
$name = $defUnknown->{NAME};
} }
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); Log3 $name, 4, "CUL_TCM97001 $name $id3 or $id4 ($msg) length:" . length($msg) . " RSSI: $rssi";
my ($msgtype, $msgtypeH, $val, $valH); my ($msgtype, $msgtypeH, $val, $valH);
@ -143,7 +151,7 @@ CUL_TCM97001_Parse($$)
my $mode=undef; my $mode=undef;
my $hashumidity = FALSE; my $hashumidity = FALSE;
my $hasbatcheck = FALSE; my $hasbatcheck = FALSE;
my $model="UNKNOWN"; my $model="Unknown";
if (length($msg) == 8) { if (length($msg) == 8) {
# Only tmp TCM device # Only tmp TCM device
@ -290,9 +298,9 @@ CUL_TCM97001_Parse($$)
$model="TCM21...."; $model="TCM21....";
} else { } else {
Log3 $name, 4, "CUL_TCM97001: CRC for TCM21.... Failed, checking other protocolls"; Log3 $name, 4, "CUL_TCM97001: CRC for TCM21.... Failed, checking other protocolls";
# Check for GT-WT-01 # Check for Prologue
if (hex($a[0]) == 0x9) { if (hex($a[0]) == 0x9) {
$model="GT-WT-.."; $model="Prologue";
# Protocol prologue start everytime with 1001 # Protocol prologue start everytime with 1001
# e.g. 91080F614C 1001 0001 0000 1000 0000 1111 0110 0001 0100 1100 # e.g. 91080F614C 1001 0001 0000 1000 0000 1111 0110 0001 0100 1100
# A B C D E F G H I # A B C D E F G H I
@ -379,7 +387,7 @@ CUL_TCM97001_Parse($$)
if ($packageOK == TRUE) { if ($packageOK == TRUE) {
if(!$def && !$def2) { if(!$def && !$def2) {
if ($model eq "GT-WT-..") { if ($model eq "Prologue") {
Log3 $name, 2, "CUL_TCM97001 Unknown device $id4, please define it"; Log3 $name, 2, "CUL_TCM97001 Unknown device $id4, please define it";
return "UNDEFINED CUL_TCM97001_$id4 CUL_TCM97001 $id4" if(!$def2); return "UNDEFINED CUL_TCM97001_$id4 CUL_TCM97001 $id4" if(!$def2);
} else { } else {
@ -387,7 +395,7 @@ CUL_TCM97001_Parse($$)
return "UNDEFINED CUL_TCM97001_$id3 CUL_TCM97001 $id3" if(!$def); return "UNDEFINED CUL_TCM97001_$id3 CUL_TCM97001 $id3" if(!$def);
} }
} }
if ($model eq "GT-WT-..") { if ($model eq "Prologue") {
$def = $def2; $def = $def2;
} }
readingsBeginUpdate($def); readingsBeginUpdate($def);
@ -395,7 +403,7 @@ CUL_TCM97001_Parse($$)
$attr{$name}{model} = $model; $attr{$name}{model} = $model;
if ($hasbatcheck) { if ($hasbatcheck) {
if ($batbit) { if ($batbit) {
readingsBulkUpdate($def, "battery", "Low"); readingsBulkUpdate($def, "battery", "low");
} else { } else {
readingsBulkUpdate($def, "battery", "ok"); readingsBulkUpdate($def, "battery", "ok");
} }
@ -405,9 +413,40 @@ CUL_TCM97001_Parse($$)
readingsBulkUpdate($def, $msgtypeH, $valH); readingsBulkUpdate($def, $msgtypeH, $valH);
} }
readingsEndUpdate($def, 1); readingsEndUpdate($def, 1);
return $name; if(defined($rssi)) {
$def->{RSSI} = $rssi;
#$addvals{RSSI} = $rssi;
} }
Log3 $name, 4, "CUL_TCM97001 Device not interpreted yet name $name msg $msg"; return $name;
} else {
Log3 $name, 4, "CUL_TCM97001 Device not interplmeted yet name $name msg $msg";
if (!$defUnknown) {
Log3 $name, 2, "CUL_TCM97001 Unknown device $name, please define it";
return "UNDEFINED CUL_TCM97001_$name CUL_TCM97001 $name" if(!$defUnknown);
}
$state="Code: $msg";
if ($defUnknown) {
$defUnknown->{lastT} = $now;
};
my $defSvg = $defs{"SVG_CUL_TCM97001_Unknown"};
if ($defSvg) {
CommandDelete(undef, $defSvg->{NAME});
}
$attr{$name}{model} = $model;
readingsBeginUpdate($defUnknown);
readingsBulkUpdate($defUnknown, "state", $state);
readingsEndUpdate($defUnknown, 1);
if(defined($rssi)) {
$defUnknown->{RSSI} = $rssi;
}
return $name;
}
return undef; return undef;