File Coverage

blib/lib/BACnet/BVLC.pm
Criterion Covered Total %
statement 6 32 18.7
branch 0 6 0.0
condition n/a
subroutine 2 6 33.3
pod 0 4 0.0
total 8 48 16.6


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package BACnet::BVLC;
4              
5 27     27   14042 use warnings;
  27         51  
  27         1584  
6 27     27   180 use strict;
  27         46  
  27         11163  
7              
8             sub construct {
9 0     0 0   my ( $class, $function, $data ) = @_;
10              
11 0           my $self = { 'data' => '', };
12              
13             # Type: BACnet/IP (Annex J)
14 0           $self->{'data'} .= pack( 'C', 0x81 );
15              
16             # Function
17 0           for ($function) {
18 0 0         $_ eq 'Original-Unicast-NPDU' and do {
19 0           $self->{'data'} .= pack( 'C', 0x0a );
20 0           last;
21             };
22             }
23              
24             # BVLC-Length
25 0           $self->{'data'} .= pack( 'n', ( length $data ) + 4 );
26              
27 0           $self->{'data'} .= $data;
28              
29 0           return bless $self, $class;
30             }
31              
32             sub parse {
33 0     0 0   my ( $class, $data ) = @_;
34              
35 0           my $self = bless { 'data' => $data, }, $class;
36              
37 0           my @data = unpack( 'C*', $data );
38              
39 0 0         if ( $data[0] != 0x81 ) {
40 0           $self->{'error'} = 'BVLC: invalid type';
41 0           return $self;
42             }
43              
44 0 0         if ( $data[1] != 0x0a ) {
45 0           $self->{'error'} = 'BVLC: function is not Original-Unicast-NPDU';
46 0           return $self;
47             }
48              
49 0           bless $self, 'BACnet::NPDU';
50              
51 0           $self->parse( substr $data, 4 );
52              
53 0           return $self;
54             }
55              
56             sub data {
57 0     0 0   my ($self) = shift;
58              
59 0           return $self->{'data'};
60             }
61              
62             sub dump {
63 0     0 0   my ($self) = shift;
64              
65 0           return join ' ', unpack( '(H2)*', $self->{'data'} );
66             }
67              
68             1;