class Samsung::Remote

Constants

APP_NAME
PORT

Attributes

display_name[RW]
ip[RW]

Public Class Methods

new(ip, display_name = "Ruby") click to toggle source
# File lib/samsung/remote.rb, line 10
def initialize(ip, display_name = "Ruby")
  self.ip = ip
  self.display_name = display_name
  connect
  send_auth
end

Public Instance Methods

connect() click to toggle source
# File lib/samsung/remote.rb, line 32
def connect
  @socket = TCPSocket.open ip, PORT
end
has_data?(wait = 0) click to toggle source
# File lib/samsung/remote.rb, line 17
def has_data?(wait = 0)
  ready = IO.select([@socket], nil, nil, wait)
  return ready != nil
end
peek_frame(wait = 1) click to toggle source
# File lib/samsung/remote.rb, line 22
def peek_frame(wait = 1)
  return nil unless has_data?(wait)
  read_frame
end
read_frame() click to toggle source
# File lib/samsung/remote.rb, line 27
def read_frame
  data = @socket.readpartial(512)
  Protocol::Response.new(data)
end
send_auth() click to toggle source
# File lib/samsung/remote.rb, line 46
def send_auth
  net = Network.new
  send_frame(
    Protocol::AuthFrame.new(
      net.local_ip,
      net.local_hw_address,
      display_name
    )
  )
end
send_frame(frame) click to toggle source
# File lib/samsung/remote.rb, line 36
def send_frame(frame)
  f = build_header
  f.push_frame(frame)
  @socket.write(f.data)
end
send_key(key_code) click to toggle source
# File lib/samsung/remote.rb, line 42
def send_key key_code
  send_frame(Protocol::KeyFrame.new(key_code))
end

Private Instance Methods

build_header() click to toggle source
# File lib/samsung/remote.rb, line 59
def build_header
  Protocol::HeaderFrame.new(APP_NAME)
end