RFXCOM/Decoder/X10Security.pm

filter: Statementstmt 100% 59 / 59 Branchbran 100% 18 / 18 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 100% 99 / 99 SCAR 25.6
CC
13
Cov
100%
decode
12.0
reverse_bits
2.0
BEGIN
1.0
CRAP 13.0
« RFXCOM/Base.pm ↑ Summary RFXCOM/Decoder/Visonic.pm »
1 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Device::RFXCOM::Decoder::X10Security;
4 4 $Device::RFXCOM::Decoder::X10Security::VERSION = '1.142010';
5 # ABSTRACT: Device::RFXCOM::Decoder::X10Security decode X10 Security RF messages
6  
7  
8 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use constant DEBUG => $ENV{DEVICE_RFXCOM_DECODER_X10_SECURITY_DEBUG};
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use base 'Device::RFXCOM::Decoder';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Device::RFXCOM::Response::Security;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Device::RFXCOM::Response::Sensor;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 sub decode {
17 34 ▶ my ($self, $parent, $message, $bytes, $bits, $result) = @_;
Subroutine decode: called CC=12 SCAR=24.8
Pod documented
18 34 ▶ ($bits == 32 || $bits == 41) or return;
Branch: 1 branch
BranchTrueFalseTotal
$bits == 32 or $bits == 41 or return 21 13 34
Condition100%3/3
$bits == 32 or $bits == 41
l!l&&r!l&&!r
8521
MC/DC100%2/2
$bits == 32 or $bits == 41
$bits == 32 $bits == 41
Truth table100%3/3
A or B
A= $bits == 32B= $bits == 41
ABresult
1X1
011
000
19  
20 # bits are not reversed yet!
21 13 ▶ (($bytes->[0]^0x0f) == $bytes->[1] && ($bytes->[2]^0xff) == $bytes->[3])
Branch: 1 branch
BranchTrueFalseTotal
($bytes->[0] ^ 15) == $bytes->[1] and ($bytes->[2] ^ 255) == $bytes->[3] or return 7 6 13
Condition100%3/3
($bytes->[0] ^ 15) == $bytes->[1] and ($bytes->[2] ^ 255) == $bytes->[3]
!ll&&!rl&&r
616
MC/DC100%2/2
($bytes->[0] ^ 15) == $bytes->[1] and ($bytes->[2] ^ 255) == $bytes->[3]
($bytes->[0] ^ 15) == $bytes->[1] ($bytes->[2] ^ 255) == $bytes->[3]
Truth table100%3/3
A and B
A= ($bytes->[0] ^ 15) == $bytes->[1]B= ($bytes->[2] ^ 255) == $bytes->[3]
ABresult
0X0
100
111
22 or return;
23  
24 6 $self->reverse_bits($bytes); # TOFIX: corrupts the input data?
25  
26 6 my $device = sprintf 'x10sec%02x', $bytes->[0];
27 6 my $short_device = $bytes->[0];
28 6 my $data = $bytes->[2];
29  
30 6 my %not_supported_yet =
31 (
32 # See: http://www.wgldesigns.com/protocols/w800rf32_protocol.txt
33 0x70 => 'SH624 arm home (min)',
34 #0x60 => 'SH624 arm away (min)',
35 0x50 => 'SH624 arm home (max)',
36 0x40 => 'SH624 arm away (max)',
37 0x41 => 'SH624 disarm',
38 0x42 => 'SH624 sec light on',
39 0x43 => 'SH624 sec light off',
40 0x44 => 'SH624 panic',
41 );
42  
43 6 my %x10_security =
44 (
45 0x60 => ['arm-away', 'min'],
46 0x61 => 'disarm',
47 0x62 => 'lights-on',
48 0x63 => 'lights-off',
49 );
50  
51 6 my $command;
52 my $tamper;
53 6 my $min_delay;
54 6 my $low_battery;
55  
56 6 ▶ if (exists $x10_security{$data}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $x10_security{$data}) { } 2 4 6
elsif (exists $not_supported_yet{$data}) { } 1 3 4
57 2 my $rec = $x10_security{$data};
58 2 ▶ if (ref $rec) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rec) { } 1 1 2
59 1 ($command, $min_delay) = @$rec;
60 } else {
61 1 $command = $rec;
62 }
63 } elsif (exists $not_supported_yet{$data}) {
64 1 warn sprintf "Not supported: %02x %s\n", $data, $not_supported_yet{$data};
65 1 return 1;
66 } else {
67  
68 3 my $alert = !($data&0x1);
69 3 ▶ $command = $alert ? 'alert' : 'normal',
Branch: 1 branch
BranchTrueFalseTotal
$alert ? : 2 1 3
70 $tamper = $data&0x2;
71 3 $min_delay = $data&0x20;
72 3 $low_battery = $data&0x80;
73 }
74  
75 5 my %args =
76 (
77 event => $command,
78 device => $device,
79 );
80 5 ▶ $args{tamper} = 1 if ($tamper);
Branch: 1 branch
BranchTrueFalseTotal
if $tamper 2 3 5
81 5 ▶ $args{min_delay} = 1 if ($min_delay);
Branch: 1 branch
BranchTrueFalseTotal
if $min_delay 3 2 5
82 5 ▶ push @{$result->{messages}},
Branch: 1 branch
BranchTrueFalseTotal
$low_battery ? : 1 4 5
83 Device::RFXCOM::Response::Security->new(%args),
84 Device::RFXCOM::Response::Sensor->new(device => $device,
85 measurement => 'battery',
86 value => $low_battery ? 10 : 90,
87 units => '%');
88 5 return 1;
89 }
90  
91  
92 sub reverse_bits {
93 6 ▶ my $self = shift;
Subroutine reverse_bits: called CC=2 SCAR=6.9
Pod documented
94 6 my $bytes = shift;
95 6 foreach (@$bytes) {
96 32 $_ = unpack 'C',(pack 'B8', (unpack 'b8', (pack 'C',$_)));
97 }
98 6 return 1;
99 }
100  
101 4 1;
102  
103 __END__
« RFXCOM/Base.pm ↑ Summary RFXCOM/Decoder/Visonic.pm »