iCub-main
customtreewidgetitem.cpp
Go to the documentation of this file.
1 #include "customtreewidgetitem.h"
2 
3 CustomTreeWidgetItem::CustomTreeWidgetItem(QTreeWidgetItem *parent, QStringList fields, int indexOfBoard, FirmwareUpdaterCore *core, int type) : QTreeWidgetItem(parent,fields,type), QObject()
4 {
5  m_indexOfBoard = indexOfBoard;
6  this->core = core;
7 
8  if(type != ETH_TREE_ROOT_NODE && type != CAN_TREE_ROOT_NODE){
9  check = new SelectionCheckBox(core,this);
10  connect(check,SIGNAL(selectedChanged(bool)),
11  this,SIGNAL(selectedChanged(bool)),Qt::QueuedConnection);
12  connect(check,SIGNAL(needChangeSelection(bool)),
13  this,SLOT(onSelectedChanged(bool)));
14  connect(check,SIGNAL(destroyed(QObject*)),
15  this,SIGNAL(selectionCheckDestroy(QObject*)));
16  connect(check,SIGNAL(needLoading(bool,bool)),
17  this,SIGNAL(needLoading(bool,bool)),Qt::DirectConnection);
18  connect(core,SIGNAL(selectedEnded()),check,SLOT(onSelectEnded()),Qt::QueuedConnection);
19  this->treeWidget()->setItemWidget(this,0,check);
20  }else{
21  check = NULL;
22  }
23  parentNode = parent;
24 }
26 {
27  return parentNode;
28 }
29 
31 {
32  return m_indexOfBoard;
33 }
34 
36 {
37  check->setEnabled(enable);
38 }
39 
41 {
42  if(!check){
43  return true;
44  }
45  return check->isEnabled();
46 }
47 
49 {
50  check->setChecked(selected);//setSelected(selected);
51 
52 }
53 
54 
56 {
57 
58 }
59 
60 void CustomTreeWidgetItem::onSelectedChanged(bool selected)
61 {
62  if(type() == ETH_TREE_NODE){
64  }else if(type() == CAN_TREE_NODE){
66  ethNode->setSelectedBoard(selected,m_indexOfBoard);
67  selectedChanged(selected);
68 // QString ethAddress;
69 // if(data(0,DEVICE_LEVEL).toInt() == 3){
70 // ethAddress = parentNode->text(ADDRESS);
71 // }
72 
73  //QtConcurrent::run(core,&FirmwareUpdaterCore::setSelectedCanBoard,m_indexOfBoard,selected,ethAddress);
74  }
75 
76 }
77 
79 {
80  if(!check){
81  return false;
82  }
83  return check->isSelected();
84 }
85 
87 {
88  return text(BOARDT);
89 }
90 
92 {
93  return text(PROCESS);
94 }
95 
97 {
99 }
100 
102 {
103  return canBoards;
104 }
105 
107 {
108  sBoard board;
109  if(index < canBoards.count()){
110  board = canBoards.at(index);
111  }
112  return board;
113 
114 }
115 
117 {
118  QString result;
119  if(type() == ETH_TREE_NODE){
121  } else if(type() == CAN_TREE_ROOT_NODE){
122  QString ttt = text(DEVICEID);
123  QString device;
124  QString IDstr;
125  getDeviceID(ttt, IDstr, device);
126  int Id = IDstr.toInt();
127  //canBoards = core->getCanBoardsFromDriver(text(DEVICE),text(ID).toInt(),&result,force);
128  canBoards = core->getCanBoardsFromDriver(device,Id,&result,force);
129  }
130 
131  return result;
132 }
133 
134 void CustomTreeWidgetItem::setCanBoards(QList<sBoard> boards)
135 {
136  canBoards = boards;
137 }
138 
140 {
141  canBoards.replace(index,board);
142 }
143 
144 /***************************************************************************/
145 
146 EthTreeWidgetItem::EthTreeWidgetItem(QTreeWidgetItem *parent, FirmwareUpdaterCore *core, int indexOfBoard) : CustomTreeWidgetItem(parent,QStringList(),indexOfBoard,core,ETH_TREE_NODE)
147 {
148  refresh();
149  QTreeWidgetItem *empty = new QTreeWidgetItem(this,QStringList() << "" << "" << "?");
150  empty->setData(0,DEVICE_LEVEL,3);
151  empty->setData(0,EMPTY_NODE,true);
152 }
153 
154 
155 void EthTreeWidgetItem::setSelectedBoard(bool selected, int index)
156 {
157  if(index >= canBoards.count()){
158  return;
159  }
160  sBoard b = canBoards.at(index);
161  b.selected = selected;
162  canBoards.replace(index,b);
163 }
164 
166 {
167  char board_ipaddr[16];
168  char board_mac[32];
169 
170  char board_version[16];
171  char board_date[24];
172  char board_built[24];
173  char board_type[24];
174  char running_process[24];
175  char board_info[32];
176 
177  memset(board_ipaddr,0,sizeof(board_ipaddr));
178  memset(board_mac,0,sizeof(board_mac));
179  memset(board_version,0,sizeof(board_version));
180  memset(board_date,0,sizeof(board_date));
181  memset(board_built,0,sizeof(board_built));
182  memset(board_type,0,sizeof(board_type));
183  memset(running_process,0,sizeof(running_process));
184  memset(board_info,0,sizeof(board_info));
185 
186  EthBoard board = getBoard();
187 
188  snprintf(board_ipaddr, sizeof(board_ipaddr), "%s", board.getIPV4string().c_str());
189 
190  ACE_UINT64 mac = board.getInfo().macaddress;
191 
192 
193  snprintf(board_mac, sizeof(board_mac), "%02X-%02X-%02X-%02X-%02X-%02X",
194  (uint8_t)(mac >> 40) & 0xff,
195  (uint8_t)(mac >> 32) & 0xff,
196  (uint8_t)(mac >> 24) & 0xff,
197  (uint8_t)(mac >> 16) & 0xff,
198  (uint8_t)(mac >> 8 ) & 0xff,
199  (uint8_t)(mac ) & 0xff
200  );
201 
202 
203  snprintf(board_version, sizeof(board_version), "%s", board.getVersionfRunning().c_str());
204  snprintf(board_type, sizeof(board_type), "%s", eoboards_type2string2(eoboards_ethtype2type(board.getInfo().boardtype), eobool_true));
205  snprintf(running_process, sizeof(running_process), "%s", eouprot_process2string((eOuprot_process_t)board.getInfo().processes.runningnow));
206  snprintf(board_info, sizeof(board_info), "%s", board.getInfoOnEEPROM().c_str());
207  snprintf(board_date, sizeof(board_date), "%s", board.getDatefRunning().c_str());
208  snprintf(board_built, sizeof(board_date), "%s", board.getCompilationDateOfRunning().c_str());
209 
210  QStringList myFields;
211  myFields.append("");
212  myFields.append("");
213  myFields.append(board_type);
214 // myFields.append("");
215  myFields.append(board_ipaddr);
216  myFields.append(running_process);
217  myFields.append(board_version);
218 // myFields.append("");
219  myFields.append(board_info);
220 
221  setData(0,INDEX_OF_BOARD,m_indexOfBoard);
222  setData(0,DEVICE_LEVEL,2);
223 
224  for(int i=0;i<myFields.count();i++) {
225  setText(i,myFields.at(i));
226  }
227 
228  if((eOuprot_process_t)board.getInfo().processes.runningnow == uprot_proc_Updater){
229  setData(0,CAN_UPLOAD_LOADER,true);
230  setData(0,CAN_UPLOAD_APP,true);
231  setData(0,CAN_UPLOAD_UPDATER,false);
232  setData(0,CAN_JUMP_UPDATER,false);
233  } else if((eOuprot_process_t)board.getInfo().processes.runningnow == uprot_proc_ApplPROGupdater){
234  setData(0,CAN_UPLOAD_LOADER,false);
235  setData(0,CAN_UPLOAD_APP,false);
236  setData(0,CAN_UPLOAD_UPDATER,true);
237  setData(0,CAN_JUMP_UPDATER,true);
238  }else{
239  setData(0,CAN_UPLOAD_LOADER,false);
240  setData(0,CAN_UPLOAD_APP,false);
241  setData(0,CAN_UPLOAD_UPDATER,false);
242  setData(0,CAN_JUMP_UPDATER,false);
243  }
244 
245 
246 }
247 
248 
249 
250 /***************************************************************************/
251 
252 CanTreeWidgetItem::CanTreeWidgetItem(QTreeWidgetItem *parent, FirmwareUpdaterCore *core, int indexOfBoard) : CustomTreeWidgetItem(parent,QStringList(),indexOfBoard,core,CAN_TREE_NODE)
253 {
254  refresh();
255  //selectedChanged(getBoard().selected);
256 }
257 
259 {
260  return ((EthTreeWidgetItem*)parentNode)->getCanBoard(m_indexOfBoard);
261 }
263 {
265  sBoard b = p->getCanBoard(m_indexOfBoard);
266  b.eeprom = erase;
267  p->replaceCanBoard(m_indexOfBoard,b);
268 }
269 
271 {
272  char board_type [50]; memset (board_type, 0, sizeof(board_type));
273  char board_process [50]; memset (board_process, 0, sizeof(board_process));
274  char board_status [50]; memset (board_status, 0, sizeof(board_status));
275  char board_add_info [50]; memset (board_add_info, 0, sizeof(board_add_info));
276  char board_firmware_version [32]; memset (board_firmware_version, 0, sizeof(board_firmware_version));
277  char board_appl_minor [10]; memset (board_appl_minor, 0, sizeof(board_appl_minor));
278  char board_appl_build [10]; memset (board_appl_build, 0, sizeof(board_appl_build));
279  char board_serial [50]; memset (board_serial, 0, sizeof(board_serial));
280  char board_protocol [10]; memset (board_protocol, 0, sizeof(board_protocol));
281 
282  sBoard board = getBoard();
283 
284  snprintf(board_type, sizeof(board_type), "%s", eoboards_type2string2((eObrd_type_t)board.type, eobool_true));
285  switch (board.status)
286  {
287  case BOARD_RUNNING:
288  strcpy(board_status, "RUNNING");
289  break;
290  case BOARD_WAITING:
291  strcpy(board_status, "WAITING");
292  break;
293  case BOARD_WAITING_ACK:
294  strcpy(board_status, "WAITING_ACK");
295  break;
296  case BOARD_DOWNLOADING:
297  strcpy(board_status, "DOWNLOADING");
298  break;
299  case BOARD_OK :
300  strcpy(board_status, "OK");
301  break;
302  case BOARD_ERR:
303  strcpy(board_status, "ERR");
304  break;
305  default:
306  strcpy(board_status, "UNKNOWN");
307  break;
308  }
309 
310  if(true == board.applicationisrunning){
311  strcpy(board_process, "canApplication");
312  } else {
313  strcpy(board_process, "canBootloader");
314  }
315 
316  strncpy (board_add_info, board.add_info,32);
317 
318  if(-1 == board.appl_vers_build){
319  snprintf (board_firmware_version, sizeof(board_firmware_version), "%d.%d", board.appl_vers_major, board.appl_vers_minor);
320  } else {
321  snprintf (board_firmware_version, sizeof(board_firmware_version), "%d.%d.%d", board.appl_vers_major, board.appl_vers_minor, board.appl_vers_build);
322  }
323 
324  snprintf (board_appl_minor, sizeof(board_appl_minor), "%d",board.appl_vers_minor);
325  snprintf (board_appl_build, sizeof(board_appl_build), "%d",board.appl_vers_build);
326  snprintf (board_serial, sizeof(board_serial), "%s",board.serial);
327 
328  if((0 == board.prot_vers_major) && (0 == board.prot_vers_minor))
329  {
330  snprintf (board_protocol, sizeof(board_protocol), "N/A");
331  }
332  else
333  {
334  snprintf (board_protocol, sizeof(board_protocol), "%d.%d", board.prot_vers_major, board.prot_vers_minor);
335  }
336 
337 #if defined(_MAIN_WINDOW_SHOW_CAN_ADDRESS_IN_ADDRESS_COLUMN)
338  char prefix[20] = {0};
339 #if defined(_MAIN_WINDOW_USE_IP_PREFIX_FOR_CAN_ADDRESS)
340  bool bParentOnEth = (parentNode->type() == ETH_TREE_NODE) ? true : false;
341  if(bParentOnEth)
342  {
343  QString ipaddress = parentNode->text(ADDRESS);
344  QByteArray ba = ipaddress.toLatin1();
345  const char *c_str2 = ba.data();
346  snprintf(prefix, sizeof(prefix), "%s:", c_str2);
347  }
348 #endif
349  QStringList myFields;
350  myFields.append("");
351  myFields.append("");
352  myFields.append(board_type);
353  //myFields.append("");
354  char canadr[32]={0};
355  snprintf(canadr, sizeof(canadr), "%sCAN%d:%d", prefix, board.bus, board.pid);
356  myFields.append(canadr);
357 #else
358  QStringList myFields;
359  //myFields.append("");
360  myFields.append(board_type);
361  myFields.append(QString("%1").arg(board.pid));
362  myFields.append(QString("CAN%1").arg(board.bus));
363 #endif
364  myFields.append(board_process);
365  myFields.append(board_firmware_version);
366  //myFields.append("");
367  myFields.append(board_add_info);
368 
369 
370  for(int i=0;i<myFields.count();i++) {
371  setText(i,myFields.at(i));
372  }
373 
374  setData(0,INDEX_OF_BOARD,m_indexOfBoard);
375  setData(0,DEVICE_LEVEL,parentNode->type() == ETH_TREE_NODE ? 3 : 2);
376  setData(0,EMPTY_NODE,false);
377  setData(0,CAN_TYPE,board.type);
378 // setData(0,CAN_ERASE_EEPROM,board.eeprom);
379 // if(board.eeprom){
380 // setIcon(ERASE_EEPROM,QIcon(":/images/remove-icon-md.png"));
381 // }else{
382 // setIcon(ERASE_EEPROM,QIcon());
383 // }
384 
385  if(isCheckSelected() != board.selected) {
386  setCheckSelected(board.selected);
387  selectedChanged(board.selected);
388  }
389 }
390 
391 bool CustomTreeWidgetItem::getDeviceID(QString devicefullstring, QString &idstr, QString &devicestr)
392 {
393  QString tmp = devicefullstring;
394  QByteArray ba = tmp.toLatin1();
395  const char *c_str2 = ba.data();
396 #if 0
397  char device_cstr[64] = {0};
398  char id_cstr[64] = {0};
399  sscanf(c_str2, "%s %s", device_cstr, id_cstr);
400  devicestr = device_cstr;
401  idstr = id_cstr;
402 #else
403  string ttmp = string(c_str2);
404  std::size_t ff = ttmp.find("<");
405  std::size_t ll = ttmp.find(">");
406  string t1;
407  t1.assign(ttmp, 0, ff);
408  string t2;
409  t2.assign(ttmp, ff+1, ll-ff-1);
410  devicestr = t1.c_str();
411  idstr = t2.c_str();
412 #endif
413 
414  return true;
415 }
416 
417 
@ everyCANbus
Definition: driver.h:51
CanTreeWidgetItem(QTreeWidgetItem *, FirmwareUpdaterCore *core, int indexOfBoard)
SelectionCheckBox * check
QList< sBoard > getCanBoards()
QString retrieveCanBoards(bool force=true)
void setCheckSelected(bool selected)
QTreeWidgetItem * parentNode
bool getDeviceID(QString devicefullstring, QString &idstr, QString &devicestr)
QTreeWidgetItem * getParentNode()
void selectionCheckDestroy(QObject *)
FirmwareUpdaterCore * core
void selectedChanged(bool)
void needLoading(bool, bool)
sBoard getCanBoard(int index)
CustomTreeWidgetItem(QTreeWidgetItem *parent, QStringList fields, int indexOfBoard, FirmwareUpdaterCore *core, int type)
void setCanBoards(QList< sBoard > boards)
void replaceCanBoard(int, sBoard)
void setCheckEnabled(bool enable)
EthTreeWidgetItem(QTreeWidgetItem *parent, FirmwareUpdaterCore *core, int indexOfBoard)
void setSelectedBoard(bool, int)
QList< sBoard > getCanBoardsFromDriver(QString driver, int networkId, QString *retString, bool force=false)
QList< sBoard > getCanBoardsFromEth(QString address, QString *retString, int canID=CanPacket::everyCANbus, bool force=false)
void setSelectedEthBoard(int index, bool selected)
EthBoardList getEthBoardList()
#define ETH_TREE_ROOT_NODE
#define CAN_TREE_ROOT_NODE
#define CAN_TREE_NODE
#define ETH_TREE_NODE
uint8_t board
#define BOARD_WAITING_ACK
Definition: downloader.h:47
#define BOARD_ERR
Definition: downloader.h:50
#define BOARD_RUNNING
Definition: downloader.h:45
#define BOARD_DOWNLOADING
Definition: downloader.h:48
#define BOARD_OK
Definition: downloader.h:49
#define BOARD_WAITING
Definition: downloader.h:46
#define CAN_UPLOAD_LOADER
#define DEVICEID
#define ADDRESS
#define CAN_UPLOAD_UPDATER
#define CAN_JUMP_UPDATER
#define CAN_UPLOAD_APP
#define CAN_TYPE
#define PROCESS
#define INDEX_OF_BOARD
#define DEVICE_LEVEL
#define BOARDT
#define EMPTY_NODE
bool eeprom
Definition: downloader.h:39
bool selected
Definition: downloader.h:38