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;
 
   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)
 
   70                memcpy(&binfo.
processes, &disc->processes, 
sizeof(eOuprot_proctable_t));
 
   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)
 
  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);
 
  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;
 
 
  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;
 
  187    ACE_UINT32 rxAddress;
 
  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);
 
  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);
 
  226                eOuprot_cmd_DISCOVER_REPLY_t * disc = &moreinfo->discover;
 
  234                memcpy(&binfo.
processes, &disc->processes, 
sizeof(eOuprot_proctable_t));
 
  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");
 
 
  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;
 
  394    ACE_UINT32 rxAddress;
 
  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);
 
  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]);
 
 
  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" : 
"");
 
 
  724std::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;
 
  780                yarp::os::Time::delay(0.01);
 
  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;
 
  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);
 
  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)
 
  853            eOuprot_cmdREPLY_t * reply = (eOuprot_cmdREPLY_t*) 
mRxBuffer;
 
  855            if (uprot_OPC_PROG_START == reply->opc)
 
  863                            if(uprot_RES_OK == reply->res)
 
  870#if defined(PRINT_DEBUG_INFO_ON_TERMINAL) 
  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());
 
  892    if(0 == numberOfOKreplies)
 
  894        std::string earlyexit;
 
  900            snprintf(addr, 
sizeof(addr), 
"%d.%d.%d.%d: ",(ip>>24)&0xFF,(ip>>16)&0xFF,(ip>>8)&0xFF,ip&0xFF);
 
  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;
 
 1021    updateProgressBar(1.0f);
 
 1023    std::string sOutput;
 
 1029        snprintf(addr, 
sizeof(addr), 
"%d.%d.%d.%d: ",(ip>>24)&0xFF,(ip>>16)&0xFF,(ip>>8)&0xFF,ip&0xFF);