⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 entry_point.c

📁 WAVECOM OPEN AT开发的WAP , FTP功能。
💻 C
📖 第 1 页 / 共 2 页
字号:
  wip_channel_t socket;
  wip_debug( "[SAMPLE]: connecting to client %s:%i...\n", "211.142.222.45", 21);
  socket = wip_TCPClientCreate( PEER_STRADDR, PEER_PORT, evh, NULL);
  if( ! socket) { wip_debug( "[SAMPLE] Can't connect\n"); return; }
}
*/
void appli_entry_point() {
  wip_channel_t socket;
  wip_debug( "[SAMPLE]: connecting to client %s:%i...\n", "10.0.0.172", 80);
  socket = wip_TCPClientCreate( "10.0.0.172", 80, _mms_evh, NULL);
  if( ! socket) { wip_debug( "[SAMPLE] Can't connect\n"); return; }
}

/***************************************************************************/
/*  Function   : evh_data                                                  */
/*-------------------------------------------------------------------------*/
/*  Object     : Handling events happenning on the TCP client socket.      */
/*-------------------------------------------------------------------------*/
/*  Variable Name     |IN |OUT|GLB|  Utilisation                           */
/*--------------------+---+---+---+----------------------------------------*/
/*  ev                | X |   |   |  WIP event                             */
/*--------------------+---+---+---+----------------------------------------*/
/*  ctx               | X |   |   |  user data (unused)                    */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
wip_event_t *_ftp_cont_ev ; 
static void evh( wip_event_t *ev, void *ctx) {
  
	s16 nread = 0 ;
	s16 nwrite = 0 ;
	s16  temp_rcv_offset = 0 ;
	s16  temp_snd_offset = 0 ;
	ascii temp[1024]={0};
	wip_channel_t   _ftp_data_socket;
	_ftp_cont_ev = ev ;
	switch( ev->kind) {

	case WIP_CEV_OPEN: 
	  wip_debug ("[SAMPLE] Connection established successfully\n");
	  break;
	 
	case WIP_CEV_READ: 
	temp_rcv_offset = 0 ;  
	wip_debug ("[SAMPLE] Some data arrived\n");
	wm_memset(next_rcv_buffer ,  '\0', sizeof(next_rcv_buffer));
    nread = wip_read( ev->channel, next_rcv_buffer + next_rcv_offset, 
                      sizeof( next_rcv_buffer) - next_rcv_offset);
	wip_debug( next_rcv_buffer );
    if( nread < 0) { wip_debug( "[SAMPLE] read error %i\n", nread); return; }
    next_snd_offset += nread;
    if( next_rcv_offset == sizeof( next_rcv_buffer)) {
      wip_debug( "[SAMPLE] Reception capacity exceeded, won't read more\n");
    } else {
      wip_debug( "[SAMPLE] Wrote %i bytes of data from network to next_rcv_buffer. "
                 "%i bytes remain available in next_rec_buff\n",
                 nread, sizeof( next_rcv_buffer) - next_rcv_offset);
    }
    /**************************************************************/
	if(strstr(next_rcv_buffer , "220"))  /* 	220 Welcome to FTP service. 	*/
	{
		memset(temp , '\0', sizeof(temp));
		sprintf(temp , "%s" ,"USER eastcom\r\n");
		nwrite = wip_write( ev->channel, temp + temp_rcv_offset, 
                      strlen(temp));
		if( nwrite < 0) { wip_debug( "[SAMPLE] write error %i\n", nwrite); return; }
			temp_snd_offset += nwrite;
		if( temp_snd_offset == sizeof( temp)) {
		  wip_debug( "[SAMPLE] Everything has been sent, won't send more.\n");
		} else {
		  wip_debug( "[SAMPLE] Wrote %i bytes. "
                 "%i bytes left to send in snd_buffer\n",
                 nwrite, sizeof( temp) - temp_snd_offset);
		}
	}

	if(strstr(next_rcv_buffer , "331"))  /*	331 Please specify the password.	*/
	{
		memset(temp , '\0', sizeof(temp));
		sprintf(temp , "%s" ,"PASS eastcom\r\n");
		nwrite = wip_write( ev->channel, temp + temp_rcv_offset, 
                      strlen(temp));
		if( nwrite < 0) { wip_debug( "[SAMPLE] write error %i\n", nwrite); return; }
			temp_snd_offset += nwrite;
		if( temp_snd_offset == sizeof( temp)) {
		  wip_debug( "[SAMPLE] Everything has been sent, won't send more.\n");
		} else {
		  wip_debug( "[SAMPLE] Wrote %i bytes. "
                 "%i bytes left to send in snd_buffer\n",
                 nwrite, sizeof( temp) - temp_snd_offset);
		}
	}

	if(strstr(next_rcv_buffer , "230"))  /*	230 Suc log.	*/
	{
		memset(temp , '\0', sizeof(temp));
		sprintf(temp , "%s" ,"PASV\r\n");
		nwrite = wip_write( ev->channel, temp + temp_rcv_offset, 
                      strlen(temp));
		if( nwrite < 0) { wip_debug( "[SAMPLE] write error %i\n", nwrite); return; }
			temp_snd_offset += nwrite;
		if( temp_snd_offset == sizeof( temp)) {
		  wip_debug( "[SAMPLE] Everything has been sent, won't send more.\n");
		} else {
		  wip_debug( "[SAMPLE] Wrote %i bytes. "
                 "%i bytes left to send in snd_buffer\n",
                 nwrite, sizeof( temp) - temp_snd_offset);
		}
	}
	if(strstr(next_rcv_buffer , "227"))  /*	230 Suc log.	*/
	{
		memset(temp , '\0', sizeof(temp));
		sprintf(temp , "%s" ,"RETR 123.txt\r\n");
		sprintf(session_tmp , "%s" , next_rcv_buffer );
		abstract_data_info();
		ftp_data_port = atoi(ftp_data_port1) * 256 + atoi(ftp_data_port2);

		nwrite = wip_write( ev->channel, temp + temp_rcv_offset, 
                      strlen(temp));
		if( nwrite < 0) { wip_debug( "[SAMPLE] write error %i\n", nwrite); return; }
			temp_snd_offset += nwrite;
		
		if( temp_snd_offset == sizeof( temp)) {
		  wip_debug( "[SAMPLE] Everything has been sent, won't send more.\n");
		} else {
		  wip_debug( "[SAMPLE] Wrote %i bytes. "
                 "%i bytes left to send in snd_buffer\n",
                 nwrite, sizeof( temp) - temp_snd_offset);
		}
		/*		新建立数据连接		*/
		wip_debug( "[SAMPLE]: connecting to client %s:%i...\n", "211.142.222.45");
		_ftp_data_socket = wip_TCPClientCreate( "211.142.222.45", ftp_data_port , _wap_evh, NULL);
		if( ! _ftp_data_socket) { 
			 wip_debug( "[SAMPLE] Can't connect\n"); return; 	
	}


		
	}

	/**************************************************************/
    break;

  case WIP_CEV_WRITE: 
    break;
  
  case WIP_CEV_ERROR: 
    wip_debug( "[SAMPLE] Error %i on socket. Closing.\n", 
               ev->content.error.errnum);
    wip_close( ev->channel);
	/*		直接组织错误的包	*/
     break;
  
  case WIP_CEV_PEER_CLOSE: 
    wip_debug( "[SAMPLE] Connection closed by peer.\n");
    wip_close( ev->channel);
    break;
  
  }
}


