read skynet return address

pull/2/head
TimEvWw 2014-02-27 21:13:31 -01:00
parent c7ad7db1b0
commit 02ee099a59
3 changed files with 19 additions and 12 deletions

View File

@ -8,7 +8,7 @@ class HardwareInterface
@pos_z = 0.0 @pos_z = 0.0
# should come from configuration: # should come from configuration:
@move_home_timeout = 3 # seconds after which home command is aborted @move_home_timeout = 30 # seconds after which home command is aborted
@sleep_after_pin_set = 0.005 @sleep_after_pin_set = 0.005
@sleep_after_enable = 0.001 @sleep_after_enable = 0.001

View File

@ -19,7 +19,7 @@ class MessageHandler
end end
# Main entry point for (Hash) commands coming in over SkyNet. # Main entry point for (Hash) commands coming in over SkyNet.
#{ # {
# "message_type" : "single_command", # "message_type" : "single_command",
# "time_stamp" : 2001-01-01 01:01:01.001 # "time_stamp" : 2001-01-01 01:01:01.001
# "command" : { # "command" : {
@ -31,8 +31,8 @@ class MessageHandler
# "amount" : 5, # "amount" : 5,
# "delay" : 6 # "delay" : 6
# } # }
#} # }
def handle_message(skynet, channel, message) def handle_message(channel, message)
@message = message @message = message
requested_command = message["message_type"].to_s.downcase requested_command = message["message_type"].to_s.downcase
if whitelist.include?(requested_command) if whitelist.include?(requested_command)
@ -50,10 +50,12 @@ class MessageHandler
def single_command(message) def single_command(message)
time_stamp = message['time_stamp'] time_stamp = message['time_stamp']
sender = message['fromUuid']
if time_stamp != @last_time_stamp if time_stamp != @last_time_stamp
@last_time_stamp = time_stamp @last_time_stamp = time_stamp
# send the command to the queue # send the command to the queue
delay = message['command']['delay'] delay = message['command']['delay']
action = message['command']['action'] action = message['command']['action']
@ -64,7 +66,7 @@ class MessageHandler
amount = message['command']['amount'] amount = message['command']['amount']
delay = message['command']['delay'] delay = message['command']['delay']
puts "[new command] received at #{Time.now}" puts "[new command] received at #{Time.now} from #{sender}"
puts "[#{action}] x: #{x}, y: #{y}, z: #{z}, speed: #{speed}, amount: "\ puts "[#{action}] x: #{x}, y: #{y}, z: #{z}, speed: #{speed}, amount: "\
"#{amount} delay: #{delay}" "#{amount} delay: #{delay}"
@ -73,16 +75,17 @@ class MessageHandler
speed.to_s, amount.to_i) speed.to_s, amount.to_i)
@command_queue.save_new_command @command_queue.save_new_command
skynet.confirmed = false $skynet.confirmed = false
command = command =
{ {
:message_type => 'confirmation', :message_type => 'confirmation',
:time_stamp => Time.now.to_f.to_s, :time_stamp => Time.now.to_f.to_s,
:confirm_id => time_stamp :confirm_id => time_stamp
} }
skynet.send_message("44128811-8c59-11e3-b99a-11476114e05f", command) $skynet.send_message(sender, command)
end end
end end
end end

View File

@ -21,8 +21,12 @@ class Skynet
@uuid = creds[:uuid] @uuid = creds[:uuid]
@token = creds[:token] @token = creds[:token]
@socket = SocketIO::Client::Simple.connect 'http://skynet.im:80' @socket = SocketIO::Client::Simple.connect 'http://skynet.im:80'
@confirmed = false
create_socket_events create_socket_events
puts "uuid: #{@uuid}"
@message_handler = MessageHandler.new @message_handler = MessageHandler.new
end end
@ -36,16 +40,16 @@ class Skynet
def handle_message(channel, message) def handle_message(channel, message)
if message.class.to_s == 'Hash' if message.class.to_s == 'Hash'
@message_handler.handle_message(self, channel, message) @message_handler.handle_message(channel, message)
end end
if message.class.to_s == 'String' if message.class.to_s == 'String'
message_hash = JSON.parse(message) message_hash = JSON.parse(message)
@message_handler.handle_message(self, channel, message_hash) @message_handler.handle_message(channel, message_hash)
end end
rescue rescue
raise "Runtime error while attempting to parse message: #{message}." raise "Runtime error while attempting to parse message: #{message}."
end end
end end