Class: Dovado::Router::Info

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/dovado/router/info.rb,
lib/dovado/router/info/signal.rb,
lib/dovado/router/info/operator.rb,
lib/dovado/router/info/operator/telia.rb

Overview

Router information.

Since:

  • 1.0.0

Defined Under Namespace

Classes: Operator, Signal

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = nil) ⇒ Info

Create a new Dovado::Router::Info object.

Parameters:

  • args (Hash) (defaults to: nil)

    optional hash to initialize with.

Since:

  • 1.0.0



117
118
119
120
121
122
123
124
125
# File 'lib/dovado/router/info.rb', line 117

def initialize(args=nil)
  # Defaults
  @data = ThreadSafe::Cache.new

  @last_update = nil
  unless args.nil?
    @data = args
  end
end

Instance Attribute Details

#connected_devicesArray<String> (readonly)

Get connected devices

Returns:

  • (Array<String>)

    an array with connected devices

Since:

  • 1.0.3



112
113
114
# File 'lib/dovado/router/info.rb', line 112

def connected_devices
  @connected_devices
end

#connectionString (readonly)

Get the currently active connection

Returns:

  • (String)

    the port currently active as internet connection

Since:

  • 1.0.3



46
47
48
# File 'lib/dovado/router/info.rb', line 46

def connection
  @connection
end

#dateDate (readonly)

Get the current date on the router

Returns:

  • (Date)

    current date

Since:

  • 1.0.3



64
65
66
# File 'lib/dovado/router/info.rb', line 64

def date
  @date
end

#external_ipIPAddr (readonly)

Get the external IP address of the router

Returns:

  • (IPAddr)

    external IP address

Since:

  • 1.0.3



58
59
60
# File 'lib/dovado/router/info.rb', line 58

def external_ip
  @external_ip
end

#gps_latFloat (readonly)

Get the GPS latitude

Returns:

  • (Float)

    GPS latitude

Since:

  • 1.0.3



82
83
84
# File 'lib/dovado/router/info.rb', line 82

def gps_lat
  @gps_lat
end

#gps_longFloat (readonly)

Get the GPS longitude

Returns:

  • (Float)

    GPS longitude

Since:

  • 1.0.3



88
89
90
# File 'lib/dovado/router/info.rb', line 88

def gps_long
  @gps_long
end

#gps_typeString (readonly)

Get the GPS type

Returns:

  • (String)

    the type of GPS

Since:

  • 1.0.3



76
77
78
# File 'lib/dovado/router/info.rb', line 76

def gps_type
  @gps_type
end

#modem_statusString (readonly)

Get the current state of the connected modem

Returns:

  • (String)

    current state of the connected modem

Since:

  • 1.0.3



52
53
54
# File 'lib/dovado/router/info.rb', line 52

def modem_status
  @modem_status
end

#product_nameString (readonly)

Get the product name

Returns:

  • (String)

    product name

Since:

  • 1.0.3



19
20
21
# File 'lib/dovado/router/info.rb', line 19

def product_name
  @product_name
end

#signal_strengthInfo::Signal (readonly)

Get the current signal strength information

Returns:

