Class | RDremoconConnector |
In: |
rdremocon.rb
|
Parent: | Object |
ネットリモコンの通信をエミュレートするクラス
rdremo = RDremoconConnector.new("rd-x6")
rdremo.start()
ConnectionCommand | = | "\x10\x48" | 接続中に送りつづけるコマンド 16進数で1048 |
channel | [R] | チャンネル |
netkeyboard | [R] | ネットキーボードの状態(ON=1 OFF=0) |
no | [R] | タイトル番号 |
time_now | [R] | 再生中の時間(秒数) |
time_now2 | [R] | チャプター始点からの時間(秒数) |
time_tortal | [R] | 総時間(秒数) |
title | [R] | タイトル名 |
初期化する
host ホスト名
# 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
ネットキーボード状態が変化した場合に呼ばれるメソッドの登録
# File rdremocon.rb, line 100 def netkeyboard_changed @proc_netkeyboard = Proc.new end
通信スレッドを開始させる
# 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
現在秒数が変化した場合に呼ばれるメソッドの登録
# File rdremocon.rb, line 115 def time_now_changed @proc_time_now = Proc.new end
時間の状態文字列を返す
# File rdremocon.rb, line 92 def time_status return format("%s / %s", time_to_s(@time_now), time_to_s(@time_tortal)) end
トータル秒数が変化した場合に呼ばれるメソッド登録
# File rdremocon.rb, line 110 def time_tortal_changed @proc_time_tortal = Proc.new end