| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
1
|
|
|
1
|
|
8214
|
use strict; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
45
|
|
|
2
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
64
|
|
|
3
|
|
|
|
|
|
|
package AnyEvent::RFXCOM::TX; |
|
4
|
|
|
|
|
|
|
$AnyEvent::RFXCOM::TX::VERSION = '1.142240'; |
|
5
|
|
|
|
|
|
|
# ABSTRACT: AnyEvent module for an RFXCOM transmitter |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
27
|
use 5.008; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
47
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use constant DEBUG => $ENV{ANYEVENT_RFXCOM_TX_DEBUG}; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
83
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use base qw/AnyEvent::RFXCOM::Base Device::RFXCOM::TX/; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
916
|
|
|
11
|
1
|
|
|
1
|
|
66947
|
use AnyEvent; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
35
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use Carp qw/croak/; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
64
|
|
|
13
|
1
|
|
|
1
|
|
6
|
use Sub::Name; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
47
|
|
|
14
|
1
|
|
|
1
|
|
5
|
use Scalar::Util qw/weaken/; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
723
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _handle_setup { |
|
18
|
2
|
|
|
2
|
|
4
|
my $self = shift; |
|
19
|
2
|
|
|
|
|
8
|
my $handle = $self->{handle}; |
|
20
|
2
|
|
|
|
|
3
|
my $weak_self = $self; |
|
21
|
2
|
|
|
|
|
14
|
weaken $weak_self; |
|
22
|
|
|
|
|
|
|
$handle->on_rtimeout(subname 'on_rtimeout_cb' => sub { |
|
23
|
0
|
|
|
0
|
|
0
|
my ($handle) = @_; |
|
24
|
0
|
|
|
|
|
0
|
print STDERR $handle.": no ack\n" if DEBUG; |
|
25
|
0
|
|
|
|
|
0
|
$handle->rtimeout(0); |
|
26
|
0
|
|
|
|
|
0
|
$weak_self->_init_mode(); |
|
27
|
2
|
|
|
|
|
27
|
}); |
|
28
|
|
|
|
|
|
|
$handle->on_drain(subname 'on_drain_cb' => sub { |
|
29
|
18
|
|
|
18
|
|
1075
|
my ($handle) = @_; |
|
30
|
18
|
50
|
|
|
|
56
|
return unless (defined $handle); |
|
31
|
18
|
|
|
|
|
23
|
print STDERR $handle.": on drain\n" if DEBUG; |
|
32
|
18
|
|
|
|
|
75
|
$handle->rtimeout_reset(); |
|
33
|
18
|
|
|
|
|
118
|
$handle->rtimeout($weak_self->{ack_timeout}); |
|
34
|
2
|
|
|
|
|
32
|
}); |
|
35
|
|
|
|
|
|
|
$handle->on_read(subname 'on_read_cb' => sub { |
|
36
|
16
|
|
|
16
|
|
23470
|
my ($handle) = @_; |
|
37
|
16
|
|
|
|
|
57
|
$handle->rtimeout(0); |
|
38
|
16
|
|
|
|
|
281
|
my $rbuf = \$handle->{rbuf}; |
|
39
|
16
|
|
|
|
|
31
|
my $data = $$rbuf; |
|
40
|
16
|
|
|
|
|
23
|
$$rbuf = ''; |
|
41
|
16
|
50
|
|
|
|
82
|
$weak_self->{callback}->($data) if ($weak_self->{callback}); |
|
42
|
16
|
|
|
|
|
140
|
print STDERR $handle.": read ", (unpack 'H*', $data), "\n" if DEBUG; |
|
43
|
16
|
|
|
|
|
33
|
my $wait_record = $weak_self->{_waiting}; |
|
44
|
16
|
50
|
|
|
|
47
|
if ($wait_record) { |
|
45
|
16
|
|
|
|
|
27
|
my ($time, $rec) = @$wait_record; |
|
46
|
16
|
|
|
|
|
25
|
push @{$rec->{result}}, $data; |
|
|
16
|
|
|
|
|
50
|
|
|
47
|
16
|
|
|
|
|
26
|
my $cv = $rec->{cv}; |
|
48
|
16
|
100
|
|
|
|
65
|
$cv->end if ($cv); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
16
|
|
|
|
|
162
|
$weak_self->_write_now(); |
|
51
|
16
|
|
|
|
|
194
|
return; |
|
52
|
2
|
|
|
|
|
114
|
}); |
|
53
|
2
|
|
|
|
|
109
|
1; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub transmit { |
|
57
|
9
|
|
|
9
|
1
|
11313
|
my $self = shift; |
|
58
|
9
|
|
|
|
|
245
|
my $cv = AnyEvent->condvar; |
|
59
|
9
|
|
|
|
|
62
|
my $res = []; |
|
60
|
9
|
|
|
|
|
15
|
my $weak_cv = $cv; |
|
61
|
9
|
|
|
|
|
31
|
weaken $weak_cv; |
|
62
|
9
|
|
|
7
|
|
114
|
$cv->cb(subname 'transmit_cb' => sub { $weak_cv->send($res->[0]) }); |
|
|
7
|
|
|
|
|
127
|
|
|
63
|
9
|
|
|
|
|
127
|
$self->SUPER::transmit(args => [ cv => $cv, result => $res ], @_); |
|
64
|
8
|
|
|
|
|
508
|
return $cv; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _open { |
|
68
|
2
|
|
|
2
|
|
16411
|
my $self = shift; |
|
69
|
2
|
|
|
|
|
23
|
$self->SUPER::_open($self->_open_condvar); |
|
70
|
2
|
|
|
|
|
7
|
return 1; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _open_serial_port { |
|
74
|
0
|
|
|
0
|
|
0
|
my ($self, $cv) = @_; |
|
75
|
0
|
|
|
|
|
0
|
my $fh = $self->SUPER::_open_serial_port; |
|
76
|
0
|
|
|
|
|
0
|
$cv->send($fh); |
|
77
|
0
|
|
|
|
|
0
|
return $cv; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub DESTROY { |
|
81
|
2
|
|
|
2
|
|
4242
|
$_[0]->cleanup; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub cleanup { |
|
86
|
2
|
|
|
2
|
1
|
7
|
my ($self, $error) = @_; |
|
87
|
2
|
|
|
|
|
22
|
$self->SUPER::cleanup(@_); |
|
88
|
2
|
|
|
|
|
7
|
undef $self->{discard_timer}; |
|
89
|
2
|
|
|
|
|
64
|
undef $self->{dup_timer}; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |