コード例 #1
0
def find_sch_pid():  ### UNUSED ###

    # No longer needed
    # In case the game scheduler service is running but
    # there is no stored pid for the service. In this case
    # the flag_access option could be False but the service is still
    # accessable meaning stage 2 would be unsolvable
    # Extremely slow way to find the process but ensures it will be found. Should NEVER be used.
    # Only here to make sure nothing compromises challenge.

    logger = app_api.logging_setup("CTF-Challenge")

    request = '{ps{pid,cmd}}'

    try:
        response = SERVICES.query(service="monitor-service", query=request)
    except Exception as e:
        print(f"{logger} err: Something went seriously wrong with challenge.")
        print(f"{logger} warn: Fixing but you should open a new challenge.")
        print(f"{logger} info: Fixing challenge...")

    for ps in response['ps']:
        if ('sch-service' in ps['cmd']):
            print(f"{logger} info: Challenged fixed.")
            return ps['pid']

    print(f"{logger} err: Challenge not fixed.")

    sys.exit(-1)

    return
コード例 #2
0
def main():

    logger = app_api.logging_setup("payload-image-transfer")

    # parse arguments for config file and run type
    parser = argparse.ArgumentParser()
    parser.add_argument('--run', '-r', nargs=1)
    parser.add_argument('--config', '-c', nargs=1)
    args = parser.parse_args()

    if args.config is not None:
        # use user config file if specified in command line
        SERVICES = app_api.Services(args.config[0])
    else:
        # else use default global config file
        SERVICES = app_api.Services("/home/kubos/kubos/local_config.toml")

    # run app onboot or oncommand logic
    if args.run is not None:
        if args.run[0] == 'OnBoot':
            on_boot(logger, SERVICES)
        elif args.run[0] == 'OnCommand':
            on_command(logger, SERVICES)
    else:
        on_command(logger, SERVICES)
コード例 #3
0
def main():

    logger = app_api.logging_setup("keep_alive")
    
    parser = argparse.ArgumentParser()
    
    parser.add_argument('--config', '-c', nargs=1)
    parser.add_argument('--stop', '-s', action='store_true')
    
    args = parser.parse_args()
    
    if args.config is not None:
        global SERVICES
        SERVICES = app_api.Services(args.config[0])
    else:
        SERVICES = app_api.Services()
    
    if args.stop is not None:
        sys.exit(0)

    ######### START #########

    app_name = "leon3_i2c"

    if check_app_running(logger, app_name) == False:
        logger.warning("I2C application not running. Starting...")
        start_app(logger)
コード例 #4
0
ファイル: python-mission-app.py プロジェクト: rip1ey/kubos
def main():

    logger = app_api.logging_setup("mission-framework")

    parser = argparse.ArgumentParser()

    parser.add_argument('--run', '-r', nargs=1)
    parser.add_argument('--config', '-c', nargs=1)
    parser.add_argument('cmd_args', nargs='*')

    args = parser.parse_args()

    if args.config is not None:
        global SERVICES
        SERVICES = app_api.Services(args.config[0])
    else:
        SERVICES = app_api.Services()

    if args.run[0] == 'OnBoot':
        on_boot(logger)
    elif args.run[0] == 'OnCommand':
        on_command(logger)
    else:
        logger.error("Unknown run level specified")
        sys.exit(1)
コード例 #5
0
def main():

    logger = app_api.logging_setup("imu-read-qua")

    # parse arguments for config file and run type
    parser = argparse.ArgumentParser()
    parser.add_argument('--run', '-r', nargs=1)
    parser.add_argument('--config', '-c', nargs=1)
    parser.add_argument('cmd_args', nargs='*')
    args = parser.parse_args()

    if args.config is not None:
        # use user config file if specified in command line
        SERVICES = app_api.Services(args.config[0])
    else:
        # else use default global config file
        SERVICES = app_api.Services()

    # run app onboot or oncommand logic
    if args.run is not None:
        if args.run[0] == 'OnBoot':
            on_boot(logger, SERVICES)
        elif args.run[0] == 'OnCommand':
            on_command(logger, SERVICES)
    else:
        on_command(logger, SERVICES)
