ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/RCU/Irman/Irman.pm
Revision: 1.1
Committed: Sun Nov 6 17:17:37 2005 UTC (18 years, 8 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 =head1 NAME
2    
3     RCU::Irman - RCU interface to libirman.
4    
5     =head1 SYNOPSIS
6    
7     use RCU::Irman;
8    
9     =head1 DESCRIPTION
10    
11     See L<RCU>.
12    
13     =over 4
14    
15     =cut
16    
17     package RCU::Irman;
18    
19     use Carp;
20     use Errno ();
21     use Fcntl;
22    
23     use RCU;
24    
25     use base qw(RCU::Interface);
26    
27     $VERSION = 0.11;
28    
29     =item new <path>
30    
31     Create an interface to the RCU receiver at serial port <path> (default
32     from in irman.conf used if omitted).
33    
34     =cut
35    
36     sub new {
37     my $class = shift;
38     my $path = shift;
39     my $self = $class->SUPER::new();
40     local (*CW, *CR);
41    
42     $self->{fh} = local *IRMAN_FH;
43     $self->{ifh} = local *IRMAN_IFH;
44    
45     pipe $self->{fh}, CW or die "unable to create communications pipe";
46     pipe CR, $self->{ifh} or die "unable to create communications pipe";
47    
48     $self->{pid} = fork;
49    
50     if ($self->{pid} == 0) {
51     use Config;
52     close $self->{ifh}; close $self->{fh};
53     open STDIN, "<&CR"; open STDOUT, ">&CW"; close STDERR;
54     fcntl STDIN, F_SETFD, 0; fcntl STDOUT, F_SETFD, 0;
55     exec "$Config{installbin}/rcu-irman-helper", "", $path || "";
56     } elsif (!defined $self->{pid}) {
57     die;
58     }
59     close CR; close CW;
60    
61     $self->get; # wait for I packet
62    
63     $self;
64     }
65    
66     sub fd {
67     fileno $_[0]->{fh};
68     }
69    
70     sub _get {
71     my $self = shift;
72     my $fh = $self->{fh};
73     local $/ = "\x00";
74     $! = 0;
75     my $code = <$fh>;
76     if ("=" eq substr $code, 0, 1) {
77     split /\x01/, substr $code, 1, -1;
78     } elsif ($code =~ s/^E//) {
79     die substr $code, 0, -1;
80     } elsif ($code =~ /^I/) {
81     # NOP
82     ();
83     } elsif ($! != Errno::EAGAIN) {
84     delete $self->{fh}; # to make event stop
85     croak "irman communication error ($!)";
86     } else {
87     ();
88     }
89     }
90    
91     sub get {
92     fcntl $_[0]->{fh}, F_SETFL, 0;
93     goto &_get;
94     }
95    
96     sub poll {
97     fcntl $_[0]->{fh}, F_SETFL, O_NONBLOCK;
98     goto &_get;
99     }
100    
101     1;
102    
103     =back
104    
105     =head1 AUTHOR
106    
107     This perl extension was written by Marc Lehmann <schmorp@schmorp.de>.
108    
109    
110    
111    
112