line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
2840
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
129
|
|
2
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
177
|
|
3
|
|
|
|
|
|
|
package Device::RFXCOM::Decoder::CM119; |
4
|
|
|
|
|
|
|
$Device::RFXCOM::Decoder::CM119::VERSION = '1.163170'; |
5
|
|
|
|
|
|
|
# ABSTRACT: Device::RFXCOM::Decoder::CM119 decode OWL CM119 RF messages |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
63
|
use 5.006; |
|
3
|
|
|
|
|
14
|
|
9
|
3
|
|
|
3
|
|
11
|
use constant DEBUG => $ENV{DEVICE_RFXCOM_DECODER_CM119_DEBUG}; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
203
|
|
10
|
3
|
|
|
3
|
|
12
|
use Carp qw/croak/; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
163
|
|
11
|
3
|
|
|
3
|
|
21
|
use Device::RFXCOM::Decoder qw/hi_nibble lo_nibble nibble_sum/; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
172
|
|
12
|
3
|
|
|
3
|
|
14
|
use base 'Device::RFXCOM::Decoder'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
256
|
|
13
|
3
|
|
|
3
|
|
14
|
use Device::RFXCOM::Response::Sensor; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1104
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub decode { |
17
|
89
|
|
|
89
|
1
|
179
|
my ($self, $parent, $message, $bytes, $bits, $result) = @_; |
18
|
89
|
100
|
|
|
|
543
|
$bits == 108 or return; |
19
|
5
|
100
|
|
|
|
25
|
($bytes->[0]&0xf)==0xa or return; |
20
|
|
|
|
|
|
|
|
21
|
4
|
|
|
|
|
11
|
my $s = _ns(1, 10, $bytes); |
22
|
4
|
|
|
|
|
16
|
$s += lo_nibble($bytes->[11]); |
23
|
4
|
|
|
|
|
11
|
$s -= (lo_nibble($bytes->[12])<<4) + hi_nibble($bytes->[11]); |
24
|
4
|
100
|
|
|
|
19
|
$s == 0 or return; |
25
|
|
|
|
|
|
|
|
26
|
3
|
|
|
|
|
7
|
my $ch = $bytes->[0]>>4; |
27
|
3
|
100
|
100
|
|
|
24
|
if ($ch < 1 || $ch > 3) { |
28
|
2
|
|
|
|
|
43
|
warn "CM119 channel not 1 - 3?\n"; |
29
|
|
|
|
|
|
|
} |
30
|
3
|
|
|
|
|
30
|
my $device = sprintf "%02x", $bytes->[2]; |
31
|
3
|
|
|
|
|
12
|
my $counter = lo_nibble($bytes->[1]); |
32
|
3
|
|
|
|
|
9
|
my $now = (lo_nibble($bytes->[5])<<16) + ($bytes->[4]<<8) + $bytes->[3]; |
33
|
3
|
|
|
|
|
14
|
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
|
|
|
|
|
6
|
$total /= 223000; # kWh |
37
|
3
|
|
|
|
|
10
|
my $dev = $device.'.'.$ch; |
38
|
3
|
|
|
|
|
4
|
printf "cm119 d=%s power=%dW\n", $dev, $now if DEBUG; |
39
|
3
|
|
|
|
|
5
|
push @{$result->{messages}}, |
|
3
|
|
|
|
|
28
|
|
40
|
|
|
|
|
|
|
Device::RFXCOM::Response::Sensor->new(device => 'cm119.'.$dev, |
41
|
|
|
|
|
|
|
measurement => 'power', |
42
|
|
|
|
|
|
|
value => $now); |
43
|
3
|
|
|
|
|
19
|
return 1; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _ns { |
47
|
4
|
|
|
4
|
|
8
|
my ($s, $e, $b) = @_; |
48
|
4
|
|
|
|
|
6
|
my $sum = 0; |
49
|
4
|
|
|
|
|
15
|
foreach ($s .. $e) { |
50
|
40
|
|
|
|
|
88
|
$sum += lo_nibble($b->[$_]) + hi_nibble($b->[$_]); |
51
|
|
|
|
|
|
|
} |
52
|
4
|
|
|
|
|
9
|
$sum; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |