14 #include "branding/branding.h"
16 #include "rc_genicam_api/system.h"
17 #include "rc_genicam_api/interface.h"
19 #include "check_calib.h"
20 #include "check_license.h"
23 #include <rclic/verify.h>
25 #include <Fl/fl_ask.H>
32 bool isSupportedCamera(
const std::shared_ptr<rcg::Device> &dev,
const char *vendor_model[])
35 for (
size_t i=0; !found && vendor_model[i] != 0; i+=2)
37 found=(dev->getVendor() == vendor_model[i] &&
38 dev->getModel().compare(0, strlen(vendor_model[i+1]), vendor_model[i+1]) == 0);
47 Fl_Text_Buffer *buffer, std::atomic_bool &running)
54 const char *vendor_model[]=
56 "MATRIX VISION GmbH",
"mvBlueCOUGAR",
57 "MATRIX VISION GmbH",
"mvBlueFOX3",
58 "Basler",
"a2A2448-23gcBAS",
59 "Basler",
"a2A2448-23gmBAS",
63 std::vector<std::shared_ptr<rcg::Device> > devices;
64 bool multiple_interfaces=
false;
66 for (
size_t i=0; i<ilist.size() && !multiple_interfaces; i++)
71 std::vector<std::shared_ptr<rcg::Device> > list=ilist[i]->getDevices();
73 for (
size_t k=0; k<list.size() && !multiple_interfaces; k++)
75 if (isSupportedCamera(list[k], vendor_model))
80 std::string sn=list[k]->getSerialNumber();
81 for (
size_t j=0; j<devices.size(); j++)
83 if (devices[j]->getSerialNumber() == sn)
85 multiple_interfaces=
true;
90 devices.push_back(list[k]);
94 catch (
const std::exception &ex)
96 std::ostringstream out;
99 fl_alert(
"%s", ex.what());
107 if (multiple_interfaces)
109 std::ostringstream out;
111 out <<
"Found cameras with identical serial numbers. This indicates that ";
112 out <<
"cameras can be reached through different network interfaces, e.g. ";
113 out <<
"LAN and WLAN. Please ensure that cameras are only visible through ";
114 out <<
"one interface, e.g. by turning off WLAN, and try again.";
117 buffer->text(out.str().c_str());
125 bool misconfigured=
false;
126 std::vector<std::shared_ptr<rcg::Device> > all=devices;
128 for (
size_t i=0; i<all.size(); i++)
133 lname=all[i]->getUserDefinedName();
134 if (lname.size() == 0) lname=all[i]->getDisplayName();
137 if (lname.size() >= 1 && lname.back() ==
'L')
139 for (
size_t k=0; k<all.size(); k++)
144 rname=all[k]->getUserDefinedName();
145 if (rname.size() == 0) rname=all[k]->getDisplayName();
148 if (lname.size() == rname.size() && rname.back() ==
'R' &&
149 lname.compare(0, lname.size()-1, rname, 0, lname.size()-1) == 0)
153 if (all[i]->getModel() == all[k]->getModel())
158 for (
size_t j=0; !found && j<all.size(); j++)
160 if (all[j] && j != i && j != k)
162 std::string name=all[j]->getUserDefinedName();
163 if (name.size() == 0) name=all[j]->getDisplayName();
165 if (name == lname || name == rname)
176 std::shared_ptr<gutil::Properties> calib;
178 std::string snleft=all[i]->getSerialNumber();
179 std::string snright=all[k]->getSerialNumber();
180 std::string calib_status=getCalibrationStatus(calib, all[i]);
181 std::string license_status=getLicenseStatus(all[i], all[k]);
184 list->
add(lname.substr(0, lname.size()-1).c_str(),
185 snleft.c_str(), snright.c_str(), calib_status.c_str(),
186 license_status.c_str(), all[i], all[k], calib);
189 if ((calib_status !=
"ok" && calib_status !=
"no access") ||
190 (license_status !=
"ok" && license_status !=
"no access"))
192 if ((calib_status ==
"no access" || calib_status ==
"no nodemap") &&
193 (license_status ==
"no access" || license_status ==
"no nodemap"))
210 std::ostringstream out;
211 out <<
"Error: Cameras " << lname <<
" (" << all[i]->getSerialNumber() <<
212 ") and " << rname <<
" (" << all[k]->getSerialNumber() <<
213 " would match by name, but names are not unique!\n\n";
216 buffer->text(out.str().c_str());
222 std::ostringstream out;
223 out <<
"Error: Cameras " << lname <<
" (" << all[i]->getSerialNumber() <<
224 ") and " << rname <<
" (" << all[k]->getSerialNumber() <<
225 " would match by name, but have different model!\n\n";
228 buffer->text(out.str().c_str());
238 bool wrong_name=
false;
240 for (
size_t k=0; k<all.size(); k++)
247 std::string lsn=getLeftSNFromLicense(all[k]);
253 for (
size_t i=0; i<all.size(); i++)
255 if (all[i] && i != k && all[i]->getSerialNumber() == lsn)
259 std::shared_ptr<gutil::Properties> calib;
261 std::string snleft=all[i]->getSerialNumber();
262 std::string snright=all[k]->getSerialNumber();
263 std::string calibration_status=getCalibrationStatus(calib, all[i]);
266 list->
add(
"?", snleft.c_str(), snright.c_str(),
267 calibration_status.c_str(),
"ok", all[i], all[k], calib);
270 if (calibration_status !=
"ok")
272 if (calibration_status ==
"no access" || calibration_status ==
"no nodemap")
300 while (i < all.size())
308 all.erase(all.begin()+i);
317 std::ostringstream out;
319 out <<
"Misconfigured " RC_VISCORE_NAME
". Request factory backup file from Roboception\n";
320 out <<
"and choose 'Reset from file ...' in menu.\n\n";
323 buffer->text(out.str().c_str());
330 buffer->text(
"Select " RC_VISCORE_NAME
" with name '?' and press 'Reset Name'\n\n");
336 std::ostringstream out;
338 out <<
"Cannot access cameras. Please ensure that they are not used by any\n";
339 out <<
"other application.\n\n";
342 buffer->text(out.str().c_str());
348 std::ostringstream out;
352 out <<
"The following camera may belong to an " RC_VISCORE_NAME
", but only one\n";
353 out <<
"is visible. Check network connection and configuration (see\n";
354 out <<
"troubleshooting section of the manual).\n\n";
358 out <<
"The following cameras may belong to an " RC_VISCORE_NAME
". Check on the label of\n";
359 out <<
"the " RC_VISCORE_NAME
" if both serial numbers are listed below. If not, check\n";
360 out <<
"network connection and configuration (see troubleshooting section of the\n";
361 out <<
"manual). If the serial numbers of both cameras are listed, request a\n";
362 out <<
"backup file from Roboception and choose 'Reset from file ...' in menu.\n";
366 for (
size_t i=0; i<all.size(); i++)
368 out << all[i]->getSerialNumber() <<
"\n";
372 buffer->text(out.str().c_str());
376 if (!misconfigured && !noaccess && !wrong_name && all.size() == 0)
378 if (devices.size() > 0)
381 buffer->text(
"All discovered " RC_VISCORE_NAME
" are ok.\n");
386 std::ostringstream out;
387 out <<
"No " RC_VISCORE_NAME
" connected.\n\n";
388 out <<
"Check connection and network settings of cameras with other tools.\n";
391 buffer->text(out.str().c_str());
399 for (
size_t i=0; i<ilist.size(); i++)
407 fl_alert(
"Unknown exception in discover function!");
424 ldev->open(rcg::Device::CONTROL);
425 rdev->open(rcg::Device::CONTROL);
427 resetNames(ldev->getRemoteNodeMap(), rdev->getRemoteNodeMap());
429 catch (
const std::exception &ex)
432 fl_alert(
"%s", ex.what());
438 if (ldev) ldev->close();
439 if (rdev) rdev->close();
444 fl_alert(
"Unknown exception in reset name function!");
454 std::atomic_bool &running)
462 ldev->open(rcg::Device::CONTROL);
463 rdev->open(rcg::Device::CONTROL);
465 std::shared_ptr<GenApi::CNodeMapRef> lmap=ldev->getRemoteNodeMap();
466 std::shared_ptr<GenApi::CNodeMapRef> rmap=rdev->getRemoteNodeMap();
470 std::string calib=rcg::loadFile(lmap, getUserFileName(lmap).c_str(),
true);
471 std::string license=rcg::loadFile(rmap, getUserFileName(rmap).c_str(),
true);
476 out.exceptions(std::ifstream::failbit | std::ifstream::badbit);
478 out.open(backup_file);
482 if (calib.size() > 0 && calib[calib.size()-1] !=
'\n')
487 out <<
"====================\n";
495 fl_message(
"Backup of " RC_VISCORE_NAME
" successfully stored!");
498 catch (
const std::exception &ex)
501 fl_alert(
"Error '%s'", ex.what());
507 if (ldev) ldev->close();
508 if (rdev) rdev->close();
513 fl_alert(
"Unknown exception in update worker!");
521 const char *backup_file, std::atomic_bool &running)
532 in.exceptions(std::ifstream::failbit | std::ifstream::badbit);
534 in.open(backup_file);
535 std::ostringstream out;
539 catch (
const std::exception &ex)
542 fl_alert(
"Cannot open file '%s'", backup_file);
553 for (
size_t i=0; i<all.size(); i++)
562 else if (all[i] !=
'=')
567 else if (all[i] ==
'\n' && i < all.size() && all[i+1] ==
'=')
576 fl_alert(
"Invalid " RC_VISCORE_NAME
" backup file '%s'", backup_file);
585 std::string calib=all.substr(0, i1);
586 std::string license=all.substr(i2+1);
595 rcl::Verify verify(license);
596 std::string licdata=verify.verify();
598 std::istringstream in(licdata);
603 std::getline(in, line);
605 if (line.compare(0, 6,
"extra=") == 0 && line.size() > 16)
607 if (line.compare(line.size()-10, 10,
",type=left") == 0)
609 snleft=line.substr(6, line.size()-6-10);
611 else if (line.compare(line.size()-11, 11,
",type=right") == 0)
613 snright=line.substr(6, line.size()-6-11);
618 catch (
const std::exception &ex)
621 fl_alert(
"Invalid " RC_VISCORE_NAME
" backup file '%s': %s", backup_file, ex.what());
632 std::shared_ptr<rcg::Device> ldev;
633 std::shared_ptr<rcg::Device> rdev;
637 for (
size_t i=0; i<ilist.size(); i++)
639 if (!ldev) ldev=ilist[i]->getDevice(snleft.c_str());
640 if (!rdev) rdev=ilist[i]->getDevice(snright.c_str());
647 ldev->open(rcg::Device::CONTROL);
648 rdev->open(rcg::Device::CONTROL);
650 std::shared_ptr<GenApi::CNodeMapRef> lmap=ldev->getRemoteNodeMap();
651 std::shared_ptr<GenApi::CNodeMapRef> rmap=rdev->getRemoteNodeMap();
655 resetNames(lmap, rmap);
659 rcg::saveFile(lmap, getUserFileName(lmap).c_str(), calib,
true);
663 rcg::saveFile(rmap, getUserFileName(rmap).c_str(), license,
true);
668 fl_message(RC_VISCORE_NAME
" successfully reset to factory defaults. You must check calibration before working with this camera!");
674 fl_alert(
"Cannot find devices '%s' and '%s'", snleft.c_str(), snright.c_str());
678 catch (
const std::exception &ex)
681 fl_alert(
"Error '%s'", ex.what());
687 if (ldev) ldev->close();
688 if (rdev) rdev->close();
693 fl_alert(
"Unknown exception in update worker!");
703 std::atomic_bool &running)
711 ldev->open(rcg::Device::CONTROL);
713 std::shared_ptr<GenApi::CNodeMapRef> lmap=ldev->getRemoteNodeMap();
717 std::ostringstream calibdata;
718 calib->save(calibdata);
722 rcg::saveFile(lmap, getUserFileName(lmap).c_str(), calibdata.str(),
true);
727 fl_message(
"Data stored successfully.");
730 catch (
const std::exception &ex)
733 fl_alert(
"Error '%s'", ex.what());
739 if (ldev) ldev->close();
744 fl_alert(
"Unknown exception in set calibration worker!");