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

filter: Statementstmt 92.8% 52 / 56 Branchbran 75.0% 12 / 16 Conditioncond 53.8% 14 / 26 MC/DCmcdc 23.0% 3 / 13 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 5 totaltotal 70.4% 88 / 125 CC 21 SCAR 21.4
CC
21
Cov
80%
decode_timing
13.9
decode_params
6.6
decode_raw
6.0
CRAP 8.5
« blib/lib/Protocol/IR/Format/Pronto.pm ↑ Summary blib/lib/Protocol/IR/Proto/Aiwa.pm »
1 package Protocol::IR::Proto::GICable;
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 => 'G.I.Cable',
16 bits => 16,
17 address => 0,
18 subaddress => -1,
19 command => $val & 0xffff,
20 data => $val & 0xffff,
21 );
22 }
23  
24 2 ▶sub decode_params {
Subroutine decode_params: called CC=5 SCAR=18.9
Pod undocumented
25 2 my ($class, %args) = @_;
26 2 ▶ my $cmd = $args{command} // $args{function} // $args{device} // 0;
Condition37%3/8
(($args{"command"} // $args{"function"}) // $args{"device"}) // 0
l!l
20
($args{"command"} // $args{"function"}) // $args{"device"}
l!l&&r!l&&!r
200
$args{"command"} // $args{"function"}
l!l&&r!l&&!r
200
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 2 ▶ $cmd = hex($cmd) if $cmd =~ /^0x/i;
Branch: 1 branch
BranchTrueFalseTotal
if $cmd =~ /^0x/i 0 2 2
28 2 $cmd &= 0xffff;
29 2 return Protocol::IR::Code->new(
30 protocol => 'G.I.Cable',
31 bits => 16,
32 address => 0,
33 subaddress => -1,
34 command => $cmd,
35 data => $cmd,
36 );
37 }
38  
39 141 ▶sub decode_timing {
Subroutine decode_timing: called CC=13 SCAR=26.3
Pod undocumented
40 141 my ($class, $pairs) = @_;
41 141 ▶ return undef unless ref $pairs eq 'ARRAY' && @$pairs >= 17;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pairs eq "ARRAY" and @$pairs >= 17 73 68 141
Condition66%2/3
ref $pairs eq "ARRAY" and @$pairs >= 17
!ll&&!rl&&r
07368
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 68 my ($hm, $hs) = @{$pairs->[0]};
43 68 ▶ return undef unless $hm >= 8000 && $hm <= 10000 && $hs >= 3800 && $hs <= 5000;
Branch: 1 branch
BranchTrueFalseTotal
unless $hm >= 8000 and $hm <= 10000 and $hs >= 3800 and $hs <= 5000 62 6 68
Condition66%6/9
$hm >= 8000 and $hm <= 10000 and $hs >= 3800 and $hs <= 5000
!ll&&!rl&&r
6206
$hm >= 8000 and $hm <= 10000 and $hs >= 3800
!ll&&!rl&&r
6206
$hm >= 8000 and $hm <= 10000
!ll&&!rl&&r
6206
MC/DC25%1/4
$hm >= 8000 and $hm <= 10000 and $hs >= 3800 and $hs <= 5000
$hm >= 8000 $hm <= 10000 $hs >= 3800 $hs <= 5000
Truth table40%2/5
A and B and C and D
A= $hm >= 8000B= $hm <= 10000C= $hs >= 3800D= $hs <= 5000
ABCDresult
0XXX0
10XX0
110X0
11100
11111
44 6 my $data = 0;
45 6 for my $i (0 .. 15) {
46 66 my ($mark, $space) = @{$pairs->[$i + 1]};
47 66 ▶ return undef unless $mark >= 400 && $mark <= 700;
Branch: 1 branch
BranchTrueFalseTotal
unless $mark >= 400 and $mark <= 700 0 66 66
Condition33%1/3
$mark >= 400 and $mark <= 700
!ll&&!rl&&r
0066
MC/DC0%0/2
$mark >= 400 and $mark <= 700
$mark >= 400 $mark <= 700
Truth table33%1/3
A and B
A= $mark >= 400B= $mark <= 700
ABresult
0X0
100
111
48 66 my $bit;
49 66 my $mid = (4400 + 2200) / 2;
50 66 ▶ if ($space > $mid) { $bit = 1; }
Branch: 2 branches
BranchTrueFalseTotal
if ($space > $mid) { } 8 58 66
elsif ($space < $mid and $space >= 1100) { } 56 2 58
51 56 ▶ elsif ($space < $mid && $space >= 1100) { $bit = 0; }
Condition66%2/3
$space < $mid and $space >= 1100
!ll&&!rl&&r
0256
MC/DC50%1/2
$space < $mid and $space >= 1100
$space < $mid $space >= 1100
Truth table66%2/3
A and B
A= $space < $midB= $space >= 1100
ABresult
0X0
100
111
52 2 else { return undef; }
53 64 $data = ($data << 1) | $bit;
54 }
55 4 return Protocol::IR::Code->new(
56 protocol => 'G.I.Cable',
57 bits => 16,
58 address => 0,
59 subaddress => -1,
60 command => $data,
61 data => $data,
62 );
63 }
64  
65 2 ▶sub to_pronto {
Subroutine to_pronto: called CC=4 SCAR=13.9
Pod undocumented
66 2 my ($class, $code) = @_;
67 2 my $data = $code->{data} & 0xffff;
68 2 my $carrier_hz = 38000;
69 2 my $freq_word = int(1000000.0 / ($carrier_hz * 0.241246) + 0.5);
70 2 my $period_us = $freq_word * 0.241246;
71 2 ▶ my $us_to_pulses = sub { int($_[0] / $period_us + 0.5) };
Subroutine __ANON__: called CC=1 SCAR=0.0
72  
73 2 my @bits;
74 2 for my $i (reverse 0 .. 15) { push @bits, ($data >> $i) & 1; }
75  
76 2 my @pairs = ( [ $us_to_pulses->(9000), $us_to_pulses->(4400) ] );
77 2 for my $bit (@bits) {
78 32 ▶ push @pairs, [ $us_to_pulses->(550), $us_to_pulses->($bit ? 4400 : 2200) ];
Branch: 1 branch
BranchTrueFalseTotal
$bit ? : 4 28 32
79 }
80  
81 2 my $seq1 = scalar(@pairs);
82 2 my $header = sprintf('0000 %04X %04X 0000', $freq_word, $seq1);
83 2 my $payload = join(' ', map { sprintf('%04X %04X', $_->[0], $_->[1]) } @pairs);
84 2 return "$header $payload";
85 }
86  
87 55 1;
88  
89 =head1 NAME
90  
91 Protocol::IR::Proto::GICable - IR protocol handler
92  
93 =head1 VERSION
94  
95 version 1.5
96  
97 =cut
« blib/lib/Protocol/IR/Format/Pronto.pm ↑ Summary blib/lib/Protocol/IR/Proto/Aiwa.pm »