File Coverage

blib/lib/BACnet/PDUTypes/SimpleACK.pm
Criterion Covered Total %
statement 39 43 90.7
branch 2 4 50.0
condition n/a
subroutine 10 10 100.0
pod 0 5 0.0
total 51 62 82.2


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package BACnet::PDUTypes::SimpleACK;
4              
5 27     27   202 use warnings;
  27         60  
  27         1649  
6 27     27   150 use strict;
  27         49  
  27         633  
7              
8 27     27   161 use bytes;
  27         63  
  27         152  
9              
10 27     27   767 use BACnet::APDU;
  27         50  
  27         905  
11              
12             require BACnet::PDUTypes::Utils;
13              
14 27     27   117 use parent 'BACnet::PDUTypes::PDU';
  27         50  
  27         140  
15              
16             sub construct {
17 2     2 0 160726 my ( $class, @rest ) = @_;
18              
19 2         7 my %args = (
20             invoke_id => undef,
21             service_choice => undef,
22             @rest,
23             );
24              
25             my $self = {
26             data => '',
27             invoke_id => $args{invoke_id},
28             service_choice => $args{service_choice},
29 2         10 };
30              
31             $self->{data} .=
32 2         16 pack( 'C', ( $BACnet::APDU::apdu_types->{'Simple-ACK'} << 4 ) );
33              
34 2         5 $self->{data} .= pack( 'C', $args{invoke_id} );
35              
36             $self->{data} .= pack(
37             'C',
38             $BACnet::PDUTypes::Utils::confirmed_service->{
39             $self->{service_choice}
40             }
41 2         8 );
42              
43 2         6 return bless $self, $class;
44              
45             #flags are 0000
46              
47             }
48              
49             sub parse {
50              
51 2     2 0 7 my ( $class, $data_in ) = @_;
52              
53 2         5 my $self = bless { data => $data_in, }, $class;
54              
55 2 50       6 if ( length($data_in) < 3 ) {
56 0         0 $self->{error} = "Simple ACK: too short";
57 0         0 return $self;
58             }
59              
60 2         5 my $offset = 0;
61 2         3 $offset += 1;
62              
63 2         9 $self->{invoke_id} = unpack( 'C', substr( $data_in, $offset, 1 ) );
64 2         4 $offset += 1;
65              
66             my $service_choice = $BACnet::PDUTypes::Utils::confirmed_service_rev->{
67 2         8 unpack( 'C', substr( $data_in, $offset, 1 ) ) };
68              
69 2 50       6 if ( !defined $service_choice ) {
70 0         0 $self->{error} = "Simple ACK: unknown service choice";
71 0         0 return $self;
72             }
73              
74 2         4 $self->{service_choice} = $service_choice;
75              
76 2         4 return $self;
77             }
78              
79             sub service_choice {
80 4     4 0 1915 my ($self) = @_;
81              
82 4         12 return $self->{service_choice};
83             }
84              
85             sub invoke_id {
86 4     4 0 8 my ($self) = @_;
87              
88 4         10 return $self->{invoke_id};
89             }
90              
91             sub flags {
92 4     4 0 7 my ($self) = @_;
93              
94 4         10 return 0;
95             }
96              
97             1;