2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

FHEM2FHEM.pm: add encoding unicode support (Forum #126088)

git-svn-id: https://svn.fhem.de/fhem/trunk@25703 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2022-02-18 18:25:03 +00:00
parent d740b4e8c0
commit 651b9c7269
2 changed files with 18 additions and 7 deletions

View File

@ -124,12 +124,12 @@ FHEM2FHEM_Write($$)
} }
return if(!$conn); # Hopefuly it is reported elsewhere return if(!$conn); # Hopefuly it is reported elsewhere
$hash->{TCPDev2} = $conn; $hash->{TCPDev2} = $conn;
syswrite($hash->{TCPDev2}, $hash->{portpassword} . "\n") F2F_sw($hash->{TCPDev2}, $hash->{portpassword} . "\n")
if($hash->{portpassword}); if($hash->{portpassword});
} }
my $rdev = $hash->{rawDevice}; my $rdev = $hash->{rawDevice};
syswrite($hash->{TCPDev2}, "iowrite $rdev $fn $msg\n"); F2F_sw($hash->{TCPDev2}, "iowrite $rdev $fn $msg\n");
} }
##################################### #####################################
@ -153,6 +153,8 @@ FHEM2FHEM_Read($)
return; return;
} }
$buf = Encode::decode('UTF-8', $buf) if($unicodeEncoding);
my $name = $hash->{NAME}; my $name = $hash->{NAME};
return if(IsDisabled($name)); return if(IsDisabled($name));
my $excl = AttrVal($name, "excludeEvents", undef); my $excl = AttrVal($name, "excludeEvents", undef);
@ -310,13 +312,13 @@ FHEM2FHEM_OpenDev($$)
$hash->{STATE}= "connected"; $hash->{STATE}= "connected";
DoTrigger($name, "CONNECTED") if($reopen); DoTrigger($name, "CONNECTED") if($reopen);
syswrite($hash->{TCPDev}, $hash->{portpassword} . "\n") F2F_sw($hash->{TCPDev}, $hash->{portpassword} . "\n")
if($hash->{portpassword}); if($hash->{portpassword});
my $type = AttrVal($hash->{NAME},"addStateEvent",0) ? "onWithState" : "on"; my $type = AttrVal($hash->{NAME},"addStateEvent",0) ? "onWithState" : "on";
my $msg = $hash->{informType} eq "LOG" ? my $msg = $hash->{informType} eq "LOG" ?
"inform $type $hash->{regexp}" : "inform raw"; "inform $type $hash->{regexp}" : "inform raw";
syswrite($hash->{TCPDev}, $msg . "\n"); F2F_sw($hash->{TCPDev}, $msg . "\n");
syswrite($hash->{TCPDev}, "trigger global CONNECTED $name\n") F2F_sw($hash->{TCPDev}, "trigger global CONNECTED $name\n")
if(AttrVal($name, "reportConnected", 0)); if(AttrVal($name, "reportConnected", 0));
my $ki = AttrVal($hash->{NAME}, "keepaliveInterval", 0); my $ki = AttrVal($hash->{NAME}, "keepaliveInterval", 0);
@ -353,6 +355,15 @@ FHEM2FHEM_Disconnected($)
DoTrigger($name, "DISCONNECTED"); DoTrigger($name, "DISCONNECTED");
} }
sub
F2F_sw($$)
{
my ($io, $buf) = @_;
$buf = Encode::encode('UTF-8', $buf) if($unicodeEncoding);
return syswrite($io, $buf);
}
sub sub
FHEM2FHEM_Set($@) FHEM2FHEM_Set($@)
{ {
@ -374,7 +385,7 @@ FHEM2FHEM_Set($@)
return "Not connected" if(!$hash->{TCPDev}); return "Not connected" if(!$hash->{TCPDev});
my $cmd = join(" ",@a[2..$#a]); my $cmd = join(" ",@a[2..$#a]);
$cmd = '{my $r=fhem("'.$cmd.'");; defined($r) ? "\\0$r\\0" : $r}'."\n"; $cmd = '{my $r=fhem("'.$cmd.'");; defined($r) ? "\\0$r\\0" : $r}'."\n";
syswrite($hash->{TCPDev}, $cmd); F2F_sw($hash->{TCPDev}, $cmd);
$hash->{".lcmd"} = $hash->{CL}; $hash->{".lcmd"} = $hash->{CL};
} }
return undef; return undef;

View File

@ -3866,7 +3866,7 @@ DoTrigger($$@)
my $txt = ($inform{$c}{type} eq "timer" ? "$t " : ""). my $txt = ($inform{$c}{type} eq "timer" ? "$t " : "").
"$hash->{TYPE} $dev $event\n"; "$hash->{TYPE} $dev $event\n";
my $enc = $dc->{encoding} && $dc->{encoding} eq "latin1" ? "Latin1":"UTF-8"; my $enc = $dc->{encoding} && $dc->{encoding} eq "latin1" ? "Latin1":"UTF-8";
$txt = Encode::encode($enc, $txt); $txt = Encode::encode($enc, $txt) if($unicodeEncoding);
addToWritebuffer($dc, $txt); addToWritebuffer($dc, $txt);
} }
} }