Help with dota

Hi i am trying to use dota but i have a problem for me it seems that dota starts, i mean the reading of data from the ftp file starts but then it restarts over and over in a infinite loop, because i keep getting wip_cev_read event, if a put a boolean flag so that only once the read to start then reading of data freezes. Could someone help me out? Here is my code

void dota_read_upgrade(void){
  s32 len;
  u8 buf[1500];
  s32 RetVal32 = 0x00;
  //Keep reading until you read 0
  while ((len = wip_read(dataChannel, buf, sizeof(buf))) > 0)
  {
    //New Data is added to end of Current data in Cell
    RetVal32 = adl_adWrite(DOTA_Cell_Handle, len, (void*)buf);
    if (RetVal32 != 0)
    {
      TRACE(TRACE_LEVEL_FTP,"Something is wrong with A&D Space,Please format and Retry");
      wip_close(controlChannel);
    }
  } 

}


//*********************************************************************************************************
// Handler for the events related to the data channel
//*********************************************************************************************************

static void dota_ftpUpgradedataChannelHandler(wip_event_t * event, void * context) {
    ascii buff[4];
    ascii buffer[30];
    s32 s32RetVal;
    wm_sprintf(buff,"%d",event->kind);
    dbg_writeToConsole(TRACE_LEVEL_FTP,"dota_ftpUpgradedataChannelHandler event");
    dbg_writeToConsole(TRACE_LEVEL_FTP,buff);
    switch (event->kind) {
            case WIP_CEV_OPEN: break;
		    case WIP_CEV_READ:
                dbg_writeToConsole(TRACE_LEVEL_FTP, "Start read");
				dota_read_upgrade();
                break; 
            case WIP_CEV_PEER_CLOSE:
                dbg_writeToConsole(TRACE_LEVEL_FTP, "WIP_CEV_PEER_CLOSE");
                //all Data Downloaded
                dbg_writeToConsole(TRACE_LEVEL_FTP, "FTP Download Completed");
                //Finalize Cell with Undefined Size before you can use it
                s32RetVal = adl_adFinalise(DOTA_Cell_Handle);
                //Install The New Application
                s32RetVal = adl_adInstall(DOTA_Cell_Handle);
				break;
		    case WIP_CEV_ERROR:
                wip_debug( "Error %i on channel 0x%x\n", event->content.error.errnum,event->channel);
//                if (dataChannel) {
                    wip_close( dataChannel); 
                    dataChannel = (wip_channel_t)NULL;
//                }
                if( controlChannel) {
                    wip_close( controlChannel); 
                    controlChannel = (wip_channel_t)NULL; 
                }
                LOG_ERR(E_FTP_NOT_ABLE_TO_SEND);
                
                break;
            default : dbg_writeToConsole(TRACE_LEVEL_FTP,"ftp_dataChannelHandler default event"); 
                //LOG_ERR(E_FTP_NOT_ABLE_TO_SEND);
                break;
             
    }
	
}

//*********************************************************************************************************
// Handler for the events related to the ftp channel
//*********************************************************************************************************

static void dota_ftpUpgradeControlChannelHandler(wip_event_t *event,void *context){
    ascii buff[4];
    ascii buffer[30];
    wm_sprintf(buff,"%d",event->kind);
    dbg_writeToConsole(TRACE_LEVEL_FTP,"dota_ftpUpgradeControlChannelHandler event");
    dbg_writeToConsole(TRACE_LEVEL_FTP,buff);
    switch( event->kind) {   
        case WIP_CEV_DONE:
			dbg_writeToConsole(TRACE_LEVEL_FTP,"WIP_CEV_DONE");
            //wip_getFileSize(controlChannel,ftpFile);            
            break;
        case WIP_CEV_OPEN:
            dataChannel = wip_getFile( controlChannel, ftpFile, dota_ftpUpgradedataChannelHandler, NULL);
            if( ! dataChannel) { 
                wip_debug( "Can't create data channel"); 
                LOG_ERR(E_FTP_NOT_ABLE_TO_CONNECT);
               
                return; 
            }
            break;    
        case WIP_CEV_ERROR:
             wip_debug( "Error %i on cx channel\n", event->content.error.errnum);
             // fall through 
         case WIP_CEV_PEER_CLOSE:
             wip_debug( "Closing everything\n");
             if( dataChannel) { 
                 wip_close( dataChannel); 
                 dataChannel = (wip_channel_t)NULL; 
             }
            wip_close( controlChannel); 
            controlChannel = (wip_channel_t)NULL;
            LOG_ERR(E_FTP_NOT_ABLE_TO_CONNECT);
             break;
         default :  
             LOG_ERR(E_FTP_NOT_ABLE_TO_CONNECT);
             dbg_writeToConsole(TRACE_LEVEL_FTP,"Default for ftp_controlChannelHandler");
             break;
   }
}

