class PduSms::PacketDataUnit

Attributes

da[R]
data_coding_scheme[R]
dcs[R]
destination_address[R]
message_reference[R]
mr[R]
oa[R]
originating_address[R]
pdu_type[R]
pid[R]
protocol_identifier[R]
sca[R]
scts[R]
service_center_address[R]
service_center_time_stamp[R]
ud[R]
udl[R]
user_data[R]
user_data_length[R]
validity_period[R]
vp[R]

Public Class Methods

decode(pdu) click to toggle source
# File lib/pdu_sms/packet_data_unit.rb, line 89
def PacketDataUnit.decode(pdu)
  pdu_type = PDUType.decode(pdu)
  if pdu_type.message_type_indicator_in?
    decode_sc(pdu)
  elsif pdu_type.message_type_indicator_out?
    decode_ms(pdu)
  else
    raise ArgumentError, 'failed to recognize the type of package'
  end
end
decode_ms(pdu) click to toggle source
# File lib/pdu_sms/packet_data_unit.rb, line 50
def PacketDataUnit.decode_ms(pdu)
  service_center_address = ServiceCenterAddress.decode_ms(pdu)
  pdu_type = PDUType.decode_ms(pdu)
  message_reference = MessageReference.decode_ms(pdu)
  destination_address = DestinationAddress.decode_ms(pdu)
  protocol_identifier = ProtocolIdentifier.decode_ms(pdu)
  data_coding_scheme = DataCodingScheme.decode_ms(pdu)
  validity_period = ValidityPeriod.decode_ms(pdu)
  user_data_length = UserDataLength.decode_ms(pdu)
  user_data = UserData.decode_ms(pdu)
  new(sca: service_center_address, pdu_type: pdu_type, mr: message_reference, da: destination_address, pid: protocol_identifier, dcs: data_coding_scheme, vp: validity_period, udl: user_data_length, ud: user_data).freeze
end
decode_sc(pdu) click to toggle source
# File lib/pdu_sms/packet_data_unit.rb, line 77
def PacketDataUnit.decode_sc(pdu)
  service_center_address = ServiceCenterAddress.decode_sc(pdu)
  pdu_type = PDUType.decode_sc(pdu)
  originating_address = OriginatingAddress.decode_sc(pdu)
  protocol_identifier = ProtocolIdentifier.decode_sc(pdu)
  data_coding_scheme = DataCodingScheme.decode_sc(pdu)
  service_center_time_stamp = ServiceCenterTimeStamp.decode_sc(pdu)
  user_data_length = UserDataLength.decode_sc(pdu)
  user_data = UserData.decode_sc(pdu)
  new(sca: service_center_address, pdu_type: pdu_type, pid: protocol_identifier, dcs: data_coding_scheme, udl: user_data_length, ud: user_data, oa: originating_address, scts: service_center_time_stamp).freeze
end
encode_ms(phone, message, coding: :auto, phone_npi: false, phone_ton: false, sca: false, sca_npi: false, sca_ton: false, rp: REPLY_PATH_0, srr: STATUS_REPORT_REQUEST_0, vp: false, rd: REJECT_DUPLICATES_0, message_class: false, compressed: UNCOMPRESSED) click to toggle source
# File lib/pdu_sms/packet_data_unit.rb, line 35
def PacketDataUnit.encode_ms(phone, message, coding: :auto, phone_npi: false, phone_ton: false, sca: false, sca_npi: false, sca_ton: false, rp: REPLY_PATH_0, srr: STATUS_REPORT_REQUEST_0, vp: false, rd: REJECT_DUPLICATES_0, message_class: false, compressed: UNCOMPRESSED)
  user_data_array = UserData.encode_ms(message, coding)
  user_data_array.collect.each_with_index do |user_data, current_num_pdu|
    service_center_address = ServiceCenterAddress.encode_ms(sca, sca_npi, sca_ton)
    destination_address = DestinationAddress.encode_ms(phone, phone_npi, phone_ton)
    protocol_identifier = ProtocolIdentifier.encode_ms
    message_reference = MessageReference.encode_ms(current_num_pdu)
    validity_period = ValidityPeriod.encode_ms(vp)
    pdu_type = PDUType.encode_ms(rp:rp, srr:srr, rd:rd, udhi: user_data.get_udh, vpf: validity_period.is_setup)
    data_coding_scheme = DataCodingScheme.encode_ms(compressed: compressed, message_class: message_class, alphabet: user_data.get_coding)
    user_data_length = UserDataLength.encode_ms(user_data)
    new(sca: service_center_address, pdu_type: pdu_type, mr: message_reference, da: destination_address, pid: protocol_identifier, dcs: data_coding_scheme, vp: validity_period, udl: user_data_length, ud: user_data).freeze
  end
end
encode_sc(sca, phone, message, coding: :auto, sca_npi: false, sca_ton: false, phone_npi: false, phone_ton: false, rp: REPLY_PATH_0, sri: STATUS_REPORT_INDICATION_0, mms: MORE_MESSAGES_TO_SEND_0, message_class: false, compressed: UNCOMPRESSED, scts: Time.now.getutc.to_i) click to toggle source
# File lib/pdu_sms/packet_data_unit.rb, line 63
def PacketDataUnit.encode_sc(sca, phone, message, coding: :auto, sca_npi: false, sca_ton: false, phone_npi: false, phone_ton: false, rp: REPLY_PATH_0, sri: STATUS_REPORT_INDICATION_0, mms: MORE_MESSAGES_TO_SEND_0, message_class: false, compressed: UNCOMPRESSED, scts: Time.now.getutc.to_i)
  user_data_array = UserData.encode_sc(message, coding)
  user_data_array.collect do |user_data|
    service_center_address = ServiceCenterAddress.encode_sc(sca, sca_npi, sca_ton)
    pdu_type = PDUType.encode_sc(rp: rp, udhi: user_data.get_udh, sri: sri, mms: mms)
    originating_address = OriginatingAddress.encode_sc(phone, phone_npi, phone_ton)
    protocol_identifier = ProtocolIdentifier.encode_sc
    data_coding_scheme = DataCodingScheme.encode_sc(compressed: compressed, message_class: message_class, alphabet: user_data.get_coding)
    service_center_time_stamp = ServiceCenterTimeStamp.encode_sc(scts)
    user_data_length = UserDataLength.encode_sc(user_data)
    new(sca: service_center_address, pdu_type: pdu_type, pid: protocol_identifier, dcs: data_coding_scheme, udl: user_data_length, ud: user_data, oa: originating_address, scts: service_center_time_stamp).freeze
  end
