def main(): log.begin() parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) # Add required command line argument parser.add_argument('filename', default=None) # Add optional command line arguments parser.add_argument('--port', default=ait.config.get('command.port', ait.DEFAULT_CMD_PORT), type=int) parser.add_argument('--verbose', default=0, type=int) # Get command line arguments args = vars(parser.parse_args()) host = '127.0.0.1' port = args['port'] data = ' '.join(args) verbose = args['verbose'] cmd = api.CmdAPI(port, verbose=verbose) filename = args['filename'] try: with open(filename, 'r') as stream: for line in stream.readlines(): line = line.strip() # Skip blank lines and comments if len(line) == 0 or line.startswith('#'): continue # Meta-command elif line.startswith('%'): command = line[1:].strip() system(command) # Sequence command else: tokens = line.split() delay = float(tokens[0]) name = tokens[1] args = [util.toNumber(t, t) for t in tokens[2:]] args = cmd.parseArgs(name, *args) time.sleep(delay) log.info(line) cmd.send(name, *args) except IOError: log.error("Could not open '%s' for reading." % filename) log.end()
def main(): log.begin() description = """ Sends the given command and its arguments to the ISS simulator via UDP. Examples: $ ait-cmd-send OCO3_CMD_START_SEQUENCE_NOW 1 """ arguments = OrderedDict({ '--port': { 'type': int, 'default': ait.config.get('command.port', ait.DEFAULT_CMD_PORT), 'help': 'Port on which to send data' }, '--host': { 'type': str, 'default': "127.0.0.1", 'help': 'Host to which to send data' }, '--verbose': { 'action': 'store_true', 'default': False, 'help': 'Hexdump of the raw command being sent.' } }) arguments['command'] = { 'type': str, 'help': 'Name of the command to send.' } arguments['arguments'] = { 'type': util.toNumberOrStr, 'metavar': 'argument', 'nargs': '*', 'help': 'Command arguments.' } args = gds.arg_parse(arguments, description) host = args.host port = args.port verbose = args.verbose cmdApi = api.CmdAPI(port, verbose=verbose) cmdArgs = cmdApi.parseArgs(args.command, *args.arguments) cmdApi.send(args.command, *cmdArgs) log.end()
def main(): log.begin() descr = ( "Sends the given command and its arguments to the ISS simulator via " "the AIT server, or if the 'udp' flag is set then directly via UDP.") parser = argparse.ArgumentParser( description=descr, formatter_class=argparse.ArgumentDefaultsHelpFormatter) arg_defns = OrderedDict({ "--topic": { "type": str, "default": ait.config.get("command.topic", ait.DEFAULT_CMD_TOPIC), "help": "Name of topic from which to publish data", }, "--verbose": { "action": "store_true", "default": False, "help": "Hexdump of the raw command being sent.", }, "--udp": { "action": "store_true", "default": False, "help": "Send data to UDP socket.", }, "--host": { "type": str, "default": ait.DEFAULT_CMD_HOST, "help": "Host to which to send data", }, "--port": { "type": int, "default": ait.config.get("command.port", ait.DEFAULT_CMD_PORT), "help": "Port on which to send data", }, }) arg_defns["command"] = { "type": str, "help": "Name of the command to send." } arg_defns["arguments"] = { "type": util.toNumberOrStr, "metavar": "arguments", "nargs": "*", "help": "Command arguments.", } # Push argument defs to the parser for name, params in arg_defns.items(): parser.add_argument(name, **params) # Get arg results of the parser args = parser.parse_args() # Extract args to local fields host = args.host port = args.port verbose = args.verbose udp = args.udp topic = args.topic # If UDP enabled, collect host/port info if udp: if host is not None: dest = (host, port) else: dest = port cmd_api = api.CmdAPI(udp_dest=dest, verbose=verbose) # Default CmdAPI connect hooks up to C&DH server 0MQ port else: cmd_api = api.CmdAPI(verbose=verbose, cmdtopic=topic) cmd_args = cmd_api.parse_args(args.command, *args.arguments) cmd_api.send(args.command, *cmd_args) log.end()
def main(): log.begin() descr = ( "Sends the given relative timed sequence via the AIT server, or if the 'udp' " "flag is set then directly via UDP.") parser = argparse.ArgumentParser( description=descr, formatter_class=argparse.RawDescriptionHelpFormatter) # The optional argument(s) arg_defns = OrderedDict({ "--topic": { "type": str, "default": ait.config.get("command.topic", ait.DEFAULT_CMD_TOPIC), "help": "Name of topic from which to publish data", }, "--verbose": { "action": "store_true", "default": False, "help": "Hexdump of the raw command being sent.", }, "--udp": { "action": "store_true", "default": False, "help": "Send data to UDP socket.", }, "--host": { "type": str, "default": ait.DEFAULT_CMD_HOST, "help": "Host to which to send data", }, "--port": { "type": int, "default": ait.config.get("command.port", ait.DEFAULT_CMD_PORT), "help": "Port on which to send data", }, }) # Required argument(s) arg_defns["filename"] = { "type": str, "help": "Name of the sequence file.", "default": None, } # Push argument defs to the parser for name, params in arg_defns.items(): parser.add_argument(name, **params) # Get arg results of the parser args = parser.parse_args() # Extract args to local fields host = args.host port = args.port verbose = args.verbose udp = args.udp topic = args.topic filename = args.filename # If UDP enabled, collect host/port info if udp: if host is not None: dest = (host, port) else: dest = port cmd_api = api.CmdAPI(udp_dest=dest, verbose=verbose) # Default CmdAPI connect hooks up to C&DH server 0MQ port else: cmd_api = api.CmdAPI(verbose=verbose, cmdtopic=topic) try: with open(filename, "r") as stream: for line in stream.readlines(): line = line.strip() # Skip blank lines and comments if len(line) == 0 or line.startswith("#"): continue # Meta-command elif line.startswith("%"): command = line[1:].strip() system(command) # Sequence command else: tokens = line.split() delay = float(tokens[0]) cmd_name = tokens[1] cmd_args = [util.toNumber(t, t) for t in tokens[2:]] cmd_args = cmd_api.parse_args(cmd_name, *cmd_args) time.sleep(delay) log.info(line) cmd_api.send(cmd_name, *cmd_args) except IOError: log.error("Could not open '%s' for reading." % filename) log.end()