Class: Smartware::Driver::Modem::Standard
- Inherits:
-
Object
- Object
- Smartware::Driver::Modem::Standard
- Defined in:
- lib/smartware/drivers/modem/standard.rb
Defined Under Namespace
Classes: LogConnection
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#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.
- #shutdown(callback) ⇒ Object
- #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.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/smartware/drivers/modem/standard.rb', line 49 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 @shutdown = false @account = nil logpipe_smartware, @logpipe_ppp = IO.pipe EventMachine.attach logpipe_smartware, LogConnection, self end |
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
47 48 49 |
# File 'lib/smartware/drivers/modem/standard.rb', line 47 def account @account end |
#balance ⇒ Object (readonly)
Returns the value of attribute balance.
46 47 48 |
# File 'lib/smartware/drivers/modem/standard.rb', line 46 def balance @balance end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
46 47 48 |
# File 'lib/smartware/drivers/modem/standard.rb', line 46 def error @error end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
46 47 48 |
# File 'lib/smartware/drivers/modem/standard.rb', line 46 def model @model end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
46 47 48 |
# File 'lib/smartware/drivers/modem/standard.rb', line 46 def version @version end |
Instance Method Details
#shutdown(callback) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/smartware/drivers/modem/standard.rb', line 77 def shutdown(callback) @shutdown_callback = callback Logging.logger.info "stopping modem gracefully" @shutdown = true @shutdown_timer = EventMachine.add_periodic_timer(0.5) do if @state == :closed && @ppp_state == :stopped Logging.logger.info "modem stopped" EventMachine.cancel_timer @shutdown_timer @shutdown_callback.call end end end |
#signal_level ⇒ Object
91 92 93 94 |
# File 'lib/smartware/drivers/modem/standard.rb', line 91 def signal_level value = @signal.gsub("+CSQ: ",'').split(',')[0].to_i "#{(-113 + value * 2)} dbm" end |
#tick ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/smartware/drivers/modem/standard.rb', line 96 def tick begin modem_tick ppp_tick wait_for_event rescue => e Logging.logger.error "uncatched exception in modem monitor: #{e}" end end |
#unsolicited(type, fields) ⇒ Object
107 108 109 110 111 112 |
# File 'lib/smartware/drivers/modem/standard.rb', line 107 def unsolicited(type, fields) case type when "CUSD" ussd *fields end end |
#ussd(mode, string = nil, dcs = nil) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/smartware/drivers/modem/standard.rb', line 114 def ussd(mode, string = nil, dcs = nil) if mode != "0" 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 |