?? networkapply.c
字號:
#include "44b.h"
#include "44blib.h"
extern unsigned long server_ip;
extern unsigned long local_ip;
void Dhcp_Test()
{
NicInit();
NetInit();
Uart_Printf("\n Waiting DHCP server to Respond.\n");
Uart_Printf("\n Press any key to exit ...\n");
LCD_view(vcol,vrow,BLACK,"Waiting DHCP server to Respond.");
LCD_view(vcol,vrow+pad,BLACK,"Press any key to exit ...");
DhcpQuery();
Uart_Printf("\nReceive DHCP Message from server %d.%d.%d.%d",
(char)(server_ip>>0),
(char)(server_ip>>8),
(char)(server_ip>>16),
(char)(server_ip>>24));
Uart_Printf("\nConfig local ip address %d.%d.%d.%d\n",
(char)(local_ip>>0),
(char)(local_ip>>8),
(char)(local_ip>>16),
(char)(local_ip>>24));
sprintf(buf, "Receive DHCP Message from server %d.%d.%d.%d",
(char)(server_ip>>0),
(char)(server_ip>>8),
(char)(server_ip>>16),
(char)(server_ip>>24));
LCD_view(vcol,vrow+pad*2,BLACK,buf);
sprintf(buf, "Config local ip address %d.%d.%d.%d\n",
(char)(local_ip>>0),
(char)(local_ip>>8),
(char)(local_ip>>16),
(char)(local_ip>>24));
LCD_view(vcol,vrow+pad*3,BLACK,buf);
Delay(100);
}
void Tftp_Test()
{
char* pData;
unsigned long write_addr;
char input_string[64];
char tmp_ip[4] = {0,0,0,0};
int tmp,len,i,j,num=0;
int b10 =0; int b100 =0; int flag=0;
NicInit();
NetInit();
Uart_Printf("\n Do you want to configure local IP ?\n");
Uart_Printf(" Y/y to configure local IP addr; D/d to use Default IP addr(192.192.192.200).\n");
Uart_Printf(" Press any key to continue ...\n");
LCD_view(vcol,vrow,BLACK,"D/d to use Default IP addr(192.192.192.200)");
LCD_view(vcol,vrow+pad,BLACK,"E to set a new IP address OR any key to continue...");
while(!(i = Uart_GetKey()))
{
i = key_read() ;
if (i != -1) {
i += 0x57; break;}
}
Uart_Printf(" ( %c )", i);
if(( i == 'e') | ( i == 'Y') | (i == 'y')) {
Uart_Printf(" Please input IP address(xxx.xxx.xxx.xxx) then press ENTER:\n");
LCD_view(vcol,vrow+pad*2,BLACK,"Input IP address(xxx.xxx.xxx.xxx) then press E:");
if( i == 'e')
{
for( i = 16; i != 0; i--) input_string[i] = 0xaa;
tmp = -1;
input_char = -1;
while(tmp != 0xE) // E to exit
{
while(input_char ==-1);
tmp = input_char;
if((tmp == 0xB)&(i != 0)) {
i -=1;
LCD_view(vcol+(pad-2)*i,vrow+pad*3,WHITE," ");
continue;}
if(tmp == 0xF)
{tmp = '.';
sprintf(buf, "%c",tmp);
tmp = '.'-0x30;}
else
sprintf(buf, "%x",tmp);
LCD_view(vcol+(pad-2)*i,vrow+pad*3,BLACK,buf);
input_string[i++] = tmp+0x30;
Delay(100);
input_char = -1;
}
} else {
for( i = 16; i != 0; i--) input_string[i] = 0xaa;
Uart_GetString(&input_string);
}
for( i = 0;((i <16)&(input_string[i] != 0xAA)); i++)
if(input_string[i] == '.') num +=1;
if(num != 3) flag = 1;
else
{
num = i - 2; j =0;
for( i = num; i >= 0; i--)
{
if(input_string[i] != '.' )
{
if((input_string[i] < '0' | input_string[i] > '9'))
{ flag = 1; break; }
else
{
tmp = (input_string[i] - 0x30);
if (b100) { tmp *=100; b10 =0; }
if (b10) { tmp *= 10; b100 =1;}
b10 = 1;
if(tmp < 256) tmp_ip[j] += tmp; else local_ip = 0x4dc0c0c0;
}
}else { j++; b10 =0; b100 =0;}
}
}
if(!flag)
{
Uart_Printf("\nManual Set local ip %d.%d.%d.%d\n",
tmp_ip[3],tmp_ip[2],tmp_ip[1],tmp_ip[0]
);
local_ip = ((tmp_ip[0]<<24))+((tmp_ip[1]<<16))\
+((tmp_ip[2]<<8))+tmp_ip[3];
sprintf(buf, "Manual Set local ip %d.%d.%d.%d\n",
tmp_ip[3],tmp_ip[2],tmp_ip[1],tmp_ip[0]
);
LCD_view(vcol,vrow+pad*4,BLACK,buf);
} else {
Uart_Printf("\nIP address error (xxx.xxx.xxx.xxx)!\n");
LCD_view(vcol,vrow+pad*4,BLACK,"IP address error (xxx.xxx.xxx.xxx)!");
}
}// yes
else if(i == 'D' || i == 'd')
{
local_ip = 0xc8c0c0c0; // config local ip 192.192.192.200
Uart_Printf("\nDefault Set local ip %d.%d.%d.%d\n",
local_ip&0x000000FF,(local_ip&0x0000FF00)>>8,
(local_ip&0x00FF0000)>>16,(local_ip&0xFF000000)>>24
);
sprintf(buf, "Default Set local ip %d.%d.%d.%d",
local_ip&0x000000FF,(local_ip&0x0000FF00)>>8,
(local_ip&0x00FF0000)>>16,(local_ip&0xFF000000)>>24
);
LCD_view(vcol,vrow+pad*3,BLACK,buf);
}
Uart_Printf("\nPress any key to exit ...\n");
LCD_view(vcol,vrow+pad*5,BLACK,"Press any key to exit ...");
for( ; ; )
{
if(Uart_GetKey()|(key_read() != -1)) return;
pData = (char *)TftpRecv(&len);
if( (pData == 0) || (len <= 0) )
continue;
write_addr = (pData[0])+(pData[1]<<8)+(pData[2]<<16)+(pData[3]<<24);
pData = pData + sizeof(long);
if( Program(write_addr,pData,len-4) == FALSE )
{
continue;
}
MakeAnswer();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -