File Coverage

blib/lib/BACnet/NPDU.pm
Criterion Covered Total %
statement 9 24 37.5
branch 0 2 0.0
condition n/a
subroutine 3 5 60.0
pod 0 2 0.0
total 12 33 36.3


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package BACnet::NPDU;
4              
5 27     27   12411 use strict;
  27         62  
  27         1019  
6 27     27   141 use warnings;
  27         52  
  27         1654  
7              
8 27     27   141 use parent 'BACnet::BVLC';
  27         42  
  27         223  
9              
10             sub construct {
11 0     0 0   my ($class, $apdu_data) = @_;
12              
13 0           my $data = '';
14              
15             # Version: ASHRAE 135-1995
16 0           $data .= pack('C', 0x01);
17              
18             # Control: bit-field
19             # - 0x04 = Expecting Reply: BACnet-Confirmed-Request-PDU
20 0           $data .= pack('C', 0x04);
21              
22 0           $data .= $apdu_data;
23              
24 0           my $self = BACnet::BVLC->construct('Original-Unicast-NPDU', $data);
25              
26 0           return bless $self, $class;
27             }
28              
29             sub parse {
30 0     0 0   my ($self, $data) = @_;
31              
32 0           my @data = unpack('C*', $data);
33              
34 0 0         if ($data[0] != 0x01) {
35 0           $self->{'error'} = 'NPDU: Invalid version';
36 0           return $self;
37             }
38              
39             #if ($data[1] != 0x00) {
40             # $self->{'error'} = 'NPDU: Invalid control';
41             # return $self;
42             #}
43              
44 0           bless $self, 'BACnet::APDU';
45              
46 0           $self->parse(substr $data, 2);
47              
48 0           return $self;
49             }
50              
51             1;
52