blib/lib/Net/EMI/Common.pm

filter: Statementstmt 44.8% 26 / 58 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 53.3% 8 / 15 Podpod 100% 6 / 6 totaltotal 37.0% 40 / 108 CC 14 SCAR 32.4
CC
14
Cov
32%
encode_7bit
72.0
ia5_decode
20.0
checksum
12.0
CRAP 25.6
↑ Summary
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
BranchTrueFalseTotal
defined $_[0] or return 0 0 0 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 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
BranchTrueFalseTotal
defined $msg and length $msg or return "00" 0 0 0
Condition0%0/3
defined $msg and length $msg
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (defined $bit_string and length $bit_string) 0 0 0
Condition0%0/3
defined $bit_string and length $bit_string
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
length $bit_string > 8 ? : 0 0 0
66 }
67  
68 0 ▶ sprintf("%02X",length($rest)<5?length($user_data)-1:length($user_data)).uc($user_data);
Branch: 1 branch
BranchTrueFalseTotal
length $rest < 5 ? : 0 0 0
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
BranchTrueFalseTotal
defined $message and length $message or return "" 0 0 0
Condition0%0/3
defined $message and length $message
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
77  
78 0 ▶ for($i=0;$i<=length($message);$i+=2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= length $message) 0 0 0
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__
↑ Summary