Ejemplo n.º 1
0
int cmd_load(struct cli_state *state, int argc, char **argv)
{
    /* Valid commands:
        load fpga <filename>
        load fx3 <filename>
    */
    int rv = CMD_RET_OK ;

    if (!cli_device_is_opened(state)) {
        return CMD_RET_NODEV;
    } else if (cli_device_is_streaming(state)) {
        return CMD_RET_BUSY;
    }

    if ( argc == 3 ) {
        if( strcasecmp( argv[1], "fpga" ) == 0 ) {
            rv = load_fpga(state, argv[2]);
        } else if( strcasecmp( argv[1], "fx3" ) == 0 ) {
            rv = load_fx3(state, argv[2]);
        } else {
            cli_err(state, argv[0],
                    "\"%s\" is not a valid programming target\n", argv[1]) ;
            rv = CMD_RET_INVPARAM;
        }
    } else {
        rv = CMD_RET_NARGS;
    }

    return rv;
}
Ejemplo n.º 2
0
/* Usage:
 *  open [device identifier items]
 *
 * It's a bit silly, but we just merge all the argv items into the
 * device identifier string here.
 */
int cmd_open(struct cli_state *state, int argc, char **argv)
{
    char *dev_ident = NULL;
    size_t dev_ident_len;
    int i;
    int status;
	int ret;

    /* Disallow opening of a diffrent device if the current one is doing work */
    if (cli_device_is_streaming(state)) {
        return CMD_RET_BUSY;
    }

    if (state->dev) {
        bladerf_close(state->dev);
    }

    /* We have some device indentifer items */
    if (argc > 1) {
        dev_ident_len = argc - 2; /* # spaces to place between args */

        for (i = 1; i < argc; i++) {
            dev_ident_len += strlen(argv[i]);
        }

        /* Room for '\0' terminator */
        dev_ident_len++;

        dev_ident = calloc(dev_ident_len, 1);
        if (!dev_ident) {
            return CMD_RET_MEM;
        }

        for (i = 1; i < argc; i++) {
            strncat(dev_ident, argv[i], (dev_ident_len - 1 - strlen(dev_ident)));

            if (i != (argc - 1)) {
                dev_ident[strlen(dev_ident)] = ' ';
            }
        }

        printf("Using device string: %s\n", dev_ident);
    }

    status = bladerf_open(&state->dev, dev_ident);
    if (status) {
        state->last_lib_error = status;
        ret = CMD_RET_LIBBLADERF;
    } else {
        ret = 0;
    }

    free(dev_ident);
    return ret;
}
Ejemplo n.º 3
0
int flash_check_state(struct cli_state *s, const char *cmd_name)
{
    if (!cli_device_is_opened(s)) {
        return CLI_RET_NODEV;
    }

    if (cli_device_is_streaming(s)) {
        cli_err(s, cmd_name, "Flash operations require that the device is not "
                             "actively streaming.");

        /* Technically not the error, but we want to suppress the more generic
         * error message... */
        return CLI_RET_INVPARAM;
    }

    return 0;
}