Class: LadderDrive::Emulator::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/plc/emulator/plc_plugins.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plc) ⇒ Plugin

Returns a new instance of Plugin.



112
113
114
115
116
117
# File 'lib/plc/emulator/plc_plugins.rb', line 112

def initialize plc
  @config = load_config
  @plc = plc
  @device_states = {}
  @trigger_states = {}
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



85
86
87
# File 'lib/plc/emulator/plc_plugins.rb', line 85

def config
  @config
end

#plcObject (readonly)

Returns the value of attribute plc.



84
85
86
# File 'lib/plc/emulator/plc_plugins.rb', line 84

def plc
  @plc
end

Class Method Details

.device_names_with_plc_from_str(plc, dev_str) ⇒ Object



98
99
100
# File 'lib/plc/emulator/plc_plugins.rb', line 98

def device_names_with_plc_from_str plc, dev_str
  devices_with_plc_from_str.map{|d| d.name}
end

.devices_with_plc_from_str(plc, dev_str) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/plc/emulator/plc_plugins.rb', line 89

def devices_with_plc_from_str plc, dev_str
  dev_str.split(",").map{|e| e.split("-")}.map do |devs|
    devs = devs.map{|d| plc.device_by_name d.strip}
    d1 = devs.first
    d2 = devs.last
    [d2.number - d1.number + 1, 1].max.times.inject([]){|a, i| a << d1; d1 += 1; a}
  end.flatten
end

Instance Method Details

#device_names_with_plc_from_str(plc, dev_str) ⇒ Object



108
109
110
# File 'lib/plc/emulator/plc_plugins.rb', line 108

def device_names_with_plc_from_str plc, dev_str
  self.class.device_names_with_plc_from_str plc, dev_str
end

#devices_with_plc_from_str(plc, dev_str) ⇒ Object



104
105
106
# File 'lib/plc/emulator/plc_plugins.rb', line 104

def devices_with_plc_from_str plc, dev_str
  self.class.devices_with_plc_from_str plc, dev_str
end

#disabled?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/plc/emulator/plc_plugins.rb', line 123

def disabled?
  config.empty? || config[:disable]
end

#nameObject



119
120
121
# File 'lib/plc/emulator/plc_plugins.rb', line 119

def name
  @name ||= self.class.name.split(":").last.underscore.scan(/(.*)_plugin$/).first.first
end

#run_cycle(plc) ⇒ Object



127
128
129
# File 'lib/plc/emulator/plc_plugins.rb', line 127

def run_cycle plc
  return false unless self.plc == plc
end

#trigger_state_for(trigger_config) ⇒ Object



138
139
140
# File 'lib/plc/emulator/plc_plugins.rb', line 138

def trigger_state_for trigger_config
  @trigger_states[trigger_config.object_id] ||= PluginTriggerState.new(plc, trigger_config)
end

#triggered?(trigger_config) ⇒ Boolean

Returns:

  • (Boolean)


131
132
133
134
135
136
# File 'lib/plc/emulator/plc_plugins.rb', line 131

def triggered? trigger_config
  state = trigger_state_for trigger_config
  state.reset
  state.update
  state.triggered?
end