| 1 | package Device::Modbus::Exception; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use parent 'Device::Modbus'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use overload '""' => \&stringify; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 13 | my %exc_descr_for = ( | |||||||||||||||||||||||||||||||||||||||||
| 11 | 1 => '1 - Function code not supported', | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 => '2 - Incorrect address or address not supported', | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 => '3 - Invalid data (either quantity or values)', | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 => '4 - Execution failed', | ||||||||||||||||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 66 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=11 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 66 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | # Must receive either a function name or a function code | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 66 | ▶ | unless (exists $args{function} or exists $args{code}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $args{"function"} or exists $args{"code"}
MC/DC100%2/2
exists $args{"function"} or exists $args{"code"}
exists $args{"function"}
exists $args{"code"}
Truth table100%3/3
A or B
A= exists $args{"function"}B= exists $args{"code"}
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | croak 'Please specify either a function name or code to instantiate an exception'; | |||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 65 | ▶ | if (exists $args{function} && exists $Device::Modbus::code_for{$args{function}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
exists $args{"function"} and exists $Device::Modbus::code_for{$args{"function"}}
MC/DC100%2/2
exists $args{"function"} and exists $Device::Modbus::code_for{$args{"function"}}
exists $args{"function"}
exists $Device::Modbus::code_for{$args{"function"}}
Truth table100%3/3
A and B
A= exists $args{"function"}B= exists $Device::Modbus::code_for{$args{"function"}}
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 12 | $args{code} = $Device::Modbus::code_for{$args{function}} + 0x80; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | ▶ | elsif (exists $args{code} && exists $Device::Modbus::function_for{$args{code} - 0x80}) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
exists $args{"code"} and exists $Device::Modbus::function_for{$args{"code"} - 128}
MC/DC100%2/2
exists $args{"code"} and exists $Device::Modbus::function_for{$args{"code"} - 128}
exists $args{"code"}
exists $Device::Modbus::function_for{$args{"code"} - 128}
Truth table100%3/3
A and B
A= exists $args{"code"}B= exists $Device::Modbus::function_for{$args{"code"} - 128}
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 50 | $args{function} = $Device::Modbus::function_for{$args{code} - 0x80}; | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | elsif (exists $args{code}) { | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | $args{function} = 'Non-supported function'; | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | croak "Function $args{function} is not supported"; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | # Must receive an exception code | ||||||||||||||||||||||||||||||||||||||||||
| 39 | croak 'A valid exception code (between 1 and 4) is required' | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 64 | ▶ | unless exists $args{exception_code} && $args{exception_code} > 0 && $args{exception_code} <= 4; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
exists $args{"exception_code"} and $args{"exception_code"} > 0 and $args{"exception_code"} <= 4
exists $args{"exception_code"} and $args{"exception_code"} > 0
MC/DC100%3/3
exists $args{"exception_code"} and $args{"exception_code"} > 0 and $args{"exception_code"} <= 4
exists $args{"exception_code"}
$args{"exception_code"} > 0
$args{"exception_code"} <= 4
Truth table100%4/4
A and B and C
A= exists $args{"exception_code"}B= $args{"exception_code"} > 0C= $args{"exception_code"} <= 4
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 61 | return bless \%args, $class; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | sub pdu { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pdu: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | return pack('CC', $self->{code}, $self->{exception_code}); | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 26 | ▶ | sub stringify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 26 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 26 | ▶ | my $str = $Device::Modbus::function_for{$self->{code}-0x80} // 'Unknown'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$Device::Modbus::function_for{$self->{"code"} - 128} // "Unknown"
MC/DC100%1/1
$Device::Modbus::function_for{$self->{"code"} - 128} // "Unknown"
$Device::Modbus::function_for{$self->{"code"} - 128}
Truth table100%2/2
A
A= $Device::Modbus::function_for{$self->{"code"} - 128}
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 26 | my $descr = $exc_descr_for{$self->{exception_code}}; | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 26 | return "Exception for function <$str>: $descr"; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||