iCub-main
main.cpp
Go to the documentation of this file.
1 #include "mainwindow.h"
2 #include <QApplication>
3 #include <QCommandLineParser>
4 #include <QCommandLineOption>
5 #include <QFileInfo>
6 #include <qdebug.h>
7 #include <QDir>
8 
9 #include "firmwareupdatercore.h"
10 
11 #undef UPDATER_RELEASE
12 
13 #ifdef Q_OS_WIN
14 #include <Windows.h>
15 #endif
16 
17 #define MY_ADDR "10.0.1.104"
18 #define MY_PORT 3333
19 
20 
21 int verbosity = 1;
22 
23 using namespace yarp::os;
24 
26 {
45 };
46 
47 enum class SensorModel
48 {
49  ft45,
50  ft58
51 };
52 
53 
56 void printCanDevices(QList<sBoard> canBoards, QString onIPboard, bool slimprint);
57 int printSecondLevelDevices(FirmwareUpdaterCore*,QString device,QString id, bool slimprint);
58 int printThirdLevelDevices(FirmwareUpdaterCore*,QString device,QString id,QString board, bool forceMaintenance, bool forceApplication, bool slimprint);
59 int programEthDevice(FirmwareUpdaterCore*,QString device,QString id,QString board,QString file);
60 int programCanDevice(FirmwareUpdaterCore*, QString device, QString id, QString board, QString canLine, QString canId, QString file, bool eraseEEprom);
61 int setBoardToApplication(FirmwareUpdaterCore *core,QString device,QString id,QString board);
62 int setBoardToMaintenance(FirmwareUpdaterCore *core,QString device,QString id,QString board);
63 //int eraseEthEEprom(FirmwareUpdaterCore *core,QString device,QString id,QString board);
64 
65 int verifyOnSecondLevel(FirmwareUpdaterCore *core,QString device,QString id, const QString &targetIPaddr, const QString &targetCANline, const QString &targetCANaddr, const QString &targetFWvers);
66 int verifyOnSecondLevel_ETHboard(FirmwareUpdaterCore *core, QString device, QString id, const QString &targetIPaddr, const QString &targetFWvers);
67 int verifyOnSecondLevel_CANboard(FirmwareUpdaterCore *core, QString device, QString id, const QString &targetCANline, const QString &targetCANaddr, const QString &targetFWvers);
68 int verifyCanDevices(QList<sBoard> canBoards, const QString &targetCANline, const QString &targetCANaddr, const QString &targetFWvers);
69 int verifyOnThirdLevel_CANunderETH(FirmwareUpdaterCore *core, QString device, QString id, QString board, const QString &targetCANline, const QString &targetCANaddr, const QString &targetFWvers);
70 
71 //int queryOnSecondLevel(FirmwareUpdaterCore *core,QString device,QString id, const QString &targetIPaddr, const QString &targetCANline, const QString &targetCANaddr);
72 int queryOnSecondLevel_ETHboard(FirmwareUpdaterCore *core, QString device, QString id, const QString &targetIPaddr);
73 int queryOnSecondLevel_CANboard(FirmwareUpdaterCore *core, QString device, QString id, const QString &targetCANline, const QString &targetCANaddr);
74 int queryCanDevices(QList<sBoard> canBoards, const QString onIPboard, const QString &targetCANline, const QString &targetCANaddr);
75 int queryOnThirdLevel_CANunderETH(FirmwareUpdaterCore *core, QString device, QString id, const QString board, const QString &targetCANline, const QString &targetCANaddr);
76 int loadDatFileStrain2(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId,QString file,bool eraseEEprom);
77 int saveDatFileStrain2(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId,bool eraseEEprom);
78 int setStrainSn(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId, QString serialNumber);
79 int setStrainGainsOffsets(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId,SensorModel model);
80 int getCanBoardVersion(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId,bool save);
81 int changeCanId(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId, QString canIdNew);
82 int changeBoardIp(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString newipaddr);
83 
84 
85 int main(int argc, char *argv[])
86 {
87  Network yarp;
88  QApplication a(argc, argv);
89 
90  QApplication::setStyle("motif");
91 
92 
94 
95 #ifdef UPDATER_RELEASE
96  if(!checkApplicationLock()){
97  yDebug() << "The application is busy";
98  qDebug() << "The application is busy. Check if an instance is already running, or if it is in zombie state. If none of them ... remove the file .firmwareUpdater.singleton";
99  return 0;
100  }
101 #endif
102 
103  QCommandLineParser parser;
104  parser.addVersionOption();
105  parser.setApplicationDescription("Firmware Updater Help");
106  parser.addHelpOption();
107 
108  QCommandLineOption noGuiOption(QStringList() << "g" << "nogui", "The application starts in console mode");
109  QCommandLineOption strainCalibOption(QStringList() << "0" << "strain-acquisition", "The application starts the STRAIN acquisition mode");
110  QCommandLineOption adminOption(QStringList() << "a" << "admin", "The application starts in admin mode");
111  QCommandLineOption iniFileOption(QStringList() << "f" << "from", "Override the default ini file","config","firmwareupdater.ini");
112  QCommandLineOption addressOption(QStringList() << "s" << "address", "Override the default address","address",MY_ADDR);
113  QCommandLineOption portOption(QStringList() << "p" << "port", "Override the default port","port","3333");
114  QCommandLineOption discoverOption(QStringList() << "d" << "discover", "Discover devices");
115  QCommandLineOption deviceOption(QStringList() << "e" << "device", "Choose Device (i.e. ETH or CFW2_CAN, ESD_CAN...)","device","");
116  QCommandLineOption idOption(QStringList() << "i" << "id", "Choose a device id (i.e. eth1 or 1-2-3...)","id","");
117  QCommandLineOption boardOption(QStringList() << "t" << "eth_board", "Choose a device board (i.e. 10.0.0.1)","eth_board","");
118  QCommandLineOption programOption(QStringList() << "r" << "program", "Program devices");
119  QCommandLineOption fileOption(QStringList() << "l" << "file", "Path to a firmware file","file","");
120  QCommandLineOption ethCanLineOption(QStringList() << "c" << "can_line", "Select a can line","can_line","");
121  QCommandLineOption ethCanIdOption(QStringList() << "n" << "can_id", "Select a can id","can_id","");
122  QCommandLineOption ethForceMaintenance(QStringList() << "m" << "force-eth-maintenance", "Force the board to go in maintenace mode","");
123  QCommandLineOption ethForceApplication(QStringList() << "o" << "force-eth-application", "Force the board to go in application mode","");
124  QCommandLineOption eraseEEpromOption(QStringList() << "1" << "erase_eeprom" << "Erase EEPROM of STRAIN during FW update","");
125  QCommandLineOption verbosityOption(QStringList() << "x" << "verbosity", "Choose a verbosity level [0, 1]","verbosity","");
126  QCommandLineOption verifyOption(QStringList() << "y" << "verify", "Verify FW version [ma.mi / ma.mi.re]. returns 0 if address and FW both match, 1 if board is found but FW does not match, 2 if board is not even found","verify","");
127  QCommandLineOption queryOption(QStringList() << "q" << "query", "Queries a given address for its type and FW version [ma.mi / ma.mi.re]. prints a result on stdout. it returns 1 if it does not find a board at address");
128  QCommandLineOption loadDatFileOption(QStringList() << "z" << "load-dat-file", "Loads the calibration .dat file into STRAIN2 eeprom (pass the file.dat with -l or --file option)","","");
129  QCommandLineOption setStrainSnOption(QStringList() << "w" << "set-strain-sn", "Sets the passed serialNumber (i.e. SN001) on STRAIN2","sn","");
130  QCommandLineOption setStrainGainsOffsetOption(QStringList() << "j" << "set-strain-gains", "Sets on STRAIN2 default gains to (8,24,24,10,10,24) , adjust the offset and check if some channel saturates","","");
131  QCommandLineOption setStrainGainsSpecificOffsetOption(QStringList() << "3" << "set-strain-gains-specific", "Sets on STRAIN2 default gains to (8,24,24,10,10,24) or to (8,10,10,10,10,10) depending on the sensor type, adjust the offset and check if some channel saturates","xx","");
132  QCommandLineOption getCanBoardVersionOption(QStringList() << "b" << "get-canboard-version", "Gets Bootloader or Application version (<saveFile> must be y or n to save or not a file containing fw info)","saveFile","");
133  QCommandLineOption saveDatFileOption(QStringList() << "u" << "save-dat-file", "Saves the calibration .dat file from STRAIN2 eeprom","","");
134  QCommandLineOption changeCanIdOption(QStringList() << "k" << "change-can-id", "changes CAN ID","id-new","");
135  QCommandLineOption changeBoardIpOption(QStringList() << "2" << "change-ip-addr", "changes board IP address","ip-new","");
136 
137 
138  parser.addOption(noGuiOption);
139  parser.addOption(strainCalibOption);
140  parser.addOption(adminOption);
141  parser.addOption(iniFileOption);
142  parser.addOption(addressOption);
143  parser.addOption(portOption);
144  parser.addOption(discoverOption);
145  parser.addOption(deviceOption);
146  parser.addOption(idOption);
147  parser.addOption(boardOption);
148  parser.addOption(programOption);
149  parser.addOption(fileOption);
150  parser.addOption(ethCanLineOption);
151  parser.addOption(ethCanIdOption);
152  parser.addOption(ethForceMaintenance);
153  parser.addOption(ethForceApplication);
154  parser.addOption(eraseEEpromOption);
155  parser.addOption(verbosityOption);
156  parser.addOption(verifyOption);
157  parser.addOption(queryOption);
158  parser.addOption(loadDatFileOption);
159  parser.addOption(setStrainSnOption);
160  parser.addOption(setStrainGainsOffsetOption);
161  parser.addOption(setStrainGainsSpecificOffsetOption);
162  parser.addOption(getCanBoardVersionOption);
163  parser.addOption(saveDatFileOption);
164  parser.addOption(changeCanIdOption);
165  parser.addOption(changeBoardIpOption);
166 
167  parser.process(a);
168 
169  bool noGui = parser.isSet(noGuiOption);
170  bool adminMode = parser.isSet(adminOption);
171  //bool strainCalibMode = parser.isSet(strainCalibOption);
172  QString iniFile = parser.value(iniFileOption);
173  QString address = MY_ADDR;
174  bool bPrintUsage=false;
175  int port = MY_PORT;
176 
177  if(parser.isSet(verbosityOption))
178  {
179  QString vv = parser.value(verbosityOption);
180  verbosity = vv.toInt();
181  }
182 
183 
184  if(parser.isSet(addressOption)){
185  address = parser.value(addressOption);
186  }else{
187  if(verbosity >= 1) qDebug() << "Using default address " << MY_ADDR;
188  //yDebug() << "Using default address " << MY_ADDR;
189  bPrintUsage=true;
190  }
191 
192  if(parser.isSet(portOption)){
193  port = parser.value(portOption).toInt();
194  }else{
195  if(verbosity >= 1) qDebug() << "Using default port " << MY_PORT;
196  //yDebug() << "Using default port " << MY_PORT;
197  bPrintUsage=true;
198  }
199 
200  if (bPrintUsage){
201  //qDebug() << "Usage: " << argv[0] << " --port n --address xxx.xxx.xxx.xxx\n";
202  }
203 
204  ResourceFinder rf;
205  rf.setDefaultContext("firmwareUpdater");
206  rf.setDefaultConfigFile(iniFile.toLatin1().data());
207 
208  if(!rf.configure(argc, argv)){
209  return false;
210  }
211 
212  if(!core.init(rf, port, address, verbosity)){
213  return -1;
214  }
215  int ret = 1;
216  MainWindow w(&core,adminMode/*,strainCalibMode*/);
217  if(!noGui){
218  w.show();
219  ret = a.exec();
220  }else{
221  bool discover = parser.isSet(discoverOption);
222  bool program = parser.isSet(programOption);
223  bool verify = parser.isSet(verifyOption);
224  bool query = parser.isSet(queryOption);
225  QString device = parser.value(deviceOption);
226  QString id = parser.value(idOption);
227  QString board = parser.value(boardOption);
228  QString file = parser.value(fileOption);
229  QString canLine = parser.value(ethCanLineOption);
230  QString canId = parser.value(ethCanIdOption);
231  QString sensorModel = parser.value(setStrainGainsSpecificOffsetOption);
232 
233  if(parser.isSet(setStrainGainsSpecificOffsetOption)){
234  if(verbosity >= 1) qDebug() << "Sensor model:" << sensorModel;
235  }
236 
237  QString targetFW = parser.value(verifyOption);
238 
239  bool forceMaintenance = parser.isSet(ethForceMaintenance);
240  bool forceApplication = parser.isSet(ethForceApplication);
241  bool eraseEEprom = parser.isSet(eraseEEpromOption);
242  bool loadDatFile = parser.isSet(loadDatFileOption);
243  bool saveDatFile = parser.isSet(saveDatFileOption);
244  bool setSn = parser.isSet(setStrainSnOption);
245  QString serialNumber = parser.value(setStrainSnOption);
246  bool setGains = parser.isSet(setStrainGainsOffsetOption);
247  bool setGainsSpecific = parser.isSet(setStrainGainsSpecificOffsetOption);
248  QString saveVersion = parser.value(getCanBoardVersionOption);
249  bool getVersion = parser.isSet(getCanBoardVersionOption);
250  bool changeCanID = parser.isSet(changeCanIdOption);
251  bool changeIp = parser.isSet(changeBoardIpOption);
252 
253 
254  QString canIdNew = parser.value(changeCanIdOption);
255  QString newIp = parser.value(changeBoardIpOption);
256 
257 
258 
259  core.setVerbosity(verbosity);
260 
261  action_t action = action_none;
262 
263  // check mutual exclusive actions: discover or query or verify or program or forceapplication or forcemaintenance
264  // to do: move code into functions
265 
266  if((discover) && (action_impossible != action))
267  {
268  if(action == action_none)
269  {
270  action = action_discover;
271  }
272  else
273  {
274  action = action_impossible;
275  }
276  }
277 
278  if((query) && (action_impossible != action))
279  {
280  if(action == action_none)
281  {
282  action = action_query;
283  }
284  else
285  {
286  action = action_impossible;
287  }
288  }
289 
290  if((verify) && (action_impossible != action))
291  {
292  if(action == action_none)
293  {
294  action = action_verify;
295  }
296  else
297  {
298  action = action_impossible;
299  }
300  }
301 
302  if((program) && (action_impossible != action))
303  {
304  if(action == action_none)
305  {
306  action = action_program;
307  }
308  else
309  {
310  action = action_impossible;
311  }
312  }
313 
314  if((forceMaintenance) && (action_impossible != action))
315  {
316  if(action == action_none)
317  {
318  action = action_forcemaintenance;
319  }
320  else
321  {
322  action = action_impossible;
323  }
324  }
325 
326  if((forceApplication) && (action_impossible != action))
327  {
328  if(action == action_none)
329  {
330  action = action_forceapplication;
331  }
332  else
333  {
334  action = action_impossible;
335  }
336  }
337 
338  if((loadDatFile) && (action_impossible != action))
339  {
340  if(action == action_none)
341  {
342  action = action_loaddatfile;
343  }
344  else
345  {
346  action = action_impossible;
347  }
348  }
349 
350  if((setSn) && (action_impossible != action))
351  {
352  if(action == action_none)
353  {
354  action = action_setstrainsn;
355  }
356  else
357  {
358  action = action_impossible;
359  }
360  }
361 
362  if((setGains) && (action_impossible != action))
363  {
364  if(action == action_none)
365  {
367  }
368  else
369  {
370  action = action_impossible;
371  }
372  }
373 
374  if((setGainsSpecific) && (action_impossible != action))
375  {
376  if(action == action_none)
377  {
379  }
380  else
381  {
382  action = action_impossible;
383  }
384  }
385 
386  if((getVersion) && (action_impossible != action))
387  {
388  if(action == action_none)
389  {
390  action = action_getcanboardversion;
391  }
392  else
393  {
394  action = action_impossible;
395  }
396  }
397 
398  if((saveDatFile) && (action_impossible != action))
399  {
400  if(action == action_none)
401  {
402  action = action_savedatfile;
403  }
404  else
405  {
406  action = action_impossible;
407  }
408  }
409 
410 
411  if((changeCanID) && (action_impossible != action))
412  {
413  if(action == action_none)
414  {
415  action = action_changeCanId;
416  }
417  else
418  {
419  action = action_impossible;
420  }
421  }
422 
423  if((changeIp) && (action_impossible != action))
424  {
425  if(action == action_none)
426  {
427  action = action_changeBoardIp;
428  }
429  else
430  {
431  action = action_impossible;
432  }
433  }
434 
435  // now use a switch case
436 
437  switch(action)
438  {
439  default:
440  case action_none:
441  {
442  ret = 1;
443 
444  if(verbosity >= 1) qDebug() << "specify at least one option amongst discover / verify / program / forcemaintenance / forceapplication";
445 
446  } break;
447 
448  case action_impossible:
449  {
450  ret = 1;
451 
452  if(verbosity >= 1) qDebug() << "specify only one option amongst discover / verify / program / forcemaintenance / forceapplication";
453 
454  } break;
455 
456  case action_discover:
457  {
458  ret = 1;
459  //yDebug() << "discover";
460 
461  if(device.isEmpty()){
462  if(verbosity >= 1) qDebug() << "Need a device to be set";
463  }else if(id.isEmpty()){
464  if(verbosity >= 1) qDebug() << "Need an id to be set";
465  }else{
466 
467  if(board.isEmpty()){
468  ret = printSecondLevelDevices(&core,device,id, true);
469  }else{
470  ret = printThirdLevelDevices(&core,device,id,board,true,false, true);
471  }
472  }
473 
474  } break;
475 
476  case action_query:
477  {
478  ret = 1;
479  //yDebug() << "query";
480 
481  if(device.isEmpty())
482  {
483  if(verbosity >= 1) qDebug() << "Need a device";
484  }
485  else if (device.contains("ETH"))
486  {
487  // second level eth (ipaddr + ethfwversion) or third level can_under_eth (ipaddr+canaddr + canfwversion) or ..
488  if(board.isEmpty())
489  {
490  if(verbosity >= 1) qDebug() << "Need an IP address";
491  }
492  else if((canLine.isEmpty()) && (canId.isEmpty()))
493  {
494  // we query the fw version of an eth board
495  ret = queryOnSecondLevel_ETHboard(&core, device, id, board);
496  }
497  else if((!canLine.isEmpty()) && (!canId.isEmpty()))
498  {
499  // we query the fw version of a can board below eth
500  // FirmwareUpdater --nogui --verbosity 1 --device ETH --id eth1 --eth_board 10.0.1.1 --can_line 2 --can_id 2 --query
501  ret = queryOnThirdLevel_CANunderETH(&core, device, id, board, canLine, canId);
502  }
503  else
504  {
505  if(verbosity >= 1) qDebug() << "Must have both can line and address";
506  }
507  }
508  else
509  {
510  // second level cfw2 or other can driver
511  if((canLine.isEmpty()) || (canId.isEmpty()))
512  {
513  if(verbosity >= 1) qDebug() << "Must have both can line and address";
514  }
515  else
516  {
517  // we query the fw version of a can board below cfw2
518  ret = queryOnSecondLevel_CANboard(&core, device, id, canLine, canId);
519  }
520 
521  }
522 
523  } break;
524 
525 
526  case action_verify:
527  {
528  ret = 2;
529  //yDebug() << "verify";
530 
531  if(device.isEmpty())
532  {
533  if(verbosity >= 1) qDebug() << "Need a device";
534  }
535  else if (device.contains("ETH"))
536  {
537  // second level eth (ipaddr + ethfwversion) or third level can_under_eth (ipaddr+canaddr + canfwversion) or ..
538  if(board.isEmpty())
539  {
540  if(verbosity >= 1) qDebug() << "Need an ip address";
541  }
542  else if(targetFW.isEmpty())
543  {
544  if(verbosity >= 1) qDebug() << "Need a target fw version";
545  }
546  else if((canLine.isEmpty()) && (canId.isEmpty()))
547  {
548  // we evaluate the fw version of an eth board
549  ret = verifyOnSecondLevel_ETHboard(&core, device, id, board, targetFW);
550  }
551  else if((!canLine.isEmpty()) && (!canId.isEmpty()))
552  {
553  // we evaluate the fw version of a can board below eth
554  // FirmwareUpdater --nogui --verbosity 1 --device ETH --id eth1 --eth_board 10.0.1.1 --can_line 2 --can_id 2 --verify 1.3.7
555  ret = verifyOnThirdLevel_CANunderETH(&core, device, id, board, canLine, canId, targetFW);
556  }
557  else
558  {
559  if(verbosity >= 1) qDebug() << "Must have both can line and address";
560  }
561  }
562  else
563  {
564  // second level cfw2 or other can driver
565  if(targetFW.isEmpty())
566  {
567  if(verbosity >= 1) qDebug() << "Need a target fw version";
568  }
569  else if((canLine.isEmpty()) || (canId.isEmpty()))
570  {
571  if(verbosity >= 1) qDebug() << "Must have both can line and address";
572  }
573  else
574  {
575  // we evaluate the fw version of a can board below eth
576  ret = verifyOnSecondLevel_CANboard(&core, device, id, canLine, canId, targetFW);
577  }
578 
579  }
580 
581  } break;
582 
583  case action_program:
584  {
585  ret = 1;
586  //yDebug() << "program";
587 
588  if(device.isEmpty()){
589  if(verbosity >= 1) qDebug() << "Need a device to be set";
590  }else if(id.isEmpty()){
591  if(verbosity >= 1) qDebug() << "Need an id to be set";
592  }else if(board.isEmpty() && device.contains("ETH")){
593  if(verbosity >= 1) qDebug() << "Need a board to be set";
594  }else if(file.isEmpty()){
595  if(verbosity >= 1) qDebug() << "Need a file path to be set";
596  }else if(canLine.isEmpty() && canId.isEmpty()){
597  ret = programEthDevice(&core,device,id,board,file);
598 // if(eraseEEprom && ret == 0){
599 // ret = eraseEthEEprom(&core,device,id,board);
600 // }
601  }else{
602  if(canLine.isEmpty()){
603  if(verbosity >= 1) qDebug() << "Need a can line to be set";
604  } else if(canId.isEmpty()){
605  if(verbosity >= 1) qDebug() << "Need a can id to be set";
606  }else{
607  ret = programCanDevice(&core,device,id,board,canLine,canId,file,eraseEEprom);
608  }
609  }
610 
611  } break;
612 
614  {
615  ret = 1;
616  //yDebug() << "forcemaintenance";
617 
618  if(device.isEmpty()){
619  if(verbosity >= 1) qDebug() << "Need a device to be set";
620  }else if(id.isEmpty()){
621  if(verbosity >= 1) qDebug() << "Need an id to be set";
622  }else if(board.isEmpty()){
623  if(verbosity >= 1) qDebug() << "Need a board to be set";
624  }else{
625 
626  ret = setBoardToMaintenance(&core,device,id,board);
627  }
628 
629  } break;
630 
632  {
633  ret = 1;
634  //yDebug() << "forceapplication";
635 
636  if(device.isEmpty()){
637  if(verbosity >= 1) qDebug() << "Need a device to be set";
638  }else if(id.isEmpty()){
639  if(verbosity >= 1) qDebug() << "Need an id to be set";
640  }else if(board.isEmpty()){
641  if(verbosity >= 1) qDebug() << "Need a board to be set";
642  }else{
643 
644  ret = setBoardToApplication(&core,device,id,board);
645  }
646 
647  } break;
648 
649  case action_loaddatfile:
650  {
651  ret = 1;
652 
653  if(device.isEmpty()){
654  if(verbosity >= 1) qDebug() << "Need a device to be set";
655  }else if(id.isEmpty()){
656  if(verbosity >= 1) qDebug() << "Need an id to be set";
657  }else if(file.isEmpty()){
658  if(verbosity >= 1) qDebug() << "Need a file path to be set";
659  }else{
660  if(!device.contains("ETH") && canLine.isEmpty()){
661  if(verbosity >= 1) qDebug() << "Need a can line to be set";
662  } else if(!device.contains("ETH") && canId.isEmpty()){
663  if(verbosity >= 1) qDebug() << "Need a can id to be set";
664  }else{
665  ret = loadDatFileStrain2(&core,device,id,board,canLine,canId,file,eraseEEprom);
666  }
667  }
668 
669  } break;
670 
671  case action_setstrainsn:
672  {
673  ret = 1;
674 
675  if(device.isEmpty()){
676  if(verbosity >= 1) qDebug() << "Need a device to be set";
677  }else if(id.isEmpty()){
678  if(verbosity >= 1) qDebug() << "Need an id to be set";
679  }else{
680  if(!device.contains("ETH") && canLine.isEmpty()){
681  if(verbosity >= 1) qDebug() << "Need a can line to be set";
682  } else if(!device.contains("ETH") && canId.isEmpty()){
683  if(verbosity >= 1) qDebug() << "Need a can id to be set";
684  }else if(!device.contains("ETH") && serialNumber.isEmpty()){
685  if(verbosity >= 1) qDebug() << "Need a serial number to be set";
686  }else{
687  ret = setStrainSn(&core,device,id,board,canLine,canId,serialNumber);
688  }
689  }
690 
691  } break;
692 
694  {
695  ret = 1;
696 
697  if(device.isEmpty()){
698  if(verbosity >= 1) qDebug() << "Need a device to be set";
699  }else if(id.isEmpty()){
700  if(verbosity >= 1) qDebug() << "Need an id to be set";
701  }else{
702  if(!device.contains("ETH") && canLine.isEmpty()){
703  if(verbosity >= 1) qDebug() << "Need a can line to be set";
704  } else if(!device.contains("ETH") && canId.isEmpty()){
705  if(verbosity >= 1) qDebug() << "Need a can id to be set";
706  }else{
707  ret = setStrainGainsOffsets(&core,device,id,board,canLine,canId,SensorModel::ft45);
708  }
709  }
710 
711  } break;
712 
714  {
715  ret = 1;
716 
717  if(device.isEmpty()){
718  if(verbosity >= 1) qDebug() << "Need a device to be set";
719  }else if(id.isEmpty()){
720  if(verbosity >= 1) qDebug() << "Need an id to be set";
721  }else{
722  if(!device.contains("ETH") && canLine.isEmpty()){
723  if(verbosity >= 1) qDebug() << "Need a can line to be set";
724  } else if(!device.contains("ETH") && canId.isEmpty()){
725  if(verbosity >= 1) qDebug() << "Need a can id to be set";
726  }else{
727 
728  if(sensorModel=="FT58")
729  {
730  ret = setStrainGainsOffsets(&core,device,id,board,canLine,canId,SensorModel::ft58);
731  }
732  else
733  {
734  ret = setStrainGainsOffsets(&core,device,id,board,canLine,canId,SensorModel::ft45);
735  }
736  }
737  }
738 
739  } break;
740 
742  {
743  ret = 1;
744 
745  if(device.isEmpty()){
746  if(verbosity >= 1) qDebug() << "Need a device to be set";
747  }else if(id.isEmpty()){
748  if(verbosity >= 1) qDebug() << "Need an id to be set";
749  }else{
750  if(!device.contains("ETH") && canLine.isEmpty()){
751  if(verbosity >= 1) qDebug() << "Need a can line to be set";
752  } else if(!device.contains("ETH") && canId.isEmpty()){
753  if(verbosity >= 1) qDebug() << "Need a can id to be set";
754  }else{
755  bool save;
756  if(saveVersion == "y") save = true;
757  else save = false;
758  ret = getCanBoardVersion(&core,device,id,board,canLine,canId,save);
759  }
760  }
761 
762  } break;
763 
764  case action_savedatfile:
765  {
766  ret = 1;
767 
768  if(device.isEmpty()){
769  if(verbosity >= 1) qDebug() << "Need a device to be set";
770  }else if(id.isEmpty()){
771  if(verbosity >= 1) qDebug() << "Need an id to be set";
772  }else{
773  if(!device.contains("ETH") && canLine.isEmpty()){
774  if(verbosity >= 1) qDebug() << "Need a can line to be set";
775  } else if(!device.contains("ETH") && canId.isEmpty()){
776  if(verbosity >= 1) qDebug() << "Need a can id to be set";
777  }else{
778  ret = saveDatFileStrain2(&core,device,id,board,canLine,canId,eraseEEprom);
779  }
780  }
781 
782  } break;
783 
784  case action_changeCanId:
785  {
786  ret = 1;
787  if(device.isEmpty()){
788  if(verbosity >= 1) qDebug() << "Need a device to be set";
789  }else if(id.isEmpty()){
790  if(verbosity >= 1) qDebug() << "Need an id to be set";
791  }else{
792  if(!device.contains("ETH") && canLine.isEmpty()){
793  if(verbosity >= 1) qDebug() << "Need a can line to be set";
794  } else if(!device.contains("ETH") && canId.isEmpty()){
795  if(verbosity >= 1) qDebug() << "Need a can id to be set";
796  }else{
797  ret = changeCanId(&core,device,id,board,canLine,canId,canIdNew);
798  }
799  }
800 
801  } break;
802 
804  {
805  ret = 1;
806  if(device.isEmpty()){
807  if(verbosity >= 1) qDebug() << "Need a device to be set";
808  }else if(id.isEmpty()){
809  if(verbosity >= 1) qDebug() << "Need an id to be set";
810  }else{
811  if(!device.contains("ETH") || board.isEmpty() || newIp.isEmpty()){
812  if(verbosity >= 1) qDebug() << "\nNeed a ETH device, the old IP and the new one to be set\n i.e.FirmwareUpdater -g -e ETH -i eth1 -t 10.0.1.1 -2 10.0.1.2";
813  }else{
814  ret = changeBoardIp(&core,device,id,board, newIp);
815  }
816  }
817 
818  } break;
819 
820  };
821 #if 0
822 // old code now substituted by the switch-case
823  if(discover){
824  if(device.isEmpty()){
825  if(verbosity >= 1) qDebug() << "Need a device to be set";
826  }else if(id.isEmpty()){
827  if(verbosity >= 1) qDebug() << "Need an id to be set";
828  }else{
829 
830  if(board.isEmpty()){
831  ret = printSecondLevelDevices(&core,device,id);
832  }else{
833  ret = printThirdLevelDevices(&core,device,id,board,forceMaintenance,forceApplication);
834  }
835  }
836  }else if(program){
837  if(device.isEmpty()){
838  if(verbosity >= 1) qDebug() << "Need a device to be set";
839  }else if(id.isEmpty()){
840  if(verbosity >= 1) qDebug() << "Need an id to be set";
841  }else if(board.isEmpty() && device.contains("ETH")){
842  if(verbosity >= 1) qDebug() << "Need a board to be set";
843  }else if(file.isEmpty()){
844  if(verbosity >= 1) qDebug() << "Need a file path to be set";
845  }else if(canLine.isEmpty() && canId.isEmpty()){
846  ret = programEthDevice(&core,device,id,board,file);
847 // if(eraseEEprom && ret == 0){
848 // ret = eraseEthEEprom(&core,device,id,board);
849 // }
850  }else{
851  if(canLine.isEmpty()){
852  if(verbosity >= 1) qDebug() << "Need a can line to be set";
853  } else if(canId.isEmpty()){
854  if(verbosity >= 1) qDebug() << "Need a can id to be set";
855  }else{
856  ret = programCanDevice(&core,device,id,board,canLine,canId,file,eraseEEprom);
857  }
858  }
859  }else if(forceApplication || forceMaintenance){
860  if(device.isEmpty()){
861  if(verbosity >= 1) qDebug() << "Need a device to be set";
862  }else if(id.isEmpty()){
863  if(verbosity >= 1) qDebug() << "Need an id to be set";
864  }else if(board.isEmpty()){
865  if(verbosity >= 1) qDebug() << "Need a board to be set";
866  }else{
867  if(forceApplication){
868  ret = setBoardToApplication(&core,device,id,board);
869  }else {
870  ret = setBoardToMaintenance(&core,device,id,board);
871  }
872 
873  }
874 // if(eraseEEprom && ret == 0){
875 // ret = eraseEthEEprom(&core,device,id,board);
876 // }
877  }
878 #endif
879 
880  }
881 
882 
883 
884 #ifdef UPDATER_RELEASE
886 #endif
887 
888  return ret;
889 }
890 
891 
892 /**************************************************/
893 
894 //int eraseEthEEprom(FirmwareUpdaterCore *core,QString device,QString id,QString board)
895 //{
896 // int boards = core->connectTo(device,id);
897 // if(boards > 0){
898 // if(device.contains("ETH")){
899 // core->setSelectedEthBoard(board,true);
900 // core->eraseEthEprom();
901 // }
902 // }
903 // return 0;
904 //}
905 
906 /* // the chosen gains:
907  const strain2_ampl_discretegain_t ampsets[NUMofCHANNELS] =
908  {
909  ampl_gain08, ampl_gain24, ampl_gain24,
910  ampl_gain10, ampl_gain10, ampl_gain24
911  };
912 
913  yDebug() << "strain2-amplifier-tuning: STEP-1. imposing gains which are different of each channel";
914 
915  for(int channel=0; channel<NUMofCHANNELS; channel++)
916  {
917  yDebug() << "strain2-amplifier-tuning: STEP-1. on channel" << channel << "we impose gain =" << strain_amplifier_discretegain2float(ampsets[channel]);
918 
919  strain_set_amplifier_discretegain(bus, target_id, channel, ampsets[channel], regset, errorstring);
920 
921  // i wait some time
922  yarp::os::Time::delay(1.0);
923  }
924 
925  */
926 int changeBoardIp(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString newipaddr)
927 {
928  // FirmwareUpdater -g -e ETH -i eth1 -t 10.0.1.1 -2 10.0.1.2
929 
930  QString retString;
931  bool ret;
932  string msg;
933  int index;
934  QString result;
935 
936  ret = setBoardToMaintenance(core,device,id,board);
937  if(!core->isBoardInMaintenanceMode(board)){
938  yError("ETH board is not present or not in maintenace mode!!\n");
939  return false;
940  }
941 
942  EthBoardList ethl = core->getEthBoardList();
943 
944  for(int i = 0 ; i< ethl.size(); i++){
945  if(ethl[i].getIPV4string() == board.toStdString()) index = i;
946  }
947 
948  ret = core->setEthBoardAddress(index, newipaddr);
949  if(ret) yInfo() << "Cahnge board IP Succeded !!!";
950  else yError() << "Cahnge board IP Failed !!!";
951  return -1;
952 }
953 
954 int changeCanId(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId, QString canIdNew)
955 {
956  // FirmwareUpdater -g -e SOCKETCAN -i 0 -c 0 -n 1 -k 2
957  // FirmwareUpdater -g -e ETH -i eth1 -t 10.0.1.1 -c 1 -n 1 -k 2
958 
959  QList <sBoard> canBoards;
960  QString retString;
961  bool ret;
962  int ret1;
963  string msg;
964 
965  if(device.contains("SOCKETCAN"))
966  {
967 
968  if (canId.toInt() <1 || canId.toInt() >= 15 || canIdNew.toInt() <1 || canIdNew.toInt() >= 15){
969  yError("Invalid board address!\n");
970  return false;
971  }
972 
973  canBoards = core->getCanBoardsFromDriver(device,id.toInt(),&retString,true);
974 
975  if(canBoards.count() > 0)
976  {
977  core->getDownloader()->change_card_address(canLine.toInt(),canId.toInt(),canIdNew.toInt(),canBoards[0].type);
978  yInfo() << "Cahnge CAN ID message sent !!!";
979 
980  } else {
981  yError() << "No CAN board found, stopped!";
982  return false;
983  }
984  }
985  else if(device.contains("ETH"))
986  {
987 
988  QString result;
989  ret = setBoardToMaintenance(core,device,id,board);
990  if(!core->isBoardInMaintenanceMode(board)){
991  yError("ETH board is not present or not in maintenace mode!!\n");
992  return false;
993  }
994  canBoards = core->getCanBoardsFromEth(board,&result,canLine.toInt(),true);
995  if(canBoards.count() > 0)
996  {
997  core->setSelectedCanBoards(canBoards,board,-1);
998  ret = core->setCanBoardAddress(canLine.toInt(),canId.toInt(),canBoards[0].type,canIdNew,board,-1,&result);
999  if(ret) yInfo() << "Cahnge CAN ID Succeded !!!";
1000  else yError() << "Cahnge CAN ID Failed !!!";
1001 
1002  } else {
1003  yError() << "No CAN board found, stopped!";
1004  return false;
1005  }
1006  }
1007 
1008  return -1;
1009 }
1010 
1011 int getCanBoardVersion(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId,bool save)
1012 {
1013  QList <sBoard> canBoards;
1014  QString retString;
1015  int ret;
1016  string msg;
1017 
1018  if(device.contains("SOCKETCAN"))
1019  {
1020  if (canId.toInt() <1 || canId.toInt() >= 15){
1021  yError("Invalid board address!\n");
1022  return false;
1023  }
1024 
1025  canBoards = core->getCanBoardsFromDriver(device,id.toInt(),&retString,true);
1026 
1027 
1028  }
1029  else if(device.contains("ETH"))
1030  {
1031  QString result, ret;
1032  ret = setBoardToMaintenance(core,device,id,board);
1033  if(!core->isBoardInMaintenanceMode(board)){
1034  yError("ETH board is not present or not in maintenace mode!!\n");
1035  return false;
1036  }
1037  canBoards = core->getCanBoardsFromEth(board,&result,canLine.toInt(),true);
1038  }
1039 
1040  if(canBoards.count() > 0 && icubCanProto_boardType__strain2 == canBoards[0].type)
1041  {
1042  ofstream myfile;
1043  string prefix = "Application ";
1044 
1045  if(!canBoards[0].applicationisrunning && save)
1046  {
1047  try{
1048  myfile.open ("firmware-info.txt", std::ios_base::app);
1049  prefix = " Bootloader ";
1050  myfile << canBoards[0].appl_vers_major << "." << canBoards[0].appl_vers_minor << "\n";
1051  myfile.close();
1052  yInfo() << prefix << " version : " << canBoards[0].appl_vers_major << "." << canBoards[0].appl_vers_minor;
1053  }
1054  catch (std::ifstream::failure e) {
1055  yError() << "Exception opening file";
1056  return false;
1057  }
1058  }else if(canBoards[0].applicationisrunning && save)
1059  {
1060  try{
1061  myfile.open ("firmware-info.txt", std::ios_base::app);
1062  prefix = " Application ";
1063  myfile << canBoards[0].appl_vers_major << "." << canBoards[0].appl_vers_minor << "." << canBoards[0].appl_vers_build << "\n";
1064  myfile.close();
1065  yInfo() << prefix << " version : " << canBoards[0].appl_vers_major << "." << canBoards[0].appl_vers_minor << "." << canBoards[0].appl_vers_build;
1066  }
1067  catch (std::ifstream::failure e) {
1068  yError() << "Exception opening file";
1069  return false;
1070  }
1071  }
1072 
1073  } else {
1074  yError() << "No CAN board found, stopped!";
1075  return false;
1076  }
1077 
1078  return -1;
1079 }
1080 
1081 
1082 
1083 int setStrainGainsOffsets(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId,SensorModel model)
1084 {
1085  //10-2020 - davide.tome@iit.it
1086  //This method is used to set the PGA gains to
1087  // i.e. FirmwareUpdater -g -e ETH -i eth1 -t 10.0.1.1 -c 1 -n 13 -z -w SN001
1088 
1089  QList <sBoard> canBoards;
1090  QString retString;
1091  int ret;
1092  string msg;
1093  std::vector<strain2_ampl_discretegain_t> gains(0);
1094  std::vector<int16_t> targets(0);
1095 
1096  std::vector<strain2_ampl_discretegain_t> ampsets = {
1099 
1100  if (model == SensorModel::ft45) {
1101  ampsets = {ampl_gain08, ampl_gain24, ampl_gain24,
1103  } else {
1104  ampsets = {ampl_gain08, ampl_gain10, ampl_gain10,
1106  }
1107 
1108  for(int i = 0; i < 6; i++){ targets.push_back(0); gains.push_back(ampsets[i]);}
1109 
1110  if(device.contains("SOCKETCAN"))
1111  {
1112  if (canId.toInt() <1 || canId.toInt() >= 15){
1113  yError("Invalid board address!\n");
1114  return false;
1115  }
1116 
1117  canBoards = core->getCanBoardsFromDriver(device,id.toInt(),&retString,true);
1118 
1119 
1120  }
1121  else if(device.contains("ETH"))
1122  {
1123  QString result, ret;
1124  ret = setBoardToMaintenance(core,device,id,board);
1125  if(!core->isBoardInMaintenanceMode(board)){
1126  yError("ETH board is not present or not in maintenace mode!!\n");
1127  return false;
1128  }
1129  canBoards = core->getCanBoardsFromEth(board,&result,canLine.toInt(),true);
1130  }
1131 
1132  if(canBoards.count() > 0 && icubCanProto_boardType__strain2 == canBoards[0].type)
1133  {
1134  string error = "e";
1135 
1136  yDebug() << "strain2-amplifier-tuning: STEP-1. imposing gains which are different of each channel";
1137 
1138  core->getDownloader()->strain_calibrate_offset2(canLine.toInt(), canId.toInt(), icubCanProto_boardType__strain2, gains, targets, &msg);
1139  yarp::os::Time::delay(0.2);
1140  core->getDownloader()->strain_save_to_eeprom(canLine.toInt(),canId.toInt(), &msg);
1141  yInfo() << "Gains Saved!";
1142 
1143  } else {
1144  yError() << "No STRAIN2 board found, stopped!";
1145  return false;
1146  }
1147 
1148  unsigned int adc[6];
1149  char tempbuf [250];
1150  bool failCh = false;
1151 
1152  for(int i=0; i<6; i++){
1153 
1154  if(i==0)ret = core->getDownloader()->strain_get_adc (canLine.toInt(),canId.toInt(), i, adc[i], 0, &msg);
1155  else ret |= core->getDownloader()->strain_get_adc (canLine.toInt(),canId.toInt(), i, adc[i], 0, &msg);
1156 
1157  unsigned int z = static_cast<int>(adc[i])-32768;
1158  sprintf(tempbuf,"%d",z);
1159  int t = std::stoi(tempbuf);
1160  if(t < -500 || t > 500) failCh = true;
1161  yDebug() << i << " " << std::stoi(tempbuf);
1162  yarp::os::Time::delay(0.2);
1163  }
1164 
1165  if(failCh){
1166  yError() << "Strange value on Channels ADC readings...";
1167  return false;
1168  }else{
1169  yInfo() << "Good values in ADC channels reading!";
1170  }
1171 
1172  /* if(device.contains("ETH")){
1173  ret = setBoardToApplication(core,device,id,board);
1174  if(core->isBoardInMaintenanceMode(board)){
1175  yError("ETH board not switched to application mode!!\n");
1176  return false;
1177  } else yInfo() << "ETH board ready!";
1178  } */
1179 
1180 
1181  return -1;
1182 }
1183 
1184 int setStrainSn(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId, QString serialNumber)
1185 {
1186  //10-2020 - davide.tome@iit.it
1187  //This method is used to set the SN in the STRAIN EEPROM
1188  // i.e. FirmwareUpdater -g -e ETH -i eth1 -t 10.0.1.1 -c 1 -n 13 -z -w SN001
1189 
1190  QList <sBoard> canBoards;
1191  QString retString;
1192  int ret;
1193  string msg;
1194 
1195  QByteArray string = serialNumber.toLatin1();
1196  char * sn = string.data();
1197 
1198  if(device.contains("SOCKETCAN"))
1199  {
1200  if (canId.toInt() <1 || canId.toInt() >= 15){
1201  yError("Invalid board address!\n");
1202  return false;
1203  }
1204 
1205  canBoards = core->getCanBoardsFromDriver(device,id.toInt(),&retString,true);
1206 
1207  }
1208  else if(device.contains("ETH"))
1209  {
1210  QString result, ret;
1211  ret = setBoardToMaintenance(core,device,id,board);
1212  if(!core->isBoardInMaintenanceMode(board)){
1213  yError("ETH board is not present or not in maintenace mode!!\n");
1214  return false;
1215  }
1216  canBoards = core->getCanBoardsFromEth(board,&result,canLine.toInt(),true);
1217  }
1218 
1219 
1220  if(canBoards.count() > 0 && icubCanProto_boardType__strain2 == canBoards[0].type)
1221  {
1222 
1223 
1224  core->getDownloader()->strain_set_serial_number(canLine.toInt(),canId.toInt(), sn);
1225  core->getDownloader()->strain_save_to_eeprom(canLine.toInt(),canId.toInt(), &msg);
1226 
1227  yInfo() << "Serial Number Saved!";
1228 
1229 
1230  } else {
1231  yError() << "No STRAIN2 board found, stopped!";
1232  return false;
1233  }
1234 
1235  /* if(device.contains("ETH")){
1236  ret = setBoardToApplication(core,device,id,board);
1237  if(core->isBoardInMaintenanceMode(board)){
1238  yError("ETH board not switched to application mode!!\n");
1239  return false;
1240  } else yInfo() << "ETH board ready!";
1241  } */
1242 
1243  return -1;
1244 }
1245 
1246 int loadDatFileStrain2(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId,QString file,bool eraseEEprom)
1247 {
1248  //09-2020 - davide.tome@iit.it
1249  //This method is used to load a calibration file into the eeprom of the STRAIN2 using the dedicated CLI option -z/--load-dat-file (and -l/--file option to specify the file to be loaded)
1250  // i.e. FirmwareUpdater -g -e SOCKETCAN -i 0 -c 1 -n 13 -z -l calibrationDataSN003.dat
1251  // i.e. FirmwareUpdater -g -e ETH -i eth1 -t 10.0.1.1 -c 1 -n 13 -z -l calibrationDataSN003.dat
1252 
1253  QList <sBoard> canBoards;
1254  QString retString;
1255  int ret;
1256  char sn[256];
1257  int index = 0;
1258  unsigned int CHANNEL_COUNT = 6;
1259  strain2_ampl_regs_t amp_registers[6];
1260  unsigned int offset[6];
1261  unsigned int calib_matrix[3][6][6];
1262  int calib_bias[6];
1263  unsigned int full_scale_const[3][6];
1264  string msg;
1265 
1266 
1267  if (file==NULL){
1268  yError("File not found!\n");
1269  return false;
1270  }
1271 
1272 
1273  if(device.contains("SOCKETCAN"))
1274  {
1275  if (canId.toInt() <1 || canId.toInt() >= 15){
1276  yError("Invalid board address!\n");
1277  return false;
1278  }
1279 
1280  canBoards = core->getCanBoardsFromDriver(device,id.toInt(),&retString,true);
1281 
1282 
1283  }
1284  else if(device.contains("ETH"))
1285  {
1286  QString result, ret;
1287  ret = setBoardToMaintenance(core,device,id,board);
1288  if(!core->isBoardInMaintenanceMode(board)){
1289  yError("ETH board is not present or not in maintenace mode!!\n");
1290  return false;
1291  }
1292  canBoards = core->getCanBoardsFromEth(board,&result,canLine.toInt(),true);
1293  }
1294 
1295  //Flash the .dat file
1296  if(canBoards.count() > 0 && icubCanProto_boardType__strain2 == canBoards[0].type)
1297  {
1298  int ret = core->getDownloader()->get_serial_no(canLine.toInt(),canId.toInt(),sn);
1299  if(canBoards.count() > 0)
1300  {
1301  int boardtype = canBoards[0].type;
1302  int regset = canBoards[0].strainregsetinuse;
1303 
1304  int file_version=0;
1305  fstream filestr;
1306  filestr.open (file.toLatin1().data(), fstream::in);
1307  if (!filestr.is_open()){
1308  yError("Error opening calibration file!\n");
1309  return false;
1310  }
1311 
1312  int i=0;
1313  char buffer[256];
1314 
1315  //file version
1316  filestr.getline (buffer,256);
1317  filestr.getline (buffer,256);
1318  sscanf (buffer,"%d",&file_version);
1319 
1320 
1321  if((icubCanProto_boardType__strain2 == boardtype) && (3 != file_version))
1322  {
1323  yError("Wrong file. Calibration version not supported for strain2: %d\n", file_version);
1324  return false;
1325  }
1326  else if((icubCanProto_boardType__strain == boardtype) && (2 != file_version))
1327  {
1328  yError("Wrong file. Calibration version not supported: %d\n", file_version);
1329  return false;
1330  }
1331 
1332  if(3 == file_version)
1333  {
1334  // Board type:
1335  filestr.getline (buffer,256);
1336  filestr.getline (buffer,256);
1337  if(0 != strcmp(buffer, "strain2"))
1338  {
1339  yError("Wrong file. Board type not supported: %s\n", buffer);
1340  return false;
1341  }
1342 
1343  // Serial number:
1344  filestr.getline (buffer,256);
1345  filestr.getline (buffer,256);
1346  sprintf(sn,"%s", buffer);
1347  core->getDownloader()->strain_set_serial_number(canLine.toInt(),canId.toInt(), sn);
1348  //yDebug() << buffer;
1349 
1350  // Amplifier registers:
1351  filestr.getline (buffer,256);
1352  for (i=0;i<CHANNEL_COUNT; i++)
1353  {
1354  filestr.getline (buffer,256);
1355  yDebug() << buffer;
1356  unsigned int t08[6] = {0};
1357  sscanf (buffer,"0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x", &t08[0], &t08[1], &t08[2], &t08[3], &t08[4], &t08[5]);
1358  for(int j=0; j<6; j++) amp_registers[i].data[j] = t08[j];
1359 
1360  core->getDownloader()->strain_set_amplifier_regs(canLine.toInt(),canId.toInt(), i, amp_registers[i], regset);
1361 
1362  // downloader.strain_set_offset (downloader.board_list[selected].bus, downloader.board_list[selected].pid, i, offset[i]);
1363  //core->getDownloader()->strain_set_offset (bus,id, i, offset[i]);
1364  //printf("0X%02x, 0X%02x, 0X%02x, 0X%02x, 0X%02x,0X%02x", amp_registers[i].data[0], amp_registers[i].data[1], amp_registers[i].data[2], amp_registers[i].data[3], amp_registers[i].data[4], amp_registers[i].data[5]);
1365  //fflush(stdout);
1366  drv_sleep(10);
1367  }
1368 
1369  }
1370  else
1371  {
1372 
1373  //serial number
1374  filestr.getline (buffer,256);
1375  filestr.getline (buffer,256);
1376  sprintf(sn,"%s", buffer);
1377  core->getDownloader()->strain_set_serial_number(canLine.toInt(),canId.toInt(), sn);
1378 
1379  //offsets
1380  filestr.getline (buffer,256);
1381  for (i=0;i<CHANNEL_COUNT; i++)
1382  {
1383  filestr.getline (buffer,256);
1384  sscanf (buffer,"%d",&offset[i]);
1385  // downloader.strain_set_offset (downloader.board_list[selected].bus, downloader.board_list[selected].pid, i, offset[i]);
1386  core->getDownloader()->strain_set_offset (canLine.toInt(),canId.toInt(), i, offset[i], regset);
1387  drv_sleep(200);
1388  }
1389  }
1390 
1391  //calibration matrix
1392  filestr.getline (buffer,256);
1393  for (i=0;i<36; i++){
1394  int ri=i/6;
1395  int ci=i%6;
1396  filestr.getline (buffer,256);
1397  sscanf (buffer,"%x",&calib_matrix[index][ri][ci]);
1398  //printf("%d %x\n", calib_matrix[index][ri][ci],calib_matrix[index][ri][ci]);
1399  core->getDownloader()->strain_set_matrix_rc(canLine.toInt(),canId.toInt(), ri, ci, calib_matrix[index][ri][ci], regset);
1400  }
1401 
1402  //matrix gain
1403  filestr.getline (buffer,256);
1404  filestr.getline (buffer,256);
1405  int cc=0;
1406  sscanf (buffer,"%d",&cc);
1407  core->getDownloader()->strain_set_matrix_gain(canLine.toInt(),canId.toInt(), cc, regset);
1408 
1409  //tare
1410  filestr.getline (buffer,256);
1411  for (i=0;i<CHANNEL_COUNT; i++){
1412  filestr.getline (buffer,256);
1413  sscanf (buffer,"%d",&calib_bias[i]);
1414  core->getDownloader()->strain_set_calib_bias(canLine.toInt(),canId.toInt(), i, calib_bias[i], regset);
1415  }
1416 
1417  //full scale values
1418  filestr.getline (buffer,256);
1419  for (i=0;i<CHANNEL_COUNT; i++){
1420  filestr.getline (buffer,256);
1421  sscanf (buffer,"%d",&full_scale_const[index][i]);
1422  core->getDownloader()->strain_set_full_scale(canLine.toInt(),canId.toInt(), i, full_scale_const[index][i], regset);
1423  }
1424  filestr.close();
1425  filestr.clear();
1426 
1427  core->getDownloader()->strain_save_to_eeprom(canLine.toInt(),canId.toInt(), &msg);
1428 
1429  yInfo() << "Calibration file loaded!";
1430  }
1431 
1432  } else {
1433  yError() << "No STRAIN2 board found, stopped!";
1434  return false;
1435  }
1436 
1437  /* if(device.contains("ETH")){
1438  ret = setBoardToApplication(core,device,id,board);
1439  if(core->isBoardInMaintenanceMode(board)){
1440  yError("ETH board not switched to application mode!!\n");
1441  return false;
1442  } else yInfo() << "ETH board ready!";
1443  } */
1444 
1445  return -1;
1446 }
1447 
1448 int saveDatFileStrain2(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId,bool eraseEEprom)
1449 {
1450  //09-2020 - davide.tome@iit.it
1451  //This method is used to saves the calibration of the STRAIN2
1452  // i.e. FirmwareUpdater -g -e ETH -i eth1 -t 10.0.1.1 -c 1 -n 13 -u
1453 
1454  QList <sBoard> canBoards;
1455  QString retString;
1456  int ret;
1457  char sn[256];
1458  unsigned int CHANNEL_COUNT = 6;
1459  strain2_ampl_regs_t amp_registers[6];
1460  unsigned int offset[6];
1461  unsigned int calib_matrix[3][6][6];
1462  int calib_bias[6];
1463  float amp_gains[6];
1464  uint16_t amp_offsets[6];
1465  unsigned int full_scale_const[3][6];
1466  unsigned int matrix[3][6][6];
1467  unsigned int full_scale_calib[3][6];
1468  unsigned int calib_const[3];
1469  char serial_no[8];
1470  string msg;
1471 
1472  calib_const[0] = 1;
1473  calib_const[1] = 1;
1474  calib_const[2] = 1;
1475 
1476 
1477  int index = 0;
1478 
1479  char path[256] = { 0 };
1480  std::string filename;
1481 
1482 
1483  int i=0;
1484  char buffer[256];
1485 
1486  if(device.contains("SOCKETCAN"))
1487  {
1488  if (canId.toInt() <1 || canId.toInt() >= 15){
1489  yError("Invalid board address!\n");
1490  return false;
1491  }
1492 
1493  canBoards = core->getCanBoardsFromDriver(device,id.toInt(),&retString,true);
1494 
1495  }
1496  else if(device.contains("ETH"))
1497  {
1498  QString result, ret;
1499  ret = setBoardToMaintenance(core,device,id,board);
1500  if(!core->isBoardInMaintenanceMode(board)){
1501  yError("ETH board is not present or not in maintenace mode!!\n");
1502  return false;
1503  }
1504  canBoards = core->getCanBoardsFromEth(board,&result,canLine.toInt(),true);
1505  }
1506 
1507  //Flash the .dat file
1508  if(canBoards.count() > 0 && icubCanProto_boardType__strain2 == canBoards[0].type)
1509  {
1510  core->getDownloader()->strain_get_serial_number(canLine.toInt(),canId.toInt(), serial_no);
1511 
1512  filename += "calibrationData";
1513  filename += serial_no;
1514  filename += ".dat";
1515  fstream filestr;
1516  filestr.open (filename.c_str(), fstream::out);
1517 
1518  for(int i=0; i<6; i++)
1519  {
1520  core->getDownloader()->strain_get_amplifier_regs(canLine.toInt(),canId.toInt(), i, amp_registers[i], cDownloader::strain_regset_inuse, &msg);
1521  core->getDownloader()->strain_get_amplifier_gain_offset(canLine.toInt(),canId.toInt(), i, amp_gains[i], amp_offsets[i], cDownloader::strain_regset_inuse, &msg);
1522  core->getDownloader()->strain_get_offset (canLine.toInt(),canId.toInt(), i, offset[i], cDownloader::strain_regset_inuse, &msg);
1523  }
1524 
1525  for(int mi=0;mi<1;mi++){
1526 
1527  for (int ri=0;ri<CHANNEL_COUNT;ri++){
1528  for (int ci=0;ci<CHANNEL_COUNT;ci++){
1529  core->getDownloader()->strain_get_matrix_rc(canLine.toInt(),canId.toInt(), ri, ci, matrix[mi][ri][ci], cDownloader::strain_regset_inuse, &msg);
1530  core->getDownloader()->strain_get_full_scale(canLine.toInt(),canId.toInt(), ri, full_scale_const[mi][ri], cDownloader::strain_regset_inuse, &msg);
1531  }
1532  }
1533  }
1534 
1535  if(icubCanProto_boardType__strain2 == canBoards[0].type)
1536  {
1537  // file version
1538  filestr<<"File version:"<<endl;
1539  filestr<<"3"<<endl;
1540  // board type
1541  filestr<<"Board type:"<<endl;
1542  filestr<<"strain2"<<endl;
1543  // serial number
1544  filestr<<"Serial number:"<<endl;
1545  sprintf (buffer,"%s",serial_no);
1546  filestr<<buffer<<endl;
1547  // amplifier registers
1548  filestr<<"Amplifier registers:"<<endl;
1549  for (i=0;i<CHANNEL_COUNT; i++){
1550  sprintf (buffer,"0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x",
1551  amp_registers[i].data[0], amp_registers[i].data[1], amp_registers[i].data[2],
1552  amp_registers[i].data[3], amp_registers[i].data[4], amp_registers[i].data[5]);
1553  filestr<<buffer<<endl;
1554  }
1555  }
1556  else
1557  {
1558  //file version
1559  filestr<<"File version:"<<endl;
1560  filestr<<"2"<<endl;
1561 
1562  //serial number
1563  filestr<<"Serial number:"<<endl;
1564  sprintf (buffer,"%s",serial_no);
1565  filestr<<buffer<<endl;
1566 
1567  //offsets
1568  filestr<<"Offsets:"<<endl;
1569  for (i=0;i<CHANNEL_COUNT; i++){
1570  sprintf (buffer,"%d",offset[i]);
1571  filestr<<buffer<<endl;
1572  }
1573  }
1574 
1575 
1576 
1577  //calibration matrix
1578  filestr<<"Calibration matrix:"<<endl;
1579  for (i=0;i<36; i++){
1580  sprintf (buffer,"%x",matrix[index][i/6][i%6]);
1581  filestr<<buffer<<endl;
1582  }
1583 
1584 
1585  //matrix gain
1586  filestr<<"Matrix gain:"<<endl;
1587  sprintf (buffer,"%d",calib_const[index]);
1588  filestr<<buffer<<endl;
1589 
1590 
1591  //tare
1592  filestr<<"Tare:"<<endl;
1593  for (i=0;i<CHANNEL_COUNT; i++){
1594  sprintf (buffer,"%d",calib_bias[i]);
1595  filestr<<buffer<<endl;
1596  }
1597 
1598  //full scale values
1599  filestr<<"Full scale values:"<<endl;
1600  for (i=0;i<CHANNEL_COUNT; i++){
1601  sprintf (buffer,"%d",full_scale_const[index][i]);
1602  filestr<<buffer<<endl;
1603  }
1604 
1605  yInfo() << "Calibration file saved!";
1606  filestr.close();
1607  } else {
1608  yError() << "No STRAIN2 board found, stopped!";
1609  return false;
1610  }
1611 
1612  return -1;
1613 }
1614 
1615 int setBoardToApplication(FirmwareUpdaterCore *core,QString device,QString id,QString board)
1616 {
1617  int boards = core->connectTo(device,id);
1618  if(boards > 0){
1619  if(device.contains("ETH")){
1620  core->setSelectedEthBoard(board,true);
1621  core->goToApplication();
1622  }
1623  }
1624  return 0;
1625 }
1626 
1627 int setBoardToMaintenance(FirmwareUpdaterCore *core,QString device,QString id,QString board)
1628 {
1629  int boards = core->connectTo(device,id);
1630  if(boards > 0){
1631  if(device.contains("ETH")){
1632  core->setSelectedEthBoard(board,true);
1633  core->goToMaintenance();
1634  }
1635  }
1636 
1637  return 0;
1638 }
1639 
1640 
1641 int programCanDevice(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString canLine,QString canId,QString file,bool eraseEEprom)
1642 {
1643  QString retString;
1644  if(device.contains("ETH")){
1645  int boards = core->connectTo(device,id);
1646  if(boards > 0){
1647  char board_ipaddr[16];
1648  for(int i=0;i<core->getEthBoardList().size();i++){
1649  EthBoard ethBoard = core->getEthBoardList()[i];
1650  snprintf(board_ipaddr, sizeof(board_ipaddr), "%s", ethBoard.getIPV4string().c_str());
1651 
1652  if(board.contains(board_ipaddr)){
1653  core->setSelectedEthBoard(i,true);
1654  QList <sBoard> canBoards = core->getCanBoardsFromEth(board,&retString,canLine.toInt(),true);
1655  if(canBoards.count() > 0){
1656  int selectedCount = 0;
1657  for(int j=0;j<canBoards.count();j++){
1658  sBoard b = canBoards.at(j);
1659  if(b.bus == canLine.toInt() && b.pid == canId.toInt()){
1660  b.selected = true;
1661  b.eeprom = eraseEEprom;
1662  canBoards.replace(j,b);
1663  selectedCount++;
1664  }
1665 
1666  }
1667  if(selectedCount > 0){
1668  core->setSelectedCanBoards(canBoards,board);
1669  bool ret = core->uploadCanApplication(file, &retString, eraseEEprom, board);
1670  if(verbosity >= 1) qDebug() << retString;
1671  return ret ? 0 : -1;
1672  }else{
1673  if(verbosity >= 1) qDebug() << "No board selected";
1674  return -1;
1675  }
1676  }else{
1677  if(verbosity >= 1) qDebug() << retString;
1678  return -1;
1679  }
1680 
1681  }
1682  }
1683 
1684  }
1685  }else{
1686  QList <sBoard> canBoards = core->getCanBoardsFromDriver(device,id.toInt(),&retString,true);
1687  if(canBoards.count() > 0){
1688  int selectedCount = 0;
1689  for(int j=0;j<canBoards.count();j++){
1690  sBoard b = canBoards.at(j);
1691  if(b.bus == canLine.toInt() && b.pid == canId.toInt()){
1692  b.selected = true;
1693  b.eeprom = eraseEEprom;
1694  canBoards.replace(j,b);
1695  selectedCount++;
1696  }
1697  }
1698  if(selectedCount > 0){
1699  core->setSelectedCanBoards(canBoards,device,id.toInt());
1700  bool ret = core->uploadCanApplication(file, &retString, eraseEEprom, device, id.toInt());
1701  if(verbosity >= 1) qDebug() << retString;
1702  return ret ? 0 : -1;
1703  }else{
1704  if(verbosity >= 1) qDebug() << "No board selected";
1705  return -1;
1706  }
1707  }else{
1708  if(verbosity >= 1) qDebug() << retString;
1709  return -1;
1710  }
1711  }
1712  return -1;
1713 }
1714 
1715 
1716 int programEthDevice(FirmwareUpdaterCore *core,QString device,QString id,QString board,QString file)
1717 {
1718  int boards = core->connectTo(device,id);
1719  if(boards > 0){
1720  if(device.contains("ETH")){
1721  char board_ipaddr[16];
1722  for(int i=0;i<core->getEthBoardList().size();i++){
1723  EthBoard ethBoard = core->getEthBoardList()[i];
1724  snprintf(board_ipaddr, sizeof(board_ipaddr), "%s", ethBoard.getIPV4string().c_str());
1725 
1726  if(board.contains(board_ipaddr)){
1727  core->setSelectedEthBoard(i,true);
1728  QString resultString;
1729  bool b = core->uploadEthApplication(file,&resultString);
1730  if(!b){
1731  if(verbosity >= 1) qDebug() << resultString;
1732  return -1;
1733  }else{
1734  if(verbosity >= 1) qDebug() << "Update Done";
1735  return 0;
1736  }
1737  break;
1738  }
1739  }
1740  }
1741 
1742  }else{
1743  if(verbosity >= 1) qDebug() << "No boards found";
1744  }
1745  return -1;
1746 
1747 }
1748 
1749 int printSecondLevelDevices(FirmwareUpdaterCore *core,QString device,QString id, bool slimprint)
1750 {
1751  if(device.contains("ETH")){
1752  int boards = core->connectTo(device,id);
1753  if(boards > 0){
1754 
1755  char board_ipaddr[16];
1756  char board_mac[32];
1757 
1758  char board_version[16];
1759  char board_date[24];
1760  char board_built[24];
1761  char board_type[24];
1762  char running_process[24];
1763  char board_info[32];
1764  char appl_version[32] = {0};
1765 
1766  memset(board_ipaddr,0,sizeof(board_ipaddr));
1767  memset(board_mac,0,sizeof(board_mac));
1768  memset(board_version,0,sizeof(board_version));
1769  memset(board_date,0,sizeof(board_date));
1770  memset(board_built,0,sizeof(board_built));
1771  memset(board_type,0,sizeof(board_type));
1772  memset(running_process,0,sizeof(running_process));
1773  memset(board_info,0,sizeof(board_info));
1774 
1775 
1776  if(verbosity >= 1) qDebug() << "-------------------------------------------------------------";
1777  for(int i=0;i<core->getEthBoardList().size();i++){
1778  EthBoard board = core->getEthBoardList()[i];
1779 
1780  snprintf(board_ipaddr, sizeof(board_ipaddr), "%s", board.getIPV4string().c_str());
1781 
1782  ACE_UINT64 mac = board.getInfo().macaddress;
1783 
1784  snprintf(board_mac, sizeof(board_mac), "%02X-%02X-%02X-%02X-%02X-%02X",
1785  (uint8_t)(mac >> 40) & 0xff,
1786  (uint8_t)(mac >> 32) & 0xff,
1787  (uint8_t)(mac >> 24) & 0xff,
1788  (uint8_t)(mac >> 16) & 0xff,
1789  (uint8_t)(mac >> 8 ) & 0xff,
1790  (uint8_t)(mac ) & 0xff
1791  );
1792 
1793 
1794  snprintf(board_version, sizeof(board_version), "%s", board.getVersionfRunning().c_str());
1795  snprintf(board_type, sizeof(board_type), "%s", eoboards_type2string2(eoboards_ethtype2type(board.getInfo().boardtype), eobool_true));
1796  snprintf(running_process, sizeof(running_process), "%s", eouprot_process2string((eOuprot_process_t)board.getInfo().processes.runningnow));
1797  snprintf(board_info, sizeof(board_info), "%s", board.getInfoOnEEPROM().c_str());
1798  snprintf(board_date, sizeof(board_date), "%s", board.getDatefRunning().c_str());
1799  snprintf(board_built, sizeof(board_date), "%s", board.getCompilationDateOfRunning().c_str());
1800  snprintf(appl_version, sizeof(appl_version), "%d.%d", board.getInfo().processes.info[2].version.major, board.getInfo().processes.info[2].version.minor);
1801 
1802  if(true == slimprint)
1803  {
1804  char IPslimstring[512] = {0};
1805  snprintf(IPslimstring, sizeof(IPslimstring), "%s: type = %s, application = %d.%d, updater = %d.%d, loader = %d.%d",
1806  board.getIPV4string().c_str(),
1807  eoboards_type2string2(eoboards_ethtype2type(board.getInfo().boardtype), eobool_true),
1808  board.getInfo().processes.info[2].version.major, board.getInfo().processes.info[2].version.minor,
1809  board.getInfo().processes.info[1].version.major, board.getInfo().processes.info[1].version.minor,
1810  board.getInfo().processes.info[0].version.major, board.getInfo().processes.info[0].version.minor);
1811 
1812  qDebug() << IPslimstring;
1813  }
1814  else
1815  {
1816  if(verbosity >= 1) qDebug() << "************** Device " << i << " ******************";
1817  if(verbosity >= 1) qDebug() << "Ip: "<< board_ipaddr;
1818  if(verbosity >= 1) qDebug() << "Mac: "<< board_mac;
1819  if(verbosity >= 1) qDebug() << "Version: "<< board_version;
1820  if(verbosity >= 1) qDebug() << "Appl Ver: "<< appl_version;
1821  if(verbosity >= 1) qDebug() << "Type: "<< board_type;
1822  if(verbosity >= 1) qDebug() << "Process: "<< running_process;
1823  if(verbosity >= 1) qDebug() << "Info: "<< board_info;
1824  if(verbosity >= 1) qDebug() << "Date: "<< board_date;
1825  if(verbosity >= 1) qDebug() << "Built: "<< board_built;
1826  if(verbosity >= 1) qDebug() << "\n";
1827  }
1828 
1829  }
1830  if(verbosity >= 1) qDebug() << "-------------------------------------------------------------";
1831 
1832  }
1833  }else{
1834  QString retString;
1835  QList <sBoard> canBoards = core->getCanBoardsFromDriver(device,id.toInt(),&retString,true);
1836  if(canBoards.count() <= 0){
1837  if(verbosity >= 1) qDebug() << retString;
1838  }else{
1839  QString empty;
1840  printCanDevices(canBoards, empty, slimprint);
1841  }
1842  }
1843  return 0;
1844 }
1845 
1846 int printThirdLevelDevices(FirmwareUpdaterCore *core,QString device,QString id,QString board, bool forceMaintenance, bool forceApplication, bool slimprint)
1847 {
1848 
1849 // if(forceMaintenance)
1850 // {
1851 // yDebug() << "printThirdLevelDevices() is sending in manteinance mode:" << board.toStdString();
1852 // int ret = setBoardToMaintenance(core,device,id,board);
1853 // yDebug() << "ret is " << ret;
1854 // }
1855 
1856  int boards = core->connectTo(device,id);
1857  if(boards > 0){
1858  if(device.contains("ETH")){
1859  if(forceMaintenance){
1860  core->setSelectedEthBoard(board,true);
1861  core->goToMaintenance();
1862  }else if(forceApplication){
1863  core->setSelectedEthBoard(board,true);
1864  core->goToApplication();
1865  }
1866  if(core->isBoardInMaintenanceMode(board)){
1867  QString retString;
1868  QList <sBoard> canBoards = core->getCanBoardsFromEth(board,&retString);
1869  if(canBoards.count() <= 0){
1870  if(verbosity >= 1) qDebug() << retString;
1871  }else{
1872  printCanDevices(canBoards, board, slimprint);
1873  }
1874 
1875  }else{
1876  if(verbosity >= 1) qDebug() << "for board" << board << "You have to put the device in maintenace mode to perform this operation.";
1877  }
1878 
1879  }
1880  }else{
1881  if(verbosity >= 1) qDebug() << "No boards Found";
1882  }
1883 
1884  return 0;
1885 }
1886 
1887 void printCanDevices(QList<sBoard> canBoards, QString onIPboard, bool slimprint)
1888 {
1889  if(verbosity >= 1) qDebug() << "-------------------------------------------------------------";
1890  for(int i=0;i<canBoards.count();i++){
1891  sBoard board = canBoards.at(i);
1892 
1893  char board_type [50]; memset (board_type, 0, sizeof(board_type));
1894  char board_process [50]; memset (board_process, 0, sizeof(board_process));
1895  char board_status [50]; memset (board_status, 0, sizeof(board_status));
1896  char board_add_info [50]; memset (board_add_info, 0, sizeof(board_add_info));
1897  char board_firmware_version [32]; memset (board_firmware_version, 0, sizeof(board_firmware_version));
1898  char board_appl_minor [10]; memset (board_appl_minor, 0, sizeof(board_appl_minor));
1899  char board_appl_build [10]; memset (board_appl_build, 0, sizeof(board_appl_build));
1900  char board_serial [50]; memset (board_serial, 0, sizeof(board_serial));
1901  char board_protocol [10]; memset (board_protocol, 0, sizeof(board_protocol));
1902 
1903  snprintf(board_type, sizeof(board_type), "%s", eoboards_type2string2((eObrd_type_t)board.type, eobool_true));
1904 
1905  switch (board.status)
1906  {
1907  case BOARD_RUNNING:
1908  strcpy(board_status, "RUNNING");
1909  break;
1910  case BOARD_WAITING:
1911  strcpy(board_status, "WAITING");
1912  break;
1913  case BOARD_WAITING_ACK:
1914  strcpy(board_status, "WAITING_ACK");
1915  break;
1916  case BOARD_DOWNLOADING:
1917  strcpy(board_status, "DOWNLOADING");
1918  break;
1919  case BOARD_OK :
1920  strcpy(board_status, "OK");
1921  break;
1922  case BOARD_ERR:
1923  strcpy(board_status, "ERR");
1924  break;
1925  default:
1926  strcpy(board_status, "UNKNOWN");
1927  break;
1928  }
1929 
1930  if(true == board.applicationisrunning){
1931  strcpy(board_process, "canApplication");
1932  } else {
1933  strcpy(board_process, "canBootloader");
1934  }
1935 
1936  strncpy (board_add_info, board.add_info,32);
1937 
1938  if(-1 == board.appl_vers_build){
1939  snprintf (board_firmware_version, sizeof(board_firmware_version), "%d.%d", board.appl_vers_major, board.appl_vers_minor);
1940  } else {
1941  snprintf (board_firmware_version, sizeof(board_firmware_version), "%d.%d.%d", board.appl_vers_major, board.appl_vers_minor, board.appl_vers_build);
1942  }
1943 
1944  snprintf (board_appl_minor, sizeof(board_appl_minor), "%d",board.appl_vers_minor);
1945  snprintf (board_appl_build, sizeof(board_appl_build), "%d",board.appl_vers_build);
1946  snprintf (board_serial, sizeof(board_serial), "%s", board.serial);
1947 
1948  if((0 == board.prot_vers_major) && (0 == board.prot_vers_minor))
1949  {
1950  snprintf (board_protocol, sizeof(board_protocol), "N/A");
1951  }
1952  else
1953  {
1954  snprintf (board_protocol, sizeof(board_protocol), "%d.%d", board.prot_vers_major, board.prot_vers_minor);
1955  }
1956 
1957  if(true == slimprint)
1958  {
1959  char CANslimstring[512] = {0};
1960  char IPstr[24] = {0};
1961  if(false == onIPboard.isEmpty())
1962  {
1963  snprintf(IPstr, sizeof(IPstr), "%s:", onIPboard.toStdString().c_str());
1964  }
1965  snprintf(CANslimstring, sizeof(CANslimstring), "%sCAN%d:%d: type = %s, application = %s",
1966  IPstr,
1967  board.bus, board.pid,
1968  //board.getIPV4string().c_str(),
1969  eoboards_type2string2((eObrd_type_t)board.type, eobool_true),
1970  board_firmware_version);
1971 
1972  qDebug() << CANslimstring;
1973  }
1974  else
1975  {
1976  if(verbosity >= 1) qDebug() << "************** Board " << i << " ******************";
1977  if(verbosity >= 1) qDebug() << "Type: " << board_type;
1978  if(verbosity >= 1) qDebug() << "Id: " << board.pid;
1979  if(verbosity >= 1) qDebug() << "Address: " << "CAN_" << board.bus;
1980  if(verbosity >= 1) qDebug() << "Process: " << board_process;
1981  if(verbosity >= 1) qDebug() << "Status: " << board_status;
1982  if(verbosity >= 1) qDebug() << "Info: " << board_add_info;
1983  if(verbosity >= 1) qDebug() << "Firmware Version: " << board_firmware_version;
1984  if(verbosity >= 1) qDebug() << "Serial: " << board_serial;
1985  if(verbosity >= 1) qDebug() << "Protocol: " << board_protocol;
1986  if(verbosity >= 1) qDebug() << "\n";
1987  }
1988  }
1989  if(verbosity >= 1) qDebug() << "-------------------------------------------------------------";
1990 }
1991 
1993 {
1994  QString tempFile;
1995 #ifdef Q_OS_WIN
1996  tempFile = QDir::homePath() + "/firmwareUpdater.singleton";
1997 #else
1998  tempFile = QDir::homePath() + "/.firmwareUpdater.singleton";
1999 #endif
2000 
2001  QFileInfo fInfo(tempFile);
2002  if(fInfo.exists()){
2003  return false;
2004  }
2005 
2006  QFile f(tempFile);
2007  f.open(QIODevice::WriteOnly);
2008  f.write("busy");
2009  f.flush();
2010  f.close();
2011 
2012 #ifdef Q_OS_WIN
2013  LPCSTR a = (const char*)fInfo.filePath().utf16();
2014  BOOL b = SetFileAttributes(a,FILE_ATTRIBUTE_HIDDEN);
2015 #endif
2016 
2017  return true;
2018 
2019 }
2020 
2021 
2023 {
2024  QString tempFile;
2025 #ifdef Q_OS_WIN
2026  tempFile = QDir::homePath() + "/firmwareUpdater.singleton";
2027 #else
2028  tempFile = QDir::homePath() + "/.firmwareUpdater.singleton";
2029 #endif
2030 
2031  QFileInfo fInfo(tempFile);
2032  if(!fInfo.exists()){
2033  return;
2034  }
2035 
2036  QFile f(tempFile);
2037  f.remove();
2038 
2039 }
2040 
2041 int verifyOnSecondLevel(FirmwareUpdaterCore *core, QString device, QString id, const QString &targetIPaddr, const QString &targetCANline, const QString &targetCANaddr, const QString &targetFWvers)
2042 {
2043  int ret = 1;
2044 
2045  if(device.contains("ETH"))
2046  {
2047  int boards = core->connectTo(device, id);
2048  if(boards > 0)
2049  {
2050 
2051  if(verbosity >= 1) qDebug() << "-------------------------------------------------------------";
2052 
2053  bool found = false;
2054  for(int i=0;i<core->getEthBoardList().size();i++)
2055  {
2056  EthBoard board = core->getEthBoardList()[i];
2057 
2058  if(targetIPaddr.toStdString() == board.getIPV4string())
2059  {
2060  found = true;
2061 
2062  char board_ipaddr[16] = {0};
2063  char appl_version[32] = {0};
2064 
2065  snprintf(board_ipaddr, sizeof(board_ipaddr), "%s", board.getIPV4string().c_str());
2066  snprintf(appl_version, sizeof(appl_version), "%d.%d", board.getInfo().processes.info[2].version.major, board.getInfo().processes.info[2].version.minor);
2067 
2068  if(targetFWvers == appl_version)
2069  {
2070  ret = 0;
2071  if(verbosity >= 1) qDebug() << "MATCHED";
2072  }
2073  else
2074  {
2075  ret = 1;
2076  if(verbosity >= 1) qDebug() << "NOT MATCHED";
2077  }
2078 
2079  break;
2080  }
2081 
2082 
2083 
2084  }
2085 
2086  if(!found)
2087  {
2088  ret = 1;
2089  if(verbosity >= 1) qDebug() << "NOT MATCHED (IP = " << targetIPaddr << " not in found boards)";
2090  }
2091  if(verbosity >= 1) qDebug() << "-------------------------------------------------------------";
2092 
2093  }
2094  else
2095  {
2096  ret = 1;
2097  if(verbosity >= 1) qDebug() << "NOT MATCHED (found no board)";
2098  }
2099  }
2100  else
2101  {
2102  QString retString;
2103  QList <sBoard> canBoards = core->getCanBoardsFromDriver(device,id.toInt(),&retString,true);
2104  if(canBoards.count() <= 0)
2105  {
2106  ret = 1;
2107  if(verbosity >= 1) qDebug() << retString;
2108  }
2109  else
2110  {
2111  ret = verifyCanDevices(canBoards, targetCANline, targetCANaddr, targetFWvers);
2112  }
2113  }
2114 
2115  return ret;
2116 }
2117 
2118 
2119 int verifyOnSecondLevel_ETHboard(FirmwareUpdaterCore *core, QString device, QString id, const QString &targetIPaddr, const QString &targetFWvers)
2120 {
2121  int ret = 2;
2122 
2123 // if(device.contains("ETH"))
2124 // {
2125  int boards = core->connectTo(device, id);
2126  if(boards > 0)
2127  {
2128 
2129  if(verbosity >= 1) qDebug() << "-------------------------------------------------------------";
2130 
2131  bool found = false;
2132  for(int i=0;i<core->getEthBoardList().size();i++)
2133  {
2134  EthBoard board = core->getEthBoardList()[i];
2135 
2136  if(targetIPaddr.toStdString() == board.getIPV4string())
2137  {
2138  found = true;
2139  ret = 1;
2140 
2141  char board_ipaddr[16] = {0};
2142  char appl_version[32] = {0};
2143 
2144  snprintf(board_ipaddr, sizeof(board_ipaddr), "%s", board.getIPV4string().c_str());
2145  snprintf(appl_version, sizeof(appl_version), "%d.%d", board.getInfo().processes.info[2].version.major, board.getInfo().processes.info[2].version.minor);
2146 
2147  if(targetFWvers == appl_version)
2148  {
2149  ret = 0;
2150  if(verbosity >= 1) qDebug() << "ETH FOUND + FW MATCHED";
2151  }
2152  else
2153  {
2154  ret = 1;
2155  if(verbosity >= 1) qDebug() << "ETH FOUND + FW NOT MATCHED";
2156  }
2157 
2158  break;
2159  }
2160 
2161 
2162 
2163  }
2164 
2165  if(!found)
2166  {
2167  ret = 2;
2168  if(verbosity >= 1) qDebug() << "NOT MATCHED (IP = " << targetIPaddr << " not in found boards)";
2169  }
2170  if(verbosity >= 1) qDebug() << "-------------------------------------------------------------";
2171 
2172  }
2173  else
2174  {
2175  ret = 2;
2176  if(verbosity >= 1) qDebug() << "NOT MATCHED (found no board)";
2177  }
2178 
2179 // }
2180 // else
2181 // {
2182 // QString retString;
2183 // QList <sBoard> canBoards = core->getCanBoardsFromDriver(device,id.toInt(),&retString,true);
2184 // if(canBoards.count() <= 0)
2185 // {
2186 // ret = 1;
2187 // if(verbosity >= 1) qDebug() << retString;
2188 // }
2189 // else
2190 // {
2191 // ret = verifyCanDevices(canBoards, targetCANline, targetCANaddr, targetFWvers);
2192 // }
2193 // }
2194 
2195  return ret;
2196 }
2197 
2198 int verifyOnSecondLevel_CANboard(FirmwareUpdaterCore *core, QString device, QString id, const QString &targetCANline, const QString &targetCANaddr, const QString &targetFWvers)
2199 {
2200  int ret = 2; // not found, not matched
2201 
2202  QString retString;
2203  QList <sBoard> canBoards = core->getCanBoardsFromDriver(device, id.toInt(), &retString, true);
2204  if(canBoards.count() <= 0)
2205  {
2206  ret = 2;
2207  if(verbosity >= 1) qDebug() << retString;
2208  }
2209  else
2210  {
2211  ret = verifyCanDevices(canBoards, targetCANline, targetCANaddr, targetFWvers);
2212  }
2213 
2214 
2215  return ret;
2216 }
2217 
2218 int verifyCanDevices(QList<sBoard> canBoards, const QString &targetCANline, const QString &targetCANaddr, const QString &targetFWvers)
2219 {
2220  int ret = 2; // not found, not matched
2221 
2222  bool found = false;
2223 
2224  for(int i=0;i<canBoards.count();i++)
2225  {
2226  sBoard board = canBoards.at(i);
2227 
2228  if(verbosity >= 1) qDebug() << "---------------------------------------------------------";
2229 
2230  // see if address matches
2231  char line[8] = {0};
2232  snprintf(line, sizeof(line), "%d", board.bus);
2233  char addr[8] = {0};
2234  snprintf(addr, sizeof(addr), "%d", board.pid);
2235 
2236  //if(verbosity >= 1) qDebug() << targetCANline << targetCANaddr;
2237  //printf("line+addr = %s %s", line, addr);
2238 
2239  if((targetCANline.toStdString() == string(line)) && (targetCANaddr.toStdString() == string(addr)) )
2240  {
2241  found = true;
2242  ret = 1; // found, maybe not yet fw match
2243 
2244  if(verbosity >= 1) qDebug() << "CAN ADDRESS: FOUND";
2245 
2246  //snprintf(board_type, sizeof(board_type), "%s", eoboards_type2string2((eObrd_type_t)board.type, eobool_true));
2247 
2248  if(true == board.applicationisrunning)
2249  {
2250  char board_firmware_version [32] = {0};
2251  snprintf (board_firmware_version, sizeof(board_firmware_version), "%d.%d.%d", board.appl_vers_major, board.appl_vers_minor, board.appl_vers_build);
2252  //printf("ss %s", board_firmware_version);
2253 
2254  if(string(board_firmware_version) == targetFWvers.toStdString())
2255  {
2256  ret = 0; // match!
2257  if(verbosity >= 1) qDebug() << "CAN FW VERSION: MATCHES";
2258  }
2259  }
2260 
2261  break;
2262  }
2263  }
2264 
2265  if(verbosity >= 1) qDebug() << "-------------------------------------------------------------";
2266 
2267  return ret;
2268 }
2269 
2270 
2271 int verifyOnThirdLevel_CANunderETH(FirmwareUpdaterCore *core, QString device, QString id, QString board, const QString &targetCANline, const QString &targetCANaddr, const QString &targetFWvers)
2272 {
2273  int ret = 2;
2274 
2275  const bool forceMaintenance = true;
2276 
2277  int boards = core->connectTo(device, id);
2278 
2279  if(boards > 0)
2280  {
2281  if(device.contains("ETH"))
2282  {
2283  if(forceMaintenance)
2284  {
2285  core->setSelectedEthBoard(board, true);
2286  core->goToMaintenance();
2287  }
2288 
2289  if(core->isBoardInMaintenanceMode(board))
2290  {
2291  QString retString;
2292  QList <sBoard> canBoards = core->getCanBoardsFromEth(board, &retString);
2293  if(canBoards.count() <= 0)
2294  {
2295  if(verbosity >= 1) qDebug() << retString;
2296  }
2297  else
2298  {
2299  ret = verifyCanDevices(canBoards, targetCANline, targetCANaddr, targetFWvers);
2300  }
2301 
2302  }
2303  else
2304  {
2305  if(verbosity >= 1) qDebug() << "You have to put the device in maintenace mode to perform this operation.";
2306  }
2307 
2308  }
2309  }
2310  else
2311  {
2312  if(verbosity >= 1) qDebug() << "No boards Found";
2313  }
2314 
2315  return ret;
2316 }
2317 
2318 
2319 int queryOnSecondLevel_ETHboard(FirmwareUpdaterCore *core, QString device, QString id, const QString &targetIPaddr)
2320 {
2321  int ret = 1;
2322 
2323  const bool slimprint = true;
2324 
2325  bool found = false;
2326 
2327  if(verbosity >= 1) qDebug() << "-------------------------------------------------------------";
2328 
2329  int boards = core->connectTo(device, id);
2330  if(boards > 0)
2331  {
2332  for(int i=0;i<core->getEthBoardList().size();i++)
2333  {
2334  EthBoard board = core->getEthBoardList()[i];
2335 
2336  if(targetIPaddr.toStdString() == board.getIPV4string())
2337  {
2338  found = true;
2339  ret = 0;
2340 
2341  if(true == slimprint)
2342  {
2343  char IPslimstring[512] = {0};
2344  snprintf(IPslimstring, sizeof(IPslimstring), "%s: type = %s, application = %d.%d, updater = %d.%d, loader = %d.%d",
2345  board.getIPV4string().c_str(),
2346  eoboards_type2string2(eoboards_ethtype2type(board.getInfo().boardtype), eobool_true),
2347  board.getInfo().processes.info[2].version.major, board.getInfo().processes.info[2].version.minor,
2348  board.getInfo().processes.info[1].version.major, board.getInfo().processes.info[1].version.minor,
2349  board.getInfo().processes.info[0].version.major, board.getInfo().processes.info[0].version.minor);
2350 
2351  qDebug() << IPslimstring;
2352  }
2353 
2354  break;
2355  }
2356 
2357 
2358  }
2359 
2360 
2361  }
2362 
2363  if(!found)
2364  {
2365  ret = 1;
2366  char notfound[512] = {0};
2367  snprintf(notfound, sizeof(notfound), "%s: not found",
2368  targetIPaddr.toStdString().c_str());
2369 
2370  qDebug() << notfound;
2371  }
2372  if(verbosity >= 1) qDebug() << "-------------------------------------------------------------";
2373 
2374 
2375  return ret;
2376 }
2377 
2378 
2379 int queryOnThirdLevel_CANunderETH(FirmwareUpdaterCore *core, QString device, QString id, const QString board, const QString &targetCANline, const QString &targetCANaddr)
2380 {
2381  int ret = 1;
2382 
2383  const bool forceMaintenance = true;
2384 
2385  char notfound[256] = {0};
2386 
2387  int boards = core->connectTo(device, id);
2388 
2389  if(boards > 0)
2390  {
2391  if(device.contains("ETH"))
2392  {
2393  if(forceMaintenance)
2394  {
2395  core->setSelectedEthBoard(board, true);
2396  core->goToMaintenance();
2397  }
2398 
2399  if(core->isBoardInMaintenanceMode(board))
2400  {
2401  QString retString;
2402  QList <sBoard> canBoards = core->getCanBoardsFromEth(board, &retString);
2403  if(canBoards.count() <= 0)
2404  {
2405  if(verbosity >= 1) qDebug() << retString;
2406  snprintf(notfound, sizeof(notfound), "%s: no can board beneath", board.toStdString().c_str());
2407  qDebug() << notfound;
2408  }
2409  else
2410  {
2411  ret = queryCanDevices(canBoards, board, targetCANline, targetCANaddr);
2412  }
2413 
2414  }
2415  else
2416  {
2417  if(verbosity >= 1) qDebug() << "You have to put the device in maintenace mode to perform this operation.";
2418  }
2419 
2420  }
2421  }
2422  else
2423  {
2424  if(verbosity >= 1) qDebug() << "No boards Found";
2425  snprintf(notfound, sizeof(notfound), "%s: cannot find it", board.toStdString().c_str());
2426  qDebug() << notfound;
2427  }
2428 
2429  return ret;
2430 }
2431 
2432 
2433 int queryCanDevices(QList<sBoard> canBoards, const QString onIPboard, const QString &targetCANline, const QString &targetCANaddr)
2434 {
2435  int ret = 1; // not found
2436 
2437  bool found = false;
2438  const bool slimprint = true;
2439 
2440  for(int i=0;i<canBoards.count();i++)
2441  {
2442  sBoard board = canBoards.at(i);
2443 
2444  if(verbosity >= 1) qDebug() << "---------------------------------------------------------";
2445 
2446  // see if address matches
2447  char line[8] = {0};
2448  snprintf(line, sizeof(line), "%d", board.bus);
2449  char addr[8] = {0};
2450  snprintf(addr, sizeof(addr), "%d", board.pid);
2451 
2452 
2453  if((targetCANline.toStdString() == string(line)) && (targetCANaddr.toStdString() == string(addr)) )
2454  {
2455  found = true;
2456  ret = 0; // found
2457 
2458  char board_firmware_version[32] = {0};
2459 
2460  if(true == board.applicationisrunning)
2461  {
2462  snprintf (board_firmware_version, sizeof(board_firmware_version), "%d.%d.%d", board.appl_vers_major, board.appl_vers_minor, board.appl_vers_build);
2463  }
2464  else
2465  {
2466  snprintf (board_firmware_version, sizeof(board_firmware_version), "%d.%d", board.appl_vers_major, board.appl_vers_minor);
2467  }
2468 
2469  if(true == slimprint)
2470  {
2471  char CANslimstring[512] = {0};
2472  char IPstr[24] = {0};
2473  if(false == onIPboard.isEmpty())
2474  {
2475  snprintf(IPstr, sizeof(IPstr), "%s:", onIPboard.toStdString().c_str());
2476  }
2477  snprintf(CANslimstring, sizeof(CANslimstring), "%sCAN%d:%d: type = %s, application = %s",
2478  IPstr,
2479  board.bus, board.pid,
2480  eoboards_type2string2((eObrd_type_t)board.type, eobool_true),
2481  board_firmware_version);
2482 
2483  qDebug() << CANslimstring;
2484  }
2485 
2486  break;
2487  }
2488  }
2489 
2490  if(!found)
2491  {
2492  ret = 1;
2493  char notfound[512] = {0};
2494  char IPstr[24] = {0};
2495  if(false == onIPboard.isEmpty())
2496  {
2497  snprintf(IPstr, sizeof(IPstr), "%s:", onIPboard.toStdString().c_str());
2498  }
2499  snprintf(notfound, sizeof(notfound), "%sCAN%s:%s: not found",
2500  IPstr,
2501  targetCANline.toStdString().c_str(), targetCANaddr.toStdString().c_str());
2502 
2503  qDebug() << notfound;
2504  }
2505 
2506  if(verbosity >= 1) qDebug() << "-------------------------------------------------------------";
2507 
2508  return ret;
2509 }
2510 
2511 
2512 int queryOnSecondLevel_CANboard(FirmwareUpdaterCore *core, QString device, QString id, const QString &targetCANline, const QString &targetCANaddr)
2513 {
2514  int ret = 1; // not found
2515 
2516  char notfound[256] = {0};
2517 
2518  QString retString;
2519  QList <sBoard> canBoards = core->getCanBoardsFromDriver(device, id.toInt(), &retString, true);
2520  if(canBoards.count() <= 0)
2521  {
2522  ret = 1;
2523  if(verbosity >= 1) qDebug() << retString;
2524  snprintf(notfound, sizeof(notfound), "<%s>: no can boards beneath", device.toStdString().c_str());
2525  qDebug() << notfound;
2526  }
2527  else
2528  {
2529  QString none;
2530  ret = queryCanDevices(canBoards, targetCANline, none, targetCANaddr);
2531  }
2532 
2533 
2534  return ret;
2535 }
2536 
2537 
BOARD_ERR
#define BOARD_ERR
Definition: downloader.h:50
cDownloader::strain_set_amplifier_regs
int strain_set_amplifier_regs(int bus, int target_id, unsigned char channel, const strain2_ampl_regs_t &ampregs, int regset=strain_regset_inuse, string *errorstring=NULL)
Definition: downloader.cpp:913
setBoardToApplication
int setBoardToApplication(FirmwareUpdaterCore *core, QString device, QString id, QString board)
Definition: main.cpp:1615
printThirdLevelDevices
int printThirdLevelDevices(FirmwareUpdaterCore *, QString device, QString id, QString board, bool forceMaintenance, bool forceApplication, bool slimprint)
Definition: main.cpp:1846
changeCanId
int changeCanId(FirmwareUpdaterCore *core, QString device, QString id, QString board, QString canLine, QString canId, QString canIdNew)
Definition: main.cpp:954
checkApplicationLock
bool checkApplicationLock()
Definition: main.cpp:1992
changeBoardIp
int changeBoardIp(FirmwareUpdaterCore *core, QString device, QString id, QString board, QString newipaddr)
Definition: main.cpp:926
action_savedatfile
@ action_savedatfile
Definition: main.cpp:39
verifyOnSecondLevel_CANboard
int verifyOnSecondLevel_CANboard(FirmwareUpdaterCore *core, QString device, QString id, const QString &targetCANline, const QString &targetCANaddr, const QString &targetFWvers)
Definition: main.cpp:2198
SensorModel
SensorModel
Definition: main.cpp:47
FirmwareUpdaterCore::goToMaintenance
bool goToMaintenance()
Definition: firmwareupdatercore.cpp:141
action_setstrainft58gainsoffsets
@ action_setstrainft58gainsoffsets
Definition: main.cpp:43
drv_sleep
void drv_sleep(double time)
Definition: downloader.cpp:26
saveDatFileStrain2
int saveDatFileStrain2(FirmwareUpdaterCore *core, QString device, QString id, QString board, QString canLine, QString canId, bool eraseEEprom)
Definition: main.cpp:1448
BOARD_RUNNING
#define BOARD_RUNNING
Definition: downloader.h:45
FirmwareUpdaterCore::init
bool init(Searchable &config, int port, QString address, int VerbositY)
Definition: firmwareupdatercore.cpp:54
BOARD_DOWNLOADING
#define BOARD_DOWNLOADING
Definition: downloader.h:48
FirmwareUpdaterCore::isBoardInMaintenanceMode
bool isBoardInMaintenanceMode(QString ip)
Definition: firmwareupdatercore.cpp:207
verifyOnSecondLevel
int verifyOnSecondLevel(FirmwareUpdaterCore *core, QString device, QString id, const QString &targetIPaddr, const QString &targetCANline, const QString &targetCANaddr, const QString &targetFWvers)
Definition: main.cpp:2041
action_forceapplication
@ action_forceapplication
Definition: main.cpp:33
action_changeCanId
@ action_changeCanId
Definition: main.cpp:40
printCanDevices
void printCanDevices(QList< sBoard > canBoards, QString onIPboard, bool slimprint)
Definition: main.cpp:1887
e
e
Definition: compute_ekf_fast.m:13
loadDatFileStrain2
int loadDatFileStrain2(FirmwareUpdaterCore *core, QString device, QString id, QString board, QString canLine, QString canId, QString file, bool eraseEEprom)
Definition: main.cpp:1246
cDownloader::strain_set_serial_number
int strain_set_serial_number(int bus, int target_id, const char *serial_number, string *errorstring=NULL)
Definition: downloader.cpp:644
action_query
@ action_query
Definition: main.cpp:34
cDownloader::strain_get_amplifier_gain_offset
int strain_get_amplifier_gain_offset(int bus, int target_id, unsigned char channel, float &gain, uint16_t &offset, int regset=strain_regset_inuse, string *errorstring=NULL)
Definition: downloader.cpp:1088
main
int main(int argc, char *argv[])
Definition: main.cpp:31
action_discover
@ action_discover
Definition: main.cpp:29
verifyOnThirdLevel_CANunderETH
int verifyOnThirdLevel_CANunderETH(FirmwareUpdaterCore *core, QString device, QString id, QString board, const QString &targetCANline, const QString &targetCANaddr, const QString &targetFWvers)
Definition: main.cpp:2271
z
z
Definition: show_eyes_axes.m:22
FirmwareUpdaterCore::setSelectedCanBoards
void setSelectedCanBoards(QList< sBoard > selectedBoards, QString address, int deviceId=-1)
Definition: firmwareupdatercore.cpp:246
FirmwareUpdaterCore::getCanBoardsFromDriver
QList< sBoard > getCanBoardsFromDriver(QString driver, int networkId, QString *retString, bool force=false)
Definition: firmwareupdatercore.cpp:334
out
out
Definition: sine.m:8
offset
degrees offset
Definition: sine.m:4
cDownloader::strain_calibrate_offset2
int strain_calibrate_offset2(int bus, int target_id, icubCanProto_boardType_t boardtype, const std::vector< strain2_ampl_discretegain_t > &gains, const std::vector< int16_t > &targets, string *errorstring=NULL)
Definition: downloader.cpp:1699
removeApplicationLock
void removeApplicationLock()
Definition: main.cpp:2022
file
FILE * file
Definition: main.cpp:81
cDownloader::strain_set_matrix_gain
int strain_set_matrix_gain(int bus, int target_id, unsigned int gain, int regset=strain_regset_inuse, string *errorstring=NULL)
Definition: downloader.cpp:891
cDownloader::strain_get_full_scale
int strain_get_full_scale(int bus, int target_id, unsigned char channel, unsigned int &full_scale, int regset=strain_regset_inuse, string *errorstring=NULL)
Definition: downloader.cpp:1184
scripting.app
app
Definition: scripting.py:196
action_loaddatfile
@ action_loaddatfile
Definition: main.cpp:35
BOARD_WAITING_ACK
#define BOARD_WAITING_ACK
Definition: downloader.h:47
action_getcanboardversion
@ action_getcanboardversion
Definition: main.cpp:38
verbosity
int verbosity
Definition: main.cpp:21
cDownloader::strain_get_matrix_rc
int strain_get_matrix_rc(int bus, int target_id, char r, char c, unsigned int &elem, int regset=strain_regset_inuse, string *errorstring=NULL)
Definition: downloader.cpp:1245
setStrainGainsOffsets
int setStrainGainsOffsets(FirmwareUpdaterCore *core, QString device, QString id, QString board, QString canLine, QString canId, SensorModel model)
Definition: main.cpp:1083
sBoard::selected
bool selected
Definition: downloader.h:38
FirmwareUpdaterCore::setVerbosity
bool setVerbosity(int verb)
Definition: firmwareupdatercore.cpp:118
cDownloader::strain_get_serial_number
int strain_get_serial_number(int bus, int target_id, char *serial_number, string *errorstring=NULL)
Definition: downloader.cpp:672
data
@ data
Definition: ST_M1_dataType.h:64
queryOnSecondLevel_CANboard
int queryOnSecondLevel_CANboard(FirmwareUpdaterCore *core, QString device, QString id, const QString &targetCANline, const QString &targetCANaddr)
Definition: main.cpp:2512
setBoardToMaintenance
int setBoardToMaintenance(FirmwareUpdaterCore *core, QString device, QString id, QString board)
Definition: main.cpp:1627
action_changeBoardIp
@ action_changeBoardIp
Definition: main.cpp:41
FirmwareUpdaterCore::setCanBoardAddress
bool setCanBoardAddress(int bus, int id, int canType, QString newAddress, QString ethAddress="", int deviceId=-1, QString *resultString=NULL)
Definition: firmwareupdatercore.cpp:599
EthBoardList::size
int size()
Definition: EthBoard.cpp:273
action_forcemaintenance
@ action_forcemaintenance
Definition: main.cpp:32
action_none
@ action_none
Definition: main.cpp:28
EthBoard
Definition: EthBoard.h:75
BOARD_WAITING
#define BOARD_WAITING
Definition: downloader.h:46
cDownloader::change_card_address
int change_card_address(int bus, int target_id, int new_id, int board_type)
Definition: downloader.cpp:2413
FirmwareUpdaterCore::getDownloader
cDownloader * getDownloader()
Definition: firmwareupdatercore.cpp:1171
FirmwareUpdaterCore::uploadEthApplication
bool uploadEthApplication(QString filename, QString *resultString)
Definition: firmwareupdatercore.cpp:1139
cDownloader::strain_get_offset
int strain_get_offset(int bus, int target_id, char channel, unsigned int &offset, int regset=strain_regset_inuse, string *errorstring=NULL)
Definition: downloader.cpp:399
MainWindow
Definition: mainwindow.h:20
action_impossible
@ action_impossible
Definition: main.cpp:27
queryOnSecondLevel_ETHboard
int queryOnSecondLevel_ETHboard(FirmwareUpdaterCore *core, QString device, QString id, const QString &targetIPaddr)
Definition: main.cpp:2319
EthBoardList
Definition: EthBoard.h:127
programEthDevice
int programEthDevice(FirmwareUpdaterCore *, QString device, QString id, QString board, QString file)
Definition: main.cpp:1716
action_setstraingainsspecificoffsets
@ action_setstraingainsspecificoffsets
Definition: main.cpp:44
FirmwareUpdaterCore::goToApplication
bool goToApplication()
Definition: firmwareupdatercore.cpp:149
queryOnThirdLevel_CANunderETH
int queryOnThirdLevel_CANunderETH(FirmwareUpdaterCore *core, QString device, QString id, const QString board, const QString &targetCANline, const QString &targetCANaddr)
Definition: main.cpp:2379
sBoard::eeprom
bool eeprom
Definition: downloader.h:39
cDownloader::strain_set_matrix_rc
int strain_set_matrix_rc(int bus, int target_id, char r, char c, unsigned int elem, int regset=strain_regset_inuse, string *errorstring=NULL)
Definition: downloader.cpp:1291
mainwindow.h
EthBoard::getIPV4string
string getIPV4string()
Definition: EthBoard.cpp:65
FirmwareUpdaterCore::uploadCanApplication
bool uploadCanApplication(QString filename, QString *resultString, bool ee, QString address="", int deviceId=-1, QList< sBoard > *resultCanBoards=NULL)
Definition: firmwareupdatercore.cpp:961
SensorModel::ft58
@ ft58
getCanBoardVersion
int getCanBoardVersion(FirmwareUpdaterCore *core, QString device, QString id, QString board, QString canLine, QString canId, bool save)
Definition: main.cpp:1011
cDownloader::strain_save_to_eeprom
int strain_save_to_eeprom(int bus, int target_id, string *errorstring=NULL)
Definition: downloader.cpp:214
MY_PORT
#define MY_PORT
Definition: main.cpp:18
ampl_gain24
@ ampl_gain24
Definition: downloader.h:106
string
string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS}") include_directories($
Definition: CMakeLists.txt:9
action_verify
@ action_verify
Definition: main.cpp:30
SensorModel::ft45
@ ft45
setStrainSn
int setStrainSn(FirmwareUpdaterCore *core, QString device, QString id, QString board, QString canLine, QString canId, QString serialNumber)
Definition: main.cpp:1184
FirmwareUpdaterCore::getEthBoardList
EthBoardList getEthBoardList()
Definition: firmwareupdatercore.cpp:218
verifyCanDevices
int verifyCanDevices(QList< sBoard > canBoards, const QString &targetCANline, const QString &targetCANaddr, const QString &targetFWvers)
Definition: main.cpp:2218
action_t
action_t
Definition: main.cpp:25
FirmwareUpdaterCore::setEthBoardAddress
bool setEthBoardAddress(int index, QString newAddress)
Definition: firmwareupdatercore.cpp:648
firmwareupdatercore.h
f
f
Definition: compute_ekf_sym.m:22
printSecondLevelDevices
int printSecondLevelDevices(FirmwareUpdaterCore *, QString device, QString id, bool slimprint)
Definition: main.cpp:1749
cDownloader::strain_set_calib_bias
int strain_set_calib_bias(int bus, int target_id, string *errorstring=NULL)
Definition: downloader.cpp:476
ampl_gain10
@ ampl_gain10
Definition: downloader.h:107
action_setstrainft45gainsoffsets
@ action_setstrainft45gainsoffsets
Definition: main.cpp:42
queryCanDevices
int queryCanDevices(QList< sBoard > canBoards, const QString onIPboard, const QString &targetCANline, const QString &targetCANaddr)
Definition: main.cpp:2433
cDownloader::strain_set_offset
int strain_set_offset(int bus, int target_id, char channel, unsigned int offset, int regset=strain_regset_inuse, string *errorstring=NULL)
Definition: downloader.cpp:1316
FirmwareUpdaterCore::getCanBoardsFromEth
QList< sBoard > getCanBoardsFromEth(QString address, QString *retString, int canID=CanPacket::everyCANbus, bool force=false)
Definition: firmwareupdatercore.cpp:413
board
uint8_t board
Definition: main.cpp:123
strain2_ampl_regs_t
Definition: downloader.h:94
BOARD_OK
#define BOARD_OK
Definition: downloader.h:49
yarp
Copyright (C) 2008 RobotCub Consortium.
Definition: DebugInterfaces.h:51
FirmwareUpdaterCore::setSelectedEthBoard
void setSelectedEthBoard(int index, bool selected)
Definition: firmwareupdatercore.cpp:223
scripting.argc
argc
Definition: scripting.py:184
sBoard::pid
int pid
Definition: downloader.h:26
CHANNEL_COUNT
#define CHANNEL_COUNT
Definition: calibrationwindow.cpp:11
MY_ADDR
#define MY_ADDR
Definition: main.cpp:17
cDownloader::strain_get_amplifier_regs
int strain_get_amplifier_regs(int bus, int target_id, unsigned char channel, strain2_ampl_regs_t &ampregs, int regset=strain_regset_inuse, string *errorstring=NULL)
Definition: downloader.cpp:947
action_setstraingainsoffsets
@ action_setstraingainsoffsets
Definition: main.cpp:37
action_program
@ action_program
Definition: main.cpp:31
sBoard
Definition: downloader.h:22
cDownloader::strain_get_adc
int strain_get_adc(int bus, int target_id, char channel, unsigned int &adc, int type, string *errorstring=NULL)
Definition: downloader.cpp:348
programCanDevice
int programCanDevice(FirmwareUpdaterCore *, QString device, QString id, QString board, QString canLine, QString canId, QString file, bool eraseEEprom)
Definition: main.cpp:1641
verifyOnSecondLevel_ETHboard
int verifyOnSecondLevel_ETHboard(FirmwareUpdaterCore *core, QString device, QString id, const QString &targetIPaddr, const QString &targetFWvers)
Definition: main.cpp:2119
cDownloader::strain_set_full_scale
int strain_set_full_scale(int bus, int target_id, unsigned char channel, unsigned int full_scale, int regset=strain_regset_inuse, string *errorstring=NULL)
Definition: downloader.cpp:1221
FirmwareUpdaterCore
Definition: firmwareupdatercore.h:15
action_setstrainsn
@ action_setstrainsn
Definition: main.cpp:36
FirmwareUpdaterCore::connectTo
int connectTo(QString device, QString id)
Definition: firmwareupdatercore.cpp:184
cDownloader::strain_regset_inuse
@ strain_regset_inuse
Definition: downloader.h:147
ampl_gain08
@ ampl_gain08
Definition: downloader.h:107
sBoard::bus
int bus
Definition: downloader.h:25
cDownloader::get_serial_no
int get_serial_no(int bus, int target_id, char *board_info)
Definition: downloader.cpp:2123