Exemple #1
0
int cmd_version(struct cli_state *state, int argc, char **argv)
{
    int status;

    struct bladerf_version fw_version, fpga_version, lib_version;
    bool fpga_loaded = false;

    bladerf_version(&lib_version);

    printf("\n");
    printf("  bladeRF-cli version:        " BLADERF_CLI_VERSION "\n");
    printf("  libbladeRF version:         %s\n", lib_version.describe);
    printf("\n");

    /* Exit cleanly if no device is attached */
    if (state->dev == NULL) {
        printf("  Device version information unavailable: No device attached.\n");
        return 0;
    }

    status = bladerf_is_fpga_configured(state->dev);
    if (status < 0) {
        state->last_lib_error = status;
        return CLI_RET_LIBBLADERF;
    } else if (status != 0) {
        fpga_loaded = true;
        status = bladerf_fpga_version(state->dev, &fpga_version);
        if (status < 0) {
            state->last_lib_error = status;
            return CLI_RET_LIBBLADERF;
        }
    }

    status = bladerf_fw_version(state->dev, &fw_version);
    if (status < 0) {
        state->last_lib_error = status;
        return CLI_RET_LIBBLADERF;
    }


    printf("  Firmware version:           %s\n", fw_version.describe);

    if (fpga_loaded) {
        printf("  FPGA version:               %s\n", fpga_version.describe);
    } else {
        printf("  FPGA version:               Unknown (FPGA not loaded)\n");
    }

    printf("\n");
    return CLI_RET_OK;
}
//! Do any initialization required
void BladeRfTxComponent::initialize()
{
    // Set up the input DataBuffer
    inBuf_ = castToType< complex<float> >(inputBuffers.at(0));

    // Initialize raw sample vector to some multiple of block size
    rawSampleBuffer_.data.resize(128 * BLADERF_SAMPLE_BLOCK_SIZE);

    // Set up the BladeRF
    try
    {
        // Create the device
        LOG(LINFO) << "Trying to open device " << deviceName_x;
        int ret = bladerf_open(&device_, deviceName_x.c_str());
        if (ret != 0) {
            throw IrisException("Failed to open bladeRF device!");
        }

        // Check whether FPGA is configured yet
        if (bladerf_is_fpga_configured(device_) != 1 ) {
            // try to load FPGA image
            if (not fpgaImage_x.empty()) {
                ret = bladerf_load_fpga(device_, fpgaImage_x.c_str());
                if (ret != 0) {
                    throw IrisException("Failed to load FPGA to bladeRF!");
                } else {
                    LOG(LINFO) << "FPGA image successfully loaded.";
                }
            } else {
                throw IrisException("BladeRF FPGA is not configured and no FPGA image given!");
            }
        }

        // Print some information about device
        struct bladerf_version version;
        if (bladerf_fw_version(device_, &version) == 0) {
            LOG(LINFO) << "Using FW " << version.describe;
        }
        if (bladerf_fpga_version(device_, &version) == 0) {
            LOG(LINFO) << "Using FPGA " << version.describe;
        }
        if (bladerf_is_fpga_configured(device_) != 1 ) {
            throw IrisException("BladeRF FPGA is not configured!");
        }

        // setting up sync config
        ret = bladerf_sync_config(device_,
                                  BLADERF_MODULE_TX,
                                  BLADERF_FORMAT_SC16_Q11,
                                  BLADERF_DEFAULT_STREAM_BUFFERS,
                                  BLADERF_DEFAULT_STREAM_SAMPLES,
                                  BLADERF_DEFAULT_STREAM_XFERS,
                                  BLADERF_SYNC_TIMEOUT_MS);
        if (ret != 0) {
            throw IrisException("Couldn't enable BladeRF Tx sync handle!");
            LOG(LERROR) << bladerf_strerror(ret);
        }

        // Turn on transmitter
        ret = bladerf_enable_module(device_, BLADERF_MODULE_TX, true);
        if ( ret != 0 ) {
            throw IrisException("Couldn't enable BladeRF Tx module!");
        }

        // Set sample rate
        uint32_t actualValue;
        ret = bladerf_set_sample_rate(device_, BLADERF_MODULE_TX, (uint32_t)rate_x, &actualValue);
        if (ret != 0) {
            throw IrisException("Failed to set sample rate!");
        }
        LOG(LINFO) << "Actual Tx sample rate is: " << actualValue << " Hz";

        // Set center frequency
        ret = bladerf_set_frequency(device_, BLADERF_MODULE_TX, frequency_x);
        if (ret != 0) {
            throw IrisException("Failed to set center frequency!");
        }
        bladerf_get_frequency(device_, BLADERF_MODULE_TX, &actualValue);
        LOG(LINFO) << "Actual Tx center frequency is: " << actualValue << " Hz";

        // Set bandwidth
        ret = bladerf_set_bandwidth(device_, BLADERF_MODULE_TX, bw_x, &actualValue);
        if (ret != 0) {
            throw IrisException("Failed to set receive bandwidth!");
        }
        LOG(LINFO) << "Actual Tx bandwidth is " << actualValue << " Hz";

        // Set VGA1 gain
        int actualGain;
        ret = bladerf_set_txvga1(device_, vga1Gain_x);
        if (ret != 0) {
            throw IrisException("Failed to set VGA1 gain!");
        }
        bladerf_get_txvga1(device_, &actualGain);
        LOG(LINFO) << "Actual VGA1 gain is " << actualGain << " dB";

        // Set VGA2 gain
        ret = bladerf_set_txvga2(device_, vga2Gain_x);
        if (ret != 0) {
            throw IrisException("Failed to set VGA2 gain!");
        }
        bladerf_get_txvga2(device_, &actualGain);
        LOG(LINFO) << "Actual VGA2 gain is " << actualGain << " dB";
    }
    catch(const boost::exception &e)
    {
        throw IrisException(boost::diagnostic_information(e));
    }
    catch(std::exception& e)
    {
        throw IrisException(e.what());
    }
}