Class: PduSms::UserData
- Inherits:
-
Object
- Object
- PduSms::UserData
- Defined in:
- lib/pdu_sms/user_data.rb
Class Method Summary collapse
-
.cut_off_pdu(pdu, part = :all, type = :ms) ⇒ Object
tail current.
- .decode_ms(pdu_str) ⇒ Object
- .decode_sc(pdu_str) ⇒ Object
- .encode_ms(message, coding = :auto) ⇒ Object
- .encode_sc(message, coding = :auto) ⇒ Object
Instance Method Summary collapse
- #get_coding ⇒ Object
- #get_hex ⇒ Object
- #get_ied1 ⇒ Object
- #get_ied2 ⇒ Object
- #get_ied3 ⇒ Object
- #get_iedl ⇒ Object
- #get_iei ⇒ Object
- #get_message ⇒ Object
- #get_udh ⇒ Object
- #get_udhl ⇒ Object
-
#initialize(message, coding, ied1: false, ied2: false, ied3: false, udhl: false, iei: false, iedl: false) ⇒ UserData
constructor
A new instance of UserData.
- #is_udh? ⇒ Boolean
Constructor Details
#initialize(message, coding, ied1: false, ied2: false, ied3: false, udhl: false, iei: false, iedl: false) ⇒ UserData
Returns a new instance of UserData.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/pdu_sms/user_data.rb', line 4 def initialize(, coding, ied1: false, ied2: false, ied3: false, udhl: false, iei: false, iedl: false) @coding = _check_coding coding @ied1 = _check_ied1 ied1 @ied2 = _check_ied2 ied2 @ied3 = _check_ied3 ied3 @udhl = udhl ? udhl : _check_udhl(ied1) @iei = iei ? iei : _check_iei(ied1) @iedl = iedl ? iedl : _check_iedl(ied1) = , coding, ied1 end |
Class Method Details
.cut_off_pdu(pdu, part = :all, type = :ms) ⇒ Object
tail current
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/pdu_sms/user_data.rb', line 114 def UserData.cut_off_pdu(pdu, part=:all, type=:ms) # tail current part_pdu = UserDataLength.cut_off_pdu(pdu, :tail, type) pdu_type = PDUType.decode(pdu) raise ArgumentError, 'The "pdu_str" is incorrect' if part_pdu.length < 2 if pdu_type.user_data_header_included? current = part_pdu[0..(part_pdu[0..1].to_i(16) * 2 + 1)] tail = part_pdu[(part_pdu[0..1].to_i(16) * 2 + 2)..-1] else current = '' tail = part_pdu[0..-1] end case part when :current then current when :tail then tail else [current,tail] end end |
.decode_ms(pdu_str) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pdu_sms/user_data.rb', line 46 def UserData.decode_ms(pdu_str) header, = UserData.cut_off_pdu(pdu_str, :all, :ms) dcs = DataCodingScheme.decode_ms(pdu_str) if dcs.alphabet_7bit? coding = dcs.get_alphabet.to_i(2) if header.empty? = Helpers.decode_7bit() else = Helpers.decode_7bit_fill_bits(, header[0..1]) end elsif dcs.alphabet_8bit? coding = dcs.get_alphabet.to_i(2) = Helpers.decode_8bit() elsif dcs.alphabet_16bit? coding = dcs.get_alphabet.to_i(2) = Helpers.decode_ucs2() else raise ArgumentError, 'The "pdu_str" is incorrect' end if header.empty? new(, coding).freeze else if header[0..1].to_i(16) == UDHL_SIZE_6 new(, coding, udhl: header[0..1].to_i(16), iei: header[2..3].to_i(16), iedl: header[4..5].to_i(16), ied1: header[6..9], ied2: header[10..11].to_i(16), ied3: header[12..13].to_i(16)).freeze elsif header[0..1].to_i(16) == UDHL_SIZE_5 new(, coding, udhl: header[0..1].to_i(16), iei: header[2..3].to_i(16), iedl: header[4..5].to_i(16), ied1: header[6..7], ied2: header[8..9].to_i(16), ied3: header[10..11].to_i(16)).freeze else new(, coding).freeze end end end |
.decode_sc(pdu_str) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/pdu_sms/user_data.rb', line 82 def UserData.decode_sc(pdu_str) header, = UserData.cut_off_pdu(pdu_str, :all, :sc) dcs = DataCodingScheme.decode_sc(pdu_str) if dcs.alphabet_7bit? coding = dcs.get_alphabet.to_i(2) if header.empty? = Helpers.decode_7bit() else = Helpers.decode_7bit_fill_bits(, header[0..1]) end elsif dcs.alphabet_8bit? coding = dcs.get_alphabet.to_i(2) = Helpers.decode_8bit() elsif dcs.alphabet_16bit? coding = dcs.get_alphabet.to_i(2) = Helpers.decode_ucs2() else raise ArgumentError, 'The "pdu_str" is incorrect' end if header.empty? new(, coding).freeze else if header[0..1].to_i(16) == UDHL_SIZE_6 new(, coding, udhl: header[0..1].to_i(16), iei: header[2..3].to_i(16), iedl: header[4..5].to_i(16), ied1: header[6..9], ied2: header[10..11].to_i(16), ied3: header[12..13].to_i(16)).freeze elsif header[0..1].to_i(16) == UDHL_SIZE_5 new(, coding, udhl: header[0..1].to_i(16), iei: header[2..3].to_i(16), iedl: header[4..5].to_i(16), ied1: header[6..7], ied2: header[8..9].to_i(16), ied3: header[10..11].to_i(16)).freeze else new(, coding).freeze end end end |
.encode_ms(message, coding = :auto) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pdu_sms/user_data.rb', line 15 def UserData.encode_ms(, coding=:auto) = [] coding = Helpers.is_7bit?() ? ALPHABET_7BIT : ALPHABET_16BIT if coding == :auto if coding == ALPHABET_7BIT if .length > 160 = .scan(/.{1,152}/) ied1 = '%04X' % rand(65535) end elsif coding == ALPHABET_8BIT if .length > 140 = .scan(/.{1,133}/) ied1 = '%04X' % rand(65535) end elsif coding == ALPHABET_16BIT if .length > 70 = .scan(/.{1,67}/) ied1 = '%02X' % rand(255) end else raise ArgumentError, 'The "coding" is incorrect' end .collect.each_with_index do |mess, | if .length > 1 new(mess, coding, ied1:ied1, ied2:.length, ied3:+1).freeze else new(mess, coding).freeze end end end |
.encode_sc(message, coding = :auto) ⇒ Object
78 79 80 |
# File 'lib/pdu_sms/user_data.rb', line 78 def UserData.encode_sc(, coding=:auto) UserData.encode_ms(, coding) end |
Instance Method Details
#get_coding ⇒ Object
136 137 138 |
# File 'lib/pdu_sms/user_data.rb', line 136 def get_coding @coding end |
#get_hex ⇒ Object
182 183 184 185 186 187 188 189 190 191 |
# File 'lib/pdu_sms/user_data.rb', line 182 def get_hex if @coding == ALPHABET_7BIT = Helpers.encode_7bit_fill_bits(, get_udhl) elsif @coding == ALPHABET_8BIT = Helpers.encode_8bit() else = Helpers.encode_ucs2() end '%s%s%s%s%s%s%s' % [get_udhl, get_iei, get_iedl, get_ied1, get_ied2, get_ied3, ] end |
#get_ied1 ⇒ Object
152 153 154 155 |
# File 'lib/pdu_sms/user_data.rb', line 152 def get_ied1 return '' unless @ied1 @ied1 end |
#get_ied2 ⇒ Object
157 158 159 160 |
# File 'lib/pdu_sms/user_data.rb', line 157 def get_ied2 return '' unless @ied2 '%02X' % @ied2 end |
#get_ied3 ⇒ Object
162 163 164 165 |
# File 'lib/pdu_sms/user_data.rb', line 162 def get_ied3 return '' unless @ied3 '%02X' % @ied3 end |
#get_iedl ⇒ Object
177 178 179 180 |
# File 'lib/pdu_sms/user_data.rb', line 177 def get_iedl return '' unless @iedl '%02X' % @iedl end |
#get_iei ⇒ Object
172 173 174 175 |
# File 'lib/pdu_sms/user_data.rb', line 172 def get_iei return '' unless @iei '%02X' % @iei end |
#get_message ⇒ Object
132 133 134 |
# File 'lib/pdu_sms/user_data.rb', line 132 def end |
#get_udh ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/pdu_sms/user_data.rb', line 144 def get_udh if is_udh? USER_DATA_HEADER_INCLUDED_1 else USER_DATA_HEADER_INCLUDED_0 end end |
#get_udhl ⇒ Object
167 168 169 170 |
# File 'lib/pdu_sms/user_data.rb', line 167 def get_udhl return '' unless @udhl '%02X' % @udhl end |
#is_udh? ⇒ Boolean
140 141 142 |
# File 'lib/pdu_sms/user_data.rb', line 140 def is_udh? @ied1 ? true : false end |