read skynet return address
parent
c7ad7db1b0
commit
02ee099a59
|
@ -8,7 +8,7 @@ class HardwareInterface
|
|||
@pos_z = 0.0
|
||||
|
||||
# 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_enable = 0.001
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class MessageHandler
|
|||
end
|
||||
|
||||
# Main entry point for (Hash) commands coming in over SkyNet.
|
||||
#{
|
||||
# {
|
||||
# "message_type" : "single_command",
|
||||
# "time_stamp" : 2001-01-01 01:01:01.001
|
||||
# "command" : {
|
||||
|
@ -31,8 +31,8 @@ class MessageHandler
|
|||
# "amount" : 5,
|
||||
# "delay" : 6
|
||||
# }
|
||||
#}
|
||||
def handle_message(skynet, channel, message)
|
||||
# }
|
||||
def handle_message(channel, message)
|
||||
@message = message
|
||||
requested_command = message["message_type"].to_s.downcase
|
||||
if whitelist.include?(requested_command)
|
||||
|
@ -50,10 +50,12 @@ class MessageHandler
|
|||
|
||||
def single_command(message)
|
||||
time_stamp = message['time_stamp']
|
||||
sender = message['fromUuid']
|
||||
|
||||
if time_stamp != @last_time_stamp
|
||||
@last_time_stamp = time_stamp
|
||||
|
||||
|
||||
# send the command to the queue
|
||||
delay = message['command']['delay']
|
||||
action = message['command']['action']
|
||||
|
@ -64,7 +66,7 @@ class MessageHandler
|
|||
amount = message['command']['amount']
|
||||
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: "\
|
||||
"#{amount} delay: #{delay}"
|
||||
|
||||
|
@ -73,16 +75,17 @@ class MessageHandler
|
|||
speed.to_s, amount.to_i)
|
||||
@command_queue.save_new_command
|
||||
|
||||
skynet.confirmed = false
|
||||
$skynet.confirmed = false
|
||||
|
||||
command =
|
||||
{
|
||||
:message_type => 'confirmation',
|
||||
:time_stamp => Time.now.to_f.to_s,
|
||||
:confirm_id => time_stamp
|
||||
}
|
||||
}
|
||||
|
||||
skynet.send_message("44128811-8c59-11e3-b99a-11476114e05f", command)
|
||||
$skynet.send_message(sender, command)
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,8 +21,12 @@ class Skynet
|
|||
@uuid = creds[:uuid]
|
||||
@token = creds[:token]
|
||||
@socket = SocketIO::Client::Simple.connect 'http://skynet.im:80'
|
||||
@confirmed = false
|
||||
|
||||
create_socket_events
|
||||
|
||||
puts "uuid: #{@uuid}"
|
||||
|
||||
@message_handler = MessageHandler.new
|
||||
end
|
||||
|
||||
|
@ -36,16 +40,16 @@ class Skynet
|
|||
def handle_message(channel, message)
|
||||
|
||||
if message.class.to_s == 'Hash'
|
||||
@message_handler.handle_message(self, channel, message)
|
||||
@message_handler.handle_message(channel, message)
|
||||
end
|
||||
|
||||
if message.class.to_s == 'String'
|
||||
message_hash = JSON.parse(message)
|
||||
@message_handler.handle_message(self, channel, message_hash)
|
||||
@message_handler.handle_message(channel, message_hash)
|
||||
end
|
||||
|
||||
rescue
|
||||
raise "Runtime error while attempting to parse message: #{message}."
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue