mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-16 10:46:03 +00:00
- M232 counter does not wraparound but locks at 65535. Workaround enabled.
git-svn-id: https://svn.fhem.de/fhem/trunk@380 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
af9f791d21
commit
5187426aad
@ -45,7 +45,7 @@ M232Counter_GetStatus($)
|
|||||||
|
|
||||||
my $d = IOWrite($hash, "z");
|
my $d = IOWrite($hash, "z");
|
||||||
if(!defined($d)) {
|
if(!defined($d)) {
|
||||||
my $msg = "M232Counter $name read error";
|
my $msg = "M232Counter $name tick count read error";
|
||||||
Log GetLogLevel($name,2), $msg;
|
Log GetLogLevel($name,2), $msg;
|
||||||
return $msg;
|
return $msg;
|
||||||
}
|
}
|
||||||
@ -73,7 +73,8 @@ M232Counter_GetStatus($)
|
|||||||
}
|
}
|
||||||
my $basis_prev= $basis;
|
my $basis_prev= $basis;
|
||||||
|
|
||||||
# previous count
|
|
||||||
|
# previous count (this variable is currently unused)
|
||||||
my $count_prev;
|
my $count_prev;
|
||||||
if(defined($r->{count})) {
|
if(defined($r->{count})) {
|
||||||
$count_prev= $r->{count}{VAL};
|
$count_prev= $r->{count}{VAL};
|
||||||
@ -83,10 +84,20 @@ M232Counter_GetStatus($)
|
|||||||
|
|
||||||
# current count
|
# current count
|
||||||
my $count= hex $d;
|
my $count= hex $d;
|
||||||
if($count< $count_prev) {
|
# If the counter reaches 65536, the counter does not wrap around but
|
||||||
$basis+= 65536;
|
# stops at 0. We therefore purposefully reset the counter to 0 before
|
||||||
$r->{basis}{VAL} = $basis;
|
# it reaches its final tick count.
|
||||||
$r->{basis}{TIME}= $tn;
|
if($count > 64000) {
|
||||||
|
$basis+= count;
|
||||||
|
$count= 0;
|
||||||
|
$r->{basis}{VAL} = $basis;
|
||||||
|
$r->{basis}{TIME}= $tn;
|
||||||
|
my $ret = IOWrite($hash, "Z1");
|
||||||
|
if(!defined($ret)) {
|
||||||
|
my $msg = "M232Counter $name reset error";
|
||||||
|
Log GetLogLevel($name,2), $msg;
|
||||||
|
return $msg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# previous value
|
# previous value
|
||||||
@ -110,7 +121,8 @@ M232Counter_GetStatus($)
|
|||||||
$r->{tsecs}{TIME} = $tn;
|
$r->{tsecs}{TIME} = $tn;
|
||||||
$r->{tsecs}{VAL} = $tsecs;
|
$r->{tsecs}{VAL} = $tsecs;
|
||||||
|
|
||||||
$hash->{CHANGED}[0]= "value: $value";
|
$hash->{CHANGED}[0]= "count: $count";
|
||||||
|
$hash->{CHANGED}[1]= "value: $value";
|
||||||
|
|
||||||
# delta
|
# delta
|
||||||
my $tsecs_delta= $tsecs-$tsecs_prev;
|
my $tsecs_delta= $tsecs-$tsecs_prev;
|
||||||
@ -121,7 +133,7 @@ M232Counter_GetStatus($)
|
|||||||
$delta= int($delta*1000.0+0.5)/1000.0;
|
$delta= int($delta*1000.0+0.5)/1000.0;
|
||||||
$r->{delta}{TIME} = $tn;
|
$r->{delta}{TIME} = $tn;
|
||||||
$r->{delta}{VAL} = $delta;
|
$r->{delta}{VAL} = $delta;
|
||||||
$hash->{CHANGED}[1]= "delta: $delta";
|
$hash->{CHANGED}[2]= "delta: $delta";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user