2 * This file is part of the SmuView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5 * Copyright (C) 2017-2021 Frank Stettner <frank-stettner@gmx.net>
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include <libsigrokcxx/libsigrokcxx.hpp>
32 #include "src/application.hpp"
33 #include "src/devicemanager.hpp"
34 #include "src/session.hpp"
35 #include "src/settingsmanager.hpp"
36 #include "src/mainwindow.hpp"
37 #include "src/ui/tabs/smuscripttab.hpp"
40 #include "signalhandler.hpp"
45 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin
)
46 Q_IMPORT_PLUGIN(QSvgPlugin
)
50 using std::make_shared
;
51 using std::shared_ptr
;
59 " %s [OPTIONS] [FILE]\n"
62 " -h, -?, --help Show help option\n"
64 "Application Options:\n"
65 " -V, --version Show release version\n"
66 " -l, --loglevel Set libsigrok loglevel (0-5, default: 2)\n"
67 " -d, --driver Specify the device driver(s) to use\n"
68 " -D, --dont-scan Don't auto-scan for devices, use -d spec only\n"
69 " -s, --script Specify the SmuScript to load and execute\n"
70 " -c, --clean Don't restore previous settings on startup\n"
71 /* Disable cmd line options i and I
72 " -i, --input-file Load input from file\n"
73 " -I, --input-format Input format\n"
77 " %s --driver tecpel-dmm-8061-ser:conn=/dev/ttyUSB0\n"
79 " %s --driver uni-t-ut61e:conn=1a86.e008\n"
81 " %s --driver voltcraft-k204:conn=/dev/ttyUSB0 \\\n"
82 " --driver uni-t-ut61d:conn=1a86.e008 \\\n"
83 " --driver uni-t-ut61e-ser:conn=/dev/ttyUSB1\n",
84 SV_BIN_NAME
, SV_BIN_NAME
, SV_BIN_NAME
, SV_BIN_NAME
);
87 int main(int argc
, char *argv
[])
90 shared_ptr
<sigrok::Context
> context
;
92 vector
<string
> drivers
;
94 //string open_file_format;
97 bool restore_settings
= true;
99 Application
app(argc
, argv
);
103 static const struct option long_options
[] = {
104 { "help", no_argument
, nullptr, 'h' },
105 { "version", no_argument
, nullptr, 'V' },
106 { "loglevel", required_argument
, nullptr, 'l' },
107 { "driver", required_argument
, nullptr, 'd' },
108 { "dont-scan", no_argument
, nullptr, 'D' },
109 { "script", required_argument
, nullptr, 's' },
110 { "clean", no_argument
, nullptr, 'c' },
111 /* Disable cmd line options i and I
112 { "input-file", required_argument, nullptr, 'i' },
113 { "input-format", required_argument, nullptr, 'I' },
115 { nullptr, 0, nullptr, 0 }
118 /* Disable cmd line options i and I
119 const int c = getopt_long(argc, argv,
120 "l:Vhc?d:i:I:", long_options, nullptr);
122 const int c
= getopt_long(argc
, argv
,
123 "h?VDl:d:s:c", long_options
, nullptr);
135 // Print version info
136 fprintf(stdout
, "%s %s\n", SV_TITLE
, SV_VERSION_STRING
);
141 loglevel
= atoi(optarg
);
143 const QSettings settings
;
144 qDebug() << "Settings:" << settings
.fileName()
145 << "format" << settings
.format();
151 drivers
.push_back(optarg
);
159 script_file
= optarg
;
163 restore_settings
= false;
166 /* Disable cmd line options i and I
172 open_file_format = optarg;
178 /* Disable cmd line options i and I
179 if (argc - optind > 1) {
180 fprintf(stderr, "Only one file can be opened.\n");
184 if (argc - optind == 1)
185 open_file = argv[argc - 1];
188 // Initialise libsigrok
189 context
= sigrok::Context::create();
190 sv::Session::sr_context
= context
;
195 context
->set_log_level(sigrok::LogLevel::get(loglevel
));
197 sv::SettingsManager::set_restore_settings(restore_settings
);
199 // Initialize global start timestamp
200 // TODO: use std::chrono / std::time
201 sv::Session::session_start_timestamp
=
202 (double)QDateTime::currentMSecsSinceEpoch() / (double)1000;
204 // Create the device manager, initialise the drivers
205 sv::DeviceManager
device_manager(context
, drivers
, do_scan
);
207 // Initialise the session.
208 auto session
= make_shared
<sv::Session
>(device_manager
);
210 // Initialise the main window.
211 sv::MainWindow
w(device_manager
, session
);
214 if (!script_file
.empty())
215 w
.add_smuscript_tab(script_file
)->run_script();
217 #ifdef ENABLE_SIGNALS
218 if (SignalHandler::prepare_signals()) {
219 SignalHandler
*const handler
=
220 new SignalHandler(&w
);
221 QObject::connect(handler
,
222 SIGNAL(int_received()),
224 QObject::connect(handler
,
225 SIGNAL(term_received()),
229 qWarning() << "Could not prepare signal handler.";
233 // Run the application
234 ret
= Application::exec();
236 catch (exception
&e
) {
237 qCritical() << "main() failed: " << e
.what();