Class: NetworkManager::Modem
- Inherits:
-
Object
- Object
- NetworkManager::Modem
- Defined in:
- lib/network_manager/modem.rb
Instance Attribute Summary collapse
-
#bus_path ⇒ Object
(also: #dbus_path)
readonly
Returns the value of attribute bus_path.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Class Method Summary collapse
Instance Method Summary collapse
- #device ⇒ Object
- #disable! ⇒ Object
- #disabled? ⇒ Boolean
- #enable! ⇒ Object
- #imei ⇒ Object
- #imsi ⇒ Object
-
#initialize(opts = {}) ⇒ Modem
constructor
A new instance of Modem.
- #inspect ⇒ Object
- #model ⇒ Object
- #operator_code ⇒ Object
- #scan ⇒ Object
- #send_ussd(message) ⇒ Object
- #signal ⇒ Object
- #status ⇒ Object (also: #enabled?)
- #to_h ⇒ Object
- #ussd_state ⇒ Object
- #vendor ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Modem
Returns a new instance of Modem.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/network_manager/modem.rb', line 6 def initialize(opts = {}) opts.each do |k,v| instance_variable_set("@#{k}", v) unless v.nil? end unless defined?(@service) @bus ||= DBus::SystemBus.instance @service = @bus.service(NetworkManager::MM_DBUS_SERVICE) end # Set DBUS proxy @proxy = @service.object(@bus_path) @proxy.introspect @properties = @proxy.dup @properties.default_iface = NetworkManager::DBUS_PROPERTIES @properties.introspect @s_modem = @proxy[NetworkManager::MM_DBUS_INTERFACE_MODEM_SIMPLE] @modem = @proxy[NetworkManager::MM_DBUS_INTERFACE_MODEM] @network = @proxy[NetworkManager::MM_DBUS_INTERFACE_MODEM_GSM_NETWORK] @ussd = @proxy[NetworkManager::MM_DBUS_INTERFACE_MODEM_GSM_USSD] @device_info = @properties.GetInfo[0] rescue nil end |
Instance Attribute Details
#bus_path ⇒ Object (readonly) Also known as: dbus_path
Returns the value of attribute bus_path.
4 5 6 |
# File 'lib/network_manager/modem.rb', line 4 def bus_path @bus_path end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
4 5 6 |
# File 'lib/network_manager/modem.rb', line 4 def service @service end |
Class Method Details
.fetch(paths_array, opts = {}) ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/network_manager/modem.rb', line 132 def fetch(paths_array, opts = {}) devices = [] paths_array.compact.reject {|x| x && x.size <= 0 }.each do |path| devices << self.new(opts.merge({bus_path: path})) end devices end |
Instance Method Details
#device ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/network_manager/modem.rb', line 96 def device { model: model, port: @properties[MM_DBUS_INTERFACE_MODEM]['Device'], unlock_required: @properties[MM_DBUS_INTERFACE_MODEM]['UnlockRequired'], master_device: @properties[MM_DBUS_INTERFACE_MODEM]['MasterDevice'], dbus_path: @bus_path } end |
#disable! ⇒ Object
40 41 42 |
# File 'lib/network_manager/modem.rb', line 40 def disable! @modem.Enable(false) == [] if enabled? end |
#disabled? ⇒ Boolean
36 37 38 |
# File 'lib/network_manager/modem.rb', line 36 def disabled? !enabled? end |
#enable! ⇒ Object
32 33 34 |
# File 'lib/network_manager/modem.rb', line 32 def enable! @modem.Enable(true) == [] if disabled? end |
#imei ⇒ Object
69 70 71 |
# File 'lib/network_manager/modem.rb', line 69 def imei @properties.GetImei[0] rescue nil end |
#imsi ⇒ Object
73 74 75 |
# File 'lib/network_manager/modem.rb', line 73 def imsi @properties.GetImsi[0] rescue nil end |
#inspect ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/network_manager/modem.rb', line 110 def inspect if enabled? "#<NetworkManager::Modem##{object_id} IMEI: #{imei} Device: #{vendor} #{model} #{version} USSD_STATE: #{ussd_state}>" else "#<NetworkManager::Modem##{object_id} DISABLED Device: #{vendor} #{model} #{version}" end end |
#model ⇒ Object
44 45 46 |
# File 'lib/network_manager/modem.rb', line 44 def model @device_info[1] rescue nil end |
#operator_code ⇒ Object
53 54 55 |
# File 'lib/network_manager/modem.rb', line 53 def operator_code status["operator_code"] rescue nil end |
#scan ⇒ Object
77 78 79 |
# File 'lib/network_manager/modem.rb', line 77 def scan @network.Scan[0] rescue nil end |
#send_ussd(message) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/network_manager/modem.rb', line 81 def send_ussd() rsp = case ussd_state when 'idle' @ussd.Initiate() when 'active' @ussd.Cancel rescue nil @ussd.Initiate() when 'user-response' @ussd.Respond() end # @ussd.Cancel rescue nil rsp[0] if rsp.is_a?(Array) end |
#signal ⇒ Object
65 66 67 |
# File 'lib/network_manager/modem.rb', line 65 def signal @properties.GetSignalQuality[0] rescue 0 end |
#status ⇒ Object Also known as: enabled?
48 49 50 |
# File 'lib/network_manager/modem.rb', line 48 def status @properties['org.freedesktop.ModemManager.Modem']['Enabled'] end |
#to_h ⇒ Object
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/network_manager/modem.rb', line 118 def to_h { imei: imei, imsi: imsi, signal: signal, operator_code: operator_code, device: device, status: (enabled? ? :enabled : :disabled ) } end |
#ussd_state ⇒ Object
106 107 108 |
# File 'lib/network_manager/modem.rb', line 106 def ussd_state @properties['org.freedesktop.ModemManager.Modem.Gsm.Ussd']['State'] end |
#vendor ⇒ Object
57 58 59 |
# File 'lib/network_manager/modem.rb', line 57 def vendor @device_info[0] rescue nil end |
#version ⇒ Object
61 62 63 |
# File 'lib/network_manager/modem.rb', line 61 def version @device_info[2] rescue nil end |