diff --git a/lib/biju/modem.rb b/lib/biju/modem.rb index f72ccbe..18353bd 100644 --- a/lib/biju/modem.rb +++ b/lib/biju/modem.rb @@ -3,6 +3,11 @@ require_relative 'sms' module Biju class Modem + + # Receives a hash of options where :port is mandatory + # + # Biju::Modem.new(:port => '/dev/ttyUSB0') + # def initialize(options={}) raise Exception.new("Port is required") unless options[:port] @connection = connection(options) @@ -10,15 +15,14 @@ module Biju cmd("AT+CMGF=1") end - def connection(options) - port = options.delete(:port) - SerialPort.new(port, default_options.merge!(options)) - end - + # Close the serial port connection. def close @connection.close end + # Returns an Array of Sms if there is messages, + # if not other way return nil + # def messages sms = cmd("AT+CMGL=\"ALL\"") msgs = sms.scan(/\+CMGL\:\s*?(\d+)\,.*?\,\"(.+?)\"\,.*?\,\"(.+?)\".*?\n(.*)/) @@ -27,6 +31,12 @@ module Biju end 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 { :baud => 9600, :data_bits => 8, :stop_bits => 1, :parity => SerialPort::NONE } end