2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-21 20:06:18 +00:00

added RFXX10REC. Error handling for serial port init.

git-svn-id: https://svn.fhem.de/fhem/trunk@826 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
wherzig 2011-02-05 20:23:41 +00:00
parent d741807b02
commit 805a00c61b

View File

@ -64,13 +64,12 @@ RFXCOM_Initialize($)
# Provider # Provider
$hash->{ReadFn} = "RFXCOM_Read"; $hash->{ReadFn} = "RFXCOM_Read";
$hash->{Clients} = $hash->{Clients} =
#":RFXMETER:OREGON:RFXELSE:"; ":RFXMETER:OREGON:RFXX10REC:RFXELSE:";
":RFXMETER:OREGON:";
my %mc = ( my %mc = (
"1:RFXMETER" => "^0.*", "1:RFXMETER" => "^0.*",
"2:OREGON" => "^[^0]", "2:OREGON" => "^[\x38-\x78].*",
#"2:OREGON" => "^[\x38-\x78].*", "3:RFXX10REC" => "^(\\ |\\)).*", # 0x20 or 0x29
#"3:RFXELSE" => "^.*", "4:RFXELSE" => "^.*",
); );
$hash->{MatchList} = \%mc; $hash->{MatchList} = \%mc;
@ -222,6 +221,7 @@ RFXCOM_DoInit($)
my $err; my $err;
my $msg = undef; my $msg = undef;
my $buf; my $buf;
my $char = undef ;
RFXCOM_Clear($hash); RFXCOM_Clear($hash);
@ -243,7 +243,7 @@ RFXCOM_DoInit($)
sleep(1); sleep(1);
$buf = RFXCOM_SimpleRead($hash); $buf = RFXCOM_SimpleRead($hash);
my $char = ord($buf); if (defined($buf)) { $char = ord($buf); }
if (! $buf) { if (! $buf) {
return "RFXCOM: Initialization Error $name: no char read"; return "RFXCOM: Initialization Error $name: no char read";
} elsif ($char ne 0x2c) { } elsif ($char ne 0x2c) {
@ -319,16 +319,23 @@ RFXCOM_Parse($$$$)
Log 5, "RFXCOM_Parse1 '$hexline'"; Log 5, "RFXCOM_Parse1 '$hexline'";
my %addvals; my %addvals;
# Parse only if message is different within 2 seconds (some Oregon sensors always sends the message twice # Parse only if message is different within 2 seconds
if (("$last_rmsg" ne "$rmsg") || (time()-1) > $last_time) { Dispatch($hash, $rmsg, \%addvals); } # (some Oregon sensors always sends the message twice, X10 security sensors even sends the message five times)
#if ("$last_rmsg" ne "$rmsg") { Dispatch($hash, $rmsg, \%addvals); } if (("$last_rmsg" ne "$rmsg") || (time() - $last_time) > 1) {
Log 5, "RFXCOM_Dispatch '$hexline'";
#Log 1, "RFXCOM_Dispatch '$hexline'";
Dispatch($hash, $rmsg, \%addvals);
$hash->{"${name}_MSGCNT"}++;
$hash->{"${name}_TIME"} = TimeNow();
$hash->{RAWMSG} = $rmsg;
} else {
#Log 1, "RFXCOM_Dispatch '$hexline' dup";
#Log 1, "<-duplicate->";
}
$last_rmsg = $rmsg; $last_rmsg = $rmsg;
$last_time = time(); $last_time = time();
$hash->{"${name}_MSGCNT"}++;
$hash->{"${name}_TIME"} = TimeNow();
$hash->{RAWMSG} = $rmsg;
#$hexline = unpack('H*', $rmsg); #$hexline = unpack('H*', $rmsg);
#Log 1, "RFXCOM_Parse2 '$hexline'"; #Log 1, "RFXCOM_Parse2 '$hexline'";
@ -376,14 +383,10 @@ RFXCOM_SimpleRead($)
$buf = $hash->{USBDev}->read(1) ; $buf = $hash->{USBDev}->read(1) ;
#my $hexline = unpack('H*', $buf); #my $hexline = unpack('H*', $buf);
#Log 1, "RFXCOM: RFXCOM_SimpleRead1 '$hexline'"; #Log 1, "RFXCOM: RFXCOM_SimpleRead1 '$hexline'";
#if (length($buf) == 0) { $buf = $hash->{USBDev}->read(1) ; } if (!defined($buf) || length($buf) == 0) {
if (length($buf) == 0) {
#sleep(1); #sleep(1);
$buf = $hash->{USBDev}->read(1) ; $buf = $hash->{USBDev}->read(1) ;
}
#my $hexline = unpack('H*', $buf);
#Log 1, "RFXCOM: RFXCOM_SimpleRead2 '$hexline'";
}
return $buf; return $buf;
} }
@ -409,6 +412,7 @@ RFXCOM_CloseDev($)
return if(!$dev); return if(!$dev);
Log 1, "RFXCOM: closing $dev";
if($hash->{TCPDev}) { if($hash->{TCPDev}) {
$hash->{TCPDev}->close(); $hash->{TCPDev}->close();
delete($hash->{TCPDev}); delete($hash->{TCPDev});
@ -470,9 +474,9 @@ RFXCOM_OpenDev($$)
require Win32::SerialPort; require Win32::SerialPort;
$po = new Win32::SerialPort ($dev); $po = new Win32::SerialPort ($dev);
} else { } else {
#Log(1, "RFXCOM: new Device");
require Device::SerialPort; require Device::SerialPort;
#$po = new Device::SerialPort ($dev); $po = new Device::SerialPort ($dev);
$po = Device::SerialPort->new($dev);
} }
if(!$po) { if(!$po) {
@ -491,16 +495,22 @@ RFXCOM_OpenDev($$)
$selectlist{"$name.$dev"} = $hash; $selectlist{"$name.$dev"} = $hash;
} }
$po->databits(8); #$po->reset_error || Log 1, "RFXCOM reset_error";
$po->baudrate(4800); $po->databits(8) || Log 1, "RFXCOM could not set databits";
$po->parity('none'); $po->baudrate(4800) || Log 1, "RFXCOM could not set baudrate";
$po->stopbits(1); $po->parity('none') || Log 1, "RFXCOM could not set parity";
$po->handshake('none'); $po->stopbits(1) || Log 1, "RFXCOM could not set stopbits";
$po->reset_error(); $po->handshake('none') || Log 1, "RFXCOM could not set handshake";
$po->lookclear; # clear buffers $po->datatype('raw') || Log 1, "RFXCOM could not set datatype";
#$po->lookclear || Log 1, "RFXCOM could not set lookclear";
$po->write_settings || Log 1, "RFXCOM could not write_settings $dev";
$hash->{po} = $po;
$hash->{socket} = 0;
Log 1, "RFXCOM: RFXCOM_OpenDev $dev done"; Log 1, "RFXCOM: RFXCOM_OpenDev $dev done";
} }
if($reopen) { if($reopen) {