#!/usr/bin/perl use Time::HiRes qw( usleep ); use DBI; # use strict; use warnings; open (CONFIG, "connect("DBI:mysql:$conf{DatabaseName}:$conf{DatabaseServer}",$conf{DatabaseUser},$conf{DatabaseSecret}); my $X = 0; while( $X != 1 ) { $Query_lookque = "SELECT COUNT(*) FROM Input_Que"; my $lookque = $db_homenet->prepare( $Query_lookque ); $lookque->execute(); my ( $rows ); $lookque->bind_columns( undef, \$rows ); while( $lookque->fetch() ){} if ( $rows >= 1 ) { my $data = ""; $Query_check_inputque = "SELECT * FROM `Input_Que` WHERE 1 LIMIT 1"; my $check_inputque = $db_homenet->prepare( $Query_check_inputque ); $check_inputque->execute(); my( $nr, $timestamp, $busname, $data ); $check_inputque->bind_columns( undef, \$nr, \$timestamp, \$busname, \$data ); while( $check_inputque->fetch() ){ } print "$nr - $timestamp - $busname - $data"; if ( $data =~ /.*(\w{2})(\w{2})>(\w+)>/ ) # hard command { my $data_type = "hard_command"; my $sender_id = $1; my $receiver_id = $2; my $command = $3; print "HARD-COMMAND van $sender_id naar $receiver_id op bus $busname: Command = $command\n"; received_command($sender_id, $busname, $receiver_id, $busname, $command); } elsif ( $data =~ /.*(\w+)>(\w+)>(.+)>(\w+)>/ ) # soft command { my $data_type = "soft_command"; my $receiver_id = $3; my $command = $4; my $sender_id = "S3"; print "SOFT-COMMAND naar $receiver_id op bus $busname: Command = $command\n"; received_command($sender_id, $busname, $receiver_id, $busname, $command); } else { print "data kan niet worden ontcijferd! \n"; } $Query_delete_from_que = "DELETE FROM `Input_Que` WHERE `nr` = $nr LIMIT 1"; $db_homenet->do( $Query_delete_from_que ); } usleep 100000 } sub received_command { my $command_source = "*"; my $sbus = "*"; my $command_destination = "*"; my $dbus = "*"; my $data = "*"; ($command_source, $sbus, $command_destination, $dbus, $data) = @_; print "@_\n"; my $cod = "$command_destination"; # $Query_gettype = "SELECT `type` , `softv_high` , `softv_low` FROM `master_devices` WHERE naam = ( '$command_destination' ) && bus = ( '$dbus' ) LIMIT 1"; my $Query_gettype = "SELECT `type` , `softv_high` , `softv_low` FROM `master_devices` WHERE naam = ( '$cod' ) LIMIT 1"; print "$Query_gettype\n"; my $gettype = $db_homenet->prepare( $Query_gettype ); $gettype->execute(); my( $type, $swh, $swl ); $gettype->bind_columns( undef, \$type, \$swh, \$swl ); while( $gettype->fetch() ){} print "$type\n"; print "$swh\n"; print "$swl\n"; $devtype = "$type.$swh.$swl"; print "Device Type = $devtype\n"; } #### ./hbat-test "my" variable $data masks earlier declaration in same scope at ./hbat-test line 41. 9873 - 20050806205302 - 10.54.1.250 - 1>h>U1>h> SOFT-COMMAND naar U1 op bus 10.54.1.250: Command = h S3 10.54.1.250 U1 10.54.1.250 h SELECT `type` , `softv_high` , `softv_low` FROM `master_devices` WHERE naam = ( 'U1' ) LIMIT 1 Use of uninitialized value in concatenation (.) or string at ./hbat-test line 102. Use of uninitialized value in concatenation (.) or string at ./hbat-test line 103. Use of uninitialized value in concatenation (.) or string at ./hbat-test line 104. Use of uninitialized value in concatenation (.) or string at ./hbat-test line 105. Use of uninitialized value in concatenation (.) or string at ./hbat-test line 105. Use of uninitialized value in concatenation (.) or string at ./hbat-test line 105. Device Type = ..