Class: Device::Network
- Inherits:
-
Object
- Object
- Device::Network
- Defined in:
- lib/device/network.rb
Constant Summary collapse
- MEDIA_GPRS =
"gprs"- MEDIA_WIFI =
"wifi"- MEDIA_ETHERNET =
"ethernet"- AUTH_NONE_OPEN =
"open"- AUTH_NONE_WEP =
"wep"- AUTH_NONE_WEP_SHARED =
"wepshared"- AUTH_IEEE8021X =
"IEEE8021X"- AUTH_WPA_PSK =
"wpapsk"- AUTH_WPA_WPA2_PSK =
"wpawpa2psk"- AUTH_WPA2_PSK =
"wpa2psk"- PARE_CIPHERS_NONE =
"none"- PARE_CIPHERS_WEP64 =
"wep64"- PARE_CIPHERS_WEP128 =
"wep128"- PARE_CIPHERS_WEPX =
"wepx"- PARE_CIPHERS_CCMP =
"ccmp"- PARE_CIPHERS_TKIP =
"tkip"- MODE_IBSS =
"ibss"- MODE_STATION =
"station"- TIMEOUT =
-3320
- NO_CONNECTION =
-1012
- SUCCESS =
0- PROCESSING =
1
Class Attribute Summary collapse
-
.apn ⇒ Object
Returns the value of attribute apn.
-
.password ⇒ Object
Returns the value of attribute password.
-
.socket ⇒ Object
Returns the value of attribute socket.
-
.type ⇒ Object
Returns the value of attribute type.
-
.user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
- .adapter ⇒ Object
- .attach ⇒ Object
- .config ⇒ Object
-
.config_media ⇒ Object
TODO should check if WIFI, ETHERNET and etc.
- .configured? ⇒ Boolean
- .connect ⇒ Object
- .connected? ⇒ Boolean
- .dhcp_client(timeout) ⇒ Object
- .disconnect ⇒ Object
- .ethernet? ⇒ Boolean
- .gprs? ⇒ Boolean
- .init(type, options) ⇒ Object
- .ping(host, port) ⇒ Object
- .power(command) ⇒ Object
-
.scan ⇒ Array
Scan for wifi aps available.
-
.signal ⇒ Fixnum
Check signal value.
- .sim_id ⇒ Object
- .wifi? ⇒ Boolean
Class Attribute Details
.apn ⇒ Object
Returns the value of attribute apn.
38 39 40 |
# File 'lib/device/network.rb', line 38 def apn @apn end |
.password ⇒ Object
Returns the value of attribute password.
38 39 40 |
# File 'lib/device/network.rb', line 38 def password @password end |
.socket ⇒ Object
Returns the value of attribute socket.
38 39 40 |
# File 'lib/device/network.rb', line 38 def socket @socket end |
.type ⇒ Object
Returns the value of attribute type.
38 39 40 |
# File 'lib/device/network.rb', line 38 def type @type end |
.user ⇒ Object
Returns the value of attribute user.
38 39 40 |
# File 'lib/device/network.rb', line 38 def user @user end |
Class Method Details
.adapter ⇒ Object
47 48 49 |
# File 'lib/device/network.rb', line 47 def self.adapter Device.adapter::Network end |
.attach ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/device/network.rb', line 138 def self.attach ret = Device::Network.connected? if ret != SUCCESS ret = Device::Network.init(*self.config) ret = Device::Network.connect ret = Device::Network.connected? if ret != SUCCESS while(ret == PROCESSING) ret = Device::Network.connected? end if ret == SUCCESS && (wifi? || ethernet?) Device::Network.dhcp_client(20000) end Device::Setting.network_configured = 0 if ret != SUCCESS end ret end |
.config ⇒ Object
155 156 157 158 |
# File 'lib/device/network.rb', line 155 def self.config # TODO raise some error if media was not set [Device::Setting.media, self.config_media] end |
.config_media ⇒ Object
TODO should check if WIFI, ETHERNET and etc
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/device/network.rb', line 161 def self.config_media if gprs? { apn: Device::Setting.apn, user: Device::Setting.user, password: Device::Setting.password } elsif wifi? { authentication: Device::Setting.authentication, password: Device::Setting.password, essid: Device::Setting.essid, channel: Device::Setting.channel, cipher: Device::Setting.cipher, mode: Device::Setting.mode } elsif ethernet? Hash.new end end |
.configured? ⇒ Boolean
72 73 74 |
# File 'lib/device/network.rb', line 72 def self.configured? Device::Setting.network_configured == "1" end |
.connect ⇒ Object
59 60 61 |
# File 'lib/device/network.rb', line 59 def self.connect adapter.connect end |
.connected? ⇒ Boolean
63 64 65 66 67 68 69 70 |
# File 'lib/device/network.rb', line 63 def self.connected? if self.adapter.started? || (self.configured? && Device::Network.init(*self.config) == SUCCESS) return adapter.connected? end NO_CONNECTION end |
.dhcp_client(timeout) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/device/network.rb', line 125 def self.dhcp_client(timeout) time = Time.now + (timeout.to_f / 1000.0) ret = adapter.dhcp_client_start if (ret == SUCCESS) ret = PROCESSING while(ret == PROCESSING) # 1 - In process to attach ret = adapter.dhcp_client_check break ret = TIMEOUT unless (time >= Time.now) end end ret end |
.disconnect ⇒ Object
80 81 82 |
# File 'lib/device/network.rb', line 80 def self.disconnect adapter.disconnect end |
.ethernet? ⇒ Boolean
190 191 192 |
# File 'lib/device/network.rb', line 190 def self.ethernet? Device::Setting.media == "ethernet" end |
.gprs? ⇒ Boolean
182 183 184 |
# File 'lib/device/network.rb', line 182 def self.gprs? Device::Setting.media == "gprs" end |
.init(type, options) ⇒ Object
51 52 53 |
# File 'lib/device/network.rb', line 51 def self.init(type, ) adapter.init(type, ) end |
.ping(host, port) ⇒ Object
76 77 78 |
# File 'lib/device/network.rb', line 76 def self.ping(host, port) adapter.ping(host, port) end |
.power(command) ⇒ Object
55 56 57 |
# File 'lib/device/network.rb', line 55 def self.power(command) adapter.power(command) end |
.scan ⇒ Array
Scan for wifi aps available
119 120 121 122 123 |
# File 'lib/device/network.rb', line 119 def self.scan if wifi? adapter.scan if Device::Network.init(*self.config) end end |
.signal ⇒ Fixnum
Check signal value
95 96 97 |
# File 'lib/device/network.rb', line 95 def self.signal adapter.signal end |
.sim_id ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/device/network.rb', line 84 def self.sim_id if adapter.respond_to? :sim_id adapter.sim_id else "" end end |