File Coverage

blib/lib/Device/Gsm/Sms/Token/PDUTYPE.pm
Criterion Covered Total %
statement 39 44 88.6
branch 0 2 0.0
condition 0 3 0.0
subroutine 12 13 92.3
pod n/a
total 51 62 82.2


line stmt bran cond sub pod time code
1             # Sms::Token::PDUTYPE - SMS PDU TYPE token (type of message)
2             # Copyright (C) 2002-2015 Cosimo Streppone, cosimo@cpan.org
3             #
4             # This program is free software; you can redistribute it and/or modify
5             # it only under the terms of Perl itself.
6             #
7             # This program is distributed in the hope that it will be useful,
8             # but WITHOUT ANY WARRANTY; without even the implied warranty of
9             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10             # Perl licensing terms for details.
11              
12             package Sms::Token::PDUTYPE;
13 7     7   21 use integer;
  7         7  
  7         36  
14 7     7   144 use strict;
  7         5  
  7         90  
15 7     7   19 use Device::Gsm::Sms::Token;
  7         8  
  7         2048  
16              
17             @Sms::Token::PDUTYPE::ISA = ('Sms::Token');
18              
19             # takes (scalar message (string) reference)
20             # returns success/failure of decoding
21             # if all ok, removes PDUTYPE from message
22             sub decode {
23 16     16   12 my ($self, $rMessage) = @_;
24 16         11 my $ok = 0;
25              
26 16         43 $self->data(substr($$rMessage, 0, 2));
27              
28             # Update PDU type flags into token object
29 16         46 $self->set('pdutype', hex(substr($$rMessage, 0, 2)));
30 16         25 $self->set('MTI', $self->MTI());
31 16         25 $self->set('MMS', $self->MMS());
32 16         22 $self->set('RD', $self->RD());
33 16         20 $self->set('VPF', $self->VPF());
34 16         25 $self->set('SRR', $self->SRR());
35 16         21 $self->set('SRI', $self->SRI());
36 16         23 $self->set('UDHI', $self->UDHI());
37 16         19 $self->set('RP', $self->RP());
38              
39             # Remove PDU TYPE from message
40 16         22 $$rMessage = substr($$rMessage, 2);
41              
42 16         32 return 1;
43             }
44              
45             #
46             # [token]->encode( [$data] )
47             #
48             # takes internal token data and encodes it, returning the result
49             # or undef value in case of errors
50             #
51             sub encode {
52 0     0   0 my $self = shift;
53              
54             # Take supplied data (optional) or object internal data
55 0         0 my $data = shift;
56 0 0 0     0 if (!defined $data || $data eq '') {
57 0         0 $data = $self->data();
58             }
59              
60 0         0 return $data;
61             }
62              
63             #--------------------------------------------
64             # Bit component flags
65              
66             sub RP { # REPLY PATH PARAMETER SET
67 16     16   13 my $self = shift;
68 16         22 ($self->get('pdutype') & 0x80) >> 7;
69             }
70              
71             sub UDHI { # USER DATA HEADER PRESENT
72 32     32   22 my $self = shift;
73 32         44 ($self->get('pdutype') & 0x40) >> 6;
74             }
75              
76             sub SRR { # STATUS REPORT REQUESTED
77 16     16   10 my $self = shift;
78 16         25 ($self->get('pdutype') & 0x20) >> 5;
79             }
80              
81             sub SRI { # STATUS REPORT WILL BE RETURNED
82 16     16   13 my $self = shift;
83 16         19 ($self->get('pdutype') & 0x20) >> 5;
84             }
85              
86             sub VPF
87             { # VALIDITY PERIOD FLAG 0=not present, 1=reserved, 2=integer, 3=semioctet
88 18     18   17 my $self = shift;
89 18         24 ($self->get('pdutype') & 0x18) >> 3;
90             }
91              
92             sub MMS { # MORE MESSAGES WAITING AT SMS-C
93 16     16   13 my $self = shift;
94 16         23 ($self->get('pdutype') & 0x04) >> 2;
95             }
96              
97             sub RD { # ... allow repeated sending (REJECT DUPLICATES)
98 16     16   14 my $self = shift;
99 16         21 ($self->get('pdutype') & 0x04) >> 2;
100             }
101              
102             sub MTI
103             { # TYPE OF SMS (0x00=SMS-DELIVER, 0x01=SMS-SUBMIT, 0x10=SMS-STATUS/COMMAND, 0x11=RESERVED
104 32     32   20 my $self = shift;
105 32         51 $self->get('pdutype') & 0x03;
106             }
107              
108             1;