class SiriProxy::Plugin::SamsungRemote

Attributes

myip[RW]
mymac[RW]
port[RW]
tvip[RW]

Public Class Methods

new(config = {}) click to toggle source
# File lib/siriproxy-samsungremote.rb, line 58
def initialize(config = {})
  
  self.tvip = config["tvip"]
  self.myip = config["myip"]
  self.mymac = config["mymac"]
  self.port = '55000'
end

Public Instance Methods

close_socket() click to toggle source
# File lib/siriproxy-samsungremote.rb, line 225
def close_socket
   @s.close               # Close the socket when done
end
press_the(btn) click to toggle source
# File lib/siriproxy-samsungremote.rb, line 179
def press_the(btn)
  if @@know_btns.include?(btn.upcase)
    send_hanshake
    send_command btn.upcase
    close_socket
    say "#{btn} pressed"
    request_completed #always complete your request! Otherwise the phone will "spin" at the user!
  else
    say "I can't find the #{btn} button right now"
    ask "Try again"
    request_completed #always complete your request! Otherwise the phone will "spin" at the user!
  end
  
end
send_command(command) click to toggle source
# File lib/siriproxy-samsungremote.rb, line 212
def send_command(command)
  
  #Send remote key
  key = "KEY_" + command
  # say "Sending #{command}"
  messagepart3 = 0x00.chr + 0x00.chr + 0x00.chr + Base64.encode64(key).length.chr + 0x00.chr + Base64.encode64(key)
  part3 = 0x00.chr + @@tvappstring.length.chr + 0x00.chr + @@tvappstring + messagepart3.length.chr + 0x00.chr + messagepart3

  @s.send(part3, 0)

 
end
send_hanshake() click to toggle source
# File lib/siriproxy-samsungremote.rb, line 194
def send_hanshake
  @s = TCPSocket.open(self.tvip, self.port)

  ipencoded = Base64.encode64(self.myip)
      macencoded = Base64.encode64(self.mymac)

  messagepart1 = 0x64.chr + 0x00.chr + ipencoded.length.chr + 0x00.chr + ipencoded + macencoded.length.chr + 0x00.chr + macencoded + Base64.encode64(@@remotename).length.chr + 0x00.chr + Base64.encode64(@@remotename)
  part1 = 0x00.chr + @@appstring.length.chr + 0x00.chr + @@appstring + messagepart1.length.chr + 0x00.chr + messagepart1

  @s.send(part1, 0)
  
  messagepart2 = 0xc8.chr + 0x00.chr
  part2 = 0x00.chr + @@appstring.length.chr + 0x00.chr + @@appstring + messagepart2.length.chr + 0x00.chr + messagepart2
  
  @s.send(part2, 0)
  
end