00_TCM: error corrections for special devices (RS485, none) and delay timer

git-svn-id: https://svn.fhem.de/fhem/trunk@6156 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
klaus-schauer 2014-06-23 19:48:37 +00:00
parent 22d8b67389
commit 02b8da56eb

View File

@ -61,7 +61,7 @@ TCM_Initialize($)
$hash->{NotifyFn} = "TCM_Notify"; $hash->{NotifyFn} = "TCM_Notify";
$hash->{AttrFn} = "TCM_Attr"; $hash->{AttrFn} = "TCM_Attr";
$hash->{AttrList} = "do_not_notify:1,0 dummy:1,0 blockSenderID:own,no learningMode:always,demand,nearfield " . $hash->{AttrList} = "do_not_notify:1,0 dummy:1,0 blockSenderID:own,no learningMode:always,demand,nearfield " .
"sendInterval:0,25,40,50,100,150,200,250"; "comType:TCM,RS485 sendInterval:0,25,40,50,100,150,200,250";
} }
# Define # Define
@ -560,7 +560,7 @@ TCM_Get($@)
{ {
my ($hash, @a) = @_; my ($hash, @a) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
return if (AttrVal($name, "comType", "TCM") eq "RS485" || $hash->{DeviceName} eq "none");
return "\"get $name\" needs one parameter" if(@a != 2); return "\"get $name\" needs one parameter" if(@a != 2);
my $cmd = $a[1]; my $cmd = $a[1];
my ($err, $msg); my ($err, $msg);
@ -574,6 +574,7 @@ TCM_Get($@)
$rawcmd .= "000000000000000000"; $rawcmd .= "000000000000000000";
TCM_Write($hash, "", $rawcmd); TCM_Write($hash, "", $rawcmd);
($err, $msg) = TCM_ReadAnswer($hash, "get $cmd"); ($err, $msg) = TCM_ReadAnswer($hash, "get $cmd");
$msg = TCM_Parse120($hash, $msg, 1) if(!$err); $msg = TCM_Parse120($hash, $msg, 1) if(!$err);
} else { } else {
# TCM 310 # TCM 310
@ -584,6 +585,7 @@ TCM_Get($@)
my $cmdHex = $cmdhash->{cmd}; my $cmdHex = $cmdhash->{cmd};
TCM_Write($hash, sprintf("%04X0005", length($cmdHex)/2), $cmdHex); TCM_Write($hash, sprintf("%04X0005", length($cmdHex)/2), $cmdHex);
($err, $msg) = TCM_ReadAnswer($hash, "get $cmd"); ($err, $msg) = TCM_ReadAnswer($hash, "get $cmd");
$msg = TCM_Parse310($hash, $msg, $cmdhash) if(!$err); $msg = TCM_Parse310($hash, $msg, $cmdhash) if(!$err);
} }
if($err) { if($err) {
@ -633,12 +635,11 @@ TCM_Set($@)
{ {
my ($hash, @a) = @_; my ($hash, @a) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
return if (AttrVal($name, "comType", "TCM") eq "RS485" || $hash->{DeviceName} eq "none");
return "\"set $name\" needs at least one parameter" if(@a < 2); return "\"set $name\" needs at least one parameter" if(@a < 2);
my $cmd = $a[1]; my $cmd = $a[1];
my $arg = $a[2]; my $arg = $a[2];
my ($err, $msg); my ($err, $msg);
my $chash = ($hash->{MODEL} eq "ESP2" ? \%sets120 : \%sets310); my $chash = ($hash->{MODEL} eq "ESP2" ? \%sets120 : \%sets310);
my $cmdhash = $chash->{$cmd}; my $cmdhash = $chash->{$cmd};
return "Unknown argument $cmd, choose one of ".join(" ",sort keys %{$chash}) return "Unknown argument $cmd, choose one of ".join(" ",sort keys %{$chash})
@ -793,6 +794,14 @@ TCM_Attr(@) {
CommandDeleteAttr(undef, "$name $attrName"); CommandDeleteAttr(undef, "$name $attrName");
} }
} elsif ($attrName eq "comType") {
if (!defined $attrVal){
} elsif ($attrVal !~ m/^(TCM|RS485)$/) {
Log3 $name, 2, "EnOcean $name attribute-value [$attrName] = $attrVal wrong";
CommandDeleteAttr(undef, "$name $attrName");
}
} elsif ($attrName eq "learningMode") { } elsif ($attrName eq "learningMode") {
if (!defined $attrVal){ if (!defined $attrVal){
@ -818,17 +827,29 @@ sub TCM_Notify(@) {
my $name = $hash->{NAME}; my $name = $hash->{NAME};
if ($dev->{NAME} eq "global" && grep (m/^INITIALIZED$/,@{$dev->{CHANGED}})){ if ($dev->{NAME} eq "global" && grep (m/^INITIALIZED$/,@{$dev->{CHANGED}})){
my $attrVal; my $attrVal;
my $comType = AttrVal($name, "comType", "TCM");
my $setCmdVal = ""; my $setCmdVal = "";
my @setCmd = ("set", "reset", $setCmdVal); my @setCmd = ("set", "reset", $setCmdVal);
# read and discard receive buffer, modem reset # read and discard receive buffer, modem reset
if ($hash->{MODEL} eq "ESP2") { if ($hash->{MODEL} eq "ESP2") {
if ($comType eq "TCM") {
TCM_ReadAnswer($hash, "set reset");
TCM_Set($hash, @setCmd);
}
} else { } else {
TCM_ReadAnswer($hash, "set reset"); TCM_ReadAnswer($hash, "set reset");
TCM_Set($hash, @setCmd); TCM_Set($hash, @setCmd);
#usleep(200); #usleep(200);
} }
# default attributes # default attributes
my %setAttrInit = ("sendInterval" => {ESP2 => 100, ESP3 => 0}); my %setAttrInit;
if ($comType eq "RS485" || $hash->{DeviceName} eq "none") {
%setAttrInit = ("sendInterval" => {ESP2 => 100, ESP3 => 0},
"learningMode" => {ESP2 => "always", ESP3 => "always"}
);
}else {
%setAttrInit = ("sendInterval" => {ESP2 => 100, ESP3 => 0});
}
foreach(keys %setAttrInit) { foreach(keys %setAttrInit) {
$attrVal = AttrVal($name, $_, undef); $attrVal = AttrVal($name, $_, undef);
if(!defined $attrVal && defined $setAttrInit{$_}{$hash->{MODEL}}) { if(!defined $attrVal && defined $setAttrInit{$_}{$hash->{MODEL}}) {
@ -837,6 +858,7 @@ sub TCM_Notify(@) {
} }
} }
# default transceiver parameter # default transceiver parameter
if ($comType ne "RS485" && $hash->{DeviceName} ne "none") {
my %setCmdRestore = ("mode" => "00", my %setCmdRestore = ("mode" => "00",
"maturity" => "01", "maturity" => "01",
"repeater" => "RepEnable: 00 RepLevel: 00" "repeater" => "RepEnable: 00 RepLevel: 00"
@ -866,6 +888,8 @@ sub TCM_Notify(@) {
} }
} }
} }
}
if ($comType ne "RS485" && $hash->{DeviceName} ne "none") {
my @getBaseID = ("get", "baseID"); my @getBaseID = ("get", "baseID");
if (TCM_Get($hash, @getBaseID) =~ /[Ff]{2}[\dA-Fa-f]{6}/ ) { if (TCM_Get($hash, @getBaseID) =~ /[Ff]{2}[\dA-Fa-f]{6}/ ) {
$hash->{BaseID} = sprintf "%08X", hex $&; $hash->{BaseID} = sprintf "%08X", hex $&;
@ -874,6 +898,7 @@ sub TCM_Notify(@) {
$hash->{BaseID} = "00000000"; $hash->{BaseID} = "00000000";
$hash->{LastID} = "00000000"; $hash->{LastID} = "00000000";
} }
}
CommandSave(undef, undef); CommandSave(undef, undef);
readingsSingleUpdate($hash, "state", "initialized", 1); readingsSingleUpdate($hash, "state", "initialized", 1);
Log3 $name, 2, "TCM $name initialized"; Log3 $name, 2, "TCM $name initialized";
@ -930,7 +955,7 @@ TCM_Undef($$)
of commands depends on the hardware and the firmware version. A firmware update of commands depends on the hardware and the firmware version. A firmware update
is usually not provided. is usually not provided.
<br><br> <br><br>
The TCM module enables also a read-only wired connection to Eltako actuators over the The TCM module enables also a wired connection to Eltako actuators over the
Eltako RS485 bus in the switchboard or distribution box via Eltako FGW14 RS232-RS485 Eltako RS485 bus in the switchboard or distribution box via Eltako FGW14 RS232-RS485
gateway modules. These actuators are linked to an associated wireless antenna module gateway modules. These actuators are linked to an associated wireless antenna module
(FAM14) on the bus. The FAM14 device frequently polls the actuator status of all (FAM14) on the bus. The FAM14 device frequently polls the actuator status of all
@ -940,9 +965,9 @@ TCM_Undef($$)
downtime. As all actuators are polled approx. every 1-2 seconds, it should be avoided to downtime. As all actuators are polled approx. every 1-2 seconds, it should be avoided to
use event-on-update-reading. Use instead either event-on-change-reading or use event-on-update-reading. Use instead either event-on-change-reading or
event-min-interval. event-min-interval.
The Eltako bus uses the EnOcean Serial Protocol version 2 (ESP2) protocol, which is The Eltako bus uses the EnOcean Serial Protocol version 2 (ESP2). For this reason,
the same serial protocol used by TCM 120 modules. For this reason, a FGW14 can be a FGW14 can be configured as a ESP2. The attribute <a href="#TCM_comType">comType</a>
configured as a TCM 120.<br><br> must be set to RS485.<br><br>
<a name="TCMdefine"></a> <a name="TCMdefine"></a>
<b>Define</b> <b>Define</b>
@ -1067,6 +1092,10 @@ TCM_Undef($$)
Block receiving telegrams with a TCM SenderID sent by repeaters. Block receiving telegrams with a TCM SenderID sent by repeaters.
</li> </li>
<li><a href="#attrdummy">dummy</a></li> <li><a href="#attrdummy">dummy</a></li>
<li><a name="TCM_comType">comType</a> &lt;TCM|RS485&gt;,
comType = TCM is default.<br>
Type of communication device
</li>
<li><a href="#do_not_notify">do_not_notify</a></li> <li><a href="#do_not_notify">do_not_notify</a></li>
<li><a name="TCM_learningMode">learningMode</a> &lt;always|demand|nearfield&gt;, <li><a name="TCM_learningMode">learningMode</a> &lt;always|demand|nearfield&gt;,
[learningMode] = demand is default.<br> [learningMode] = demand is default.<br>
@ -1075,8 +1104,9 @@ TCM_Undef($$)
[learningMode] = demand: Teach-In/Teach-Out telegrams accepted if Fhem is in learning mode, see also <code>set &lt;IODev&gt; teach &lt;t/s&gt;</code><br> [learningMode] = demand: Teach-In/Teach-Out telegrams accepted if Fhem is in learning mode, see also <code>set &lt;IODev&gt; teach &lt;t/s&gt;</code><br>
[learningMode] = nearfield: Teach-In/Teach-Out telegrams accepted if Fhem is in learning mode and the signal strength RSSI >= -60 dBm.<be> [learningMode] = nearfield: Teach-In/Teach-Out telegrams accepted if Fhem is in learning mode and the signal strength RSSI >= -60 dBm.<be>
</li> </li>
<li><a name="TCM_sendInterval">sendInterval</a> &lt;0 ... 250&gt;, <li><a name="TCM_sendInterval">sendInterval</a> &lt;0 ... 250&gt;<br>
sendInterval = 100 ms is default.<br> ESP2: sendInterval = 100 ms is default.<br>
ESP3: sendInterval = 0 ms is default.<br>
Smallest interval between two sending telegrams Smallest interval between two sending telegrams
</li> </li>
<li><a href="#verbose">verbose</a></li> <li><a href="#verbose">verbose</a></li>