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
|
|
|
|
*/
|
|
|
|
|
2013-12-29 02:29:23 +08:00
|
|
|
#ifdef ENABLE_DECODE
|
2013-05-04 02:54:27 +08:00
|
|
|
#include <libsigrokdecode/libsigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
|
2013-12-29 02:29:23 +08:00
|
|
|
#endif
|
2013-04-17 02:45:04 +08:00
|
|
|
|
2012-05-11 16:48:50 +08:00
|
|
|
#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-04-19 04:17:47 +08:00
|
|
|
#ifdef ENABLE_SIGNALS
|
2013-03-31 17:31:51 +08:00
|
|
|
#include "signalhandler.h"
|
2013-04-19 04:17:47 +08:00
|
|
|
#endif
|
|
|
|
|
2013-04-28 04:53:21 +08:00
|
|
|
#include "pv/devicemanager.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);
|
2013-12-29 02:29:23 +08:00
|
|
|
|
|
|
|
#ifdef ENABLE_DECODE
|
2013-03-25 00:50:49 +08:00
|
|
|
srd_log_loglevel_set(loglevel);
|
2013-12-29 02:29:23 +08:00
|
|
|
#endif
|
2013-04-17 02:45:04 +08:00
|
|
|
|
2013-03-25 00:50:49 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-17 02:45:04 +08:00
|
|
|
do {
|
|
|
|
|
2013-12-29 02:29:23 +08:00
|
|
|
#ifdef ENABLE_DECODE
|
2013-04-17 02:45:04 +08:00
|
|
|
// Initialise libsigrokdecode
|
|
|
|
if (srd_init(NULL) != SRD_OK) {
|
|
|
|
qDebug() << "ERROR: libsigrokdecode init failed.";
|
|
|
|
break;
|
|
|
|
}
|
2012-11-02 08:11:21 +08:00
|
|
|
|
|
|
|
// Load the protocol decoders
|
|
|
|
srd_decoder_load_all();
|
2013-12-29 02:29:23 +08:00
|
|
|
#endif
|
2012-11-02 08:11:21 +08:00
|
|
|
|
2013-04-28 04:53:21 +08:00
|
|
|
try {
|
|
|
|
// Create the device manager, initialise the drivers
|
|
|
|
pv::DeviceManager device_manager(sr_ctx);
|
2012-05-11 16:48:50 +08:00
|
|
|
|
2012-11-02 08:11:21 +08:00
|
|
|
// Initialise the main window
|
2013-04-28 04:53:21 +08:00
|
|
|
pv::MainWindow w(device_manager, open_file);
|
2012-11-02 08:11:21 +08:00
|
|
|
w.show();
|
2012-05-11 16:48:50 +08:00
|
|
|
|
2013-04-19 04:17:47 +08:00
|
|
|
#ifdef ENABLE_SIGNALS
|
2013-03-31 17:45:44 +08:00
|
|
|
if(SignalHandler::prepare_signals()) {
|
|
|
|
SignalHandler *const handler =
|
2013-03-31 17:31:51 +08:00
|
|
|
new SignalHandler(&w);
|
2013-03-31 17:45:44 +08:00
|
|
|
QObject::connect(handler,
|
|
|
|
SIGNAL(int_received()),
|
2013-03-31 17:31:51 +08:00
|
|
|
&w, SLOT(close()));
|
2013-03-31 17:45:44 +08:00
|
|
|
QObject::connect(handler,
|
|
|
|
SIGNAL(term_received()),
|
2013-03-31 17:31:51 +08:00
|
|
|
&w, SLOT(close()));
|
|
|
|
} else {
|
|
|
|
qWarning() <<
|
|
|
|
"Could not prepare signal handler.";
|
|
|
|
}
|
2013-04-19 04:17:47 +08:00
|
|
|
#endif
|
2013-03-31 17:31:51 +08:00
|
|
|
|
2012-11-02 08:11:21 +08:00
|
|
|
// Run the application
|
|
|
|
ret = a.exec();
|
2013-04-28 04:53:21 +08:00
|
|
|
|
|
|
|
} catch(std::exception e) {
|
|
|
|
qDebug() << e.what();
|
2012-06-28 05:36:23 +08:00
|
|
|
}
|
|
|
|
|
2013-12-29 02:29:23 +08:00
|
|
|
#ifdef ENABLE_DECODE
|
2013-04-17 02:45:04 +08:00
|
|
|
// Destroy libsigrokdecode
|
2012-11-02 08:11:21 +08:00
|
|
|
srd_exit();
|
2013-12-29 02:29:23 +08:00
|
|
|
#endif
|
2012-05-11 16:48:50 +08:00
|
|
|
|
2013-04-17 02:45:04 +08:00
|
|
|
} while (0);
|
2012-05-11 16:48:50 +08:00
|
|
|
|
2013-04-17 02:45:04 +08:00
|
|
|
// Destroy libsigrok
|
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
|
|
|
}
|