class PduSms::PDUType
Public Class Methods
cut_off_pdu(pdu, part=:all, type=:ms)
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 70 def PDUType.cut_off_pdu(pdu, part=:all, type=:ms) # tail current part_pdu = ServiceCenterAddress.cut_off_pdu(pdu, :tail) raise TypeError.new('Слишком короткая строка') 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(pdu_str)
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 36 def PDUType.decode(pdu_str) pdu = '%08b' % PDUType.cut_off_pdu(pdu_str, :current, :ms) mti = pdu[6..7].to_i(2) if mti == MESSAGE_TYPE_INDICATOR_00 PDUType.decode_sc(pdu_str) elsif mti == MESSAGE_TYPE_INDICATOR_01 PDUType.decode_ms(pdu_str) elsif mti == MESSAGE_TYPE_INDICATOR_10 raise PacketDataUnitError, 'oops SMS-SUBMIT not supported by this version of the library' else raise PacketDataUnitError, 'format error' end end
decode_ms(pdu_str)
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 54 def PDUType.decode_ms(pdu_str) pdu = '%08b' % PDUType.cut_off_pdu(pdu_str, :current, :ms).to_i(16) raise ArgumentError, 'wrong format "PDU" package' if pdu[6..7].to_i(2) != MESSAGE_TYPE_INDICATOR_01 new(:decode_ms, rp:pdu[0].to_i(2), udhi:pdu[1].to_i(2), srr:pdu[2].to_i(2), vpf:pdu[3..4].to_i(2), rd:pdu[5].to_i(2), mti:MESSAGE_TYPE_INDICATOR_01).freeze end
decode_sc(pdu_str)
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 64 def PDUType.decode_sc(pdu_str) pdu = '%08b' % PDUType.cut_off_pdu(pdu_str, :current, :sc).to_i(16) raise ArgumentError, 'wrong format "PDU" package' if pdu[6..7].to_i(2) != MESSAGE_TYPE_INDICATOR_00 new(:decode_ms, rp:pdu[0].to_i(2), udhi:pdu[1].to_i(2), sri:pdu[2].to_i(2), mms:pdu[5].to_i(2), mti:MESSAGE_TYPE_INDICATOR_00).freeze end
encode(rp: REPLY_PATH_0, udhi: USER_DATA_HEADER_INCLUDED_0, srr: STATUS_REPORT_REQUEST_0, vpf: VALIDITY_PERIOD_FORMAT_00, rd: REJECT_DUPLICATES_0, mti: MESSAGE_TYPE_INDICATOR_01, sri: STATUS_REPORT_INDICATION_0, mms:MORE_MESSAGES_TO_SEND_0)
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 26 def PDUType.encode(rp: REPLY_PATH_0, udhi: USER_DATA_HEADER_INCLUDED_0, srr: STATUS_REPORT_REQUEST_0, vpf: VALIDITY_PERIOD_FORMAT_00, rd: REJECT_DUPLICATES_0, mti: MESSAGE_TYPE_INDICATOR_01, sri: STATUS_REPORT_INDICATION_0, mms:MORE_MESSAGES_TO_SEND_0) if mti == MESSAGE_TYPE_INDICATOR_01 PDUType.encode_ms(rp:rp,udhi:udhi, srr:srr, vpf:vpf, rd:rd) elsif mti == MESSAGE_TYPE_INDICATOR_00 PDUType.encode_sc(rp:rp, udhi:udhi, sri:sri, mms:mms) elsif mti == MESSAGE_TYPE_INDICATOR_10 raise PacketDataUnitError, 'oops SMS-SUBMIT not supported by this version of the library' end end
encode_ms(rp: REPLY_PATH_0, udhi: USER_DATA_HEADER_INCLUDED_0, srr: STATUS_REPORT_REQUEST_0, vpf: VALIDITY_PERIOD_FORMAT_00, rd: REJECT_DUPLICATES_0)
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 50 def PDUType.encode_ms(rp: REPLY_PATH_0, udhi: USER_DATA_HEADER_INCLUDED_0, srr: STATUS_REPORT_REQUEST_0, vpf: VALIDITY_PERIOD_FORMAT_00, rd: REJECT_DUPLICATES_0) new(:encode_ms, rp:rp, udhi:udhi, srr:srr, vpf:vpf, rd:rd, mti:MESSAGE_TYPE_INDICATOR_01).freeze end
encode_sc(rp: REPLY_PATH_0, udhi: USER_DATA_HEADER_INCLUDED_0, sri: STATUS_REPORT_INDICATION_0, mms:MORE_MESSAGES_TO_SEND_0)
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 60 def PDUType.encode_sc(rp: REPLY_PATH_0, udhi: USER_DATA_HEADER_INCLUDED_0, sri: STATUS_REPORT_INDICATION_0, mms:MORE_MESSAGES_TO_SEND_0) new(:encode_ms, rp:rp, udhi:udhi, sri:sri, mms:mms, mti:MESSAGE_TYPE_INDICATOR_00).freeze end
new(type, rp: REPLY_PATH_0, udhi: USER_DATA_HEADER_INCLUDED_0, mti: MESSAGE_TYPE_INDICATOR_01, vpf: false, srr: false, sri: false, rd: false, mms: false)
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 4 def initialize(type, rp: REPLY_PATH_0, udhi: USER_DATA_HEADER_INCLUDED_0, mti: MESSAGE_TYPE_INDICATOR_01, vpf: false, srr: false, sri: false, rd: false, mms: false) raise ArgumentError, 'The "rp" is incorrect' unless (REPLY_PATH_0..REPLY_PATH_1).include?(rp) raise ArgumentError, 'The "udhi" is incorrect' unless (USER_DATA_HEADER_INCLUDED_0..USER_DATA_HEADER_INCLUDED_1).include?(udhi) raise ArgumentError, 'The "mti" is incorrect' unless (MESSAGE_TYPE_INDICATOR_00..MESSAGE_TYPE_INDICATOR_11).include?(mti) if mti == MESSAGE_TYPE_INDICATOR_01 raise ArgumentError, 'The "srr" is incorrect' unless (STATUS_REPORT_REQUEST_0..STATUS_REPORT_REQUEST_1).include?(srr) raise ArgumentError, 'The "vpf" is incorrect' unless (VALIDITY_PERIOD_FORMAT_00..VALIDITY_PERIOD_FORMAT_11).include?(vpf) raise ArgumentError, 'The "rd" is incorrect' unless (REJECT_DUPLICATES_0..REJECT_DUPLICATES_1).include?(rd) elsif mti == MESSAGE_TYPE_INDICATOR_00 raise ArgumentError, 'The "sri" is incorrect' unless (STATUS_REPORT_INDICATION_0..STATUS_REPORT_INDICATION_1).include?(sri) raise ArgumentError, 'The "mms" is incorrect' unless (MORE_MESSAGES_TO_SEND_0..MORE_MESSAGES_TO_SEND_1).include?(mms) end @rp = rp @udhi = udhi @srr = srr @vpf = vpf @rd = rd @mti = mti @mms = mms @sri = sri end
Public Instance Methods
get_hex()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 170 def get_hex if message_type_indicator_out? '%02X' % [('' << get_reply_path << get_user_data_header_included << get_status_report_request << get_validity_period_format << get_reject_duplicates << get_message_type_indicator).to_i(2)] elsif message_type_indicator_in? '%02X' % [('' << get_reply_path << get_user_data_header_included << get_status_report_indication << '00' << get_more_messages_to_send << get_message_type_indicator).to_i(2)] end end
get_message_type_indicator()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 158 def get_message_type_indicator '%02b' % @mti end
get_more_messages_to_send()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 166 def get_more_messages_to_send '%b' % @mms end
get_reject_duplicates()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 154 def get_reject_duplicates '%b' % @rd end
get_reply_path()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 138 def get_reply_path '%b' % @rp end
get_status_report_indication()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 162 def get_status_report_indication '%b' % @sri end
get_status_report_request()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 146 def get_status_report_request '%b' % @srr end
get_user_data_header_included()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 142 def get_user_data_header_included '%b' % @udhi end
get_validity_period_format()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 150 def get_validity_period_format '%02b' % @vpf end
message_type_indicator_in?()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 114 def message_type_indicator_in? @mti == MESSAGE_TYPE_INDICATOR_00 end
message_type_indicator_out?()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 118 def message_type_indicator_out? @mti == MESSAGE_TYPE_INDICATOR_01 end
message_type_indicator_report?()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 122 def message_type_indicator_report? @mti == MESSAGE_TYPE_INDICATOR_10 end
message_type_indicator_reserve?()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 126 def message_type_indicator_reserve? @mti == MESSAGE_TYPE_INDICATOR_11 end
more_messages_to_send?()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 130 def more_messages_to_send? @mms == MORE_MESSAGES_TO_SEND_1 end
reject_duplicates?()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 110 def reject_duplicates? @rd == REJECT_DUPLICATES_1 end
reply_path?()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 82 def reply_path? @rp == REPLY_PATH_1 end
status_report_indication?()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 134 def status_report_indication? @sri == STATUS_REPORT_INDICATION_1 end
status_report_request?()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 90 def status_report_request? @srr == STATUS_REPORT_REQUEST_1 end
user_data_header_included?()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 86 def user_data_header_included? @udhi == USER_DATA_HEADER_INCLUDED_1 end
validity_period_format_absolute?()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 106 def validity_period_format_absolute? @vpf == VALIDITY_PERIOD_FORMAT_11 end
validity_period_format_off?()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 94 def validity_period_format_off? @vpf == VALIDITY_PERIOD_FORMAT_00 end
validity_period_format_relative?()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 102 def validity_period_format_relative? @vpf == VALIDITY_PERIOD_FORMAT_10 end
validity_period_format_reserve?()
click to toggle source
# File lib/pdu_sms/pdu_type.rb, line 98 def validity_period_format_reserve? @vpf == VALIDITY_PERIOD_FORMAT_01 end