line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Sms::Token::DCS - SMS DCS (data coding scheme) token |
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::DCS; |
13
|
2
|
|
|
2
|
|
7
|
use integer; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
7
|
|
14
|
2
|
|
|
2
|
|
40
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
24
|
|
15
|
2
|
|
|
2
|
|
6
|
use Device::Gsm::Sms::Token; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
222
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
@Sms::Token::DCS::ISA = ('Sms::Token'); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# takes (scalar message (string) reference) |
20
|
|
|
|
|
|
|
# returns success/failure of decoding |
21
|
|
|
|
|
|
|
# if all ok, removes token from message |
22
|
|
|
|
|
|
|
sub decode { |
23
|
14
|
|
|
14
|
|
9
|
my ($self, $rMessage) = @_; |
24
|
14
|
|
|
|
|
10
|
my $ok = 0; |
25
|
|
|
|
|
|
|
|
26
|
14
|
|
|
|
|
35
|
$self->data(hex substr($$rMessage, 0, 2)); |
27
|
14
|
|
|
|
|
30
|
$self->state(Sms::Token::DECODED); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Remove DCS from message |
30
|
14
|
|
|
|
|
16
|
$$rMessage = substr($$rMessage, 2); |
31
|
|
|
|
|
|
|
|
32
|
14
|
|
|
|
|
29
|
return 1; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# |
36
|
|
|
|
|
|
|
# [token]->encode( [$data] ) |
37
|
|
|
|
|
|
|
# |
38
|
|
|
|
|
|
|
# takes internal token data and encodes it, returning the result |
39
|
|
|
|
|
|
|
# or undef value in case of errors |
40
|
|
|
|
|
|
|
# |
41
|
|
|
|
|
|
|
sub encode { |
42
|
0
|
|
|
0
|
|
|
my $self = shift; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Take supplied data (optional) or object internal data |
45
|
0
|
|
|
|
|
|
my $data = shift; |
46
|
0
|
0
|
0
|
|
|
|
if (!defined $data || $data eq '') { |
47
|
0
|
|
|
|
|
|
$data = $self->data(); |
48
|
0
|
|
0
|
|
|
|
$data ||= '00'; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
return $data; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |