Sha256: 7ca0deec8914e5a488c7012e8ee692a5f0d5948535ca54148b25a90fbe9dee82

Contents?: true

Size: 1.53 KB

Versions: 18

Compression:

Stored size: 1.53 KB

Contents

class ProconBypassMan::DeviceConnection::PreBypass
  attr_accessor :gadget, :procon, :output_report_watcher

  def initialize(gadget: , procon: )
    self.gadget = ProconBypassMan::DeviceModel.new(gadget)
    self.procon = ProconBypassMan::DeviceModel.new(procon)
    self.output_report_watcher = ProconBypassMan::DeviceConnection::OutputReportWatcher.new
  end

  # @return [void]
  def execute!
    loop do
      run_once

      if output_report_watcher.timeout_or_completed?
        break
      end
    end
  end

  # @return [void]
  def run_once
    begin
      raw_data = non_blocking_read_switch
      output_report_watcher.mark_as_send(raw_data)
      ProconBypassMan.logger.info "[pre_bypass] >>> #{raw_data.unpack("H*").first}"
      send_procon(raw_data)
    rescue IO::EAGAINWaitReadable
      # no-op
    end

    3.times do
      begin
        raw_data = non_blocking_read_procon
        output_report_watcher.mark_as_receive(raw_data)
        ProconBypassMan.logger.info "[pre_bypass] <<< #{raw_data.unpack("H*").first}"
        send_switch(raw_data)
      rescue IO::EAGAINWaitReadable
        # no-op
      end
    end
  end

  private

  # @raise [IO::EAGAINWaitReadable]
  # @return [String]
  def non_blocking_read_switch
    gadget.non_blocking_read
  end

  # @raise [IO::EAGAINWaitReadable]
  # @return [String]
  def non_blocking_read_procon
    procon.non_blocking_read
  end

  # @return [void]
  def send_procon(raw_data)
    procon.send(raw_data)
  end

  # @return [void]
  def send_switch(raw_data)
    gadget.send(raw_data)
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
procon_bypass_man-0.3.11 lib/procon_bypass_man/device_connection/pre_bypass.rb
procon_bypass_man-0.3.10 lib/procon_bypass_man/device_connection/pre_bypass.rb
procon_bypass_man-0.3.9 lib/procon_bypass_man/device_connection/pre_bypass.rb
procon_bypass_man-0.3.8.1 lib/procon_bypass_man/device_connection/pre_bypass.rb
procon_bypass_man-0.3.8 lib/procon_bypass_man/device_connection/pre_bypass.rb
procon_bypass_man-0.3.7 lib/procon_bypass_man/device_connection/pre_bypass.rb
procon_bypass_man-0.3.6 lib/procon_bypass_man/device_connection/pre_bypass.rb
procon_bypass_man-0.3.5 lib/procon_bypass_man/device_connection/pre_bypass.rb
procon_bypass_man-0.3.4 lib/procon_bypass_man/device_connection/pre_bypass.rb
procon_bypass_man-0.3.3.1 lib/procon_bypass_man/device_connection/pre_bypass.rb
procon_bypass_man-0.3.3 lib/procon_bypass_man/device_connection/pre_bypass.rb
procon_bypass_man-0.3.2 lib/procon_bypass_man/device_connection/pre_bypass.rb
procon_bypass_man-0.3.1 lib/procon_bypass_man/device_connection/pre_bypass.rb
procon_bypass_man-0.3.0 lib/procon_bypass_man/device_connection/pre_bypass.rb
procon_bypass_man-0.2.3 lib/procon_bypass_man/device_connection/pre_bypass.rb
procon_bypass_man-0.2.2 lib/procon_bypass_man/device_connection/pre_bypass.rb
procon_bypass_man-0.2.1 lib/procon_bypass_man/device_connection/pre_bypass.rb
procon_bypass_man-0.2.0 lib/procon_bypass_man/device_connection/pre_bypass.rb