def robot_update_pos(conn, addr): robot_ip = addr[0] # read new position (row, col) data = receive_message(conn, 4) (from_x, from_y, to_x, to_y) = unpack("B" * 4, data) print("Robot", robot_ip, "now arrives", (from_x, from_y, to_x, to_y)) planning.update_robot_pos(robot_ip, from_x, from_y, to_x, to_y)
def robot_join(conn, addr): print("Robot " + addr[0] + " request to join the network") robot_ip = addr[0] # log the socket robot_sockets[robot_ip] = conn # WARNING: magic number # TODO: more plan on what to do planning.update_robot_pos(robot_ip, 0, 0, 1, 0) planning.robot_enter_rest(robot_ip) db_manager.robot_join(addr[0]) conn.sendall(pack("B", 3)) # tell it where to go # if there's no task, just do nothing assigned_task = planning.add_free_robot(robot_ip) if assigned_task is not None: planning.robot_perform_task(robot_ip, assigned_task)