def run_async(args): logger.info("Starting up!") loop = asyncio.get_event_loop() logger.debug("Setting up Demo Satellite") demo_sat = DemoSat(name="Space Oddity") logger.debug("Setting up MajorTom") gateway = GatewayAPI(host=args.majortomhost, gateway_token=args.gatewaytoken, basic_auth=args.basicauth, command_callback=demo_sat.command_callback, cancel_callback=demo_sat.cancel_callback, http=args.http) logger.debug("Connecting to MajorTom") asyncio.ensure_future(gateway.connect_with_retries()) logger.debug("Sending Command Definitions") asyncio.ensure_future( gateway.update_command_definitions(system=demo_sat.name, definitions=demo_sat.definitions)) logger.debug("Starting Event Loop") loop.run_forever()
def run_sync(args): logger.debug("Starting Event Loop") loop = asyncio.get_event_loop() # Gateways are the link between the generic interfaces of Major Tom and the specifics of your # satellite(s) and groundstation(s). They can be designed to handle one or more satellites and # one or more groundstations. logger.debug("Setting up Gateway") gateway = Gateway() # Gateways use a websocket API, and we have a library to make the interface easier. # We instantiate the API, making sure to specify both sides of the connection: # - The Major Tom side, which requires a host and authentication # - The Gateway side, which specifies all the callbacks to be used when Major Tom communicates with this Gateway logger.debug("Setting up websocket connection") websocket_connection = GatewayAPI( host=args.majortomhost, gateway_token=args.gatewaytoken, basic_auth=args.basicauth, http=args.http, command_callback=gateway.command_callback, error_callback=gateway.error_callback, rate_limit_callback=gateway.rate_limit_callback, cancel_callback=gateway.cancel_callback, transit_callback=gateway.transit_callback, received_blob_callback=gateway.received_blob_callback, ) # It is useful to have a reference to the websocket api within your Gateway gateway.api = websocket_connection # Connect to MT asyncio.ensure_future(websocket_connection.connect_with_retries()) # To make it easier to interact with this Gateway, we are going to configure a bunch of commands for a satellite # called "Example FlatSat". Please see the associated json file to see the list of commands. logger.debug( "Setting up Example Flatsat satellite and associated commands") with open('satellite/example_commands.json', 'r') as f: command_defs = json.loads(f.read()) asyncio.ensure_future( websocket_connection.update_command_definitions( system="Example FlatSat", definitions=command_defs["definitions"])) try: loop.run_forever() except KeyboardInterrupt: loop.run_until_complete(loop.shutdown_asyncgens()) loop.close()
level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') else: logging.basicConfig( level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') logger.info("Starting up!") loop = asyncio.get_event_loop() logger.debug("Setting up WinSAT-1 Satellite") winsat = WinSat(name="WinSAT-1") logger.debug("Setting up MajorTom") gateway = GatewayAPI(host=args.majortomhost, gateway_token=args.gatewaytoken, basic_auth=args.basicauth, command_callback=winsat.command_callback, cancel_callback=winsat.cancel_callback, http=args.http) logger.debug("Connecting to MajorTom") asyncio.ensure_future(gateway.connect_with_retries()) logger.debug("Sending Command Definitions") asyncio.ensure_future( gateway.update_command_definitions(system=winsat.name, definitions=winsat.definitions)) logger.debug("Starting Event Loop") loop.run_forever()