Class: NetworkManager::Modem

Inherits:
Object
  • Object
show all
Defined in:
lib/network_manager/modem.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_pathObject (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

#serviceObject (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

#deviceObject



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

Returns:

  • (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

#imeiObject



69
70
71
# File 'lib/network_manager/modem.rb', line 69

def imei
  @properties.GetImei[0] rescue nil
end

#imsiObject



73
74
75
# File 'lib/network_manager/modem.rb', line 73

def imsi
  @properties.GetImsi[0] rescue nil
end

#inspectObject



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

#modelObject



44
45
46
# File 'lib/network_manager/modem.rb', line 44

def model
  @device_info[1] rescue nil
end

#operator_codeObject



53
54
55
# File 'lib/network_manager/modem.rb', line 53

def operator_code
  status["operator_code"] rescue nil
end

#scanObject



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(message)
  rsp = case ussd_state
  when 'idle'
    @ussd.Initiate(message)
  when 'active'
    @ussd.Cancel rescue nil
    @ussd.Initiate(message)
  when 'user-response'
    @ussd.Respond(message)
  end

  # @ussd.Cancel rescue nil
  rsp[0] if rsp.is_a?(Array)
end

#signalObject



65
66
67
# File 'lib/network_manager/modem.rb', line 65

def signal
  @properties.GetSignalQuality[0] rescue 0
end

#statusObject 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_hObject



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_stateObject



106
107
108
# File 'lib/network_manager/modem.rb', line 106

def ussd_state
  @properties['org.freedesktop.ModemManager.Modem.Gsm.Ussd']['State']
end

#vendorObject



57
58
59
# File 'lib/network_manager/modem.rb', line 57

def vendor
  @device_info[0] rescue nil
end

#versionObject



61
62
63
# File 'lib/network_manager/modem.rb', line 61

def version
  @device_info[2] rescue nil
end