
| Current Path : /var/www/web-klick.de/dsh/90_akt/PPLTest.old/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/web-klick.de/dsh/90_akt/PPLTest.old/multiplexer.pl |
# Multiplexer: Stellt die Verbindung her zwischen Testframework und Target:
# Aus Sicht des Testframework ist das die Schnittstelle zum Target.
# Environment:
#
# localhost: Rechner, auf dem das Target laeuft
# localport: Port
# data_xml: Pfad zur MonitorData.xml
# list_xml: Pfad zur List.xml
# data_bin: Pfad zum Executable
# in_db: Blackboard vom Testframework
# out_db: Blackboard zum Testframework
use strict;
use IO::Socket;
use IO::Select;
use Server::BlackBoard;
use MIME::Base64;
use PPLTest::Buffer_Semantic;
use Time::HiRes qw(usleep);
use Data::Dumper;
use DivBasicF::COMsimple;
use Sys::Hostname;
use Win32::Process;
use Win32::Process::Info;
DivBasicF::COMsimple->read_in_environment();
#if (kill_application()) {
# sleep 5;
#}
#unlink("refresh.txt");
my $buffer = [];
my $counter = 0;
my $socket = "";
my $client = "";
my $o; my $o1; my $messages;
# Die Locale IP Addresse
my $host = hostname();
my $LocalAddr = inet_ntoa(scalar gethostbyname($host || 'localhost'));
# Port vom MMIMonitor
my $LocalPort = '11000';
print "\n\n MULTIPLEXER STARTED...\n\n-----\n\n\n";
$LocalPort = $ENV{'localport'} || $LocalPort;
$LocalAddr = $ENV{'localhost'} || $LocalAddr;
# starte SLT
system("start " . $ENV{'slt_bin'} . "\n");
sleep 5;
# verwendet dynamisch generierte local address (funktioniert auch)
print "Connect-Daten: $host $LocalAddr $LocalPort\n";
$socket = IO::Socket::INET->new(
'Type' => SOCK_STREAM,
'Listen' => SOMAXCONN,
'ReuseAddr' => 1,
'Timeout' => 6,
'LocalAddr' => $LocalAddr, # verwendet dynamisch generierte local address (funktioniert auch)
'LocalPort' => $LocalPort, # verwendet hard codierter local port (funktioniert auch)
'Proto' => 'tcp');
# starte client
system("start " . $ENV{'data_bin'});
# warte bis client connektiert ist
my $semantic = PPLTest::Buffer_Semantic->new();
print "Waiting for client...\n";
while ($socket and !$client) {
if ($client = $socket->accept()) {
print "connected to ", $client->peerhost(), ":", $client->peerport(), "\n";
}
print ".";
sleep 1;
}
# starte Flash-Application
sleep 3;
my $loader = $ENV{'data_bin'};
$loader =~ s/SimulationApplication.exe/HMI_Loader.swf/;
system("start FlashPlayer10 " . $loader);
my $in = Server::BlackBoard->new($ENV{'in_db'});
my $out = Server::BlackBoard->new($ENV{'out_db'});
my $select = IO::Select->new();
$select->add($client);
while (0 == 0) {
if (rand(2) > 0.8 and $select->can_read(1)) { # Lesen vom Target
$client->recv($o,256);
while ($o) {
$buffer->[0] = $buffer->[0] . sprintf("%02x",ord(substr($o,0,1)));
$o = substr($o,1);
}
while (0 == 0) {
$o = $semantic->semantic($buffer);
last if (!$o);
next if ($o =~ /^06/);
$o = $semantic->receive($o);
$out->msg($o);
}
}
else {
$messages = $in->get();
if (@$messages) { # Lesen vom Blackboard
while (@$messages) {
$o = shift(@$messages);
$o = $o->[1];
print "\nCOMMAND: $o\n";
if ($o =~ /^refresh/) {
unlink("refresh.txt");
kill_application();
print "\n\n MULTIPLEXER STOPPED...\n\n-----\n\n\n";
exit;
}
else { # Weitersenden von Kommandos ans Target
$o = $semantic->send($o); # Umwandlung in Byte-Stream
while ($o) {
$o1 = substr($o,0,2);
$o = substr($o,2);
if ($o1 eq "sl") {
usleep(1000*substr($o,0,8));
}
elsif ($o1 eq "ct") {
$counter = $counter + 1;
if ($counter == 256) { $counter = 0; }
print $client chr($counter) if ($client);
}
else {
print $client chr(hex($o1)) if ($client);
}
}
}
}
} else {
#print "Waiting ...\n";
sleep 1;
}
}
}
$client->shutdown(2);
sub kill_application {
my $proc_handler = "";
$proc_handler = Win32::Process::Info->new();
return(0) if (!$proc_handler);
my @procs = $proc_handler->GetProcInfo();
my $erg = 0;
foreach my $p (@procs) {
# print "Process found: " . $p->{'ProcessId'} .
# " " . $p->{'Name'} . "\n";
if ($p->{'Name'} =~ /(SimulationApplication|FlashPlayer)/) {
Win32::Process::KillProcess($p->{'ProcessId'},255);
$erg = 1;
}
}
return($erg);
}