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

filter: Statementstmt 32.8% 21 / 64 Branchbran 33.3% 6 / 18 Conditioncond 25.0% 4 / 16 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 44.4% 4 / 9 Podpod 0.0% 0 / 5 totaltotal 30.8% 37 / 120 CC 21 SCAR 34.1
CC
21
Cov
32%
decode_params
56.0
to_pronto
56.0
decode_timing
9.5
CRAP 30.3
« blib/lib/Protocol/IR/Proto/Panasonic.pm ↑ Summary blib/lib/Protocol/IR/Proto/RC6.pm »
1 package Protocol::IR::Proto::Sharp;
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 => 'SHARP',
16 bits => 15,
17 address => ($val >> 10) & 0x1f,
18 subaddress => -1,
19 command => ($val >> 2) & 0xff,
20 data => $val & 0x7fff,
21 );
22 }
23  
24 0 ▶sub decode_params {
Subroutine decode_params: not called CC=7 SCAR=40.3
Pod undocumented
25 0 my ($class, %args) = @_;
26 0 ▶ my $addr = $args{address} // $args{device} // 0;
Condition0%0/5
($args{"address"} // $args{"device"}) // 0
l!l
00
$args{"address"} // $args{"device"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($args{"address"} // $args{"device"}) // 0
$args{"address"} $args{"device"}
Truth table0%0/3
A // B
A= $args{"address"}B= $args{"device"}
ABresult
1X1
011
000
27 0 ▶ $addr = hex($addr) if $addr =~ /^0x/i;
Branch: 1 branch
BranchTrueFalseTotal
if $addr =~ /^0x/i 0 0 0
28 0 ▶ my $cmd = $args{command} // $args{function} // 0;
Condition0%0/5
($args{"command"} // $args{"function"}) // 0
l!l
00
$args{"command"} // $args{"function"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($args{"command"} // $args{"function"}) // 0
$args{"command"} $args{"function"}
Truth table0%0/3
A // B
A= $args{"command"}B= $args{"function"}
ABresult
1X1
011
000
29 0 ▶ $cmd = hex($cmd) if $cmd =~ /^0x/i;
Branch: 1 branch
BranchTrueFalseTotal
if $cmd =~ /^0x/i 0 0 0
30 0 $addr &= 0x1f;
31 0 $cmd &= 0xff;
32 0 my $data = ($addr << 10) | ($cmd << 2);
33 0 return Protocol::IR::Code->new(
34 protocol => 'SHARP',
35 bits => 15,
36 address => $addr,
37 subaddress => -1,
38 command => $cmd,
39 data => $data,
40 );
41 }
42  
43 145 ▶sub decode_timing {
Subroutine decode_timing: called CC=8 SCAR=22.5
Pod undocumented
44 145 my ($class, $pairs) = @_;
45 145 ▶ return undef unless ref $pairs eq 'ARRAY' && @$pairs >= 15;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pairs eq "ARRAY" and @$pairs >= 15 73 72 145
Condition66%2/3
ref $pairs eq "ARRAY" and @$pairs >= 15
!ll&&!rl&&r
07372
MC/DC50%1/2
ref $pairs eq "ARRAY" and @$pairs >= 15
ref $pairs eq "ARRAY" @$pairs >= 15
Truth table66%2/3
A and B
A= ref $pairs eq "ARRAY"B= @$pairs >= 15
ABresult
0X0
100
111
46 72 my $data = 0;
47 72 for my $i (0 .. 14) {
48 72 my ($mark, $space) = @{$pairs->[$i]};
49 72 ▶ return undef unless $mark >= 200 && $mark <= 400;
Branch: 1 branch
BranchTrueFalseTotal
unless $mark >= 200 and $mark <= 400 65 7 72
Condition66%2/3
$mark >= 200 and $mark <= 400
!ll&&!rl&&r
0657
MC/DC50%1/2
$mark >= 200 and $mark <= 400
$mark >= 200 $mark <= 400
Truth table66%2/3
A and B
A= $mark >= 200B= $mark <= 400
ABresult
0X0
100
111
50 7 my $bit;
51 0 ▶ if (abs($space - 1820) < 200) { $bit = 1; }
Branch: 2 branches
BranchTrueFalseTotal
if (abs $space - 1820 < 200) { } 0 7 7
elsif (abs $space - 780 < 200) { } 0 7 7
52 0 elsif (abs($space - 780) < 200) { $bit = 0; }
53 7 else { return undef; }
54 0 $data = ($data << 1) | $bit;
55 }
56 0 return Protocol::IR::Code->new(
57 protocol => 'SHARP',
58 bits => 15,
59 address => ($data >> 10) & 0x1f,
60 subaddress => -1,
61 command => ($data >> 2) & 0xff,
62 data => $data,
63 );
64 }
65  
66 0 ▶sub to_pronto {
Subroutine to_pronto: not called CC=7 SCAR=40.3
Pod undocumented
67 0 my ($class, $code) = @_;
68 0 my $data = $code->{data} & 0x7fff;
69 0 my $carrier_hz = 38000;
70 0 my $freq_word = int(1000000.0 / ($carrier_hz * 0.241246) + 0.5);
71 0 my $period_us = $freq_word * 0.241246;
72 0 ▶ my $us_to_pulses = sub { int($_[0] / $period_us + 0.5) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
73  
74 0 my @bits;
75 0 for my $i (reverse 0 .. 14) { push @bits, ($data >> $i) & 1; }
76  
77 0 my @pairs;
78 0 for my $bit (@bits) {
79 0 ▶ push @pairs, [ $us_to_pulses->(260), $us_to_pulses->($bit ? 1820 : 780) ];
Branch: 1 branch
BranchTrueFalseTotal
$bit ? : 0 0 0
80 }
81 # inverted frame
82 0 my $addr = ($data >> 10) & 0x1f;
83 0 my $rest = $data & 0x3ff;
84 0 my $inverted = ($addr << 10) | (~$rest & 0x3ff);
85 0 my @invbits;
86 0 for my $i (reverse 0 .. 14) { push @invbits, ($inverted >> $i) & 1; }
87 0 for my $bit (@invbits) {
88 0 ▶ push @pairs, [ $us_to_pulses->(260), $us_to_pulses->($bit ? 1820 : 780) ];
Branch: 1 branch
BranchTrueFalseTotal
$bit ? : 0 0 0
89 }
90  
91 0 my $seq1 = scalar(@pairs);
92 0 my $header = sprintf('0000 %04X %04X 0000', $freq_word, $seq1);
93 0 my $payload = join(' ', map { sprintf('%04X %04X', $_->[0], $_->[1]) } @pairs);
94 0 return "$header $payload";
95 }
96  
97 55 1;
98  
99 =head1 NAME
100  
101 Protocol::IR::Proto::Sharp - IR protocol handler
102  
103 =head1 VERSION
104  
105 version 1.5
106  
107 =cut
« blib/lib/Protocol/IR/Proto/Panasonic.pm ↑ Summary blib/lib/Protocol/IR/Proto/RC6.pm »