RFXCOM/Decoder/HomeEasy.pm

filter: Statementstmt 100% 54 / 54 Branchbran 100% 14 / 14 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 100% 84 / 84 SCAR 22.0
CC
9
Cov
100%
decode
6.0
from_rf
4.0
BEGIN
1.0
CRAP 9.0
« RFXCOM/Encoder/HomeEasy.pm ↑ Summary RFXCOM/Decoder/Electrisave.pm »
1 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Device::RFXCOM::Decoder::HomeEasy;
4 3 $Device::RFXCOM::Decoder::HomeEasy::VERSION = '1.142010';
5 # ABSTRACT: Device::RFXCOM::Decoder::HomeEasy decode HomeEasy RF messages
6  
7  
8 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use constant DEBUG => $ENV{DEVICE_RFXCOM_DECODER_HOMEEASY_DEBUG};
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use base 'Device::RFXCOM::Decoder';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Device::RFXCOM::Response::HomeEasy;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 sub decode {
16 81 ▶ my ($self, $parent, $message, $bytes, $bits, $result) = @_;
Subroutine decode: called CC=6 SCAR=17.9
Pod documented
17  
18 81 ▶ $bits == 34 or $bits == 38 or return;
Branch: 1 branch
BranchTrueFalseTotal
$bits == 34 or $bits == 38 or return 77 4 81
Condition100%3/3
$bits == 34 or $bits == 38
l!l&&r!l&&!r
3177
MC/DC100%2/2
$bits == 34 or $bits == 38
$bits == 34 $bits == 38
Truth table100%3/3
A or B
A= $bits == 34B= $bits == 38
ABresult
1X1
011
000
19  
20 # HomeEasy devices seem to send duplicates with different byte[4] high nibble
21 4 my @b = @{$bytes};
22 4 my $b4 = $b[4];
23 4 $b[4] &= 0xf;
24 4 ▶ if ($b[4] != $b4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b[4] != $b4) 3 1 4
25 3 $result->{key} = $bits.'!'.(pack "C*", @b);
26 3 my $entry = $parent->_cache_get($result);
27 3 ▶ if ($entry) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry) 1 2 3
28 1 $result->{messages} = $entry->{result}->{messages};
29 1 $result->{duplicate} = $parent->_cache_is_duplicate($entry);
30 1 return 1;
31 }
32 2 $b[4] = $b4;
33 }
34  
35 3 my $res = from_rf($bits, $bytes);
36  
37 printf "homeeasy c=%s u=%s a=%x\n",
38 3 $res->{command}, $res->{unit}, $res->{address} if DEBUG;
39 my %body = (
40 address => (sprintf "%#x",$res->{address}),
41 unit => $res->{unit},
42 command => $res->{command},
43 3 );
44  
45 3 ▶ $body{level} = $res->{level} if ($res->{command} eq 'preset');
Branch: 1 branch
BranchTrueFalseTotal
if $res->{"command"} eq "preset" 1 2 3
46  
47 3 push @{$result->{messages}}, Device::RFXCOM::Response::HomeEasy->new(%body);
48 3 return 1;
49 }
50  
51  
52 sub from_rf {
53 3 ▶ my $length = shift;
Subroutine from_rf: called CC=4 SCAR=13.9
Pod documented
54 3 my $bytes = shift;
55 3 my %p = ();
56 3 $p{address} = ($bytes->[0] << 18) + ($bytes->[1] << 10) +
57 ($bytes->[2] << 2) + ($bytes->[3] >> 6);
58 3 my $command = ($bytes->[3] >> 4) & 0x3;
59 3 ▶ $p{unit} = ($command & 0x2) ? 'group' : ($bytes->[3] & 0xf);
Branch: 1 branch
BranchTrueFalseTotal
$command & 2 ? : 1 2 3
60 3 ▶ if ($length == 38) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length == 38) { } 1 2 3
61 1 $p{command} = 'preset';
62 1 $p{level} = $bytes->[4] >> 4;
63 } else {
64 2 ▶ $p{command} = ($command & 0x1) ? 'on' : 'off';
Branch: 1 branch
BranchTrueFalseTotal
$command & 1 ? : 1 1 2
65 }
66 3 return \%p;
67 }
68  
69 3 1;
70  
71 __END__
« RFXCOM/Encoder/HomeEasy.pm ↑ Summary RFXCOM/Decoder/Electrisave.pm »