Exemplo n.º 1
0
uint8_t tcp_socket_init(TCP_CONFIG *config)
{

	static bool startup=false;
	if(!startup)
	{
		GPIO_Configuration();
		Reset_W5200();
		WIZ_SPI_Init();
		Set_network(config->Source_IP, config->Gateway, config->MAC, config->Subnet);
		startup=true;
		while (getSn_SR(config->s) != SOCK_CLOSED);
	}

	if(socket(config->s,Sn_MR_TCP,config->Source_Port,0x00)== 0)    /* reinitialize the socket */
	{
		return 0; //TCP socket failed
	}

	while (getSn_SR(config->s) != SOCK_INIT); // Wait for socket to open

	IINCHIP_WRITE(Sn_CR(config->s), Sn_CR_LISTEN); // Start listening on port specified
	while (IINCHIP_READ(Sn_CR(config->s))); // Check status
	while (getSn_SR(config->s) != SOCK_LISTEN); // Wait for listen
	return 1;
}
Exemplo n.º 2
0
void WIZ_Config(void)
{
	uint8 i;
	wiz_NetInfo netinfo;

	Reset_W5200();
	wizInit();

	for(i=0; i<4; i++){
		netinfo.Mac[i] = Mac[i];
		printf("MAC[%d]: 0x%2x\r\n", i, Mac[i]);
		netinfo.IP[i] = IP[i];
		netinfo.Subnet[i] = Subnet[i];
		netinfo.Gateway[i] = Gateway[i];
		netinfo.DNSServerIP[i] = DNSServerIP[i];
	}
	netinfo.Mac[i] = Mac[i];
	printf("MAC[%d]: 0x%2x\r\n", i, Mac[i]);
	i++;
	netinfo.Mac[i] = Mac[i];
	printf("MAC[%d]: 0x%2x\r\n", i, Mac[i]);

	SetNetInfo(&netinfo);

	printf("\r\n--------------------------------------- \r\n");
	printf("W5200E01-M3                       \r\n");
	printf("Network Configuration Information \r\n");
	printf("--------------------------------------- ");

	GetNetInfo(&netinfo);
	printf("\r\nMAC : %.2X.%.2X.%.2X.%.2X.%.2X.%.2X", netinfo.Mac[0],netinfo.Mac[1],netinfo.Mac[2],netinfo.Mac[3],netinfo.Mac[4],netinfo.Mac[5]);
	printf("\r\nIP : %d.%d.%d.%d", netinfo.IP[0],netinfo.IP[1],netinfo.IP[2],netinfo.IP[3]);
	printf("\r\nSN : %d.%d.%d.%d", netinfo.Subnet[0],netinfo.Subnet[1],netinfo.Subnet[2],netinfo.Subnet[3]);
	printf("\r\nGW : %d.%d.%d.%d", netinfo.Gateway[0],netinfo.Gateway[1],netinfo.Gateway[2],netinfo.Gateway[3]);
	printf("\r\nDNS server : %d.%d.%d.%d", netinfo.DNSServerIP[0],netinfo.DNSServerIP[1],netinfo.DNSServerIP[2],netinfo.DNSServerIP[3]);
}
Exemplo n.º 3
0
void WIZ_Config(void)
{
	uint8 i;
	wiz_NetInfo netinfo;
	extern u_char GET_SN_MASK[4];			        /**< Subnet mask received from the DHCP server */
	extern u_char GET_GW_IP[4];			        /**< Gateway ip address received from the DHCP server */
	extern u_char GET_SIP[4];				/**< Local ip address received from the DHCP server */

	Reset_W5200();
	wizInit();

	if(Enable_DHCP == OFF){
		for(i=0; i<4; i++){
			netinfo.Mac[i] = Mac[i];
			netinfo.IP[i] = IP[i];
			netinfo.Subnet[i] = Subnet[i];
			netinfo.Gateway[i] = Gateway[i];
			netinfo.DNSServerIP[i] = DNSServerIP[i];
		}
		netinfo.Mac[i] = Mac[i];
		i++;
		netinfo.Mac[i] = Mac[i];

	} else{
		for(i=0; i<6; i++){
			SRC_MAC_ADDR[i] = Mac[i];
		}

		printf("Delay for 2 Seconds..\r\n");
		Delay_ms(2000);

		// Set DHCP
		init_dhcp_client(SOCK_DHCP, wizSWReset, wizSWReset);
		getIP_DHCPS();

		for(i=0; i<4; i++){
			netinfo.Mac[i] = SRC_MAC_ADDR[i];
			netinfo.IP[i] = GET_SIP[i];
			netinfo.Subnet[i] = GET_SN_MASK[i];
			netinfo.Gateway[i] = GET_GW_IP[i];
			netinfo.DNSServerIP[i] = GET_DNS_IP[i];
		}
		netinfo.Mac[i] = SRC_MAC_ADDR[i];
		i++;
		netinfo.Mac[i] = SRC_MAC_ADDR[i];
	}

	SetNetInfo(&netinfo);

	printf("\r\n--------------------------------------- \r\n");
	printf("W5200E01-M3                       \r\n");
	printf("Network Configuration Information \r\n");
	printf("--------------------------------------- ");

	GetNetInfo(&netinfo);
	printf("\r\nMAC : %.2X.%.2X.%.2X.%.2X.%.2X.%.2X", netinfo.Mac[0],netinfo.Mac[1],netinfo.Mac[2],netinfo.Mac[3],netinfo.Mac[4],netinfo.Mac[5]);
	printf("\r\nIP : %d.%d.%d.%d", netinfo.IP[0],netinfo.IP[1],netinfo.IP[2],netinfo.IP[3]);
	printf("\r\nSN : %d.%d.%d.%d", netinfo.Subnet[0],netinfo.Subnet[1],netinfo.Subnet[2],netinfo.Subnet[3]);
	printf("\r\nGW : %d.%d.%d.%d", netinfo.Gateway[0],netinfo.Gateway[1],netinfo.Gateway[2],netinfo.Gateway[3]);
	printf("\r\nDNS server : %d.%d.%d.%d", netinfo.DNSServerIP[0],netinfo.DNSServerIP[1],netinfo.DNSServerIP[2],netinfo.DNSServerIP[3]);
}
Exemplo n.º 4
0
/*******************************************************************************
* Function Name  : main
* Description    : Main program.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
int main(void)
{  
	uint16 i; 
        RCC_Configuration(); // Configure the system clocks
	NVIC_Configuration(); // NVIC Configuration
	GPIO_Configuration();
	USART1_Init(115200);
	Timer_Configuration();
        
        printf("============================================\r\n");
	printf("   HTTP client for W5200 \r\n");
	printf("============================================\r\n");
       
	WIZ_SPI_Init();	
        Reset_W5200();
        wizInit();
        InitNetInfo();
        DisplayNetInfo();
	              
        // LED3 and LED4 On!
	LED3_onoff(ON);
	LED4_onoff(ON);
     
       
        uint8  url[MAX_URL_SIZE];			//full url
	uint8  url_dn[MAX_URL_SIZE];			//domain name url
	uint8  url_path[MAX_URL_SIZE];		//local path in html server
	char * split;				//string split pointer 
	
	
	uint16 done_http = 0;
	uint16 start_idx = 0 ;
	uint16 end_idx = 0;
	uint16 tmp_start;
	uint16 tmp_end;
	uint8 BR [4]= "<BR>";
	uint8 rBR [4]= "\r\n";
	uint8 TITLE [7]= "<TITLE>";
	uint8 bTITLE [8]= "</TITLE>";
	

	uint16 tmp_idx;
	uint8 no_pr = 0;
	uint8 str[17];
       
	
            while (1)
            {
                          
              sprintf((char*)str,"%.3d.%.3d.%.3d.%.3d ",
				IINCHIP_READ (SIPR0+0), IINCHIP_READ (SIPR0+1), 
				IINCHIP_READ (SIPR0+2), IINCHIP_READ (SIPR0+3));
                            
                           
                            /* Get Http Address  */
                            printf("\r\n Please enter a HTTP Address without 'http://' \n\r"); 
                            printf("http://");
                            memset(url,0,sizeof(url));	
                            //Modified by Gang 2011-10-04
                            zScanf_s(1, url);
                            printf("\r\n Your HTTP address is: %s \r\n",url);		
                            
                            /* Parse URL Path  */
                            split = strchr((char const*)url,'/');			
                            strcpy((char*)url_path,split); 			
                            printf("Domain path: %s \r\n",url_path);
                    
                            /* Parse URL Domain  */
                            split = strtok((char*)url,"/");			
                            strcpy((char*)url_dn,split);				
                            printf("Domain name: %s \r\n",url_dn);
                            
               
                            /* Do DNS Client */
                            memset(httpclient_NetInfo.HTTPs_IP,0,sizeof(httpclient_NetInfo.HTTPs_IP));
                            //Delay_ms(10);
                            done_dns = dns_query(DNS_SOCK, url_dn, httpclient_NetInfo.HTTPs_IP);
                            printf("\r\n HTTPs_IP= %d.%d.%d.%d",httpclient_NetInfo.HTTPs_IP[0],httpclient_NetInfo.HTTPs_IP[1],httpclient_NetInfo.HTTPs_IP[2],httpclient_NetInfo.HTTPs_IP[3]);
                          
                            while(done_dns) {
                            
                            /* Do HTTP Client */
                            done_http = http_client(HTTPC_SOCK, httpclient_NetInfo.HTTPs_IP, url_path, url_dn,data_buf);
                           
                            if(done_http) { // on success, done_dns is not  '0'
                                            
    #define Recieved_DATA
    #ifdef Recieved_DATA
                                            printf("\r\n<< Recieved Data -- START>> \r\n");
                                           
                                            for(i=0; i<done_http; i++){
                                                  
                                                  printf("%c",(uint8)data_buf[i]);
                                              }   
                                            printf("\r\n");
                                            printf("<< Recieved Data -- END>> \r\n");
                                           
    #endif
                                        /* parsed index */
                                            //All other HTML elements are nested between the opening <html> and </html> tags.
                                            start_idx = pased_idx((uint8 *)str_start , sizeof(str_start), done_http );
                                            end_idx   = pased_idx((uint8 *)str_end , sizeof(str_end), done_http );			
    
                                            /* printf get <html> ...</html> */							
                                            for(i=start_idx; i<(end_idx+7); i++){						
                                                    /* remove header */
                                                    data_buf[i-start_idx] = data_buf[i];
                                             }   
                                            printf("\r\n");
                                            
    
                                            /* replace <br> tag to \r\n */
                                            //The br tag is used for specifying a line break.
                                            do{
                                                    tmp_idx = pased_idx((uint8*)BR, sizeof(BR) , end_idx-start_idx) ;
                                                    if(tmp_idx == 0 ) 
                                                            break;
                                                 
                                                    memcpy((uint8 *)data_buf+tmp_idx, (uint8*)rBR, sizeof(rBR)) ;
                                            }while(tmp_idx!=end_idx-start_idx);
    
    #define Parsed_DATA
    #ifdef Parsed_DATA
                                            /* parsed DATA */
                                            printf("\r\n<< Parsed Data -- START >>");
                                            printf("\r\nTITLE : \r\n");
                                            /* parse <TITLE> and </TITLE> tags */
                                            tmp_start = pased_idx((uint8 *)TITLE , sizeof(TITLE),(end_idx-start_idx) ) + sizeof(TITLE);
                                            tmp_end   = pased_idx((uint8 *)bTITLE , sizeof(bTITLE),(end_idx-start_idx) );												
                                            for(i=tmp_start; i<tmp_end; i++){
                                                   
                                                    printf("%c",(uint8)data_buf[i]); // printf title
                                            }   
    
                                            printf("\r\n BODY : \r\n");
                                            /*DO NOT PRINT TAG COMMAND: between '<' with '>' */
                                            for(i=tmp_end; i<(end_idx-start_idx); i++){
                                                    //Tag command - ex.)<PRE>
                                                    //'<' is a start point of tag command.
                                                    if((uint8)data_buf[i]=='<'){ 
                                                            no_pr = 0;
                                                    }
                                                    //'>' is a end point of Tag command.
                                                    //To avoid in row tags -> ex.) <PRE><H1>						
                                                    if((uint8)data_buf[i]=='>' && (uint8)data_buf[i+1] !='<' ) {
                                                            no_pr = 1;
                                                            i++;
                                                    }					
                                                    if(no_pr){
                                                        Delay_ms(1);    
                                                        printf("%c",(uint8)data_buf[i]);
                                                    }
                                            }   
                                            printf("\r\n<< Parsed Data -- END >>\r\n");
    #endif
                                            /* Init. parameter */
                                            start_idx= 0;
                                            end_idx= 0;				
                                    done_dns = 0;  
                                    break;
    
                            }
                           //done_http
                            //done_dns=0;
                    }//while : done_dns == 1		
            }
}