File Coverage

blib/lib/BACnet/DataTypes/Time.pm
Criterion Covered Total %
statement 44 46 95.6
branch 1 2 50.0
condition n/a
subroutine 12 12 100.0
pod 0 7 0.0
total 57 67 85.0


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package BACnet::DataTypes::Time;
4              
5 27     27   166 use warnings;
  27         51  
  27         1527  
6 27     27   128 use strict;
  27         89  
  27         738  
7              
8 27     27   115 use BACnet::DataTypes::Utils;
  27         37  
  27         645  
9              
10 27     27   105 use parent 'BACnet::DataTypes::DataType';
  27         43  
  27         132  
11              
12 27     27   3552 use constant { LENGTH => 0x04 };
  27         64  
  27         16781  
13              
14             # this did not check if the date make sense or not, because someone may want to use some weird calendar
15              
16             sub construct {
17 8     8 0 260415 my ( $class, $hour, $minute, $second, $centisecond, $modified_tag ) = @_;
18              
19 8         50 my $self = {
20             data => '',
21             hour => $hour,
22             minute => $minute,
23             second => $second,
24             centisecond => $centisecond,
25             };
26              
27 8         48 $self->{data} .= BACnet::DataTypes::Utils::_construct_head(
28             BACnet::DataTypes::Utils::TIME_TAG,
29             $modified_tag, LENGTH );
30              
31             $self->{data} .=
32 8         45 BACnet::DataTypes::Utils::_encode_int_octet_undef( $hour, 0xFF );
33             $self->{data} .=
34 8         24 BACnet::DataTypes::Utils::_encode_int_octet_undef( $minute, 0xFF );
35             $self->{data} .=
36 8         27 BACnet::DataTypes::Utils::_encode_int_octet_undef( $second, 0xFF );
37             $self->{data} .=
38 8         21 BACnet::DataTypes::Utils::_encode_int_octet_undef( $centisecond, 0xFF );
39              
40 8         29 return bless $self, $class;
41             }
42              
43             sub parse {
44 8     8 0 21 my ( $class, $data_in ) = @_;
45              
46 8         21 my $data = substr $data_in, 1;
47 8         25 my $self = bless { data => $data_in, }, $class;
48              
49 8         40 my $headache = BACnet::DataTypes::Utils::_correct_head(
50             data_in => $data_in,
51             expected_tag => BACnet::DataTypes::Utils::TIME_TAG,
52             expected_length => LENGTH,
53             );
54              
55 8 50       58 if ( $headache ne "" ) {
56 0         0 $self->{error} = "Time: $headache";
57 0         0 return $self;
58             }
59              
60 8         22 my $head_len = BACnet::DataTypes::Utils::_get_head_length($data_in);
61              
62             $self->{hour} =
63 8         46 BACnet::DataTypes::Utils::_decode_int_octet_undef(
64             substr( $data_in, $head_len, 1 ), 0xFF );
65             $self->{minute} =
66 8         30 BACnet::DataTypes::Utils::_decode_int_octet_undef(
67             substr( $data_in, $head_len + 1, 1 ), 0xFF );
68             $self->{second} =
69 8         25 BACnet::DataTypes::Utils::_decode_int_octet_undef(
70             substr( $data_in, $head_len + 2, 1 ), 0xFF );
71             $self->{centisecond} =
72 8         28 BACnet::DataTypes::Utils::_decode_int_octet_undef(
73             substr( $data_in, $head_len + 3, 1 ), 0xFF );
74              
75 8         26 return $self;
76             }
77              
78             sub val {
79 16     16 0 3227 my ($self) = @_;
80              
81             return return [
82             $self->{hour}, $self->{minute},
83             $self->{second}, $self->{centisecond}
84 16         66 ];
85             }
86              
87             sub hour {
88 8     8 0 2802 my ($self) = @_;
89              
90 8         34 return $self->{hour};
91             }
92              
93             sub minute {
94 8     8 0 18 my ($self) = @_;
95              
96 8         31 return $self->{minute};
97             }
98              
99             sub second {
100 8     8 0 49 my ($self) = @_;
101              
102 8         33 return $self->{second};
103             }
104              
105             sub centisecond {
106 8     8 0 20 my ($self) = @_;
107              
108 8         34 return $self->{centisecond};
109             }
110              
111             1;