2012-09-03 20:20:51 +08:00
|
|
|
/*
|
2012-10-13 04:20:44 +08:00
|
|
|
* This file is part of the PulseView project.
|
2012-09-03 20:20:51 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2012-05-11 16:48:50 +08:00
|
|
|
#include <sigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <libsigrok/libsigrok.h>
|
|
|
|
|
2012-10-13 07:59:37 +08:00
|
|
|
#include <getopt.h>
|
|
|
|
|
2012-09-03 20:20:51 +08:00
|
|
|
#include <QtGui/QApplication>
|
2012-05-11 16:48:50 +08:00
|
|
|
#include <QDebug>
|
2012-10-13 04:38:06 +08:00
|
|
|
|
2013-03-31 17:31:51 +08:00
|
|
|
#include "signalhandler.h"
|
2012-10-13 05:41:01 +08:00
|
|
|
#include "pv/mainwindow.h"
|
2012-09-03 20:20:51 +08:00
|
|
|
|
2012-10-13 04:38:06 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2012-10-13 08:15:47 +08:00
|
|
|
void usage()
|
|
|
|
{
|
2013-02-20 18:39:38 +08:00
|
|
|
fprintf(stdout,
|
2012-10-13 08:15:47 +08:00
|
|
|
"Usage:\n"
|
2013-03-03 17:06:44 +08:00
|
|
|
" %s [OPTION…] [FILE] — %s\n"
|
2012-10-13 08:15:47 +08:00
|
|
|
"\n"
|
|
|
|
"Help Options:\n"
|
2013-03-25 00:50:49 +08:00
|
|
|
" -l, --loglevel Set libsigrok/libsigrokdecode loglevel\n"
|
2012-10-13 08:15:47 +08:00
|
|
|
" -V, --version Show release version\n"
|
|
|
|
" -h, -?, --help Show help option\n"
|
|
|
|
"\n", PV_BIN_NAME, PV_DESCRIPTION);
|
|
|
|
}
|
|
|
|
|
2012-09-03 20:20:51 +08:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2012-11-02 08:11:21 +08:00
|
|
|
int ret = 0;
|
2012-10-22 07:12:52 +08:00
|
|
|
struct sr_context *sr_ctx = NULL;
|
2013-03-03 17:06:44 +08:00
|
|
|
const char *open_file = NULL;
|
2012-10-22 07:12:52 +08:00
|
|
|
|
2012-09-03 20:20:51 +08:00
|
|
|
QApplication a(argc, argv);
|
|
|
|
|
2012-10-13 07:13:44 +08:00
|
|
|
// Set some application metadata
|
2012-10-13 04:38:06 +08:00
|
|
|
QApplication::setApplicationVersion(PV_VERSION_STRING);
|
2012-10-08 03:15:15 +08:00
|
|
|
QApplication::setApplicationName("PulseView");
|
2012-05-11 16:40:27 +08:00
|
|
|
QApplication::setOrganizationDomain("http://www.sigrok.org");
|
|
|
|
|
2012-10-13 07:59:37 +08:00
|
|
|
// Parse arguments
|
|
|
|
while (1) {
|
|
|
|
static const struct option long_options[] = {
|
2013-03-25 00:50:49 +08:00
|
|
|
{"loglevel", required_argument, 0, 'l'},
|
2012-12-13 05:19:22 +08:00
|
|
|
{"version", no_argument, 0, 'V'},
|
|
|
|
{"help", no_argument, 0, 'h'},
|
2012-10-13 07:59:37 +08:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
2013-03-08 07:51:08 +08:00
|
|
|
const int c = getopt_long(argc, argv,
|
2013-03-25 00:50:49 +08:00
|
|
|
"l:Vh?", long_options, NULL);
|
2012-10-13 07:59:37 +08:00
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (c) {
|
2013-03-25 00:50:49 +08:00
|
|
|
case 'l':
|
|
|
|
{
|
|
|
|
const int loglevel = atoi(optarg);
|
|
|
|
sr_log_loglevel_set(loglevel);
|
|
|
|
srd_log_loglevel_set(loglevel);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-10-13 07:59:37 +08:00
|
|
|
case 'V':
|
|
|
|
// Print version info
|
2013-02-20 18:39:38 +08:00
|
|
|
fprintf(stdout, "%s %s\n", PV_TITLE, PV_VERSION_STRING);
|
2012-10-13 07:59:37 +08:00
|
|
|
return 0;
|
2012-10-13 08:15:47 +08:00
|
|
|
|
|
|
|
case 'h':
|
|
|
|
case '?':
|
|
|
|
usage();
|
|
|
|
return 0;
|
2012-10-13 07:59:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-03 17:06:44 +08:00
|
|
|
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];
|
|
|
|
|
2012-10-13 07:13:44 +08:00
|
|
|
// Initialise libsigrok
|
2012-10-22 07:12:52 +08:00
|
|
|
if (sr_init(&sr_ctx) != SR_OK) {
|
2012-05-11 16:48:50 +08:00
|
|
|
qDebug() << "ERROR: libsigrok init failed.";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-10-13 07:13:44 +08:00
|
|
|
// Initialise libsigrokdecode
|
2012-11-02 08:11:21 +08:00
|
|
|
if (srd_init(NULL) == SRD_OK) {
|
|
|
|
|
|
|
|
// Load the protocol decoders
|
|
|
|
srd_decoder_load_all();
|
|
|
|
|
|
|
|
// Initialize all libsigrok drivers
|
|
|
|
sr_dev_driver **const drivers = sr_driver_list();
|
|
|
|
for (sr_dev_driver **driver = drivers; *driver; driver++) {
|
2012-12-03 11:23:37 +08:00
|
|
|
if (sr_driver_init(sr_ctx, *driver) != SR_OK) {
|
2012-11-02 08:11:21 +08:00
|
|
|
qDebug("Failed to initialize driver %s",
|
|
|
|
(*driver)->name);
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-05-11 16:48:50 +08:00
|
|
|
|
2012-12-13 05:19:22 +08:00
|
|
|
if (ret == 0) {
|
2012-11-02 08:11:21 +08:00
|
|
|
// Initialise the main window
|
2013-03-03 17:06:44 +08:00
|
|
|
pv::MainWindow w(open_file);
|
2012-11-02 08:11:21 +08:00
|
|
|
w.show();
|
2012-05-11 16:48:50 +08:00
|
|
|
|
2013-03-31 17:31:51 +08:00
|
|
|
if(SignalHandler::prepareSignals()) {
|
|
|
|
SignalHandler *const signalHandler =
|
|
|
|
new SignalHandler(&w);
|
|
|
|
QObject::connect(signalHandler,
|
|
|
|
SIGNAL(sigIntReceived()),
|
|
|
|
&w, SLOT(close()));
|
|
|
|
QObject::connect(signalHandler,
|
|
|
|
SIGNAL(sigTermReceived()),
|
|
|
|
&w, SLOT(close()));
|
|
|
|
} else {
|
|
|
|
qWarning() <<
|
|
|
|
"Could not prepare signal handler.";
|
|
|
|
}
|
|
|
|
|
2012-11-02 08:11:21 +08:00
|
|
|
// Run the application
|
|
|
|
ret = a.exec();
|
2012-06-28 05:36:23 +08:00
|
|
|
}
|
|
|
|
|
2012-11-02 08:11:21 +08:00
|
|
|
// Destroy libsigrokdecode and libsigrok
|
|
|
|
srd_exit();
|
2012-05-11 16:48:50 +08:00
|
|
|
|
2012-11-02 08:11:21 +08:00
|
|
|
} else {
|
|
|
|
qDebug() << "ERROR: libsigrokdecode init failed.";
|
|
|
|
}
|
2012-05-11 16:48:50 +08:00
|
|
|
|
2012-10-22 07:12:52 +08:00
|
|
|
if (sr_ctx)
|
|
|
|
sr_exit(sr_ctx);
|
2012-05-11 16:48:50 +08:00
|
|
|
|
|
|
|
return ret;
|
2012-09-03 20:20:51 +08:00
|
|
|
}
|