valveCtrl update

git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@4814 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
martinp876
2014-02-05 15:32:21 +00:00
parent e25e8a78dd
commit 6a4d8b82b1

View File

@@ -3263,20 +3263,21 @@ sub CUL_HM_Set($@) {
$hash->{helper}{vd}{val} .= sprintf("%02X", $hash->{helper}{vd}{vinH}) $hash->{helper}{vd}{val} .= sprintf("%02X", $hash->{helper}{vd}{vinH})
if ($hash->{helper}{vd}{vinH} && $hash->{helper}{vd}{vinH} ne ""); if ($hash->{helper}{vd}{vinH} && $hash->{helper}{vd}{vinH} ne "");
} }
$hash->{helper}{vd}{idh} = hex(substr($dst,2,2))*20077; $hash->{helper}{vd}{idh} = hex(substr($dst,2,2))*20077;
$hash->{helper}{vd}{idl} = hex(substr($dst,4,2))*256; $hash->{helper}{vd}{idl} = hex(substr($dst,4,2))*256;
CUL_HM_UpdtReadSingle($hash,".msgCnt",ReadingsVal($name,".msgCnt",1),0); $hash->{helper}{vd}{msgCnt} = ReadingsVal($name,".msgCnt",0)
if (!defined $hash->{helper}{vd}{msgCnt});
if (!$hash->{helper}{virtTC}){ if (!$hash->{helper}{virtTC}){
my $pn = CUL_HM_id2Name($hash->{helper}{vd}{id}); my $pn = CUL_HM_id2Name($hash->{helper}{vd}{id});
$hash->{helper}{vd}{ackT} = ReadingsTimestamp($pn, "ValvePosition", ""); $hash->{helper}{vd}{ackT} = ReadingsTimestamp($pn, "ValvePosition", "")
if (!defined $hash->{helper}{vd}{ackT});
$hash->{helper}{vd}{miss} = 0 if (!defined$hash->{helper}{vd}{miss}); $hash->{helper}{vd}{miss} = 0 if (!defined$hash->{helper}{vd}{miss});
$hash->{helper}{virtTC} = ($cmd eq "valvePos")?"03":"00"; $hash->{helper}{virtTC} = ($cmd eq "valvePos")?"03":"00";
CUL_HM_UpdtReadSingle($hash,"valveCtrl","init",1)if ($cmd eq "valvePos"); CUL_HM_UpdtReadSingle($hash,"valveCtrl","init",1)if ($cmd eq "valvePos");
CUL_HM_UpdtReadSingle($hash,".next", $hash->{helper}{vd}{next} = ReadingsVal($name,".next",gettimeofday())
ReadingsVal($name,".next",gettimeofday()),0); if (!defined $hash->{helper}{vd}{next});
CUL_HM_valvePosUpdt("valvePos:$dst$chn"); CUL_HM_valvePosUpdt("valvePos:$dst$chn");
}; }
$hash->{helper}{virtTC} = ($cmd eq "valvePos")?"03":"00"; $hash->{helper}{virtTC} = ($cmd eq "valvePos")?"03":"00";
} }
CUL_HM_UpdtReadSingle($hash,$lim{$cmd}{rd},$valu.$lim{$cmd}{u},1); CUL_HM_UpdtReadSingle($hash,$lim{$cmd}{rd},$valu.$lim{$cmd}{u},1);
@@ -3578,10 +3579,10 @@ sub CUL_HM_valvePosUpdt(@) {#update valve position periodically to please valve
my(undef,$vId) = split(':',$in); my(undef,$vId) = split(':',$in);
my $hash = CUL_HM_id2Hash($vId); my $hash = CUL_HM_id2Hash($vId);
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $msgCnt = ReadingsVal($name,".msgCnt",0); my $msgCnt = $hash->{helper}{vd}{msgCnt};
my ($idl,$lo,$hi,$nextTimer); my ($idl,$lo,$hi,$nextTimer);
my $tn = gettimeofday(); my $tn = gettimeofday();
$hash->{helper}{vd}{nextF} = ReadingsVal($name,".next",0); $hash->{helper}{vd}{nextF} = $hash->{helper}{vd}{next};
# int32_t result = (((_address << 8) | messageCounter) * 1103515245 + 12345) >> 16; # int32_t result = (((_address << 8) | messageCounter) * 1103515245 + 12345) >> 16;
# 4e6d = 20077 12996205 = C64E6D # 4e6d = 20077 12996205 = C64E6D
@@ -3594,6 +3595,8 @@ sub CUL_HM_valvePosUpdt(@) {#update valve position periodically to please valve
$nextTimer = (($lo+$hi)&0xff)/4 + 120; $nextTimer = (($lo+$hi)&0xff)/4 + 120;
$hash->{helper}{vd}{nextF} += $nextTimer; $hash->{helper}{vd}{nextF} += $nextTimer;
} until ($hash->{helper}{vd}{nextF} > $tn); } until ($hash->{helper}{vd}{nextF} > $tn);
$hash->{helper}{vd}{nextM} = $tn+$nextTimer;
$hash->{helper}{vd}{msgCnt} = $msgCnt;
if ($hash->{helper}{vd}{cmd}){ if ($hash->{helper}{vd}{cmd}){
if ($hash->{helper}{vd}{typ} == 1){ if ($hash->{helper}{vd}{typ} == 1){
CUL_HM_PushCmdStack($hash,sprintf("%02X%s%s%s" CUL_HM_PushCmdStack($hash,sprintf("%02X%s%s%s"
@@ -3614,10 +3617,6 @@ sub CUL_HM_valvePosUpdt(@) {#update valve position periodically to please valve
CUL_HM_UpdtReadSingle($hash,"state","stopped",1); CUL_HM_UpdtReadSingle($hash,"state","stopped",1);
return;# terminate processing return;# terminate processing
} }
$hash->{helper}{vd}{nextF} = ReadingsVal($name,".next",0) + $nextTimer;
CUL_HM_UpdtReadBulk($hash,0,".next:".($tn+$nextTimer)
,".msgCnt:$msgCnt");
$hash->{helper}{virtTC} = "00"; $hash->{helper}{virtTC} = "00";
CUL_HM_ProcessCmdStack($hash); CUL_HM_ProcessCmdStack($hash);
InternalTimer($tn+10,"CUL_HM_valvePosTmr","valveTmr:$vId",0); InternalTimer($tn+10,"CUL_HM_valvePosTmr","valveTmr:$vId",0);
@@ -3632,13 +3631,16 @@ sub CUL_HM_valvePosTmr(@) {#calc next vd wakeup
my $ackTime = ReadingsTimestamp($pn, "ValvePosition", ""); my $ackTime = ReadingsTimestamp($pn, "ValvePosition", "");
my $vc; my $vc;
if (!$ackTime || $ackTime eq $hash->{helper}{vd}{ackT} ){ if (!$ackTime || $ackTime eq $hash->{helper}{vd}{ackT} ){
CUL_HM_UpdtReadSingle($hash,".next",$hash->{helper}{vd}{nextF},0); $hash->{helper}{vd}{next} = $hash->{helper}{vd}{nextF};
$vc = (++$hash->{helper}{vd}{miss} > 5) $vc = (++$hash->{helper}{vd}{miss} > 5)
?"lost" ?"lost"
:"miss_".$hash->{helper}{vd}{miss}; :"miss_".$hash->{helper}{vd}{miss};
Log3 $name,5,"CUL_HM $name virtualTC use fail-timer"; Log3 $name,5,"CUL_HM $name virtualTC use fail-timer";
} }
else{ else{
CUL_HM_UpdtReadBulk($hash,0,".next:".$hash->{helper}{vd}{next}
,".msgCnt:".($hash->{helper}{vd}{msgCnt}-1));
$hash->{helper}{vd}{next} = $hash->{helper}{vd}{nextM};
$vc = "ok"; $vc = "ok";
$hash->{helper}{vd}{miss} = 0; $hash->{helper}{vd}{miss} = 0;
} }
@@ -3646,7 +3648,7 @@ sub CUL_HM_valvePosTmr(@) {#calc next vd wakeup
if(ReadingsVal($name,"valveCtrl","") ne $vc); if(ReadingsVal($name,"valveCtrl","") ne $vc);
$hash->{helper}{vd}{ackT} = $ackTime; $hash->{helper}{vd}{ackT} = $ackTime;
} }
InternalTimer(ReadingsVal($name,".next",0),"CUL_HM_valvePosUpdt","valvePos:$vId",0); InternalTimer($hash->{helper}{vd}{next},"CUL_HM_valvePosUpdt","valvePos:$vId",0);
} }
sub CUL_HM_weather(@) {#periodically send weather data sub CUL_HM_weather(@) {#periodically send weather data
my($in ) = @_; my($in ) = @_;