示例#1
0
文件: main.cpp 项目: ksjoberg/sigrok
int main(int argc, char *argv[])
{
    QString locale = QLocale::system().name();
    QApplication a(argc, argv);
    QTranslator translator;

    translator.load(QString("locale/sigrok-gui_") + locale);
    a.installTranslator(&translator);

    /* Set some application metadata. */
    QApplication::setApplicationVersion(APP_VERSION);
    QApplication::setApplicationName("sigrok-gui");
    QApplication::setOrganizationDomain("http://www.sigrok.org");

    /* Disable this to actually allow running the (pre-alpha!) GUI. */
    qDebug() << "The GUI is not yet usable, aborting.";
    // return 1;

    if (sr_init() != SR_OK) {
        qDebug() << "ERROR: libsigrok init failed.";
        return 1;
    }
    qDebug() << "libsigrok initialized successfully.";

    if (srd_init() != SRD_OK) {
        qDebug() << "ERROR: libsigrokdecode init failed.";
        return 1;
    }
    qDebug() << "libsigrokdecode initialized successfully.";

    w = new MainWindow;
    w->show();

    return a.exec();
}
示例#2
0
END_TEST

/*
 * Check whether nested srd_init()/srd_exit() calls work/fail correctly.
 * Two consecutive srd_init() calls without any srd_exit() inbetween are
 * not allowed and should fail. However, two consecutive srd_exit() calls
 * are currently allowed, the second one will just be a NOP basically.
 */
START_TEST(test_init_exit_2)
{
	int ret;

	ret = srd_init(NULL);
	fail_unless(ret == SRD_OK, "srd_init() 1 failed: %d.", ret);
	ret = srd_init(NULL);
	fail_unless(ret != SRD_OK, "srd_init() 2 didn't fail: %d.", ret);
	ret = srd_exit();
	fail_unless(ret == SRD_OK, "srd_exit() 2 failed: %d.", ret);
	ret = srd_exit();
	fail_unless(ret == SRD_OK, "srd_exit() 1 failed: %d.", ret);
}
示例#3
0
END_TEST

/*
 * Check whether three nested srd_init()/srd_exit() calls work/fail correctly.
 */
