| 1 | package Device::Modbus::Server; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use Device::Modbus; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use Device::Modbus::Request; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Device::Modbus::Response; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Device::Modbus::Exception; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Device::Modbus::Unit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | sub proto { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
proto: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | units => {}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | log_level => 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | timeout => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ### Unit management | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 34 | ▶ | sub units { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
units: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 34 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 34 | return $self->{units}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 5 | ▶ | sub add_server_unit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_server_unit: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 5 | my ($self, $unit, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 5 | ▶ | if (ref $unit && $unit->isa('Device::Modbus::Unit')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $unit and $unit->isa("Device::Modbus::Unit")
MC/DC100%2/2
ref $unit and $unit->isa("Device::Modbus::Unit")
ref $unit
$unit->isa("Device::Modbus::Unit")
Truth table100%3/3
A and B
A= ref $unitB= $unit->isa("Device::Modbus::Unit")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | $unit->init_unit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | $self->units->{$unit->id} = $unit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | return $unit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | croak "Units must be subclasses of Device::Modbus::Unit"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 16 | ▶ | sub get_server_unit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_server_unit: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 16 | my ($self, $unit_id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 16 | return $self->units->{$unit_id}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # To be overrided in subclasses | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | sub init_server { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_server: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | croak "Server must be initialized\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ### Request parsing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 37 | ▶ | sub receive_request { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
receive_request: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 37 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 37 | $self->read_port; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 37 | my $adu = $self->new_adu(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 37 | $self->parse_header($adu); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 37 | $self->parse_pdu($adu); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 37 | $self->parse_footer($adu); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 37 | return $adu; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 37 | ▶ | sub parse_pdu { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_pdu: called CC=17 SCAR=28.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 37 | my ($self, $adu) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 37 | my $request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 37 | my $code = $self->parse_buffer(1,'C'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 37 | ▶ | if ($code == 0x01 || $code == 0x02 || $code == 0x03 || $code == 0x04) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition100%9/9
$code == 1 or $code == 2 or $code == 3 or $code == 4
$code == 1 or $code == 2 or $code == 3
$code == 1 or $code == 2
MC/DC100%4/4
$code == 1 or $code == 2 or $code == 3 or $code == 4
$code == 1
$code == 2
$code == 3
$code == 4
Truth table100%5/5
A or B or C or D
A= $code == 1B= $code == 2C= $code == 3D= $code == 4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # Read coils, discrete inputs, holding registers, input registers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 16 | my ($address, $quantity) = $self->parse_buffer(4,'nn'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 16 | $request = Device::Modbus::Request->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | code => $code, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | address => $address, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | quantity => $quantity | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | ▶ | elsif ($code == 0x05 || $code == 0x06) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$code == 5 or $code == 6
MC/DC100%2/2
$code == 5 or $code == 6
$code == 5
$code == 6
Truth table100%3/3
A or B
A= $code == 5B= $code == 6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # Write single coil and single register | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 5 | my ($address, $value) = $self->parse_buffer(4, 'nn'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 5 | ▶ | if ($code == 0x05 && $value != 0xFF00 && $value != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$code == 5 and $value != 65280 and $value != 0
$code == 5 and $value != 65280
MC/DC100%3/3
$code == 5 and $value != 65280 and $value != 0
$code == 5
$value != 65280
$value != 0
Truth table100%4/4
A and B and C
A= $code == 5B= $value != 65280C= $value != 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | $request = Device::Modbus::Exception->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | code => $code + 0x80, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | exception_code => 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 4 | $request = Device::Modbus::Request->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | code => $code, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | address => $address, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | value => $value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | elsif ($code == 0x0F) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # Write multiple coils | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 6 | my ($address, $qty, $bytes) = $self->parse_buffer(5, 'nnC'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 6 | ▶ | my $bytes_qty = $qty % 8 ? int($qty/8) + 1 : $qty/8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 6 | ▶ | if ($bytes == $bytes_qty) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 5 | my (@values) = $self->parse_buffer($bytes, 'C*'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 5 | @values = Device::Modbus->explode_bit_values(@values); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 5 | $request = Device::Modbus::Request->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | code => $code, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | address => $address, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | quantity => $qty, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | bytes => $bytes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | values => \@values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | $request = Device::Modbus::Exception->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | code => $code + 0x80, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | exception_code => 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | elsif ($code == 0x10) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # Write multiple registers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 4 | my ($address, $qty, $bytes) = $self->parse_buffer(5, 'nnC'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 4 | ▶ | if ($bytes == 2 * $qty) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 3 | my (@values) = $self->parse_buffer($bytes, 'n*'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 3 | $request = Device::Modbus::Request->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | code => $code, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | address => $address, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | quantity => $qty, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | bytes => $bytes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | values => \@values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | $request = Device::Modbus::Exception->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | code => $code + 0x80, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | exception_code => 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | elsif ($code == 0x17) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # Read/Write multiple registers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 5 | my ($read_addr, $read_qty, $write_addr, $write_qty, $bytes) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | = $self->parse_buffer(9, 'nnnnC'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 5 | ▶ | if ($bytes == 2 * $write_qty) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 4 | my (@values) = $self->parse_buffer($bytes, 'n*'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 4 | $request = Device::Modbus::Request->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | code => $code, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | read_address => $read_addr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | read_quantity => $read_qty, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | write_address => $write_addr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | write_quantity => $write_qty, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | bytes => $bytes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | values => \@values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | $request = Device::Modbus::Exception->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | code => $code + 0x80, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | exception_code => 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # Unimplemented function | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 1 | $request = Device::Modbus::Exception->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | code => $code + 0x80, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | exception_code => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 37 | $adu->message($request); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 37 | return $request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | ### Server code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # 'Read Coils' => 0x01, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # 'Read Discrete Inputs' => 0x02, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # 'Read Holding Registers' => 0x03, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # 'Read Input Registers' => 0x04, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # 'Write Single Coil' => 0x05, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # 'Write Single Register' => 0x06, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # 'Write Multiple Coils' => 0x0F, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # 'Write Multiple Registers' => 0x10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # 'Read/Write Multiple Registers' => 0x17, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | #my %area_and_mode_for = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 4 | my %can_read_zone = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0x01 => ['discrete_coils', 'read' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0x02 => ['discrete_inputs', 'read' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0x03 => ['holding_registers', 'read' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0x04 => ['input_registers', 'read' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0x17 => ['holding_registers', 'read' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 4 | my %can_write_zone = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0x05 => ['discrete_coils', 'write' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0x06 => ['holding_registers', 'write' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0x0F => ['discrete_coils', 'write' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0x10 => ['holding_registers', 'write' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0x17 => ['holding_registers', 'write' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 15 | ▶ | sub modbus_server { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
modbus_server: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 15 | my ($server, $adu) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | ### Make sure the requested unit exists in this server | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 15 | ▶ | unless (exists $server->units->{$adu->unit}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | return $server->request_for_others($adu); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | ### Process write requests first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 15 | ▶ | if (exists $can_write_zone{ $adu->code }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 7 | my ($zone, $mode) = @{$can_write_zone{$adu->code}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 7 | my $resp = $server->process_write_requests($adu, $zone, $mode); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 7 | ▶ | return $resp if $resp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | ### Process read requests last | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 9 | my ($zone, $mode) = @{$can_read_zone{$adu->code}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 9 | my $resp = $server->process_read_requests($adu, $zone, $mode); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 9 | return $resp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 7 | ▶ | sub process_write_requests { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_write_requests: called CC=11 SCAR=24.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 7 | my ($server, $adu, $zone, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 7 | my $unit = $server->get_server_unit($adu->unit); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 7 | my $code = $adu->code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 7 | ▶ | my $address = $adu->message->{address} // $adu->message->{write_address}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$adu->message->{"address"} // $adu->message->{"write_address"}
MC/DC0%0/2
$adu->message->{"address"} // $adu->message->{"write_address"}
$adu->message->{"address"}
$adu->message->{"write_address"}
Truth table66%2/3
A // B
A= $adu->message->{"address"}B= $adu->message->{"write_address"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 7 | ▶ | my $values = $adu->message->{values} // [ $adu->message->{value} ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$adu->message->{"values"} // [$adu->message->{"value"}]
MC/DC100%1/1
$adu->message->{"values"} // [$adu->message->{"value"}]
$adu->message->{"values"}
Truth table100%2/2
A
A= $adu->message->{"values"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 7 | my $quantity = @$values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # Find the requested address within unit's addresses | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 7 | $server->log(4, "Routing 'write' zone: <$zone> address: <$address> qty: <$quantity>"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 7 | my $match = $unit->route($zone, $mode, $address, $quantity); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 7 | ▶ | $server->log(4, 'Match was' . (ref $match ? ' ' : ' not ') . 'successful'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | return Device::Modbus::Exception->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 7 | ▶ | function => $Device::Modbus::function_for{$code}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | exception_code => $match, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | unit => $adu->unit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | ) unless ref $match; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # Execute the requested route with the given parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 4 | my $response; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 4 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 4 | $match->routine->($unit, $server, $adu->message, $address, $quantity, $values); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | $server->log(4, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | "Action failed for 'write' zone: <$zone> address: <$address> quantity: <$quantity> error: $_ "); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | $response = Device::Modbus::Exception->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | function => $Device::Modbus::function_for{$code}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | exception_code => 4, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | unit => $adu->unit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 4 | ▶ | return $response if defined $response; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # Build the response | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # Write single values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 3 | ▶ | if ($code == 0x05 || $code == 0x06) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$code == 5 or $code == 6
MC/DC50%1/2
$code == 5 or $code == 6
$code == 5
$code == 6
Truth table66%2/3
A or B
A= $code == 5B= $code == 6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 1 | $response = Device::Modbus::Response->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | code => $code, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | address => $address, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | value => $values->[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | # Write multiple values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | ▶ | elsif ($code == 0x0F || $code == 0x10) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$code == 15 or $code == 16
MC/DC50%1/2
$code == 15 or $code == 16
$code == 15
$code == 16
Truth table66%2/3
A or B
A= $code == 15B= $code == 16
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 1 | $response = Device::Modbus::Response->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | code => $code, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | address => $address, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | quantity => $quantity | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | elsif ($code == 0x17) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # 0x17 must perform a read operation afterwards | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 1 | $response = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 3 | return $response; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 9 | ▶ | sub process_read_requests { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_read_requests: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 9 | my ($server, $adu, $zone, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 9 | my $unit = $server->get_server_unit($adu->unit); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 9 | my $code = $adu->code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 9 | ▶ | my $address = $adu->message->{address} // $adu->message->{write_address}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$adu->message->{"address"} // $adu->message->{"write_address"}
MC/DC0%0/2
$adu->message->{"address"} // $adu->message->{"write_address"}
$adu->message->{"address"}
$adu->message->{"write_address"}
Truth table66%2/3
A // B
A= $adu->message->{"address"}B= $adu->message->{"write_address"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 9 | ▶ | my $quantity = $adu->message->{quantity} // $adu->message->{read_quantity}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$adu->message->{"quantity"} // $adu->message->{"read_quantity"}
MC/DC0%0/2
$adu->message->{"quantity"} // $adu->message->{"read_quantity"}
$adu->message->{"quantity"}
$adu->message->{"read_quantity"}
Truth table66%2/3
A // B
A= $adu->message->{"quantity"}B= $adu->message->{"read_quantity"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 9 | $server->log(4, "Routing 'read' zone: <$zone> address: <$address> quantity: <$quantity>"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 9 | my $match = $unit->route($zone, 'read', $address, $quantity); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 9 | ▶ | $server->log(4, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 'Match was' . (ref $match ? ' ' : ' not ') . 'successful'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | return Device::Modbus::Exception->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 9 | ▶ | function => $Device::Modbus::function_for{$code}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | exception_code => $match, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | unit => $adu->unit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | ) unless ref $match; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 4 | my @vals; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | my $response; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 4 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 4 | @vals = $match->routine->($unit, $server, $adu->message, $address, $quantity); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 3 | ▶ | croak 'Quantity of returned values differs from request' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | unless scalar @vals == $quantity; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 2 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 2 | $server->log(4, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | "Action failed for 'read' zone: <$zone> address: <$address> quantity: <$quantity> -- $_"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | $response = Device::Modbus::Exception->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 2 | function => $Device::Modbus::function_for{$code}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | exception_code => 4, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | unit => $adu->unit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 4 | ▶ | unless (defined $response) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 2 | $response = Device::Modbus::Response->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | code => $code, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | values => \@vals | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 4 | return $response; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||