Sha256: 5a60e2e50786268011f578fa8b345cfd3080096faccf70a39e214eba7b4867d6

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

require 'osc'
require 'rca_command'

module CanControlsGateway

  class OscToRcaDispatcher
    
    attr_reader :event, :raw_data, :osc_packet, :osc_message
    
    def initialize data
      @raw_data    = data
      @osc_packet  = OSC::Packet.decode @raw_data rescue @osc_packet = nil
      @osc_message = @osc_packet[0][1] rescue @osc_message = nil
      @event       = extract_event @osc_message
    end
    
    def dispatch_rca
      return true if @event.nil?
      my_args = { 'action' => @event }
      Ccg.logger.info "OscToRcaDispatcher: sending command : rci_uri: #{STATION['rci_uri']}, target: #{STATION['target']}, args: #{my_args.inspect}"
      my_command = CanControlsGateway::RcaCommand.new STATION['rci_uri'],
                                                      STATION['target'],
                                                      my_args
      Ccg.logger.info my_command.send_command
    end
    
    private
    
    def extract_event omsg
      return nil if omsg.nil?
      if omsg[0].kind_of?(OSC::OSCString) #s
        EVENTS[omsg[0].to_s]
      elsif omsg[2].kind_of?(OSC::OSCString) # ffs
        EVENTS[omsg[2].to_s]
      else
        nil # something else, e.g. ff
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tg-can-controls-gateway-0.1.3 lib/osc_to_rca_dispatcher.rb