Class: Biju::Modem
- Inherits:
-
Object
- Object
- Biju::Modem
- Defined in:
- lib/biju/modem.rb
Instance Method Summary collapse
-
#close ⇒ Object
Close the serial connection.
-
#delete(id) ⇒ Object
Delete a sms message by id.
-
#initialize(options = {}) ⇒ Modem
constructor
A new instance of Modem.
-
#messages ⇒ Object
Return an Array of Sms if there is messages nad return nil if not.
Constructor Details
#initialize(options = {}) ⇒ Modem
Returns a new instance of Modem.
12 13 14 15 16 17 |
# File 'lib/biju/modem.rb', line 12 def initialize(={}) raise Exception.new("Port is required") unless [:port] @connection = connection() cmd("AT") cmd("AT+CMGF=1") end |
Instance Method Details
#close ⇒ Object
Close the serial connection.
20 21 22 |
# File 'lib/biju/modem.rb', line 20 def close @connection.close end |
#delete(id) ⇒ Object
Delete a sms message by id.
34 35 36 |
# File 'lib/biju/modem.rb', line 34 def delete(id) cmd("AT+CMGD=#{id}") end |
#messages ⇒ Object
Return an Array of Sms if there is messages nad return nil if not.
25 26 27 28 29 30 |
# File 'lib/biju/modem.rb', line 25 def sms = cmd("AT+CMGL=\"ALL\"") msgs = sms.scan(/\+CMGL\:\s*?(\d+)\,.*?\,\"(.+?)\"\,.*?\,\"(.+?)\".*?\n(.*)/) return nil unless msgs msgs.collect!{ |msg| Biju::Sms.new(:id => msg[0], :phone_number => msg[1], :datetime => msg[2], :message => msg[3].chomp) } end |