2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-03 16:56:54 +00:00

10_HXBDevice.pm: allow multiple devices in fhem for same physical device (ipv6 address)

git-svn-id: https://svn.fhem.de/fhem/trunk@7492 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
borisneubert 2015-01-10 14:20:38 +00:00
parent aeca465c94
commit 57cab65b70

View File

@ -156,9 +156,18 @@ HXBDevice_Define($$)
$hash->{fhem}{ipv6}= $ipv6;
AssignIoPort($hash);
$modules{$hash->{TYPE}}{defptr}{"$ipv6"}= $hash;
my @devarray= ();
my $devarrayref= $modules{$hash->{TYPE}}{defptr}{"$ipv6"};
if(defined($devarrayref)) {
@devarray= @{$devarrayref};
}
push @devarray, $hash;
$modules{$hash->{TYPE}}{defptr}{"$ipv6"}= \@devarray;
return undef;
# Todo: HXBDevice_Undefine
}
###################################
@ -194,15 +203,27 @@ sub
HXBDevice_Parse($$)
{
# we never come here if $msg does not match $hash->{MATCH} in the first place
# we never come here if $msg does not match $IOhash->{MATCH} in the first place
my ($IOhash, $data) = @_; # IOhash points to the HXB, not to the HXBDevice
my $socket= $IOhash->{TCPDev};
my $ipv6= $socket->peerhost;
my $hash= $modules{"HXBDevice"}{defptr}{"$ipv6"};
return "UNDEFINED HXB_$ipv6 HXBDevice $ipv6" unless(defined($hash));
my $hash;
# array of device hash with that IPv6 address
my @devices= ();
# matching devices
my @devarray= ();
my $devarrayref= $modules{"HXBDevice"}{defptr}{"$ipv6"};
if(defined($devarrayref)) {
@devarray= @{$devarrayref};
}
return "UNDEFINED HXB_$ipv6 HXBDevice $ipv6" if($#devarray< 0);
foreach $hash (@devarray) {
my $n= length($data);
return undef if($n< 8);
@ -243,10 +264,11 @@ HXBDevice_Parse($$)
readingsSingleUpdate($hash, "state", "$ep= $v", 1);
readingsSingleUpdate($hash, $ep, $v, 1);
return $hash->{NAME};
push @devices, $hash->{NAME};
}
}
return undef;
return @devices;
}