コード例 #6
0
def main():

    logger = app_api.logging_setup("mission-app")

    parser = argparse.ArgumentParser()

    # The -r argument is required to be present by the applications service
    parser.add_argument(
        '-r',
        '--run',
        nargs=1,
        help='Determines run behavior. Either "OnBoot" or "OnCommand"',
        required=True)
    # Other optional arguments which will be passed through to the underlying logic
    parser.add_argument('cmd_args', nargs='*')

    args = parser.parse_args()

    if args.run[0] == 'OnBoot':
        on_boot(logger)
    elif args.run[0] == 'OnCommand':
        on_command(logger, args.cmd_args)
    else:
        logger.error("Unknown run level specified")
        sys.exit(1)
コード例 #7
0
ファイル: kubos-makeLED.py プロジェクト: astrosec/kubos
def main():

    logger = app_api.logging_setup("kubos-linux-makeLED")

    logger.info("Entering main LED logic BLINKER!!! ")

    parser = argparse.ArgumentParser()

    parser.add_argument(
        '-c',
        '--config',
        nargs=1,
        help='Specifies the location of a non-default configuration file')

    parser.add_argument('-s', '--subcommand', help='on, off, flash')

    args = parser.parse_args()

    if args.config is not None:
        global SERVICES
        SERVICES = app_api.Services(args.config[0])
    else:
        SERVICES = app_api.Services()

    logger.info("Command to LED Blinker is " + str(args.subcommand))

    if args.subcommand == 'flash':
        on_command(logger, 'flash')
    elif args.subcommand == 'off':
        on_command(logger, 'off')
    elif args.subcommand == 'on':
        on_command(logger, 'on')
    else:
        logger.error("Bad command to led blinker " + args.subcommand)
コード例 #8
0
def main():

    logger = app_api.logging_setup("change-app-version")

    # parse arguments for config file and run type
    parser = argparse.ArgumentParser()
    parser.add_argument('--run', '-r', nargs=1)
    parser.add_argument('--config', '-c', nargs=1)
    parser.add_argument('name')
    parser.add_argument('version')
    args = parser.parse_args()

    if args.config is not None:
        # use user config file if specified in command line
        SERVICES = app_api.Services(args.config[0])
    else:
        # else use default global config file
        SERVICES = app_api.Services("/etc/kubos-config.toml")

    # run app onboot or oncommand logic
    if args.run is not None:
        if args.run[0] == 'OnBoot':
            on_boot(logger, SERVICES)
        elif args.run[0] == 'OnCommand':
            on_command(logger, SERVICES, args.name, args.version)
    else:
        on_command(logger, SERVICES, args.name, args.version)
コード例 #9
0
    def __init__(self):

        self.logger = app_api.logging_setup("payload-api")
        self.use_uart = False
        try:
            self.UART = uart.UART(1)
            self.use_uart = True
        except Exception as e:
            self.logger.error(
                "FATAL ERROR: Unable to open UART port {}:{}. No communication with payload. Using fake connection..."
                .format(type(e).__name__, str(e)))
コード例 #10
0
    def __init__(self, port_number):
        self.port = config.PORT_NAME[port_number]
        self.serial = serial.Serial(
            port=self.port,
            baudrate=115200,
            parity=serial.PARITY_NONE,
            stopbits=serial.STOPBITS_ONE,
            bytesize=serial.EIGHTBITS,
            timeout=1)

        # setup xmodem for image transfers
        self.modem = XMODEM(self.getc, self.putc)
    
        self.logger = app_api.logging_setup("UART")
