| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::EMI::Common; |
|
2
|
1
|
|
|
1
|
|
15619
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
43
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
7
|
use vars qw($VERSION); |
|
|
1
|
|
|
|
|
65
|
|
|
|
1
|
|
|
|
|
393
|
|
|
5
|
|
|
|
|
|
|
$VERSION='1.01'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
########################################################################################################### |
|
8
|
|
|
|
|
|
|
# Since 'constants' are actually implemented as subs, |
|
9
|
|
|
|
|
|
|
# they can be called from the outside as any other class method. |
|
10
|
1
|
|
|
1
|
|
14
|
use constant STX=>chr(2); |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
94
|
|
|
11
|
1
|
|
|
1
|
|
5
|
use constant ETX=>chr(3); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
52
|
|
|
12
|
1
|
|
|
1
|
|
8
|
use constant UCP_DELIMITER=>'/'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
41
|
|
|
13
|
1
|
|
|
1
|
|
5
|
use constant DEF_SMSC_PORT=>3024; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
52
|
|
|
14
|
1
|
|
|
1
|
|
5
|
use constant ACK=>'A'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
52
|
|
|
15
|
1
|
|
|
1
|
|
4
|
use constant NACK=>'N'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1310
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
########################################################################################################### |
|
18
|
|
|
|
|
|
|
sub new { |
|
19
|
0
|
|
|
0
|
1
|
|
my$self={}; |
|
20
|
0
|
|
|
|
|
|
bless($self,shift())->_init(@_); |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
########################################################################################################### |
|
24
|
|
|
|
|
|
|
# Calculate packet checksum |
|
25
|
|
|
|
|
|
|
sub checksum { |
|
26
|
0
|
|
|
0
|
1
|
|
shift; # Ignore $self. |
|
27
|
0
|
0
|
|
|
|
|
defined($_[0])||return(0); |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my$checksum=0; |
|
30
|
0
|
|
|
|
|
|
for(split(//,shift)) { |
|
31
|
0
|
|
|
|
|
|
$checksum+=ord; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
# 2003-Apr-24 Rainer Thieringer: format string corrected from %X to %02X. |
|
34
|
0
|
|
|
|
|
|
sprintf("%02X",$checksum%256); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
########################################################################################################### |
|
38
|
|
|
|
|
|
|
# Calculate data length |
|
39
|
|
|
|
|
|
|
sub data_len { |
|
40
|
0
|
|
|
0
|
1
|
|
my$len=length(pop @_)+17; |
|
41
|
0
|
|
|
|
|
|
for(1..(5-length($len))) { |
|
42
|
0
|
|
|
|
|
|
$len='0'.$len; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
0
|
|
|
|
|
|
$len; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
########################################################################################################### |
|
48
|
|
|
|
|
|
|
# The first 'octet' in the string returned will contain the length of the remaining user data. |
|
49
|
|
|
|
|
|
|
sub encode_7bit { |
|
50
|
0
|
|
|
0
|
1
|
|
my($self,$msg)=@_; |
|
51
|
0
|
|
|
|
|
|
my($bit_string,$user_data)=('',''); |
|
52
|
0
|
|
|
|
|
|
my($octet,$rest); |
|
53
|
|
|
|
|
|
|
|
|
54
|
0
|
0
|
0
|
|
|
|
defined($msg)&&length($msg)||return('00'); # Zero length user data. |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
for(split(//,$msg)) { |
|
57
|
0
|
|
|
|
|
|
$bit_string.=unpack('b7',$_); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#print("Bitstring:$bit_string\n"); |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
|
0
|
|
|
|
while(defined($bit_string)&&(length($bit_string))) { |
|
63
|
0
|
|
|
|
|
|
$rest=$octet=substr($bit_string,0,8); |
|
64
|
0
|
|
|
|
|
|
$user_data.=unpack("H2",pack("b8",substr($octet.'0'x7,0,8))); |
|
65
|
0
|
0
|
|
|
|
|
$bit_string=(length($bit_string)>8)?substr($bit_string,8):''; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
sprintf("%02X",length($rest)<5?length($user_data)-1:length($user_data)).uc($user_data); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
########################################################################################################### |
|
72
|
|
|
|
|
|
|
sub ia5_decode { |
|
73
|
0
|
|
|
0
|
1
|
|
my($self,$message)=@_; |
|
74
|
0
|
|
|
|
|
|
my($decoded,$i); |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
0
|
0
|
|
|
|
defined($message)&&length($message)||return(''); |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
for($i=0;$i<=length($message);$i+=2) { |
|
79
|
0
|
|
|
|
|
|
$decoded.=chr(hex(substr($message,$i,2))); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
0
|
|
|
|
|
|
$decoded; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
########################################################################################################### |
|
85
|
|
|
|
|
|
|
sub ia5_encode { |
|
86
|
0
|
|
|
0
|
1
|
|
join('',map{sprintf "%X",ord} split(//,pop(@_))); |
|
|
0
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
########################################################################################################### |
|
90
|
|
|
|
|
|
|
########################################################################################################### |
|
91
|
|
|
|
|
|
|
# |
|
92
|
|
|
|
|
|
|
# 'Internal' subs. Don't call these since they may, and will, change without notice. |
|
93
|
|
|
|
|
|
|
# |
|
94
|
|
|
|
|
|
|
########################################################################################################### |
|
95
|
|
|
|
|
|
|
########################################################################################################### |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
########################################################################################################### |
|
98
|
|
|
|
|
|
|
sub _init { |
|
99
|
0
|
|
|
0
|
|
|
shift; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
########################################################################################################### |
|
103
|
|
|
|
|
|
|
'Choppers rule'; |
|
104
|
|
|
|
|
|
|
__END__ |