See Also:

  • Dovado::Router::Info.{Info{Info::Signal}

Since:

  • 1.0.3



26
27
28
# File 'lib/dovado/router/info.rb', line 26

def signal_strength
  @signal_strength
end

#smsSms (readonly)

Get the sms object

Returns:

  • (Sms)

    the sms object

Since:

  • 1.0.3



106
107
108
# File 'lib/dovado/router/info.rb', line 106

def sms
  @sms
end

#sunriseTime (readonly)

Get the sunrise at the current location

Returns:

  • (Time)

    sunrise at the current location

Since:

  • 1.0.3



94
95
96
# File 'lib/dovado/router/info.rb', line 94

def sunrise
  @sunrise
end

#sunsetTime (readonly)

Get sunset at the current location

Returns:

  • (Time)

    sunset at the current location

Since:

  • 1.0.3



100
101
102
# File 'lib/dovado/router/info.rb', line 100

def sunset
  @sunset
end

#timeTime (readonly)

Get the current time on the router

Returns:

  • (Time)

    current time

Since:

  • 1.0.3



70
71
72
# File 'lib/dovado/router/info.rb', line 70

def time
  @time
end

#traffic_modem_rxInteger (readonly)

Get the number of kilobytes read from the internet since last traffic counter reset.

Returns:

  • (Integer)

    number of kilobytes read from the internet

Since:

  • 1.0.3



40
41
42
# File 'lib/dovado/router/info.rb', line 40

def traffic_modem_rx
  @traffic_modem_rx
end

#traffic_modem_txInteger (readonly)

Get the number of kilobytes sent to the internet since last traffic counter reset.

Returns:

  • (Integer)

    number of kilobytes sent to the internet

Since:

  • 1.0.3



33
34
35
# File 'lib/dovado/router/info.rb', line 33

def traffic_modem_tx
  @traffic_modem_tx
end

Instance Method Details

#[](key) ⇒ Object

Fetch an entry from the Dovado::Router::Info object.

Parameters:

  • key (Symbol)

    The key to fetch.

Since:

  • 1.0.0



185
186
187
# File 'lib/dovado/router/info.rb', line 185

def [](key)
  @data[key]
end

#create_from_string(data_string = nil) ⇒ Object

Create a new Dovado::Router::Info object from a String.

Parameters:

  • data_string (String) (defaults to: nil)

    router information string from the router.

Since:

  • 1.0.0



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/dovado/router/info.rb', line 130

def create_from_string(data_string=nil)
  unless Actor[:sms]
    Sms.supervise as: :sms, size: 1
  end
  sms = Actor[:sms]
  data_array = data_string.split("\n")
  data_array.each do |data_entry|
    entry_array = data_entry.split('=')
    if entry_array.length == 2
      key = entry_array[0].downcase
      val = entry_array[1]
      keysym = Utilities.name_to_sym(key)
      case key
      when 'traffic_modem_tx', 'traffic_modem_rx'
        @data[keysym] = val.strip.to_i
      when 'time', 'sunset', 'sunrise'
        @data[keysym] = Time.parse(val.strip)
      when 'date'
        @data[:date] = Date.parse(val.strip)
      when 'sms_unread'
        @data[:sms] = sms if @data[:sms].nil?
        @data[:sms].unread = val.strip.to_i
      when 'sms_total'
        @data[:sms] = sms if @data[:sms].nil?
        @data[:sms].total = val.strip.to_i
      when 'connected_devices'
        val = val.strip.split(',')
        @data[keysym] = val
      when 'gps_lat', 'gps_long'
        @data[keysym] = val.to_f
      when 'external_ip'
        @data[keysym] = IPAddr.new val.strip
      when 'signal_strength'
        match = val.strip.match(/(\d+)\W\%\W(\-?\d+)\WdBm\W\((\d\w)\)/)
        so = Info::Signal.new(strength: match[1], noise: match[2], network: match[3])
        @data[keysym] = so
      else
        @data[keysym] = val.strip
      end
    end
  end
  touch!
end

#has_key?(key) ⇒ Boolean

Check if the Dovado::Router::Info object has a given key.

Parameters:

  • key (Symbol)

    the key to check for.

Returns:

  • (Boolean)

    true or false

Since:

  • 1.0.0



200
201
202
# File 'lib/dovado/router/info.rb', line 200

def has_key?(key)
  keys.member?(key)
end

#keysArray<Symbol>

Fetch the list of entries in the Dovado::Router::Info object.

Returns:

  • (Array<Symbol>)

Since:

  • 1.0.0



192
193
194
# File 'lib/dovado/router/info.rb', line 192

def keys
  @data.keys
end

#valid?Boolean

Determine if this info object is valid.

Returns:

  • (Boolean)

    true or false.

Since:

  • 1.0.0



177
178
179
180
# File 'lib/dovado/router/info.rb', line 177

def valid?
  return false if @last_update.nil?
  (@last_update + SecureRandom.random_number(9) + 1 <= Time.now.to_i)
end