void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    struct bladerf *dev;
	bladerf_module mod;
	int ret, bw;
	long long *ip;
	int *m_ptr;

	if (nrhs < 2)
		return;

	ip = (long long *)mxGetPr(prhs[0]);
	m_ptr = (int *)mxGetPr(prhs[1]);

	dev = (struct bladerf *)*ip;
	mod = (bladerf_module)(*m_ptr);

	
	ret = bladerf_get_bandwidth(dev, mod, &bw);

	if (nlhs >= 2) {
		plhs[1] = mxCreateNumericMatrix(1,1,mxINT64_CLASS,mxREAL);
		ip = (long long *)mxGetData(plhs[1]);
		*ip = bw;
	}

	if (nlhs >= 1) {
		plhs[0] = mxCreateNumericMatrix(1,1,mxINT64_CLASS,mxREAL);
		ip = (long long *)mxGetData(plhs[0]);
		*ip = ret;
	}
}
Exemple #2
0
static inline int backup_and_update_settings(struct bladerf *dev,
                                            bladerf_module module,
                                            struct settings *settings)
{
    int status;

    status = bladerf_get_bandwidth(dev, module, &settings->bandwidth);
    if (status != 0) {
        return status;
    }

    status = bladerf_get_frequency(dev, module, &settings->frequency);
    if (status != 0) {
        return status;
    }

    status = bladerf_get_rational_sample_rate(dev, module,
                                              &settings->samplerate);
    if (status != 0) {
        return status;
    }

    status = bladerf_set_bandwidth(dev, module, CAL_BANDWIDTH, NULL);
    if (status != 0) {
        return status;
    }

    status = bladerf_set_sample_rate(dev, module, CAL_SAMPLERATE, NULL);

    return status;
}
Exemple #3
0
static int set_and_check(struct bladerf *dev, bladerf_module m,
                         unsigned int bandwidth)
{
    int status;
    unsigned int actual, readback;

    status = bladerf_set_bandwidth(dev, m, bandwidth, &actual);
    if (status != 0) {
        PR_ERROR("Failed to set bandwidth: %s\n",
                 bladerf_strerror(status));
        return status;
    }

    status = bladerf_get_bandwidth(dev, m, &readback);
    if (status != 0) {
        PR_ERROR("Failed to read back bandwidth: %s\n",
                 bladerf_strerror(status));
        return status;
    }

    if (readback != actual) {
        PR_ERROR("Unexpected bandwidth. requested=%u, actual=%u, readback=%u\n",
                 bandwidth, actual, readback);
        return -1;
    }

    return 0;
}
Exemple #4
0
int print_bandwidth(struct cli_state *state, int argc, char **argv)
{
    /* Usage: print bandwidth [rx|tx]*/
    int rv = CLI_RET_OK, status;
    bladerf_module module = BLADERF_MODULE_RX ;
    unsigned int bw ;

    if( argc == 3 ) {
        bool ok;
        module = get_module( argv[2], &ok );
        if( !ok ) {
            invalid_module(state, argv[0], argv[2]);
            return CLI_RET_INVPARAM;
        }
    } else if (argc != 2) {
        /* Assume both RX & TX if not specified */
        return CLI_RET_NARGS;
    }

    printf( "\n" ) ;

    if( argc == 2 || module == BLADERF_MODULE_RX ) {
        status =  bladerf_get_bandwidth( state->dev, BLADERF_MODULE_RX, &bw );
        if (status < 0) {
            state->last_lib_error = status;
            rv = CLI_RET_LIBBLADERF;
        } else {
            printf( "  RX Bandwidth: %9uHz\n", bw );
        }
    }

    if( argc == 2 || module == BLADERF_MODULE_TX ) {
        status = bladerf_get_bandwidth( state->dev, BLADERF_MODULE_TX, &bw );
        if (status < 0) {
            state->last_lib_error = status;
            rv = CLI_RET_LIBBLADERF;
        } else {
            printf( "  TX Bandwidth: %9uHz\n", bw );
        }
    }

    printf( "\n" );

    return rv;
}
Exemple #5
0
static int get_rx_cal_backup(struct bladerf *dev, struct rx_cal_backup *b)
{
    int status;

    status = bladerf_get_rational_sample_rate(dev, BLADERF_MODULE_RX,
                                              &b->rational_sample_rate);
    if (status != 0) {
        return status;
    }

    status = bladerf_get_bandwidth(dev, BLADERF_MODULE_RX, &b->bandwidth);
    if (status != 0) {
        return status;
    }

    status = bladerf_get_frequency(dev, BLADERF_MODULE_TX, &b->tx_freq);
    if (status != 0) {
        return status;
    }

    return status;
}