コード例 #11
0
def main():

    logger = app_api.logging_setup("initchallenge")

    parser = argparse.ArgumentParser()

    parser.add_argument('--config', '-c', nargs=1)
    parser.add_argument('--mode', '-m', nargs=1)
    parser.add_argument('--schedule', '-s', nargs=1)

    args = parser.parse_args()

    if args.config is not None:
        global SERVICES
        SERVICES = app_api.Services(args.config[0])
    else:
        SERVICES = app_api.Services()

    ######### START #########

    logger.info("Initializing system. This will only run once.")

    if args.mode is None:
        mode_name = "nominal"  # Name of mode to create
    else:
        mode_name = args.mode

    if args.schedule is None:
        schedule_name = "imager"  # Name of schedule to insert into mode
    else:
        schedule_name = args.schedule

    # Apps to register
    i2c_app = "/home/microsd/mission-apps/leon3_i2c"
    # alive_app = "/home/microsd/mission-apps/keep_alive"

    ### Alive app was removed in order to speed up i2c. ###
    # apps_registrar = [i2c_app, alive_app]
    apps_registrar = [i2c_app]

    register_all_apps(logger, apps_registrar)

    create_mode(logger, mode_name)
    create_mode_schedule(logger, mode_name, schedule_name)

    activate_mode(logger, mode_name)

    logger.info("Initialized successfully.")
コード例 #12
0
def main():

    logger = app_api.logging_setup("mission-framework")

    parser = argparse.ArgumentParser()

    parser.add_argument('--config', '-c', nargs=1)

    args = parser.parse_args()

    if args.config is not None:
        global SERVICES
        SERVICES = app_api.Services(args.config[0])
    else:
        SERVICES = app_api.Services()

    logger.info("Starting mission logic")
コード例 #13
0
ファイル: i2c-app.py プロジェクト: Tetra7ton/kubos
def main():

    logger = app_api.logging_setup("i2c-app")

    parser = argparse.ArgumentParser()

    parser.add_argument('--run', '-r')

    args = parser.parse_args()

    if args.run == 'OnBoot':
        on_boot(logger)
    elif args.run == 'OnCommand':
        on_command(logger)
    else:
        logger.error("Unknown run level specified")
        sys.exit(1)
コード例 #14
0
def main():

    logger = app_api.logging_setup("python-proj")

    parser = argparse.ArgumentParser()

    parser.add_argument(
        '-c',
        '--config',
        nargs=1,
        help='Specifies the location of a non-default configuration file')
    parser.add_argument('-t', '--test', nargs=1)
    parser.add_argument('-e', '--error', action='store_true')
    parser.add_argument('-f', '--flag', action='store_true')
    parser.add_argument('positional', nargs='?')

    matches = parser.parse_args()

    if matches.config is not None:
        global SERVICES
        SERVICES = app_api.Services(matches.config[0])
    else:
        SERVICES = app_api.Services()

    success = False

    sub.test_func()

    if matches.error:
        sys.exit(123)

    if matches.flag:
        success = True

    if matches.test is not None and matches.test[0] == "test":
        success = True

    if matches.positional is not None and matches.positional == "pos":
        success = True

    if success:
        sys.exit(0)
    else:
        logging.error("No valid arguments were found")
        sys.exit(1)
コード例 #15
0
ファイル: set-adcs-idle.py プロジェクト: Tetra7ton/kubos
def main():

    logger = app_api.logging_setup("set-adcs-idle")

    # parse arguments for config file and run type
    parser = argparse.ArgumentParser()
    parser.add_argument('--run', '-r', nargs=1)
    args = parser.parse_args()

    SERVICES = app_api.Services("/etc/kubos-config.toml")

    # run app onboot or oncommand logic
    if args.run is not None:
        if args.run[0] == 'OnBoot':
            on_boot(logger, SERVICES)
        elif args.run[0] == 'OnCommand':
            on_command(logger, SERVICES)
    else:
        on_command(logger, SERVICES)
