Esempio n. 1
0
void dialogs_init(GtkBuilder *builder)
{
    const char *name = NULL;
    struct iio_context *ctx;
    GtkWidget *tmp;

    dialogs.builder = builder;

    dialogs.about = GTK_WIDGET(gtk_builder_get_object(builder, "About_dialog"));
    dialogs.connect = GTK_WIDGET(gtk_builder_get_object(builder, "connect_dialog"));
    dialogs.connect_fru = GTK_WIDGET(gtk_builder_get_object(builder, "fru_info"));
    dialogs.serial_num = GTK_WIDGET(gtk_builder_get_object(builder, "serial_number_popup"));
    dialogs.connect_iio = GTK_WIDGET(gtk_builder_get_object(builder, "connect_iio_devices"));
    dialogs.ctx_info = GTK_WIDGET(gtk_builder_get_object(builder, "connect_iio_ctx_info"));
    dialogs.load_save_profile = GTK_WIDGET(gtk_builder_get_object(builder, "load_save_profile"));
    dialogs.connect_net = GTK_WIDGET(gtk_builder_get_object(builder, "connect_net"));
    dialogs.net_ip = GTK_WIDGET(gtk_builder_get_object(builder, "connect_net_IP"));
    dialogs.ok_btn = GTK_WIDGET(gtk_builder_get_object(builder, "button3"));
    dialogs.latest_version = GTK_WIDGET(gtk_builder_get_object(builder, "latest_version_popup"));
    dialogs.ver_progress_window = GTK_WIDGET(gtk_builder_get_object(builder, "progress_window"));
    dialogs.ver_progress_bar = GTK_WIDGET(gtk_builder_get_object(builder, "progressbar"));
    gtk_builder_connect_signals(builder, &dialogs);

    /* Bind some dialogs radio buttons to text/labels */
    tmp = GTK_WIDGET(gtk_builder_get_object(builder, "connect_net_label"));
    serial_num = GTK_WIDGET(gtk_builder_get_object(builder, "serial_number"));
    fru_date = GTK_WIDGET(gtk_builder_get_object(builder, "fru_date"));
    fru_file_list = GTK_WIDGET(gtk_builder_get_object(builder, "FRU_files"));

    g_object_bind_property(dialogs.connect_net, "active", tmp, "sensitive", 0);
    g_object_bind_property(dialogs.connect_net, "active", dialogs.net_ip, "sensitive", 0);

    /* Grey out the "local context" option if it is not available */
    ctx = get_context_from_osc();
    if (ctx)
        name = iio_context_get_name(ctx);
    if (!name || strcmp(name, "local")) {
        ctx = iio_create_local_context();
        if (ctx) {
            iio_context_destroy(ctx);
        } else {
            GtkWidget *local = GTK_WIDGET(gtk_builder_get_object(
                                              builder, "connect_local"));
            gtk_widget_set_sensitive(local, false);
            gtk_toggle_button_set_active(
                GTK_TOGGLE_BUTTON(dialogs.connect_net), true);
        }
    }
}
Esempio n. 2
0
static gint fru_connect_dialog(Dialogs *data, bool load_profile)
{
    /* Connect Dialog */
    gint ret;
    struct iio_context *ctx;
    const char *name = NULL;
    bool has_context = false;

    /* Preload the device list and FRU info only if we can use the local
     * backend */
    ctx = get_context_from_osc();
    if (ctx)
        name = iio_context_get_name(ctx);
    if (name && !strcmp(name, "local"))
        has_context = connect_fillin(data);

    while (true) {
        gtk_widget_set_sensitive(data->ok_btn, has_context);

        ret = gtk_dialog_run(GTK_DIALOG(data->connect));
        switch (ret) {
        case GTK_RESPONSE_APPLY:
            widget_set_cursor(data->connect, GDK_WATCH);
            has_context = connect_fillin(data);
            widget_use_parent_cursor(data->connect);
            continue;
        case GTK_RESPONSE_OK:
            ctx = get_context(data);
            widget_set_cursor(data->connect, GDK_WATCH);
            widget_use_parent_cursor(data->connect);
            if (!ctx)
                continue;

            application_reload(ctx, load_profile);
            break;
        default:
            printf("unknown response (%i) in %s(%s)\n", ret, __FILE__, __func__);
        case GTK_RESPONSE_CANCEL:
        case GTK_RESPONSE_DELETE_EVENT:
            break;
        }

        gtk_widget_hide(data->connect);
        return ret;
    }
}
Esempio n. 3
0
static bool pr_config_identify(void)
{
	/* Use the OSC's IIO context just to detect the devices */
	struct iio_context *osc_ctx = get_context_from_osc();

	if (!iio_context_find_device(osc_ctx, PHY_DEVICE) ||
		!iio_context_find_device(osc_ctx, DEVICE_NAME_ADC) ||
		!iio_context_find_device(osc_ctx, DEVICE_NAME_DAC))
		return false;

	ctx = osc_create_context();
	phy = iio_context_find_device(ctx, PHY_DEVICE);
	adc = iio_context_find_device(ctx, DEVICE_NAME_ADC);
	dac = iio_context_find_device(ctx, DEVICE_NAME_DAC);

	context_is_local = !strncmp(iio_context_get_name(ctx), "local", strlen("local"));

	int id;
	bool init = true;

	if (!phy || !adc || !dac) {
		init = false;
	} else {
		id = getPrId();
		if ((id != PR_LOGIC_DEFAULT_ID) &&
				(id != PR_LOGIC_BIST_ID) &&
				(id != PR_LOGIC_QPSK_ID))
			init = false;
	}
	if (phy && !iio_device_get_debug_attrs_count(phy))
		init = false;
	if (!init)
		iio_context_destroy(ctx);

	return init;
}
Esempio n. 4
0
int main(int argc, char **argv)
{
	struct iio_context *ctx;
	int c, option_index = 0, arg_index = 0;
	enum backend backend = LOCAL;
	unsigned int major, minor;
	char git_tag[8];
	int ret;

	while ((c = getopt_long(argc, argv, "+hn:x:",
					options, &option_index)) != -1) {
		switch (c) {
		case 'h':
			usage();
			return EXIT_SUCCESS;
		case 'n':
			if (backend != LOCAL) {
				ERROR("-x and -n are mutually exclusive\n");
				return EXIT_FAILURE;
			}
			backend = NETWORK;
			arg_index += 2;
			break;
		case 'x':
			if (backend != LOCAL) {
				ERROR("-x and -n are mutually exclusive\n");
				return EXIT_FAILURE;
			}
			backend = XML;
			arg_index += 2;
			break;
		case '?':
			return EXIT_FAILURE;
		}
	}

	if (arg_index >= argc) {
		fprintf(stderr, "Incorrect number of arguments.\n\n");
		usage();
		return EXIT_FAILURE;
	}

	iio_library_get_version(&major, &minor, git_tag);
	INFO("Library version: %u.%u (git tag: %s)\n", major, minor, git_tag);

	if (backend == XML)
		ctx = iio_create_xml_context(argv[arg_index]);
	else if (backend == NETWORK)
		ctx = iio_create_network_context(argv[arg_index]);
	else
		ctx = iio_create_local_context();

	if (!ctx) {
		ERROR("Unable to create IIO context\n");
		return EXIT_FAILURE;
	}

	INFO("IIO context created with %s backend.\n",
			iio_context_get_name(ctx));

	ret = iio_context_get_version(ctx, &major, &minor, git_tag);
	if (!ret)
		INFO("Backend version: %u.%u (git tag: %s)\n",
				major, minor, git_tag);
	else
		ERROR("Unable to get backend version: %i\n", ret);

	unsigned int nb_devices = iio_context_get_devices_count(ctx);
	INFO("IIO context has %u devices:\n", nb_devices);

	unsigned int i;
	for (i = 0; i < nb_devices; i++) {
		const struct iio_device *dev = iio_context_get_device(ctx, i);
		const char *name = iio_device_get_name(dev);
		INFO("\t%s: %s\n", iio_device_get_id(dev), name ? name : "" );

		unsigned int nb_channels = iio_device_get_channels_count(dev);
		INFO("\t\t%u channels found:\n", nb_channels);

		unsigned int j;
		for (j = 0; j < nb_channels; j++) {
			struct iio_channel *ch = iio_device_get_channel(dev, j);
			const char *type_name;

			if (iio_channel_is_output(ch))
				type_name = "output";
			else
				type_name = "input";

			name = iio_channel_get_name(ch);
			INFO("\t\t\t%s: %s (%s)\n",
					iio_channel_get_id(ch),
					name ? name : "", type_name);

			unsigned int nb_attrs = iio_channel_get_attrs_count(ch);
			if (!nb_attrs)
				continue;

			INFO("\t\t\t%u channel-specific attributes found:\n",
					nb_attrs);

			unsigned int k;
			for (k = 0; k < nb_attrs; k++) {
				const char *attr = iio_channel_get_attr(ch, k);
				char buf[1024];
				ret = (int) iio_channel_attr_read(ch,
						attr, buf, 1024);
				if (ret > 0)
					INFO("\t\t\t\tattr %u: %s"
							" value: %s\n", k,
							attr, buf);
				else if (ret == -ENOSYS)
					INFO("\t\t\t\tattr %u: %s\n", k, attr);
				else
					ERROR("Unable to read attribute %s\n",
							attr);
			}
		}

		unsigned int nb_attrs = iio_device_get_attrs_count(dev);
		if (!nb_attrs)
			continue;

		INFO("\t\t%u device-specific attributes found:\n", nb_attrs);
		for (j = 0; j < nb_attrs; j++) {
			const char *attr = iio_device_get_attr(dev, j);
			char buf[1024];
			ret = (int) iio_device_attr_read(dev,
					attr, buf, 1024);
			if (ret > 0)
				INFO("\t\t\t\tattr %u: %s value: %s\n", j,
						attr, buf);
			else if (ret == -ENOSYS)
				INFO("\t\t\t\tattr %u: %s\n", j, attr);
			else
				ERROR("Unable to read attribute: %s\n", attr);
		}
	}

	iio_context_destroy(ctx);
	return EXIT_SUCCESS;
}