RFXCOM/TX.pm

filter: Statementstmt 93.8% 76 / 81 Branchbran 73.0% 19 / 26 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 95.0% 19 / 20 Podpod 100% 8 / 8 totaltotal 89.1% 123 / 138 SCAR 28.6
CC
17
Cov
88%
transmit
6.0
wait_for_ack
5.7
_init
5.0
CRAP 17.5
« RFXCOM/Decoder/Oregon.pm ↑ Summary RFXCOM/Decoder/RFXSensor.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Device::RFXCOM::TX;
4 1 $Device::RFXCOM::TX::VERSION = '1.142010';
5 # ABSTRACT: Module to support an RFXCOM RF transmitter
6  
7  
8 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 use constant {
10 DEBUG => $ENV{DEVICE_RFXCOM_TX_DEBUG},
11 TESTING => $ENV{DEVICE_RFXCOM_TX_TESTING},
12 1 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use base 'Device::RFXCOM::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Carp qw/croak carp/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 use Module::Pluggable
18 1 search_path => 'Device::RFXCOM::Encoder',
19 1 ▶ instantiate => 'new';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21  
22 sub new {
23 4 ▶ my $pkg = shift;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
24 4 my $self = $pkg->SUPER::_new(device => '/dev/rfxcom-tx',
25 ack_timeout => 6,
26 receiver_connected => 0,
27 flamingo => 0,
28 harrison => 0,
29 koko => 0,
30 x10 => 1,
31 @_);
32 2 foreach my $plugin ($self->plugins()) {
33 4 my $p = lc ref $plugin;
34 4 $p =~ s/.*:://;
35 4 $self->{plugin_map}->{$p} = $plugin;
36 4 print STDERR "Initialized plugin for $p messages\n" if DEBUG;
37 }
38 2 $self;
39 }
40  
41  
42 2 ▶sub receiver_connected { shift->{receiver_connected} }
Subroutine receiver_connected: called CC=1 SCAR=0.0
Pod documented
43  
44  
45 2 ▶sub flamingo { shift->{flamingo} }
Subroutine flamingo: called CC=1 SCAR=0.0
Pod documented
46  
47  
48 2 ▶sub harrison { shift->{harrison} }
Subroutine harrison: called CC=1 SCAR=0.0
Pod documented
49  
50  
51 2 ▶sub koko { shift->{koko} }
Subroutine koko: called CC=1 SCAR=0.0
Pod documented
52  
53  
54 2 ▶sub x10 { shift->{x10} }
Subroutine x10: called CC=1 SCAR=0.0
Pod documented
55  
56 sub _init {
57 2 ▶ my $self = shift;
Subroutine _init: called CC=5 SCAR=16.1
58 2 $self->_write(hex => 'F030F030', desc => 'version check');
59 2 ▶ $self->_write(hex => 'F03CF03C', desc => 'enabling harrison')
Branch: 1 branch
BranchTrueFalseTotal
if $self->harrison 1 1 2
60 if ($self->harrison);
61 2 ▶ $self->_write(hex => 'F03DF03D', desc => 'enabling klikon-klikoff')
Branch: 1 branch
BranchTrueFalseTotal
if $self->koko 1 1 2
62 if ($self->koko);
63 2 ▶ $self->_write(hex => 'F03EF03E', desc => 'enabling flamingo')
Branch: 1 branch
BranchTrueFalseTotal
if $self->flamingo 1 1 2
64 if ($self->flamingo);
65 2 ▶ $self->_write(hex => 'F03FF03F', desc => 'disabling x10') unless ($self->x10);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->x10 1 1 2
66 2 $self->_init_mode($self->{init_callback});
67 2 $self->{init} = 1;
68 }
69  
70 sub _init_mode {
71 2 ▶ my ($self, $cb) = @_;
Subroutine _init_mode: called CC=3 SCAR=11.0
72 2 ▶ my @args =
Branch: 1 branch
BranchTrueFalseTotal
$self->receiver_connected ? : 1 1 2
73 $self->receiver_connected ?
74 (hex => 'F033F033',
75 desc => 'variable length mode w/receiver connected') :
76 (hex => 'F037F037',
77 desc=> 'variable length mode w/o receiver connected');
78 2 ▶ push @args, callback => $cb if ($cb);
Branch: 1 branch
BranchTrueFalseTotal
if $cb 2 0 2
79 2 $self->_write(@args);
80 }
81  
82 sub _reset_device {
83 0 ▶ my $self = shift;
Subroutine _reset_device: not called CC=1 SCAR=6.9
84 0 carp "No ack from transmitter!\n";
85 0 $self->init_device();
86 0 1;
87 }
88  
89  
90 sub transmit {
91 9 ▶ my ($self, %p) = @_;
Subroutine transmit: called CC=6 SCAR=18.0
Pod documented
92 9 ▶ my $type = $p{type} || 'x10';
Condition50%1/2
$p{'type'} || 'x10'
l!l
90
MC/DC0%0/1
$p{'type'} || 'x10'
$p{'type'}
Truth table50%1/2
A
A= $p{'type'}
Aresult
11
00
93 9 ▶ my @args = @{$p{args}||[]};
Branch: 1 branch
BranchTrueFalseTotal
$p{"args"} or [] 9 0 9
94 9 ▶ my $plugin = $self->{plugin_map}->{$type} or
Branch: 1 branch
BranchTrueFalseTotal
my $plugin = $self->{"plugin_map"}{$type} or croak($self, "->transmit: ", $type, " encoding not supported") 1 8 9
95 croak $self, '->transmit: ', $type, ' encoding not supported';
96 8 my $encode = $plugin->encode($self, \%p);
97 8 ▶ if (ref $encode eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $encode eq 'ARRAY') { } 4 4 8
98 4 foreach my $e (@$encode) {
99 4 $self->_write(%$e, @args);
100 }
101 4 return scalar @$encode;
102 } else {
103 4 $self->_write(%$encode, @args);
104 4 return 1;
105 }
106 }
107  
108  
109 sub wait_for_ack {
110 16 ▶ my ($self, $timeout) = @_;
Subroutine wait_for_ack: called CC=5 SCAR=17.4
Pod documented
111 16 ▶ $timeout = $self->{ack_timeout} unless (defined $timeout);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $timeout 16 0 16
112 16 my $fh = $self->filehandle;
113 16 my $sel = IO::Select->new($fh);
114 16 ▶ $sel->can_read($timeout) or return;
Branch: 1 branch
BranchTrueFalseTotal
$sel->can_read($timeout) or return 0 16 16
115 16 my $buf;
116 16 my $bytes = sysread $fh, $buf, 2048;
117 16 ▶ unless ($bytes) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($bytes) 0 16 16
118 0 ▶ croak defined $bytes ? 'closed' : 'error: '.$!;
Branch: 1 branch
BranchTrueFalseTotal
defined $bytes ? : 0 0 0
119 }
120 16 $self->_write_now();
121 16 print STDERR "Received: ", (unpack 'H*', $buf), "\n" if DEBUG;
122 16 return $buf;
123 }
124  
125 1 1;
126  
127 __END__
« RFXCOM/Decoder/Oregon.pm ↑ Summary RFXCOM/Decoder/RFXSensor.pm »