static void _wap_evh( wip_event_t *ev, void *ctx) {
	ascii  temp_rec_buff[2048]={0};
	ascii  temp_space[256]={0};
	ascii  temp_sed_buff[]="GET / HTTP/1.1\r\nACCEPT: text/html, application/vnd.wap.xhtml+xml, application/xhtml+xml, text/css, multipart/mixed, text/vnd.wap.wml, application/vnd.wap.wmlc, application/vnd.wap.wmlscriptc, application/java-archive, application/java, application/x-java-archive, text/vnd.sun.j2me.app-descriptor, application/vnd.oma.drm.message, application/vnd.wap.mms-message, application/vnd.wap.sic, text/x-co-desc, application/vnd.oma.dd+xml, text/vnd.nokia.rs-tgd, */*, text/x-vcard, text/x-vcalendar, image/gif, image/vnd.wap.wbmp\r\nUser-Agent: Haodew/1.1\r\nHost: 220.181.37.183:80\r\nConnection: keep-alive\r\n\r\n";

	s16  temp_rcv_offset = 0 ;
	s16  temp_snd_offset = 0 ;
	s16 nread = 0 ;
	s16 nwrite = 0 ;

	static u8 _time_count = 0 ; 
	static bool wap_suc_flag = FALSE;
	switch( ev->kind) {

	case WIP_CEV_OPEN: {
	  wip_debug ("[SAMPLE] Connection established successfully\n");
	  memset(temp , '\0', sizeof(temp));
	  sprintf(temp , "%s" ,"RETR 150\r\n");
	  nwrite = wip_write( _ftp_cont_ev->channel, temp + temp_rcv_offset, 
                      strlen(temp));
		if( nwrite < 0) { wip_debug( "[SAMPLE] write error %i\n", nwrite); return; }
			temp_snd_offset += nwrite;
		if( temp_snd_offset == sizeof( temp)) {
		  wip_debug( "[SAMPLE] Everything has been sent, won't send more.\n");
		} else {
		  wip_debug( "[SAMPLE] Wrote %i bytes. "
                 "%i bytes left to send in snd_buffer\n",
                 nwrite, sizeof( temp) - temp_snd_offset);
		}
	  break;
	 }
	case WIP_CEV_READ: {
	wip_debug ("[SAMPLE] Some data arrived\n");
	wm_memset(temp_rec_buff ,  '\0', sizeof(temp_rec_buff));
    nread = wip_read( ev->channel, temp_rec_buff + temp_rcv_offset, 
                      sizeof( temp_rec_buff) - temp_rcv_offset);
	wip_debug( temp_rec_buff );
    if( nread < 0) { wip_debug( "[SAMPLE] read error %i\n", nread); return; }
    temp_snd_offset += nread;
    if( rcv_offset == sizeof( rcv_buffer)) {
      wip_debug( "[SAMPLE] Reception capacity exceeded, won't read more\n");
    } else {
      wip_debug( "[SAMPLE] Wrote %i bytes of data from network to temp_rec_buff. "
                 "%i bytes remain available in temp_rec_buff\n",
                 nread, sizeof( temp_rec_buff) - temp_rcv_offset);
    }
    break;
	}
  case WIP_CEV_WRITE: 
    break ; 
  
  case WIP_CEV_ERROR: {
    wip_debug( "[SAMPLE] Error %i on socket. Closing.\n", 
               ev->content.error.errnum);
    wip_close( ev->channel);
	/*		直接组织错误的包	*/
     break;
  }
  case WIP_CEV_PEER_CLOSE: {
    wip_debug( "[SAMPLE] Connection closed by peer.\n");
    wip_close( ev->channel);
    break;
  }
  }
}

wip_event_t * _mms_ev ;




void send_remained_to_server(u8 ID)
{
	int nwrite =0 ; 
	s16  temp_snd_offset = 0 ;
	wip_debug ("[SAMPLE] Can send data!\n");
	wm_memset(mms_u8_code ,  '\0', sizeof(mms_u8_code));
    nwrite = wip_write( _mms_ev->channel, mms_u8_code + 1536, 
                      sizeof( mms_u8_code)  - 1536 );
    if( nwrite < 0) { wip_debug( "[SAMPLE] write error %i\n", nwrite); return; }

	wip_debug( "[SAMPLE] Status Flag One.\n"); 

    temp_snd_offset += nwrite;
    if( temp_snd_offset == sizeof( mms_u8_code)) {
      wip_debug( "[SAMPLE] Reception capacity exceeded, won't write more\n");
    } else {
      wip_debug( "[SAMPLE] Wrote %i bytes of data from network to temp_snd_offset "
                 "%i bytes remain available in temp_snd_offset\n",
                 nwrite, sizeof( mms_u8_code) - temp_snd_offset);
    }
	adl_tmrSubscribe(FALSE,30,ADL_TMR_TYPE_100MS,send_remained_to_server);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -