| 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::OregonScale; | ||||||||||||||||||||||||||||
| 4 | 3 | $Device::RFXCOM::Decoder::OregonScale::VERSION = '1.142010'; | |||||||||||||||||||||||||||
| 5 | # ABSTRACT: Device::RFXCOM::Decoder::OregonScale decode Oregon Scale 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_OREGON_SCALE_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/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | our @ISA = qw(Device::RFXCOM::Decoder); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | sub decode { | ||||||||||||||||||||||||||||
| 16 | 58 | ▶ | my ($self, $parent, $message, $bytes, $bits, $result) = @_; | ||||||||||||||||||||||||||
|
Subroutine
decode: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 58 | ▶ | if ($bits == 64 && lo_nibble($bytes->[0]) == 3) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$bits == 64 and lo_nibble($bytes->[0]) == 3
MC/DC100%2/2
$bits == 64 and lo_nibble($bytes->[0]) == 3
$bits == 64
lo_nibble($bytes->[0]) == 3
Truth table100%3/3
A and B
A= $bits == 64B= lo_nibble($bytes->[0]) == 3
| |||||||||||||||||||||||||||||
| 18 | 1 | return parse_gr101($self, $parent, $message, $bytes, $bits, $result); | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | 57 | ▶ | return unless (scalar @$bytes == 7); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 4 | ▶ | return unless (($bytes->[0]&0xf0) == ($bytes->[5]&0xf0) && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
($bytes->[0] & 240) == ($bytes->[5] & 240) and ($bytes->[1] & 15) == ($bytes->[6] & 15)
MC/DC100%2/2
($bytes->[0] & 240) == ($bytes->[5] & 240) and ($bytes->[1] & 15) == ($bytes->[6] & 15)
($bytes->[0] & 240) == ($bytes->[5] & 240)
($bytes->[1] & 15) == ($bytes->[6] & 15)
Truth table100%3/3
A and B
A= ($bytes->[0] & 240) == ($bytes->[5] & 240)B= ($bytes->[1] & 15) == ($bytes->[6] & 15)
| |||||||||||||||||||||||||||||
| 22 | ($bytes->[1]&0xf) == ($bytes->[6]&0xf)); | ||||||||||||||||||||||||||||
| 23 | 2 | my $weight = | |||||||||||||||||||||||||||
| 24 | sprintf "%x%02x%x", $bytes->[5]&0x1, $bytes->[4], hi_nibble($bytes->[3]); | ||||||||||||||||||||||||||||
| 25 | 2 | ▶ | return unless ($weight =~ /^\d+$/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 1 | $weight /= 10; | |||||||||||||||||||||||||||
| 27 | 1 | my $dev_str = sprintf 'bwr102.%02x', hi_nibble($bytes->[1]); | |||||||||||||||||||||||||||
| 28 | 1 | my $unknown = sprintf "%x%x", lo_nibble($bytes->[3]), hi_nibble($bytes->[2]); | |||||||||||||||||||||||||||
| 29 | 1 | push @{$result->{messages}}, | |||||||||||||||||||||||||||
| 30 | Device::RFXCOM::Response::Sensor->new(device => $dev_str, | ||||||||||||||||||||||||||||
| 31 | measurement => 'weight', | ||||||||||||||||||||||||||||
| 32 | value => $weight, | ||||||||||||||||||||||||||||
| 33 | unknown => $unknown, | ||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | 1 | return 1; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | sub parse_gr101 { | ||||||||||||||||||||||||||||
| 40 | 1 | ▶ | my ($self, $parent, $message, $bytes, $bits, $result) = @_; | ||||||||||||||||||||||||||
|
Subroutine
parse_gr101: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 1 | my $weight = | |||||||||||||||||||||||||||
| 43 | (lo_nibble($bytes->[4])<<12) + ($bytes->[3]<<4) + ($bytes->[2]>>4); | ||||||||||||||||||||||||||||
| 44 | 1 | $weight = sprintf "%.1f", $weight/400.8; | |||||||||||||||||||||||||||
| 45 | 1 | my $dev_str = sprintf 'gr101.%02x', $bytes->[1]; | |||||||||||||||||||||||||||
| 46 | 1 | push @{$result->{messages}}, | |||||||||||||||||||||||||||
| 47 | Device::RFXCOM::Response::Sensor->new(device => $dev_str, | ||||||||||||||||||||||||||||
| 48 | measurement => 'weight', | ||||||||||||||||||||||||||||
| 49 | value => $weight); | ||||||||||||||||||||||||||||
| 50 | 1 | return 1; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 3 | 1; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | __END__ | ||||||||||||||||||||||||||||