Add better comments

master
Rodrigo Pinto 2012-05-29 16:12:40 -03:00
parent 1d4ce23ddb
commit 997b4993e5
1 changed files with 4 additions and 6 deletions

View File

@ -4,7 +4,8 @@ require_relative 'sms'
module Biju module Biju
class Modem class Modem
# Receives a hash of options where :port is mandatory # @param [Hash] Options to serial connection.
# @option options [String] :port The modem port to connect
# #
# Biju::Modem.new(:port => '/dev/ttyUSB0') # Biju::Modem.new(:port => '/dev/ttyUSB0')
# #
@ -15,14 +16,12 @@ module Biju
cmd("AT+CMGF=1") cmd("AT+CMGF=1")
end end
# Close the serial port connection. # Close the serial connection.
def close def close
@connection.close @connection.close
end end
# Returns an Array of Sms if there is messages, # Return an Array of Sms if there is messages nad return nil if not.
# 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(.*)/)
@ -36,7 +35,6 @@ module Biju
SerialPort.new(port, default_options.merge!(options)) SerialPort.new(port, default_options.merge!(options))
end 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