Module: RSMP::SupervisorProxy::Modules::Commands
- Included in:
- RSMP::SupervisorProxy
- Defined in:
- lib/rsmp/proxy/supervisor/modules/commands.rb
Overview
Command request handling
Instance Method Summary collapse
- #build_command_rvs(args) ⇒ Object
- #execute_commands(message, component_id, rvs) ⇒ Object
- #process_command_request(message) ⇒ Object
- #simplify_command_requests(arg) ⇒ Object
Instance Method Details
#build_command_rvs(args) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/rsmp/proxy/supervisor/modules/commands.rb', line 15 def build_command_rvs(args) args.map do |item| item = item.dup.merge('age' => 'recent') item.delete 'cO' item end end |
#execute_commands(message, component_id, rvs) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rsmp/proxy/supervisor/modules/commands.rb', line 23 def execute_commands(, component_id, rvs) component = @site.find_component component_id commands = simplify_command_requests .attributes['arg'] commands.each_pair do |command_code, arg| component.handle_command command_code, arg end log "Received #{message.type}", message: , level: :log rescue UnknownComponent log "Received #{message.type} with unknown component id '#{component_id}' and cannot infer type", message: , level: :warning rvs.map { |item| item['age'] = 'undefined' } end |
#process_command_request(message) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rsmp/proxy/supervisor/modules/commands.rb', line 36 def process_command_request() component_id = .attributes['cId'] rvs = build_command_rvs(.attributes['arg']) execute_commands(, component_id, rvs) response = CommandResponse.new({ 'cId' => component_id, 'cTS' => clock.to_s, 'rvs' => rvs }) response acknowledge response end |
#simplify_command_requests(arg) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/rsmp/proxy/supervisor/modules/commands.rb', line 6 def simplify_command_requests(arg) sorted = {} arg.each do |item| sorted[item['cCI']] ||= {} sorted[item['cCI']][item['n']] = item['v'] end sorted end |