2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-13 17:26:34 +00:00

CUL/HMS changes

git-svn-id: https://svn.fhem.de/fhem/trunk@411 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2009-07-11 08:41:23 +00:00
parent bb106c95a5
commit 0037191961
3 changed files with 64 additions and 65 deletions

View File

@ -514,3 +514,4 @@
- =DATE= (4.7)
- bugfix: Reattached corrupted CUL device caused uninitialized message
- bugfix: CUL/HMS changes, HMS cleanup

View File

@ -167,10 +167,17 @@ sub
CUL_Shutdown($)
{
my ($hash) = @_;
CUL_SimpleWrite($hash, "X00") if($hash->{VERSION} !~ m/CUR/);
CUL_SimpleWrite($hash, "X00") if(!CUL_isCUR($hash));
return undef;
}
sub
CUL_isCUR($)
{
my ($hash) = @_;
return ($hash->{VERSION} && $hash->{VERSION} =~ m/CUR/);
}
#####################################
sub
@ -258,8 +265,7 @@ GOTBW:
} elsif($type eq "file") {
return "Only supported for CUR devices (see VERSION)"
if($hash->{VERSION} !~ m/CUR/);
return "Only supported for CUR devices (see VERSION)" if(!CUL_isCUR($hash));
return "$name: Need 2 further arguments: source destination"
if(@a != 2);
@ -294,8 +300,7 @@ WRITEEND:
} elsif($type eq "time") {
return "Only supported for CUR devices (see VERSION)"
if($hash->{VERSION} !~ m/CUR/);
return "Only supported for CUR devices (see VERSION)" if(!CUL_isCUR($hash));
my @a = localtime;
my $msg = sprintf("c%02d%02d%02d", $a[2],$a[1],$a[0]);
CUL_SimpleWrite($hash, $msg);
@ -347,8 +352,7 @@ CUL_Get($@)
} elsif($a[1] eq "file") {
return "Only supported for CUR devices (see VERSION)"
if($hash->{VERSION} !~ m/CUR/);
return "Only supported for CUR devices (see VERSION)" if(!CUL_isCUR($hash));
CUL_Clear($hash);
CUL_SimpleWrite($hash, "X00");
@ -749,8 +753,14 @@ CUL_Read($)
} elsif($fn eq "H" && $len >= 13) { # Reformat for 12_HMS.pm
$dmsg = sprintf("81%02x04xxxx5%sa001%s0000%s",
$len/2+8, substr($dmsg,6,1), substr($dmsg,1,4), substr($dmsg,5));
my $type = hex(substr($dmsg,6,1));
my $prf = $type > 1 ? "02" : "05";
my $bat = $type > 1 ? hex(substr($dmsg,5,1))+1 : 1;
$dmsg = sprintf("81%02x04xx%s%x%xa001%s0000%s",
$len/2+8, # Packet-Length
$prf, $bat, $type,
substr($dmsg,1,4), # House-Code
substr($dmsg,5)); # Values
$dmsg = lc($dmsg);
} elsif($fn eq "K" && $len >= 5) {

View File

@ -108,108 +108,98 @@ HMS_Parse($$)
my $def = $defptr{$dev};
return "" if($def->{IODev} && $def->{IODev}{NAME} ne $hash->{NAME});
my (@v, @txt, @sfx);
my (@v, @txt);
# Used for HMS100TF & HMS100T
my $batstr1 = "ok";
my $status1 = hex(substr($val, 0, 1));
$batstr1 = "empty" if( $status1 & 2 );
$batstr1 = "replaced" if( $status1 & 4 );
# Used for the other devices
my $batstr2 = "ok";
my $status = hex(substr($val, 1, 1));
my $status2 = hex(substr($msg, 10, 1));
$batstr2 = "empty" if( $status2 & 4 );
$batstr2 = "replaced" if( $status2 & 8 );
if($type eq "HMS100TF") {
@txt = ( "temperature", "humidity", "battery");
@sfx = ( "(Celsius)", "(%)", "");
# Codierung <s1><s0><t1><t0><f0><t2><f2><f1>
my $status = hex(substr($val, 0, 1));
$v[0] = int(substr($val, 5, 1) . substr($val, 2, 2))/10;
$v[0] = -$v[0] if($status1 & 8);
$v[1] = int(substr($val, 6, 2) . substr($val, 4, 1))/10;
$v[2] = "ok";
if ( $status & 2 ) { $v[2] = "empty"; }
if ( $status & 4 ) { $v[2] = "replaced"; }
if ( $status & 8 ) { $v[0] = -$v[0]; }
$v[2] = $batstr1;
$val = "T: $v[0] H: $v[1] Bat: $v[2]";
$v[0] = "$v[0] (Celsius)";
$v[1] = "$v[1] (%)";
} elsif ($type eq "HMS100T") {
@txt = ( "temperature", "battery");
@sfx = ( "(Celsius)", "");
my $status = hex(substr($val, 0, 1));
$v[0] = int(substr($val, 5, 1) . substr($val, 2, 2))/10;
$v[1] = "ok";
if ( $status & 2 ) { $v[1] = "empty"; }
if ( $status & 4 ) { $v[1] = "replaced"; }
if ( $status & 8 ) { $v[0] = -$v[0]; }
$v[0] = -$v[0] if($status1 & 8);
$v[1] = $batstr1;
$val = "T: $v[0] Bat: $v[1]";
$v[0] = "$v[0] (Celsius)";
} elsif ($type eq "HMS100WD") {
@txt = ( "water_detect", "battery");
@sfx = ( "", "");
my $status = hex(substr($val, 1, 1));
$v[0] = "off";
if ( $status & 1 ) { $v[0] = "on"; }
$v[0] = ($status ? "on" : "off");
$v[1] = $batstr2;
$val = "Water Detect: $v[0]";
$status = hex(substr($msg, 10, 1)); #Battery low condition
$v[1] = (($status & 4) ? "empty" : "ok"); # bit is set if Voltage < 2.5 V.
} elsif ($type eq "HMS100TFK") { # By Peter P.
@txt = ( "switch_detect", "battery");
@sfx = ( "", "");
my $status = hex(substr($val, 1, 1));
$v[0] = ($status ? "on" : "off");
$v[1] = $batstr2;
$val = "Switch Detect: $v[0]";
$status = hex(substr($msg, 10, 1)); #Battery low condition
$v[1] = (($status & 4) ? "empty" : "ok"); # bit is set if Voltage < 2.5 V.
} elsif($type eq "RM100-2") {
@txt = ( "smoke_detect", "battery");
@sfx = ( "", "");
$v[0] = ( hex(substr($val, 1, 1)) != "0" ) ? "on" : "off";
$v[1] = "ok";
my $status = hex(substr($msg, 10, 1));
if( $status & 4 ) { $v[1] = "empty"; }
if( $status & 8 ) { $v[1] = "replaced"; }
$v[0] = ($status ? "on" : "off");
$v[1] = $batstr2;
$val = "smoke_detect: $v[0]";
} elsif ($type eq "HMS100MG") { # By Peter Stark
@txt = ( "gas_detect", "battery");
@sfx = ( "", "");
# Battery-low condition detect is not yet properly
# implemented.
my $status = hex(substr($val, 1, 1));
$v[0] = ($status != "0") ? "on" : "off";
$v[1] = "off";
if ($status & 1) { $v[0] = "on"; }
$v[0] = ($status ? "on" : "off");
$v[1] = $batstr2; # Battery conditions not yet verified
$val = "Gas Detect: $v[0]";
} elsif ($type eq "HMS100CO") { # By PAN
@txt = ( "gas_detect", "battery");
@sfx = ( "", "");
# Battery-low condition detect is not yet properly
# implemented.
my $status = hex(substr($val, 1, 1));
$v[0] = ($status != "0") ? "on" : "off";
$v[1] = "off";
if ($status & 1) { $v[0] = "on"; }
$v[0] = ($status ? "on" : "off");
$v[1] = $batstr2; # Battery conditions not yet verified
$val = "CO Detect: $v[0]";
} elsif ($type eq "HMS100FIT") { # By PAN
@txt = ( "fi_triggered", "battery");
@sfx = ( "", "");
# Battery-low condition detect is not yet properly
# implemented.
my $status = hex(substr($val, 1, 1));
$v[0] = ($status != "0") ? "on" : "off";
$v[1] = "off";
if ($status & 1) { $v[0] = "on"; }
$v[0] = ($status ? "on" : "off");
$v[1] = $batstr2; # Battery conditions not yet verified
$val = "FI triggered: $v[0]";
} else {
@ -225,17 +215,15 @@ HMS_Parse($$)
my $max = int(@txt);
for( my $i = 0; $i < $max; $i++) {
$def->{READINGS}{$txt[$i]}{TIME} = $now;
my $v = "$v[$i] $sfx[$i]";
$def->{READINGS}{$txt[$i]}{VAL} = $v;
$def->{CHANGED}[$i] = "$txt[$i]: $v";
$def->{READINGS}{$txt[$i]}{VAL} = $v[$i];
$def->{CHANGED}[$i] = "$txt[$i]: $v[$i]";
}
$def->{READINGS}{type}{TIME} = $now;
$def->{READINGS}{type}{VAL} = $type;
$def->{STATE} = $val;
$def->{CHANGED}[$max] = $val;
$def->{CHANGED}[$max+1] = "ExactId: $odev" if($odev ne $dev);
$def->{CHANGED}[$max++] = $val;
$def->{CHANGED}[$max++] = "ExactId: $odev" if($odev ne $dev);
return $def->{NAME};
}