2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-01 01:09:47 +00:00

CUL: added homematic changed from Martin

git-svn-id: https://svn.fhem.de/fhem/trunk@4467 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2013-12-26 17:11:11 +00:00
parent 8d2c182d89
commit e97a202e2e

View File

@ -677,22 +677,33 @@ CUL_XmitLimitCheck($$$)
} }
sub sub
CUL_XmitLimitCheckHM($$$) CUL_XmitDlyHM($$$)
{ {
# add a delay to last received. Thisis dynamic to obey System performance
# was working with 700ms - added buffer to 900ms
my ($hash,$fn,$now) = @_; my ($hash,$fn,$now) = @_;
my $id = (length($fn)>19)?substr($fn,16,6):"";#get HMID destination my $id = (length($fn)>19)?substr($fn,16,6):"";#get HMID destination
if($id && if($id &&
$hash->{helper} && $hash->{helper} &&
$hash->{helper}{nextSend} && $hash->{helper}{$id} &&
$hash->{helper}{nextSend}{$id}) { $hash->{helper}{$id}{nextSend}) {
my $DevDelay = $hash->{helper}{nextSend}{$id} - $now; my $dDly = $hash->{helper}{$id}{nextSend} - $now;
if ($DevDelay > 0.01){# wait less then 10 ms will not work if ($dDly > 0.01){# wait less then 10 ms will not work
$DevDelay = ((int($DevDelay*100))%100)/100;# security: no more then 1 sec $dDly = 0.1 if($dDly > 0.1);
select(undef, undef, undef, $DevDelay); Log3 $hash->{NAME}, 5, "CUL $id dly:".int($dDly*1000)."ms";
InternalTimer($now+$dDly,"CUL_XmitDlyHMTo", "$hash->{NAME}:$id", 1);
return 1;
} }
} }
shift(@{$hash->{helper}{$id}{QUEUE}});
InternalTimer($now+0.1, "CUL_XmitDlyHMTo", "$hash->{NAME}:$id", 1)
if (scalar(@{$hash->{helper}{$id}{QUEUE}}));
return 0;
}
sub
CUL_XmitDlyHMTo($)
{ # waited long enough - next send for this ID
my ($name,$id) = split(":",$_[0]);
CUL_SendFromQueue($defs{$name}, ${$defs{$name}{helper}{$id}{QUEUE}}[0]);
} }
##################################### #####################################
@ -736,7 +747,6 @@ CUL_Write($$$)
($fn, $msg) = CUL_WriteTranslate($hash, $fn, $msg); ($fn, $msg) = CUL_WriteTranslate($hash, $fn, $msg);
return if(!defined($fn)); return if(!defined($fn));
my $name = $hash->{NAME}; my $name = $hash->{NAME};
Log3 $name, 5, "$hash->{NAME} sending $fn$msg"; Log3 $name, 5, "$hash->{NAME} sending $fn$msg";
my $bstring = "$fn$msg"; my $bstring = "$fn$msg";
@ -744,7 +754,7 @@ CUL_Write($$$)
$bstring =~ m/^u....F/ || # FS20 messages sent over an RFR $bstring =~ m/^u....F/ || # FS20 messages sent over an RFR
($fn eq "" && ($bstring =~ m/^A/ || $bstring =~ m/^Z/ ))) { # AskSin/BidCos/HomeMatic/MAX ($fn eq "" && ($bstring =~ m/^A/ || $bstring =~ m/^Z/ ))) { # AskSin/BidCos/HomeMatic/MAX
CUL_AddFS20Queue($hash, $bstring); CUL_AddSendQueue($hash, $bstring);
} else { } else {
@ -763,7 +773,6 @@ CUL_SendFromQueue($$)
my $mz = ($bstring =~ m/^Z/); my $mz = ($bstring =~ m/^Z/);
my $to = ($hm ? 0.15 : 0.3); my $to = ($hm ? 0.15 : 0.3);
my $now = gettimeofday(); my $now = gettimeofday();
if($bstring ne "") { if($bstring ne "") {
my $sp = AttrVal($name, "sendpool", undef); my $sp = AttrVal($name, "sendpool", undef);
if($sp) { # Is one of the CUL-fellows sending data? if($sp) { # Is one of the CUL-fellows sending data?
@ -772,8 +781,7 @@ CUL_SendFromQueue($$)
if($f ne $name && if($f ne $name &&
$defs{$f} && $defs{$f} &&
$defs{$f}{QUEUE} && $defs{$f}{QUEUE} &&
$defs{$f}{QUEUE}->[0] ne "") $defs{$f}{QUEUE}->[0] ne ""){
{
unshift(@{$hash->{QUEUE}}, ""); unshift(@{$hash->{QUEUE}}, "");
InternalTimer($now+$to, "CUL_HandleWriteQueue", $hash, 1); InternalTimer($now+$to, "CUL_HandleWriteQueue", $hash, 1);
return; return;
@ -782,12 +790,13 @@ CUL_SendFromQueue($$)
} }
if($hm) { if($hm) {
CUL_XmitLimitCheckHM($hash,$bstring, $now); CUL_SimpleWrite($hash, $bstring) if(!CUL_XmitDlyHM($hash,$bstring,$now));
return;
} else { } else {
CUL_XmitLimitCheck($hash, $bstring, $now); CUL_XmitLimitCheck($hash, $bstring, $now);
}
CUL_SimpleWrite($hash, $bstring); CUL_SimpleWrite($hash, $bstring);
} }
}
############## ##############
# Write the next buffer not earlier than 0.23 seconds # Write the next buffer not earlier than 0.23 seconds
@ -797,15 +806,19 @@ CUL_SendFromQueue($$)
} }
sub sub
CUL_AddFS20Queue($$) CUL_AddSendQueue($$)
{ {
my ($hash, $bstring) = @_; my ($hash, $bstring) = @_;
if(!$hash->{QUEUE}) { my $qHash = $hash;
$hash->{QUEUE} = [ $bstring ]; if ($bstring =~ m/^A/){ # HM device
my $id = substr($bstring,16,6);#get HMID destination
$qHash = $hash->{helper}{$id};
}
if(!$qHash->{QUEUE} || 0 == scalar(@{$qHash->{QUEUE}})) {
$qHash->{QUEUE} = [ $bstring ];
CUL_SendFromQueue($hash, $bstring); CUL_SendFromQueue($hash, $bstring);
} else { } else {
push(@{$hash->{QUEUE}}, $bstring); push(@{$qHash->{QUEUE}}, $bstring);
} }
} }
@ -858,18 +871,20 @@ sub
CUL_Parse($$$$$) CUL_Parse($$$$$)
{ {
my ($hash, $iohash, $name, $rmsg, $initstr) = @_; my ($hash, $iohash, $name, $rmsg, $initstr) = @_;
my $rssi; my $rssi;
my $dmsg = $rmsg; my $dmsg = $rmsg;
my $dmsgLog = (AttrVal($name,"rfmode","") eq "HomeMatic")
? join(" ",(unpack'A1A2A2A4A6A6A*',$rmsg))
:$dmsg;
if($dmsg =~ m/^[AFTKEHRStZri]([A-F0-9][A-F0-9])+$/) { # RSSI if($dmsg =~ m/^[AFTKEHRStZri]([A-F0-9][A-F0-9])+$/) { # RSSI
my $l = length($dmsg); my $l = length($dmsg);
$rssi = hex(substr($dmsg, $l-2, 2)); $rssi = hex(substr($dmsg, $l-2, 2));
$dmsg = substr($dmsg, 0, $l-2); $dmsg = substr($dmsg, 0, $l-2);
$rssi = ($rssi>=128 ? (($rssi-256)/2-74) : ($rssi/2-74)); $rssi = ($rssi>=128 ? (($rssi-256)/2-74) : ($rssi/2-74));
Log3 $name, 5, "$name: $dmsg $rssi"; Log3 $name, 4, "CUL_Parse: $name $dmsgLog $rssi";
} else { } else {
Log3 $name, 5, "$name: $dmsg"; Log3 $name, 4, "CUL_Parse: $name $dmsgLog";
} }
########################################### ###########################################
@ -885,7 +900,7 @@ CUL_Parse($$$$$)
my $len = length($dmsg); my $len = length($dmsg);
if($fn eq "F" && $len >= 9) { # Reformat for 10_FS20.pm if($fn eq "F" && $len >= 9) { # Reformat for 10_FS20.pm
CUL_AddFS20Queue($iohash, ""); # Delay immediate replies CUL_AddSendQueue($iohash, ""); # Delay immediate replies
$dmsg = sprintf("81%02x04xx0101a001%s00%s", $dmsg = sprintf("81%02x04xx0101a001%s00%s",
$len/2+7, substr($dmsg,1,6), substr($dmsg,7)); $len/2+7, substr($dmsg,1,6), substr($dmsg,7));
$dmsg = lc($dmsg); $dmsg = lc($dmsg);
@ -940,7 +955,7 @@ CUL_Parse($$$$$)
; ;
} elsif($fn eq "A" && $len >= 20) { # AskSin/BidCos/HomeMatic } elsif($fn eq "A" && $len >= 20) { # AskSin/BidCos/HomeMatic
my $srcId = substr($dmsg,9,6); my $srcId = substr($dmsg,9,6);
$hash->{helper}{nextSend}{$srcId} = gettimeofday() + 0.100; $hash->{helper}{$srcId}{nextSend} = gettimeofday() + 0.100;
$dmsg .= "::$rssi:$name" if(defined($rssi)); $dmsg .= "::$rssi:$name" if(defined($rssi));
} elsif($fn eq "Z" && $len >= 21) { # Moritz/Max } elsif($fn eq "Z" && $len >= 21) { # Moritz/Max
@ -996,7 +1011,12 @@ CUL_SimpleWrite(@)
} }
my $name = $hash->{NAME}; my $name = $hash->{NAME};
if (AttrVal($name,"rfmode","") eq "HomeMatic"){
Log3 $name, 4, "CUL_send: $name".join(" ",unpack('A2A2A2A4A6A6A*',$msg));
}
else{
Log3 $name, 5, "SW: $msg"; Log3 $name, 5, "SW: $msg";
}
$msg .= "\n" unless($nonl); $msg .= "\n" unless($nonl);