class LadderDrive::Emulator::Plugin

Attributes

config[R]
plc[R]

Public Class Methods

device_names_with_plc_from_str(plc, dev_str) click to toggle source
# 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) click to toggle source
# 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
new(plc) click to toggle source
# File lib/plc/emulator/plc_plugins.rb, line 112
def initialize plc
  @config = load_config
  @plc = plc
  @device_states = {}
  @trigger_states = {}
end

Public Instance Methods

device_names_with_plc_from_str(plc, dev_str) click to toggle source
# 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) click to toggle source
# 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?() click to toggle source
# File lib/plc/emulator/plc_plugins.rb, line 123
def disabled?
  config.empty? || config[:disable]
end
name() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

load_config() click to toggle source
# File lib/plc/emulator/plc_plugins.rb, line 145
def load_config
  h = {}
  path = File.join("config", "plugins", "#{name}.yml")
  if File.exist?(path)
    erb = ERB.new File.read(path)
    h = YAML.load(erb.result(binding))
    h = JSON.parse(h.to_json, symbolize_names: true)
  end
  h
end