mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +00:00
vbs did some changes
git-svn-id: https://svn.fhem.de/fhem/trunk@6079 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
5481b9e76b
commit
56faf322bf
@ -29,21 +29,34 @@
|
||||
##############################################################################
|
||||
|
||||
package main;
|
||||
use strict;
|
||||
use warnings;
|
||||
use IO::Socket::INET;
|
||||
use Sys::Hostname;
|
||||
use MIME::Base64;
|
||||
use DevIo;
|
||||
|
||||
my @gets = ('dummy');
|
||||
|
||||
sub
|
||||
STV_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
my ($hash) = @_;
|
||||
$hash->{DefFn} = "STV_Define";
|
||||
$hash->{UndefFn} = "STV_Undefine";
|
||||
$hash->{StateFn} = "STV_SetState";
|
||||
$hash->{SetFn} = "STV_Set";
|
||||
$hash->{AttrFn} = "STV_Attr";
|
||||
$hash->{AttrList} = "MAC";
|
||||
$hash->{ReadFn} = "STV_Read";
|
||||
$hash->{ReadyFn} = "STV_Ready";
|
||||
$hash->{AttrList} = "MAC fork:enable,disable setWhenOffline:execute,ignore " . $readingFnAttributes;;
|
||||
}
|
||||
|
||||
sub STV_Undefine($$)
|
||||
{
|
||||
my ($hash,$arg) = @_;
|
||||
DevIo_CloseDev($hash);
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
@ -61,7 +74,7 @@ STV_SetState($$$$)
|
||||
{
|
||||
my ($hash, $tim, $vt, $val) = @_;
|
||||
$val = $1 if($val =~ m/^(.*) \d+$/);
|
||||
return "Undefined value $val" if(!defined($it_c2b{$val}));
|
||||
# return "Undefined value $val" if(!defined($it_c2b{$val}));
|
||||
return undef;
|
||||
}
|
||||
|
||||
@ -72,9 +85,65 @@ sub getIP()
|
||||
return "$address";
|
||||
}
|
||||
|
||||
sub STV_Ready($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
if(AttrVal($hash->{NAME},'fork','disable') eq 'enable') {
|
||||
if($hash->{CHILDPID} && !(kill 0, $hash->{CHILDPID})) {
|
||||
$hash->{CHILDPID} = undef;
|
||||
return DevIo_OpenDev($hash, 1, "STV_Init");
|
||||
}
|
||||
elsif(!$hash->{CHILDPID}) {
|
||||
return if($hash->{CHILDPID} = fork);
|
||||
my $ppid = getppid();
|
||||
|
||||
### Copied from Blocking.pm
|
||||
foreach my $d (sort keys %defs) { # Close all kind of FD
|
||||
my $h = $defs{$d};
|
||||
TcpServer_Close($h) if($h->{SERVERSOCKET});
|
||||
if($h->{DeviceName}) {
|
||||
require "$attr{global}{modpath}/FHEM/DevIo.pm";
|
||||
DevIo_CloseDev($h,1);
|
||||
}
|
||||
}
|
||||
### End of copied from Blocking.pm
|
||||
|
||||
while(kill 0, $ppid) {
|
||||
DevIo_OpenDev($hash, 1, "STV_ChildExit");
|
||||
sleep(5);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
} else {
|
||||
return DevIo_OpenDev($hash, 1, "STV_Init");
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub STV_Read($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
#we dont really expect data here. Its just to gracefully close the device if the connection was closed
|
||||
my $buf = DevIo_SimpleRead($hash);
|
||||
}
|
||||
|
||||
sub STV_Init($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub STV_ChildExit($)
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
|
||||
sub STV_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
DevIo_CloseDev($hash);
|
||||
my @args = split("[ \t]+", $def);
|
||||
|
||||
if (int(@args) < 3)
|
||||
@ -100,6 +169,7 @@ sub STV_Define($$)
|
||||
"PLAY PAUSE REWIND FF REC STOP ".
|
||||
"TV HDMI PIP_ONOFF ASPECT EXT20";
|
||||
my $system = $^O;
|
||||
my $result;
|
||||
if($system =~ m/Win/) {
|
||||
$result = `ipconfig /all`;
|
||||
my @myarp=split(/\n/,$result);
|
||||
@ -127,11 +197,15 @@ sub STV_Define($$)
|
||||
|
||||
$hash->{MAC} = $result;
|
||||
$hash->{MyIP} = getIP();
|
||||
}
|
||||
|
||||
if ( $hash->{Port} != 55000 && $hash->{Port} != 52235 ){
|
||||
$hash->{DeviceName} = $hash->{Host} . ":" . $hash->{Port};
|
||||
my $dev = $hash->{DeviceName};
|
||||
$readyfnlist{"$args[0].$dev"} = $hash;
|
||||
}
|
||||
|
||||
if ( $hash->{Port} != 55000 && $hash->{Port} != 52235 ){
|
||||
return "[STV] Port is not supported";
|
||||
}
|
||||
}
|
||||
|
||||
Log3 undef, 3, "[STV] defined with host: $hash->{Host} port: $hash->{Port} MAC: $hash->{MAC}";
|
||||
$hash->{STATE} = 'Initialized';
|
||||
@ -144,7 +218,7 @@ sub connection($$)
|
||||
Log3 undef, 4, "[STV] connection message: $tmp";
|
||||
my $TV = shift;
|
||||
my $buffer = "";
|
||||
my $tmp2 = "";
|
||||
my @tmp2 = "";
|
||||
|
||||
my $sock = new IO::Socket::INET (
|
||||
PeerAddr => $TV,
|
||||
@ -174,7 +248,6 @@ sub STV_55000($$$)
|
||||
my $par=undef;
|
||||
my @ARGV = split(" ",$cmd);
|
||||
#### Configuration
|
||||
my $name = $hash->{NAME};
|
||||
my $tv = "UE46ES8090"; # Might need changing to match your TV type #"UE46ES8090"
|
||||
my $port = $hash->{Port}; # TCP port of Samsung TV
|
||||
my $tvip = $hash->{Host}; # IP Address of TV #"192.168.2.124"
|
||||
@ -199,6 +272,7 @@ sub STV_55000($$$)
|
||||
Proto => 'tcp',
|
||||
Timout => 5
|
||||
);
|
||||
|
||||
if (defined ($sock)){
|
||||
my $messagepart1 = chr(0x64) . chr(0x00) . chr(length(encode_base64($myip, ""))) . chr(0x00) . encode_base64($myip, "") . chr(length(encode_base64($mymac, ""))) . chr(0x00) . encode_base64($mymac, "") . chr(length(encode_base64($remotename, ""))) . chr(0x00) . encode_base64($remotename, "");
|
||||
my $part1 = chr(0x00) . chr(length($appstring)) . chr(0x00) . $appstring . chr(length($messagepart1)) . chr(0x00) . $messagepart1;
|
||||
@ -237,9 +311,8 @@ sub STV_55000($$$)
|
||||
}
|
||||
|
||||
# old Samsung Models
|
||||
sub STV_52235($@$@)
|
||||
sub STV_52235($@)
|
||||
{
|
||||
|
||||
my ($hash, @a) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
my $TV = $hash->{Host};
|
||||
@ -270,47 +343,47 @@ sub STV_52235($@$@)
|
||||
my $size = "";
|
||||
my $body = "";
|
||||
|
||||
if ( $arg eq "mute" )
|
||||
{
|
||||
if ( $arg eq "mute" )
|
||||
{
|
||||
$kind = 1;
|
||||
if ( $cont2 eq "off" ){
|
||||
$cont2 = 0 ;
|
||||
}else {
|
||||
$cont2 = 1 ;
|
||||
}
|
||||
}
|
||||
if ( $arg eq "volume")
|
||||
{
|
||||
}
|
||||
if ( $arg eq "volume")
|
||||
{
|
||||
if ( $cont2 > 0 and $cont2 < 100 ){
|
||||
$kind = 1;
|
||||
}else {
|
||||
Log3 $name, 3, "[STV] $name Volume: not correct";
|
||||
$kind = 0;
|
||||
}
|
||||
}
|
||||
if ( $arg eq "call")
|
||||
{
|
||||
}
|
||||
if ( $arg eq "call")
|
||||
{
|
||||
$kind = 2;
|
||||
|
||||
}
|
||||
if ( $arg eq "sms")
|
||||
{
|
||||
}
|
||||
if ( $arg eq "sms")
|
||||
{
|
||||
$kind = 3;
|
||||
for my $i (6..$count){
|
||||
$body .= $a[$i];
|
||||
$body .= " ";
|
||||
}
|
||||
}
|
||||
if ( $arg eq "date")
|
||||
{
|
||||
}
|
||||
if ( $arg eq "date")
|
||||
{
|
||||
$kind = 4;
|
||||
for my $i (10..$count){
|
||||
$body .= $a[$i];
|
||||
$body .= " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $kind eq 1){
|
||||
if ( $kind eq 1){
|
||||
$callsoap .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
|
||||
$callsoap .= "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n";
|
||||
$callsoap .= "<s:Body>\r\n";
|
||||
@ -335,14 +408,14 @@ if ( $kind eq 1){
|
||||
|
||||
$message .= $head;
|
||||
$message .= $callsoap;
|
||||
}
|
||||
}
|
||||
|
||||
my $calldate=`date +"%Y-%m-%d"`;
|
||||
chomp($calldate);
|
||||
my $calltime=`date +"%H:%M:%S"`;
|
||||
chomp($calltime);
|
||||
my $calldate=`date +"%Y-%m-%d"`;
|
||||
chomp($calldate);
|
||||
my $calltime=`date +"%H:%M:%S"`;
|
||||
chomp($calltime);
|
||||
|
||||
if ( $kind eq 2 ){ # CALL
|
||||
if ( $kind eq 2 ){ # CALL
|
||||
$callsoap .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
|
||||
$callsoap .= "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" >\r\n";
|
||||
$callsoap .= "<s:Body>\r\n";
|
||||
@ -383,7 +456,7 @@ if ( $kind eq 2 ){ # CALL
|
||||
$message .= $callsoap;
|
||||
}
|
||||
|
||||
if ( $kind eq 3 ){ # SMS
|
||||
if ( $kind eq 3 ){ # SMS
|
||||
$callsoap .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
|
||||
$callsoap .= "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" >\r\n";
|
||||
$callsoap .= "<s:Body>\r\n";
|
||||
@ -425,7 +498,7 @@ if ( $kind eq 3 ){ # SMS
|
||||
$message .= $callsoap;
|
||||
}
|
||||
|
||||
if ( $kind eq 4 ){ # Termin
|
||||
if ( $kind eq 4 ){ # Termin
|
||||
$callsoap .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
|
||||
$callsoap .= "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" >\r\n";
|
||||
$callsoap .= "<s:Body>\r\n";
|
||||
@ -467,9 +540,9 @@ if ( $kind eq 4 ){ # Termin
|
||||
|
||||
$message .= $head;
|
||||
$message .= $callsoap;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $kind ne 0 ){
|
||||
if ( $kind ne 0 ){
|
||||
connection($message, $TV);
|
||||
}else{
|
||||
return "Unknown argument $name, choose one of mute volume call sms date";
|
||||
@ -488,6 +561,11 @@ sub STV_Set($@)
|
||||
return $hash->{".validcommands"};
|
||||
}
|
||||
if ($hash->{".validcommands"} =~ /$cmd/) {
|
||||
if ((AttrVal($name, "setWhenOffline", undef) eq "ignore") and ($hash->{STATE} ne "opened")) {
|
||||
Log3 $name, 3, "[STV] Device seems offline. Set command ignored: $cmd";
|
||||
return;
|
||||
}
|
||||
|
||||
if ($Port eq 55000 ){
|
||||
STV_55000($hash,$nam,$cmd);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user