2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-07 19:04:20 +00:00

CUL_MAX: parse some messages (ShutterState/HeatingThermostatState)

git-svn-id: https://svn.fhem.de/fhem/trunk@2202 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
mgehre 2012-11-26 19:48:40 +00:00
parent 828242f03a
commit 18c534358c

View File

@ -16,6 +16,11 @@ CUL_MAX_Initialize($)
$hash->{Match} = "^Z"; $hash->{Match} = "^Z";
$hash->{DefFn} = "CUL_MAX_Define"; $hash->{DefFn} = "CUL_MAX_Define";
$hash->{Clients} = ":MAX:";
my %mc = (
"1:MAX" => "^MAX",
);
$hash->{MatchList} = \%mc;
$hash->{UndefFn} = "CUL_MAX_Undef"; $hash->{UndefFn} = "CUL_MAX_Undef";
$hash->{ParseFn} = "CUL_MAX_Parse"; $hash->{ParseFn} = "CUL_MAX_Parse";
$hash->{AttrList} = "IODev do_not_notify:1,0 ignore:0,1 " . $hash->{AttrList} = "IODev do_not_notify:1,0 ignore:0,1 " .
@ -29,12 +34,17 @@ CUL_MAX_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_MAX <srdAddr>" if(@a<2); return "wrong syntax: define <name> CUL_MAX <srdAddr>" if(@a<3);
$hash->{addr} = $a[1]; if(exists($modules{CUL_MAX}{defptr})) {
Log 1, "There is already on CUL_MAX defined";
return "There is already on CUL_MAX defined";
}
$modules{CUL_MAX}{defptr} = $hash;
$hash->{addr} = $a[2];
$hash->{STATE} = "Defined"; $hash->{STATE} = "Defined";
$hash->{cnt} = 0; $hash->{cnt} = 0;
Log 4, "CUL_MAX defined";
AssignIoPort($hash); AssignIoPort($hash);
#This interface is shared with 00_MAXLAN.pm #This interface is shared with 00_MAXLAN.pm
@ -57,15 +67,38 @@ my @culHmCmdFlags = ("WAKEUP", "WAKEMEUP", "BCAST", "Bit3",
sub sub
CUL_MAX_Parse($$) CUL_MAX_Parse($$)
{ {
my ($hash, $msg) = @_; my ($hash, $rmsg) = @_;
$msg =~ m/Z(..)(..)(..)(..)(......)(......)(.*)/;
my ($len,$msgcnt,$msgFlag,$msgType,$src,$dst,$p) = ($1,$2,$3,$4,$5,$6,$7); if(!exists($modules{CUL_MAX}{defptr})) {
Log 1, "CUL_MAX_Parse: len mismatch" . (length($msg)/2-1) . " != ". hex($len) if(hex($len) != length($msg)/2-1); Log 5, "No CUL_MAX defined";
return "UNDEFINED CULMAX0 CUL_MAX 123456";
}
my $shash = $modules{CUL_MAX}{defptr};
$rmsg =~ m/Z(..)(..)(..)(..)(......)(......)(..)(.*)/;
my ($len,$msgcnt,$msgFlag,$msgType,$src,$dst,$zero,$payload) = ($1,$2,$3,$4,$5,$6,$7,$8);
Log 1, "CUL_MAX_Parse: len mismatch" if(2*hex($len)+3 != length($rmsg)); #+3 = +1 for 'Z' and +2 for len field in hex
Log 1, "CUL_MAX_Parse zero = $zero" if($zero != 0);
my $msgFlLong = ""; my $msgFlLong = "";
for(my $i = 0; $i < @culHmCmdFlags; $i++) { for(my $i = 0; $i < @culHmCmdFlags; $i++) {
$msgFlLong .= ",$culHmCmdFlags[$i]" if(hex($msgFlag) & (1<<$i)); $msgFlLong .= ",$culHmCmdFlags[$i]" if(hex($msgFlag) & (1<<$i));
} }
Log 5, "CUL_MAX_Parse: len $len, msgcnt $msgcnt, msgflag $msgFlLong, msgType $msgType, src $src, dst $dst, payload $p";
#convert adresses to lower case
$src = lc($src);
$dst = lc($dst);
Log 5, "CUL_MAX_Parse: len $len, msgcnt $msgcnt, msgflag $msgFlLong, msgType $msgType, src $src, dst $dst, payload $payload";
if($msgType eq "30") {
Dispatch($shash, "MAX,ShutterContactState,$src,$payload", {RAWMSG => $rmsg});
} elsif($msgType eq "60") {
Dispatch($shash, "MAX,HeatingThermostatState,$src,$payload", {RAWMSG => $rmsg});
} elsif($msgType eq "02") { #Ack
Log 5, "Got Ack";
} else {
Log 2, "Got unhandled message type $msgType";
}
return undef; return undef;
} }
@ -73,10 +106,8 @@ sub CUL_MAX_SendDeviceCmd($$)
{ {
my ($hash,$payload) = @_; my ($hash,$payload) = @_;
my $srcAddr = AttrVal($hash->{NAME},"srcAddrMAX","123456");
$hash->{cnt} += 1; $hash->{cnt} += 1;
substr($payload,3,3) = pack("H6",$srcAddr); substr($payload,3,3) = pack("H6",$hash->{addr});
substr($payload,1,0) = pack("C",$hash->{cnt}); substr($payload,1,0) = pack("C",$hash->{cnt});
$payload = pack("C",length($payload)) . $payload; $payload = pack("C",length($payload)) . $payload;
@ -94,12 +125,17 @@ sub CUL_MAX_SendDeviceCmd($$)
<ul> <ul>
The CUL_MAX module interprets MAX! messages received by the CUL. It will be automatically created by autocreate, just make sure The CUL_MAX module interprets MAX! messages received by the CUL. It will be automatically created by autocreate, just make sure
that you set the right rfmode like <code>attr CUL0 rfmode MAX</code>.<br> that you set the right rfmode like <code>attr CUL0 rfmode MAX</code>.<br>
You should also set a (random) source address for this module by <code>attr CUL0 srcAddrMAX <6-digit-hex></code>
<br><br> <br><br>
<a name="CUL_MAXdefine"></a> <a name="CUL_MAXdefine"></a>
<b>Define</b> <b>Define</b>
<ul>N/A</ul> <ul>
<code>define &lt;name&gt; CUL_MAX &lt;addr&gt;</code>
<br><br>
Defines an CUL_MAX device of type &lt;type&gt; and rf address &lt;addr&gt. The rf address
must not be in use by any other MAX device.
</ul>
<br> <br>
<a name="CUL_MAXset"></a> <a name="CUL_MAXset"></a>