Fcm problem: download file repeatedly


#1

Good morning, I got a little problem with the FCM method. I made a program that from time to time he would check whether it had any file in the ftp, if you download it to the module and prints, but he can only check whether there is 6x the file, then they make the process and not I am answer.
I would like some help if possible with some example explaining the problem.

The Code is:

void ftp_Read( void)
{
	int len, i=0;
	u8 buffer[256];
	if( ftp_fcmResume) return;
	
	while( (len = wip_read( ftp_WipDataHandle, buffer, sizeof(buffer))) > 0) {
                s8 ret;
               //Printing
 ret = adl_fcmSendData ( ftp_V24Handle, buffer, len );

 

	//Termina Impressao
    if( (ret == ADL_FCM_RET_OK_WAIT_RESUME) ||
        (ret == ADL_FCM_RET_ERR_WAIT_RESUME)) {
		ftp_fcmResume = TRUE;
		break;
	}
  }
}
// FTP Data Connection Handler
void ftp_DataHandler( wip_event_t *ev, void *ctx)
{
  wip_debug( "FTP data event: %d\n", ev->kind);
  
  switch( ev->kind) {
  
  case WIP_CEV_OPEN:
    break;
   
  case WIP_CEV_READ:
	adl_fcmSendData ( ftp_V24Handle, "\r\ndata handler read\r\n", 25 );
    if ( ftp_Mode == FTP_MODE_GET ) {
      // Read FTP data
      ftp_Read();
    }
    break;

  case WIP_CEV_WRITE:
    if ( ftp_Mode == FTP_MODE_PUT ) {
      // Write FTP data
      ftp_Write();
    }
    break;
    
  case WIP_CEV_PEER_CLOSE:
  case WIP_CEV_ERROR:
    //Fim da Tranferencia
    adl_fcmSwitchV24State ( ftp_V24Handle, ADL_FCM_V24_STATE_AT );
    //Fechando canal de dados
    wip_close( ftp_WipDataHandle);
    //Fechando conexão ftp
    if( ftp_WipHandle != NULL) {
      wip_close( ftp_WipHandle);
      ftp_WipHandle = NULL;
    }
    break;
  }
}


// V24 Ctrl handler
bool ftp_V24CtrlHandler ( u8 Event )
{
    TRACE (( 1, "V24 event %d", Event ));    
    // Switch on event
    switch ( Event )
    {
        case ADL_FCM_EVENT_FLOW_OPENNED :
            
			//Mudando para modo de dados
			//Abrindo porta Uart1
            adl_fcmSwitchV24State ( ftp_V24Handle, ADL_FCM_V24_STATE_DATA );
        break;
        
        case ADL_FCM_EVENT_V24_DATA_MODE :
            
			//Iniciando Get
			if ( ftp_Mode == FTP_MODE_GET )
			{ 
				ftp_fcmResume = FALSE;
				
				// get file
				if( ftp_WipHandle != NULL) {
					adl_fcmSendData ( ftp_V24Handle, "if1\n", 5 );
					ftp_WipDataHandle = wip_getFile( ftp_WipHandle, ftp_DestAddr.nota, ftp_DataHandler, NULL);
					if( ftp_WipDataHandle == NULL) {
						// FTP error
                        wip_close( ftp_WipHandle);
                        ftp_WipHandle = NULL;
						arquivo=FALSE;
					}
				}
				else {
					adl_fcmSendData ( ftp_V24Handle, "\r\nElse1...\r\n", 21 );
					ftp_WipDataHandle = NULL;
				}
				if( ftp_WipDataHandle == NULL) {
					// Switch back
					adl_fcmSwitchV24State ( ftp_V24Handle, ADL_FCM_V24_STATE_AT );
				}
				else {
					adl_fcmSendData ( ftp_V24Handle, "\r\nElse2...\r\n", 21 );
				}
			}
			break;
		case ADL_FCM_EVENT_RESUME:
            if ( ftp_Mode == FTP_MODE_GET ) {
                // continue to read FTP data
                ftp_fcmResume = FALSE;
                ftp_Read();
            }
        break;
        
        case ADL_FCM_EVENT_V24_AT_MODE :
        {    
			adl_atSendResponse (  ADL_AT_RSP, "ADL_FCM_EVENT_V24_AT_MODE" );
			//Fecha Conexão do Get
			// Switched to at mode : FTP end
			ftp_State = 0;			
			adl_atSendResponse ( ADL_AT_RSP, "\r\nArquivo TRUE\r\n" );
			adl_fcmUnsubscribe ( ftp_V24Handle );
            //Fazendo Backup
			if(arquivo){
				ftp_Mode = FTP_MODE_PUT_GET_BUFFER; 
				put2 = 1;
				adl_atCmdCreate("at+ftp", TRUE, WIPFTP_cmdHandler,"*",NULL);
			}
			arquivo=TRUE;
		}
        break;
    }
    return TRUE;
}

// V24 Data handler
bool ftp_V24DataHandler ( u16 DataLength, u8 * Data )
{
    return TRUE;
}