void upgradeApp(ascii * fileName){
    dbg_writeToConsole(TRACE_LEVEL_FTP,"Starting update of project");
    dbg_writeToConsole(TRACE_LEVEL_FTP,fileName);
    ftpFile=fileName;
    controlChannel = wip_FTPCreateOpts (dota_ftp_settings->ftpServerName,  dota_ftpUpgradeControlChannelHandler, NULL, 
        WIP_COPT_USER, dota_ftp_settings->ftpUserName, WIP_COPT_PASSWORD, dota_ftp_settings->ftpPassword, WIP_COPT_PASSIVE, 
        TRUE, WIP_COPT_END);
        
}

Of course you do!

You get a wip_cev_read event every time another “chunk” of data is received!

You need to keep reading these “chunks” until you have completed the whole transfer.

Note that this has nothing specifically to do with DOTA - this is a basic principle of any sort of data transfer, for any purpose.

Ok so i have this while loop

while ((len = wip_read(dataChannel, buf, sizeof(buf))) > 0)
  {
    //New Data is added to end of Current data in Cell
    RetVal32 = adl_adWrite(DOTA_Cell_Handle, len, (void*)buf);
    if (RetVal32 != 0)
    {
      TRACE(TRACE_LEVEL_FTP,"Something is wrong with A&D Space,Please format and Retry");
      wip_close(controlChannel);
    }
  }

This generates those cev_read events so i guess i put in a wrong place this dota_read_upgrade() function call . But i still can’t figure it out where to put it then or should i put a switch so only one call for the function be possible?

Before you store the data in AD, you should do a test to see how much data you’re receiving and see how long it takes.
You say that it seems to get stuck in an infinite loop, but have you checked what data you receive?

You’re using FTP
FTP is - as the name suggests - a protocol for transferring files.

The way FTP works is entirely independent of the nature or purpose of the files themselves - therefore, you first need to understand how to transfer any arbitrary file using FTP

Once you have transferred the file, then you can start to think about what to do with it.

So, forget DOAT for now and just look at the FTP example at the end of the WIP Development Guide: it shows you how to transfer a file - including how to identify when the transfer is complete.

I still have some problems with this download. The thing is that every time i loop through the code the same data is read it is like the read pointer remains always at the beginning of the file. I print the buffer in which i put the data and always the same value is printed, nothing new is added. Here is the code:

//*********************************************************************************************************
// Handler for the events related to the data channel
//*********************************************************************************************************

