3 #include <EoUpdaterProtocol.h>
10 self->updateProgress(fraction);
14 bool FirmwareUpdaterCore::isValidIpAddress(QString addr)
18 ipFields = addr.split(
".");
19 if(ipFields.count() == 4 && ipFields[3].contains(
":"))
21 QString address_,port_;
22 int ipv0, ipv1, ipv2, ipv3;
24 address_ = addr.split(
":")[0];
25 port_ = ipFields[3].split(
":")[1];
28 if (!re.exactMatch(port_))
return false;
29 for(
int k=0; k<4; k++)
31 if (!re.exactMatch(address_.split(
".")[k]))
return false;
34 ipv0 = address_.split(
".")[0].toInt();
35 ipv1 = address_.split(
".")[1].toInt();
36 ipv2 = address_.split(
".")[2].toInt();
37 ipv3 = address_.split(
".")[3].toInt();
39 if(ipv0 == 10 && 0 < ipv1 < 255 && 0 < ipv2 < 255 && 0 < ipv3 < 255 && 0 < port_.toInt() < 255)
41 hostIPaddress = EO_COMMON_IPV4ADDR(ipv0, ipv1, ipv2, ipv3);
56 verbosity = VerbositY;
62 Bottle sensorSetConfig=config.findGroup(
"DRIVERS").tail();
64 for (
int t=0; t<sensorSetConfig.size(); ++t){
65 yarp::os::Bottle sensorConfig(sensorSetConfig.get(t).toString());
67 QString type = QString(
"%1").arg(sensorConfig.get(0).asString().c_str());
68 QString line = QString(
"%1").arg(sensorConfig.get(1).asString().c_str());
69 if(verbosity>0) qDebug() << type <<
"-" << line;
72 int num = QString(
"%1").arg(line).toInt(&
ok);
74 devices.append(QPair<QString,QVariant>(type,num));
76 devices.append(QPair<QString,QVariant>(type,line));
83 if(isValidIpAddress(line))
85 port = line.split(
":")[1].toInt();
86 qDebug() <<
"IP address FOUND in .ini file, Using :" << line.split(
":")[0];
87 qDebug() <<
"Port Number FOUND in .ini file, Using :" << line.split(
":")[1];
91 int ipv0, ipv1, ipv2, ipv3;
93 ipv0 = address.split(
".")[0].toInt();
94 ipv1 = address.split(
".")[1].toInt();
95 ipv2 = address.split(
".")[2].toInt();
96 ipv3 = address.split(
".")[3].toInt();
98 hostIPaddress = EO_COMMON_IPV4ADDR(ipv0, ipv1, ipv2, ipv3);
100 qDebug() <<
"Missing or invalid IP address found in .ini file (format is 10.0.X.Y:Z , 0 < X,Y < 255 , Z port number)";
101 qDebug() <<
"Skipped, using defaults:";
113 if(!gMNT.
open(hostIPaddress, port))
115 if(verbosity>0) qDebug(
"Can't open socket, aborting.");
127 bool lowers_are_verbose = (verb >= 1) ?
true :
false;
128 gMNT.
verbose(lowers_are_verbose);
138 for(
int i=0;i<devices.count();i++){
139 QPair<QString,QVariant>
p = devices.at(i);
140 names.append(
p.first);
193 if(!device.isEmpty() && !
id.isEmpty()){
194 if(device.contains(
"ETH")){
198 yDebug() <<
"FirmwareUpdaterCore::connectTo() has found " << num <<
" ETH boards";
216 QString boardIp = QString(
"%1").arg(gMNT.
boards_get()[i].getIPV4string().c_str());
218 return gMNT.
boards_get()[i].isInMaintenance();
233 gMNT.
boards_get()[index].setSelected(selected);
243 if(QString(
"%1").arg(gMNT.
boards_get()[i].getIPV4string().c_str()) == boardIp){
256 if(!address.isEmpty() && deviceId == -1){
262 this->canBoards = selectedBoards;
264 foreach (
sBoard b, selectedBoards) {
296 if(!address.isEmpty() && deviceId == -1){
312 *address = gMNT.
boards_get()[boardNum].getIPV4();
313 if(infoString &&
info.protversion == 0){
314 *infoString = QString(
"%1").arg(gMNT.
moreinformation(*address,
false).c_str());
326 case uprot_proc_Loader:
328 case uprot_proc_Updater:
330 case uprot_proc_Application00:
331 return isMultiCore ?
"eApplication_core_0" :
"eApplication";
332 case uprot_proc_Application01:
333 return "eApplication_core_1";
334 case uprot_proc_ApplPROGupdater:
335 return "eApplPROGupdater";
349 if(downloader.
connected && (!currentAddress.isEmpty() || (currentDriver != driver || currentId !=
networkId ))){
352 if(currentDriver == driver && currentId ==
networkId){
359 yarp::os::Property params;
361 if(driver.contains(
"CFW2",Qt::CaseInsensitive)){
363 }
else if(driver.contains(
"ECAN",Qt::CaseInsensitive)){
365 }
else if(driver.contains(
"PCAN",Qt::CaseInsensitive)){
367 }
else if(driver.contains(
"SOCKET",Qt::CaseInsensitive)){
370 params.put(
"device",
networkType.toLatin1().data());
372 params.put(
"canTxQueue", 64);
373 params.put(
"canRxQueue", 64);
374 params.put(
"canTxTimeout", 2000);
375 params.put(
"canRxTimeout", 2000);
378 int ret = downloader.
initdriver(params, (verbosity>1) ?
true :
false);
382 if(verbosity>0) qDebug() <<
"FirmwareUpdaterCore::getCanBoardsFromDriver(): Init ETH driver - The ETH board has just jumped to eUpdater\n Connect again";
383 *retString =
"FirmwareUpdaterCore::getCanBoardsFromDriver(): Init ETH driver - The ETH board has just jumped to eUpdater\n Connect again";
386 if(verbosity>0) qDebug() <<
"FirmwareUpdaterCore::getCanBoardsFromDriver(): Init driver failed - Hardware busy or not connected?!";
387 *retString =
"Cannot init driver " + driver +
"<" + QString::number(
networkId) +
"> ... HW is busy or not connected";
399 if(verbosity>0) qDebug() <<
"FirmwareUpdaterCore::getCanBoardsFromDriver(): No answer received from CAN boards after a successful driver init.";
400 *retString =
"No CAN boards found beneath " + driver +
"<" + QString::number(
networkId) +
">";
412 currentDriver = driver;
428 if(downloader.
connected && address != currentAddress && !currentAddress.isEmpty() || (currentAddress.isEmpty() && !currentDriver.isEmpty())){
432 if(currentAddress == address){
446 if(verbosity>0) qDebug() <<
"FirmwareUpdaterCore::getCanBoardsFromEth(): Init driver failed - Could not find network interface";
448 *retString =
"Init driver failed - Could not find network interface";
455 yarp::os::Property params;
456 params.put(
"device",
"ETH");
459 params.put(
"canid",
canID);
463 int ret = downloader.
initdriver(params, (verbosity>1) ?
true :
false);
467 if(verbosity>0) qDebug() <<
"FirmwareUpdaterCore::getCanBoardsFromEth((): Init ETH driver - The ETH board has just jumped to eUpdater\n Connect again";
468 *retString =
"FirmwareUpdaterCore::getCanBoardsFromEth((): Init ETH driver - The ETH board has just jumped to eUpdater\n Connect again";
471 if(verbosity>0) qDebug() <<
"FirmwareUpdaterCore::getCanBoardsFromEth((): Init driver failed - Hardware busy or not connected?!";
472 *retString =
"FirmwareUpdaterCore::getCanBoardsFromEth(): Init driver failed - Hardware busy or not connected?!";
484 if(verbosity>0) qDebug() <<
"FirmwareUpdaterCore::getCanBoardsFromEth(): No CAN boards found beneath " << address <<
" after a successful driver init.";
485 *retString =
"No CAN boards found beneath " + address;
496 currentAddress = address;
506 bool FirmwareUpdaterCore::compile_ip_addresses(
const char* addr,
unsigned int *
remoteAddr,
unsigned int *
localAddr)
508 ACE_UINT32 ip1,ip2,ip3,ip4;
509 sscanf(addr,
"%d.%d.%d.%d",&ip1,&ip2,&ip3,&ip4);
513 ACE_INET_Addr* addr_array=NULL;
514 int ret=ACE::get_ip_interfaces(count,addr_array);
522 *
localAddr=addr_array[0].get_ip_address();
524 for (
unsigned int a=1; a<count; ++a)
526 if ((*
remoteAddr & 0xFFFF0000)==(addr_array[a].get_ip_address() & 0xFFFF0000))
528 *
localAddr=addr_array[a].get_ip_address();
546 QString ret = QString(
"%1").arg(gMNT.
boards_get()[index].getInfoOnEEPROM().c_str());
554 char board_ipaddr[16];
556 sprintf(board_ipaddr,
"%d.%d.%d.%d",(ip>>24)&0xFF,(ip>>16)&0xFF,(ip>>8)&0xFF,ip&0xFF);
558 return QString(
"%1").arg(board_ipaddr);
564 eOipv4addr_t address = gMNT.
boards_get()[index].getIPV4();
567 if(verbosity>0) qDebug() <<
"setEthBoardInfo failed";
572 foreach (
string v, vv) {
573 if(verbosity>0) qDebug() << v.c_str();
578 if(verbosity>0) qDebug() << gMNT.
boards_get()[index].getInfoOnEEPROM().c_str();
588 if(!address.isEmpty() && deviceId == -1){
611 if(!address.isEmpty() && deviceId == -1){
617 int new_val = newAddress.toInt();
618 if (new_val <=0 || new_val> 15){
619 if(verbosity>0) qDebug() <<
"Error, new address out of range 0 - 15";
624 if(verbosity>0) qDebug() <<
"Error, same address set";
661 sscanf(newAddress.toLatin1().data(),
"%d.%d.%d.%d",&ip1,&ip2,&ip3,&ip4);
662 if (ip1<0 || ip1>255 || ip2<0 || ip2>255 || ip3<0 || ip3>255 || ip4<0 || ip4>255){
666 ACE_UINT32 iNewAddress=(ip1<<24)|(ip2<<16)|(ip3<<8)|ip4;
670 ACE_UINT32 mask = 0xFFFFFF00;
672 if(iNewAddress == (iNewAddress & mask)){
673 if(verbosity>0) qDebug() <<
"Error Setting address";
678 if((~mask) == (iNewAddress & (~mask))){
679 if(verbosity>0) qDebug() <<
"Error Setting address";
684 if (iNewAddress == address){
685 if(verbosity>0) qDebug() <<
"Error, same address set";
690 sprintf(old_addr,
"%d.%d.%d.%d",(address>>24)&0xFF,(address>>16)&0xFF,(address>>8)&0xFF,address&0xFF);
704 FILE *programFile=fopen(filename.toLatin1().data(),
"r");
707 if(verbosity>0) qDebug() <<
"Error opening the selected file!";
711 eOipv4addr_t ipv4 = 0;
712 eObrd_ethtype_t type = eobrd_ethtype_none;
721 *resultString = QString(
"%1").arg(result.c_str());
734 FILE *programFile=fopen(filename.toLatin1().data(),
"r");
737 if(verbosity>0) qDebug() <<
"Error opening the selected file!";
741 eOipv4addr_t ipv4 = 0;
742 eObrd_ethtype_t type = eobrd_ethtype_none;
751 *resultString = QString(
"%1").arg(result.c_str());
765 if(!ethAddress.isEmpty()){
766 if(currentAddress != ethAddress){
774 double timer_start =0;
778 *resultString =
"Driver not running";
784 bool at_least_one_board_selected =
false;
789 at_least_one_board_selected =
true;
792 if (!at_least_one_board_selected){
793 *resultString =
"No Boards selected! - Select one or more boards to update the firmware";
798 QMap<int,int> canDevices;
805 if(verbosity>0) qDebug() <<
"FOUND SELECTED SCHEDA " << i <<
" ON BUS " << downloader.
board_list[i].
bus;
811 int busCount = canDevices.uniqueKeys().count();
812 for(
int k=0;k<busCount;k++){
814 int bus = canDevices.uniqueKeys().at(k);
816 if (downloader.
open_file(filename.toLatin1().data())!=0){
817 *resultString =
"Error opening the selected file!";
821 if(verbosity>0) qDebug() <<
"FILE " << filename <<
" OPENED";
837 int download_type = icubCanProto_boardType__unknown;
838 bool download_eeprom =
false;
841 QList<int> indexes = canDevices.values(bus);
848 for(
int i=0;i<indexes.count();i++){
849 int index = indexes.at(i);
851 if(verbosity>0) qDebug() <<
"SELECTING BOARD " << index <<
" OF BUS " << bus;
857 *resultString =
"Unable to start the board - Unable to send message 'start' or no answer received";
861 if(verbosity>0) qDebug() <<
"START SCHEDA " << index <<
" ON BUS " << bus <<
" OK";
891 timer_start= yarp::os::Time::now();
893 bool print00 =
false, print25 =
false, print50 =
false, print75 =
false, print99 =
false;
897 ret = downloader.
download_file(bus, 0x0F, download_type,download_eeprom);
898 if (
float(downloader.
progress)/downloader.
file_length/busCount >0.0 && print00==
false) {
if(verbosity>0) qDebug(
"downloading %s, 1%% done\n",filename.toLatin1().data()); print00=
true;}
899 if (
float(downloader.
progress)/downloader.
file_length/busCount >0.25 && print25==
false) {
if(verbosity>0) qDebug(
"downloading %s, 25%% done\n",filename.toLatin1().data()); print25=
true;}
900 if (
float(downloader.
progress)/downloader.
file_length/busCount >0.50 && print50==
false) {
if(verbosity>0) qDebug(
"downloading %s, 50%% done\n",filename.toLatin1().data()); print50=
true;}
901 if (
float(downloader.
progress)/downloader.
file_length/busCount >0.75 && print75==
false) {
if(verbosity>0) qDebug(
"downloading %s, 75%% done\n",filename.toLatin1().data()); print75=
true;}
902 if (
float(downloader.
progress)/downloader.
file_length/busCount >0.99 && print99==
false) {
if(verbosity>0) qDebug(
"downloading %s, finished!\n",filename.toLatin1().data()); print99=
true;}
908 if(verbosity>0) qDebug() <<
"Fatal Error during download, terminate";
909 *resultString =
"Fatal Error during download, terminate";
913 if(verbosity>0) qDebug() <<
"Download terminated";
914 *resultString =
"Download terminated";
924 if(verbosity>0) qDebug() <<
"ERROR STOPPING SCHEDA";
926 if(verbosity>0) qDebug() <<
"scheda stopped";
929 foreach (
int index, indexes) {
931 if(verbosity>0) qDebug() <<
"DE-SELECTING BOARD " << index <<
" OF BUS " << bus;
937 timer_end= yarp::os::Time::now();
946 double download_time = (timer_end-timer_start) ;
947 sprintf (time_text,
"All Board OK! Download Time (s): %.2f", download_time);
949 *resultString = QString(
"Download Finished. %1").arg(time_text);
981 if(!address.isEmpty() && deviceId == -1){
988 double timer_start =0;
992 *resultString =
"Driver not running";
997 bool at_least_one_board_selected =
false;
1003 at_least_one_board_selected =
true;
1006 if (!at_least_one_board_selected){
1007 *resultString =
"No Boards selected! - Select one or more boards to update the firmware";
1010 if (downloader.
open_file(filename.toLatin1().data())!=0){
1011 *resultString =
"Error opening the selected file!";
1024 int firmware_board_type=0;
1025 int firmware_version=0;
1026 int firmware_revision=0;
1029 int download_type = icubCanProto_boardType__unknown;
1030 bool download_eeprom =
false;
1040 download_eeprom = ee;
1048 *resultString =
"Unable to start the board - Unable to send message 'start' or no answer received";
1059 timer_start= yarp::os::Time::now();
1064 bool print00 =
false, print25 =
false, print50 =
false, print75 =
false, print99 =
false;
1069 if (
float(downloader.
progress)/downloader.
file_length >0.0 && print00==
false) {
if(verbosity>0) qDebug(
"programming %s: 1%% done",filename.toLatin1().data()); print00=
true;}
1070 if (
float(downloader.
progress)/downloader.
file_length >0.25 && print25==
false) {
if(verbosity>0) qDebug(
"programming %s: 25%% done",filename.toLatin1().data()); print25=
true;}
1071 if (
float(downloader.
progress)/downloader.
file_length >0.50 && print50==
false) {
if(verbosity>0) qDebug(
"programming %s: 50%% done",filename.toLatin1().data()); print50=
true;}
1072 if (
float(downloader.
progress)/downloader.
file_length >0.75 && print75==
false) {
if(verbosity>0) qDebug(
"programming %s: 75%% done",filename.toLatin1().data()); print75=
true;}
1073 if (
float(downloader.
progress)/downloader.
file_length >0.99 && print99==
false) {
if(verbosity>0) qDebug(
"programming %s: finished!",filename.toLatin1().data()); print99=
true;}
1087 *resultString =
"Fatal Error during download, terminate";
1092 *resultString =
"Download terminated";
1097 while (finished!=1);
1098 timer_end= yarp::os::Time::now();
1106 yarp::os::Time::delay(3.0);
1110 char time_text [50];
1111 double download_time = (timer_end-timer_start) ;
1112 sprintf (time_text,
"All Board OK! Download Time (s): %.2f", download_time);
1114 *resultString = QString(
"Download Finished. %1").arg(time_text);
1123 if(resultCanBoards){
1124 *resultCanBoards = canBoards;
1142 *resultCanBoards = canBoards;
1150 FILE *programFile=fopen(filename.toLatin1().data(),
"r");
1154 if(verbosity>0) qDebug() <<
"Error opening the selected file:" << filename <<
"or .." << filename.toLatin1().data();
1158 eOipv4addr_t ipv4 = 0;
1159 eObrd_ethtype_t type = eobrd_ethtype_none;
1168 *resultString = QString(
"%1").arg(result.c_str());
eOipv4addr_t acetoipv4(ACE_UINT32 address)
ACE_UINT32 ipv4toace(eOipv4addr_t ipv4)
std::string moreinformation(eOipv4addr_t ipv4, bool forcemaintenance=false)
bool command_jump2updater(eOipv4addr_t ipv4)
EthBoardList discover(bool clearbeforediscovery=true, int numberofdiscoveries=1, double waittimeout=1.0)
static const eOipv4addr_t ipv4OfAllSelected
bool open(eOipv4addr_t ipv4=hostIPaddress, eOipv4port_t port=mainIPport)
bool command_def2run(eOipv4addr_t ipv4, eOuprot_process_t process, bool forcemaintenance=true, bool verify=true)
bool go2application(eOipv4addr_t ipv4, bool checkdef2runapplication=true, double bootstraptime=10.0, bool verify=true)
EthBoardList & boards_get(void)
bool go2maintenance(eOipv4addr_t ipv4, bool verify=true, int retries=6, double timegap=1.0)
bool command_info32_set(eOipv4addr_t ipv4, const string &info32)
vector< string > command_info32_get(eOipv4addr_t ipv4)
bool command_blink(eOipv4addr_t ipv4)
bool program(eOipv4addr_t ipv4, eObrd_ethtype_t type, eOuprot_process_t process, eOversion_t targetversion, FILE *fp, bool forcemaintenance=true, void progress(float)=NULL, bool restart2application=true)
bool command_eeprom_erase(eOipv4addr_t ipv4)
bool command_restart(eOipv4addr_t ipv4)
bool command_changeaddress(eOipv4addr_t ipv4, eOipv4addr_t ipv4new, bool checkifnewispresent=true, bool forcemaintenance=true, bool restart=false, bool verify=false)
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)
QString getProcessFromUint(uint8_t id, bool isMultiCore=false)
QString getEthBoardInfo(int index)
QList< sBoard > getCanBoardsFromEth(QString address, QString *retString, int canID=CanPacket::everyCANbus, bool force=false)
void setSelectedEthBoard(int index, bool selected)
void disconnectFrom(QString device, QString id)
FirmwareUpdaterCore(QObject *parent=0)
void setSelectedCanBoard(int index, bool selected, QString ethAddress="", int deviceId=-1)
QString getEthBoardAddress(int index)
boardInfo2_t getMoreDetails(int boardNum=EthMaintainer::ipv4OfAllSelected, QString *infoString=NULL, eOipv4addr_t *address=NULL)
EthBoardList getEthBoardList()
QList< QPair< QString, QVariant > > getDevices()
void updateProgress(float)
void bootFromApplication()
bool setEthBoardInfo(int index, QString newInfo)
bool uploadUpdater(QString filename, QString *resultString)
bool isBoardInMaintenanceMode(QString ip)
void setCanBoardInfo(int bus, int id, QString newInfo, QString ethAddress="", int deviceId=-1, QString *resultString=NULL)
bool setCanBoardAddress(int bus, int id, int canType, QString newAddress, QString ethAddress="", int deviceId=-1, QString *resultString=NULL)
QStringList getDevicesName()
bool uploadEthApplication(QString filename, QString *resultString)
bool uploadLoader(QString filename, QString *resultString)
bool init(Searchable &config, int port, QString address, int VerbositY)
cDownloader * getDownloader()
bool setVerbosity(int verb)
int open_file(std::string file)
int change_card_address(int bus, int target_id, int new_id, int board_type)
int startscheda(int bus, int board_pid, bool board_eeprom, int download_type)
int stopscheda(int bus, int board_pid)
void set_verbose(bool verbose)
int change_board_info(int bus, int target_id, char *board_info)
int initdriver(yarp::os::Searchable &config, bool verbose=true)
int download_file(int bus, int board_pid, int download_type, bool eeprom)
static void updateProgressCallback(float fraction)
#define DEFAULT_IP_ADDRESS