Class: Samsung::Remote
- Inherits:
-
Object
- Object
- Samsung::Remote
- Defined in:
- lib/samsung/remote.rb
Constant Summary collapse
- PORT =
55000
- APP_NAME =
"net.kapati.samsung.remote"
Instance Attribute Summary collapse
-
#display_name ⇒ Object
Returns the value of attribute display_name.
-
#ip ⇒ Object
Returns the value of attribute ip.
Instance Method Summary collapse
- #connect ⇒ Object
- #has_data?(wait = 0) ⇒ Boolean
-
#initialize(ip, display_name = "Ruby") ⇒ Remote
constructor
A new instance of Remote.
- #peek_frame(wait = 1) ⇒ Object
- #read_frame ⇒ Object
- #send_auth ⇒ Object
- #send_frame(frame) ⇒ Object
- #send_key(key_code) ⇒ Object
Constructor Details
#initialize(ip, display_name = "Ruby") ⇒ Remote
Returns a new instance of Remote.
10 11 12 13 14 15 |
# 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 |
Instance Attribute Details
#display_name ⇒ Object
Returns the value of attribute display_name.
8 9 10 |
# File 'lib/samsung/remote.rb', line 8 def display_name @display_name end |
#ip ⇒ Object
Returns the value of attribute ip.
8 9 10 |
# File 'lib/samsung/remote.rb', line 8 def ip @ip end |
Instance Method Details
#connect ⇒ Object
32 33 34 |
# File 'lib/samsung/remote.rb', line 32 def connect @socket = TCPSocket.open ip, PORT end |
#has_data?(wait = 0) ⇒ Boolean
17 18 19 20 |
# 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) ⇒ Object
22 23 24 25 |
# File 'lib/samsung/remote.rb', line 22 def peek_frame(wait = 1) return nil unless has_data?(wait) read_frame end |
#read_frame ⇒ Object
27 28 29 30 |
# File 'lib/samsung/remote.rb', line 27 def read_frame data = @socket.readpartial(512) Protocol::Response.new(data) end |
#send_auth ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# 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) ⇒ Object
36 37 38 39 40 |
# File 'lib/samsung/remote.rb', line 36 def send_frame(frame) f = build_header f.push_frame(frame) @socket.write(f.data) end |