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

00_KNXIO.pm: fix IO-device ready check (Forum Thread #127792)

git-svn-id: https://svn.fhem.de/fhem/trunk@26202 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
erwin 2022-07-09 10:59:00 +00:00
parent 49bddd28bf
commit ca50fb9ce6

View File

@ -32,6 +32,7 @@
# 25/04/2022 changed 'state connected' logic (issue after handshake complete...) # 25/04/2022 changed 'state connected' logic (issue after handshake complete...)
# 25/05/2022 first SVN version # 25/05/2022 first SVN version
# 07/07/2022 cleanup, no functional changes # 07/07/2022 cleanup, no functional changes
# 09/07/2022 fix IOdevice ready check on set-cmd (KNXIO_write)
package FHEM::KNXIO; ## no critic 'package' package FHEM::KNXIO; ## no critic 'package'
@ -308,7 +309,7 @@ sub KNXIO_ReadM {
# header format: 0x06 - header size / 0x10 - KNXNET-IPVersion / 0x0530 - Routing Indicator / 0xYYYY - Header size + size of cEMIFrame # header format: 0x06 - header size / 0x10 - KNXNET-IPVersion / 0x0530 - Routing Indicator / 0xYYYY - Header size + size of cEMIFrame
my ($header, $header_routing, $total_length) = unpack('nnn',$buf); my ($header, $header_routing, $total_length) = unpack('nnn',$buf);
Log3 ($name, 5, 'KNXIO_Read: -header=' . sprintf("%04x",$header) . ', -routing=' . sprintf("%04x",$header_routing) . ', TotalLength=' . $total_length . '(dezimal)'); Log3 ($name, 5, 'KNXIO_Read: -header=' . sprintf('%04x',$header) . ', -routing=' . sprintf('%04x',$header_routing) . ', TotalLength=' . $total_length . '(dezimal)');
if ($header != 0x0610 ) { if ($header != 0x0610 ) {
Log3 ($name, 1, 'KNXIO_Read: invalid header size or version'); Log3 ($name, 1, 'KNXIO_Read: invalid header size or version');
@ -346,7 +347,7 @@ sub KNXIO_ReadM {
return; # ignore with silence return; # ignore with silence
} }
else { else {
Log3 ($name, 4, 'KNXIO_Read: a packet with unsupported service type ' . sprintf("%04x",$header_routing) . ' was received. - discarded'); Log3 ($name, 4, 'KNXIO_Read: a packet with unsupported service type ' . sprintf('%04x',$header_routing) . ' was received. - discarded');
return; return;
} }
@ -471,7 +472,7 @@ sub KNXIO_Ready {
return if (! $init_done || exists($hash->{DNSWAIT}) || IsDisabled($name) == 1); return if (! $init_done || exists($hash->{DNSWAIT}) || IsDisabled($name) == 1);
return if (exists($hash->{NEXT_OPEN}) && $hash->{NEXT_OPEN} > gettimeofday()); # avoid open loop return if (exists($hash->{NEXT_OPEN}) && $hash->{NEXT_OPEN} > gettimeofday()); # avoid open loop
return KNXIO_openDev($hash) if (ReadingsVal($hash, 'state', 'disconnected') ne 'connected'); return KNXIO_openDev($hash) if (ReadingsVal($name, 'state', 'disconnected') ne 'connected');
return; return;
} }
@ -486,7 +487,7 @@ sub KNXIO_Write {
Log3 ($name, 5, 'KNXIO_write: started'); Log3 ($name, 5, 'KNXIO_write: started');
return if(!defined($fn) && $fn ne $TULID); return if(!defined($fn) && $fn ne $TULID);
if (ReadingsVal($hash, 'state', 'disconnected') ne 'connected') { if (ReadingsVal($name, 'state', 'disconnected') ne 'connected') {
# if ($hash->{STATE} ne 'connected') { # if ($hash->{STATE} ne 'connected') {
Log3 ($name, 3, 'KNXIO_write called while not connected! Msg: ' . $msg . ' lost'); Log3 ($name, 3, 'KNXIO_write called while not connected! Msg: ' . $msg . ' lost');
return; return;
@ -574,7 +575,7 @@ sub KNXIO_FingerPrint {
my $buf = shift; my $buf = shift;
my $mode = $defs{$ioname}->{model}; my $mode = $defs{$ioname}->{model};
substr( $buf, 1, 5, "-----" ); # ignore src addr substr( $buf, 1, 5, '-----' ); # ignore src addr
# Log3 ($ioname, 5, 'KNXIO_Fingerprint: ' . $buf); # Log3 ($ioname, 5, 'KNXIO_Fingerprint: ' . $buf);
# return ( $ioname, $buf ); # ignore src addr # return ( $ioname, $buf ); # ignore src addr
return ( q{}, $buf ); # ignore ioname & src addr return ( q{}, $buf ); # ignore ioname & src addr
@ -615,7 +616,7 @@ sub KNXIO_gethostbyname_Cb {
if ($error) { if ($error) {
delete $hash->{DeviceName}; delete $hash->{DeviceName};
delete $hash->{PORT}; delete $hash->{PORT};
Log3 ($name, 1, 'KNXIO-define: hostname could not be resolved: ' . $error); Log3 ($name, 1, 'KNXIO_define: hostname could not be resolved: ' . $error);
return 'KNXIO-define: hostname could not be resolved: ' . $error; return 'KNXIO-define: hostname could not be resolved: ' . $error;
} }
my $host = ip2str($dhost); my $host = ip2str($dhost);
@ -671,7 +672,7 @@ sub KNXIO_openDev {
} }
$host = $port if ($param =~ /UNIX:STREAM:/ix); $host = $port if ($param =~ /UNIX:STREAM:/ix);
Log3 ($name, 5, "KNXIO_openDev: $mode, $host, $port, reopen=$reopen"); Log3 ($name, 5, 'KNXIO_openDev: ' . $mode . ', ' . $host . ', ' . $port . ', reopen=' . $reopen);
my $ret = undef; # result my $ret = undef; # result
@ -680,11 +681,11 @@ sub KNXIO_openDev {
delete $hash->{TCPDev}; # devio ? delete $hash->{TCPDev}; # devio ?
$ret = TcpServer_Open($hash, $port, $host, 1); $ret = TcpServer_Open($hash, $port, $host, 1);
if (defined($ret)) { # error if (defined($ret)) { # error
Log3 ($name, 2, "KNXIO_openDev: $name can't connect: $ret") if(!$reopen); Log3 ($name, 2, 'KNXIO_openDev: ' . $name . " can't connect: " . $ret) if(!$reopen);
} }
$ret = TcpServer_MCastAdd($hash,$host); $ret = TcpServer_MCastAdd($hash,$host);
if (defined($ret)) { # error if (defined($ret)) { # error
Log3 ($name, 2, "KNXIO_openDev: $name MC add failed: $ret") if(!$reopen); Log3 ($name, 2, 'KNXIO_openDev: ' . $name . ' MC add failed: ' . $ret) if(!$reopen);
} }
delete $hash->{NEXT_OPEN}; delete $hash->{NEXT_OPEN};
@ -706,7 +707,7 @@ sub KNXIO_openDev {
my $conn = 0; my $conn = 0;
$conn = IO::Socket::INET->new(PeerAddr => "$host:$port", Type => SOCK_DGRAM, Proto => 'udp', Reuse => 1); $conn = IO::Socket::INET->new(PeerAddr => "$host:$port", Type => SOCK_DGRAM, Proto => 'udp', Reuse => 1);
if (!($conn)) { if (!($conn)) {
Log3 ($name, 2, "KNXIO_openDev: device $name can't connect: $ERRNO") if(!$reopen); # PBP Log3 ($name, 2, 'KNXIO_openDev: device ' . $name . " can't connect: " . $ERRNO) if(!$reopen); # PBP
$readyfnlist{"$name.$param"} = $hash; $readyfnlist{"$name.$param"} = $hash;
readingsSingleUpdate($hash, 'state', 'disconnected', 0); readingsSingleUpdate($hash, 'state', 'disconnected', 0);
$hash->{NEXT_OPEN} = gettimeofday() + $reconnectTO; $hash->{NEXT_OPEN} = gettimeofday() + $reconnectTO;
@ -947,7 +948,8 @@ sub KNXIO_decodeEMI {
my $rwp = $acpicodes[$acpi]; my $rwp = $acpicodes[$acpi];
if (! defined($rwp) || ($rwp eq 'invalid')) { if (! defined($rwp) || ($rwp eq 'invalid')) {
Log3 ($name, 3, 'KNXIO_decodeEMI: no valid acpi-code (read/reply/write) received, discard packet'); Log3 ($name, 3, 'KNXIO_decodeEMI: no valid acpi-code (read/reply/write) received, discard packet');
Log3 ($name, 4, "discarded packet: src=$src - dst=$dst - acpi=" . sprintf('%02x',$acpi) . " - leng=" . scalar(@data) . " - data=" . sprintf('%02x' x scalar(@data),@data)); # Log3 ($name, 4, 'discarded packet: src=' . $src . ' - dst=' . $dst . ' - acpi=' . sprintf('%02x',$acpi) . ' - leng=' . scalar(@data) . ' - data=' . sprintf('%02x' x scalar(@data),@data));
# Log3 ($name, 4, "discarded packet: src=$src - dst=$dst - acpi=" . sprintf('%02x',$acpi) . " - leng=" . scalar(@data) . " - data=" . sprintf('%02x' x scalar(@data),@data));
return; return;
} }
@ -1001,7 +1003,7 @@ sub KNXIO_decodeCEMI {
my $rwp = $acpicodes[$acpi]; my $rwp = $acpicodes[$acpi];
if (! defined($rwp) || ($rwp eq 'invalid')) { # not a groupvalue-read/write/reply if (! defined($rwp) || ($rwp eq 'invalid')) { # not a groupvalue-read/write/reply
Log3 ($name, 3, 'KNXIO_decodeCEMI: no valid acpi-code (read/reply/write) received, discard packet'); Log3 ($name, 3, 'KNXIO_decodeCEMI: no valid acpi-code (read/reply/write) received, discard packet');
Log3 ($name, 4, 'discarded packet: src=' . $src . ' - dst=' . $dst . ' - destaddrType=' . $dest_addrType . ' - prio=' . $prio . ' - hop_count=' . $hop_count . ' - leng=' . scalar(@data) . ' - data=' . sprintf('%02x' x scalar(@data),@data)); # Log3 ($name, 4, 'discarded packet: src=' . $src . ' - dst=' . $dst . ' - destaddrType=' . $dest_addrType . ' - prio=' . $prio . ' - hop_count=' . $hop_count . ' - leng=' . scalar(@data) . ' - data=' . sprintf('%02x' x scalar(@data),@data));
return; return;
} }