def main(args: argparse.Namespace): orbitx_connection = network.StateClient(network.Request.MIST, args.physics_server) log.info(f'Connecting to OrbitX Physics Server: {args.physics_server}') random.seed() try: while True: print( random.choice( ['ASTRONAUT STATUS: DYING', 'astronaut status: okay'])) print( orbitx_connection.get_state([ network.Request(ident=network.Request.NOOP) ])['Earth'].pos) time.sleep(1) except grpc.RpcError as err: log.error(f'Got response code {err.code()} from orbitx, shutting down') raise err
def main(args: argparse.Namespace): orbitx_connection = network.StateClient( network.Request.COMPAT, args.physics_server) log.info(f'Connecting to OrbitX Physics Server: {args.physics_server}') intermediary = orbitv_file_interface.OrbitVIntermediary( Path(args.piloting)) try: # Make sure we have a connection before continuing. orbitx_connection.get_state( [network.Request(ident=network.Request.NOOP)]) except grpc.RpcError as err: log.error(f'Could not connect to Physics Server: {err.code()}') StartupFailedGui(args.physics_server, err) return gui = CompatGui(args.physics_server, intermediary) last_orbitsse_modified_time = 0.0 last_orbitsse_read_datetime = datetime.fromtimestamp(0) try: while True: orbitsse_modified_time = intermediary.orbitsse.stat().st_mtime if orbitsse_modified_time == last_orbitsse_modified_time: # We've already seen this version of ORBITSSE.RND. update = network.Request(ident=network.Request.NOOP) else: last_orbitsse_modified_time = orbitsse_modified_time last_orbitsse_read_datetime = datetime.now() update = intermediary.read_engineering_update() state = orbitx_connection.get_state([update]) intermediary.write_state(state) gui.update( update, state._entity_names, last_orbitsse_read_datetime) except grpc.RpcError as err: log.error( f'Got response code {err.code()} from orbitx, shutting down') gui.notify_shutdown(err)
def mirroring_loop(args): """Main, 'while True'-style loop for a mirroring client. Blocking. See help text for CLI arguments for the difference between mirroring and serving.""" currently_mirroring = True log.info('Connecting to CnC server...') with network.StateClient(args.data_location.hostname, args.data_location.port) as mirror_state: log.info(f'Querying lead server {args.data_location.geturl()}') state = mirror_state() physics_engine = physics.PEngine(state) if not args.no_gui: log.info('Initializing graphics (thanks sean)...') gui = flight_gui.FlightGui(state) global cleanup_function cleanup_function = gui.shutdown while True: try: if currently_mirroring: state = mirror_state() physics_engine.set_state(state) else: state = physics_engine.get_state() if not args.no_gui: gui.draw(state) gui.rate(common.FRAMERATE) if gui.closed: break else: time.sleep(1 / common.FRAMERATE) except KeyboardInterrupt: # TODO: hacky solution to turn off mirroring right now is a ^C if currently_mirroring: currently_mirroring = False else: raise
def main(args: argparse.Namespace): log.info(f'Connecting to physics server {args.physics_server}.') time_of_next_network_update = 0.0 lead_server_connection = network.StateClient(Request.HAB_FLIGHT, args.physics_server) state = lead_server_connection.get_state() physics_engine = physics.PhysicsEngine(state) gui = flight_gui.FlightGui(state, title=name, running_as_mirror=False) atexit.register(gui.shutdown) while True: gui.draw(state) user_commands = gui.pop_commands() current_time = time.monotonic() # If there are user commands or we've gone a while since our last # contact with the physics server, request an update. if user_commands or current_time > time_of_next_network_update: # Our state is stale, get the latest update # TODO: what if this fails? Do anything smarter than an exception? state = lead_server_connection.get_state(user_commands) physics_engine.set_state(state) if len(user_commands) == 0: time_of_next_network_update = ( current_time + common.TIME_BETWEEN_NETWORK_UPDATES) else: # If we sent a user command, still ask for an update soon so # the user input can be reflected in hab flight's GUI as soon # as possible. # Magic number alert! The constant we add should be enough that # the physics server has had enough time to simulate the effect # of our input, but we should minimize the constant to minimize # input lag. time_of_next_network_update = current_time + 0.15 else: state = physics_engine.get_state() gui.rate(common.FRAMERATE)
def main(args: argparse.Namespace): time_of_last_network_update = 0.0 networking = True # Whether data is requested over the network log.info(f'Connecting to physics server {args.physics_server}.') lead_server_connection = network.StateClient(Request.MC_FLIGHT, args.physics_server) state = lead_server_connection.get_state() physics_engine = physics.PhysicsEngine(state) gui = flight_gui.FlightGui(state, title=name, running_as_mirror=True) atexit.register(gui.shutdown) while True: old_networking = networking networking = gui.requesting_read_from_physics_server() if old_networking != networking: log.info(('STARTED' if networking else 'STOPPED') + ' networking with the physics server at ' + args.physics_server) if (networking and time.monotonic() - time_of_last_network_update > common.TIME_BETWEEN_NETWORK_UPDATES): # Our state is stale, get the latest update # TODO: what if this fails? Set networking to False? state = lead_server_connection.get_state() physics_engine.set_state(state) time_of_last_network_update = time.monotonic() else: state = physics_engine.get_state() gui.draw(state) if not networking: # When we're not networking, allow user input. physics_engine.handle_requests(gui.pop_commands()) gui.rate(common.FRAMERATE)
from orbitx.compat import orbit_file_interface parser = argparse.ArgumentParser() parser.add_argument("--engineering", default="orbit-files/", help=("Path to engineering, " "containing OSbackup.RND and ORBITSSE.RND")) parser.add_argument( "--piloting", default=( f"{common.DEFAULT_LEAD_SERVER_HOST}:{common.DEFAULT_LEAD_SERVER_PORT}" ), help="address:port of piloting client") args = parser.parse_args() with network.StateClient(*args.piloting.split(':')) as orbitx_connection: assert Path(args.engineering).exists osbackup = Path(args.engineering) / 'OSbackup.RND' assert osbackup.exists print(f'Writing to legacy flight database: {osbackup}') orbitsse = Path(args.engineering) / 'ORBITSSE.RND' assert orbitsse.exists print(f'Reading from legacy engineering database: {orbitsse}') try: while True: update = orbit_file_interface.read_update_from_orbitsse(orbitsse) state = orbitx_connection(update) orbit_file_interface.write_state_to_osbackup(state, osbackup)