mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +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:
parent
d740b4e8c0
commit
651b9c7269
@ -124,12 +124,12 @@ FHEM2FHEM_Write($$)
|
||||
}
|
||||
return if(!$conn); # Hopefuly it is reported elsewhere
|
||||
$hash->{TCPDev2} = $conn;
|
||||
syswrite($hash->{TCPDev2}, $hash->{portpassword} . "\n")
|
||||
F2F_sw($hash->{TCPDev2}, $hash->{portpassword} . "\n")
|
||||
if($hash->{portpassword});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$buf = Encode::decode('UTF-8', $buf) if($unicodeEncoding);
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
return if(IsDisabled($name));
|
||||
my $excl = AttrVal($name, "excludeEvents", undef);
|
||||
@ -310,13 +312,13 @@ FHEM2FHEM_OpenDev($$)
|
||||
|
||||
$hash->{STATE}= "connected";
|
||||
DoTrigger($name, "CONNECTED") if($reopen);
|
||||
syswrite($hash->{TCPDev}, $hash->{portpassword} . "\n")
|
||||
F2F_sw($hash->{TCPDev}, $hash->{portpassword} . "\n")
|
||||
if($hash->{portpassword});
|
||||
my $type = AttrVal($hash->{NAME},"addStateEvent",0) ? "onWithState" : "on";
|
||||
my $msg = $hash->{informType} eq "LOG" ?
|
||||
"inform $type $hash->{regexp}" : "inform raw";
|
||||
syswrite($hash->{TCPDev}, $msg . "\n");
|
||||
syswrite($hash->{TCPDev}, "trigger global CONNECTED $name\n")
|
||||
F2F_sw($hash->{TCPDev}, $msg . "\n");
|
||||
F2F_sw($hash->{TCPDev}, "trigger global CONNECTED $name\n")
|
||||
if(AttrVal($name, "reportConnected", 0));
|
||||
|
||||
my $ki = AttrVal($hash->{NAME}, "keepaliveInterval", 0);
|
||||
@ -353,6 +355,15 @@ FHEM2FHEM_Disconnected($)
|
||||
DoTrigger($name, "DISCONNECTED");
|
||||
}
|
||||
|
||||
|
||||
sub
|
||||
F2F_sw($$)
|
||||
{
|
||||
my ($io, $buf) = @_;
|
||||
$buf = Encode::encode('UTF-8', $buf) if($unicodeEncoding);
|
||||
return syswrite($io, $buf);
|
||||
}
|
||||
|
||||
sub
|
||||
FHEM2FHEM_Set($@)
|
||||
{
|
||||
@ -374,7 +385,7 @@ FHEM2FHEM_Set($@)
|
||||
return "Not connected" if(!$hash->{TCPDev});
|
||||
my $cmd = join(" ",@a[2..$#a]);
|
||||
$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};
|
||||
}
|
||||
return undef;
|
||||
|
@ -3866,7 +3866,7 @@ DoTrigger($$@)
|
||||
my $txt = ($inform{$c}{type} eq "timer" ? "$t " : "").
|
||||
"$hash->{TYPE} $dev $event\n";
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user