static void dota_ftpUpgradedataChannelHandler(wip_event_t * event, void * context) {
    ascii buff[4];
    ascii buffer[30];
    s32 s32RetVal;
	static int nwritten;
	int i=0;
    wm_sprintf(buff,"%d",event->kind);
    dbg_writeToConsole(TRACE_LEVEL_FTP,"dota_ftpUpgradedataChannelHandler event");
    dbg_writeToConsole(TRACE_LEVEL_FTP,buff);
    switch (event->kind) {
            case WIP_CEV_OPEN: 
				nwritten=0;
				break;
		    case WIP_CEV_READ:
                                dbg_writeToConsole(TRACE_LEVEL_FTP, "Reading");
				nwritten+=wip_read(dataChannel,dotaBuffer+nwritten, size-nwritten);
                                // print the contents of the buffer    <--- here always the same data is printed the start of the file
				dbg_writeToConsole(TRACE_LEVEL_FTP, dotaBuffer);
                break; 
            case WIP_CEV_PEER_CLOSE:
                dbg_writeToConsole(TRACE_LEVEL_FTP, "WIP_CEV_PEER_CLOSE");
                //all Data Downloaded
                dbg_writeToConsole(TRACE_LEVEL_FTP, "FTP Download Completed");
                //Finalize Cell with Undefined Size before you can use it
              //  s32RetVal = adl_adFinalise(DOTA_Cell_Handle);
                //Install The New Application
               // s32RetVal = adl_adInstall(DOTA_Cell_Handle);
				
		    case WIP_CEV_ERROR:
                wip_debug( "Error %i on channel 0x%x\n", event->content.error.errnum,event->channel);
//                if (dataChannel) {
                    wip_close( dataChannel); 
                    dataChannel = (wip_channel_t)NULL;
//                }
                if( controlChannel) {
                    wip_close( controlChannel); 
                    controlChannel = (wip_channel_t)NULL; 
                }
                LOG_ERR(E_FTP_NOT_ABLE_TO_SEND);
                
                break;
            default : dbg_writeToConsole(TRACE_LEVEL_FTP,"dota_ftpUpgradedataChannelHandler default event"); 
                //LOG_ERR(E_FTP_NOT_ABLE_TO_SEND);
                break;
             
    }
	
}

//*********************************************************************************************************
// Handler for the events related to the ftp channel
//*********************************************************************************************************

static void dota_ftpUpgradeControlChannelHandler(wip_event_t *event,void *context){
    ascii buff[4];
    ascii buffer[30];
    wm_sprintf(buff,"%d",event->kind);
    dbg_writeToConsole(TRACE_LEVEL_FTP,"dota_ftpUpgradeControlChannelHandler event");
    dbg_writeToConsole(TRACE_LEVEL_FTP,buff);
    switch( event->kind) {   
        case WIP_CEV_OPEN:
	   dbg_writeToConsole(TRACE_LEVEL_FTP,"Get file size");
            wip_getFileSize(controlChannel,ftpFile);            
            break;
        case WIP_CEV_DONE:
            size=event->content.done.aux;
	    // alocate memory for the buffer in which data will be stored
            dotaBuffer=ADL_memGET(size);
			*dotaBuffer=0;
            // FTP control initialized successfully -> open data dchannel 
            dataChannel = wip_getFile( controlChannel, ftpFile, dota_ftpUpgradedataChannelHandler, NULL);
            if( ! dataChannel) { 
                wip_debug( "Can't create data channel"); 
                LOG_ERR(E_FTP_NOT_ABLE_TO_CONNECT);
               
                return; 
            }
            break;    
        case WIP_CEV_ERROR:
             wip_debug( "Error %i on cx channel\n", event->content.error.errnum);
             // fall through 
         case WIP_CEV_PEER_CLOSE:
             wip_debug( "Closing everything\n");
             if( dataChannel) { 
                 wip_close( dataChannel); 
                 dataChannel = (wip_channel_t)NULL; 
             }
            wip_close( controlChannel); 
            controlChannel = (wip_channel_t)NULL;
            LOG_ERR(E_FTP_NOT_ABLE_TO_CONNECT);
             break;
         default :  
             LOG_ERR(E_FTP_NOT_ABLE_TO_CONNECT);
             dbg_writeToConsole(TRACE_LEVEL_FTP,"Default for ftp_controlChannelHandler");
             break;
   }
}

Ok i think i managed to solve the problem but i still stumbled upon another. After download is completed i receive the wip_per_close event and i do this :

//Finalize Cell with Undefined Size before you can use it
                s32RetVal = adl_adFinalise(DOTA_Cell_Handle);
                //Install The New Application
                s32RetVal = adl_adInstall(DOTA_Cell_Handle);

After this i receive the ADL_AD_EVENT_INSTALL but after this nothing happens does anybody know what’s wrong? I aspect the application to be reseted and the new version should be installed why doesn’t this happen

Ok guys i figured it out Actually my code was ok the thing is that if you run the application in rte the download completes ok, i think that even the install completes ok but the application doesn’t reboot, you need to run on wismo an then everything goes smooth