iCub-main
Loading...
Searching...
No Matches
mainwindow.cpp
Go to the documentation of this file.
1#include "mainwindow.h"
2#include "changeinfodialog.h"
4#include "ui_mainwindow.h"
5#include <qdebug.h>
6#include <QCheckBox>
7#include <QtConcurrent/QtConcurrent>
8#include <QFileDialog>
9#include <QMessageBox>
10#include <QToolButton>
11#include "straincalibgui.h"
12
13MainWindow::MainWindow(FirmwareUpdaterCore *core, bool adminMode, QWidget *parent) :
14 QMainWindow(parent), /*mutex(QMutex::Recursive)*/
15 ui(new Ui::MainWindow)
16{
17 ui->setupUi(this);
18 //core->strainCalibMode = strainCalibMode;
19 qRegisterMetaType <QList<sBoard> > ("QList<sBoard>");
20 qRegisterMetaType <QVector<int> > ("QVector<int>");
21 qRegisterMetaType <boardInfo2_t> ("boardInfo2_t");
22 qRegisterMetaType <eOipv4addr_t> ("eOipv4addr_t");
23 qRegisterMetaType <sBoard> ("sBoard");
24 sgboardtype = icubCanProto_boardType__strain;
25 isLoading = false;
26 loadCounter = 0;
27 calibDlg = NULL;
28
29
30 QWidget *container = new QWidget(ui->statusBar);
31 QHBoxLayout *layout = new QHBoxLayout(container);
32 container->setLayout(layout);
33 container->setFixedHeight(40);
34 //container->setFixedWidth(300);
35
36
37 progress = new QProgressBar(container);
38 progress->setEnabled(false);
39 progress->setFixedWidth(100);
40 layout->addWidget(progress);
41
42 infoResult = new QLabel(container);
43 infoResult->setVisible(false);
44 layout->addWidget(infoResult);
45
46
47 QSpacerItem *spacer = new QSpacerItem(20,40,QSizePolicy::MinimumExpanding,QSizePolicy::Fixed);
48 layout->addSpacerItem(spacer);
49
50 ui->statusBar->addWidget(container,100);
51 //ui->statusBar->layout()->addWidget(container);
52// ui->splitter->setStretchFactor(0,80);
53// ui->splitter->setStretchFactor(0,20);
54
55 infoTreeWidget = new QTreeWidget(ui->groupBox_2);
56 infoTreeWidget->setVisible(false);
57 ui->groupBox_2->layout()->addWidget(infoTreeWidget);
58 ui->groupBox_2->setTitle("Board Properties");
59 infoTreeWidget->setColumnCount(2);
60 infoTreeWidget->setHeaderLabels(QStringList() << "Name" << "Value");
61 infoTreeWidget->addTopLevelItem(new QTreeWidgetItem(infoTreeWidget,QStringList() << "Board"));
62 infoTreeWidget->addTopLevelItem(new QTreeWidgetItem(infoTreeWidget,QStringList() << "Bootstrap Processes"));
63 infoTreeWidget->addTopLevelItem(new QTreeWidgetItem(infoTreeWidget,QStringList() << "Properties of the Processes"));
64
65
66 ui->checkBoxEE->setCheckState(Qt::Unchecked); //(Qt::Checked); Qt::Unchecked
67 ui->checkBoxEE->setEnabled(false);
68 //Qt::CheckState eestate = ui->checkBoxEE->checkState();
69
70
71 ui->actionSel->setIcon(QIcon(":/images/sel-bw.png"));
72 ui->actionDes->setIcon(QIcon(":/images/des-bw.png"));
73
74 //ui->actionSel->setText("SS");
75
76 connect(ui->actionSel, SIGNAL(triggered()), this, SLOT(onSel()));
77 connect(ui->actionDes, SIGNAL(triggered()), this, SLOT(onDes()));
78
79
80 this->core = core;
81
82 QList < QPair<QString,QVariant> > devices = core->getDevices();
83
84 //ui->devicesTree->setSelectionMode(QTreeWidget::MultiSelection);
85 for(int i=0;i<devices.count();i++){
86 int type = devices.at(i).first.contains("ETH") ? ETH_TREE_ROOT_NODE : CAN_TREE_ROOT_NODE;
87
88 QString dev = devices.at(i).first + "<" + devices.at(i).second.toString() + ">";
89 //CustomTreeWidgetItem *item = new CustomTreeWidgetItem(NULL,QStringList() << "" << devices.at(i).first << devices.at(i).second.toString(),-1,core,type);
90 CustomTreeWidgetItem *item = new CustomTreeWidgetItem(NULL,QStringList() << "" << dev << "",-1,core,type);
91 ui->devicesTree->addTopLevelItem(item);
92
93 QTreeWidgetItem *empty = new QTreeWidgetItem(item,QStringList() << "" << "" << "?");
94 empty->setData(0,EMPTY_NODE,true);
95
96 item->setTextColor(DEVICEID,QColor(Qt::red));
97 }
98 if(!adminMode){
99 ui->advancedGroup->setVisible(false);
100 ui->strainGroup->setVisible(false);
101 }
102
103// if(!strainCalibMode){
104
105// ui->btnStrainCalib->setVisible(false);
106// }else{
107// ui->strainGroup->setVisible(false);
108// ui->advancedGroup->setVisible(false);
109// ui->btnCahngeInfo->setVisible(false);
110// ui->btnUploadApp->setVisible(false);
111// }
112
113 connect(core,SIGNAL(updateProgress(float)),
114 this,SLOT(onUpdateProgressBar(float)),Qt::QueuedConnection);
115
116 connect(ui->devicesTree,SIGNAL(itemSelectionChanged()),
117 this,SLOT(onDeviceSelectionChanged()));
118 connect(this,SIGNAL(deviceSelectionChanged()),
119 this,SLOT(onDeviceSelectionChanged()),Qt::QueuedConnection);
120
121 connect(ui->devicesTree,SIGNAL(itemExpanded(QTreeWidgetItem*)),
122 this,SLOT(onDeviceExpanded(QTreeWidgetItem*)));
123
124 connect(this,SIGNAL(refreshCanBoardsFromEth(QTreeWidgetItem*)),
125 this,SLOT(onDeviceExpanded(QTreeWidgetItem*)),Qt::QueuedConnection);
126
127
128 connect(ui->connectButton,SIGNAL(clicked(bool)),
129 this,SLOT(onConnect()));
130
131 connect(this,SIGNAL(appendInfo(sBoard)),
132 this,SLOT(onAppendInfo(sBoard)),Qt::QueuedConnection);
133
134
135 connect(this,SIGNAL(appendInfo(QString)),
136 this,SLOT(onAppendInfo(QString)),Qt::QueuedConnection);
137
138 connect(this,SIGNAL(appendInfo(boardInfo2_t,eOipv4addr_t)),
139 this,SLOT(onAppendInfo(boardInfo2_t,eOipv4addr_t)),Qt::QueuedConnection);
140
141 connect(this,SIGNAL(canBoardsRetrieved(QTreeWidgetItem*,bool )),
142 this,SLOT(onCanBoardsRetrieved(QTreeWidgetItem*, bool)),Qt::QueuedConnection);
143
144 connect(this,SIGNAL(refreshEthBoardsNode(QTreeWidgetItem*,bool,bool)),
145 this,SLOT(populateEthBoardsNode(QTreeWidgetItem*,bool,bool)),Qt::QueuedConnection);
146
147 connect(this,SIGNAL(setInfoRes(QString)),
148 this,SLOT(onSetInfoRes(QString)),Qt::QueuedConnection);
149
150 connect(this,SIGNAL(needSetRestartOnSelected()),
151 this,SLOT(onNeedSetRestartOnSelected()),Qt::QueuedConnection);
152
153 connect(this,SIGNAL(needLoading(bool,bool,QString,bool)),
154 this,SLOT(loading(bool,bool,QString,bool)),Qt::QueuedConnection);
155
156 connect(ui->btnBlink,SIGNAL(clicked(bool)),this,SLOT(onBlinkPressed(bool)));
157 connect(ui->btnCahngeInfo,SIGNAL(clicked(bool)),this,SLOT(onChangeInfo(bool)));
158 connect(ui->btnChangeIp,SIGNAL(clicked(bool)),this,SLOT(onChangeAddress(bool)));
159 connect(ui->btnChangeCanAddr,SIGNAL(clicked(bool)),this,SLOT(onChangeAddress(bool)));
160 connect(ui->btnEraseApplication,SIGNAL(clicked(bool)),this,SLOT(onEraseApplication(bool)));
161 connect(ui->btnRestart,SIGNAL(clicked(bool)),this,SLOT(onRestartBoards(bool)));
162 //connect(ui->btnRestartSecs,SIGNAL(clicked(bool)),this,SLOT(onRestartBoards5Secs(bool)));
163 connect(ui->btnCalibrate,SIGNAL(clicked(bool)),this,SLOT(onCalibrate(bool)));
164 connect(ui->btnBootApp,SIGNAL(clicked(bool)),this,SLOT(onBootApplication(bool)));
165 connect(ui->btnBootUpdater,SIGNAL(clicked(bool)),this,SLOT(onBootUpdater(bool)));
166 connect(ui->btnUploadApp,SIGNAL(clicked(bool)),this,SLOT(onUploadApplication(bool)));
167 connect(ui->btnUploadLoader,SIGNAL(clicked(bool)),this,SLOT(onUploadLoader(bool)));
168 connect(ui->btnUploadUpdater,SIGNAL(clicked(bool)),this,SLOT(onUploadUpdater(bool)));
169 connect(ui->btnJumpUpdater,SIGNAL(clicked(bool)),this,SLOT(onJumpToUpdater(bool)));
170 connect(ui->btnGoToMaintenance,SIGNAL(clicked(bool)),this,SLOT(onGoToMaintenance(bool)));
171 connect(ui->btnGoToApplication,SIGNAL(clicked(bool)),this,SLOT(onGoToApplication(bool)));
172 connect(ui->btnEraseEeprom,SIGNAL(clicked(bool)),this,SLOT(onEraseEprom(bool)));
173 connect(ui->btnStrainCalib,SIGNAL(clicked(bool)),this,SLOT(onStrainCalib(bool)));
174 connect(&watcher, SIGNAL(finished()), this, SLOT(onFutureFinished()));
175
176 ui->devicesTree->sortItems(ADDRESS,Qt::AscendingOrder);
177}
178
180{
181 delete ui;
182}
183
184void MainWindow::onSel(void)
185{
186
187 if(selectedNodes.isEmpty())
188 {
189 return;
190 }
191
192#if 0
193 test che mette tutti a sel
194 for(int i=0;i<ui->devicesTree->topLevelItemCount();i++){
195 QTreeWidgetItem *topLevel = ui->devicesTree->topLevelItem(i);
196 for(int j=0;j<topLevel->childCount();j++){
197
198 QTreeWidgetItem *widgItem = topLevel->child(j);
199
200 if((widgItem->type() != ETH_TREE_ROOT_NODE) && (widgItem->type() != CAN_TREE_ROOT_NODE) && (widgItem->type() != QTreeWidgetItem::Type))
201 {
202 CustomTreeWidgetItem *child = (CustomTreeWidgetItem *)widgItem;
203 if(!child->isCheckSelected()){
204 if(child->type() == ETH_TREE_NODE){
205 child->setCheckSelected(true);
206 printf("sel-eth\n");
207 }
208 if(child->type() == CAN_TREE_NODE)
209 {
210 child->setCheckSelected(true);
211 printf("sel-can\n");
212 }
213 }
214 }
215 }
216 }
217#else
218
219 CustomTreeWidgetItem *c = selectedNodes.first();
220
221 QString targetboard = c->getBoardType();
222
223 if(true){
224
225 for(int i=0;i<ui->devicesTree->topLevelItemCount();i++){
226 QTreeWidgetItem *topLevel = ui->devicesTree->topLevelItem(i);
227 int mmm = topLevel->childCount();
228 for(int j=0;j<topLevel->childCount();j++){
229
230 QTreeWidgetItem *widgItem = topLevel->child(j);
231 if(widgItem->type() != QTreeWidgetItem::Type){
232 CustomTreeWidgetItem *child = (CustomTreeWidgetItem*)widgItem;
233 QString brd = child->getBoardType();
234 if(child->checkIsEnabled()){
235 if((child->getBoardType() == c->getBoardType()) && (c->getParentNode() == child->getParentNode())){
236 child->setCheckSelected(true);
237 }
238 }
239
240 int nnn = topLevel->child(j)->childCount();
241 for(int k=0; k<topLevel->child(j)->childCount();k++ ){
242 QTreeWidgetItem *widgItem1 = topLevel->child(j)->child(k);
243 if(widgItem1->type() != QTreeWidgetItem::Type){
244 CustomTreeWidgetItem *child1 = (CustomTreeWidgetItem*)widgItem1;
245
246 if(child1->checkIsEnabled()){
247 if((child1->getBoardType() == c->getBoardType()) && (c->getParentNode() == child1->getParentNode())){
248 child1->setCheckSelected(true);
249 }
250 }
251 }
252
253 }
254 }
255
256
257
258
259 }
260
261 }
262 }
263
264
265
266#endif
267
268// int size = selectedNodes.size();
269// for(int i=0;i<size;i++){
270
271// CustomTreeWidgetItem *child = selectedNodes[i];
272// if(child->isCheckSelected()){
273// if(child->type() == ETH_TREE_NODE){
274// child->setCheckSelected(false);
275// printf("des-eth\n");
276// }
277// if(child->type() == CAN_TREE_NODE)
278// {
279// child->setCheckSelected(false);
280// printf("des-can\n");
281// }
282// }
283// }
284
285 checkEnableButtons();
286}
287
288
289void MainWindow::onDes(void)
290{
291
292 if(selectedNodes.isEmpty())
293 {
294 return;
295 }
296
297// for(int i=0;i<ui->devicesTree->topLevelItemCount();i++){
298// QTreeWidgetItem *topLevel = ui->devicesTree->topLevelItem(i);
299// for(int j=0;j<topLevel->childCount();j++){
300
301// QTreeWidgetItem *widgItem = topLevel->child(j);
302// if(selectedNodes.first()->type() != widgItem->type())
303// {
304// continue;
305// }
306
307// if((widgItem->type() != ETH_TREE_ROOT_NODE) && (widgItem->type() != CAN_TREE_ROOT_NODE) && (widgItem->type() != QTreeWidgetItem::Type))
308// {
309// CustomTreeWidgetItem *child = (CustomTreeWidgetItem *)widgItem;
310// if(child->isCheckSelected()){
311// if(child->type() == ETH_TREE_NODE){
312// child->setCheckSelected(false);
313// printf("des-eth\n");
314// }
315// if(child->type() == CAN_TREE_NODE)
316// {
317// child->setCheckSelected(false);
318// printf("des-can\n");
319// }
320// }
321// }
322// }
323// }
324
325 int size = selectedNodes.size();
326 for(int i=0;i<size;i++){
327
328 CustomTreeWidgetItem *child = selectedNodes[i];
329 if(child->isCheckSelected()){
330 if(child->type() == ETH_TREE_NODE){
331 child->setCheckSelected(false);
332 //printf("des-eth\n");
333 }
334 if(child->type() == CAN_TREE_NODE)
335 {
336 child->setCheckSelected(false);
337 //printf("des-can\n");
338 }
339 }
340 }
341
342 checkEnableButtons();
343
344}
345
346void MainWindow::onUploadLoader(bool click)
347{
348 QString filename = QFileDialog::getOpenFileName(this,"Choose File",QDir::home().absolutePath());
349
350 if(filename.isEmpty()){
351 return;
352 }
353
354 QtConcurrent::run(this,&MainWindow::uploadLoader,filename);
355
356
357}
358void MainWindow::onUploadUpdater(bool click)
359{
360 QString filename = QFileDialog::getOpenFileName(this,"Choose File",QDir::home().absolutePath());
361
362 if(filename.isEmpty()){
363 return;
364 }
365
366 QtConcurrent::run(this,&MainWindow::uploadUpdater,filename);
367
368
369}
370void MainWindow::onUploadApplication(bool click)
371{
372 QString filename = QFileDialog::getOpenFileName(this,"Choose File",QDir::home().absolutePath());
373
374 if(filename.isEmpty()){
375 return;
376 }
377
378 if(!selectedNodes.isEmpty()){
379 if(selectedNodes.first()->type() == ETH_TREE_NODE){
380 QtConcurrent::run(this,&MainWindow::uploadEthApplication,filename);
381 } else if(selectedNodes.first()->type() == CAN_TREE_NODE){
382 if(selectedNodes.first()->getParentNode()->type() == ETH_TREE_NODE){
383 QString address = selectedNodes.first()->getParentNode()->text(ADDRESS);
384 CustomTreeWidgetItem *parentNode = (CustomTreeWidgetItem*)selectedNodes.first()->getParentNode();
385 QtConcurrent::run(this,&MainWindow::uploadCanApplication,filename,address,-1,parentNode);
386 }else if(selectedNodes.first()->getParentNode()->type() == CAN_TREE_ROOT_NODE){
387// QString driver = selectedNodes.first()->getParentNode()->text(DEVICE);
388// int deviceId = selectedNodes.first()->getParentNode()->text(ID).toInt();
389 QString driver;
390 QString deviceIdstr;
391 getDeviceID(selectedNodes.first()->getParentNode(), deviceIdstr, driver);
392 int deviceId = deviceIdstr.toInt();
393 CustomTreeWidgetItem *parentNode = (CustomTreeWidgetItem*)selectedNodes.first()->getParentNode();
394 QtConcurrent::run(this,&MainWindow::uploadCanApplication,filename,driver,deviceId,parentNode);
395 }
396 }
397 }
398
399
400
401
402}
403
404void MainWindow::uploadLoader(QString filename)
405{
406 QString result;
407 core->uploadLoader(filename,&result);
408 if(selectedNodes.count() > 0){
409 CustomTreeWidgetItem *node = selectedNodes.first();
410 if(node->getParentNode()->type() == ETH_TREE_ROOT_NODE){
412 }
413 }
414 setInfoRes(result);
415 // needSetRestartOnSelected();
416}
417
418void MainWindow::uploadUpdater(QString filename)
419{
420 QString result;
421 core->uploadUpdater(filename,&result);
422 if(selectedNodes.count() > 0){
423 CustomTreeWidgetItem *node = selectedNodes.first();
424 if(node->getParentNode()->type() == ETH_TREE_ROOT_NODE){
426 }
427 }
428 setInfoRes(result);
429 //needSetRestartOnSelected();
430}
431
432void MainWindow::uploadEthApplication(QString filename)
433{
434 QString result;
435 core->uploadEthApplication(filename,&result);
436 if(selectedNodes.count() > 0){
437 CustomTreeWidgetItem *node = selectedNodes.first();
438 if(node->getParentNode()->type() == ETH_TREE_ROOT_NODE){
440 }
441 }
442 setInfoRes(result);
443 //needSetRestartOnSelected();
444}
445
446void MainWindow::uploadCanApplication(QString filename,QString address,int deviceId,CustomTreeWidgetItem *node)
447{
448 bool bEraseEEPROM = false;
449 if(ui->checkBoxEE->isEnabled())
450 {
451 Qt::CheckState eestate = ui->checkBoxEE->checkState();
452 bEraseEEPROM = (Qt::Checked == eestate) ? true : false;
453 }
454
455 needLoading(true,true,"",false);
456 QString result;
457 if(node){
458 core->setSelectedCanBoards(node->getCanBoards(),address,deviceId);
459 }
460 QList <sBoard> resultCanBoards;
461 core->uploadCanApplication(filename, &result, bEraseEEPROM, address, deviceId, &resultCanBoards);
462 needLoading(false,false,"",false);
463 needLoading(true,true);
464 node->setCanBoards(resultCanBoards);
465 setInfoRes(result);
466 canBoardsRetrieved(node,false);
467 needLoading(false,false);
468// if(!ethAddress.isEmpty()){
469// refreshCanBoardsFromEth(selectedNodes.first()->getTreeNode()->parent());
470// }
471
472}
473
474void MainWindow::onNeedSetRestartOnSelected()
475{
476// foreach (SelectionCheckBox *c, selectedNodes) {
477// setNodeRestartNeed(c->getTreeNode());
478// }
479}
480
481
482void MainWindow::onBootApplication(bool click)
483{
484 core->bootFromApplication();
485 QString devicestr;
486 QString idstr;
487 getDeviceID(ui->devicesTree->currentItem()->parent()->text(DEVICEID), idstr, devicestr);
488 if(ui->devicesTree->currentItem()->data(0,DEVICE_LEVEL).toInt() == 2 && devicestr == "ETH"){
489// if(ui->devicesTree->currentItem()->data(0,DEVICE_LEVEL).toInt() == 2 && ui->devicesTree->currentItem()->parent()->text(DEVICE) == "ETH"){
490 QtConcurrent::run(this,&MainWindow::populateInfo,ui->devicesTree->currentItem()->data(0,INDEX_OF_BOARD).toInt());
491 }
492
493}
494
495void MainWindow::onBootUpdater(bool click)
496{
497 core->bootFromUpdater();
498 QString devicestr;
499 QString idstr;
500 getDeviceID(ui->devicesTree->currentItem()->parent()->text(DEVICEID), idstr, devicestr);
501 if(ui->devicesTree->currentItem()->data(0,DEVICE_LEVEL).toInt() == 2 && devicestr == "ETH"){
502// if(ui->devicesTree->currentItem()->data(0,DEVICE_LEVEL).toInt() == 2 && ui->devicesTree->currentItem()->parent()->text(DEVICE) == "ETH"){
503 QtConcurrent::run(this,&MainWindow::populateInfo,ui->devicesTree->currentItem()->data(0,INDEX_OF_BOARD).toInt());
504 }
505}
506
507void MainWindow::onJumpToUpdater(bool click)
508{
509 loading(true,true);
510 QFuture<bool> future = QtConcurrent::run(core,&FirmwareUpdaterCore::jumpToUpdater);
511 watcher.setFuture(future);
512}
513
514void MainWindow::onGoToMaintenance(bool click)
515{
516 loading(true,true);
517// foreach (CustomTreeWidgetItem *node, selectedNodes) {
518// node->setCheckSelected(false);
519// }
520 QFuture<bool> future = QtConcurrent::run(core,&FirmwareUpdaterCore::goToMaintenance);
521 watcher.setFuture(future);
522
523}
524
525void MainWindow::onGoToApplication(bool click)
526{
527 loading(true,true);
528 foreach (CustomTreeWidgetItem *node, selectedNodes) {
529 emptyNode(node);
530 }
531 QFuture<bool> future = QtConcurrent::run(core,&FirmwareUpdaterCore::goToApplication);
532 watcher.setFuture(future);
533
534}
535
536
537void MainWindow::onEraseEprom(bool click)
538{
539 if(selectedNodes.count() > 0){
540 if(selectedNodes.first()->type() == ETH_TREE_NODE){
541 loading(true,true);
542 QFuture<bool> future = QtConcurrent::run(core,&FirmwareUpdaterCore::eraseEthEprom);
543 watcher.setFuture(future);
544 } else if(selectedNodes.first()->type() == CAN_TREE_NODE){
545// CustomTreeWidgetItem *node = selectedNodes.first();
546// ((CanTreeWidgetItem*)node)->erasEeprom(!node->data(0,CAN_ERASE_EEPROM).toBool());
547// node->refresh();
548
549// checkSelection(true,node);
550 }
551 }
552}
553
554void MainWindow::onFutureFinished()
555{
556 if(watcher.result()){
557 foreach (CustomTreeWidgetItem *it, selectedNodes) {
558 it->refresh();
559 it->setCheckSelected(false);
560 }
561 }
562 loading(false);
563 checkEnableButtons();
564 onDeviceSelectionChanged();
565}
566
567void MainWindow::onStrainCalib(bool click)
568{
569 if(selectedNodes.isEmpty()){
570 return;
571 }
572 CanTreeWidgetItem *it = (CanTreeWidgetItem*)selectedNodes.first();
573
574 sBoard board = it->getBoard();
575 yDebug() << "onStrainCalib() has device = " << device.toStdString();
576 yDebug() << "onStrainCalib() has bus = " << board.bus;
577 yDebug() << "onStrainCalib() has id = " << board.pid;
578 StrainCalibGui strainCalibGui(device,board.bus,board.pid,core);
579 strainCalibGui.exec();
580}
581
582void MainWindow::onBlinkPressed(bool click)
583{
584 core->blinkEthBoards();
585}
586
587bool MainWindow::getDeviceID(QTreeWidgetItem *child, QString &idstr, QString &devicestr)
588{
589 QString tmp = child->text(DEVICEID);
590 QByteArray ba = tmp.toLatin1();
591 const char *c_str2 = ba.data();
592#if 0
593 char device_cstr[64] = {0};
594 char id_cstr[64] = {0};
595 sscanf(c_str2, "%s %s", device_cstr, id_cstr);
596 devicestr = device_cstr;
597 idstr = id_cstr;
598#else
599 string ttmp = string(c_str2);
600 std::size_t ff = ttmp.find("<");
601 std::size_t ll = ttmp.find(">");
602 string t1;
603 t1.assign(ttmp, 0, ff);
604 string t2;
605 t2.assign(ttmp, ff+1, ll-ff-1);
606 devicestr = t1.c_str();
607 idstr = t2.c_str();
608#endif
609
610 return true;
611}
612
613bool MainWindow::getDeviceID(QString devicefullstring, QString &idstr, QString &devicestr)
614{
615 QString tmp = devicefullstring;
616 QByteArray ba = tmp.toLatin1();
617 const char *c_str2 = ba.data();
618#if 0
619 char device_cstr[64] = {0};
620 char id_cstr[64] = {0};
621 sscanf(c_str2, "%s %s", device_cstr, id_cstr);
622 devicestr = device_cstr;
623 idstr = id_cstr;
624#else
625 string ttmp = string(c_str2);
626 std::size_t ff = ttmp.find("<");
627 std::size_t ll = ttmp.find(">");
628 string t1;
629 t1.assign(ttmp, 0, ff);
630 string t2;
631 t2.assign(ttmp, ff+1, ll-ff-1);
632 devicestr = t1.c_str();
633 idstr = t2.c_str();
634#endif
635 return true;
636}
637
638
639void MainWindow::onChangeAddress(bool click)
640{
641 if(selectedNodes.count() != 1){
642 return;
643 }
644 CustomTreeWidgetItem *child = selectedNodes.first();
645
646
647 int cbus = 0;
648 int cadr = 0;
649 QString oldAddress;
650 if(child->type() == ETH_TREE_NODE){
651 oldAddress = core->getEthBoardAddress(child->getIndexOfBoard());
652 } else if(child->type() == CAN_TREE_NODE){
653 QString canBus;
654 getCANaddress(child, cbus, cadr, canBus, oldAddress);
655 }else{
656 return;
657 }
658
660 dlg.setOldAddress(oldAddress);
661 if(dlg.exec() == QDialog::Accepted){
662 if(dlg.getNewAddress() != oldAddress){
663 if(child->type() == ETH_TREE_NODE){
664 emptyNode(child);
665 QtConcurrent::run(this,&MainWindow::setEthBoardAddress,
666 child->getIndexOfBoard(),
667 dlg.getNewAddress(),
668 child);
669 } else if(child->type() == CAN_TREE_NODE){
670 QString address = child->getParentNode()->text(ADDRESS);
671 for(int i=0;i<child->childCount();i++){
672 child->child(i)->setDisabled(true);
673 }
674 int canType = child->data(0,CAN_TYPE).toInt();
676
677 if(parentNode->type() == ETH_TREE_NODE){
678
679 QPair <QString,QString> addr;
680 addr.second = dlg.getNewAddress();
681 addr.first = address;
682
683 QtConcurrent::run(this,&MainWindow::setCanBoardAddress,
684 QPair<int,int>(cbus, cadr),
685 canType,
686 addr,
687 -1,
688 parentNode);
689
690
691
692 }else if(parentNode->type() == CAN_TREE_ROOT_NODE){
693
694 //QString driver = parentNode->text(DEVICE);
695 //int networkId = parentNode->text(ID).toInt();
696 QString driver;
697 QString networkIdstr;
698 getDeviceID(child->getParentNode(), networkIdstr, driver);
699 int networkId = networkIdstr.toInt();
700
701 QPair <QString,QString> addr;
702 addr.second = dlg.getNewAddress();
703 addr.first = driver;
704
705 QtConcurrent::run(this,&MainWindow::setCanBoardAddress,
706 QPair<int,int>(cbus, cadr),
707 canType,
708 addr,
709 networkId,
710 parentNode);
711 }
712
713
714
715 }
716 }
717 }
718}
719
720void MainWindow::onEraseApplication(bool click)
721{
722 // TODO: work in progress
723 std::cout << "Erase application button clicked! Functionality not yet implemented." << std::endl;
724}
725
726void MainWindow::onChangeInfo(bool click)
727{
728 if(selectedNodes.count() != 1){
729 return;
730 }
731
732 CustomTreeWidgetItem *child = selectedNodes.first();
733
734 QString oldInfo;
735 if(child->type() == ETH_TREE_NODE){
736 oldInfo = core->getEthBoardInfo(child->getIndexOfBoard());
737 } else if(child->type() == CAN_TREE_NODE){
738 oldInfo = child->text(INFO);
739 }else{
740 return;
741 }
742
744 dlg.setOldInfo(oldInfo);
745 if(dlg.exec() == QDialog::Accepted){
746 if(dlg.getNewInfo() != oldInfo){
747 if(child->type() == ETH_TREE_NODE){
748 QtConcurrent::run(this,&MainWindow::setEthBoardInfo,child->getIndexOfBoard(),dlg.getNewInfo(),child);
749 } else if(child->type() == CAN_TREE_NODE){
751
752
753 for(int i=0;i<child->childCount();i++){
754 child->child(i)->setDisabled(true);
755 }
756
757 int cbus = 0;
758 int cadr = 0;
759 QString cbustring;
760 QString cadrstring;
761 getCANaddress(child, cbus, cadr, cbustring, cadrstring);
762
763 if(parentNode->type() == ETH_TREE_NODE){
764 QString address = parentNode->text(ADDRESS);
765 QtConcurrent::run(this,&MainWindow::setCanBoardInfo,
766 QPair<int,int>(cbus, cadr),
767 dlg.getNewInfo(),
768 address,
769 -1,
770 parentNode);
771
772 } else if(parentNode->type() == CAN_TREE_ROOT_NODE){
773 //QString driver = child->getParentNode()->text(DEVICE);
774 //int networkId = child->getParentNode()->text(ID).toInt();
775 QString driver;
776 QString networkIdstr;
777 getDeviceID(child->getParentNode(), networkIdstr, driver);
778 int networkId = networkIdstr.toInt();
779
780 QtConcurrent::run(this,&MainWindow::setCanBoardInfo,
781 QPair<int,int>(cbus, cadr),
782 dlg.getNewInfo(),
783 driver,
784 networkId,
785 parentNode);
786
787 }
788
789
790
791 }
792 }
793 }
794
795}
796
797void MainWindow::onCalibrate(bool click)
798{
799 if(calibDlg){
800 delete calibDlg;
801 calibDlg = NULL;
802 }
803
804 calibDlg = new CalibrationWindow(core,sgboardtype, selectedNodes.first(),this);
805 calibDlg->show();
806
807}
808
809void MainWindow::setCanBoardInfo(QPair <int,int> canData, QString info, QString address, int deviceId,QTreeWidgetItem *refreshNode)
810{
811 needLoading(true,true);
812 int bus = canData.first;
813 int id = canData.second;
814 QString result;
815 CustomTreeWidgetItem *ethNode =(CustomTreeWidgetItem*)refreshNode;
816
817 core->setSelectedCanBoards(ethNode->getCanBoards(),address,deviceId);
818 core->setCanBoardInfo(bus,id,info,address,deviceId,&result);
819
820 result = ethNode->retrieveCanBoards();
821 canBoardsRetrieved(refreshNode, true);
822 needLoading(false,false,result);
823
824}
825
826void MainWindow::setCanBoardAddress(QPair <int,int> canData, int canType, QPair<QString, QString> addr, int deviceId,QTreeWidgetItem *refreshNode)
827{
828 needLoading(true,true);
829 int bus = canData.first;
830 int id = canData.second;
831 QString result;
832 CustomTreeWidgetItem *ethNode =(CustomTreeWidgetItem*)refreshNode;
833 core->setSelectedCanBoards(ethNode->getCanBoards(),addr.first,deviceId);
834 core->setCanBoardAddress(bus,id,canType,addr.second,addr.first,deviceId,&result);
835 result = ethNode->retrieveCanBoards();
836 canBoardsRetrieved(refreshNode, false);
837 needLoading(false,false,result);
838
839}
840
841void MainWindow::setEthBoardInfo(int index,QString info, QTreeWidgetItem *refreshNode)
842{
843 loading(true,true);
844 QFuture<bool> future = QtConcurrent::run(core,&FirmwareUpdaterCore::setEthBoardInfo,index,info);
845 watcher.setFuture(future);
846
847// loading(true);
848// core->setEthBoardInfo(index,info);
849// refreshEthBoardsNode(refreshNode,true);
850// loading(false);
851}
852
853void MainWindow::setEthBoardAddress(int index,QString address, QTreeWidgetItem *refreshNode)
854{
855 loading(true,true);
856 QFuture<bool> future = QtConcurrent::run(core,&FirmwareUpdaterCore::setEthBoardAddress,index,address);
857 watcher.setFuture(future);
858
859// if(core->setEthBoardAddress(index,address)){
860// qDebug() << "SUCCESS";
861// //refreshEthBoardsNode(refreshNode,true);
862// ((CustomTreeWidgetItem*)refreshNode)->refresh();;
863// checkEnableButtons();
864// }else{
865// qDebug() << "FAILED";
866// //TODO ERROR
867// }
868// loading(false);
869}
870
871void MainWindow::setNodeRestartNeed(QTreeWidgetItem *refreshNode, bool need)
872{
873 if(need){
874 refreshNode->setIcon(DEVICEID,QIcon(":/images/restart-needed.png"));
875 }else{
876 refreshNode->setIcon(DEVICEID,QIcon());
877 }
878
879 refreshNode->setData(0,REFRESH_NEED,need);
880 for(int i=0;i<refreshNode->childCount();i++){
881 QTreeWidgetItem *child = refreshNode->child(i);
882 child->setDisabled(need);
883 child->setData(0,REFRESH_NEED,need);
884 }
885
886}
887
888void MainWindow::onRestartBoards(bool click)
889{
890 core->restartEthBoards();
891 //QtConcurrent::run(this,&MainWindow::refreshDevices,true,8000);
892}
893
894//void MainWindow::onRestartBoards5Secs(bool click)
895//{
896// core->restartEthBoards();
897// QtConcurrent::run(this,&MainWindow::refreshDevices,true,3000);
898//}
899
900void MainWindow::checkConnectionButton(QTreeWidgetItem *it)
901{
902 if(it->parent() == NULL || it->data(0,DEVICE_LEVEL) == 2){
903 ui->connectButton->setEnabled(true);
904// if(it->data(0,CONNECTED).toBool() == true){
905// ui->connectButton->setText("Disconnect");
906// }else{
907// ui->connectButton->setText("Connect");
908// }
909
910 }else{
911 ui->connectButton->setEnabled(false);
912 }
913}
914
915
916void MainWindow::onDeviceSelectionChanged()
917{
918 if(ui->devicesTree->selectedItems().count() > 0){
919 checkConnectionButton(ui->devicesTree->currentItem());
920
921 // If it is a child node
922 if(ui->devicesTree->currentItem() && ui->devicesTree->currentItem()->parent()){
923 appendInfo();
924 if(ui->devicesTree->currentItem()->parent()->text(DEVICEID).contains("ETH")){
925 for(int i=0; i < ui->devicesTree->currentItem()->parent()->childCount();i++){
926 if(ui->devicesTree->currentItem()->parent()->child(i)->isSelected() &&
927 ui->devicesTree->currentItem()->parent()->child(i)->data(0,EMPTY_NODE).toBool() == false){
928 int boardNum = ui->devicesTree->currentItem()->parent()->child(i)->data(0,INDEX_OF_BOARD).toInt();
929
930 QtConcurrent::run(this,&MainWindow::populateInfo,boardNum);
931 }
932 }
933 }
934 else
935 {
936 // it is a can board either under an ETH board or under a different device
937 // must be able to detect if it is can node under an ETH board or under CFW2...
938
939 int level = ui->devicesTree->currentItem()->data(0,DEVICE_LEVEL).toInt();
940 level = level;
941
942 for(int i=0; i < ui->devicesTree->currentItem()->parent()->childCount();i++){
943 if(ui->devicesTree->currentItem()->parent()->child(i)->isSelected() &&
944 ui->devicesTree->currentItem()->parent()->child(i)->data(0,EMPTY_NODE).toBool() == false){
945 //int boardNum = 0;
946 int boardNum = ui->devicesTree->currentItem()->parent()->child(i)->data(0,INDEX_OF_BOARD).toInt();
947
948 sBoard canBoard;
949 if(3 == level)
950 {
951 canBoard = ((EthTreeWidgetItem*)ui->devicesTree->currentItem()->parent())->getCanBoard(boardNum);
952 }
953 else
954 { // on cfw2 or others
955 canBoard = ((CanTreeWidgetItem*)ui->devicesTree->currentItem())->getBoard();
956 }
957
958 QtConcurrent::run(this,&MainWindow::populateCANinfo,canBoard);
959 }
960 }
961 }
962
963
964 }else{
965 appendInfo();
966 }
967 }else{
968 ui->connectButton->setEnabled(false);
969 ui->actionSel->setEnabled(false);
970 ui->actionDes->setEnabled(false);
971 appendInfo();
972 }
973 checkEnableButtons();
974
975}
976
977void MainWindow::populateInfo(int boardNum)
978{
979 needLoading(true,true);
980 QString details;
981 eOipv4addr_t address;
982 boardInfo2_t info = core->getMoreDetails(boardNum,&details,&address);
983 if(!details.isEmpty()){
984 appendInfo(details);
985 }else{
986 appendInfo(info,address);
987 }
988 needLoading(false,false);
989}
990
991void MainWindow::populateCANinfo(sBoard canboard)
992{
993 needLoading(true,true);
994 appendInfo(canboard);
995 needLoading(false,false);
996}
997
998void MainWindow::onAppendInfo(boardInfo2_t info,eOipv4addr_t address)
999{
1000 ui->detailsText->setVisible(false);
1001 infoTreeWidget->setVisible(true);
1002
1003 infoTreeWidget->clear();
1004 QTreeWidgetItem *boardNode = new QTreeWidgetItem(infoTreeWidget,QStringList() << "ETH board");
1005 QTreeWidgetItem *bootStrapNode = new QTreeWidgetItem(infoTreeWidget,QStringList() << "Bootstrap Processes");
1006 QTreeWidgetItem *propertiesNode = new QTreeWidgetItem(infoTreeWidget,QStringList() << "Properties of the Processes");
1007 infoTreeWidget->addTopLevelItem(boardNode);
1008 infoTreeWidget->addTopLevelItem(bootStrapNode);
1009 infoTreeWidget->addTopLevelItem(propertiesNode);
1010
1011 constexpr uint8_t maxNumberOfProcessesOnSingleCore {3};
1012
1013 QString type = eoboards_type2string(eoboards_ethtype2type(info.boardtype));
1014 // switch (info.boardtype) {
1015 // case eobrd_ethtype_amc:
1016 // type = "amc";
1017 // break;
1018 // case eobrd_ethtype_ems4:
1019 // type = "ems";
1020 // break;
1021 // case eobrd_ethtype_mc4plus:
1022 // type = "mc4plus";
1023 // break;
1024 // case eobrd_ethtype_mc2plus:
1025 // type = "mc2plus";
1026 // break;
1027 // case eobrd_ethtype_none:
1028 // type = "none";
1029 // break;
1030 // case eobrd_ethtype_unknown:
1031 // type = "unknown";
1032 // break;
1033 // default:
1034 // break;
1035 // }
1036
1037 QTreeWidgetItem *typeNode = new QTreeWidgetItem(boardNode, QStringList() << "Type" << type);
1038 boardNode->addChild(typeNode);
1039 boardNode->setExpanded(true);
1040
1041 ACE_UINT64 mac = info.macaddress;
1042 char board_mac[32];
1043
1044 snprintf(board_mac, sizeof(board_mac), "%02X-%02X-%02X-%02X-%02X-%02X",
1045 (uint8_t)(mac >> 40) & 0xff,
1046 (uint8_t)(mac >> 32) & 0xff,
1047 (uint8_t)(mac >> 24) & 0xff,
1048 (uint8_t)(mac >> 16) & 0xff,
1049 (uint8_t)(mac >> 8 ) & 0xff,
1050 (uint8_t)(mac ) & 0xff);
1051
1052 QTreeWidgetItem *macNode = new QTreeWidgetItem(boardNode, QStringList() << "MAC" << board_mac);
1053 boardNode->addChild(macNode);
1054
1055 QTreeWidgetItem *ipNode = new QTreeWidgetItem(boardNode, QStringList() << "IP" << ipv4tostring(address).c_str());
1056 boardNode->addChild(ipNode);
1057
1058 QString mode = (info.maintenanceIsActive ? "maintenance" : "application");
1059 if(eApplPROGupdater == info.processes.runningnow)
1060 {
1061 mode = "special application for programming the updater";
1062 }
1063 else if((eApplication == info.processes.runningnow) && (0xff != info.applicationdetails))
1064 {
1065 if(0x01 == (0x01 & info.applicationdetails))
1066 {
1067 mode = "application (RUNNING)";
1068 }
1069 else
1070 {
1071 mode = "application (IDLE)";
1072 }
1073 }
1074
1075 QTreeWidgetItem *statusNode = new QTreeWidgetItem(boardNode, QStringList() << "Status" << mode);
1076
1077 { // changing color to the mode
1078 QFont ff = statusNode->font(1);
1079 ff.setBold(true);
1080 statusNode->setFont(1, ff);
1081
1082 if(eApplPROGupdater == info.processes.runningnow)
1083 {
1084 statusNode->setForeground(1, Qt::magenta);
1085 }
1086 else if(eUpdater == info.processes.runningnow)
1087 {
1088 statusNode->setForeground(1, Qt::blue);
1089 }
1090 else
1091 {
1092 statusNode->setForeground(1, Qt::black);
1093 }
1094 }
1095
1096 boardNode->addChild(statusNode);
1097
1098 /*******************************************************************************/
1099 bool isMulticore = (eoboards_type2numberofcores(eoboards_ethtype2type(info.boardtype))) > 1 ? true : false;
1100 QTreeWidgetItem *startUpNode = new QTreeWidgetItem(bootStrapNode, QStringList() << "Startup" << core->getProcessFromUint(info.processes.startup, isMulticore));
1101 bootStrapNode->addChild(startUpNode);
1102 bootStrapNode->setExpanded(true);
1103
1104 QTreeWidgetItem *defaultNode = new QTreeWidgetItem(bootStrapNode, QStringList() << "Default" << core->getProcessFromUint(info.processes.def2run, isMulticore));
1105 bootStrapNode->addChild(defaultNode);
1106
1107 QTreeWidgetItem *runningNode = new QTreeWidgetItem(bootStrapNode, QStringList() << "Running" << core->getProcessFromUint(info.processes.runningnow, isMulticore));
1108 bootStrapNode->addChild(runningNode);
1109
1110 /*******************************************************************************/
1111
1112 propertiesNode->setExpanded(true);
1113 for(uint8_t i= 0; i < info.processes.numberofthem; i++){
1114 eOuprot_procinfo_t pinfo;
1115 if(i < maxNumberOfProcessesOnSingleCore)
1116 {
1117 pinfo = info.processes.info[i];
1118 }
1119 else
1120 {
1121 pinfo = info.extraprocesses[i-maxNumberOfProcessesOnSingleCore];
1122 }
1123
1124 QTreeWidgetItem *processNode = new QTreeWidgetItem(propertiesNode, QStringList() << QString("Process %1").arg(i));
1125 propertiesNode->addChild(processNode);
1126 processNode->setExpanded(true);
1127
1128 QTreeWidgetItem *processType = new QTreeWidgetItem(processNode, QStringList() << "Type" << core->getProcessFromUint(pinfo.type, isMulticore));
1129 processNode->addChild(processType);
1130
1131 QTreeWidgetItem *processVersion = new QTreeWidgetItem(processNode, QStringList() << "Version" << QString("%1.%2").arg(pinfo.version.major).arg(pinfo.version.minor));
1132 processNode->addChild(processVersion);
1133
1134 QTreeWidgetItem *processDate = new QTreeWidgetItem(processNode, QStringList() << "Date" << QDateTime(QDate(pinfo.date.year,pinfo.date.month,pinfo.date.day),
1135 QTime(pinfo.date.hour,pinfo.date.min)).toString("yyyy/MM/dd - hh:mm"));
1136 processNode->addChild(processDate);
1137
1138 QTreeWidgetItem *processBuilt = new QTreeWidgetItem(processNode, QStringList() << "Built On" << QDateTime(QDate(pinfo.compilationdate.year,pinfo.compilationdate.month,pinfo.compilationdate.day),
1139 QTime(pinfo.compilationdate.hour,pinfo.compilationdate.min)).toString("yyyy/MM/dd - hh:mm"));
1140 processNode->addChild(processBuilt);
1141
1142 std::string processStorageName = (i < maxNumberOfProcessesOnSingleCore) ? "ROM" : "FLASH";
1143 QTreeWidgetItem *processRom= new QTreeWidgetItem(processNode, QStringList() << processStorageName.c_str() << QString("[%1, %1+%2) kb").arg(pinfo.rom_addr_kb).arg(pinfo.rom_size_kb));
1144 processNode->addChild(processRom);
1145 }
1146}
1147
1148
1149
1150void MainWindow::onAppendInfo(QString text)
1151{
1152
1153 ui->detailsText->clear();
1154 if(!text.isEmpty()){
1155 ui->detailsText->appendPlainText(text);
1156 }
1157 infoTreeWidget->setVisible(false);
1158 ui->detailsText->setVisible(true);
1159}
1160
1161
1162void MainWindow::onAppendInfo(sBoard canboard)
1163{
1164 ui->detailsText->setVisible(false);
1165 infoTreeWidget->setVisible(true);
1166
1167 infoTreeWidget->clear();
1168 QTreeWidgetItem *boardNode = new QTreeWidgetItem(infoTreeWidget,QStringList() << "CAN board");
1169
1170 infoTreeWidget->addTopLevelItem(boardNode);
1171
1172#if 0
1173 QString type;
1174 type = eoboards_type2string2((eObrd_type_t)canboard.type, eobool_true);
1175
1176 QTreeWidgetItem *typeNode = new QTreeWidgetItem(boardNode, QStringList() << "Type" << type);
1177 boardNode->addChild(typeNode);
1178
1179
1180 QString addr;
1181 char aaa[16] = {0};
1182 snprintf(aaa, sizeof(aaa), "CAN%d:%d", canboard.bus, canboard.pid);
1183 addr = aaa;
1184 QTreeWidgetItem *adrNode = new QTreeWidgetItem(boardNode, QStringList() << "Address" << addr);
1185 boardNode->addChild(adrNode);
1186#else
1187
1188 char str[64] = {0};
1189
1190 const char *name = eoboards_type2string2((eObrd_type_t)canboard.type, eobool_true);
1191 QTreeWidgetItem *type = new QTreeWidgetItem(boardNode, QStringList() << "Type" << name);
1192 boardNode->addChild(type);
1193
1194
1195 snprintf(str, sizeof(str), "CAN%d:%d", canboard.bus, canboard.pid);
1196 QTreeWidgetItem *adr = new QTreeWidgetItem(boardNode, QStringList() << "Address" << str);
1197 boardNode->addChild(adr);
1198
1199 if(true == canboard.applicationisrunning)
1200 {
1201 snprintf(str, sizeof(str), "canApplication");
1202 }
1203 else
1204 {
1205 snprintf(str, sizeof(str), "canBootloader");
1206 }
1207 QTreeWidgetItem *pro = new QTreeWidgetItem(boardNode, QStringList() << "Running process" << str);
1208 boardNode->addChild(pro);
1209
1210 if(-1 == canboard.appl_vers_build)
1211 {
1212 snprintf(str, sizeof(str), "%d.%d", canboard.appl_vers_major, canboard.appl_vers_minor);
1213 }
1214 else
1215 {
1216 snprintf(str, sizeof(str), "%d.%d.%d", canboard.appl_vers_major, canboard.appl_vers_minor, canboard.appl_vers_build);
1217 }
1218 QTreeWidgetItem *fwvers = new QTreeWidgetItem(boardNode, QStringList() << "Firmware version" << str);
1219 boardNode->addChild(fwvers);
1220
1221 if((0 == canboard.prot_vers_major) && (0 == canboard.prot_vers_minor))
1222 {
1223 snprintf(str, sizeof(str), "N/A");
1224 }
1225 else
1226 {
1227 snprintf(str, sizeof(str), "%d.%d", canboard.prot_vers_major, canboard.prot_vers_minor);
1228 }
1229 QTreeWidgetItem *prvers = new QTreeWidgetItem(boardNode, QStringList() << "CAN protocol version" << str);
1230 boardNode->addChild(prvers);
1231
1232 snprintf(str, sizeof(str), "%s", canboard.add_info);
1233 QTreeWidgetItem *inf = new QTreeWidgetItem(boardNode, QStringList() << "Info" << str);
1234 boardNode->addChild(inf);
1235
1236 if((eobrd_strain == canboard.type) || (eobrd_strain2 == canboard.type) || (eobrd_strain2c == canboard.type))
1237 {
1238 QTreeWidgetItem *sn = new QTreeWidgetItem(boardNode, QStringList() << "Serial Number" << canboard.serial);
1239 boardNode->addChild(sn);
1240
1241 snprintf(str, sizeof(str), "at boot = %d, in use = %d", canboard.strainregsetatboot, canboard.strainregsetinuse);
1242 QTreeWidgetItem *rs = new QTreeWidgetItem(boardNode, QStringList() << "Regulations Set" << str);
1243 boardNode->addChild(rs);
1244
1245// QTreeWidgetItem *rsu = new QTreeWidgetItem(boardNode, QStringList() << "Regulations Set in use" << canboard.strainregsetinuse);
1246// boardNode->addChild(rsu);
1247 }
1248
1249// QTreeWidgetItem *basic = new QTreeWidgetItem(boardNode, QStringList() << "Details" << "See left panel");
1250// boardNode->addChild(basic);
1251
1252#endif
1253
1254 boardNode->setExpanded(true);
1255
1256}
1257
1258
1259
1260void MainWindow::onConnect()
1261{
1262 setInfoRes("");
1263 foreach (QTreeWidgetItem *it, ui->devicesTree->selectedItems()) {
1264 if(it->data(0,DEVICE_LEVEL).toInt() == 0){
1265
1266 if(it->data(0,CONNECTED).toBool() == true){
1267 //emptyNode(it);
1268 it->setData(0,CONNECTED,false);
1269 it->setTextColor(DEVICEID,QColor(Qt::red));
1270 }
1271 //QString device;
1272 QString deviceIdstr;
1273 getDeviceID(it, deviceIdstr, device);
1274
1275 if(core->connectTo(device,deviceIdstr) > 0){
1276 it->setData(0,CONNECTED,true);
1277 it->setExpanded(true);
1278 it->setTextColor(DEVICEID,QColor(Qt::green));
1279 }else{
1280 it->setData(0,CONNECTED,false);
1281 it->setTextColor(DEVICEID,QColor(Qt::red));
1282 }
1283
1284 QtConcurrent::run(this,&MainWindow::refreshDevices);
1285 }
1286
1287 if(it->data(0,DEVICE_LEVEL).toInt() == 2){
1288 QString sss = it->text(PROCESS);
1289 if(it->text(PROCESS).contains("eUpdater" )){
1290 QtConcurrent::run(this,&MainWindow::getCanBoards,it,false);
1291 }
1292 else{
1293 QMessageBox msgBox;
1294 msgBox.setIcon(QMessageBox::Warning);
1295 if(it->text(PROCESS).contains("eApplPROGupdater" ))
1296 {
1297 msgBox.setText("The executing process is the " + sss + " which does not allow CAN discovery but only the programming of the eUpdater. You have to put the board in maintenance mode");
1298 }
1299 else
1300 {
1301 msgBox.setText("You have to put the board in maintenance mode to perform this operation. Now it is running the " + sss);
1302 }
1303
1304 msgBox.setStandardButtons(QMessageBox::Ok );
1305 msgBox.setDefaultButton(QMessageBox::Ok);
1306 msgBox.exec();
1307 }
1308 }
1309
1310 checkConnectionButton(it);
1311 }
1312
1313
1314}
1315
1316void MainWindow::checkEnableButtons()
1317{
1318 bool isEth = false;
1319 bool needRestart = false;
1320 bool canUploadLoader = true;
1321 bool canUploadApp = true;
1322 bool canChangeInfo = true;
1323 bool canUploadUpdater = true;
1324 bool canJumpUpdater = true;
1325 bool canEraseEthEEPROM = true;
1326 bool canChangeIP = true;
1327
1328 for(int i=0;i<ui->devicesTree->topLevelItemCount();i++){
1329 QTreeWidgetItem *topLevel = ui->devicesTree->topLevelItem(i);
1330 for(int j=0;j<topLevel->childCount();j++){
1331
1332 QTreeWidgetItem *widgItem = topLevel->child(j);
1333 if(widgItem->type() != ETH_TREE_ROOT_NODE && widgItem->type() != CAN_TREE_ROOT_NODE && widgItem->type() != QTreeWidgetItem::Type){
1334 CustomTreeWidgetItem *child = (CustomTreeWidgetItem *)widgItem;
1335 if(child->isCheckSelected()){
1336 if(child->type() == ETH_TREE_NODE){
1337 isEth = true;
1338
1339
1340 canUploadLoader &= child->data(0,CAN_UPLOAD_LOADER).toBool();
1341 canUploadApp &= child->data(0,CAN_UPLOAD_APP).toBool();
1342 canChangeInfo &= child->data(0,CAN_UPLOAD_APP).toBool();
1343 canEraseEthEEPROM &= child->data(0,CAN_UPLOAD_APP).toBool();
1344 canChangeIP &= child->data(0,CAN_UPLOAD_APP).toBool();
1345 canUploadUpdater &= child->data(0,CAN_UPLOAD_UPDATER).toBool();
1346 canJumpUpdater &= child->data(0,CAN_JUMP_UPDATER).toBool();
1347 }
1348 }
1349 }
1350
1351
1352
1353// for(int k=0; k<topLevel->child(j)->childCount();k++ ){
1354// SelectionCheckBox *check1 = (SelectionCheckBox*)ui->devicesTree->itemWidget(topLevel->child(j)->child(k),0);
1355// if(check1 && check1->isEnabled() && check1->isSelected()){
1356// selectedCount++;
1357// }
1358// }
1359 }
1360 }
1361
1362 if(selectedNodes.isEmpty()){
1363 ui->btnStrainCalib->setEnabled(false);
1364 ui->btnBlink->setEnabled(false);
1365 ui->btnBootApp->setEnabled(false);
1366 ui->btnBootUpdater->setEnabled(false);
1367 ui->btnCahngeInfo->setEnabled(false);
1368 ui->btnCalibrate->setEnabled(false);
1369 ui->btnChangeCanAddr->setEnabled(false);
1370 ui->btnEraseApplication->setEnabled(false);
1371 ui->btnChangeIp->setEnabled(false);
1372 ui->btnEraseEeprom->setEnabled(false);
1373 ui->btnJumpUpdater->setEnabled(false);
1374 ui->btnRestart->setEnabled(false);
1375 //ui->btnRestartSecs->setEnabled(false);
1376 ui->btnGoToApplication->setEnabled(false);
1377 ui->btnGoToMaintenance->setEnabled(false);
1378 ui->btnUploadApp->setEnabled(false);
1379 ui->btnUploadLoader->setEnabled(false);
1380 ui->btnUploadUpdater->setEnabled(false);
1381 ui->actionSel->setEnabled(false);
1382 ui->actionDes->setEnabled(false);
1383 ui->checkBoxEE->setCheckState(Qt::Unchecked);
1384 ui->checkBoxEE->setEnabled(false);
1385 return;
1386 }
1387
1388
1389 if(isEth){
1390 if(needRestart){
1391 ui->btnGoToApplication->setEnabled(true);
1392 ui->btnGoToMaintenance->setEnabled(true);
1393 ui->btnRestart->setEnabled(true);
1394 //ui->btnRestartSecs->setEnabled(true);
1395 ui->btnBlink->setEnabled(false);
1396 ui->btnBootApp->setEnabled(false);
1397 ui->btnBootUpdater->setEnabled(false);
1398 ui->btnCalibrate->setEnabled(false);
1399
1400 ui->btnChangeCanAddr->setEnabled(false);
1401 ui->btnEraseApplication->setEnabled(false);
1402 ui->btnCahngeInfo->setEnabled(false);
1403
1404 ui->btnChangeIp->setEnabled(false);
1405 ui->btnEraseEeprom->setEnabled(false);
1406 ui->btnJumpUpdater->setEnabled(false);
1407 ui->btnUploadApp->setEnabled(false);
1408 ui->btnUploadLoader->setEnabled(false);
1409 ui->btnUploadUpdater->setEnabled(false);
1410 ui->actionSel->setEnabled(false);
1411 ui->actionDes->setEnabled(false);
1412 ui->checkBoxEE->setCheckState(Qt::Unchecked);
1413 ui->checkBoxEE->setEnabled(false);
1414 }else{
1415 ui->btnBlink->setEnabled(true);
1416 ui->btnBootApp->setEnabled(true);
1417 ui->btnBootUpdater->setEnabled(true);
1418
1419 ui->btnCalibrate->setEnabled(false);
1420 ui->btnChangeCanAddr->setEnabled(false);
1421 if(selectedNodes.count() == 1){
1422 // only if we have the updater running
1423 ui->btnChangeIp->setEnabled(canChangeIP);
1424 ui->btnCahngeInfo->setEnabled(canChangeInfo);
1425 ui->btnEraseEeprom->setEnabled(canEraseEthEEPROM);
1426 }else{
1427 ui->btnChangeIp->setEnabled(false);
1428 ui->btnCahngeInfo->setEnabled(false);
1429 ui->btnEraseEeprom->setEnabled(false);
1430 }
1431
1432 if(canJumpUpdater){
1433 ui->btnJumpUpdater->setEnabled(true);
1434 }else{
1435 ui->btnJumpUpdater->setEnabled(false);
1436 }
1437 ui->btnGoToApplication->setEnabled(true);
1438 ui->btnGoToMaintenance->setEnabled(true);
1439 ui->btnRestart->setEnabled(true);
1440 //ui->btnRestartSecs->setEnabled(true);
1441 if(canUploadApp){
1442 ui->btnUploadApp->setEnabled(true);
1443 ui->btnEraseApplication->setEnabled(true);
1444 }else{
1445 ui->btnUploadApp->setEnabled(false);
1446 }
1447 if(canUploadLoader){
1448 ui->btnUploadLoader->setEnabled(true);
1449 }else{
1450 ui->btnUploadLoader->setEnabled(false);
1451 }
1452 if(canUploadUpdater){
1453 ui->btnUploadUpdater->setEnabled(true);
1454 }else{
1455 ui->btnUploadUpdater->setEnabled(false);
1456 }
1457 ui->actionSel->setEnabled(true);
1458 ui->actionDes->setEnabled(true);
1459 ui->checkBoxEE->setCheckState(Qt::Unchecked);
1460 ui->checkBoxEE->setEnabled(false);
1461 }
1462
1463 }else{
1464 ui->btnBlink->setEnabled(false);
1465 ui->btnBootApp->setEnabled(false);
1466 ui->btnBootUpdater->setEnabled(false);
1467
1468 if(selectedNodes.count() == 1){
1469 ui->btnChangeCanAddr->setEnabled(true);
1470 // ok, we enablke it also for bootloader ...
1471 ui->btnCahngeInfo->setEnabled(true);
1472
1473 sBoard canBoard = ((EthTreeWidgetItem*)selectedNodes.first()->getParentNode())->getCanBoard(selectedNodes.first()->getIndexOfBoard());
1474 if(/*core->strainCalibMode && */(canBoard.type == icubCanProto_boardType__strain) || (canBoard.type == icubCanProto_boardType__strain2) || (canBoard.type == icubCanProto_boardType__strain2c)){
1475 ui->btnStrainCalib->setEnabled(true);
1476 }else{
1477 ui->btnStrainCalib->setEnabled(false);
1478 }
1479 if(((canBoard.type == icubCanProto_boardType__strain) || (canBoard.type == icubCanProto_boardType__strain2) || (canBoard.type == icubCanProto_boardType__strain2c) || (canBoard.type == icubCanProto_boardType__6sg)) && (canBoard.status == BOARD_RUNNING) ){
1480 sgboardtype = static_cast<icubCanProto_boardType_t>(canBoard.type);
1481 ui->btnCalibrate->setEnabled(true);
1482 //ui->btnEraseEeprom->setEnabled(true);
1483 ui->btnEraseEeprom->setEnabled(false);
1484 ui->checkBoxEE->setCheckState(Qt::Unchecked); //(Qt::Checked); Qt::Unchecked
1485 ui->checkBoxEE->setEnabled(true);
1486 }else{
1487 ui->btnCalibrate->setEnabled(false);
1488 ui->btnEraseEeprom->setEnabled(false);
1489 ui->checkBoxEE->setCheckState(Qt::Unchecked); //(Qt::Checked); Qt::Unchecked
1490 ui->checkBoxEE->setEnabled(false);
1491 }
1492 }else{
1493 ui->btnChangeCanAddr->setEnabled(false);
1494 ui->btnEraseApplication->setEnabled(false);
1495 ui->btnCahngeInfo->setEnabled(false);
1496 ui->btnCalibrate->setEnabled(false);
1497 ui->btnEraseEeprom->setEnabled(false);
1498 ui->checkBoxEE->setCheckState(Qt::Unchecked);
1499 ui->checkBoxEE->setEnabled(false);
1500 ui->btnStrainCalib->setEnabled(false);
1501 }
1502 ui->btnChangeIp->setEnabled(false);
1503
1504 ui->btnJumpUpdater->setEnabled(false);
1505 ui->btnRestart->setEnabled(false);
1506 //ui->btnRestartSecs->setEnabled(false);
1507 ui->btnGoToApplication->setEnabled(false);
1508 ui->btnGoToMaintenance->setEnabled(false);
1509 ui->btnUploadApp->setEnabled(true);
1510 ui->btnEraseApplication->setEnabled(true);
1511 ui->btnUploadLoader->setEnabled(false);
1512 ui->btnUploadUpdater->setEnabled(false);
1513 ui->actionSel->setEnabled(true);
1514 ui->actionDes->setEnabled(true);
1515 }
1516
1517
1518}
1519
1520void MainWindow::emptyNode(QTreeWidgetItem *it)
1521{
1522 removeChildren(it);
1523 QTreeWidgetItem *empty = new QTreeWidgetItem(it,QStringList() << "" << "" << "?");
1524 empty->setData(0,EMPTY_NODE,true);
1525}
1526
1528{
1529 needLoading(true,true);
1530 QString ret;
1531 for (int i = 0; i<ui->devicesTree->selectedItems().count(); i++) {
1532 QTreeWidgetItem *it = ui->devicesTree->selectedItems().at(i);
1533 if(it->parent() != NULL){
1534 continue;
1535 }
1536
1537 if(it->type() == ETH_TREE_ROOT_NODE){
1539
1540
1541
1542 }else if(it->type() == CAN_TREE_ROOT_NODE){
1543 CustomTreeWidgetItem *canRootNode = (CustomTreeWidgetItem*)it;
1544 ret = canRootNode->retrieveCanBoards();
1545 setInfoRes(ret);
1546 canBoardsRetrieved(canRootNode,false);
1547 }
1548 }
1549 needLoading(false,false,ret);
1550}
1551
1552void MainWindow::removeChildren(QTreeWidgetItem *it)
1553{
1554 for(int i=it->childCount() - 1; i >= 0; i--){
1555 QTreeWidgetItem *childItem = it->takeChild(i);
1556
1557 if(childItem->type() != QTreeWidgetItem::Type){
1558 CustomTreeWidgetItem *child = (CustomTreeWidgetItem*)childItem;
1559 if(child->isCheckSelected()){
1560 child->setCheckSelected(false);
1561 }
1562 selectedNodes.removeOne(child);
1563 }
1564
1565
1566
1567 delete childItem;
1568 }
1569}
1570
1571
1572void MainWindow::populateEthBoardsNode(QTreeWidgetItem *it, bool refreshSingleNode, bool refreshAll)
1573{
1574
1575 if(refreshSingleNode){
1576 CustomTreeWidgetItem *itemToRefresh = (CustomTreeWidgetItem*)it;
1577 itemToRefresh->refresh();
1578 return;
1579 }
1580
1581 QTreeWidgetItem *parentNode = it->parent();
1582
1583
1584 if(!refreshAll && !refreshSingleNode && core->getEthBoardList().size() > 0){
1585 // Remove the first child node that has text "?"
1586 removeChildren(it);
1587 }else{
1588 emptyNode(it);
1589 return;
1590 }
1591
1592
1593 for (int i=0; i<core->getEthBoardList().size(); ++i)
1594 {
1595 if(refreshSingleNode && it->data(0,INDEX_OF_BOARD) != i){
1596 continue;
1597 }
1598
1599 if(refreshSingleNode){
1600 int count = it->childCount();
1601 for (int i=0;i<count;i++) {
1602 if(!parentNode){
1603 break;
1604 }
1605 QTreeWidgetItem *c = parentNode->child(i);
1606 foreach (CustomTreeWidgetItem *s, selectedNodes) {
1607 if(s == c || s == it){
1608 selectedNodes.removeOne(s);
1609 s->setCheckSelected(false);
1610 }
1611 }
1612 }
1613 it->parent()->removeChild(it);
1614 }
1615
1616 if(!refreshAll){
1617 EthTreeWidgetItem *child = new EthTreeWidgetItem(it,core,i);
1618
1619
1620 connect(child,SIGNAL(selectedChanged(bool)),
1621 this,SLOT(onSelectionChanged(bool)),Qt::QueuedConnection);
1622 connect(child,SIGNAL(destroyed(QObject*)),
1623 this,SLOT(onSelectionCheckDestroy(QObject*)));
1624 connect(child,SIGNAL(needLoading(bool,bool)),
1625 this,SLOT(loading(bool,bool)),Qt::DirectConnection);
1626
1627 if(selectedNodes.count() > 0){
1628 if(selectedNodes.first()->getBoardType() != child->getBoardType()){
1629 child->setCheckEnabled(false);
1630 }
1631 }
1632 }
1633
1634 }
1635
1636}
1637
1638void MainWindow::onSelectionCheckDestroy(QObject *obj)
1639{
1640 mutex1.lock();
1641 selectedNodes.removeOne((CustomTreeWidgetItem*)obj);
1642 mutex1.unlock();
1643}
1644
1645void MainWindow::onCanBoardsRetrieved(QTreeWidgetItem *it, bool refresh)
1646{
1648
1649 int type = node->type();
1650 if(type != ETH_TREE_NODE && type != CAN_TREE_ROOT_NODE){
1651 return;
1652 }
1653
1654
1655 node->setExpanded(true);
1656
1657 if(!refresh){
1658 if(node->getCanBoards().count() > 0){
1659 removeChildren(it);
1660 it->setData(0,EMPTY_NODE,false);
1661 }else{
1662 emptyNode(it);
1663 return;
1664 }
1665 }
1666
1667 if(!refresh){
1668 for(int i=0;i<node->getCanBoards().count();i++){
1669
1670 CanTreeWidgetItem *canNode = new CanTreeWidgetItem(node,core,i);
1671
1672
1673 connect(canNode,SIGNAL(selectedChanged(bool)),
1674 this,SLOT(onSelectionChanged(bool)),Qt::QueuedConnection);
1675 connect(canNode,SIGNAL(destroyed(QObject*)),
1676 this,SLOT(onSelectionCheckDestroy(QObject*)),Qt::DirectConnection);
1677 connect(canNode,SIGNAL(needLoading(bool,bool)),
1678 this,SLOT(loading(bool,bool)),Qt::DirectConnection);
1679
1680
1681 if(selectedNodes.count() > 0){
1682 if(selectedNodes.first()->getBoardType() != canNode->getBoardType()){
1683 canNode->setCheckEnabled(false);
1684 }
1685 }
1686
1687
1688 }
1689 }else{
1690 for(int i=0;i<node->childCount();i++){
1691 CanTreeWidgetItem *canNode = (CanTreeWidgetItem*)node->child(i);
1692 canNode->refresh();
1693 }
1694 }
1695
1696 checkEnableButtons();
1697
1698// needLoading(false,false);
1699}
1700
1701void MainWindow::getCanBoards(QTreeWidgetItem *it, bool refresh)
1702{
1703
1704 if(it->type() == ETH_TREE_NODE){
1705 needLoading(true,true);
1706 QString result;
1707 EthTreeWidgetItem *canNode = (EthTreeWidgetItem *)it;
1708 result = canNode->retrieveCanBoards();
1709 canBoardsRetrieved(it, refresh);
1710 needLoading(false,false,result);
1711 }
1712
1713
1714}
1715
1716void MainWindow::onDeviceExpanded(QTreeWidgetItem *it)
1717{
1718// if(it->data(0,DEVICE_LEVEL).toInt() != 2){
1719// return;
1720// }
1721
1722// if(!it->parent()->text(DEVICE).contains("ETH")){
1723// return;
1724// }
1725
1726// if(it->data(0,REFRESH_NEED).toBool()){
1727// return;
1728// }
1729
1730// for(int i=0;i<it->childCount();i++){
1731// it->child(i)->setDisabled(true);
1732// }
1733// QtConcurrent::run(this,&MainWindow::getCanBoards,it,false);
1734}
1735
1736
1737void MainWindow::onSetInfoRes(QString result)
1738{
1739 mutex1.lock();
1740 infoResult->setVisible(true);
1741 infoResult->setText(result);
1742 onDeviceSelectionChanged();
1743 mutex1.unlock();
1744}
1745
1746void MainWindow::onUpdateProgressBar(float fraction)
1747{
1748
1749 loadingMutex.lock();
1750
1751 if (fraction < 0.0f){
1752 fraction=0.0f;
1753 }else if (fraction>1.0f){
1754 fraction=1.0f;
1755 }
1756 int val = fraction*100;
1757
1758 if(progress->maximum() == 0){
1759 progress->setMaximum(100);
1760 }
1761
1762 if(val < 100){
1763 if(!progress->isEnabled()){
1764 progress->setEnabled(true);
1765 }
1766// ui->advancedGroup->setEnabled(false);
1767// ui->controlsGroup->setEnabled(false);
1768 infoResult->setVisible(true);
1769 infoResult->setText("Updating...");
1770// ui->devicesTree->setEnabled(false);
1771 }else{
1772 progress->setEnabled(false);
1773// ui->advancedGroup->setEnabled(true);
1774// ui->controlsGroup->setEnabled(true);
1775 infoResult->setText("Update Done");
1776// ui->devicesTree->setEnabled(true);
1777 }
1778 progress->setValue(val);
1779 loadingMutex.unlock();
1780
1781}
1782
1783void MainWindow::loading(bool load, bool disableAll,QString msg,bool infiniteLoad)
1784{
1785
1786 if(load/* && !isLoading*/){
1787 loadCounter++;
1788 isLoading = true;
1789 if(infiniteLoad){
1790 progress->setMaximum(0);
1791 progress->setEnabled(true);
1792 }
1793
1794 ui->strainGroup->setEnabled(false);
1795 ui->advancedGroup->setEnabled(false);
1796 ui->controlsGroup->setEnabled(false);
1797 infoResult->setVisible(true);
1798 if(disableAll){
1799 ui->devicesTree->setEnabled(false);
1800 }
1801 infoResult->setText("Loading...");
1802 }else /*if(!load && isLoading)*/{
1803 loadCounter--;
1804 if(loadCounter == 0){
1805 if(infiniteLoad){
1806 progress->setMaximum(100);
1807 progress->setEnabled(false);
1808 }
1809 ui->strainGroup->setEnabled(true);
1810 ui->advancedGroup->setEnabled(true);
1811 ui->controlsGroup->setEnabled(true);
1812 if(!ui->devicesTree->isEnabled()){
1813 ui->devicesTree->setEnabled(true);
1814 }
1815 infoResult->setVisible(true);
1816 if(!msg.isEmpty()){
1817 infoResult->setText(msg);
1818 }else{
1819 infoResult->setText("Operation Done");
1820 }
1821 isLoading = false;
1822 }
1823
1824 }
1825}
1826
1827void MainWindow::checkSelection(bool selected,CustomTreeWidgetItem *c)
1828{
1829 if(selected){
1830
1831 for(int i=0;i<ui->devicesTree->topLevelItemCount();i++){
1832 QTreeWidgetItem *topLevel = ui->devicesTree->topLevelItem(i);
1833 for(int j=0;j<topLevel->childCount();j++){
1834
1835 QTreeWidgetItem *widgItem = topLevel->child(j);
1836 if(widgItem->type() != QTreeWidgetItem::Type){
1837 CustomTreeWidgetItem *child = (CustomTreeWidgetItem*)widgItem;
1838// marco.accame: must remove this code because otherwise, if i select an eth board w/ can beneath, the can boards are not check-deselectde
1839// if(child == c){
1840// continue;
1841// }
1842 if(child->checkIsEnabled()){
1843 if(child->getBoardType() != c->getBoardType() || c->getParentNode() != child->getParentNode() ){
1844 child->setCheckEnabled(false);
1845 }
1846 }
1847
1848 for(int k=0; k<topLevel->child(j)->childCount();k++ ){
1849 QTreeWidgetItem *widgItem1 = topLevel->child(j)->child(k);
1850 if(widgItem1->type() != QTreeWidgetItem::Type){
1851 CustomTreeWidgetItem *child1 = (CustomTreeWidgetItem*)widgItem1;
1852 if(child1 == c){
1853 continue;
1854 }
1855 if(child1->checkIsEnabled()){
1856 if(child1->getBoardType() != c->getBoardType() || c->getParentNode() != child1->getParentNode() ){
1857 child1->setCheckEnabled(false);
1858 }
1859 }
1860 }
1861
1862 }
1863 }
1864
1865 }
1866
1867 }
1868
1869 }else{
1870
1871 bool found = false;
1872 for(int i=0;i<ui->devicesTree->topLevelItemCount();i++){
1873 QTreeWidgetItem *topLevel = ui->devicesTree->topLevelItem(i);
1874 for(int j=0;j<topLevel->childCount();j++){
1875 QTreeWidgetItem *widgItem = topLevel->child(j);
1876 if(widgItem->type() != QTreeWidgetItem::Type){
1877 CustomTreeWidgetItem *child = (CustomTreeWidgetItem*)widgItem;
1878 if(child->isCheckSelected() || found){
1879 found = true;
1880 break;
1881 }
1882
1883 for(int k=0; k<topLevel->child(j)->childCount();k++ ){
1884 QTreeWidgetItem *widgItem1 = topLevel->child(j)->child(k);
1885 if(widgItem1->type() != QTreeWidgetItem::Type){
1886 CustomTreeWidgetItem *child1 = (CustomTreeWidgetItem*)widgItem1;
1887 if(child1->isCheckSelected()){
1888 found = true;
1889 break;
1890 }
1891 }
1892
1893
1894 }
1895
1896 }
1897 }
1898
1899 if(found){
1900 break;
1901 }
1902 }
1903
1904 if(!found){
1905 for(int i=0;i<ui->devicesTree->topLevelItemCount();i++){
1906 QTreeWidgetItem *topLevel = ui->devicesTree->topLevelItem(i);
1907 for(int j=0;j<topLevel->childCount();j++){
1908 QTreeWidgetItem *widgItem = topLevel->child(j);
1909 if(widgItem->type() != QTreeWidgetItem::Type){
1910 CustomTreeWidgetItem *child = (CustomTreeWidgetItem*)widgItem;
1911
1912 if(!topLevel->child(j)->isDisabled()){
1913 child->setCheckEnabled(true);
1914 }
1915 for(int k=0; k<topLevel->child(j)->childCount();k++ ){
1916 if(topLevel->child(j)->data(0,REFRESH_NEED) == true){
1917 continue;
1918 }
1919 QTreeWidgetItem *widgItem1 = topLevel->child(j)->child(k);
1920 if(widgItem1->type() != QTreeWidgetItem::Type){
1921 CustomTreeWidgetItem *child1 = (CustomTreeWidgetItem*)widgItem1;
1922 if(!topLevel->child(j)->child(k)->isDisabled()){
1923 child1->setCheckEnabled(true);
1924 }
1925 }
1926
1927 }
1928 }
1929
1930
1931
1932 }
1933
1934 }
1935 }
1936 }
1937
1938}
1939
1940void MainWindow::onSelectionChanged(bool selected)
1941{
1942 loading(true);
1944
1945 if(selected){
1946 if(selectedNodes.contains(c)){
1947 loading(false);
1948 checkEnableButtons();
1949 return;
1950 }
1951
1952 selectedNodes.append(c);
1953
1954
1955 }else{
1956
1957 selectedNodes.removeOne(c);
1958
1959 }
1960
1961 checkSelection(selected,c);
1962
1963 loading(false);
1964 checkEnableButtons();
1965}
1966
1967
1968bool MainWindow::getCANaddress(CustomTreeWidgetItem *child, int &cbus, int &cadr, QString &cbustr, QString &cadrstr)
1969{
1970#if defined(_MAIN_WINDOW_SHOW_CAN_ADDRESS_IN_ADDRESS_COLUMN)
1971
1972 QString tmp = child->text(ADDRESS);
1973 QByteArray ba = tmp.toLatin1();
1974 const char *c_str2 = ba.data();
1975
1976 bool bIPprefix = false;
1977#if defined(_MAIN_WINDOW_USE_IP_PREFIX_FOR_CAN_ADDRESS)
1978 bIPprefix = (child->getParentNode()->type() == ETH_TREE_NODE) ? true : false;
1979#endif
1980
1981 if(false == bIPprefix)
1982 { // e.g., CAN2:7
1983 sscanf(c_str2, "CAN%d:%d", &cbus, &cadr);
1984 }
1985 else
1986 { // e.g., 10.0.1.21:CAN2:7
1987 int ip1, ip2, ip3, ip4;
1988 sscanf(c_str2, "%d.%d.%d.%d:CAN%d:%d", &ip1, &ip2, &ip3, &ip4, &cbus, &cadr);
1989 }
1990
1991 char strtmp[8];
1992 snprintf(strtmp, sizeof(strtmp), "%d", cadr);
1993 cadrstr = strtmp;
1994
1995 snprintf(strtmp, sizeof(strtmp), "CAN%d", cbus);
1996 cbustr = strtmp;
1997
1998#else
1999
2000 cbus = child->text(ADDRESS).remove("CAN").toInt();
2001 cadr = child->text(ID).toInt();
2002
2003 char strtmp[8];
2004 snprintf(strtmp, sizeof(strtmp), "%d", cadr);
2005 cadrstr = strtmp;
2006
2007 snprintf(strtmp, sizeof(strtmp), "CAN%d", cbus);
2008 cbustr = strtmp;
2009
2010#endif
2011
2012 return true;
2013}
2014
2015
2016
2017
2018/***************************************************************************/
2019/***************************************************************************/
2020/***************************************************************************/
2021
string ipv4tostring(eOipv4addr_t ipv4)
void setOldAddress(QString address)
void setOldInfo(QString info)
QString retrieveCanBoards(bool force=true)
void setCheckSelected(bool selected)
QTreeWidgetItem * getParentNode()
void setCanBoards(QList< sBoard > boards)
void setCheckEnabled(bool enable)
int connectTo(QString device, QString id)
void setSelectedCanBoards(QList< sBoard > selectedBoards, QString address, int deviceId=-1)
bool setEthBoardAddress(int index, QString newAddress)
bool uploadCanApplication(QString filename, QString *resultString, bool ee, QString address="", int deviceId=-1, QList< sBoard > *resultCanBoards=NULL)
QString getProcessFromUint(uint8_t id, bool isMultiCore=false)
QString getEthBoardInfo(int index)
QString getEthBoardAddress(int index)
boardInfo2_t getMoreDetails(int boardNum=EthMaintainer::ipv4OfAllSelected, QString *infoString=NULL, eOipv4addr_t *address=NULL)
QList< QPair< QString, QVariant > > getDevices()
bool setEthBoardInfo(int index, QString newInfo)
bool uploadUpdater(QString filename, QString *resultString)
void setCanBoardInfo(int bus, int id, QString newInfo, QString ethAddress="", int deviceId=-1, QString *resultString=NULL)
bool setCanBoardAddress(int bus, int id, int canType, QString newAddress, QString ethAddress="", int deviceId=-1, QString *resultString=NULL)
bool uploadEthApplication(QString filename, QString *resultString)
bool uploadLoader(QString filename, QString *resultString)
void refreshDevices()
void needSetRestartOnSelected()
void refreshCanBoardsFromEth(QTreeWidgetItem *)
void deviceSelectionChanged()
void setInfoRes(QString)
MainWindow(FirmwareUpdaterCore *core, bool adminMode, QWidget *parent=0)
void needLoading(bool, bool, QString="", bool=true)
void canBoardsRetrieved(QTreeWidgetItem *it, bool refresh)
void appendInfo(boardInfo2_t, eOipv4addr_t)
void refreshEthBoardsNode(QTreeWidgetItem *, bool refresh=false, bool refreshAll=false)
#define ETH_TREE_ROOT_NODE
#define CAN_TREE_ROOT_NODE
#define CAN_TREE_NODE
#define ETH_TREE_NODE
uint8_t board
#define BOARD_RUNNING
Definition downloader.h:45
int networkId
Definition main.cpp:151
#define CAN_UPLOAD_LOADER
#define DEVICEID
#define ADDRESS
#define CAN_UPLOAD_UPDATER
#define CAN_JUMP_UPDATER
#define CAN_UPLOAD_APP
#define REFRESH_NEED
#define CAN_TYPE
#define PROCESS
#define INDEX_OF_BOARD
#define DEVICE_LEVEL
#define INFO
#define EMPTY_NODE
#define CONNECTED
char serial[50]
Definition downloader.h:34
int appl_vers_major
Definition downloader.h:29
int prot_vers_major
Definition downloader.h:32
int prot_vers_minor
Definition downloader.h:33
int strainregsetatboot
Definition downloader.h:36
int appl_vers_minor
Definition downloader.h:30
bool applicationisrunning
Definition downloader.h:28
int bus
Definition downloader.h:25
int type
Definition downloader.h:27
int pid
Definition downloader.h:26
char add_info[50]
Definition downloader.h:40
int appl_vers_build
Definition downloader.h:31
int status
Definition downloader.h:37
int strainregsetinuse
Definition downloader.h:35