Modbus.pm

filter: Statementstmt 100% 25 / 25 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 94.4% 34 / 36 CC 3 SCAR 6.2
CC
3
Cov
100%
flatten_bit_values
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
« Modbus/ADU.pm ↑ Summary
1 package Device::Modbus;
2  
3 14 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 14 our $VERSION = '0.021';
8  
9 14 our %code_for = (
10 'Read Coils' => 0x01,
11 'Read Discrete Inputs' => 0x02,
12 'Read Holding Registers' => 0x03,
13 'Read Input Registers' => 0x04,
14 'Write Single Coil' => 0x05,
15 'Write Single Register' => 0x06,
16 'Write Multiple Coils' => 0x0F,
17 'Write Multiple Registers' => 0x10,
18 'Read/Write Multiple Registers' => 0x17,
19 );
20  
21 14 our %function_for = reverse %code_for;
22  
23 #### Helper methods
24  
25 # Receives an array reference of bit values and builds an array
26 # of 8-bit numbers. Each number starts with the lower address
27 # in the LSB.
28 # Returns the quantity of bits packed and a reference to the array
29 # of 8-bit numbers
30 6 ▶sub flatten_bit_values {
Subroutine flatten_bit_values: called CC=3 SCAR=11.0
Pod undocumented
31 6 my ($self, $values) = @_;
32  
33 # Values must be either 1 or 0
34 6 ▶ my @values = map { $_ ? 1 : 0 } @{$values};
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 45 30 75
35  
36 # Turn the values array into an array of binary numbers
37 6 my @values_binary;
38 6 ▶ while (@values) {
Branch: 1 branch
BranchTrueFalseTotal
if (@values) 13 6 19
39 13 push @values_binary, pack 'b*', join '', splice @values, 0, 8;
40 }
41 6 return \@values_binary;
42 }
43  
44 # Receives a quantity of bits and an array of 8-bit numbers.
45 # The numbers are exploded into an array of bit values.
46 # The numbers start with the lower address in the LSB,
47 # and the first number contains the lower address.
48 # Returns an array of ones and zeros.
49 9 ▶sub explode_bit_values {
Subroutine explode_bit_values: called CC=1 SCAR=0.0
Pod undocumented
50 9 my ($self, @values) = @_;
51 9 @values = map {split //, unpack 'b8', pack 'v', $_} @values;
52 9 return @values;
53 }
54  
55 14 1;
56  
57 __END__
« Modbus/ADU.pm ↑ Summary