2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 00:36:25 +00:00

- feature: Module 09_BS.pm for brightness sensor added (Boris 2009-09-20)

git-svn-id: https://svn.fhem.de/fhem/trunk@439 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
borisneubert 2009-09-20 17:08:33 +00:00
parent c889ef8163
commit b6753d7a09
5 changed files with 157 additions and 9 deletions

View File

@ -530,3 +530,4 @@
- feature: Pachube module from Axel
- feature: dumpdef module from Axel in contrib
- feature: javascripting support in FHEMWEB (Klaus/Axel)
- feature: Module 09_BS.pm for brightness sensor added (Boris 2009-09-20)

View File

@ -57,13 +57,14 @@ FHZ_Initialize($)
# Provider
$hash->{ReadFn} = "FHZ_Read";
$hash->{WriteFn} = "FHZ_Write";
$hash->{Clients} = ":FHZ:FS20:FHT:HMS:KS300:USF1000:";
$hash->{Clients} = ":FHZ:FS20:FHT:HMS:KS300:USF1000:BS:";
my %mc = (
"1:USF1000" => "^810c04..0101a001a5ceaa00....",
"2:FS20" => "^81..(04|0c)..0101a001",
"3:FHT" => "^81..(04|09|0d)..(0909a001|83098301|c409c401)..",
"4:HMS" => "^810e04....(1|5|9).a001",
"5:KS300" => "^810d04..4027a001",
"1:USF1000" => "^81..(04|0c)..0101a001a5ceaa00....",
"2:BS" => "^81..(04|0c)..0101a001a5cf......",
"3:FS20" => "^81..(04|0c)..0101a001",
"4:FHT" => "^81..(04|09|0d)..(0909a001|83098301|c409c401)..",
"5:HMS" => "^810e04....(1|5|9).a001",
"6:KS300" => "^810d04..4027a001",
);
$hash->{MatchList} = \%mc;
$hash->{ReadyFn} = "FHZ_Ready";
@ -466,7 +467,7 @@ FHZ_ReadAnswer($$$)
}
Log 5, "FHZ/RAW: " . unpack('H*',$buf);
Log 4, "FHZ/RAW: " . unpack('H*',$buf);
$mfhzdata .= $buf;
next if(length($mfhzdata) < 2);
@ -644,7 +645,7 @@ FHZ_Read($)
my $fhzdata = $hash->{PARTIAL};
Log 5, "FHZ/RAW: " . unpack('H*',$buf) .
Log 4, "FHZ/RAW: " . unpack('H*',$buf) .
" (Unparsed: " . unpack('H*', $fhzdata) . ")";
$fhzdata .= $buf;

121
fhem/FHEM/09_BS.pm Normal file
View File

@ -0,0 +1,121 @@
#
#
# 09_BS.pm
# written by Dr. Boris Neubert 2009-06-20
# e-mail: omega at online dot de
#
##############################################
package main;
use strict;
use warnings;
my $PI= 3.141592653589793238;
my %defptr;
#############################
sub
BS_Initialize($)
{
my ($hash) = @_;
$hash->{Match} = "^81..(04|0c)..0101a001a5cf......";
$hash->{DefFn} = "BS_Define";
$hash->{UndefFn} = "BS_Undef";
$hash->{ParseFn} = "BS_Parse";
$hash->{AttrList} = "IODev do_not_notify:1,0 showtime:0,1 dummy:1,0 model:BSs loglevel:0,1,2,3,4,5,6";
}
#############################
sub
BS_Define($$)
{
my ($hash, $def) = @_;
my @a = split("[ \t][ \t]*", $def);
my $u= "wrong syntax: define <name> BS <sensor> [factor]";
return $u if((int(@a)< 3) || (int(@a)>4));
my $name = $a[0];
my $sensor = $a[2];
if($sensor !~ /[1..9]/) {
return "erroneous sensor specification $sensor, use one of 1..9";
}
$sensor= "0$sensor";
my $factor = 1.0;
$factor= $a[3] if(int(@a)==4);
$hash->{SENSOR}= "$sensor";
$hash->{FACTOR}= $factor;
my $dev= "a5cf $sensor";
$hash->{DEF}= $dev;
$defptr{$dev} = $hash;
AssignIoPort($hash);
}
#############################
sub
BS_Undef($$)
{
my ($hash, $name) = @_;
delete($defptr{$hash->{DEF}});
return undef;
}
#############################
sub
BS_Parse($$)
{
my ($hash, $msg) = @_; # hash points to the FHZ, not to the BS
# Msg format:
# 01 23 45 67 8901 2345 6789 01 23 45 67
# 81 0c 04 .. 0101 a001 a5cf xx 00 zz zz
my $sensor= substr($msg, 20, 2);
my $dev= "a5cf $sensor";
my $def= $defptr{$dev};
if(!defined($def)) {
Log 3, sprintf("BS Unknown device %s, please define it", $sensor);
return "UNDEFINED BS";
}
my $name= $def->{NAME};
return "" if($def->{IODev} && $def->{IODev}{NAME} ne $hash->{NAME});
my $t= TimeNow();
my $flags= hex(substr($msg, 24, 1)) & 0xdc;
my $value= hex(substr($msg, 25, 3)) & 0x3ff;
my $factor= $def->{FACTOR};
my $brightness= $value/10.24*$factor;
my $state= sprintf("brightness: %.2f flags: %d", $brightness, $flags);
$def->{CHANGED}[0] = $state;
$def->{STATE} = $state;
$def->{READINGS}{state}{TIME} = $t;
$def->{READINGS}{state}{VAL} = $state;
Log GetLogLevel($name, 4), "BS $name: $state";
$def->{READINGS}{brightness}{TIME} = $t;
$def->{READINGS}{brightness}{VAL} = $brightness;
$def->{READINGS}{flags}{TIME} = $t;
$def->{READINGS}{flags}{VAL} = $flags;
return $name;
}
#############################
1;

View File

@ -423,3 +423,6 @@
- Sat Sep 12 2009 (Boris)
- 00_CM11.pm: feature: get time, fwrev, set reopen for CM11 (Boris 2009-09-12)
- Sun Sep 20 2009 (Boris)
- Module 09_BS.pm for brightness sensor added (Boris 2009-09-20)

22
fhem/docs/BS.txt Normal file
View File

@ -0,0 +1,22 @@
2009-09-12bn
This document describes the protocol for the brightness sensor BS.
Datagram is of FS20 sensor message type:
81 0c 04 ?? 01 01 a0 01 a5 cf xx 00 yy zz
81: begin of FS20/FHT communication
0c: remaining length of datagram (12 bytes)
04: type of datagram
??: checksum
01 01 a0 01: FS20 fix sequence, always 01 01 a0 01
a5 cf: FS20 housecode, always a5cf for brightness sensor BS
xx: sensor #
00: always 00
yy zz: code, see below
yy zz
76543210 76543210
| ++ ++++++++----- 10 bit resolution brightness value (0..1023)
|
+------------------- 0x20 always 1 (= value byte follows)