end
new(sca: false, pdu_type: false, mr: false, da: false, pid: false, dcs: false, vp: false, udl: false, ud: false, oa: false, scts: false) click to toggle source
# File lib/pdu_sms/packet_data_unit.rb, line 10
def initialize(sca: false, pdu_type: false, mr: false, da: false, pid: false, dcs: false, vp: false, udl: false, ud: false, oa: false, scts: false)
  raise ArgumentError, 'sca parameter should contain an object of class ServiceCenterAddress' unless ServiceCenterAddress == sca.class
  raise ArgumentError, 'pdu_type parameter should contain an object of class PDUType' unless PDUType == pdu_type.class
  raise ArgumentError, 'mr parameter should contain an object of class MessageReference' unless mr == false or MessageReference == mr.class
  raise ArgumentError, 'da parameter should contain an object of class DestinationAddress' unless da == false or DestinationAddress == da.class
  raise ArgumentError, 'pid parameter should contain an object of class ProtocolIdentifier' unless ProtocolIdentifier == pid.class
  raise ArgumentError, 'dcs parameter should contain an object of class DataCodingScheme' unless DataCodingScheme == dcs.class
  raise ArgumentError, 'vp parameter should contain an object of class ValidityPeriod' unless vp == false or ValidityPeriod == vp.class
  raise ArgumentError, 'udl parameter should contain an object of class UserDataLength' unless UserDataLength == udl.class
  raise ArgumentError, 'ud parameter should contain an object of class UserData' unless UserData == ud.class
  raise ArgumentError, 'oa parameter should contain an object of class OriginatingAddress' unless oa == false or OriginatingAddress == oa.class
  raise ArgumentError, 'scts parameter should contain an object of class ServiceCenterTimeStamp' unless scts == false or ServiceCenterTimeStamp == scts.class
  @sca = @service_center_address = sca
  @pdu_type = pdu_type
  @mr = @message_reference = mr
  @da = @destination_address = da
  @pid = @protocol_identifier = pid
  @dcs = @data_coding_scheme = dcs
  @vp = @validity_period = vp
  @udl = @user_data_length = udl
  @ud = @user_data = ud
  @oa = @originating_address = oa
  @scts = @service_center_time_stamp = scts
end

Public Instance Methods

all_parts() click to toggle source
# File lib/pdu_sms/packet_data_unit.rb, line 143
def all_parts
  @ud.get_ied2.to_i(16)
end
get_hex() click to toggle source
# File lib/pdu_sms/packet_data_unit.rb, line 100
def get_hex
  if @pdu_type.message_type_indicator_out?
    '' << @sca.get_hex << @pdu_type.get_hex << @mr.get_hex << @da.get_hex << @pid.get_hex << @dcs.get_hex << @vp.get_hex << @udl.get_hex << @ud.get_hex
  elsif @pdu_type.message_type_indicator_in?
    '' << @sca.get_hex << @pdu_type.get_hex << @oa.get_hex << @pid.get_hex << @dcs.get_hex << @scts.get_hex << @udl.get_hex << @ud.get_hex
  else
    raise PacketDataUnitError, 'oops SMS-SUBMIT not supported by this version of the library'
  end
end
get_message() click to toggle source
# File lib/pdu_sms/packet_data_unit.rb, line 110
def get_message
  @ud.get_message
end
get_phone_number() click to toggle source
# File lib/pdu_sms/packet_data_unit.rb, line 114
def get_phone_number
  if @pdu_type.message_type_indicator_out?
    @da.get_phone_number
  elsif @pdu_type.message_type_indicator_in?
    @oa.get_phone_number
  else
    raise PacketDataUnitError, 'oops SMS-SUBMIT not supported by this version of the library'
  end
end
id_message() click to toggle source
# File lib/pdu_sms/packet_data_unit.rb, line 139
def id_message
  @ud.get_ied1.empty? ? nil : @ud.get_ied1.to_i(16)
end
length() click to toggle source
# File lib/pdu_sms/packet_data_unit.rb, line 124
def length
  if @pdu_type.message_type_indicator_out?
    size = (@pdu_type.get_hex << @mr.get_hex << @da.get_hex << @pid.get_hex << @dcs.get_hex << @vp.get_hex << @udl.get_hex << @ud.get_hex).to_i(16).to_s(2).length
  elsif @pdu_type.message_type_indicator_in?
    size = (@sca.get_hex << @pdu_type.get_hex << @oa.get_hex << @pid.get_hex << @dcs.get_hex << @scts.get_hex << @udl.get_hex << @ud.get_hex).to_i(16).to_s(2).length
  else
    raise PacketDataUnitError, 'oops SMS-SUBMIT not supported by this version of the library'
  end
  if (size % 8).zero?
    size / 8
  else
    (size / 8) + 1
  end
end
part_number() click to toggle source
# File lib/pdu_sms/packet_data_unit.rb, line 147
def part_number
  @ud.get_ied3.to_i(16)
end