| 1 | package Net::EMI::Common; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | $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 | ▶ | use constant STX=>chr(2); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use constant ETX=>chr(3); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use constant UCP_DELIMITER=>'/'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use constant DEF_SMSC_PORT=>3024; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use constant ACK=>'A'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use constant NACK=>'N'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | ########################################################################################################### | ||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 0 | my$self={}; | |||||||||||||||||||||||||||
| 20 | 0 | bless($self,shift())->_init(@_); | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | ########################################################################################################### | ||||||||||||||||||||||||||||
| 24 | # Calculate packet checksum | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub checksum { | ||||||||||||||||||||||||||
|
Subroutine
checksum: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 0 | shift; # Ignore $self. | |||||||||||||||||||||||||||
| 27 | 0 | ▶ | defined($_[0])||return(0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub data_len { | ||||||||||||||||||||||||||
|
Subroutine
data_len: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 0 | 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 | 0 | ▶ | sub encode_7bit { | ||||||||||||||||||||||||||
|
Subroutine
encode_7bit: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 0 | my($self,$msg)=@_; | |||||||||||||||||||||||||||
| 51 | 0 | my($bit_string,$user_data)=('',''); | |||||||||||||||||||||||||||
| 52 | 0 | my($octet,$rest); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | defined($msg)&&length($msg)||return('00'); # Zero length user data. | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $msg and length $msg
MC/DC0%0/2
defined $msg and length $msg
defined $msg
length $msg
Truth table0%0/3
A and B
A= defined $msgB= length $msg
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | for(split(//,$msg)) { | |||||||||||||||||||||||||||
| 57 | 0 | $bit_string.=unpack('b7',$_); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | #print("Bitstring:$bit_string\n"); | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | while(defined($bit_string)&&(length($bit_string))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $bit_string and length $bit_string
MC/DC0%0/2
defined $bit_string and length $bit_string
defined $bit_string
length $bit_string
Truth table0%0/3
A and B
A= defined $bit_stringB= 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 | ▶ | $bit_string=(length($bit_string)>8)?substr($bit_string,8):''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sprintf("%02X",length($rest)<5?length($user_data)-1:length($user_data)).uc($user_data); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | ########################################################################################################### | ||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub ia5_decode { | ||||||||||||||||||||||||||
|
Subroutine
ia5_decode: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 0 | my($self,$message)=@_; | |||||||||||||||||||||||||||
| 74 | 0 | my($decoded,$i); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | defined($message)&&length($message)||return(''); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $message and length $message
MC/DC0%0/2
defined $message and length $message
defined $message
length $message
Truth table0%0/3
A and B
A= defined $messageB= length $message
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | for($i=0;$i<=length($message);$i+=2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | $decoded.=chr(hex(substr($message,$i,2))); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 0 | $decoded; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | ########################################################################################################### | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub ia5_encode { | ||||||||||||||||||||||||||
|
Subroutine
ia5_encode: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 0 | join('',map{sprintf "%X",ord} split(//,pop(@_))); | |||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub _init { | ||||||||||||||||||||||||||
|
Subroutine
_init: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 99 | 0 | shift; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | ########################################################################################################### | ||||||||||||||||||||||||||||
| 103 | 1 | 'Choppers rule'; | |||||||||||||||||||||||||||
| 104 | __END__ | ||||||||||||||||||||||||||||