|
#include <stdio.h>
#include <string.h>
#include "http_webs.h"
/* 这是实际的web页面数据。大部分的编译器会将这些数据放在ROM里*/
const static char index_html[] ={
"<html>\r\n"
" <head>\r\n"
" <meta http-equiv=\"X-UA-Compatible\" content=\"IE=7\">\r\n"
" <meta http-equiv=\"content-type\" content=\"text/html;charset=gb2312\">\r\n"
" <title>CORTEX-M3 LM3S8962 HTML 测试程序</title>\r\n"
" </head>\r\n"
" <body >\r\n"
" <form name=\"loginForm\" method=\"post\" action=\"hello.htm\">\r\n"
" <table>\r\n"
" <tr><td><div align=\"right\">用户名:</div></td>\r\n"
" <td><input type=\"text\" name=\"username\"></td>\r\n"
" </tr>\r\n"
" <tr><td><div align=\"right\">口令:</div></td>\r\n"
" <td><input type=\"password\" name=\"password\"></td>\r\n"
" </tr>\r\n"
" <tr><td></td>\r\n"
" <td><input type=\"submit\" name=\"submit\" value=\"submit\"></td>\r\n"
" </tr>\r\n"
" </table>\r\n"
" </form>\r\n"
"\r\n"
" \r\n"
" </body>\r\n"
"</html>\r\n"
"\r\n"
};
const static char http_html_hdr[] = "HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\n";
/* 线程入口*/
void rt_webserver_thread(void* paramter)
{
struct netconn *conn, *newconn;
struct netbuf *TCPNetbuf=NULL;
char *rq;
char *uri;
unsigned int i;
unsigned short len;
int fd,size=1;
char file_data_buffer[100];
conn = netconn_new(NETCONN_TCP); /* 创建TCP连接 */
netconn_bind(conn,NULL,80); /* 绑定本地地址和监听的端口号 */
netconn_listen(conn); /* 进入监听状态 */
while(1)
{
newconn = netconn_accept(conn); /*阻塞当前进程到有数据接收 */
if(newconn != NULL)
{
TCPNetbuf = netconn_recv(newconn);
if(TCPNetbuf != NULL)
{
netbuf_data( TCPNetbuf,(void *)&rq,&len);
uri=&rq[4];//请求内容,前四字节是请求类型,GET与POST 后面为用户请求
if (strncmp(rq, "GET ", 4) == 0)
{
/*************************GET 用户请求********************************/
for(i = 4; i < (len - 5); i++) /*提取用户请求以HTTP为界*/
{
if ((rq == ' ')&&(rq[i + 1] == 'H') &&(rq[i + 2] == 'T') && (rq[i + 3] == 'T') &&(rq[i + 4] == 'P'))
{
rq = 0;
break;
}
}
if(i == (len - 5)) /*提取用户请求失败*/
{
netbuf_delete(TCPNetbuf);
netconn_close(newconn); /* 关闭连接 */
while(netconn_delete(newconn) != ERR_OK);
continue; /*结束本次处理,如果是在函数里面就使用返回*/
}
/*************************GET 请求********************************/
rt_kprintf("\n");
rt_kprintf((void *)uri);
rt_kprintf("\n");
if((uri[0]=='/')&&(uri[1]==0)) //默认打开的页面
{
netconn_write(newconn,http_html_hdr,sizeof(http_html_hdr),NETCONN_NOCOPY);
/* 发送头部数据 */
netconn_write(newconn,index_html,sizeof(index_html),NETCONN_NOCOPY);
/* 发送实际的WEB页面 */
}//END IF URI
else /*其它文件请求处理*/
{
rt_kprintf("send head string...\n");
netconn_write(newconn,g_psHTTPHeaderStrings[HTTP_HDR_OK],sizeof(g_psHTTPHeaderStrings[HTTP_HDR_OK]),NETCONN_NOCOPY);
netconn_write(newconn,g_psHTTPHeaderStrings[HTTP_HDR_JPG],sizeof(g_psHTTPHeaderStrings[HTTP_HDR_JPG]),NETCONN_NOCOPY);
rt_kprintf("open file...\n");
fd = open("/DCIM/100MEDIA/IMG_001.JPG", O_RDONLY,0);
if (fd >= 0)
{
rt_kprintf("send file...wait !\n");
while (1)
{
size=read(fd,file_data_buffer, sizeof(file_data_buffer));
if(!size){ close(fd);break;}
//rt_kprintf("%d\n",size);
netconn_write(newconn,file_data_buffer,size,NETCONN_NOCOPY);
}
}
}
} /*请求信息*/
rt_kprintf("clear TCPNetbuf conn..\n");
netbuf_delete(TCPNetbuf);
rt_kprintf("close conn..\n");
}
netconn_close(newconn); /* 关闭连接 */
rt_kprintf("delete conn..\n");
while(netconn_delete(newconn) != ERR_OK);
}
}
}
错误如下
/poto1.jpg
send head string...
open file...
send file...wait !
100
psr: 0x61000000
pc: 0x0000126c
lr: 0x000011c5
r12: 0x00000000
r03: 0xffffffff
r02: 0x20000998
r01: 0x00000004
r00: 0x00000004
hard fault on thread: etx
thread pri status sp stack size max used left tick error
-------- ---- ------- ---------- ---------- ---------- ---------- ---
twebsrv 0x13 suspend 0x00000130 0x00001000 0x00000278 0x00000011 000
tcpip 0x16 suspend 0x00000230 0x00000400 0x00000278 0x00000002 000
tidle 0x1f ready 0x00000050 0x00000100 0x00000050 0x00000012 000
tshell 0x14 suspend 0x00000230 0x00000800 0x00000230 0x00000064 000
led 0x19 suspend 0x00000078 0x00000200 0x00000078 0x00000009 -02
led 0x19 suspend 0x00000078 0x00000200 0x00000078 0x00000008 -02
led_stat 0x15 suspend 0x00000080 0x00000400 0x00000080 0x0000000f -02
etx 0x17 ready 0x00000078 0x00000200 0x00000090 0x00000010 000
erx 0x17 suspend 0x00000090 0x00000200 0x000000d0 0x00000010 000
问题:
每次促使要一运行到这里LWIP就挂在这里故障
//rt_kprintf("%d\n",size);
netconn_write(newconn,file_data_buffer,size,NETCONN_NOCOPY);
前面的发送又没有问题,奇怪了
是LWIP有问题还是MILBOX有问题,真的是难查出来呀。又不能单步DEBUG。FFXZ希望你能看看。谢谢了 |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|