module EISCP::Receiver::Discovery
This module discovers receivers on the local LAN.
Constants
- ONKYO_MAGIC
ISCP Magic Packet for Autodiscovery
Public Instance Methods
discover(discovery_port = Receiver::ONKYO_PORT)
click to toggle source
Returns an array of discovered Receiver
objects.
# File lib/eiscp/receiver/discovery.rb, line 30 def discover(discovery_port = Receiver::ONKYO_PORT) data = [] Socket.ip_address_list.each do | addr | if addr.ipv4? sock = UDPSocket.new sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true) sock.bind(addr.ip_address, discovery_port) sock.send(ONKYO_MAGIC, 0, '<broadcast>', discovery_port) loop do msg, addr = sock.recvfrom_nonblock(1024) data << Receiver.new(addr[2], ecn_string_to_ecn_array(msg)) rescue IO::WaitReadable io = IO.select([sock], nil, nil, 0.5) break if io.nil? end end end return data end
ecn_string_to_ecn_array(ecn_string)
click to toggle source
Populates Receiver
attributes with info from ECNQSTN response.
# File lib/eiscp/receiver/discovery.rb, line 17 def ecn_string_to_ecn_array(ecn_string) hash = {} message = Parser.parse(ecn_string) array = message.value.split('/') hash[:model] = array.shift hash[:port] = array.shift.to_i hash[:area] = array.shift hash[:mac_address] = array.shift hash end