Start to doc modem class and put connectio method to private
parent
ff47ed219b
commit
1d4ce23ddb
|
@ -3,6 +3,11 @@ require_relative 'sms'
|
||||||
|
|
||||||
module Biju
|
module Biju
|
||||||
class Modem
|
class Modem
|
||||||
|
|
||||||
|
# Receives a hash of options where :port is mandatory
|
||||||
|
#
|
||||||
|
# Biju::Modem.new(:port => '/dev/ttyUSB0')
|
||||||
|
#
|
||||||
def initialize(options={})
|
def initialize(options={})
|
||||||
raise Exception.new("Port is required") unless options[:port]
|
raise Exception.new("Port is required") unless options[:port]
|
||||||
@connection = connection(options)
|
@connection = connection(options)
|
||||||
|
@ -10,15 +15,14 @@ module Biju
|
||||||
cmd("AT+CMGF=1")
|
cmd("AT+CMGF=1")
|
||||||
end
|
end
|
||||||
|
|
||||||
def connection(options)
|
# Close the serial port connection.
|
||||||
port = options.delete(:port)
|
|
||||||
SerialPort.new(port, default_options.merge!(options))
|
|
||||||
end
|
|
||||||
|
|
||||||
def close
|
def close
|
||||||
@connection.close
|
@connection.close
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns an Array of Sms if there is messages,
|
||||||
|
# if not other way return nil
|
||||||
|
#
|
||||||
def messages
|
def messages
|
||||||
sms = cmd("AT+CMGL=\"ALL\"")
|
sms = cmd("AT+CMGL=\"ALL\"")
|
||||||
msgs = sms.scan(/\+CMGL\:\s*?(\d+)\,.*?\,\"(.+?)\"\,.*?\,\"(.+?)\".*?\n(.*)/)
|
msgs = sms.scan(/\+CMGL\:\s*?(\d+)\,.*?\,\"(.+?)\"\,.*?\,\"(.+?)\".*?\n(.*)/)
|
||||||
|
@ -27,6 +31,12 @@ module Biju
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
def connection(options)
|
||||||
|
port = options.delete(:port)
|
||||||
|
SerialPort.new(port, default_options.merge!(options))
|
||||||
|
end
|
||||||
|
|
||||||
|
# private method that generate default values for serial port connection
|
||||||
def default_options
|
def default_options
|
||||||
{ :baud => 9600, :data_bits => 8, :stop_bits => 1, :parity => SerialPort::NONE }
|
{ :baud => 9600, :data_bits => 8, :stop_bits => 1, :parity => SerialPort::NONE }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue