11 #include <yarp/os/Time.h>
13 #include <yarp/os/Log.h>
15 using namespace yarp::os;
22 #define PRINT_DEBUG_INFO_ON_TERMINAL
30 eOuprot_cmd_DISCOVER_t *
cmd = (eOuprot_cmd_DISCOVER_t*) mTxBuffer;
32 memset(
cmd, EOUPROT_VALUE_OF_UNUSED_BYTE,
sizeof(eOuprot_cmd_DISCOVER_t));
34 cmd->opc = uprot_OPC_LEGACY_SCAN;
35 cmd->opc2 = uprot_OPC_DISCOVER;
36 cmd->jump2updater = 1;
38 int numberOfDiscovered = 0;
40 mSocket.SendBroad(
cmd,
sizeof(eOuprot_cmd_DISCOVER_t), mPort);
43 ACE_UINT32 rxAddress = mMyAddress;
45 while (mSocket.ReceiveFrom(mRxBuffer,
sizeof(mRxBuffer), rxAddress, rxPort, 1000)>0)
47 eOuprot_cmd_DISCOVER_REPLY_t * disc = (eOuprot_cmd_DISCOVER_REPLY_t*) mRxBuffer;
48 eOuprot_cmd_LEGACY_SCAN_REPLY_t * scan = (eOuprot_cmd_LEGACY_SCAN_REPLY_t*) mRxBuffer;
50 snprintf(ipaddr,
sizeof(ipaddr),
"%d.%d.%d.%d",(rxAddress>>24)&0xFF, (rxAddress>>16)&0xFF, (rxAddress>>8)&0xFF, rxAddress&0xFF);
56 if(uprot_OPC_DISCOVER == disc->reply.opc)
59 if (rxAddress != mMyAddress)
70 memcpy(&binfo.
processes, &disc->processes,
sizeof(eOuprot_proctable_t));
75 mBoardList.addBoard(pBoard);
79 #if defined(PRINT_DEBUG_INFO_ON_TERMINAL)
80 uint8_t index = eouprot_process2index((eOuprot_process_t)disc->processes.runningnow);
81 printf(
"Discovered a board @ %s: %s w/ %s v %d.%d running protocol v %d w/ capabilities = 0x%x.\n",
83 eoboards_type2string2((eObrd_type_t)disc->boardtype, eobool_true),
84 eouprot_process2string((eOuprot_process_t)disc->processes.runningnow),
85 disc->processes.info[index].version.major,
86 disc->processes.info[index].version.minor,
87 disc->reply.protversion,
94 else if (uprot_OPC_LEGACY_SCAN == scan->opc)
98 if (rxAddress!=mMyAddress)
108 ACE_UINT8 protocol_version = 0;
110 ACE_UINT32 protocol_capabilities = eouprot_get_capabilities(eUpdater, protocol_version);
112 ACE_UINT8 procmajor = scan->version.major;
113 ACE_UINT8 procminor = scan->version.minor;
116 ACE_UINT32 mask=*(ACE_UINT32*)(scan->ipmask);
119 for(
int i=7; i>=0; --i)
121 mac=(mac<<8)|scan->mac48[i];
124 BoardInfo *pBoard =
new BoardInfo(rxAddress, mask, mac, procmajor, procminor, protocol_version, protocol_capabilities);
126 mBoardList.addBoard(pBoard);
128 numberOfDiscovered++;
130 #if defined(PRINT_DEBUG_INFO_ON_TERMINAL)
131 printf(
"Discovered a board @ %s: the running process is v %d.%d, uses legacy protocol, i assume protocol capabilities = 0x%x.\n",
132 ipaddr, procmajor, procminor, protocol_capabilities);
139 return numberOfDiscovered;
147 vector<BoardInfo *> boards = mBoardList.getBoards(address);
149 if(0 == boards.size())
156 for(
int i=0; i<boards.size(); i++)
158 uint32_t mask = boards[i]->mProtocolCapabilities;
159 bool r = ((mask & capability) == capability) ? true :
false;
169 eOuprot_cmd_MOREINFO_t command;
171 command.opc = uprot_OPC_LEGACY_PROCS;
172 command.opc2 = uprot_OPC_MOREINFO;
173 command.plusdescription = 1;
174 command.jump2updater = 1;
179 sendCommandSelected(&command,
sizeof(command));
183 mSocket.SendTo(&command,
sizeof(command), mPort, address);
187 ACE_UINT32 rxAddress;
191 while (mSocket.ReceiveFrom(mRxBuffer,
sizeof(mRxBuffer), rxAddress, rxPort, 500)>0)
193 eOuprot_cmd_MOREINFO_REPLY_t *moreinfo = (eOuprot_cmd_MOREINFO_REPLY_t*) mRxBuffer;
194 eOuprot_cmd_LEGACY_PROCS_REPLY_t *procs = (eOuprot_cmd_LEGACY_PROCS_REPLY_t*) mRxBuffer;
197 snprintf(ipaddr,
sizeof(ipaddr),
"%d.%d.%d.%d",(rxAddress>>24)&0xFF, (rxAddress>>16)&0xFF, (rxAddress>>8)&0xFF, rxAddress&0xFF);
199 if(uprot_OPC_LEGACY_PROCS == procs->opc)
203 #if defined(PRINT_DEBUG_INFO_ON_TERMINAL)
204 printf(
"\n received a uprot_OPC_LEGACY_PROCS from IP %s \n", ipaddr);
207 if (rxAddress != mMyAddress)
209 info+=
"------------------------------\r\n";
210 info+=std::string(
"Board\t")+std::string(ipaddr);
212 info+=std::string((
char*)procs->description);
215 else if(uprot_OPC_MOREINFO == moreinfo->discover.reply.opc)
219 #if defined(PRINT_DEBUG_INFO_ON_TERMINAL)
220 printf(
"\n received a uprot_OPC_MOREINFO with prot version %d from IP %s\n", moreinfo->discover.reply.protversion, ipaddr);
224 if (rxAddress != mMyAddress)
226 eOuprot_cmd_DISCOVER_REPLY_t * disc = &moreinfo->discover;
234 memcpy(&binfo.
processes, &disc->processes,
sizeof(eOuprot_proctable_t));
240 mBoardList.replaceBoard(pBoard);
243 #if defined(PRINT_DEBUG_INFO_ON_TERMINAL)
250 printf(
"\nBOARD at address %s:", ipaddr);
251 printf(
"\n prot = %d, boardtype = %s, startup proc = %s, def2run proc = %s. it has %d processes:",
253 eoboards_type2string2((eObrd_type_t)binfo.
boardtype, eobool_true),
254 eouprot_process2string((eOuprot_process_t)binfo.
processes.startup),
255 eouprot_process2string((eOuprot_process_t)binfo.
processes.def2run),
260 char strdate[24] = {0};
261 char builton[24] = {0};
262 eo_common_date_to_string(binfo.
processes.info[
n].date, strdate,
sizeof(strdate));
263 eo_common_date_to_string(binfo.
processes.info[
n].compilationdate, builton,
sizeof(builton));
264 printf(
"\n proc-%d: type %s w/ appl version = (%d, %d), dated %s, built on %s, rom = [%d, %d) kb",
266 eouprot_process2string((eOuprot_process_t)binfo.
processes.info[
n].type),
275 printf(
"\n now process %s is running", eouprot_process2string((eOuprot_process_t)binfo.
processes.runningnow));
279 printf(
"\n stored info32 is .. ");
280 for(
int m=0; m<32; m++)
288 printf(
"\n stored info32 is .. ");
297 info+=
"------------------------------\r\n";
298 info+=std::string(
"Board\t")+std::string(ipaddr);
300 if(1 == moreinfo->hasdescription)
302 info+=std::string((
char*)moreinfo->description);
306 info+=std::string(
"the message does not have a textual description");
321 eOuprot_cmd_PAGE_CLR_t command = {EOUPROT_VALUE_OF_UNUSED_BYTE};
322 command.opc = uprot_OPC_PAGE_CLR;
323 command.pagesize = 32;
327 sendCommandSelected(&command,
sizeof(command));
331 mSocket.SendTo(&command,
sizeof(command), mPort, address);
341 eOuprot_cmd_PAGE_SET_t *
cmd = (eOuprot_cmd_PAGE_SET_t*) mTxBuffer;
342 uint16_t sizeofcmd =
sizeof(eOuprot_cmd_PAGE_SET_t) - uprot_pagemaxsize + 32;
346 memset(
cmd, EOUPROT_VALUE_OF_UNUSED_BYTE, sizeofcmd);
348 cmd->opc = uprot_OPC_PAGE_SET;
350 memset(
cmd->page, 0, 32);
353 const char * str32 = info32.c_str();
355 int len = strlen(str32);
361 memcpy(&
cmd->page[1], str32, len);
365 sendCommandSelected(
cmd, sizeofcmd);
369 mSocket.SendTo(
cmd, sizeofcmd, mPort, address);
378 vector<string> thestrings(0);
380 eOuprot_cmd_PAGE_GET_t command = {EOUPROT_VALUE_OF_UNUSED_BYTE};
381 command.opc = uprot_OPC_PAGE_GET;
382 command.pagesize = 32;
386 sendCommandSelected(&command,
sizeof(command));
390 mSocket.SendTo(&command,
sizeof(command), mPort, address);
394 ACE_UINT32 rxAddress;
397 while(mSocket.ReceiveFrom(mRxBuffer,
sizeof(mRxBuffer), rxAddress, rxPort, 500)>0)
399 eOuprot_cmd_PAGE_GET_REPLY_t * pageget = (eOuprot_cmd_PAGE_GET_REPLY_t*) mRxBuffer;
401 if(uprot_OPC_PAGE_GET == pageget->reply.opc)
405 if((rxAddress != mMyAddress) && (uprot_RES_OK == pageget->reply.res) && (32 == pageget->pagesize) && (0xff != pageget->page[0]))
407 readstring = string((
const char*)&pageget->page[1]);
408 thestrings.push_back(readstring);
411 #if defined(PRINT_DEBUG_INFO_ON_TERMINAL)
414 snprintf(ip32,
sizeof(ip32),
"%d.%d.%d.%d",(rxAddress>>24)&0xFF, (rxAddress>>16)&0xFF, (rxAddress>>8)&0xFF, rxAddress&0xFF);
416 if(uprot_RES_OK != pageget->reply.res)
418 printf(
"\n received a eOuprot_cmd_PAGE_GET_REPLY_t from IP %s with a failure result %d for size %d", ip32, pageget->reply.res, pageget->pagesize);
420 else if(rxAddress != mMyAddress)
422 printf(
"\n received a eOuprot_cmd_PAGE_GET_REPLY_t from IP %s with size %d: ", ip32, pageget->pagesize);
424 if(32 == pageget->pagesize)
427 uint8_t info32[32] = {0};
428 memcpy(info32, pageget->page, 32);
430 if(0xff == info32[0])
432 printf(
"\n stored info32 is .. ");
433 for(
int m=0; m<32; m++)
435 printf(
"0x%x ", info32[m]);
441 printf(
"l = %d, string = %s \n", info32[0], &info32[1]);
462 eOuprot_cmd_RESTART_t command = {EOUPROT_VALUE_OF_UNUSED_BYTE};
463 command.opc = uprot_OPC_RESTART;
467 mSocket.SendTo(&command,
sizeof(command), mPort, address);
471 sendCommandSelected(&command,
sizeof(command));
482 eOuprot_cmd_DEF2RUN_t command = {EOUPROT_VALUE_OF_UNUSED_BYTE};
483 command.opc = uprot_OPC_DEF2RUN;
484 command.proc = process;
489 #if defined(PRINT_DEBUG_INFO_ON_TERMINAL)
491 snprintf(ipaddr,
sizeof(ipaddr),
"%d.%d.%d.%d",(address>>24)&0xFF, (address>>16)&0xFF, (address>>8)&0xFF, address&0xFF);
492 printf(
"send command uprot_OPC_DEF2RUN w/ process = %s to %s\n", eouprot_process2string(process), ipaddr);
495 mSocket.SendTo(&command,
sizeof(command), mPort, address);
499 for(
int i=0; i<mBoardList.size(); ++i)
501 if(mBoardList[i].mSelected)
503 address = mBoardList[i].mAddress;
505 #if defined(PRINT_DEBUG_INFO_ON_TERMINAL)
507 snprintf(ipaddr,
sizeof(ipaddr),
"%d.%d.%d.%d",(address>>24)&0xFF, (address>>16)&0xFF, (address>>8)&0xFF, address&0xFF);
508 printf(
"send command uprot_OPC_DEF2RUN w/ process = %s to %s\n", eouprot_process2string(process), ipaddr);
511 mSocket.SendTo(&command,
sizeof(command), mPort, address);
524 eOuprot_cmd_JUMP2UPDATER_t command = {EOUPROT_VALUE_OF_UNUSED_BYTE};
525 command.opc = uprot_OPC_JUMP2UPDATER;
529 mSocket.SendTo(&command,
sizeof(command), mPort, address);
533 sendCommandSelected(&command,
sizeof(command));
544 eOuprot_cmd_JUMP2ADDRESS_t command = {EOUPROT_VALUE_OF_UNUSED_BYTE};
545 command.opc = uprot_OPC_JUMP2ADDRESS;
546 command.address = romaddress;
550 mSocket.SendTo(&command,
sizeof(command), mPort, address);
554 sendCommandSelected(&command,
sizeof(command));
565 eOuprot_cmd_BLINK_t command = {EOUPROT_VALUE_OF_UNUSED_BYTE};
566 command.opc = uprot_OPC_BLINK;
570 mSocket.SendTo(&command,
sizeof(command), mPort, address);
574 sendCommandSelected(&command,
sizeof(command));
585 eOuprot_cmd_EEPROM_ERASE_t command = {EOUPROT_VALUE_OF_UNUSED_BYTE};
587 command.opc = uprot_OPC_LEGACY_EEPROM_ERASE;
588 command.opc2 = uprot_OPC_EEPROM_ERASE;
589 command.sysrestart = 0;
595 mSocket.SendTo(&command,
sizeof(command), mPort, address);
599 sendCommandSelected(&command,
sizeof(command));
620 if((0 == size) || (size > uprot_EEPROMmaxsize))
625 eOuprot_cmd_EEPROM_READ_t command = {EOUPROT_VALUE_OF_UNUSED_BYTE};
627 command.opc = uprot_OPC_EEPROM_READ;
628 command.address = from;
631 mSocket.SendTo(&command,
sizeof(command), mPort, address);
636 ACE_UINT32 rxAddress = mMyAddress;
638 while (mSocket.ReceiveFrom(mRxBuffer,
sizeof(mRxBuffer), rxAddress, rxPort, 1000)>0)
640 eOuprot_cmd_EEPROM_READ_REPLY_t * eepromread = (eOuprot_cmd_EEPROM_READ_REPLY_t*) mRxBuffer;
643 snprintf(ipaddr,
sizeof(ipaddr),
"%d.%d.%d.%d",(rxAddress>>24)&0xFF, (rxAddress>>16)&0xFF, (rxAddress>>8)&0xFF, rxAddress&0xFF);
645 if(uprot_OPC_EEPROM_READ == eepromread->reply.opc)
648 if (rxAddress == address)
650 ret = (uprot_RES_OK == eepromread->reply.res) ?
true :
false;
654 *value = eepromread->eeprom;
667 eOuprot_cmd_IP_ADDR_SET_t command = {EOUPROT_VALUE_OF_UNUSED_BYTE};
669 command.opc = uprot_OPC_LEGACY_IP_ADDR_SET;
670 command.opc2 = uprot_OPC_IP_ADDR_SET;
671 command.sysrestart = 0;
673 command.address[0] = (newaddress>>24) & 0xFF;
674 command.address[1] = (newaddress>>16) & 0xFF;
675 command.address[2] = (newaddress>>8 ) & 0xFF;
676 command.address[3] = (newaddress ) & 0xFF;
678 #if defined(PRINT_DEBUG_INFO_ON_TERMINAL)
680 snprintf(ipaddr,
sizeof(ipaddr),
"%d.%d.%d.%d",(address>>24)&0xFF, (address>>16)&0xFF, (address>>8)&0xFF, address&0xFF);
682 snprintf(newipaddr,
sizeof(ipaddr),
"%d.%d.%d.%d",(newaddress>>24)&0xFF, (newaddress>>16)&0xFF, (newaddress>>8)&0xFF, newaddress&0xFF);
693 if((10 != command.address[0]) || (0 != command.address[1]) || (1 != command.address[2]))
698 if((0 == command.address[3]) || (255 == command.address[3]))
705 #if defined(PRINT_DEBUG_INFO_ON_TERMINAL)
706 printf(
"cannot send command uprot_OPC_IP_ADDR_SET to %s with new address %s because either one or both are not valid\n", ipaddr, newipaddr);
712 #if defined(PRINT_DEBUG_INFO_ON_TERMINAL)
713 printf(
"sent command uprot_OPC_IP_ADDR_SET to %s, new address is %s. w/%s sysrestart\n", ipaddr, newipaddr, (0 == command.sysrestart) ?
"out" :
"");
716 mSocket.SendTo(&command,
sizeof(command), mPort, address);
724 std::string
EthUpdater::cmdProgram(FILE *programFile,
int partition,
void (*updateProgressBar)(
float), ACE_UINT32 address)
726 updateProgressBar(0.0f);
728 eOuprot_cmd_PROG_START_t * cmdStart = (eOuprot_cmd_PROG_START_t*) mTxBuffer;
729 eOuprot_cmd_PROG_DATA_t * cmdData = (eOuprot_cmd_PROG_DATA_t*) mTxBuffer;
730 eOuprot_cmd_PROG_END_t * cmdEnd = (eOuprot_cmd_PROG_END_t*) mTxBuffer;
732 const int sizeStart =
sizeof(eOuprot_cmd_PROG_START_t);
733 const int sizeEnd =
sizeof(eOuprot_cmd_PROG_END_t);
736 const int HEAD_SIZE = 7;
738 fseek(programFile,0,SEEK_END);
739 float fileSize=(float)(ftell(programFile)/3);
740 fseek(programFile,0,SEEK_SET);
742 memset(cmdStart, EOUPROT_VALUE_OF_UNUSED_BYTE,
sizeof(eOuprot_cmd_PROG_START_t));
743 cmdStart->opc = uprot_OPC_PROG_START;
744 cmdStart->partition = partition;
746 string partname(
"UNK");
747 eOuprot_proc_capabilities_t capability = uprot_canDO_nothing;
748 if(uprot_partitionLOADER == partition)
750 partname = string(
"LDR");
751 capability = uprot_canDO_PROG_loader;
753 else if(uprot_partitionUPDATER == partition)
755 partname = string(
"UPD");
756 capability = uprot_canDO_PROG_updater;
758 else if(uprot_partitionAPPLICATION == partition)
760 partname = string(
"APP");
761 capability = uprot_canDO_PROG_application;
773 for (
int i=0; i<mBoardList.size(); ++i)
775 if (mBoardList[i].mSelected)
777 mBoard2Prog[mN2Prog++]=&mBoardList[i];
778 mBoardList[i].mSuccess=0;
779 mSocket.SendTo(cmdStart, sizeStart, mPort, mBoardList[i].mAddress);
780 yarp::os::Time::delay(0.01);
789 vector<BoardInfo *> boards = mBoardList.getBoards(address);
791 std::string errorstring;
793 snprintf(addr,
sizeof(addr),
"%d.%d.%d.%d: ",(address>>24)&0xFF,(address>>16)&0xFF,(address>>8)&0xFF,address&0xFF);
797 if(0 == boards.size())
799 errorstring +=
"CANT find it\r\n";
802 else if(boards.size() > 1)
806 errorstring +=
"CANT prog more than one";
810 boards[0]->mSuccess = 0;
811 mBoard2Prog[mN2Prog++] = boards[0];
812 mSocket.SendTo(cmdStart, sizeStart, mPort, address);
813 yarp::os::Time::delay(0.01);
816 #if defined(PRINT_DEBUG_INFO_ON_TERMINAL)
818 printf(
"EthUpdater::cmdProgram() is about to program the %s partition of %d boards:", partname.c_str(), mN2Prog);
819 for(
int j=0; j< mN2Prog; j++)
822 ACE_UINT32 ipv4 = mBoard2Prog[j]->mAddress;
823 bool ok = isCmdSupported(capability, ipv4);
824 snprintf(ipv4str,
sizeof(ipv4str),
"%d.%d.%d.%d",(ipv4>>24)&0xFF,(ipv4>>16)&0xFF,(ipv4>>8)&0xFF,ipv4&0xFF);
826 printf(
" %s (%s)", ipv4str,
ok ? (
"candoit") : (
"CANTdoit"));
840 ACE_UINT32 rxAddress;
846 int numberOfOKreplies = 0;
849 for (
int n=0;
n<1000; ++
n)
851 while (mSocket.ReceiveFrom(mRxBuffer,
sizeof(mRxBuffer), rxAddress, rxPort, 10)>0)
853 eOuprot_cmdREPLY_t * reply = (eOuprot_cmdREPLY_t*) mRxBuffer;
855 if (uprot_OPC_PROG_START == reply->opc)
857 if (rxAddress!=mMyAddress)
859 for (
int i=0; i<mN2Prog; ++i)
861 if (rxAddress == mBoard2Prog[i]->mAddress)
863 if(uprot_RES_OK == reply->res)
865 ++(mBoard2Prog[i]->mSuccess);
870 #if defined(PRINT_DEBUG_INFO_ON_TERMINAL)
873 ACE_UINT32 ipv4 = mBoard2Prog[i]->mAddress;
875 snprintf(ipv4str,
sizeof(ipv4str),
"%d.%d.%d.%d",(ipv4>>24)&0xFF,(ipv4>>16)&0xFF,(ipv4>>8)&0xFF,ipv4&0xFF);
877 printf(
"board %s tells that we cannot program the %s partition\n", ipv4str, partname.c_str());
883 if (++success>=mN2Prog)
n=1000;
892 if(0 == numberOfOKreplies)
894 std::string earlyexit;
897 for (
int i=0; i<mN2Prog; ++i)
899 ACE_UINT32 ip=mBoard2Prog[i]->mAddress;
900 snprintf(addr,
sizeof(addr),
"%d.%d.%d.%d: ",(ip>>24)&0xFF,(ip>>16)&0xFF,(ip>>8)&0xFF,ip&0xFF);
903 earlyexit+=(mBoard2Prog[i]->mSuccess==mNProgSteps)?
" OK\r\n":
" CANT\r\n";
919 while (!beof && fgets(buffer,1024,programFile))
921 std::string line(buffer);
923 int cmd=strtol(line.substr(7,2).c_str(),NULL,16);
929 int size =strtol(line.substr(1,2).c_str(),NULL,16);
930 int addrL=strtol(line.substr(3,4).c_str(),NULL,16);
932 int address=addrH<<16|addrL;
934 if (!baseAddress) baseAddress=address;
936 if (bytesToWrite+size>uprot_PROGmaxsize || address!=baseAddress+bytesToWrite)
940 cmdData->size[0]= bytesToWrite &0xFF;
941 cmdData->size[1]=(bytesToWrite>>8)&0xFF;
942 sendPROG(uprot_OPC_PROG_DATA, cmdData, HEAD_SIZE+bytesToWrite, mN2Prog,1000);
943 updateProgressBar(
float(bytesWritten+=bytesToWrite)/fileSize);
951 cmdData->opc = uprot_OPC_PROG_DATA;
952 cmdData->address[0] = addrL&0xFF;
953 cmdData->address[1] = (addrL>>8)&0xFF;
954 cmdData->address[2] = addrH&0xFF;
955 cmdData->address[3] = (addrH>>8)&0xFF;
958 for (
int i=0; i<size; ++i)
960 cmdData->data[bytesToWrite+i]=(
unsigned char)strtol(line.substr(i*2+9,2).c_str(),NULL,16);
971 cmdData->size[0] = bytesToWrite &0xFF;
972 cmdData->size[1] = (bytesToWrite>>8)&0xFF;
973 sendPROG(uprot_OPC_PROG_DATA, cmdData, HEAD_SIZE+bytesToWrite, mN2Prog, 1000);
974 updateProgressBar(1.0f);
986 cmdData->size[0] = bytesToWrite &0xFF;
987 cmdData->size[1] = (bytesToWrite>>8)&0xFF;
988 sendPROG(uprot_OPC_PROG_DATA, cmdData, HEAD_SIZE+bytesToWrite, mN2Prog, 1000);
989 updateProgressBar(
float(bytesWritten+=bytesToWrite)/fileSize);
993 addrH=strtol(line.substr(9,4).c_str(),NULL,16);
1000 cmdData->size[0]= bytesToWrite &0xFF;
1001 cmdData->size[1]= (bytesToWrite>>8)&0xFF;
1002 sendPROG(uprot_OPC_PROG_DATA, cmdData, HEAD_SIZE+bytesToWrite, mN2Prog,1000);
1003 updateProgressBar(
float(bytesWritten+=bytesToWrite)/fileSize);
1013 memset(cmdEnd, EOUPROT_VALUE_OF_UNUSED_BYTE,
sizeof(eOuprot_cmd_PROG_END_t));
1014 cmdEnd->opc = uprot_OPC_PROG_END;
1015 cmdEnd->numberofpkts[0] = mNChunks & 0xFF;
1016 cmdEnd->numberofpkts[1] = (mNChunks>>8) & 0xFF;
1019 sendPROG(uprot_OPC_PROG_END, cmdEnd, sizeEnd, mN2Prog, 1000);
1021 updateProgressBar(1.0f);
1023 std::string sOutput;
1026 for (
int i=0; i<mN2Prog; ++i)
1028 ACE_UINT32 ip=mBoard2Prog[i]->mAddress;
1029 snprintf(addr,
sizeof(addr),
"%d.%d.%d.%d: ",(ip>>24)&0xFF,(ip>>16)&0xFF,(ip>>8)&0xFF,ip&0xFF);
1032 sOutput+=(mBoard2Prog[i]->mSuccess==mNProgSteps)?
" OK\r\n":
" NOK\r\n";
1042 for (
int i=0; i<mBoardList.size(); ++i)
1044 if (mBoardList[i].mSelected)
1046 mSocket.SendTo(
cmd, len, mPort, mBoardList[i].mAddress);
1059 for(
int k=0;k<mN2Prog; k++)
1061 mSocket.SendTo(
data, size, mPort, mBoard2Prog[k]->mAddress);
1065 ACE_UINT32 rxAddress;
1073 for (
int r=0; r<retry; ++r)
1075 for (
int a=0; a<answers; ++a)
1077 if (mSocket.ReceiveFrom(mRxBuffer,
sizeof(mRxBuffer), rxAddress, rxPort, 10)>0)
1079 eOuprot_cmdREPLY_t * reply = (eOuprot_cmdREPLY_t*) mRxBuffer;
1081 if (opc == reply->opc)
1083 if (rxAddress!=mMyAddress)
1085 for (
int i=0; i<mN2Prog; ++i)
1087 if (rxAddress==mBoard2Prog[i]->mAddress)
1089 if (uprot_RES_OK == reply->res)
1091 ++(mBoard2Prog[i]->mSuccess);
1097 if (!--answers)
return 0;
1109 bool EthUpdater::cmdChangeMask(ACE_UINT32 newMask, ACE_UINT32 address)
1113 eOuprot_cmd_LEGACY_IP_MASK_SET_t command = {EOUPROT_VALUE_OF_UNUSED_BYTE};
1115 command.opc = uprot_OPC_LEGACY_IP_MASK_SET;
1117 command.mask[0] = (newMask>>24)&0xFF;
1118 command.mask[1] = (newMask>>16)&0xFF;
1119 command.mask[2] = (newMask>>8) &0xFF;
1120 command.mask[3] = newMask &0xFF;
1122 #if defined(PRINT_DEBUG_INFO_ON_TERMINAL)
1124 snprintf(ipaddr,
sizeof(ipaddr),
"%d.%d.%d.%d",(address>>24)&0xFF, (address>>16)&0xFF, (address>>8)&0xFF, address&0xFF);
1126 snprintf(newm,
sizeof(newm),
"%d.%d.%d.%d",(newMask>>24)&0xFF, (newMask>>16)&0xFF, (newMask>>8)&0xFF, newMask&0xFF);
1129 bool stopit =
false;
1138 #if defined(PRINT_DEBUG_INFO_ON_TERMINAL)
1139 printf(
"cannot send command uprot_OPC_LEGACY_IP_MASK_SET to %s with new mask %s because either one or both are not valid\n", ipaddr, newm);
1145 #if defined(PRINT_DEBUG_INFO_ON_TERMINAL)
1146 printf(
"send command eOuprot_cmd_LEGACY_IP_MASK_SET_t to %s, new mask is %s\n", ipaddr, newm);
1149 mSocket.SendTo(&command,
sizeof(command), mPort, address);
1155 bool EthUpdater::cmdChangeMAC(uint64_t newMAC48, ACE_UINT32 address)
1159 eOuprot_cmd_LEGACY_MAC_SET_t command = {EOUPROT_VALUE_OF_UNUSED_BYTE};
1161 command.opc = uprot_OPC_LEGACY_MAC_SET;
1163 command.mac48[0] = (newMAC48>>40) & 0xFF;
1164 command.mac48[1] = (newMAC48>>32) & 0xFF;
1165 command.mac48[2] = (newMAC48>>24) & 0xFF;
1166 command.mac48[3] = (newMAC48>>16) & 0xFF;
1167 command.mac48[4] = (newMAC48>>8 ) & 0xFF;
1168 command.mac48[5] = (newMAC48 ) & 0xFF;
1170 #if defined(PRINT_DEBUG_INFO_ON_TERMINAL)
1172 snprintf(ipaddr,
sizeof(ipaddr),
"%d.%d.%d.%d",(address>>24)&0xFF, (address>>16)&0xFF, (address>>8)&0xFF, address&0xFF);
1174 snprintf(newmac,
sizeof(newmac),
"%x:%x:%x:%x:%x:%x", command.mac48[0], command.mac48[1], command.mac48[2], command.mac48[3], command.mac48[4], command.mac48[5]);
1177 bool stopit =
false;
1191 #if defined(PRINT_DEBUG_INFO_ON_TERMINAL)
1192 printf(
"cannot send command uprot_OPC_LEGACY_MAC_SET to %s with new mac %s because either one or both are not valid\n", ipaddr, newmac);
1198 #if defined(PRINT_DEBUG_INFO_ON_TERMINAL)
1199 printf(
"send command uprot_OPC_LEGACY_MAC_SET to %s, new mac is %s\n", ipaddr, newmac);
1202 mSocket.SendTo(&command,
sizeof(command), mPort, address);
1208 bool EthUpdater::cmdPageClr(eOuprot_pagesize_t pagesize, ACE_UINT32 address)
1210 eOuprot_cmd_PAGE_CLR_t command = {EOUPROT_VALUE_OF_UNUSED_BYTE};
1211 command.opc = uprot_OPC_PAGE_CLR;
1212 command.pagesize = pagesize;
1216 sendCommandSelected(&command,
sizeof(command));
1220 mSocket.SendTo(&command,
sizeof(command), mPort, address);
1227 bool EthUpdater::cmdPageSet(eOuprot_pagesize_t pagesize, uint8_t *
data, ACE_UINT32 address)
1234 eOuprot_cmd_PAGE_SET_t *
cmd = (eOuprot_cmd_PAGE_SET_t*) mTxBuffer;
1235 uint16_t sizeofcmd =
sizeof(eOuprot_cmd_PAGE_SET_t) - uprot_pagemaxsize + pagesize;
1239 memset(
cmd, EOUPROT_VALUE_OF_UNUSED_BYTE, sizeofcmd);
1241 cmd->opc = uprot_OPC_PAGE_SET;
1242 cmd->pagesize = pagesize;
1243 memcpy(&
cmd->page[0],
data, pagesize);
1247 sendCommandSelected(
cmd, sizeofcmd);
1251 mSocket.SendTo(
cmd, sizeofcmd, mPort, address);
1259 bool EthUpdater::cmdPageGet(eOuprot_pagesize_t pagesize, uint8_t **
data, ACE_UINT32 address)
1271 eOuprot_cmd_PAGE_GET_t command = {EOUPROT_VALUE_OF_UNUSED_BYTE};
1272 command.opc = uprot_OPC_PAGE_GET;
1273 command.pagesize = pagesize;
1275 mSocket.SendTo(&command,
sizeof(command), mPort, address);
1279 ACE_UINT32 rxAddress;
1283 while(mSocket.ReceiveFrom(mRxBuffer,
sizeof(mRxBuffer), rxAddress, rxPort, 500)>0)
1285 eOuprot_cmd_PAGE_GET_REPLY_t * pageget = (eOuprot_cmd_PAGE_GET_REPLY_t*) mRxBuffer;
1287 if(uprot_OPC_PAGE_GET == pageget->reply.opc)
1289 if(address == rxAddress)
1291 if((uprot_RES_OK == pageget->reply.res) && (pagesize == pageget->pagesize))
1293 *
data = pageget->page;
void sendCommandSelected(void *cmd, uint16_t len)
bool cmdRestart(ACE_UINT32 address=0)
bool cmdReadEEPROM(uint16_t from, uint16_t size, ACE_UINT32 address, uint8_t **value)
static const int partition_LOADER
std::string cmdProgram(FILE *programFile, int partition, void(*updateProgressBar)(float), ACE_UINT32 address=0)
int sendPROG(const uint8_t opc, void *data, int size, int answers, int retry)
bool cmdSetDEF2RUN(eOuprot_process_t process, ACE_UINT32 address=0)
bool cmdBlink(ACE_UINT32 address=0)
bool isCmdSupported(eOuprot_proc_capabilities_t capability, ACE_UINT32 address=0)
vector< string > cmdInfo32Get(ACE_UINT32 address=0)
bool cmdJumpUpd(ACE_UINT32 address=0)
bool cmdJump2ROMaddress(uint32_t romaddress, ACE_UINT32 address=0)
static const int partition_APPLICATION
bool cmdChangeAddress(ACE_UINT32 newaddress, ACE_UINT32 address=0)
static const int partition_UPDATER
bool cmdInfo32Set(const string &info32, ACE_UINT32 address=0)
std::string cmdGetMoreInfo(bool refreshInfo=false, ACE_UINT32 address=0)
bool cmdEraseEEPROM(ACE_UINT32 address=0)
bool cmdInfo32Clear(ACE_UINT32 address=0)
eOuprot_proctable_t processes