コード例 #1
0
ファイル: airspy_info.c プロジェクト: FlagJollyRoger/host
int main(int argc, char** argv)
{
	int i;
	uint32_t j;
	int result;
	int opt;
	uint32_t count;
	uint32_t *samplerates;
	uint32_t serial_number_msb_val;
	uint32_t serial_number_lsb_val;
	airspy_lib_version_t lib_version;
	uint8_t board_id = AIRSPY_BOARD_ID_INVALID;

	while( (opt = getopt(argc, argv, "s:")) != EOF )
	{
		result = AIRSPY_SUCCESS;
		switch( opt ) 
		{
		case 's':
			serial_number = true;
			result = parse_u64(optarg, &serial_number_val);
			serial_number_msb_val = (uint32_t)(serial_number_val >> 32);
			serial_number_lsb_val = (uint32_t)(serial_number_val & 0xFFFFFFFF);
			printf("Board serial number to open: 0x%08X%08X\n", serial_number_msb_val, serial_number_lsb_val);
			break;

		default:
			printf("unknown argument '-%c %s'\n", opt, optarg);
			usage();
			return EXIT_FAILURE;
		}
		
		if( result != AIRSPY_SUCCESS ) {
			printf("argument error: '-%c %s' %s (%d)\n", opt, optarg, airspy_error_name(result), result);
			usage();
			return EXIT_FAILURE;
		}		
	}

	result = airspy_init();
	if (result != AIRSPY_SUCCESS) {
		fprintf(stderr, "airspy_init() failed: %s (%d)\n",
				airspy_error_name(result), result);
		return EXIT_FAILURE;
	}

	airspy_lib_version(&lib_version);
	printf("airspy_lib_version: %d.%d.%d\n", 
					lib_version.major_version, lib_version.minor_version, lib_version.revision); 

	for (i = 0; i < AIRSPY_MAX_DEVICE; i++)
	{
		if(serial_number == true)
		{
			result = airspy_open_sn(&devices[i], serial_number_val);
		}else
		{
			result = airspy_open(&devices[i]);
		}
		if (result != AIRSPY_SUCCESS)
		{
			if(i == 0)
			{
				fprintf(stderr, "airspy_open() board %d failed: %s (%d)\n",
						i+1, airspy_error_name(result), result);
			}
			break;
		}
	}

	for(i = 0; i < AIRSPY_MAX_DEVICE; i++)
	{
		if(devices[i] != NULL)
		{
			printf("\nFound AirSpy board %d\n", i + 1);
			fflush(stdout);
			result = airspy_board_id_read(devices[i], &board_id);
			if (result != AIRSPY_SUCCESS) {
				fprintf(stderr, "airspy_board_id_read() failed: %s (%d)\n",
					airspy_error_name(result), result);
				continue;
			}
			printf("Board ID Number: %d (%s)\n", board_id,
				airspy_board_id_name(board_id));

			result = airspy_version_string_read(devices[i], &version[0], 255);
			if (result != AIRSPY_SUCCESS) {
				fprintf(stderr, "airspy_version_string_read() failed: %s (%d)\n",
					airspy_error_name(result), result);
				continue;
			}
			printf("Firmware Version: %s\n", version);

			result = airspy_board_partid_serialno_read(devices[i], &read_partid_serialno);
			if (result != AIRSPY_SUCCESS) {
				fprintf(stderr, "airspy_board_partid_serialno_read() failed: %s (%d)\n",
					airspy_error_name(result), result);
				continue;
			}
			printf("Part ID Number: 0x%08X 0x%08X\n",
				read_partid_serialno.part_id[0],
				read_partid_serialno.part_id[1]);
			printf("Serial Number: 0x%08X%08X\n",
				read_partid_serialno.serial_no[2],
				read_partid_serialno.serial_no[3]);

			printf("Supported sample rates:\n");
			airspy_get_samplerates(devices[i], &count, 0);
			samplerates = (uint32_t *) malloc(count * sizeof(uint32_t));
			airspy_get_samplerates(devices[i], samplerates, count);
			for (j = 0; j < count; j++)
			{
				printf("\t%f MSPS\n", samplerates[j] * 0.000001f);
			}
			free(samplerates);

			printf("Close board %d\n", i+1);
			result = airspy_close(devices[i]);
			if (result != AIRSPY_SUCCESS) {
				fprintf(stderr, "airspy_close() board %d failed: %s (%d)\n",
						i+1, airspy_error_name(result), result);
				continue;
			}
		}
	}

	airspy_exit();
	return EXIT_SUCCESS;
}
コード例 #2
0
ファイル: AirspySource.cpp プロジェクト: f4exb/sdrdaemon
// Open Airspy device.
AirspySource::AirspySource(int dev_index) :
    m_dev(0),
    m_sampleRate(10000000),
    m_frequency(100000000),
	m_ppm(0),
    m_lnaGain(8),
    m_mixGain(8),
    m_vgaGain(0),
    m_biasAnt(false),
    m_lnaAGC(false),
    m_mixAGC(false),
    m_running(false),
    m_thread(0)
{
    airspy_error rc = (airspy_error) airspy_init();

    if (rc != AIRSPY_SUCCESS)
    {
        std::ostringstream err_ostr;
        err_ostr << "Failed to open Airspy library (" << rc << ": " << airspy_error_name(rc) << ")";
        m_error = err_ostr.str();
        m_dev = 0;
    }
    else
    {
        for (int i = 0; i < AIRSPY_MAX_DEVICE; i++)
        {
            rc = (airspy_error) airspy_open(&m_dev);

            if (rc == AIRSPY_SUCCESS)
            {
                if (i == dev_index)
                {
                    break;
                }
            }
            else
            {
                std::ostringstream err_ostr;
                err_ostr << "Failed to open Airspy device at sequence " << i;
                m_error = err_ostr.str();
                m_dev = 0;
            }
        }
    }

    if (m_dev)
    {
        uint32_t nbSampleRates;
        uint32_t *sampleRates;

        airspy_get_samplerates(m_dev, &nbSampleRates, 0);

        sampleRates = new uint32_t[nbSampleRates];

        airspy_get_samplerates(m_dev, sampleRates, nbSampleRates);

        if (nbSampleRates == 0)
        {
            m_error = "Failed to get Airspy device sample rate list";
            airspy_close(m_dev);
            m_dev = 0;
        }
        else
        {
            for (uint32_t i=0; i<nbSampleRates; i++)
            {
                m_srates.push_back(sampleRates[i]);
            }
        }

        delete[] sampleRates;

        std::ostringstream srates_ostr;

        for (int s: m_srates) {
            srates_ostr << s << " ";
        }

        m_sratesStr = srates_ostr.str();

        rc = (airspy_error) airspy_set_sample_type(m_dev, AIRSPY_SAMPLE_INT16_IQ);

        if (rc != AIRSPY_SUCCESS)
        {
            m_error = "AirspyInput::start: could not set sample type to INT16_IQ";
        }
    }

    std::ostringstream lgains_ostr;

    for (int g: m_lgains) {
        lgains_ostr << g << " ";
    }

    m_lgainsStr = lgains_ostr.str();

    std::ostringstream mgains_ostr;

    for (int g: m_mgains) {
        mgains_ostr << g << " ";
    }

    m_mgainsStr = mgains_ostr.str();

    std::ostringstream vgains_ostr;

    for (int g: m_vgains) {
        vgains_ostr << g << " ";
    }

    m_vgainsStr = vgains_ostr.str();

    std::ostringstream bwfilt_ostr;
    bwfilt_ostr << std::fixed << std::setprecision(2);

    m_this = this;
}