Revert "FRM: catch exceptions from perl-firmata in FRM_OWX-calls"

This reverts commit d08208bedebd3417c7c176023e42d6dfe758813b.

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@5562 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
ntruchsess 2014-04-18 19:13:38 +00:00
parent c70515dd5b
commit 8d146101a5

View File

@ -659,23 +659,24 @@ package main;
sub FRM_I2C_Write sub FRM_I2C_Write
{ {
my ($hash,$package) = @_; my ($hash,$package) = @_;
my $firmata = FRM_Client_FirmataDevice($hash); if (defined (my $firmata = $hash->{FirmataDevice})) {
COMMANDHANDLER: { COMMANDHANDLER: {
$package->{direction} eq "i2cwrite" and do { $package->{direction} eq "i2cwrite" and do {
$firmata->i2c_write($package->{i2caddress},split(" ",$package->{data})); $firmata->i2c_write($package->{i2caddress},split(" ",$package->{data}));
last; last;
}; };
$package->{direction} eq "i2cread" and do { $package->{direction} eq "i2cread" and do {
if (defined $package->{reg}) { if (defined $package->{reg}) {
$firmata->i2c_readonce($package->{i2caddress},$package->{reg},defined $package->{nbyte} ? $package->{nbyte} : 1); $firmata->i2c_readonce($package->{i2caddress},$package->{reg},defined $package->{nbyte} ? $package->{nbyte} : 1);
} else { } else {
$firmata->i2c_readonce($package->{i2caddress},defined $package->{nbyte} ? $package->{nbyte} : 1); $firmata->i2c_readonce($package->{i2caddress},defined $package->{nbyte} ? $package->{nbyte} : 1);
} }
last; last;
}; };
} }
}
} }
sub sub
@ -713,45 +714,42 @@ sub FRM_i2c_update_device
sub FRM_string_observer sub FRM_string_observer
{ {
my ($string,$hash) = @_; my ($string,$hash) = @_;
Log3 $hash->{NAME},4,"received String_data: ".$string; Log3 $hash->{NAME},3,"received String_data: ".$string;
readingsSingleUpdate($hash,"error",$string,1); readingsSingleUpdate($hash,"error",$string,1);
} }
sub FRM_poll sub FRM_poll
{ {
my ($hash) = @_; my ($hash) = @_;
eval { if (defined $hash->{SocketDevice} and defined $hash->{SocketDevice}->{FD}) {
if (defined $hash->{SocketDevice} and defined $hash->{SocketDevice}->{FD}) { my ($rout, $rin) = ('', '');
my ($rout, $rin) = ('', ''); vec($rin, $hash->{SocketDevice}->{FD}, 1) = 1;
vec($rin, $hash->{SocketDevice}->{FD}, 1) = 1; my $nfound = select($rout=$rin, undef, undef, 0.1);
my $nfound = select($rout=$rin, undef, undef, 0.1); my $mfound = vec($rout, $hash->{SocketDevice}->{FD}, 1);
my $mfound = vec($rout, $hash->{SocketDevice}->{FD}, 1); if($mfound && defined $hash->{FirmataDevice}) {
if($mfound && defined $hash->{FirmataDevice}) { $hash->{FirmataDevice}->poll();
$hash->{FirmataDevice}->poll(); }
} return $mfound;
return $mfound; } elsif (defined $hash->{FD}) {
} elsif (defined $hash->{FD}) { my ($rout, $rin) = ('', '');
my ($rout, $rin) = ('', ''); vec($rin, $hash->{FD}, 1) = 1;
vec($rin, $hash->{FD}, 1) = 1; my $nfound = select($rout=$rin, undef, undef, 0.1);
my $nfound = select($rout=$rin, undef, undef, 0.1); my $mfound = vec($rout, $hash->{FD}, 1);
my $mfound = vec($rout, $hash->{FD}, 1); if($mfound && defined $hash->{FirmataDevice}) {
if($mfound && defined $hash->{FirmataDevice}) { $hash->{FirmataDevice}->poll();
$hash->{FirmataDevice}->poll(); }
} return $mfound;
return $mfound; } else {
} else { # This is relevant for windows/USB only
# This is relevant for windows/USB only my $po = $hash->{USBDev};
my $po = $hash->{USBDev}; my ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags);
my ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags); if($po) {
if($po) { ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags) = $po->status;
($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags) = $po->status; }
} if ($InBytes && $InBytes>0 && defined $hash->{FirmataDevice}) {
if ($InBytes && $InBytes>0 && defined $hash->{FirmataDevice}) { $hash->{FirmataDevice}->poll();
$hash->{FirmataDevice}->poll(); }
} }
}
};
Log3 $hash->{NAME},4,"FRM_poll: ".FRM_Catch($@) if ($@);
} }
######### following is code to be called from OWX: ########## ######### following is code to be called from OWX: ##########
@ -854,106 +852,105 @@ sub FRM_OWX_Verify {
} }
sub FRM_OWX_Alarms { sub FRM_OWX_Alarms {
my ($hash) = @_; my ($hash) = @_;
eval { #-- get the interface
my $firmata = FRM_Client_FirmataDevice($hash); my $frm = $hash->{IODev};
my $pin = $hash->{PIN}; return 0 unless defined $frm;
return 0 unless ( defined $firmata and defined $pin ); my $firmata = $frm->{FirmataDevice};
$hash->{ALARMDEVS} = undef; my $pin = $hash->{PIN};
$firmata->onewire_search_alarms($hash->{PIN}); return 0 unless ( defined $firmata and defined $pin );
my $times = AttrVal($hash,"ow-read-timeout",1000) / 50; #timeout in ms, defaults to 1 sec $hash->{ALARMDEVS} = undef;
for (my $i=0;$i<$times;$i++) { $firmata->onewire_search_alarms($hash->{PIN});
if (FRM_poll($hash->{IODev})) { my $times = AttrVal($hash,"ow-read-timeout",1000) / 50; #timeout in ms, defaults to 1 sec
if (defined $hash->{ALARMDEVS}) { for (my $i=0;$i<$times;$i++) {
return 1; if (FRM_poll($hash->{IODev})) {
} if (defined $hash->{ALARMDEVS}) {
} else { return 1;
select (undef,undef,undef,0.05); }
} } else {
} select (undef,undef,undef,0.05);
$hash->{ALARMDEVS} = []; }
return 1; }
}; $hash->{ALARMDEVS} = [];
Log3 $hash->{NAME},4,"FRM_OWX_Alarms:".FRM_Catch($@) if ($@); return 1;
return 0;
} }
sub FRM_OWX_Reset { sub FRM_OWX_Reset {
my ($hash) = @_; my ($hash) = @_;
eval { #-- get the interface
my $firmata = FRM_Client_FirmataDevice($hash); my $frm = $hash->{IODev};
my $pin = $hash->{PIN}; return undef unless defined $frm;
return undef unless ( defined $firmata and defined $pin ); my $firmata = $frm->{FirmataDevice};
my $pin = $hash->{PIN};
return undef unless ( defined $firmata and defined $pin );
$firmata->onewire_reset($pin); $firmata->onewire_reset($pin);
return 1;
}; return 1;
Log3 $hash->{NAME},4,"FRM_OWX_Reset:".FRM_Catch($@) if ($@);
return 0;
} }
sub FRM_OWX_Complex ($$$$) { sub FRM_OWX_Complex ($$$$) {
my ( $hash, $owx_dev, $data, $numread ) = @_; my ( $hash, $owx_dev, $data, $numread ) = @_;
my $res = ""; my $res = "";
eval { #-- get the interface
my $firmata = FRM_Client_FirmataDevice($hash); my $frm = $hash->{IODev};
my $pin = $hash->{PIN}; return 0 unless defined $frm;
return 0 unless ( defined $firmata and defined $pin ); my $firmata = $frm->{FirmataDevice};
my $pin = $hash->{PIN};
return 0 unless ( defined $firmata and defined $pin );
my $ow_command = {}; my $ow_command = {};
#-- has match ROM part #-- has match ROM part
if ($owx_dev) { if ($owx_dev) {
$ow_command->{"select"} = FRM_OWX_device_to_firmata($owx_dev); $ow_command->{"select"} = FRM_OWX_device_to_firmata($owx_dev);
#-- padding first 9 bytes into result string, since we have this #-- padding first 9 bytes into result string, since we have this
# in the serial interfaces as well # in the serial interfaces as well
$res .= "000000000"; $res .= "000000000";
} }
#-- has data part #-- has data part
if ($data) { if ($data) {
my @data = unpack "C*", $data; my @data = unpack "C*", $data;
$ow_command->{"write"} = \@data; $ow_command->{"write"} = \@data;
$res.=$data; $res.=$data;
} }
#-- has receive part
if ( $numread > 0 ) {
$ow_command->{"read"} = $numread;
#Firmata sends 0-address on read after skip
$owx_dev = '00.000000000000.00' unless defined $owx_dev;
my $id = $hash->{FRM_OWX_CORRELATIONID};
$ow_command->{"id"} = $hash->{FRM_OWX_CORRELATIONID};
$hash->{FRM_OWX_REQUESTS}->{$id} = {
command => $ow_command,
device => $owx_dev
};
delete $hash->{FRM_OWX_REPLIES}->{$owx_dev};
$hash->{FRM_OWX_CORRELATIONID} = ($id + 1) & 0xFFFF;
}
$firmata->onewire_command_series( $pin, $ow_command ); #-- has receive part
if ( $numread > 0 ) {
if ($numread) { $ow_command->{"read"} = $numread;
my $times = AttrVal($hash,"ow-read-timeout",1000) / 50; #timeout in ms, defaults to 1 sec #Firmata sends 0-address on read after skip
for (my $i=0;$i<$times;$i++) { $owx_dev = '00.000000000000.00' unless defined $owx_dev;
if (FRM_poll($hash->{IODev})) { my $id = $hash->{FRM_OWX_CORRELATIONID};
if (defined $hash->{FRM_OWX_REPLIES}->{$owx_dev}) { $ow_command->{"id"} = $hash->{FRM_OWX_CORRELATIONID};
$res .= $hash->{FRM_OWX_REPLIES}->{$owx_dev}; $hash->{FRM_OWX_REQUESTS}->{$id} = {
return $res; command => $ow_command,
} device => $owx_dev
} else { };
select (undef,undef,undef,0.05); delete $hash->{FRM_OWX_REPLIES}->{$owx_dev};
} $hash->{FRM_OWX_CORRELATIONID} = ($id + 1) & 0xFFFF;
} }
}
}; $firmata->onewire_command_series( $pin, $ow_command );
Log3 $hash->{NAME},4,"FRM_OWX_Complex:".FRM_Catch($@) if ($@);
return $res; if ($numread) {
my $times = AttrVal($hash,"ow-read-timeout",1000) / 50; #timeout in ms, defaults to 1 sec
for (my $i=0;$i<$times;$i++) {
if (FRM_poll($hash->{IODev})) {
if (defined $hash->{FRM_OWX_REPLIES}->{$owx_dev}) {
$res .= $hash->{FRM_OWX_REPLIES}->{$owx_dev};
return $res;
}
} else {
select (undef,undef,undef,0.05);
}
}
}
return $res;
} }
######################################################################################## ########################################################################################
@ -971,28 +968,27 @@ sub FRM_OWX_Discover ($) {
my ($hash) = @_; my ($hash) = @_;
eval { #-- get the interface
my $firmata = FRM_Client_FirmataDevice($hash); my $frm = $hash->{IODev};
my $pin = $hash->{PIN}; return 0 unless defined $frm;
return 0 unless ( defined $firmata and defined $pin ); my $firmata = $frm->{FirmataDevice};
my $old_devices = $hash->{DEVS}; my $pin = $hash->{PIN};
$hash->{DEVS} = undef; return 0 unless ( defined $firmata and defined $pin );
$firmata->onewire_search($hash->{PIN}); my $old_devices = $hash->{DEVS};
my $times = AttrVal($hash,"ow-read-timeout",1000) / 50; #timeout in ms, defaults to 1 sec $hash->{DEVS} = undef;
for (my $i=0;$i<$times;$i++) { $firmata->onewire_search($hash->{PIN});
if (FRM_poll($hash->{IODev})) { my $times = AttrVal($hash,"ow-read-timeout",1000) / 50; #timeout in ms, defaults to 1 sec
if (defined $hash->{DEVS}) { for (my $i=0;$i<$times;$i++) {
return 1; if (FRM_poll($hash->{IODev})) {
} if (defined $hash->{DEVS}) {
} else { return 1;
select (undef,undef,undef,0.05); }
} } else {
} select (undef,undef,undef,0.05);
$hash->{DEVS} = $old_devices; }
return 1; }
}; $hash->{DEVS} = $old_devices;
Log3 $hash->{NAME},4,"FRM_OWX_Discover:".FRM_Catch($@) if ($@); return 1;
return 0;
} }
1; 1;