30 #include <libsigrokcxx/libsigrokcxx.hpp> 32 #include <QApplication> 35 #include <QProgressDialog> 37 #include <boost/filesystem.hpp> 45 using std::placeholders::_1;
46 using std::placeholders::_2;
47 using std::shared_ptr;
49 using std::unique_ptr;
52 using Glib::VariantBase;
54 using sigrok::ConfigKey;
55 using sigrok::Context;
61 std::string driver,
bool do_scan) :
65 QObject::tr(
"Cancel"), 0, context->drivers().size() + 1));
66 progress->setWindowModality(Qt::WindowModal);
67 progress->setMinimumDuration(1);
76 std::string user_name;
77 vector<std::string> user_opts;
78 if (!driver.empty()) {
80 user_name = user_opts.front();
81 user_opts.erase(user_opts.begin());
88 for (
auto& entry : context->drivers()) {
96 progress->setLabelText(QObject::tr(
"Scanning for devices that driver %1 can access...")
97 .arg(QString::fromStdString(entry.first)));
99 if (entry.first == user_name)
101 driver_scan(entry.second, map<const ConfigKey *, VariantBase>());
103 progress->setValue(entry_num++);
104 QApplication::processEvents();
105 if (progress->wasCanceled())
118 if (!driver.empty()) {
119 shared_ptr<sigrok::Driver> scan_drv;
120 map<const ConfigKey *, VariantBase> scan_opts;
125 map<string, shared_ptr<Driver>> drivers = context->drivers();
126 auto entry = drivers.find(user_name);
127 scan_drv = (entry != drivers.end()) ? entry->second :
nullptr;
133 if (scan_drv && !user_opts.empty()) {
134 auto drv_opts = scan_drv->scan_options();
142 list< shared_ptr<devices::HardwareDevice> > found;
149 progress->setValue(entry_num++);
162 const list< shared_ptr<devices::HardwareDevice> >&
171 shared_ptr<devices::HardwareDevice>
185 map<const ConfigKey *, Glib::VariantBase>
187 set<const ConfigKey *> driver_opts)
189 map<const ConfigKey *, Glib::VariantBase> result;
191 for (
auto& entry : user_spec) {
197 size_t pos = entry.find(
"=");
198 if (pos == std::string::npos) {
202 key = entry.substr(0, pos);
203 val = entry.substr(pos + 1);
211 const ConfigKey *cfg;
213 cfg = ConfigKey::get_by_identifier(key);
216 if (driver_opts.find(cfg) == driver_opts.end())
221 result[cfg] = cfg->parse_string(val);
235 const auto keys = driver->config_keys();
237 return keys.count(ConfigKey::LOGIC_ANALYZER) | keys.count(ConfigKey::OSCILLOSCOPE);
240 list< shared_ptr<devices::HardwareDevice> >
242 shared_ptr<Driver> driver, map<const ConfigKey *, VariantBase> drvopts)
244 list< shared_ptr<devices::HardwareDevice> > driver_devices;
249 return driver_devices;
253 devices_.remove_if([&](shared_ptr<devices::HardwareDevice> device) {
254 return device->hardware_device()->driver() == driver; });
258 auto devices = driver->scan(drvopts);
261 for (shared_ptr<sigrok::HardwareDevice>& device :
devices) {
262 const shared_ptr<devices::HardwareDevice> d(
264 driver_devices.push_back(d);
268 driver_devices.end());
270 driver_devices.sort(bind(
273 }
catch (
const sigrok::Error &
e) {
274 qWarning() << QApplication::tr(
"Error when scanning device driver '%1': %2").
275 arg(QString::fromStdString(driver->name()), e.what());
278 return driver_devices;
282 shared_ptr<devices::Device> device)
284 map<string, string> result;
288 const shared_ptr<sigrok::Device> sr_dev = device->device();
289 if (sr_dev->vendor().length() > 0)
290 result[
"vendor"] = sr_dev->vendor();
291 if (sr_dev->model().length() > 0)
292 result[
"model"] = sr_dev->model();
293 if (sr_dev->version().length() > 0)
294 result[
"version"] = sr_dev->version();
295 if (sr_dev->serial_number().length() > 0)
296 result[
"serial_num"] = sr_dev->serial_number();
297 if (sr_dev->connection_id().length() > 0)
298 result[
"connection_id"] = sr_dev->connection_id();
304 const map<string, string> search_info)
306 shared_ptr<devices::HardwareDevice> last_resort_dev;
307 map<string, string> dev_info;
309 for (shared_ptr<devices::HardwareDevice> dev :
devices_) {
314 if (dev_info.count(
"vendor") > 0 && search_info.count(
"vendor") > 0)
315 if (dev_info.at(
"vendor") != search_info.at(
"vendor"))
318 if (dev_info.count(
"model") > 0 && search_info.count(
"model") > 0)
319 if (dev_info.at(
"model") != search_info.at(
"model"))
323 if ((dev_info.count(
"serial_num") > 0) && (dev_info.at(
"serial_num") !=
"0")
324 && search_info.count(
"serial_num") > 0)
325 if (dev_info.at(
"serial_num") == search_info.at(
"serial_num") &&
326 dev_info.at(
"serial_num") !=
"0")
330 if (dev_info.count(
"connection_id") > 0 &&
331 search_info.count(
"connection_id") > 0)
332 if (dev_info.at(
"connection_id") == search_info.at(
"connection_id"))
336 if (dev_info.count(
"version") > 0 &&
337 search_info.count(
"version") > 0)
338 if (dev_info.at(
"version") == search_info.at(
"version") &&
339 dev_info.at(
"version") !=
"0")
343 last_resort_dev = dev;
351 return last_resort_dev;
355 shared_ptr<devices::Device> b)
359 return a->display_name(*this).compare(b->display_name(*
this)) < 0;
manual pdf if(NOT EXISTS"${CMAKE_CURRENT_BINARY_DIR}/images") message(STATUS"creating symlink for manual's images/ subdirectory") execute_process(COMMAND $
shared_ptr< devices::HardwareDevice > user_spec_device_
bool compare_devices(shared_ptr< devices::Device > a, shared_ptr< devices::Device > b)
const shared_ptr< devices::HardwareDevice > find_device_from_info(const map< string, string > search_info)
list< shared_ptr< devices::HardwareDevice > > devices_
const shared_ptr< sigrok::Context > & context() const
const list< shared_ptr< devices::HardwareDevice > > & devices() const
DeviceManager(shared_ptr< sigrok::Context > context, std::string driver, bool do_scan)
const map< string, string > get_device_info(const shared_ptr< devices::Device > device)
vector< string > split_string(string text, string separator)
static map< const ConfigKey *, Glib::VariantBase > drive_scan_options(vector< string > user_spec, set< const ConfigKey * > driver_opts)
shared_ptr< sigrok::Context > context_
list< shared_ptr< devices::HardwareDevice > > driver_scan(shared_ptr< sigrok::Driver > driver, map< const sigrok::ConfigKey *, Glib::VariantBase > drvopts)
bool driver_supported(shared_ptr< sigrok::Driver > driver) const
shared_ptr< devices::HardwareDevice > user_spec_device() const