Class: PDUTools::Decoder

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/pdu_tools/decoder.rb

Constant Summary

Constants included from Helpers

Helpers::GSM_03_38_ESCAPES

Instance Method Summary collapse

Methods included from Helpers

#dec2hexbyte, #decode16bit, #decode7bit, #decode8bit, #encode7bit, #encode8bit, #gsm0338_to_utf8, #normal2swapped, #swapped2normal, #utf8_to_gsm0338

Constructor Details

#initialize(pdu_hex, direction = :sc_to_ms) ⇒ Decoder



6
7
8
9
# File 'lib/pdu_tools/decoder.rb', line 6

def initialize pdu_hex, direction=:sc_to_ms
  @pdu_hex = pdu_hex.dup
  @direction = direction
end

Instance Method Details

#decodeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pdu_tools/decoder.rb', line 11

def decode
  @sca_length = take(2, :integer) * 2                # Service center address length
  if @sca_length > 0
    @sca_type = parse_address_type take(2)            # Service center address type
    @sca = parse_address take(@sca_length - 2), @sca_type, @sca_length # Service center address
  end
  @pdu_type = parse_pdu_type take(2, :binary)   # PDU type octet
  @message_reference = take(2) if @pdu_type[:mti] == :sms_submit
  @address_length = take(2, :integer)
  @address_type = parse_address_type take(2)
  @address_length = @address_length.odd? ? @address_length + 1 : @address_length # Always take byte aligned - hexdecimal F is added when odd number
  @address = parse_address take(@address_length), @address_type, @address_length
  @pid = take(2)
  @data_coding_scheme = parse_data_coding_scheme take(2, :binary)
  @sc_timestamp = parse_7byte_timestamp take(14) if [:sms_deliver, :sms_deliver_report].include? @pdu_type[:mti]
  case @pdu_type[:vpf]
  when :absolute
    @validity_period = parse_7byte_timestamp take(14)
  when :relative
    @validity_period = parse_validity_period take(2, :integer)
  end
  @user_data_length = take(2, :integer)
  parse_user_data @user_data_length

  MessagePart.new @address, @message, @sc_timestamp, @validity_period, @user_data_header
end

#inspect2Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pdu_tools/decoder.rb', line 38

def inspect2
  r = "<PDUTools::Decoder"
  r << "PDU: #{@pdu_hex}\n"
  r << "SCA LENGTH: #{@sca_length}\n"
  r << "SCA TYPE: #{@sca_type}\n"
  r << "SCA: #{@sca}\n"
  r << "PDU TYPE: #{@pdu_type}\n"
  r << "MESSAGE REFERENCE: #{@message_reference}\n" if @message_reference
  r << ">"
  r
end