Class: OmfEc::Context::NetContext

Inherits:
Object
  • Object
show all
Defined in:
omf_ec/lib/omf_ec/context/net_context.rb

Overview

Holds network related configuration

Constant Summary

FREQUENCY =

Wifi frequency channel matching

{
  1 => 2412, 2 => 2417, 3 => 2422, 4 => 2427, 5 => 2432, 6 => 2437,
  7 => 2442, 8 => 2447, 9 => 2452, 10 => 2457, 11 => 2462, 12 => 2467,
  13 => 2472, 14 => 2484, 36 => 5180, 40 => 5200, 44 => 5220, 48 => 5240,
  52 => 5260, 56 => 5280, 60 => 5300, 64 => 5320, 100 => 5500, 104 => 5520,
  108 => 5540, 112 => 5560, 116 => 5580, 120 => 5600, 124 => 5620, 128 => 5640,
  132 => 5660, 136 => 5680, 140 => 5700, 149 => 5745, 153 => 5765, 157 => 5785,
  161 => 5805, 165 => 5825
}

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (NetContext) initialize(opts)

Returns a new instance of NetContext



22
23
24
25
# File 'omf_ec/lib/omf_ec/context/net_context.rb', line 22

def initialize(opts)
  self.conf = opts
  self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(name, *args, &block)

Property assignment will simply update configuration

Examples:

OEDL

node.net.w0.mode = "adhoc"
node.net.w0.essid = "helloworld"


32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'omf_ec/lib/omf_ec/context/net_context.rb', line 32

def method_missing(name, *args, &block)
  if name =~ /(.+)=/
    net_prop = $1.to_sym
    net_prop = case net_prop
               when :type then :hw_mode
               when :ip then :ip_addr
               else
                 net_prop
               end
    self.conf.merge!(net_prop => args[0].to_s)
  else
    super
  end
end

Instance Attribute Details

- (Object) conf

Returns the value of attribute conf



20
21
22
# File 'omf_ec/lib/omf_ec/context/net_context.rb', line 20

def conf
  @conf
end

Instance Method Details

- (Object) map_channel_freq

Interchange channel and frequency value



48
49
50
51
52
53
54
55
56
# File 'omf_ec/lib/omf_ec/context/net_context.rb', line 48

def map_channel_freq
  if self.conf[:channel] && self.conf[:frequency].nil?
    self.conf[:frequency] = FREQUENCY[self.conf[:channel].to_s.to_i]
  end
  if self.conf[:channel].nil? && self.conf[:frequency]
    self.conf[:channel] = FREQUENCY.keys.find { |k| FREQUENCY[k] == self.conf[:frequency].to_sto_i }
  end
  self
end