mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-17 17:36:01 +00:00
empty cmd-Q before pairing, improve autoReadReg details
git-svn-id: https://svn.fhem.de/fhem/trunk@4029 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
f228ed84f6
commit
4561c8b3c7
@ -34,6 +34,7 @@ my %sets = ( "hmPairForSec" => "HomeMatic"
|
||||
my %HMcond = ( 0 =>'ok'
|
||||
,2 =>'Warning-HighLoad'
|
||||
,4 =>'ERROR-Overload'
|
||||
,252=>'timeout'
|
||||
,253=>'disconnected'
|
||||
,254=>'Overload-released'
|
||||
,255=>'init');
|
||||
@ -50,6 +51,7 @@ sub HMLAN_Initialize($) {
|
||||
$hash->{WriteFn} = "HMLAN_Write";
|
||||
$hash->{ReadyFn} = "HMLAN_Ready";
|
||||
$hash->{SetFn} = "HMLAN_Set";
|
||||
$hash->{NotifyFn}= "HMLAN_Notify";
|
||||
$hash->{AttrFn} = "HMLAN_Attr";
|
||||
$hash->{Clients} = ":CUL_HM:";
|
||||
my %mc = (
|
||||
@ -138,7 +140,17 @@ sub HMLAN_RemoveHMPair($) {####################################################
|
||||
my $hash = $defs{$name};
|
||||
delete($hash->{hmPair});
|
||||
}
|
||||
sub HMLAN_Attr(@) {#################################
|
||||
sub HMLAN_Notify(@) {##########################################################
|
||||
my ($hash,$dev) = @_;
|
||||
return if ($dev->{NAME} ne $hash->{NAME}); # looking for our own connect/disconnect
|
||||
|
||||
foreach (grep (m/CONNECTED$/,@{$dev->{CHANGED}})) { # connect/disconnect
|
||||
if ($_ eq "DISCONNECTED") {HMLAN_condUpdate($hash,253);}
|
||||
# elsif ($_ eq "CONNECTED") {covered by init;}
|
||||
}
|
||||
return;
|
||||
}
|
||||
sub HMLAN_Attr(@) {############################################################
|
||||
my ($cmd,$name, $attrName,$aVal) = @_;
|
||||
if ($attrName eq "wdTimer"){#allow between 5 and 25 second
|
||||
return "select wdTimer between 5 and 25 seconds" if ($aVal>25 || $aVal<5);
|
||||
@ -195,14 +207,14 @@ sub HMLAN_Attr(@) {#################################
|
||||
return "please add plain integer between 100 and 600"
|
||||
if ( $aVal !~ m/^(\d+)$/
|
||||
||$aVal<100
|
||||
||$aVal >300 );
|
||||
||$aVal >600 );
|
||||
$attr{$name}{hmMsgLowLimit} =$aVal;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
sub HMLAN_UpdtMsgCnt($) {#################################
|
||||
sub HMLAN_UpdtMsgCnt($) {######################################################
|
||||
# update HMLAN capacity counter
|
||||
# HMLAN will raise high-load after ~610 msgs per hour
|
||||
# overload with send-stop after 670 msgs
|
||||
@ -215,7 +227,7 @@ sub HMLAN_UpdtMsgCnt($) {#################################
|
||||
InternalTimer(gettimeofday()+100, "HMLAN_UpdtMsgCnt", "UpdtMsg:".$name, 0);
|
||||
return;
|
||||
}
|
||||
sub HMLAN_UpdtMsgLoad($$) {#################################
|
||||
sub HMLAN_UpdtMsgLoad($$) {####################################################
|
||||
my($name,$incr) = @_;
|
||||
my $hash = $defs{$name};
|
||||
my $hCap = $hash->{helper}{q}{cap};
|
||||
@ -572,7 +584,6 @@ sub HMLAN_SimpleWrite(@) {#####################################################
|
||||
my ($hash, $msg, $nonl) = @_;
|
||||
|
||||
return if(!$hash || AttrVal($hash->{NAME}, "dummy", undef));
|
||||
HMLAN_condUpdate($hash,253) if ($hash->{STATE} eq "disconnected");#closed?
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my $ll5 = GetLogLevel($name,5);
|
||||
@ -700,8 +711,8 @@ sub HMLAN_KeepAliveCheck($) {##################################################
|
||||
my $hash = $defs{$name};
|
||||
if ($hash->{helper}{q}{keepAliveRec} != 1){# no answer
|
||||
if ($hash->{helper}{q}{keepAliveRpt} >2){# give up here
|
||||
HMLAN_condUpdate($hash,252);# trigger timeout event
|
||||
DevIo_Disconnected($hash);
|
||||
HMLAN_condUpdate($hash,253);
|
||||
}
|
||||
else{
|
||||
$hash->{helper}{q}{keepAliveRpt}++;
|
||||
|
@ -52,7 +52,6 @@ sub CUL_HM_Set($@);
|
||||
sub CUL_HM_valvePosUpdt(@);
|
||||
sub CUL_HM_infoUpdtDevData($$$);
|
||||
sub CUL_HM_infoUpdtChanData(@);
|
||||
sub CUL_HM_Pair(@);
|
||||
sub CUL_HM_getConfig($$$$$);
|
||||
sub CUL_HM_SndCmd($$);
|
||||
sub CUL_HM_responseSetup($$);
|
||||
@ -140,7 +139,7 @@ sub CUL_HM_Initialize($) {
|
||||
"rawToReadable unit ".#"KFM-Sensor" only
|
||||
"peerIDs repPeers ".
|
||||
"actCycle actStatus ".
|
||||
"autoReadReg:1_restart,0_off,2_pon-restart,3_onChange,4_reqStatus ".
|
||||
"autoReadReg:0_off,1_restart,2_pon-restart,3_onChange,4_reqStatus ".
|
||||
"expert:0_off,1_on,2_full ".
|
||||
"param msgRepeat ".
|
||||
".stc .devInfo ".
|
||||
@ -177,43 +176,40 @@ sub CUL_HM_autoReadConfig($){
|
||||
return;
|
||||
}
|
||||
while(@{$modules{CUL_HM}{helper}{autoRdCfgLst}}){
|
||||
|
||||
if ( $modules{CUL_HM}{helper}{autoRdActive} # predecisor is stored
|
||||
&& $defs{$modules{CUL_HM}{helper}{autoRdActive}}){
|
||||
my $dName = CUL_HM_getDeviceName($modules{CUL_HM}{helper}{autoRdActive});
|
||||
if ($defs{$dName}{helper}{prt}{sProc}){ # predecisor still working
|
||||
InternalTimer(gettimeofday()+$modules{CUL_HM}{hmAutoReadScan}
|
||||
,"CUL_HM_autoReadConfig"
|
||||
,"autoRdCfg",0);
|
||||
last;
|
||||
}
|
||||
my $dName = CUL_HM_getDeviceName($modules{CUL_HM}{helper}{autoRdActive});
|
||||
last if ($defs{$dName}{helper}{prt}{sProc}); # predecisor still working
|
||||
}
|
||||
|
||||
my $tName = CUL_HM_getDeviceName(${$modules{CUL_HM}{helper}{autoRdCfgLst}}[0]);
|
||||
my $ioName = $defs{$tName}{IODev}{NAME};
|
||||
if (ReadingsVal($ioName,"cond","") !~ m /^(ok|Overload-released|init)$/
|
||||
|| ( $defs{$ioName}{helper}{q}
|
||||
&& $defs{$ioName}{helper}{q}{cap}{sum}>AttrVal($ioName,"hmMsgLowLimit",500))){
|
||||
InternalTimer(gettimeofday()+$modules{CUL_HM}{hmAutoReadScan}
|
||||
,"CUL_HM_autoReadConfig"
|
||||
,"autoRdCfg",0);
|
||||
last;
|
||||
}
|
||||
#--- unqueue and process---
|
||||
my $name = shift(@{$modules{CUL_HM}{helper}{autoRdCfgLst}});
|
||||
my $hash = $defs{$name};
|
||||
delete $hash->{autoRead};
|
||||
|
||||
next if (AttrVal($name,"subType","") eq "virtual");
|
||||
|
||||
if (0 != CUL_HM_getAttrInt($name,"autoReadReg")){
|
||||
#CUL_HM_Set($hash,$name,"getSerial");
|
||||
CUL_HM_Set($hash,$name,"getConfig");
|
||||
CUL_HM_Set($hash,$name,"statusRequest");
|
||||
InternalTimer(gettimeofday()+$modules{CUL_HM}{hmAutoReadScan}
|
||||
,"CUL_HM_autoReadConfig"
|
||||
,"autoRdCfg",0);
|
||||
$modules{CUL_HM}{helper}{autoRdActive} = $name;#remember name
|
||||
my $mId = CUL_HM_getMId($hash);
|
||||
$modules{CUL_HM}{helper}{autoRdActive} = $name
|
||||
if ( CUL_HM_getRxType($hash) & 0xEB # 0x14 invers, if mode other then config
|
||||
||( $culHmModel{$mId}{cyc}
|
||||
&& $culHmModel{$mId}{cyc} !~ m/^28:/));
|
||||
last;
|
||||
}
|
||||
}
|
||||
InternalTimer(gettimeofday()+$modules{CUL_HM}{hmAutoReadScan}
|
||||
,"CUL_HM_autoReadConfig"
|
||||
,"autoRdCfg",0);
|
||||
}
|
||||
sub CUL_HM_updateConfig($){
|
||||
# this routine is called 5 sec after the last define of a restart
|
||||
@ -230,7 +226,8 @@ sub CUL_HM_updateConfig($){
|
||||
my $actCycle = AttrVal($name,"actCycle",undef);
|
||||
CUL_HM_ActAdd($id,$actCycle) if ($actCycle);# add to ActionDetect?
|
||||
# --- set default attrubutes if missing ---
|
||||
if ($hash->{helper}{role}{dev}){
|
||||
if ( $hash->{helper}{role}{dev}
|
||||
&& AttrVal($name,"subType","") ne "virtual"){
|
||||
$attr{$name}{expert} = AttrVal($name,"expert" ,"2_full");
|
||||
$attr{$name}{autoReadReg}= AttrVal($name,"autoReadReg","4_reqStatus")
|
||||
if(CUL_HM_getRxType($hash)&0xEB);
|
||||
@ -1629,17 +1626,37 @@ sub CUL_HM_parseCommon(@){#####################################################
|
||||
$ret = $reply;
|
||||
}
|
||||
elsif($mTp eq "00"){######################################
|
||||
if ($pendType eq "PairSerial"){
|
||||
if($shash->{helper}{prt}{rspWait}{forChn} = substr($p,6,20)){
|
||||
CUL_HM_respPendRm($shash);
|
||||
}
|
||||
}
|
||||
CUL_HM_ProcessCmdStack($shash) if(CUL_HM_getRxType($shash) & 0x04);#config
|
||||
CUL_HM_infoUpdtDevData($shash->{NAME}, $shash,$p);#update data
|
||||
|
||||
|
||||
my $iohash = $shash->{IODev};
|
||||
my $id = CUL_HM_Id($iohash);
|
||||
|
||||
if(!$shash->{cmdStack} || !(CUL_HM_getRxType($shash) & 0x04)) {
|
||||
CUL_HM_Pair($shash->{NAME}, $shash,$mFlg.$mTp,$src,$dst,$p);
|
||||
}
|
||||
if( $dst =~ m /(000000|$id)/ #--- see if we need to pair
|
||||
&&($iohash->{hmPair}
|
||||
||( $iohash->{hmPairSerial}
|
||||
&& $iohash->{hmPairSerial} eq $attr{$shash->{NAME}}{serialNr}))
|
||||
&&( $mFlg.$mTp ne "0400") ) {
|
||||
#-- try to pair
|
||||
Log GetLogLevel($shash->{NAME},3), "CUL_HM pair: $shash->{NAME} "
|
||||
."$attr{$shash->{NAME}}{subType}, "
|
||||
."model $attr{$shash->{NAME}}{model} "
|
||||
."serialNr $attr{$shash->{NAME}}{serialNr}";
|
||||
delete $iohash->{hmPairSerial};
|
||||
CUL_HM_respPendRm($shash); # remove all pending messages
|
||||
delete $shash->{cmdStack};
|
||||
delete $shash->{EVENTS};
|
||||
delete $shash->{helper}{prt}{rspWait};
|
||||
delete $shash->{helper}{prt}{rspWaitSec};
|
||||
|
||||
my ($idstr, $s) = ($id, 0xA);
|
||||
$idstr =~ s/(..)/sprintf("%02X%s",$s++,$1)/ge;
|
||||
CUL_HM_pushConfig($shash, $id, $src,0,0,0,0, "0201$idstr");
|
||||
CUL_HM_ProcessCmdStack($shash); # start processing immediately
|
||||
}
|
||||
elsif(CUL_HM_getRxType($shash) & 0x04){# nothing to pair - maybe send config
|
||||
CUL_HM_ProcessCmdStack($shash) ;#config
|
||||
}
|
||||
$ret = "done";
|
||||
}
|
||||
elsif($mTp eq "10"){######################################
|
||||
@ -2056,7 +2073,8 @@ sub CUL_HM_Set($@) {
|
||||
my $ret;
|
||||
return "no set value specified" if(@a < 2);
|
||||
my $name = $hash->{NAME};
|
||||
return "device ignored due to attr 'ignore'" if (CUL_HM_getAttrInt($name,"ignore"));
|
||||
return "device ignored due to attr 'ignore'"
|
||||
if (CUL_HM_getAttrInt($name,"ignore"));
|
||||
my $devName = $hash->{device}?$hash->{device}:$name;
|
||||
my $st = AttrVal($devName, "subType", "");
|
||||
my $md = AttrVal($devName, "model" , "");
|
||||
@ -3197,7 +3215,6 @@ sub CUL_HM_infoUpdtDevData($$$) {#autoread config
|
||||
CUL_HM_ActAdd($hash->{DEF},AttrVal($name,"actCycle",
|
||||
$culHmModel{$mId}{cyc}));
|
||||
}
|
||||
|
||||
}
|
||||
sub CUL_HM_infoUpdtChanData(@) {# verify attributes after reboot
|
||||
my($in ) = @_;
|
||||
@ -3205,40 +3222,6 @@ sub CUL_HM_infoUpdtChanData(@) {# verify attributes after reboot
|
||||
DoTrigger("global", 'UNDEFINED '.$chnName.' CUL_HM '.$chnId);
|
||||
$attr{CUL_HM_id2Name($chnId)}{model} = $model;
|
||||
}
|
||||
sub CUL_HM_Pair(@) {
|
||||
my ($name, $hash,$cmd,$src,$dst,$p) = @_;
|
||||
my $iohash = $hash->{IODev};
|
||||
my $id = CUL_HM_Id($iohash);
|
||||
my $serNo = $attr{$name}{serialNr};
|
||||
|
||||
Log GetLogLevel($name,3), "CUL_HM pair: $name $attr{$name}{subType}, "
|
||||
."model $attr{$name}{model} serialNr $serNo";
|
||||
|
||||
# Abort if we are not authorized
|
||||
if($dst eq "000000") {
|
||||
if(!$iohash->{hmPair} &&
|
||||
(!$iohash->{hmPairSerial} || $iohash->{hmPairSerial} ne $serNo)) {
|
||||
Log GetLogLevel($name,3),
|
||||
$iohash->{NAME}. " pairing (hmPairForSec) not enabled";
|
||||
return "";
|
||||
}
|
||||
}
|
||||
elsif($dst ne $id) {
|
||||
return "" ;
|
||||
}
|
||||
elsif($cmd eq "0400") { # WDC7000
|
||||
return "" ;
|
||||
}
|
||||
elsif($iohash->{hmPairSerial}) {
|
||||
delete($iohash->{hmPairSerial});
|
||||
}
|
||||
|
||||
my ($idstr, $s) = ($id, 0xA);
|
||||
$idstr =~ s/(..)/sprintf("%02X%s",$s++,$1)/ge;
|
||||
CUL_HM_pushConfig($hash, $id, $src,0,0,0,0, "0201$idstr");
|
||||
CUL_HM_ProcessCmdStack($hash); # start processing immediately
|
||||
return "";
|
||||
}
|
||||
sub CUL_HM_getConfig($$$$$){
|
||||
my ($hash,$chnhash,$id,$dst,$chn) = @_;
|
||||
my $flag = CUL_HM_getFlag($hash);
|
||||
|
Loading…
x
Reference in New Issue
Block a user