2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-28 17:12:32 +00:00

Queue-Bug: prevents all set/get operations

git-svn-id: https://svn.fhem.de/fhem/trunk@280 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2008-12-05 14:29:29 +00:00
parent ace6139b24
commit 05c8a69552
2 changed files with 22 additions and 18 deletions

View File

@ -8,7 +8,7 @@ use Time::HiRes qw(gettimeofday);
sub FHZ_Write($$$); sub FHZ_Write($$$);
sub FHZ_Read($); sub FHZ_Read($);
sub FHZ_ReadAnswer($$); sub FHZ_ReadAnswer($$$);
sub FHZ_Crc(@); sub FHZ_Crc(@);
sub FHZ_CheckCrc($); sub FHZ_CheckCrc($);
sub FHZ_XmitLimitCheck($$); sub FHZ_XmitLimitCheck($$);
@ -175,9 +175,11 @@ FHZ_Get($@)
my $name = $hash->{NAME}; my $name = $hash->{NAME};
Log GetLogLevel($name,2), "FHZ get $v"; Log GetLogLevel($name,2), "FHZ get $v";
FHZ_ReadAnswer($hash, "Flush", 0);
FHZ_Write($hash, $fn, $arg) if(!IsDummy($hash->{NAME})); FHZ_Write($hash, $fn, $arg) if(!IsDummy($hash->{NAME}));
my $msg = FHZ_ReadAnswer($hash, $a[1]); my $msg = FHZ_ReadAnswer($hash, $a[1], 1.0);
Log 5, "GET Got: $msg";
return $msg if(!$msg || $msg !~ /^81..c9..0102/); return $msg if(!$msg || $msg !~ /^81..c9..0102/);
if($a[1] eq "serial") { if($a[1] eq "serial") {
@ -397,9 +399,9 @@ FHZ_CheckCrc($)
##################################### #####################################
# This is a direct read for commands like get # This is a direct read for commands like get
sub sub
FHZ_ReadAnswer($$) FHZ_ReadAnswer($$$)
{ {
my ($hash,$arg) = @_; my ($hash,$arg, $to) = @_;
return undef if(!$hash || !defined($hash->{FD})); return undef if(!$hash || !defined($hash->{FD}));
@ -410,7 +412,7 @@ FHZ_ReadAnswer($$)
$nfound=FHZ_Ready($hash); $nfound=FHZ_Ready($hash);
} else { } else {
vec($rin, $hash->{FD}, 1) = 1; vec($rin, $hash->{FD}, 1) = 1;
$nfound = select($rin, undef, undef, 3); # 3 seconds timeout $nfound = select($rin, undef, undef, $to);
if($nfound < 0) { if($nfound < 0) {
next if ($! == EAGAIN() || $! == EINTR() || $! == 0); next if ($! == EAGAIN() || $! == EINTR() || $! == 0);
die("Select error $nfound / $!\n"); die("Select error $nfound / $!\n");
@ -510,9 +512,10 @@ FHZ_Write($$$)
my $bstring = FHZ_CompleteMsg($fn, $msg); my $bstring = FHZ_CompleteMsg($fn, $msg);
Log 5, "Sending " . unpack('H*', $bstring); Log 5, "Sending " . unpack('H*', $bstring);
if(!$hash->{QUEUECNT}) { if(!$hash->{QUEUE}) {
FHZ_XmitLimitCheck($hash,$bstring); FHZ_XmitLimitCheck($hash,$bstring);
$hash->{QUEUE} = [ $bstring ];
$hash->{PortObj}->write($bstring); $hash->{PortObj}->write($bstring);
############## ##############
@ -520,12 +523,9 @@ FHZ_Write($$$)
# 65.6ms + 10ms + 65.6ms), else it will be discarded by the FHZ1X00 PC # 65.6ms + 10ms + 65.6ms), else it will be discarded by the FHZ1X00 PC
InternalTimer(gettimeofday()+0.25, "FHZ_HandleWriteQueue", $hash, 1); InternalTimer(gettimeofday()+0.25, "FHZ_HandleWriteQueue", $hash, 1);
} elsif($hash->{QUEUECNT} == 1) {
$hash->{QUEUE} = [ $bstring ];
} else { } else {
push(@{$hash->{QUEUE}}, $bstring); push(@{$hash->{QUEUE}}, $bstring);
} }
$hash->{QUEUECNT}++;
} }
@ -535,14 +535,18 @@ sub
FHZ_HandleWriteQueue($) FHZ_HandleWriteQueue($)
{ {
my $hash = shift; my $hash = shift;
if($hash->{QUEUECNT} > 0) { my $arr = $hash->{QUEUE};
$hash->{QUEUECNT}--;
my $bstring = shift(@{$hash->{QUEUE}}); if(defined($arr) && @{$arr} > 0) {
if(defined($bstring)) { shift(@{$arr});
FHZ_XmitLimitCheck($hash,$bstring); if(@{$arr} == 0) {
$hash->{PortObj}->write($bstring); delete($hash->{QUEUE});
InternalTimer(gettimeofday()+0.25, "FHZ_HandleWriteQueue", $hash, 1); return;
} }
my $bstring = $arr->[0];
FHZ_XmitLimitCheck($hash,$bstring);
$hash->{PortObj}->write($bstring);
InternalTimer(gettimeofday()+0.25, "FHZ_HandleWriteQueue", $hash, 1);
} }
} }

View File

@ -514,12 +514,12 @@ getFhtBuffer($)
for(;;) { for(;;) {
FHZ_Write($io, "04", "c90185"); FHZ_Write($io, "04", "c90185");
my $msg = FHZ_ReadAnswer($io, "fhtbuf"); my $msg = FHZ_ReadAnswer($io, "fhtbuf", 1.0);
if(!defined($msg)) { $msg= ""; } if(!defined($msg)) { $msg= ""; }
Log 5, "getFhtBuffer: $count $msg"; Log 5, "getFhtBuffer: $count $msg";
return hex(substr($msg, 16, 2)) if($msg && $msg =~ m/^[0-9A-F]+$/i); return hex(substr($msg, 16, 2)) if($msg && $msg =~ m/^[0-9A-F]+$/i);
return 0 if($count++ > 5); return 0 if($count++ >= 5);
} }
} }