RFXCOM/Decoder/CM119.pm

filter: Statementstmt 100% 50 / 50 Branchbran 100% 8 / 8 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 100% 74 / 74 SCAR 19.5
CC
7
Cov
100%
decode
6.0
_ns
2.0
BEGIN
1.0
CRAP 7.0
« RFXCOM/Encoder/X10.pm ↑ Summary RFXCOM/Decoder/OregonScale.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::CM119;
4 3 $Device::RFXCOM::Decoder::CM119::VERSION = '1.142010';
5 # ABSTRACT: Device::RFXCOM::Decoder::CM119 decode OWL CM119 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_CM119_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 Device::RFXCOM::Decoder qw/hi_nibble lo_nibble nibble_sum/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use base 'Device::RFXCOM::Decoder';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Device::RFXCOM::Response::Sensor;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 sub decode {
17 89 ▶ my ($self, $parent, $message, $bytes, $bits, $result) = @_;
Subroutine decode: called CC=6 SCAR=17.9
Pod documented
18 89 ▶ $bits == 108 or return;
Branch: 1 branch
BranchTrueFalseTotal
$bits == 108 or return 84 5 89
19 5 ▶ ($bytes->[0]&0xf)==0xa or return;
Branch: 1 branch
BranchTrueFalseTotal
($bytes->[0] & 15) == 10 or return 1 4 5
20  
21 4 my $s = _ns(1, 10, $bytes);
22 4 $s += lo_nibble($bytes->[11]);
23 4 $s -= (lo_nibble($bytes->[12])<<4) + hi_nibble($bytes->[11]);
24 4 ▶ $s == 0 or return;
Branch: 1 branch
BranchTrueFalseTotal
$s == 0 or return 1 3 4
25  
26 3 my $ch = $bytes->[0]>>4;
27 3 ▶ if ($ch < 1 || $ch > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch < 1 or $ch > 3) 2 1 3
Condition100%3/3
$ch < 1 or $ch > 3
l!l&&r!l&&!r
111
MC/DC100%2/2
$ch < 1 or $ch > 3
$ch < 1 $ch > 3
Truth table100%3/3
A or B
A= $ch < 1B= $ch > 3
ABresult
1X1
011
000
28 2 warn "CM119 channel not 1 - 3?\n";
29 }
30 3 my $device = sprintf "%02x", $bytes->[2];
31 3 my $counter = lo_nibble($bytes->[1]);
32 3 my $now = (lo_nibble($bytes->[5])<<16) + ($bytes->[4]<<8) + $bytes->[3];
33 3 my $total =
34 ($bytes->[10] << 36) + ($bytes->[9] << 28) + ($bytes->[8] << 20) +
35 ($bytes->[7] << 12) + ($bytes->[6] << 4) + hi_nibble($bytes->[5]);
36 3 $total /= 223000; # kWh
37 3 my $dev = $device.'.'.$ch;
38 3 printf "cm119 d=%s power=%dW\n", $dev, $now if DEBUG;
39 3 push @{$result->{messages}},
40 Device::RFXCOM::Response::Sensor->new(device => 'cm119.'.$dev,
41 measurement => 'power',
42 value => $now);
43 3 return 1;
44 }
45  
46 sub _ns {
47 4 ▶ my ($s, $e, $b) = @_;
Subroutine _ns: called CC=2 SCAR=6.9
48 4 my $sum = 0;
49 4 foreach ($s .. $e) {
50 40 $sum += lo_nibble($b->[$_]) + hi_nibble($b->[$_]);
51 }
52 4 $sum;
53 }
54  
55 3 1;
56  
57 __END__
« RFXCOM/Encoder/X10.pm ↑ Summary RFXCOM/Decoder/OregonScale.pm »