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-2006 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             # $Id$
13              
14             package Sms::Token::PDUTYPE;
15 6     6   33 use integer;
  6         12  
  6         29  
16 6     6   153 use strict;
  6         12  
  6         167  
17 6     6   29 use Device::Gsm::Sms::Token;
  6         10  
  6         3847  
18              
19             @Sms::Token::PDUTYPE::ISA = ('Sms::Token');
20              
21             # takes (scalar message (string) reference)
22             # returns success/failure of decoding
23             # if all ok, removes PDUTYPE from message
24             sub decode {
25 8     8   14 my ($self, $rMessage) = @_;
26 8         11 my $ok = 0;
27              
28 8         36 $self->data(substr($$rMessage, 0, 2));
29              
30             # Update PDU type flags into token object
31 8         42 $self->set('pdutype', hex(substr($$rMessage, 0, 2)));
32 8         25 $self->set('MTI', $self->MTI());
33 8         21 $self->set('MMS', $self->MMS());
34 8         22 $self->set('RD', $self->RD());
35 8         26 $self->set('VPF', $self->VPF());
36 8         26 $self->set('SRR', $self->SRR());
37 8         22 $self->set('SRI', $self->SRI());
38 8         23 $self->set('UDHI', $self->UDHI());
39 8         19 $self->set('RP', $self->RP());
40              
41             # Remove PDU TYPE from message
42 8         26 $$rMessage = substr($$rMessage, 2);
43              
44 8         25 return 1;
45             }
46              
47             #
48             # [token]->encode( [$data] )
49             #
50             # takes internal token data and encodes it, returning the result
51             # or undef value in case of errors
52             #
53             sub encode {
54 0     0   0 my $self = shift;
55              
56             # Take supplied data (optional) or object internal data
57 0         0 my $data = shift;
58 0 0 0     0 if (!defined $data || $data eq '') {
59 0         0 $data = $self->data();
60             }
61              
62 0         0 return $data;
63             }
64              
65             #--------------------------------------------
66             # Bit component flags
67              
68             sub RP { # REPLY PATH PARAMETER SET
69 8     8   13 my $self = shift;
70 8         19 ($self->get('pdutype') & 0x80) >> 7;
71             }
72              
73             sub UDHI { # USER DATA HEADER PRESENT
74 16     16   42 my $self = shift;
75 16         37 ($self->get('pdutype') & 0x40) >> 6;
76             }
77              
78             sub SRR { # STATUS REPORT REQUESTED
79 8     8   10 my $self = shift;
80 8         23 ($self->get('pdutype') & 0x20) >> 5;
81             }
82              
83             sub SRI { # STATUS REPORT WILL BE RETURNED
84 8     8   12 my $self = shift;
85 8         22 ($self->get('pdutype') & 0x20) >> 5;
86             }
87              
88             sub VPF
89             { # VALIDITY PERIOD FLAG 0=not present, 1=reserved, 2=integer, 3=semioctet
90 10     10   17 my $self = shift;
91 10         30 ($self->get('pdutype') & 0x18) >> 3;
92             }
93              
94             sub MMS { # MORE MESSAGES WAITING AT SMS-C
95 8     8   15 my $self = shift;
96 8         23 ($self->get('pdutype') & 0x04) >> 2;
97             }
98              
99             sub RD { # ... allow repeated sending (REJECT DUPLICATES)
100 8     8   20 my $self = shift;
101 8         20 ($self->get('pdutype') & 0x04) >> 2;
102             }
103              
104             sub MTI
105             { # TYPE OF SMS (0x00=SMS-DELIVER, 0x01=SMS-SUBMIT, 0x10=SMS-STATUS/COMMAND, 0x11=RESERVED
106 16     16   24 my $self = shift;
107 16         45 $self->get('pdutype') & 0x03;
108             }
109              
110             1;