コード例 #16
0
def main():

    logger = app_api.logging_setup("mission-app")

    parser = argparse.ArgumentParser()

    # The -c argument should be present if you would like to be able to specify a non-default
    # configuration file
    parser.add_argument(
        '-c',
        '--config',
        nargs=1,
        help='Specifies the location of a non-default configuration file')
    # Arguments specific to this application
    parser.add_argument('-a',
                        '--apps',
                        action='store_true',
                        help='Get list of installed apps')
    parser.add_argument('-m', '--mode', nargs=1, help='System mode')
    parser.add_argument('-t',
                        '--time',
                        type=int,
                        help='Safemode time (in seconds)')

    args = parser.parse_args()

    if args.config is not None:
        global SERVICES
        SERVICES = app_api.Services(args.config[0])
    else:
        SERVICES = app_api.Services()

    if args.mode == 'safemode':
        safe_mode(logger, args.time)
    elif args.apps is not None:
        get_apps(logger)
    else:
        get_telemetry(logger)
コード例 #17
0
ファイル: mission-app.py プロジェクト: rip1ey/kubos
def main():

    logger = app_api.logging_setup("mission-app")

    parser = argparse.ArgumentParser()

    # The -r argument is required to be present by the applications service
    parser.add_argument(
        '-r',
        '--run',
        nargs=1,
        help='Determines run behavior. Either "OnBoot" or "OnCommand"',
        required=True)
    # The -c argument should be present if you would like to be able to specify a non-default
    # configuration file
    parser.add_argument(
        '-c',
        '--config',
        nargs=1,
        help='Specifies the location of a non-default configuration file')
    # Other optional arguments which will be passed through to the underlying logic
    parser.add_argument('cmd_args', nargs='*')

    args = parser.parse_args()

    if args.config is not None:
        global SERVICES
        SERVICES = app_api.Services(args.config[0])
    else:
        SERVICES = app_api.Services()

    if args.run[0] == 'OnBoot':
        on_boot(logger)
    elif args.run[0] == 'OnCommand':
        on_command(logger, args.cmd_args)
    else:
        logger.error("Unknown run level specified")
        sys.exit(1)
コード例 #18
0
    def __init__(self):
        '''
        Initialize the hardware and logging
        '''

        # Get the configuration
        parser = argparse.ArgumentParser()
        parser.add_argument('--config', '-c')
        args = parser.parse_args()

        if args.config is not None:
            global SERVICES
            SERVICES = app_api.Services(args.config)
        else:
            SERVICES = app_api.Services()

        # Setup logging
        self.logger = app_api.logging_setup(self.app_name)

        # Connect to tracking motor
        self.motor = scmd(1)

        print('I2C bus: ', self.motor.bus)
        print('I2C slave address: ', self.motor.addr)
        print('SCMD ID: ', self.motor.begin())

        self.motor.ready()
        self.motor.disable()
        time.sleep(0.25)

        self.motor.set_drive(0, 0, 0)
        self.motor.set_drive(1, 0, 0)
        self.motor.enable()
        time.sleep(0.25)

        # Make sure DORA is ready to go
        self.powerOnSensors()
コード例 #19
0
ファイル: mission-app.py プロジェクト: damons/kubos-1
def main():
   
    logger = app_api.logging_setup("mission-app")
    
    parser = argparse.ArgumentParser()

    # The -r argument is required to be present by the applications service
    parser.add_argument(
        '-r',
        '--run',
        nargs=1,
        help='Determines run behavior. Either "OnBoot" or "OnCommand"',
        required=True)
    
    # Other optional arguments
    parser.add_argument(
        '-s',
        '--cmd_string',
        help='Command Argument String passed into OnCommand behavior',
        required=False)
    parser.add_argument(
        '-i',
        '--cmd_int',
        type=int,
        help='Command Argument Integer passed into OnCommand behavior',
        required=False)

    args = parser.parse_args()

    if args.run[0] == 'OnBoot':
        on_boot(logger)
    elif args.run[0] == 'OnCommand':
        on_command(logger, args)
    else:
        logger.error("Unknown run level specified")
        sys.exit(1)