START_TEST(test_init_exit_3)
{
	int ret;

	ret = srd_init(NULL);
	fail_unless(ret == SRD_OK, "srd_init() 1 failed: %d.", ret);
	ret = srd_init(NULL);
	fail_unless(ret != SRD_OK, "srd_init() 2 didn't fail: %d.", ret);
	ret = srd_init(NULL);
	fail_unless(ret != SRD_OK, "srd_init() 3 didn't fail: %d.", ret);
	ret = srd_exit();
	fail_unless(ret == SRD_OK, "srd_exit() 3 failed: %d.", ret);
	ret = srd_exit();
	fail_unless(ret == SRD_OK, "srd_exit() 2 failed: %d.", ret);
	ret = srd_exit();
	fail_unless(ret == SRD_OK, "srd_exit() 1 failed: %d.", ret);
}
示例#4
0
文件: sigrok-cli.c 项目: jeras/sigrok
static void show_version(void)
{
	GSList *l;
	struct sr_dev_driver **drivers;
	struct sr_input_format **inputs;
	struct sr_output_format **outputs;
	struct srd_decoder *dec;
	int i;

	printf("sigrok-cli %s\n\n", VERSION);

	printf("Using libsigrok %s (lib version %s).\n",
	       sr_package_version_string_get(), sr_lib_version_string_get());
	printf("Using libsigrokdecode %s (lib version %s).\n\n",
	       srd_package_version_string_get(), srd_lib_version_string_get());

	printf("Supported hardware drivers:\n");
	drivers = sr_driver_list();
	for (i = 0; drivers[i]; i++) {
		printf("  %-20s %s\n", drivers[i]->name, drivers[i]->longname);
	}
	printf("\n");

	printf("Supported input formats:\n");
	inputs = sr_input_list();
	for (i = 0; inputs[i]; i++)
		printf("  %-20s %s\n", inputs[i]->id, inputs[i]->description);
	printf("\n");

	printf("Supported output formats:\n");
	outputs = sr_output_list();
	for (i = 0; outputs[i]; i++)
		printf("  %-20s %s\n", outputs[i]->id, outputs[i]->description);
	printf("\n");

	if (srd_init(NULL) == SRD_OK) {
		printf("Supported protocol decoders:\n");
		srd_decoder_load_all();
		for (l = srd_decoder_list(); l; l = l->next) {
			dec = l->data;
			printf("  %-20s %s\n", dec->id, dec->longname);
			/* Print protocol description upon "-l 3" or higher. */
			if (opt_loglevel >= SR_LOG_INFO)
				printf("  %-20s %s\n", "", dec->desc);
		}
		srd_exit();
	}
	printf("\n");
}
示例#5
0
文件: main.c 项目: brgl/sigrok-cli
int main(int argc, char **argv)
{
	g_log_set_default_handler(logger, NULL);

	if (parse_options(argc, argv)) {
		return 1;
	}

	/* Set the loglevel (amount of messages to output) for libsigrok. */
	if (sr_log_loglevel_set(opt_loglevel) != SR_OK)
		goto done;

	if (sr_init(&sr_ctx) != SR_OK)
		goto done;

#ifdef HAVE_SRD
	/* Set the loglevel (amount of messages to output) for libsigrokdecode. */
	if (srd_log_loglevel_set(opt_loglevel) != SRD_OK)
		goto done;

	if (opt_pds) {
		if (srd_init(NULL) != SRD_OK)
			goto done;
		if (srd_session_new(&srd_sess) != SRD_OK) {
			g_critical("Failed to create new decode session.");
			goto done;
		}
		if (register_pds(opt_pds, opt_pd_annotations) != 0)
			goto done;
		if (setup_pd_stack(opt_pds, opt_pd_stack, opt_pd_annotations) != 0)
			goto done;

		/* Only one output type is ever shown. */
		if (opt_pd_binary) {
			if (setup_pd_binary(opt_pd_binary) != 0)
				goto done;
			if (srd_pd_output_callback_add(srd_sess, SRD_OUTPUT_BINARY,
					show_pd_binary, NULL) != SRD_OK)
				goto done;
		} else if (opt_pd_meta) {
			if (setup_pd_meta(opt_pd_meta) != 0)
				goto done;
			if (srd_pd_output_callback_add(srd_sess, SRD_OUTPUT_META,
					show_pd_meta, NULL) != SRD_OK)
				goto done;
		} else {
			if (opt_pd_annotations)
				if (setup_pd_annotations(opt_pd_annotations) != 0)
					goto done;
			if (srd_pd_output_callback_add(srd_sess, SRD_OUTPUT_ANN,
					show_pd_annotations, NULL) != SRD_OK)
				goto done;
		}
	}
#endif

	if (opt_version)
		show_version();
	else if (opt_input_format && opt_show)
		show_input();
	else if (opt_output_format && opt_show)
		show_output();
	else if (opt_transform_module && opt_show)
		show_transform();
	else if (opt_scan_devs)
		show_dev_list();
#ifdef HAVE_SRD
	else if (opt_pds && opt_show)
		show_pd_detail();
#endif
	else if (opt_show)
		show_dev_detail();
	else if (opt_input_file)
		load_input_file();
	else if (opt_get)
		get_option();
	else if (opt_set)
		set_options();
	else if (opt_samples || opt_time || opt_frames || opt_continuous)
		run_session();
	else
		show_help();

#ifdef HAVE_SRD
	if (opt_pds)
		srd_exit();
#endif

done:
	if (sr_ctx)
		sr_exit(sr_ctx);

	return 0;
}
示例#6
0
int main(int argc, char *argv[])
{
	int ret = 0;
	struct sr_context *sr_ctx = NULL;
	const char *open_file = NULL;

	QApplication a(argc, argv);

	// Set some application metadata
    	QApplication::setApplicationVersion(DS_VERSION_STRING);
    	QApplication::setApplicationName("DSLogic(Beta)");
    	QApplication::setOrganizationDomain("http://www.DreamSourceLab.com");

	// Parse arguments
	while (1) {
		static const struct option long_options[] = {
			{"loglevel", required_argument, 0, 'l'},
			{"version", no_argument, 0, 'V'},
			{"help", no_argument, 0, 'h'},
			{0, 0, 0, 0}
		};

		const int c = getopt_long(argc, argv,
			"l:Vh?", long_options, NULL);
		if (c == -1)
			break;

		switch (c) {
		case 'l':
		{
			const int loglevel = atoi(optarg);
			sr_log_loglevel_set(loglevel);

#ifdef ENABLE_DECODE
			srd_log_loglevel_set(loglevel);
#endif

			break;
		}

		case 'V':
			// Print version info
			fprintf(stdout, "%s %s\n", DS_TITLE, DS_VERSION_STRING);
			return 0;

		case 'h':
		case '?':
			usage();
			return 0;
		}
	}

	if (argc - optind > 1) {
		fprintf(stderr, "Only one file can be openened.\n");
		return 1;
	} else if (argc - optind == 1)
		open_file = argv[argc - 1];

	// Initialise libsigrok
	if (sr_init(&sr_ctx) != SR_OK) {
		qDebug() << "ERROR: libsigrok init failed.";
		return 1;
	}

	do {

#ifdef ENABLE_DECODE
        QDir dir(QCoreApplication::applicationDirPath());
        assert(dir.cd("decoders"));
        std::string str = dir.absolutePath().toStdString() + "/";
        strcpy(decoders_path, str.c_str());

		// Initialise libsigrokdecode
		if (srd_init(NULL) != SRD_OK) {
			qDebug() << "ERROR: libsigrokdecode init failed.";
			break;
		}

		// Load the protocol decoders
		srd_decoder_load_all();
#endif

		try {
			// Create the device manager, initialise the drivers
			pv::DeviceManager device_manager(sr_ctx);

			// Initialise the main window
            		pv::MainWindow w(device_manager, open_file);
            		QFile qss(":/stylesheet.qss");
            		qss.open(QFile::ReadOnly);
            		a.setStyleSheet(qss.readAll());
            		qss.close();
			w.show();

			// Run the application
			ret = a.exec();

		} catch(std::exception e) {
			qDebug() << e.what();
		}

#ifdef ENABLE_DECODE
		// Destroy libsigrokdecode
		srd_exit();
#endif

	} while (0);

	// Destroy libsigrok
	if (sr_ctx)
		sr_exit(sr_ctx);

	return ret;
}
示例#7
0
文件: show.c 项目: JenSte/sigrok-cli
void show_version(void)
{
	struct sr_dev_driver **drivers, *driver;
	struct sr_input_format **inputs, *input;
	struct sr_output_format **outputs, *output;
	const GSList *l;
	GSList *sl;
	int i;
#ifdef HAVE_SRD
	struct srd_decoder *dec;
#endif

	printf("sigrok-cli %s\n\n", VERSION);

	printf("Using libsigrok %s (lib version %s).\n",
	       sr_package_version_string_get(), sr_lib_version_string_get());
#ifdef HAVE_SRD
	printf("Using libsigrokdecode %s (lib version %s).\n\n",
	       srd_package_version_string_get(), srd_lib_version_string_get());
#endif

	printf("Supported hardware drivers:\n");
	drivers = sr_driver_list();
	for (sl = NULL, i = 0; drivers[i]; i++)
		sl = g_slist_append(sl, drivers[i]);
	sl = g_slist_sort(sl, sort_drivers);
	for (l = sl; l; l = l->next) {
		driver = l->data;
		printf("  %-20s %s\n", driver->name, driver->longname);
	}
	printf("\n");
	g_slist_free(sl);

	printf("Supported input formats:\n");
	inputs = sr_input_list();
	for (sl = NULL, i = 0; inputs[i]; i++)
		sl = g_slist_append(sl, inputs[i]);
	sl = g_slist_sort(sl, sort_inputs);
	for (l = sl; l; l = l->next) {
		input = l->data;
		printf("  %-20s %s\n", input->id, input->description);
	}
	printf("\n");
	g_slist_free(sl);

	printf("Supported output formats:\n");
	outputs = sr_output_list();
	for (sl = NULL, i = 0; outputs[i]; i++)
		sl = g_slist_append(sl, outputs[i]);
	sl = g_slist_sort(sl, sort_outputs);
	for (l = sl; l; l = l->next) {
		output = l->data;
		printf("  %-20s %s\n", output->id, output->description);
	}
	printf("\n");
	g_slist_free(sl);

#ifdef HAVE_SRD
	if (srd_init(NULL) == SRD_OK) {
		printf("Supported protocol decoders:\n");
		srd_decoder_load_all();
		sl = g_slist_copy((GSList *)srd_decoder_list());
		sl = g_slist_sort(sl, sort_pds);
		for (l = sl; l; l = l->next) {
			dec = l->data;
			printf("  %-20s %s\n", dec->id, dec->longname);
			/* Print protocol description upon "-l 3" or higher. */
			if (opt_loglevel >= SR_LOG_INFO)
				printf("  %-20s %s\n", "", dec->desc);
		}
		g_slist_free(sl);
		srd_exit();
	}
	printf("\n");
#endif
}
示例#8
0
文件: sigrok-cli.c 项目: jeras/sigrok
int main(int argc, char **argv)
{
	GOptionContext *context;
	GError *error;

	g_log_set_default_handler(logger, NULL);

	error = NULL;
	context = g_option_context_new(NULL);
	g_option_context_add_main_entries(context, optargs, NULL);

	if (!g_option_context_parse(context, &argc, &argv, &error)) {
		g_critical("%s", error->message);
		return 1;
	}

	/* Set the loglevel (amount of messages to output) for libsigrok. */
	if (sr_log_loglevel_set(opt_loglevel) != SR_OK)
		return 1;

	/* Set the loglevel (amount of messages to output) for libsigrokdecode. */
	if (srd_log_loglevel_set(opt_loglevel) != SRD_OK)
		return 1;

	if (sr_init() != SR_OK)
		return 1;

	if (opt_pds) {
		if (srd_init(NULL) != SRD_OK)
			return 1;
		if (register_pds(NULL, opt_pds) != 0)
			return 1;
		if (srd_pd_output_callback_add(SRD_OUTPUT_ANN,
				show_pd_annotations, NULL) != SRD_OK)
			return 1;
		if (setup_pd_stack() != 0)
			return 1;
		if (setup_pd_annotations() != 0)
			return 1;
	}

	if (setup_output_format() != 0)
		return 1;

	if (opt_version)
		show_version();
	else if (opt_list_devs)
		show_dev_list();
	else if (opt_input_file)
		load_input_file();
	else if (opt_samples || opt_time || opt_frames || opt_continuous)
		run_session();
	else if (opt_dev)
		show_dev_detail();
	else if (opt_pds)
		show_pd_detail();
	else
		printf("%s", g_option_context_get_help(context, TRUE, NULL));

	if (opt_pds)
		srd_exit();

	g_option_context_free(context);
	sr_exit();

	return 0;
}