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