blib/lib/Protocol/IR/Proto/Dish.pm

filter: Statementstmt 91.0% 51 / 56 Branchbran 68.7% 11 / 16 Conditioncond 50.0% 13 / 26 MC/DCmcdc 15.3% 2 / 13 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 5 totaltotal 67.2% 84 / 125 CC 21 SCAR 22.2
CC
21
Cov
77%
decode_timing
15.3
decode_params
6.6
decode_raw
6.0
CRAP 9.2
« blib/lib/Protocol/IR/Format/JSON.pm ↑ Summary blib/lib/Protocol/IR/Format/Pronto.pm »
1 package Protocol::IR::Proto::Dish;
2 55 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 55 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 55 our $VERSION = '1.5';
6  
7 55 ▶use Protocol::IR::Code;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 0 ▶sub new { bless {}, shift }
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
10  
11 0 ▶sub decode_raw {
Subroutine decode_raw: not called CC=2 SCAR=17.9
Pod undocumented
12 0 my ($class, $raw) = @_;
13 0 ▶ my $val = $raw =~ /^0x/i ? hex($raw) : $raw + 0;
Branch: 1 branch
BranchTrueFalseTotal
$raw =~ /^0x/i ? : 0 0 0
14 0 return Protocol::IR::Code->new(
15 protocol => 'Dish_Network',
16 bits => 16,
17 address => 0,
18 subaddress => -1,
19 command => $val & 0xffff,
20 data => $val & 0xffff,
21 );
22 }
23  
24 3 ▶sub decode_params {
Subroutine decode_params: called CC=5 SCAR=18.9
Pod undocumented
25 3 my ($class, %args) = @_;
26 3 ▶ my $cmd = $args{command} // $args{function} // $args{device} // 0;
Condition37%3/8
(($args{"command"} // $args{"function"}) // $args{"device"}) // 0
l!l
30
($args{"command"} // $args{"function"}) // $args{"device"}
l!l&&r!l&&!r
300
$args{"command"} // $args{"function"}
l!l&&r!l&&!r
300
MC/DC0%0/3
(($args{"command"} // $args{"function"}) // $args{"device"}) // 0
$args{"command"} $args{"function"} $args{"device"}
Truth table25%1/4
A // B // C
A= $args{"command"}B= $args{"function"}C= $args{"device"}
ABCresult
1XX1
01X1
0011
0000
27 3 ▶ $cmd = hex($cmd) if $cmd =~ /^0x/i;
Branch: 1 branch
BranchTrueFalseTotal
if $cmd =~ /^0x/i 0 3 3
28 3 $cmd &= 0xffff;
29 3 return Protocol::IR::Code->new(
30 protocol => 'Dish_Network',
31 bits => 16,
32 address => 0,
33 subaddress => -1,
34 command => $cmd,
35 data => $cmd,
36 );
37 }
38  
39 137 ▶sub decode_timing {
Subroutine decode_timing: called CC=13 SCAR=27.3
Pod undocumented
40 137 my ($class, $pairs) = @_;
41 137 ▶ return undef unless ref $pairs eq 'ARRAY' && @$pairs >= 17;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pairs eq "ARRAY" and @$pairs >= 17 73 64 137
Condition66%2/3
ref $pairs eq "ARRAY" and @$pairs >= 17
!ll&&!rl&&r
07364
MC/DC50%1/2
ref $pairs eq "ARRAY" and @$pairs >= 17
ref $pairs eq "ARRAY" @$pairs >= 17
Truth table66%2/3
A and B
A= ref $pairs eq "ARRAY"B= @$pairs >= 17
ABresult
0X0
100
111
42 64 my ($hdr_mark, $hdr_space) = @{$pairs->[0]};
43 64 ▶ return undef unless $hdr_mark >= 300 && $hdr_mark <= 500 && $hdr_space >= 5500 && $hdr_space <= 6700;
Branch: 1 branch
BranchTrueFalseTotal
unless $hdr_mark >= 300 and $hdr_mark <= 500 and $hdr_space >= 5500 and $hdr_space <= 6700 57 7 64
Condition66%6/9
$hdr_mark >= 300 and $hdr_mark <= 500 and $hdr_space >= 5500 and $hdr_space <= 6700
!ll&&!rl&&r
5707
$hdr_mark >= 300 and $hdr_mark <= 500 and $hdr_space >= 5500
!ll&&!rl&&r
5707
$hdr_mark >= 300 and $hdr_mark <= 500
!ll&&!rl&&r
0577
MC/DC25%1/4
$hdr_mark >= 300 and $hdr_mark <= 500 and $hdr_space >= 5500 and $hdr_space <= 6700
$hdr_mark >= 300 $hdr_mark <= 500 $hdr_space >= 5500 $hdr_space <= 6700
Truth table40%2/5
A and B and C and D
A= $hdr_mark >= 300B= $hdr_mark <= 500C= $hdr_space >= 5500D= $hdr_space <= 6700
ABCDresult
0XXX0
10XX0
110X0
11100
11111
44 7 my $data = 0;
45 7 for my $i (0 .. 15) {
46 112 my ($mark, $space) = @{$pairs->[$i + 1]};
47 112 ▶ return undef unless $mark >= 300 && $mark <= 500;
Branch: 1 branch
BranchTrueFalseTotal
unless $mark >= 300 and $mark <= 500 0 112 112
Condition33%1/3
$mark >= 300 and $mark <= 500
!ll&&!rl&&r
00112
MC/DC0%0/2
$mark >= 300 and $mark <= 500
$mark >= 300 $mark <= 500
Truth table33%1/3
A and B
A= $mark >= 300B= $mark <= 500
ABresult
0X0
100
111
48 112 my $bit;
49 112 my $mid = (1700 + 2800) / 2;
50 112 ▶ if ($space > $mid) { $bit = 0; }
Branch: 2 branches
BranchTrueFalseTotal
if ($space > $mid) { } 95 17 112
elsif ($space < $mid and $space >= 850) { } 17 0 17
51 17 ▶ elsif ($space < $mid && $space >= 850) { $bit = 1; }
Condition33%1/3
$space < $mid and $space >= 850
!ll&&!rl&&r
0017
MC/DC0%0/2
$space < $mid and $space >= 850
$space < $mid $space >= 850
Truth table33%1/3
A and B
A= $space < $midB= $space >= 850
ABresult
0X0
100
111
52 0 else { return undef; }
53 112 $data = ($data << 1) | $bit;
54 }
55 7 return Protocol::IR::Code->new(
56 protocol => 'Dish_Network',
57 bits => 16,
58 address => 0,
59 subaddress => -1,
60 command => $data,
61 data => $data,
62 );
63 }
64  
65 3 ▶sub to_pronto {
Subroutine to_pronto: called CC=4 SCAR=13.9
Pod undocumented
66 3 my ($class, $code) = @_;
67 3 my $data = $code->{data} & 0xffff;
68 3 my $carrier_hz = 57600;
69 3 my $freq_word = int(1000000.0 / ($carrier_hz * 0.241246) + 0.5);
70 3 my $period_us = $freq_word * 0.241246;
71 3 ▶ my $us_to_pulses = sub { int($_[0] / $period_us + 0.5) };
Subroutine __ANON__: called CC=1 SCAR=0.0
72  
73 3 my @bits;
74 3 for my $i (reverse 0 .. 15) { push @bits, ($data >> $i) & 1; }
75  
76 3 my @pairs = ( [ $us_to_pulses->(400), $us_to_pulses->(6100) ] );
77 3 for my $bit (@bits) {
78 48 ▶ push @pairs, [ $us_to_pulses->(400), $us_to_pulses->($bit ? 1700 : 2800) ];
Branch: 1 branch
BranchTrueFalseTotal
$bit ? : 7 41 48
79 }
80  
81 3 my $seq1 = scalar(@pairs);
82 3 my $header = sprintf('0000 %04X %04X 0000', $freq_word, $seq1);
83 3 my $payload = join(' ', map { sprintf('%04X %04X', $_->[0], $_->[1]) } @pairs);
84 3 return "$header $payload";
85 }
86  
87 55 1;
88  
89 =head1 NAME
90  
91 Protocol::IR::Proto::Dish - IR protocol handler
92  
93 =head1 VERSION
94  
95 version 1.5
96  
97 =cut
« blib/lib/Protocol/IR/Format/JSON.pm ↑ Summary blib/lib/Protocol/IR/Format/Pronto.pm »