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
|
2016-10-20 15:53:43 +08:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2012-09-03 20:20:51 +08:00
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2017-03-19 03:01:54 +08:00
|
|
|
#include <cstdint>
|
2015-01-18 02:29:12 +08:00
|
|
|
#include <libsigrokcxx/libsigrokcxx.hpp>
|
2012-05-11 16:48:50 +08:00
|
|
|
|
2012-10-13 07:59:37 +08:00
|
|
|
#include <getopt.h>
|
|
|
|
|
2012-05-11 16:48:50 +08:00
|
|
|
#include <QDebug>
|
2017-05-10 04:08:59 +08:00
|
|
|
#include <QSettings>
|
2012-10-13 04:38:06 +08:00
|
|
|
|
2013-04-19 04:17:47 +08:00
|
|
|
#ifdef ENABLE_SIGNALS
|
2014-11-22 16:53:27 +08:00
|
|
|
#include "signalhandler.hpp"
|
2013-04-19 04:17:47 +08:00
|
|
|
#endif
|
|
|
|
|
2014-11-22 16:53:27 +08:00
|
|
|
#include "pv/application.hpp"
|
|
|
|
#include "pv/devicemanager.hpp"
|
|
|
|
#include "pv/mainwindow.hpp"
|
2017-07-02 06:48:31 +08:00
|
|
|
#include "pv/session.hpp"
|
2014-07-16 22:45:48 +08:00
|
|
|
#ifdef ANDROID
|
2014-07-18 22:17:37 +08:00
|
|
|
#include <libsigrokandroidutils/libsigrokandroidutils.h>
|
2015-09-27 07:14:11 +08:00
|
|
|
#include "android/assetreader.hpp"
|
2014-11-22 16:53:27 +08:00
|
|
|
#include "android/loghandler.hpp"
|
2014-07-16 22:45:48 +08:00
|
|
|
#endif
|
2012-09-03 20:20:51 +08:00
|
|
|
|
2012-10-13 04:38:06 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2014-01-09 07:49:47 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <QtPlugin>
|
2017-01-30 02:36:59 +08:00
|
|
|
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
|
|
|
|
Q_IMPORT_PLUGIN(QSvgPlugin)
|
2014-01-09 07:49:47 +08:00
|
|
|
#endif
|
|
|
|
|
2017-03-16 06:16:05 +08:00
|
|
|
using std::exception;
|
|
|
|
using std::shared_ptr;
|
|
|
|
using std::string;
|
|
|
|
|
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"
|
2017-06-06 22:16:11 +08:00
|
|
|
" %s [OPTIONS] [FILE]\n"
|
2012-10-13 08:15:47 +08:00
|
|
|
"\n"
|
|
|
|
"Help Options:\n"
|
|
|
|
" -h, -?, --help Show help option\n"
|
2015-04-12 21:24:58 +08:00
|
|
|
"\n"
|
|
|
|
"Application Options:\n"
|
|
|
|
" -V, --version Show release version\n"
|
|
|
|
" -l, --loglevel Set libsigrok/libsigrokdecode loglevel\n"
|
2017-06-26 01:56:33 +08:00
|
|
|
" -d, --driver Specify the device driver to use\n"
|
2018-01-25 04:11:50 +08:00
|
|
|
" -D, --no-scan Don't auto-scan for devices, use -d spec only\n"
|
2015-04-12 22:08:51 +08:00
|
|
|
" -i, --input-file Load input from file\n"
|
|
|
|
" -I, --input-format Input format\n"
|
2017-06-06 22:14:54 +08:00
|
|
|
" -c, --clean Don't restore previous sessions on startup\n"
|
2017-06-06 22:16:11 +08:00
|
|
|
"\n", PV_BIN_NAME);
|
2012-10-13 08:15:47 +08:00
|
|
|
}
|
|
|
|
|
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;
|
2017-03-16 06:16:05 +08:00
|
|
|
shared_ptr<sigrok::Context> context;
|
2017-06-26 01:56:33 +08:00
|
|
|
string open_file, open_file_format, driver;
|
2017-06-06 22:14:54 +08:00
|
|
|
bool restore_sessions = true;
|
2018-01-25 04:11:50 +08:00
|
|
|
bool do_scan = true;
|
2012-10-22 07:12:52 +08:00
|
|
|
|
2014-09-06 21:15:08 +08:00
|
|
|
Application a(argc, argv);
|
2012-05-11 16:40:27 +08:00
|
|
|
|
2014-07-16 22:45:48 +08:00
|
|
|
#ifdef ANDROID
|
2014-07-18 22:17:37 +08:00
|
|
|
srau_init_environment();
|
2014-07-16 22:45:48 +08:00
|
|
|
pv::AndroidLogHandler::install_callbacks();
|
2015-09-27 07:14:11 +08:00
|
|
|
pv::AndroidAssetReader asset_reader;
|
2014-07-16 22:45:48 +08:00
|
|
|
#endif
|
|
|
|
|
2012-10-13 07:59:37 +08:00
|
|
|
// Parse arguments
|
2017-03-19 03:01:54 +08:00
|
|
|
while (true) {
|
2012-10-13 07:59:37 +08:00
|
|
|
static const struct option long_options[] = {
|
2016-02-09 04:17:34 +08:00
|
|
|
{"help", no_argument, nullptr, 'h'},
|
|
|
|
{"version", no_argument, nullptr, 'V'},
|
|
|
|
{"loglevel", required_argument, nullptr, 'l'},
|
2017-06-26 01:56:33 +08:00
|
|
|
{"driver", required_argument, nullptr, 'd'},
|
2016-02-09 04:17:34 +08:00
|
|
|
{"input-file", required_argument, nullptr, 'i'},
|
|
|
|
{"input-format", required_argument, nullptr, 'I'},
|
2017-06-06 22:14:54 +08:00
|
|
|
{"clean", no_argument, nullptr, 'c'},
|
2016-02-09 04:17:34 +08:00
|
|
|
{nullptr, 0, nullptr, 0}
|
2012-10-13 07:59:37 +08:00
|
|
|
};
|
|
|
|
|
2013-03-08 07:51:08 +08:00
|
|
|
const int c = getopt_long(argc, argv,
|
2018-01-25 04:11:50 +08:00
|
|
|
"l:Vhc?d:Di:I:", long_options, nullptr);
|
2012-10-13 07:59:37 +08:00
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (c) {
|
2015-04-12 21:24:58 +08:00
|
|
|
case 'h':
|
|
|
|
case '?':
|
|
|
|
usage();
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case 'V':
|
|
|
|
// Print version info
|
|
|
|
fprintf(stdout, "%s %s\n", PV_TITLE, PV_VERSION_STRING);
|
|
|
|
return 0;
|
|
|
|
|
2013-03-25 00:50:49 +08:00
|
|
|
case 'l':
|
|
|
|
{
|
|
|
|
const int loglevel = atoi(optarg);
|
2018-01-03 05:13:06 +08:00
|
|
|
if (loglevel < 0 || loglevel > 5) {
|
|
|
|
qDebug() << "ERROR: invalid log level spec.";
|
|
|
|
break;
|
|
|
|
}
|
2014-10-15 08:04:55 +08:00
|
|
|
context->set_log_level(sigrok::LogLevel::get(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
|
|
|
|
2017-05-10 04:08:59 +08:00
|
|
|
if (loglevel >= 5) {
|
|
|
|
const QSettings settings;
|
|
|
|
qDebug() << "Settings:" << settings.fileName()
|
|
|
|
<< "format" << settings.format();
|
|
|
|
}
|
2013-03-25 00:50:49 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-04-12 22:08:51 +08:00
|
|
|
|
2017-06-26 01:56:33 +08:00
|
|
|
case 'd':
|
|
|
|
driver = optarg;
|
|
|
|
break;
|
|
|
|
|
2018-01-25 04:11:50 +08:00
|
|
|
case 'D':
|
|
|
|
do_scan = false;
|
|
|
|
break;
|
|
|
|
|
2015-04-12 22:08:51 +08:00
|
|
|
case 'i':
|
|
|
|
open_file = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'I':
|
|
|
|
open_file_format = optarg;
|
|
|
|
break;
|
2017-06-06 22:14:54 +08:00
|
|
|
|
|
|
|
case 'c':
|
|
|
|
restore_sessions = false;
|
|
|
|
break;
|
2012-10-13 07:59:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-21 21:23:58 +08:00
|
|
|
if (argc - optind > 1) {
|
2016-01-04 03:40:27 +08:00
|
|
|
fprintf(stderr, "Only one file can be opened.\n");
|
2013-03-03 17:06:44 +08:00
|
|
|
return 1;
|
2015-04-12 22:08:51 +08:00
|
|
|
}
|
2013-03-03 17:06:44 +08:00
|
|
|
|
2017-03-19 07:20:26 +08:00
|
|
|
if (argc - optind == 1)
|
|
|
|
open_file = argv[argc - 1];
|
|
|
|
|
2012-10-13 07:13:44 +08:00
|
|
|
// Initialise libsigrok
|
2014-10-15 08:04:55 +08:00
|
|
|
context = sigrok::Context::create();
|
2017-07-02 06:48:31 +08:00
|
|
|
pv::Session::sr_context = context;
|
|
|
|
|
2015-09-27 07:14:11 +08:00
|
|
|
#ifdef ANDROID
|
|
|
|
context->set_resource_reader(&asset_reader);
|
|
|
|
#endif
|
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
|
2015-04-12 22:54:29 +08:00
|
|
|
if (srd_init(nullptr) != SRD_OK) {
|
2013-04-17 02:45:04 +08:00
|
|
|
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
|
2018-01-25 04:11:50 +08:00
|
|
|
pv::DeviceManager device_manager(context, driver, do_scan);
|
2012-05-11 16:48:50 +08:00
|
|
|
|
2012-11-02 08:11:21 +08:00
|
|
|
// Initialise the main window
|
2017-06-10 03:57:21 +08:00
|
|
|
pv::MainWindow w(device_manager);
|
2012-11-02 08:11:21 +08:00
|
|
|
w.show();
|
2012-05-11 16:48:50 +08:00
|
|
|
|
2017-06-10 03:57:21 +08:00
|
|
|
if (restore_sessions)
|
|
|
|
w.restore_sessions();
|
|
|
|
|
|
|
|
if (!open_file.empty())
|
|
|
|
w.add_session_with_file(open_file, open_file_format);
|
|
|
|
else
|
|
|
|
w.add_default_session();
|
|
|
|
|
2013-04-19 04:17:47 +08:00
|
|
|
#ifdef ENABLE_SIGNALS
|
2015-07-26 00:05:11 +08:00
|
|
|
if (SignalHandler::prepare_signals()) {
|
2013-03-31 17:45:44 +08:00
|
|
|
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()));
|
2014-11-29 20:15:57 +08:00
|
|
|
} else {
|
2013-03-31 17:31:51 +08:00
|
|
|
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
|
|
|
|
2017-03-16 06:16:05 +08:00
|
|
|
} catch (exception e) {
|
2013-04-28 04:53:21 +08:00
|
|
|
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
|
|
|
|
2017-03-19 03:01:54 +08:00
|
|
|
} while (false);
|
2012-05-11 16:48:50 +08:00
|
|
|
|
|
|
|
return ret;
|
2012-09-03 20:20:51 +08:00
|
|
|
}
|