class Dovado::Router::Info

Router information.

@since 1.0.0

Attributes

connected_devices[R]

Get connected devices

@return [Array<String>] an array with connected devices @since 1.0.3

connection[R]

Get the currently active connection

@return [String] the port currently active as internet connection @since 1.0.3

date[R]

Get the current date on the router

@return [Date] current date @since 1.0.3

external_ip[R]

Get the external IP address of the router

@return [IPAddr] external IP address @since 1.0.3

gps_lat[R]

Get the GPS latitude

@return [Float] GPS latitude @since 1.0.3

gps_long[R]

Get the GPS longitude

@return [Float] GPS longitude @since 1.0.3

gps_type[R]

Get the GPS type

@return [String] the type of GPS @since 1.0.3

modem_status[R]

Get the current state of the connected modem

@return [String] current state of the connected modem @since 1.0.3

product_name[R]

Get the product name

@return [String] product name @since 1.0.3

signal_strength[R]

Get the current signal strength information

@return [Info::Signal] current signal strength information @since 1.0.3 @see {Info::Signal}

sms[R]

Get the sms object

@return [Sms] the sms object @since 1.0.3

sunrise[R]

Get the sunrise at the current location

@return [Time] sunrise at the current location @since 1.0.3

sunset[R]

Get sunset at the current location

@return [Time] sunset at the current location @since 1.0.3

time[R]

Get the current time on the router

@return [Time] current time @since 1.0.3

traffic_modem_rx[R]

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

@return [Integer] number of kilobytes read from the internet @since 1.0.3

traffic_modem_tx[R]

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

@return [Integer] number of kilobytes sent to the internet @since 1.0.3

Public Class Methods

new(args=nil) click to toggle source

Create a new {Info} object.

@param [Hash] args optional hash to initialize with.

# 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
setup_supervision!() click to toggle source

@api private

# File lib/dovado/router/info.rb, line 282
def self.setup_supervision!
  return supervise as: :router_info, size: 1 unless Actor[:router_info]
  return supervise as: :router_info, size: 1 if Actor[:router_info] and Actor[:router_info].dead?
end

Public Instance Methods

[](key) click to toggle source

Fetch an entry from the {Info} object.

@param [Symbol] key The key to fetch.

# File lib/dovado/router/info.rb, line 198
def [](key)
  @data[key]
end
create_from_string(data_string=nil) click to toggle source

Create a new {Info} object from a String.

@param [String] data_string router information string from the router. @api private

# File lib/dovado/router/info.rb, line 143
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) click to toggle source

Check if the {Info} object has a given key.

@param [Symbol] key the key to check for. @return [Boolean] true or false

# File lib/dovado/router/info.rb, line 213
def has_key?(key)
  keys.member?(key)
end
keys() click to toggle source

Fetch the list of entries in the {Info} object.

@return [Array<Symbol>]

# File lib/dovado/router/info.rb, line 205
def keys
  @data.keys
end
update!() click to toggle source

Update the data in this {Info} object.

# File lib/dovado/router/info.rb, line 128
def update!
  client = Actor[:client]
  client.connect unless client.connected?
  client.authenticate unless client.authenticated?
  info = client.command('info')
  create_from_string info
rescue ConnectionError => ex
  Actor[:client].terminate
  raise ex
end
valid?() click to toggle source

Determine if this info object is valid.

@return [Boolean] true or false.

# File lib/dovado/router/info.rb, line 190
def valid?
  return false if @last_update.nil?
  (@last_update + SecureRandom.random_number(9) + 1 <= Time.now.to_i)
end

Private Instance Methods

omni_method() click to toggle source
# File lib/dovado/router/info.rb, line 289
def omni_method
  this_method = caller[0][/`([^']*)'/, 1]
  @data[this_method.to_sym]
end
touch!() click to toggle source
# File lib/dovado/router/info.rb, line 294
def touch!
  @last_update = Time.now.to_i
end