📄 app.c
字号:
/*****************************************************************************
* "A Very Simple Application" from the uIP 0.6 documentation
*****************************************************************************/
#include <io.h>
#include "global.h"
#include "app.h"
#include "rprintf.h"
#include "uart.h"
u08* sendBufferPtr;
u08 sendBufferLen;
void appInit(void)
{
// listen for telnet
uip_listen(23);
// listen for http
uip_listen(80);
DDRB = 0xFF;
PORTB = 0xFF;
rprintf("application initialized\r\n");
}
void appSendBufferPutchar(u08 c)
{
*sendBufferPtr++ = c;
sendBufferLen++;
}
void appEvent(void)
{
switch(uip_conn->lport)
{
case htons(23):
appServiceTelnet();
break;
case htons(80):
appServiceHTTP();
break;
default:
break;
}
}
void appServiceTelnet(void)
{
// redirect rprintf output to network buffer
sendBufferPtr = uip_appdata;
sendBufferLen = 0;
rprintfInit(appSendBufferPutchar);
if(uip_connected())
{
rprintf("Welcome to the Internet-AVR\r\n");
rprintf("Type CTRL-D to disconnect\r\n");
rprintf("avr>");
uip_send(uip_appdata, sendBufferLen);
}
if(uip_newdata() || uip_rexmit())
{
switch(*uip_appdata)
{
//process control characters
case 0x04:
// process CTRL-D
// terminate connection
uip_close();
break;
case 0x0D:
// process CR
rprintf("\r\navr>");
uip_send(uip_appdata, sendBufferLen);
break;
default:
// echo typed characters
PORTB = ~(*uip_appdata);
uip_send(uip_appdata, uip_datalen());
break;
}
}
rprintfInit(uartSendByte);
}
void appServiceHTTP(void)
{
if(uip_newdata() || uip_rexmit())
{
uip_send("Content-type: text/html\n\nHello", 3);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -