2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-03 04:36:36 +00:00

YAMAHA_BD: added HTTP request queue, send only one request at the same time.

git-svn-id: https://svn.fhem.de/fhem/trunk@10033 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
markusbloch 2015-11-28 14:17:24 +00:00
parent b58d4cfe66
commit 6572ee3b70
2 changed files with 62 additions and 20 deletions

View File

@ -1,5 +1,8 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
- changed: YAMAHA_BD: added HTTP request queue, send only one request at the
same time. This increases command reliability and response behaviour of
the player.
- changed: 55_GDS.pm: provide gdsAlertsHeadlines() instead of gdsHeadlines
- feature: TelegramBot: multiple enhancements and fixes V1.1
keyboards on favorites and last command

View File

@ -134,7 +134,6 @@ YAMAHA_BD_Get($@)
}
}
###################################
sub
YAMAHA_BD_Set($@)
@ -479,6 +478,9 @@ YAMAHA_BD_Define($$)
$hash->{helper}{ON_INTERVAL}=$hash->{helper}{OFF_INTERVAL};
}
$hash->{helper}{CMD_QUEUE} = ();
delete($hash->{helper}{HTTP_CONNECTION}) if(exists($hash->{helper}{HTTP_CONNECTION}));
# start the status update timer
$hash->{helper}{DISABLED} = 0 unless(exists($hash->{helper}{DISABLED}));
YAMAHA_BD_ResetTimer($hash, 2);
@ -538,34 +540,65 @@ YAMAHA_BD_Undefine($$)
#############################
# pushes new command to cmd queue
sub
YAMAHA_BD_SendCommand($$$$)
{
my ($hash, $data,$cmd,$arg) = @_;
my $name = $hash->{NAME};
my $address = $hash->{helper}{ADDRESS};
my $response;
Log3 $name, 4, "YAMAHA_BD ($name) - execute \"$cmd".(defined($arg) ? " ".$arg : "")."\": $data";
Log3 $name, 4, "YAMAHA_BD ($name) - append to queue \"$cmd".(defined($arg) ? " ".$arg : "")."\": $data";
# In case any URL changes must be made, this part is separated in this function".
HttpUtils_NonblockingGet({
url => "http://".$address.":50100/YamahaRemoteControl/ctrl",
timeout => AttrVal($name, "request-timeout", 4),
noshutdown => 1,
data => "<?xml version=\"1.0\" encoding=\"utf-8\"?>".$data,
loglevel => ($hash->{helper}{AVAILABLE} ? undef : 5),
hash => $hash,
cmd => $cmd,
arg => $arg,
callback => \&YAMAHA_BD_ParseResponse
}
);
my $param = {
data => "<?xml version=\"1.0\" encoding=\"utf-8\"?>".$data,
cmd => $cmd,
arg => $arg,
};
push @{$hash->{helper}{CMD_QUEUE}}, $param;
YAMAHA_BD_HandleCmdQueue($hash);
}
#############################
# starts http requests from cmd queue
sub
YAMAHA_BD_HandleCmdQueue($)
{
my ($hash) = @_;
my $name = $hash->{NAME};
my $address = $hash->{helper}{ADDRESS};
if(not($hash->{helper}{RUNNING_REQUEST}) and @{$hash->{helper}{CMD_QUEUE}})
{
my $params = {
url => "http://".$address.":50100/YamahaRemoteControl/ctrl",
timeout => AttrVal($name, "request-timeout", 4),
noshutdown => 1,
keepalive => 0,
httpversion => "1.0",
loglevel => ($hash->{helper}{AVAILABLE} ? undef : 5),
hash => $hash,
callback => \&YAMAHA_BD_ParseResponse
};
my $request = pop @{$hash->{helper}{CMD_QUEUE}};
map {$hash->{helper}{HTTP_CONNECTION}{$_} = $params->{$_}} keys %{$params};
map {$hash->{helper}{HTTP_CONNECTION}{$_} = $request->{$_}} keys %{$request};
$hash->{helper}{RUNNING_REQUEST} = 1;
Log3 $name, 4, "YAMAHA_BD ($name) - send command \"$request->{cmd}".(defined($request->{arg}) ? " ".$request->{arg} : "")."\": $request->{data}";
HttpUtils_NonblockingGet($hash->{helper}{HTTP_CONNECTION});
}
}
#############################
# parses all HTTP response and creates events/readings
sub
YAMAHA_BD_ParseResponse($$$)
{
@ -578,6 +611,9 @@ YAMAHA_BD_ParseResponse($$$)
my $cmd = $param->{cmd};
my $arg = $param->{arg};
$hash->{helper}{RUNNING_REQUEST} = 0;
delete($hash->{helper}{HTTP_CONNECTION}) unless($param->{keepalive});
if($err ne "")
{
@ -592,10 +628,8 @@ YAMAHA_BD_ParseResponse($$$)
}
elsif($data ne "")
{
Log3 $name, 5, "YAMAHA_BD ($name) - got HTTP response for \"$cmd".(defined($arg) ? " ".$arg : "")."\": $data";
if (defined($hash->{helper}{AVAILABLE}) and $hash->{helper}{AVAILABLE} == 0)
{
Log3 $name, 3, "YAMAHA_BD: device $name reappeared";
@ -733,14 +767,19 @@ YAMAHA_BD_ParseResponse($$$)
}
readingsEndUpdate($hash, 1);
if(@{$hash->{helper}{CMD_QUEUE}})
{
YAMAHA_BD_HandleCmdQueue($hash);
}
YAMAHA_BD_GetStatus($hash, 1) if($cmd ne "statusRequest" and $cmd ne "on");
YAMAHA_BD_ResetTimer($hash, 10) if($cmd eq "on");
}
$hash->{helper}{AVAILABLE} = ($err ? 0 : 1);
}
#############################
# resets the StatusUpdate Timer according to the device state and respective interval
sub