class PduSms::ProtocolIdentifier

Public Class Methods

cut_off_pdu(pdu, part=:all, type=:ms) click to toggle source
# File lib/pdu_sms/protocol_identifier.rb, line 12
def ProtocolIdentifier.cut_off_pdu(pdu, part=:all, type=:ms)
  if type == :ms
    part_pdu = DestinationAddress.cut_off_pdu(pdu, :tail)
  elsif type == :sc
    part_pdu = OriginatingAddress.cut_off_pdu(pdu, :tail)
  else
    raise ArgumentError, 'Format "PDU" not valid'
  end
  raise ArgumentError, 'Too short packet pdu' if part_pdu.length < 2
  current = part_pdu[0..1]
  tail = part_pdu[2..-1]
  case part
    when :current then current
    when :tail then tail
    else [current,tail]
  end
end
decode_ms(pdu) click to toggle source
# File lib/pdu_sms/protocol_identifier.rb, line 34
def ProtocolIdentifier.decode_ms(pdu)
  new(ProtocolIdentifier.cut_off_pdu(pdu, :current, :ms).to_i(2)).freeze
end
decode_sc(pdu) click to toggle source
# File lib/pdu_sms/protocol_identifier.rb, line 42
def ProtocolIdentifier.decode_sc(pdu)
  new(ProtocolIdentifier.cut_off_pdu(pdu, :current, :sc).to_i(2)).freeze
end
encode_ms(pid=PROTOCOL_IDENTIFIER) click to toggle source
# File lib/pdu_sms/protocol_identifier.rb, line 30
def ProtocolIdentifier.encode_ms(pid=PROTOCOL_IDENTIFIER)
  new(pid).freeze
end
encode_sc(pid=PROTOCOL_IDENTIFIER) click to toggle source
# File lib/pdu_sms/protocol_identifier.rb, line 38
def ProtocolIdentifier.encode_sc(pid=PROTOCOL_IDENTIFIER)
  new(pid).freeze
end
new(num) click to toggle source
# File lib/pdu_sms/protocol_identifier.rb, line 4
def initialize(num)
  if (0..255).include?(num)
    @pid = num
  else
    raise ArgumentError, 'The "num is incorrect'
  end
end

Public Instance Methods

get_hex() click to toggle source
# File lib/pdu_sms/protocol_identifier.rb, line 46
def get_hex
  '%02X' % [@pid]
end
get_pid() click to toggle source
# File lib/pdu_sms/protocol_identifier.rb, line 50
def get_pid
  @pid
end