RFXCOM/Decoder/X10.pm

filter: Statementstmt 100% 60 / 60 Branchbran 100% 18 / 18 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 11 / 11 Podpod 100% 4 / 4 totaltotal 100% 103 / 103 SCAR 24.8
CC
12
Cov
100%
decode
6.0
from_rf
4.0
is_x10
4.0
CRAP 12.0
« RFXCOM/Decoder/Visonic.pm ↑ Summary RFXCOM/Encoder/HomeEasy.pm »
1 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Device::RFXCOM::Decoder::X10;
4 4 $Device::RFXCOM::Decoder::X10::VERSION = '1.142010';
5 # ABSTRACT: Device::RFXCOM::Decoder::X10 decode X10 RF messages
6  
7  
8 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use constant DEBUG => $ENV{DEVICE_RFXCOM_DECODER_X10_DEBUG};
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use base 'Device::RFXCOM::Decoder';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Device::RFXCOM::Response::X10;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 sub new {
16 8 ▶ my $pkg = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
17 8 $pkg->SUPER::new(unit_cache => {}, default_x10_level => 10, @_);
18 }
19  
20  
21 sub decode {
22 41 ▶ my ($self, $parent, $message, $bytes, $bits, $result) = @_;
Subroutine decode: called CC=6 SCAR=17.9
Pod documented
23 41 ▶ my $res = from_rf($bytes) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $res = from_rf($bytes) or return 34 7 41
24 7 my $h = $res->{house};
25 7 my $f = $res->{command};
26 7 ▶ $self->{unit_cache}->{$h} = $res->{unit} if (exists $res->{unit});
Branch: 1 branch
BranchTrueFalseTotal
if exists $res->{"unit"} 4 3 7
27 7 my %r =
28 (
29 command => $f,
30 );
31 7 my $u = $self->{unit_cache}->{$h};
32 7 my $dont_cache;
33 7 ▶ if (defined $u) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $u) { } 6 1 7
34 6 $r{device} = $h.$u;
35 } else {
36 1 warn "Don't have unit code for: $h $f\n";
37 1 $result->{dont_cache} = 1;
38 1 $r{house} = $h;
39 }
40 7 ▶ if ($f eq 'bright' or $f eq 'dim') {
Branch: 1 branch
BranchTrueFalseTotal
if ($f eq "bright" or $f eq "dim") 3 4 7
Condition100%3/3
$f eq "bright" or $f eq "dim"
l!l&&r!l&&!r
124
MC/DC100%2/2
$f eq "bright" or $f eq "dim"
$f eq "bright" $f eq "dim"
Truth table100%3/3
A or B
A= $f eq "bright"B= $f eq "dim"
ABresult
1X1
011
000
41 3 $r{level} = $self->{default_x10_level};
42 }
43 7 push @{$result->{messages}}, Device::RFXCOM::Response::X10->new(%r);
44 7 return 1;
45 }
46  
47 4 my %byte_to_house =
48 (
49 '6' => 'a', '7' => 'b', '4' => 'c', '5' => 'd', '8' => 'e', '9' => 'f',
50 '10' => 'g', '11' => 'h', '14' => 'i', '15' => 'j', '12' => 'k',
51 '13' => 'l', '0' => 'm', '1' => 'n', '2' => 'o', '3' => 'p',
52 );
53  
54 4 my %byte_to_unit =
55 (
56 0x00 => 1, 0x10 => 2, 0x08 => 3, 0x18 => 4, 0x40 => 5, 0x50 => 6,
57 0x48 => 7, 0x58 => 8
58 );
59 4 my $unit_mask= 0x58;
60  
61 4 my %byte_to_command =
62 (
63 0x0 => 'on',
64 0x20 => 'off',
65 0x80 => 'all_lights_off',
66 0x88 => 'bright',
67 0x90 => 'all_lights_on',
68 0x98 => 'dim',
69 );
70  
71  
72 sub from_rf {
73 41 ▶ my $bytes = shift;
Subroutine from_rf: called CC=4 SCAR=13.9
Pod documented
74  
75 41 ▶ return unless (is_x10($bytes));
Branch: 1 branch
BranchTrueFalseTotal
unless is_x10($bytes) 34 7 41
76 7 my %r = ();
77 7 my $mask = 0x98;
78 7 ▶ unless ($bytes->[2]&0x80) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($bytes->[2] & 128) 4 3 7
79 4 $r{unit} = $byte_to_unit{$bytes->[2]&$unit_mask};
80 4 ▶ $r{unit} += 8 if ($bytes->[0]&0x4);
Branch: 1 branch
BranchTrueFalseTotal
if $bytes->[0] & 4 2 2 4
81 4 $mask = 0x20;
82 }
83 7 $r{house} = $byte_to_house{($bytes->[0]&0xf0)>>4};
84 7 $r{command} = $byte_to_command{$bytes->[2]&$mask};
85 7 return \%r;
86 }
87  
88  
89 sub is_x10 {
90 41 ▶ my $bytes = shift;
Subroutine is_x10: called CC=4 SCAR=13.9
Pod documented
91  
92 41 ▶ return unless (scalar @$bytes == 4);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$bytes == 4 26 15 41
93  
94 15 ▶ (($bytes->[2]^0xff) == $bytes->[3] &&
Branch: 1 branch
BranchTrueFalseTotal
($bytes->[2] ^ 255) == $bytes->[3] and ($bytes->[0] ^ 255) == $bytes->[1] and not $bytes->[2] & 7 7 8 15
Condition100%3/3
($bytes->[2] ^ 255) == $bytes->[3] and ($bytes->[0] ^ 255) == $bytes->[1]
!ll&&!rl&&r
537
MC/DC100%2/2
($bytes->[2] ^ 255) == $bytes->[3] and ($bytes->[0] ^ 255) == $bytes->[1]
($bytes->[2] ^ 255) == $bytes->[3] ($bytes->[0] ^ 255) == $bytes->[1]
Truth table100%3/3
A and B
A= ($bytes->[2] ^ 255) == $bytes->[3]B= ($bytes->[0] ^ 255) == $bytes->[1]
ABresult
0X0
100
111
95 ($bytes->[0]^0xff) == $bytes->[1] &&
96 !($bytes->[2]&0x7));
97 }
98  
99 4 1;
100  
101 __END__
« RFXCOM/Decoder/Visonic.pm ↑ Summary RFXCOM/Encoder/HomeEasy.pm »