コード例 #20
0
def main():

    logger = app_api.logging_setup("install-kubos")

    # else use default global config file
    SERVICES = app_api.Services("/etc/kubos-config.toml")

    print("\n")
    ############################ REMOVE MISSION MODES ######################################
    for mode, settings in modes.items():
        
        name = mode
        # send mutation to remove mode from scheduler
        request = '''
        mutation {
            removeMode(name: "%s") {
                success
                errors
            }
        }''' % (name)
        response = SERVICES.query(service="scheduler-service", query=request)

        # get results
        response = response["removeMode"]
        success = response["success"]
        errors = response["errors"]

        if success:
            logger.info("Removed mode named: {}.".format(name))
        else:
            logger.warning("Could not remove {} mode: {}.".format(name, errors))

    print("\n")
    ############################ CREATE 3 MISSION MODES ######################################
    for mode, settings in modes.items():
        
        #try:
        name = mode
        # send mutation to create mode in scheduler
        request = '''
        mutation {
            createMode(name: "%s") {
                success
                errors
            }
        }''' % (name)
        response = SERVICES.query(service="scheduler-service", query=request)

        # get results
        response = response["createMode"]
        success = response["success"]
        errors = response["errors"]

        if success:
            logger.info("Created empty mode named: {}.".format(name))
        else:
            # check if error is due to mode already existing
            if ("exists" in errors):
                logger.info("Already a mode named: {}.".format(name))
            else:
                logger.warning("Could not create {} mode: {}.".format(name, errors))

    print("\n")
    ################## DEREGISTER ALL APPLICATIONS WITH APPLICATIONS SERVICE #######################
    for app in apps.keys():
        # send mutation to deregister app (name is required, version is optional)
        request = '''
        mutation {
            uninstall(name: "%s", version: "1.0") {
                success,
                errors
            }
        }
        ''' % (app)
        response = SERVICES.query(service="app-service", query=request)

        # get results
        response = response["uninstall"]
        success = response["success"]
        errors = response["errors"]

        if success:
            logger.info("Deregistered app: {}".format(app))
        else:
            # check if error is due to no app existing in registry
            if ("not found" in errors):
                logger.info("No app named: {} found in registry.".format(app))
            else:
                logger.warning("Unable to deregister app {}: {}".format(app, errors))

    print("\n")
    ################## REGISTER APPLICATIONS WITH APPLICATIONS SERVICE #######################
    for app, path in apps.items():

        request = ''' mutation { register(path: "%s") { success, errors, entry { active, app { name, version } } } } ''' % (path)
        response = SERVICES.query(service="app-service", query=request)

        # get results
        response = response["register"]
        success = response["success"]
        errors = response["errors"]

        if success:
            entry = response["entry"]
            active = entry["active"]
            app = entry["app"]
            name = app["name"]
            version = app["version"]

            logger.info("Registered app name: {} path: {} version: {} active: {}.".format(name, path, version, active))
        else:
            # check if error is due to app already existing in registry
            if ("exists" in errors):
                logger.info("Already a registered app named: {}.".format(app))
            else:
                logger.warning("Could not register app {} at path {}: {}".format(app, path, errors))

    print("\n")
    ################# INSTALL REGISTERED APPS INTO SPECIFIC MISSION MODES #####################
    for mode, settings in modes.items():
        
        # add safe mode tasks/mission apps to safe mode
        path = settings['path']
        name = settings['name']
        mode = settings['mode']

        request = ''' mutation { importTaskList(path: "%s", name: "%s", mode: "%s") { success errors } } ''' % (path, name, mode)
        response = SERVICES.query(service="scheduler-service", query=request)

        # get results
        response = response["importTaskList"]
        success = response["success"]
        errors = response["errors"]

        if success:
            logger.info("Added task list {} at {} to mode {}.".format(name, path, mode))
        else:
            logger.warning("Could not add task list {} at {} to mode {}: {}.".format(name, path, mode, errors))
コード例 #21
0
ファイル: gpio.py プロジェクト: Tetra7ton/kubos
 def __init__(self, pin):
     self.pin = pin
     self.logger = app_api.logging_setup("gpio-service-pin{}".format(self.pin))