class Sms::Method::GSM

Public Class Methods

new(options = {}) click to toggle source
# File lib/sms/method/gsm.rb, line 8
def initialize(options = {})
  raise ArgumentError.new('No :smsc was provided') unless options[:smsc]
  @port = SerialPort.new(options[:port] || 3, options[:baud] || 38400, options[:bits] || 8, options[:stop] || 1, SerialPort::NONE)
  @debug = options[:debug]
  cmd("AT")
  # Set to text mode
  cmd("AT+CMGF=1")
  # Set SMSC number
  cmd(%Q{AT+CSCA="#{options[:smsc]}"})
end

Public Instance Methods

close() click to toggle source
# File lib/sms/method/gsm.rb, line 19
def close
  @port.close
end

Private Instance Methods

cmd(cmd) click to toggle source
# File lib/sms/method/gsm.rb, line 24
def cmd(cmd)
  @port.write(cmd + "\r")
  wait
end
deliver!(sms) click to toggle source
# File lib/sms/method/gsm.rb, line 39
def deliver!(sms)
  cmd(%Q{AT+CMGS="#{sms.to}"})
  cmd("#{sms.text[0..140]}#{26.chr}\r\r")
  sleep 1
  wait
  cmd("AT")
end
wait() click to toggle source
# File lib/sms/method/gsm.rb, line 29
def wait
  buffer = ''
  while IO.select([@port], [], [], 0.25)
    chr = @port.getc.chr
    print chr if @debug
    buffer += chr
  end
  buffer
end