Fr os con2010_bmatrainer

Embed Size (px)

Citation preview

Slide 1

BMATrainer

Simulationsprogramm fr Brandmeldeanlagen

Die GUI

Die GUI

Die GUI

Die GUI

wxFormBuilder im Einsatz...

GUI

Plugins

Plugins I

Lst den Alarm aus

Einfache Arduino-Anwendung

Anschluss an USB-Port

Device::SerialPort zum Auslesen der Arduino-Daten

Einfacher Sketch fr Arduino

Plugins I

Plugins I

use Win32::SerialPort;

my $port = 'COM3';my $baud = 9600;my $parity = 'none';my $data = 2;my $stop = 1;my $handshake = 'none';

sub new { bless {}, shift;}

Plugins I

my $conn = Win32::SerialPort->new( $port ) or die $^E;

$conn->databits( $data ); $conn->baudrate( $baud ); $conn->parity( $parity ); $conn->stopbits( $stop );

while ( 1 ) { my $char = $conn->lookfor; no warnings 'numeric'; # read input from usb port # if 1 is returned, start alarm $conn->lookclear; }

Plugins II

Soll Hausalarm simulieren

Steuerung mit Win32::Sound

Win32-only im Moment

Plugins II

sub start_sound { my ($self) = @_; Win32::Sound::Volume( '100%' ); Win32::Sound::Play( $self->sound_file, SND_ASYNC );}

sub stop_sound { Win32::Sound::Stop();}

Plugins

threads + wxPerl use threads vor use Wx

Kommunikation zwischen den Plugins und der Anwendung muss mglich seinEin Eventsystem musste her

Einbinden muss einfach sein

Plugins einbinden

my $config_file = Path::Class::File->new( $args{directory}, 'plugins.yml', ); my $config = BMA::Config->new( $config_file->absolute.'' ); my $plugins = $config->get( 'plugins' ); for my $plugin ( @{$plugins} ) { $plugin->{package} = 'BMA::Plugins::'.$plugin->{module}; my $file = $plugin->{package} . '.pm'; $file =~ s{ :: }{/}gxms; $plugin->{file} = $file; push @{ $self->{ $plugin->{type} } }, $plugin; }

Plugins einbinden

---plugins: - type: input module: Feuermelder active: 0 label: Feuermelder - type: output module: Sirene event: AlarmStart active: 0 label: Sirene

Kommunikation

Kommunikation

GUI muss von Plugins Befehle empfangen knnenEinfach Methodenaufrufe des GUI-Objekts

GUI muss Befehle an Plugins senden knnenNicht so einfach, da GUI die Methoden der Plugins nicht kennt

Plugin Plugin mssen ber GUI-Methoden kommunizieren, da diese voneinander nichts wissen

=> Ein Eventsystem muss her

Kommunikation

Alle Output-Plugins knnen auf Events hren, alle Events knnen Events auslsen

GUI stellt an Hand der Konfig fest, welche Plugins aufgerufen werden mssen

Kommunikation

for my $plugin ( $self->plugins( $event ) ) { my $file = $plugin->{file}; eval { $logger->debug( "require $file" ); require $file; my $object = $plugin->{package}->new( %{$plugin}, logger => $logger, BMA => $args{BMA}, ); $object->run( %args ); 1; } or $logger->debug( "Could not load $file: $@" ); }

Kommunikation

$self->event( event => 'StartAlarm', );

Zukunft von BMATrainer

Es ist noch einiges zu tun

Mehr Plugins

Plugins auch unter Linux verfgbar machen

.exe fr Windows-Nutzer erstellen

Restliche Funktionalitt programmieren

Dokumentieren

Lesestoff

$foo Perl-MagazinBMATrainer: Ausgaben 13 und 14

WxPerl-Tutorial: ab Ausgabe 12

http://github.com/reneeb/BMATrainer

http://renee-baecker.de/vortraege.html

Fragen?

Hier auf der FrOSCon oder unter

[email protected]

Vielen Dank fr Ihre Aufmerksamkeit