Skip to content

Commit

Permalink
Added code to open CMxx fifo if it didn't work at startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcmerlin committed Jul 23, 2011
1 parent c34e16e commit 6703d0a
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions lib/X10_CMxx.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ program, mochad, which writes it to a fifo which this module reads.
1) Download and install mochad: http://sourceforge.net/projects/mochad/
Make sure that your version supports the --raw-data option
(mochad 0.1.12 or better will be fine) and see the README.
Make sure that your version supports the --raw-data option.
If your mochad is too old (or a version newer than 0.1.7 has not been
released yet), apply this patch to mochad: X10_CMxx_mochad-0.1.7.diff
and see the README.
2) Use these mh.ini parameters to enable this code:
Expand Down Expand Up @@ -48,6 +50,7 @@ use X10_RF;
@X10_CMxx::ISA = ('Generic_Item');

my $fifo;
my $fifo_opened = 0;

sub open_fifo {
close(X10_CMxx);
Expand All @@ -67,12 +70,13 @@ sub startup {
sleep 5;
return;
}
if (not open_fifo()) {
warn ">>>>> Can't open fifo $fifo: $!. Disabling X10_CMxx module <<<<<\n";
if (not open_fifo()) {
&::print_log(">>>>> CMxx: still can't open fifo $fifo: $!. Will try again later <<<<<<");
sleep 5;
} else {
&::MainLoop_pre_add_hook( \&X10_CMxx::check_for_data, 1 );
$fifo_opened = 1;
}
&::MainLoop_pre_add_hook( \&X10_CMxx::check_for_data, 1 );
}

my ($prev_bad_checksums);
Expand All @@ -84,8 +88,18 @@ sub check_for_data {

my $buffer;
my $buffersize = 65536;
my $rv = sysread(X10_CMxx, $buffer, $buffersize);
my $rv;

if (not $fifo_opened and &::new_minute()) {
&::print_log(">>>>> CMxx: has not yet opened $fifo. Trying again now <<<<<<");
if (not open_fifo()) {
&::print_log(">>>>> CMxx: still can't open fifo $fifo: $!. Will try again later <<<<<<");
} else {
$fifo_opened = 1;
}
}

$rv = sysread(X10_CMxx, $buffer, $buffersize);
# sysread returning undefined means fifo is ok, but no data received.
return if (not defined($rv));

Expand Down

0 comments on commit 6703d0a

Please sign in to comment.