Пример #1
0
static int handle_tx_param(struct cli_state *s,
                                const char *param, const char *value)
{
    bool ok = false;
    unsigned int tmp_uint;

    if (!strcasecmp(RXTX_PARAM_REPEAT, param)) {
        tmp_uint = str2uint(value, 0, UINT_MAX, &ok);
        if (ok) {
            s->rxtx_data->tx.repeat = tmp_uint;
        }

    } else if (!strcasecmp(RXTX_PARAM_REPEATDLY, param)) {
        tmp_uint = str2uint(value, 0, UINT_MAX, &ok);
        if (ok) {
            s->rxtx_data->tx.repeat_delay = tmp_uint;
        }
    }

    if (!ok) {
        cli_err(s, "tx", RXTX_ERRMSG_VALUE(param, value));
        return CMD_RET_INVPARAM;
    } else {
        return 0;
    }
}
Пример #2
0
static int rx_cmd_config(struct cli_state *s, int argc, char **argv)
{
    int i;
    char *val;
    int status;
    struct rx_params *rx_params = s->rx->params;

    assert(argc >= 2);

    if (argc == 2) {
        rx_print_config(s->rx);
        return 0;
    }

    for (i = 2; i < argc; i++) {
        status = rxtx_handle_config_param(s, s->rx, argv[0], argv[i], &val);

        if (status < 0) {
            return status;
        } else if (status == 0) {
            if (!strcasecmp("n", argv[i])) {
                /* Configure number of samples to receive */
                unsigned int n;
                bool ok;

                n = str2uint_suffix(val, 0, UINT_MAX, rxtx_kmg_suffixes,
                                    (int)rxtx_kmg_suffixes_len, &ok);

                if (ok) {
                    pthread_mutex_lock(&s->rx->param_lock);
                    rx_params->n_samples = n;
                    pthread_mutex_unlock(&s->rx->param_lock);
                } else {
                    cli_err(s, argv[0], RXTX_ERRMSG_VALUE(argv[1], val));
                    return CMD_RET_INVPARAM;
                }

            } else {
                cli_err(s, argv[0], "Unrecognized command: %s", argv[1]);
                return CMD_RET_INVPARAM;
            }
        }
    }

    return 0;
}
Пример #3
0
static int handle_rx_param(struct cli_state *s,
                                const char *param, const char *value)
{
    unsigned int tmp_uint;
    bool ok = false;

    if (!strcasecmp(RXTX_PARAM_NUMSAMPLES, param)) {
        tmp_uint = str2uint(value, 0, INT_MAX, &ok);
        if (ok) {
            s->rxtx_data->rx.n_samples = tmp_uint;
        }
    }

    if (!ok) {
        cli_err(s, "rx", RXTX_ERRMSG_VALUE(param, value));
        return CMD_RET_INVPARAM;
    } else {
        return 0;
    }

}
Пример #4
0
int rxtx_handle_config_param(struct cli_state *s, struct rxtx_data *rxtx,
                             const char *argv0, char *param, char **val)
{
    int status = 0;
    unsigned int tmp;
    bool ok;

    if (!param) {
        return CMD_RET_MEM;
    }

    *val = strchr(param, '=');

    if (!*val || strlen(&(*val)[1]) < 1) {
        cli_err(s, argv0, "No value provided for parameter \"%s\"", param);
        status = CMD_RET_INVPARAM;
    }

    if (status == 0) {
        (*val)[0] = '\0';
        (*val) = (*val) + 1;

        if (!strcasecmp("file", param)) {
            status = rxtx_set_file_path(rxtx, *val);
            if (status == 0) {
                status = 1;
            }
        } else if (!strcasecmp("format", param)) {
            enum rxtx_fmt fmt;
            fmt = rxtx_str2fmt(*val);

            if (fmt == RXTX_FMT_INVALID) {
                cli_err(s, argv0, RXTX_ERRMSG_VALUE(param, *val));
                status = CMD_RET_INVPARAM;
            } else {
                rxtx_set_file_format(rxtx, fmt);
                status = 1;
            }
        } else if (!strcasecmp("buffers", param)) {
            tmp = str2uint_suffix(*val, RXTX_BUFFERS_MIN,
                                  UINT_MAX, rxtx_kmg_suffixes,
                                  (int)rxtx_kmg_suffixes_len, &ok);

            if (!ok) {
                cli_err(s, argv0, RXTX_ERRMSG_VALUE(param, *val));
                status = CMD_RET_INVPARAM;
            } else {
                pthread_mutex_lock(&rxtx->data_mgmt.lock);
                rxtx->data_mgmt.num_buffers = tmp;
                pthread_mutex_unlock(&rxtx->data_mgmt.lock);
                status = 1;
            }

        } else if (!strcasecmp("samples", param)) {
            tmp = str2uint_suffix(*val, RXTX_BUFFERS_MIN,
                                  UINT_MAX, rxtx_kmg_suffixes,
                                  (int)rxtx_kmg_suffixes_len, &ok);

            if (!ok) {
                cli_err(s, argv0, RXTX_ERRMSG_VALUE(param, *val));
                status = CMD_RET_INVPARAM;
            } else if (tmp % RXTX_SAMPLES_MIN != 0) {
                cli_err(s, argv0,
                        "The '%s' paramter must be a multiple of %u.",
                        param, RXTX_BUFFERS_MIN);
                status = CMD_RET_INVPARAM;
            } else {
                pthread_mutex_lock(&rxtx->data_mgmt.lock);
                rxtx->data_mgmt.samples_per_buffer= tmp;
                pthread_mutex_unlock(&rxtx->data_mgmt.lock);
                status = 1;
            }
        } else if (!strcasecmp("xfers", param)) {
            tmp = str2uint_suffix(*val, RXTX_BUFFERS_MIN - 1, UINT_MAX,
                                  rxtx_kmg_suffixes, (int)rxtx_kmg_suffixes_len,
                                  &ok);

            if (!ok) {
                cli_err(s, argv0, RXTX_ERRMSG_VALUE(param, *val));
                status = CMD_RET_INVPARAM;
            } else {
                pthread_mutex_lock(&rxtx->data_mgmt.lock);
                rxtx->data_mgmt.num_transfers= tmp;
                pthread_mutex_unlock(&rxtx->data_mgmt.lock);
                status = 1;
            }
        }

    }

    return status;
}
Пример #5
0
static int tx_config(struct cli_state *s, int argc, char **argv)
{
    int i;
    char *val;
    int status;
    struct tx_params *tx_params = s->tx->params;

    assert(argc >= 2);

    if (argc == 2) {
        tx_print_config(s->tx);
        return 0;
    }

    for (i = 2; i < argc; i++) {

        status = rxtx_handle_config_param(s, s->tx, argv[0], argv[i], &val);

        if (status < 0) {
            return status;
        } else if (status == 0) {
            if (!strcasecmp("repeat", argv[i])) {
                /* Configure the number of transmission repetitions to use */
                unsigned int tmp;
                bool ok;

                tmp = str2uint(val, 0, UINT_MAX, &ok);
                if (ok) {
                    MUTEX_LOCK(&s->tx->param_lock);
                    tx_params->repeat = tmp;
                    MUTEX_UNLOCK(&s->tx->param_lock);
                } else {
                    cli_err(s, argv[0], RXTX_ERRMSG_VALUE(argv[1], val));
                    return CLI_RET_INVPARAM;
                }

            } else if (!strcasecmp("delay", argv[i])) {
                /* Configure the number of useconds between each repetition  */

                unsigned int tmp;
                bool ok;

                tmp = str2uint(val, 0, UINT_MAX, &ok);

                if (ok) {
                    MUTEX_LOCK(&s->tx->param_lock);
                    tx_params->repeat_delay = tmp;
                    MUTEX_UNLOCK(&s->tx->param_lock);
                } else {
                    cli_err(s, argv[0], RXTX_ERRMSG_VALUE(argv[1], val));
                    return CLI_RET_INVPARAM;
                }

            } else {
                cli_err(s, argv[0],
                        "Unrecognized config parameter: %s\n", argv[i]);
                return CLI_RET_INVPARAM;
            }
        }
    }

    return 0;
}