Method: Smpp::Transceiver#send_concat_mt

Defined in:
lib/smpp/transceiver.rb

#send_concat_mt(message_id, source_addr, destination_addr, message, options = {}) ⇒ Object

Send a concatenated message with a body of > 160 characters as multiple messages.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/smpp/transceiver.rb', line 33

def send_concat_mt(message_id, source_addr, destination_addr, message, options = {})
  logger.debug "Sending concatenated MT: #{message}"
  if @state == :bound
    # Split the message into parts of 153 characters. (160 - 7 characters for UDH)
    parts = []
    while message.size > 0 do
      parts << message.slice!(0..Smpp::Transceiver.get_message_part_size(options))
    end
    
    0.upto(parts.size-1) do |i|
      udh = sprintf("%c", 5)            # UDH is 5 bytes.
      udh << sprintf("%c%c", 0, 3)      # This is a concatenated message 

      #TODO Figure out why this needs to be an int here, it's a string elsewhere
      udh << sprintf("%c", message_id)  # The ID for the entire concatenated message

      udh << sprintf("%c", parts.size)  # How many parts this message consists of
      udh << sprintf("%c", i+1)         # This is part i+1
      
      options[:esm_class] = 64 # This message contains a UDH header.
      options[:udh] = udh

      pdu = Pdu::SubmitSm.new(source_addr, destination_addr, parts[i], options)
      write_pdu pdu
      
      # This is definately a bit hacky - multiple PDUs are being associated with a single
      # message_id.
      @ack_ids[pdu.sequence_number] = message_id
    end
  else
    raise InvalidStateException, "Transceiver is unbound. Connot send MT messages."
  end
end