Class RDremoconConnector
In: rdremocon.rb
Parent: Object

ネットリモコンの通信をエミュレートするクラス

USAGE

  1. 起動する
      rdremo = RDremoconConnector.new("rd-x6")
    
  2. 通信を開始する(スレッドを生成し、以後は逐次通信状態になります)
      rdremo.start()
    
  3. 以後はイベントが起こるたびに〜changedで登録したメソッドが呼ばれます。

Methods

Constants

ConnectionCommand = "\x10\x48"   接続中に送りつづけるコマンド 16進数で1048

Attributes

channel  [R]  チャンネル
netkeyboard  [R]  ネットキーボードの状態(ON=1 OFF=0)
no  [R]  タイトル番号
time_now  [R]  再生中の時間(秒数)
time_now2  [R]  チャプター始点からの時間(秒数)
time_tortal  [R]  総時間(秒数)
title  [R]  タイトル名

Public Class methods

初期化する

 host ホスト名

[Source]

# File rdremocon.rb, line 54
  def initialize(host)
    @host = host

    #現在のタイトル
    @title = ""
    #現在の番号
    @no = 0
    #現在の状態
    @status = 0
    #現在のファイルの総時間
    @time_tortal = 0
    #現在のチャンネル
    @channel = 0
    #現在の時刻
    @time_now = 0
    #チャプターからの時間
    @time_now2 = 0
    #ネットキーボードの状態(ON=1 OFF=0)
    @netkeyboard = 0
    #再生かどうか?(Play=2 Stop=0)
    @movie1 = 0
    #再生中の状態
    # [ ]=3 [>]=4 [<]=7 [||]=5 [>>]=6
    @movie2 = 0

    @proc_netkeyboard = nil
    @proc_title = nil
    @proc_time_tortal = nil
    @proc_time_now = nil
    @proc_movie1 = nil
  end

Public Instance methods

ネットキーボード状態が変化した場合に呼ばれるメソッドの登録

[Source]

# File rdremocon.rb, line 100
  def netkeyboard_changed
    @proc_netkeyboard = Proc.new
  end

再生停止時に呼ばれるメソッドの登録

[Source]

# File rdremocon.rb, line 120
  def play_stop_changed
    @proc_movie1 = Proc.new
  end

再生中の場合真を返す

[Source]

# File rdremocon.rb, line 87
  def playing?
    return (@movie1 == 2)
  end

通信スレッドを開始させる

[Source]

# File rdremocon.rb, line 125
  def start
    @thread = Thread.new{
      begin
        @socket = TCPSocket.open(@host, 1048)
        while true

          STDOUT << "-" * 40 + "\n" if $DEBUG
          @socket.write(ConnectionCommand)

          #まずサイズを受け取る
          head_size = @socket.read(2)
          size = head_size.unpack("n")[0]
          #サイズに合わせてレスポンスを取得
          response = @socket.read(size - 2)
          parse(response)
          if $DEBUG
            STDOUT.flush
            STDERR.flush
          end

        end
      rescue
        #エラー時の処理
        STDERR << $!
        exit(-1)
      ensure
        #抜けるときはソケットを閉じる
        @socket.close
      end
    }
  end

現在秒数が変化した場合に呼ばれるメソッドの登録

[Source]

# File rdremocon.rb, line 115
  def time_now_changed
    @proc_time_now = Proc.new
  end

時間の状態文字列を返す

[Source]

# File rdremocon.rb, line 92
  def time_status
    return format("%s / %s", time_to_s(@time_now), time_to_s(@time_tortal))
  end

トータル秒数が変化した場合に呼ばれるメソッド登録

[Source]

# File rdremocon.rb, line 110
  def time_tortal_changed
    @proc_time_tortal = Proc.new
  end

タイトルが変化した場合に呼ばれるメソッドの登録

[Source]

# File rdremocon.rb, line 105
  def title_changed
    @proc_title = Proc.new
  end

[Validate]