RFXCOM/Encoder/HomeEasy.pm

filter: Statementstmt 93.3% 56 / 60 Branchbran 85.7% 12 / 14 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 86.1% 81 / 94 SCAR 24.2
CC
11
Cov
88%
encode
8.8
encode_address
4.0
BEGIN
1.0
CRAP 11.2
« RFXCOM/Decoder/X10.pm ↑ Summary RFXCOM/Decoder/HomeEasy.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::Encoder::HomeEasy;
4 1 $Device::RFXCOM::Encoder::HomeEasy::VERSION = '1.142010';
5 # ABSTRACT: Device::RFXCOM::Encoder::HomeEasy encode HomeEasy RF messages
6  
7  
8 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use constant DEBUG => $ENV{DEVICE_RFXCOM_ENCODER_HOMEEASY_DEBUG};
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Carp qw/croak carp/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use base 'Device::RFXCOM::Encoder';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Device::RFXCOM::Response::HomeEasy;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 sub encode {
16 4 ▶ my ($self, $parent, $p) = @_;
Subroutine encode: called CC=8 SCAR=21.7
Pod documented
17 4 my @bytes = ( 0, 0, 0, 0, 0 );
18 4 my $length = 33;
19 4 my $command;
20  
21 4 ▶ unless (exists $p->{command} && exists $p->{unit} && exists $p->{address}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $p->{"command"} and exists $p->{"unit"} and exists $p->{"address"}) 0 4 4
Condition33%2/6
exists $p->{"command"} and exists $p->{"unit"} and exists $p->{"address"}
!ll&&!rl&&r
004
exists $p->{"command"} and exists $p->{"unit"}
!ll&&!rl&&r
004
MC/DC0%0/3
exists $p->{"command"} and exists $p->{"unit"} and exists $p->{"address"}
exists $p->{"command"} exists $p->{"unit"} exists $p->{"address"}
Truth table25%1/4
A and B and C
A= exists $p->{"command"}B= exists $p->{"unit"}C= exists $p->{"address"}
ABCresult
0XX0
10X0
1100
1111
22 0 carp $self.'->encode: Invalid homeeasy message';
23 0 return [];
24 }
25 4 ▶ if ($p->{command} eq 'preset') {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{'command'} eq 'preset') { } 1 3 4
26 1 ▶ unless (exists $p->{level}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $p->{"level"}) 0 1 1
27 0 carp $self.'->encode: Invalid homeeasy message';
28 0 return [];
29 }
30 1 $length = 36;
31 1 $bytes[4] = $p->{level} << 4;
32 1 $command = 0;
33 } else {
34 3 ▶ $command = $p->{command} eq 'on' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$p->{'command'} eq 'on' ? : 2 1 3
35 }
36 4 ▶ if ($p->{unit} eq 'group') {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{"unit"} eq "group") 1 3 4
37 1 $p->{unit} = 0;
38 1 $command |= 0x2;
39 }
40 4 my $addr = encode_address($p->{address});
41 4 $bytes[0] = $addr >> 18;
42 4 $bytes[1] = ($addr >> 10) & 0xff;
43 4 $bytes[2] = ($addr >> 2) & 0xff;
44 4 $bytes[3] = (($addr & 0x3) << 6);
45 4 $bytes[3] |= $p->{unit};
46 4 $bytes[3] |= ($command << 4);
47 return {
48 raw => (pack 'C6', $length, @bytes),
49 desc =>
50 'homeeasy: '.(join '/',
51 12 grep { defined $_
52 4 } @{$p}{qw/command address unit/})
53 },
54 }
55  
56  
57 sub encode_address {
58 4 ▶ my $addr = shift;
Subroutine encode_address: called CC=4 SCAR=13.9
Pod documented
59 4 ▶ return hex($addr) & 0x3ffffff if ($addr =~ /^0x[0-9a-f]{1,8}$/i);
Branch: 1 branch
BranchTrueFalseTotal
if $addr =~ /^0x[0-9a-f]{1,8}$/i 1 3 4
60 3 my $val = 0;
61 3 my $offset = 0;
62 3 foreach my $b (map { ord $_ } split //, $addr) {
63 15 $val ^= ($b&0x7f) << $offset;
64 15 $offset += 4;
65 15 ▶ $offset = 0 if ($offset > 20);
Branch: 1 branch
BranchTrueFalseTotal
if $offset > 20 1 14 15
66 }
67 3 return $val & 0x3ffffff;
68 }
69  
70 1 1;
71  
72 __END__
« RFXCOM/Decoder/X10.pm ↑ Summary RFXCOM/Decoder/HomeEasy.pm »