Class: Smartware::Driver::Modem::Standard
- Inherits:
-
Object
- Object
- Smartware::Driver::Modem::Standard
- Defined in:
- lib/smartware/drivers/modem/standard.rb
Instance Attribute Summary collapse
-
#balance ⇒ Object
readonly
Returns the value of attribute balance.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(config) ⇒ Standard
constructor
A new instance of Standard.
- #signal_level ⇒ Object
- #tick ⇒ Object
- #unsolicited(type, fields) ⇒ Object
- #ussd(mode, string = nil, dcs = nil) ⇒ Object
Constructor Details
#initialize(config) ⇒ Standard
Returns a new instance of Standard.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/smartware/drivers/modem/standard.rb', line 11 def initialize(config) @port = config["port"] @balance_ussd = config["balance_ussd"] @status_channel_id = config["status_channel"].to_i @ppp_channel_id = config["ppp_channel"].to_i @poll_interval = config["poll_interval"].to_i @balance_interval = config["balance_interval"].to_i @apn = config["apn"] @state = :closed @error = Interface::Modem::MODEM_NOT_AVAILABLE @mux = nil @status_channel = nil @info_requested = false @model = "GSM modem" @version = "" @signal = "+CSQ: 99,99" @balance_timer = 0 @balance = nil @ppp_state = :stopped @ppp_pid = nil end |
Instance Attribute Details
#balance ⇒ Object (readonly)
Returns the value of attribute balance.
9 10 11 |
# File 'lib/smartware/drivers/modem/standard.rb', line 9 def balance @balance end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
9 10 11 |
# File 'lib/smartware/drivers/modem/standard.rb', line 9 def error @error end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
9 10 11 |
# File 'lib/smartware/drivers/modem/standard.rb', line 9 def model @model end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
9 10 11 |
# File 'lib/smartware/drivers/modem/standard.rb', line 9 def version @version end |
Instance Method Details
#signal_level ⇒ Object
34 35 36 37 |
# File 'lib/smartware/drivers/modem/standard.rb', line 34 def signal_level value = @signal.gsub("+CSQ: ",'').split(',')[0].to_i "#{(-113 + value * 2)} dbm" end |
#tick ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/smartware/drivers/modem/standard.rb', line 39 def tick begin modem_tick ppp_tick wait_for_event rescue => e Smartware::Logging.logger.error "uncatched exception in modem monitor: #{e}" end end |
#unsolicited(type, fields) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/smartware/drivers/modem/standard.rb', line 50 def unsolicited(type, fields) case type when "CUSD" ussd *fields end end |
#ussd(mode, string = nil, dcs = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/smartware/drivers/modem/standard.rb', line 57 def ussd(mode, string = nil, dcs = nil) if mode != "0" Smartware::Logging.logger.warn "USSD completed with mode #{mode}, expected 0" end if string @balance = string.scan(/\w{4}/) .map! { |i| [ i.hex ].pack("U") } .join .strip else @balance = nil end end |