mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
CUL_WS upgrade
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@254 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
057a635b1c
commit
2271e88d90
@ -162,8 +162,8 @@ CUL_Set($@)
|
|||||||
my $f1 = sprintf("%02x", int($f % 65536) / 256);
|
my $f1 = sprintf("%02x", int($f % 65536) / 256);
|
||||||
my $f0 = sprintf("%02x", $f % 256);
|
my $f0 = sprintf("%02x", $f % 256);
|
||||||
$arg = sprintf("%.3f", (hex($f2)*65536+hex($f1)*256+hex($f0))/65536*26);
|
$arg = sprintf("%.3f", (hex($f2)*65536+hex($f1)*256+hex($f0))/65536*26);
|
||||||
my $msg =
|
my $msg = "Setting FREQ2..0 (0D,0E,0F) to $f2 $f1 $f0 = $arg MHz, ".
|
||||||
"Setting FREQ2..0 (0D,0E,0F) to $f2 $f1 $f0 = $arg MHz, verbose to 01";
|
"verbose to $initstr";
|
||||||
Log GetLogLevel($name,4), $msg;
|
Log GetLogLevel($name,4), $msg;
|
||||||
CUL_SimpleWrite($hash, "W0D$f2"); # Will reprogram the CC1101
|
CUL_SimpleWrite($hash, "W0D$f2"); # Will reprogram the CC1101
|
||||||
CUL_SimpleWrite($hash, "W0E$f1");
|
CUL_SimpleWrite($hash, "W0E$f1");
|
||||||
@ -191,7 +191,7 @@ CUL_Set($@)
|
|||||||
}
|
}
|
||||||
GOTBW:
|
GOTBW:
|
||||||
$ob = sprintf("%02x", $ob+$bits);
|
$ob = sprintf("%02x", $ob+$bits);
|
||||||
my $msg = "Setting MDMCFG4 (10) to $ob = $bw KHz, verbose to 01";
|
my $msg = "Setting MDMCFG4 (10) to $ob = $bw KHz, verbose to $initstr";
|
||||||
|
|
||||||
Log GetLogLevel($name,4), $msg;
|
Log GetLogLevel($name,4), $msg;
|
||||||
CUL_SimpleWrite($hash, "W10$ob");
|
CUL_SimpleWrite($hash, "W10$ob");
|
||||||
@ -494,6 +494,14 @@ CUL_Read($)
|
|||||||
($dmsg,$culdata) = split("\n", $culdata);
|
($dmsg,$culdata) = split("\n", $culdata);
|
||||||
$dmsg =~ s/\r//;
|
$dmsg =~ s/\r//;
|
||||||
|
|
||||||
|
# Debug message, X05
|
||||||
|
if($dmsg =~ m/^p /) {
|
||||||
|
foreach my $m (split("p ", $dmsg)) {
|
||||||
|
Log GetLogLevel($name,4), "CUL: p $m";
|
||||||
|
}
|
||||||
|
goto NEXTMSG;
|
||||||
|
}
|
||||||
|
|
||||||
###############
|
###############
|
||||||
# check for duplicate msg from different CUL's
|
# check for duplicate msg from different CUL's
|
||||||
my $now = gettimeofday();
|
my $now = gettimeofday();
|
||||||
@ -556,13 +564,9 @@ CUL_Read($)
|
|||||||
for(my $i = 0; $i < 14; $i+=2) { # Swap nibbles.
|
for(my $i = 0; $i < 14; $i+=2) { # Swap nibbles.
|
||||||
$dmsg .= $a[$i+2] . $a[$i+1];
|
$dmsg .= $a[$i+2] . $a[$i+1];
|
||||||
}
|
}
|
||||||
|
|
||||||
} elsif($len==9 || $len==13) { # CUL_WS / Native
|
|
||||||
;
|
|
||||||
} else {
|
|
||||||
Log GetLogLevel($name,4), "CUL: unknown message $dmsg";
|
|
||||||
goto NEXTMSG;
|
|
||||||
}
|
}
|
||||||
|
# Other K... Messages ar sent to CUL_WS
|
||||||
|
|
||||||
} elsif($fn eq "E") { # CUL_EM / Native
|
} elsif($fn eq "E") { # CUL_EM / Native
|
||||||
;
|
;
|
||||||
} else {
|
} else {
|
||||||
|
@ -6,6 +6,14 @@ use warnings;
|
|||||||
|
|
||||||
my %defptr;
|
my %defptr;
|
||||||
|
|
||||||
|
# Supports following devices:
|
||||||
|
# KS300TH (this is redirected to the more sophisticated 14_KS300 by 00_CUL)
|
||||||
|
# S300TH
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
sub
|
sub
|
||||||
CUL_WS_Initialize($)
|
CUL_WS_Initialize($)
|
||||||
@ -15,13 +23,14 @@ CUL_WS_Initialize($)
|
|||||||
# Message is like
|
# Message is like
|
||||||
# K41350270
|
# K41350270
|
||||||
|
|
||||||
$hash->{Match} = "^K(........|............)\$";
|
$hash->{Match} = "^K.....\$";
|
||||||
$hash->{DefFn} = "CUL_WS_Define";
|
$hash->{DefFn} = "CUL_WS_Define";
|
||||||
$hash->{UndefFn} = "CUL_WS_Undef";
|
$hash->{UndefFn} = "CUL_WS_Undef";
|
||||||
$hash->{ParseFn} = "CUL_WS_Parse";
|
$hash->{ParseFn} = "CUL_WS_Parse";
|
||||||
$hash->{AttrList} = "do_not_notify:0,1 showtime:0,1 model:S300TH loglevel";
|
$hash->{AttrList} = "do_not_notify:0,1 showtime:0,1 model:S300TH loglevel";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
sub
|
sub
|
||||||
CUL_WS_Define($$)
|
CUL_WS_Define($$)
|
||||||
@ -29,8 +38,8 @@ CUL_WS_Define($$)
|
|||||||
my ($hash, $def) = @_;
|
my ($hash, $def) = @_;
|
||||||
my @a = split("[ \t][ \t]*", $def);
|
my @a = split("[ \t][ \t]*", $def);
|
||||||
|
|
||||||
return "wrong syntax: define <name> CUL_WS <code> [corr1 [corr2]]"
|
return "wrong syntax: define <name> CUL_WS <code> [corr1...corr4]"
|
||||||
if(int(@a) < 3 || int(@a) > 5);
|
if(int(@a) < 3 || int(@a) > 6);
|
||||||
$a[2] = lc($a[2]);
|
$a[2] = lc($a[2]);
|
||||||
return "Define $a[0]: wrong CODE format: valid is 1-7"
|
return "Define $a[0]: wrong CODE format: valid is 1-7"
|
||||||
if($a[2] !~ m/^[1-7]$/);
|
if($a[2] !~ m/^[1-7]$/);
|
||||||
@ -38,6 +47,8 @@ CUL_WS_Define($$)
|
|||||||
$hash->{CODE} = $a[2];
|
$hash->{CODE} = $a[2];
|
||||||
$hash->{corr1} = ((int(@a) > 3) ? $a[3] : 0);
|
$hash->{corr1} = ((int(@a) > 3) ? $a[3] : 0);
|
||||||
$hash->{corr2} = ((int(@a) > 4) ? $a[4] : 0);
|
$hash->{corr2} = ((int(@a) > 4) ? $a[4] : 0);
|
||||||
|
$hash->{corr3} = ((int(@a) > 5) ? $a[5] : 0);
|
||||||
|
$hash->{corr4} = ((int(@a) > 6) ? $a[6] : 0);
|
||||||
$defptr{$a[2]} = $hash;
|
$defptr{$a[2]} = $hash;
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -57,51 +68,122 @@ sub
|
|||||||
CUL_WS_Parse($$)
|
CUL_WS_Parse($$)
|
||||||
{
|
{
|
||||||
my ($hash,$msg) = @_;
|
my ($hash,$msg) = @_;
|
||||||
my %tlist = ("2"=>"rain","3"=>"wind","4"=>"temp/hum/press","5"=>"brightness");
|
my %tlist = ("2"=>"rain",
|
||||||
|
"3"=>"wind",
|
||||||
|
"4"=>"temp/hum/press",
|
||||||
|
"5"=>"brightness");
|
||||||
|
|
||||||
# 0123456789012
|
|
||||||
# K41505268 -> Code (4+1) 5, T: 25.0 H: 68.5
|
|
||||||
# K............
|
|
||||||
|
|
||||||
my @a = split("", $msg);
|
my @a = split("", $msg);
|
||||||
|
|
||||||
|
if(@a == 5) { # 433MHz / reverse the bits
|
||||||
|
my (@b, $ob);
|
||||||
|
for(my $i = 0; $i<@a; $i++) {
|
||||||
|
my $r = hex($a[$i]);
|
||||||
|
$r = ((($r & 0x3)<<2) | (($r & 0xc)>>2));
|
||||||
|
$r = ((($r & 0x5)<<1) | (($r & 0xa)>>1));
|
||||||
|
|
||||||
|
if($i&1) {
|
||||||
|
push(@b, sprintf("%X%X", $r, $ob));
|
||||||
|
} elsif($i == (@a-1)) {
|
||||||
|
push(@b, sprintf("%X", $r));
|
||||||
|
} else {
|
||||||
|
$ob = $r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@a = @b;
|
||||||
|
}
|
||||||
|
|
||||||
my $firstbyte = hex($a[1]);
|
my $firstbyte = hex($a[1]);
|
||||||
my $cde = ($firstbyte&7) + 1;
|
my $cde = ($firstbyte&7) + 1;
|
||||||
|
|
||||||
my $type = "Temp/Hum";
|
my $type = $tlist{$a[2]} ? $tlist{$a[2]} : "unknown";
|
||||||
if(@a == 13) {
|
|
||||||
$type = $tlist{$a[2]} ? $tlist{$a[2]} : "unknown";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$defptr{$cde}) {
|
if(!$defptr{$cde}) {
|
||||||
Log 1, "CUL_WS UNDEFINED $type sensor detected, code $cde";
|
Log 1, "CUL_WS UNDEFINED $type sensor detected, code $cde";
|
||||||
return "UNDEFINED CUL_WS: $cde";
|
return "UNDEFINED CUL_WS: $cde";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(@a == 9) {
|
$hash = $defptr{$cde};
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
$hash = $defptr{$cde};
|
my $val = "";
|
||||||
my $name = $hash->{NAME};
|
|
||||||
|
if(@a == 5) { # 433MHz RainSensor
|
||||||
|
|
||||||
|
my $c = $hash->{corr1} ? $hash->{corr1} : 1;
|
||||||
|
$val = "R: " . (hex($a[5].$a[2].$a[3]) * $c);
|
||||||
|
|
||||||
|
} elsif(@a == 9) { # S300TH
|
||||||
|
|
||||||
my $sgn = ($firstbyte&8) ? -1 : 1;
|
my $sgn = ($firstbyte&8) ? -1 : 1;
|
||||||
my $tmp = $sgn * ($a[6].$a[3].".".$a[4]) + $hash->{corr1};
|
my $tmp = $sgn * ($a[6].$a[3].".".$a[4]) + $hash->{corr1};
|
||||||
my $hum = ($a[7].$a[8].".".$a[5]) + $hash->{corr2};
|
my $hum = ($a[7].$a[8].".".$a[5]) + $hash->{corr2};
|
||||||
my $val = "T: $tmp H: $hum";
|
$val = "T: $tmp H: $hum";
|
||||||
|
|
||||||
Log GetLogLevel($name,4), "CUL_WS $name: $val";
|
} elsif(@a == 13) { # WS7000 sensors
|
||||||
|
|
||||||
$hash->{STATE} = $val; # List overview
|
|
||||||
$hash->{READINGS}{state}{TIME} = TimeNow(); # For list
|
|
||||||
$hash->{READINGS}{state}{VAL} = $val;
|
|
||||||
|
|
||||||
$hash->{CHANGED}[0] = $val; # For notify
|
if($type eq "brightness") {
|
||||||
|
|
||||||
return $name;
|
# TODO
|
||||||
|
my $br = hex($a[3].$a[4].$a[5].$a[6]) + $hash->{corr1};
|
||||||
|
$val = "B: $br";
|
||||||
|
|
||||||
|
} elsif($type eq "temp/hum/press") {
|
||||||
|
|
||||||
|
my $sgn = ($firstbyte&8) ? -1 : 1;
|
||||||
|
my $tmp = $sgn * ($a[6].$a[3].".".$a[4]) + $hash->{corr1};
|
||||||
|
my $hum = ($a[7].$a[8].".".$a[5]) + $hash->{corr2};
|
||||||
|
my $prs = ($a[9].$a[10].".".$a[11]) + $hash->{corr3};
|
||||||
|
$val = "T: $tmp H: $hum P: $prs";
|
||||||
|
|
||||||
|
} elsif($type eq "wind") {
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
my $wnd = hex($a[3].$a[4].$a[5].$a[6]) + $hash->{corr1};
|
||||||
|
$val = "W: $wnd";
|
||||||
|
|
||||||
|
} elsif($type eq "rain") {
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
my $c = $hash->{corr1} ? $hash->{corr1} : 1;
|
||||||
|
my $rain = hex($a[3].$a[4].$a[5].$a[6]) * $c;
|
||||||
|
$val = "R: $rain";
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Log 1, "CUL_WS UNKNOWN sensor detected, $msg";
|
||||||
|
return "UNKNOWN CUL_WS: $cde";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} elsif(@a == 15) { # KS300/2
|
||||||
|
|
||||||
|
my $c = $hash->{corr4} ? $hash->{corr4} : 255;
|
||||||
|
my $rain = sprintf("%0.1f", hex("$a[14]$a[11]$a[12]") * $c / 1000);
|
||||||
|
my $wnd = sprintf("%0.1f", "$a[9]$a[10].$a[7]" + $hash->{corr3});
|
||||||
|
my $hum = sprintf( "%02d", "$a[8]$a[5]" + $hash->{corr2});
|
||||||
|
my $tmp = sprintf("%0.1f", ("$a[6]$a[3].$a[4]"+$hash->{corr1}) *
|
||||||
|
(($a[3] & 8) ? -1 : 1));
|
||||||
|
my $ir = ((hex($a[1]) & 0x2)) ? "yes" : "no";
|
||||||
|
|
||||||
|
$val = "T: $tmp H: $hum W: $wnd R: $rain IR: $ir";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
Log 1, "CUL_WS UNKNOWN sensor detected, $msg";
|
||||||
|
return "UNKNOWN CUL_WS: $cde";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
Log GetLogLevel($name,4), "CUL_WS $name: $val";
|
||||||
|
|
||||||
|
$hash->{STATE} = $val; # List overview
|
||||||
|
$hash->{READINGS}{state}{TIME} = TimeNow(); # For list
|
||||||
|
$hash->{READINGS}{state}{VAL} = $val;
|
||||||
|
$hash->{CHANGED}[0] = $val; # For notify
|
||||||
|
|
||||||
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user