Class: SimCard::Sim
- Inherits:
-
Object
- Object
- SimCard::Sim
- Defined in:
- lib/sim_card/sim.rb
Overview
the initial idea is borrowed from here: www.dzone.com/snippets/send-and-receive-sms-text
Instance Method Summary collapse
-
#close ⇒ Object
correctly disconnect from SIM card.
-
#delete_sms_message(sms_message) ⇒ Object
remove SMS message from SIM card memory * sms_message: instance of SimCard::SmsMessage to be deleted.
-
#initialize(user_options = {}) ⇒ Sim
constructor
connect to SIM card.
-
#phonebook ⇒ Object
return instance of Phonebook.
-
#send_raw_at_command(cmd) ⇒ Object
for hackers.
-
#send_sms(number, message_text) ⇒ Object
send SMS message.
-
#signal_strength ⇒ Object
signal strengh in dBm.
-
#sms_messages ⇒ Object
list SMS messages in SIM memory.
Constructor Details
#initialize(user_options = {}) ⇒ Sim
connect to SIM card. user_options may contain:
-
port : device where the gsm modem is connected, default is ‘/dev/ttyUSB0’
-
speed : connection speed in bauds, default is 9600
-
pin : pin code to your sim card. not required if your sim does not require authorization via pin
-
sms_center_no : SMS center of you provider. required only if you want to send SMS messages
-
debug_mode: when set to true, will print all communication with SIM card to stdout
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sim_card/sim.rb', line 14 def initialize( = {}) = {:port => '/dev/ttyUSB0', :speed => 9600} = .merge @port = SerialPort.new [:port], [:speed] debug_mode = ([:debug_mode] == true) @at_interface = RealAtInterface.new @port, debug_mode initial_check [:pin] # Set to text mode @at_interface.send "AT+CMGF=1" # Set SMSC number @at_interface.send "AT+CSCA=\"#{[:sms_center_no]}\"" if [:sms_center_no] end |
Instance Method Details
#close ⇒ Object
correctly disconnect from SIM card
32 33 34 |
# File 'lib/sim_card/sim.rb', line 32 def close @port.close end |
#delete_sms_message(sms_message) ⇒ Object
remove SMS message from SIM card memory
-
sms_message: instance of SimCard::SmsMessage to be deleted
56 57 58 |
# File 'lib/sim_card/sim.rb', line 56 def @at_interface.send "AT+CMGD=#{.}" end |
#phonebook ⇒ Object
return instance of Phonebook
50 51 52 |
# File 'lib/sim_card/sim.rb', line 50 def phonebook Phonebook.new @at_interface end |
#send_raw_at_command(cmd) ⇒ Object
for hackers
67 68 69 |
# File 'lib/sim_card/sim.rb', line 67 def send_raw_at_command cmd @at_interface.send cmd end |
#send_sms(number, message_text) ⇒ Object
send SMS message
37 38 39 40 41 42 |
# File 'lib/sim_card/sim.rb', line 37 def send_sms number, @at_interface.send "AT+CMGS=\"#{number}\"" @at_interface.send "#{[0..140]}#{26.chr}\r\r" sleep 3 @at_interface.send "AT" end |
#signal_strength ⇒ Object
signal strengh in dBm. -60 is almost perfect signal, -112 is very poor (call dropping bad)
61 62 63 64 |
# File 'lib/sim_card/sim.rb', line 61 def signal_strength sq = SimCard::SignalQuality.new @at_interface return sq.signal_strength end |
#sms_messages ⇒ Object
list SMS messages in SIM memory
45 46 47 |
# File 'lib/sim_card/sim.rb', line 45 def ReceivedSmsMessage. @at_interface end |