初级会员

- 积分
- 53
- 金钱
- 53
- 注册时间
- 2014-1-20
- 在线时间
- 2 小时
|
方案采用的stm32 enc28j60 lwip协议 因为要传输图像远超过1.5kmtu限制所以要分包发送 但是各个地方插入
plen=fill_tcp_data(buf,0,img);//假设分包就是把img发送两遍
goto SENDTCP;
都失败了 请教一下应该怎么解决
贴上代码
#include "enc28j60.h"
#include "ip_arp_udp_tcp.h"
#include "net.h"
#include "web_server.h"
#include <string.h>
#include <stdio.h>
#include "led.h" // LED 亮灭控制头文件
#include "DHT11.h"
#include "stm32f10x_it.h"
#include "ov7620.h"
#include "sys.h"
#include "5110.h"
#define PSTR(s) s
extern unsigned char img[];
extern u8 Vsync_Flag;
int countx=0,flag;
/* mac地址和ip地址在局域网内必须唯一,否则将与其他主机冲突,导致连接不成功 */
static unsigned char mymac[6] = {0x00,0x07,0x03,0x11,0x02,0x04};
static unsigned char myip[4] = {192,168,3,250};
/* tcp/www监听端口号,范围为:1-254 */
static unsigned int mywwwport =80;
/* udp 监听端口号,即本地(开发板)端口号 */
static unsigned int myudpport =1200;
/* 发送数据缓冲区 */
#define BUFFER_SIZE 1514
static unsigned char buf[BUFFER_SIZE+1];
int Web_Server(void)
{
char feedback[128]={0},*id;
unsigned int plen, i1 = 0;
unsigned int dat_p;
u16 i = 0;
unsigned char *buf1;//cmd,
unsigned int payloadlen = 0;
/* 初始化 enc28j60 的MAC地址(物理地址),这个函数必须要调用一次 */
enc28j60Init(mymac);
/* PHY LED 配置,LED用来指示通信的状态 */
enc28j60PhyWrite(PHLCON,0x476);
/* 将enc28j60第三引脚的时钟输出改为:from 6.25MHz to 12.5MHz(本例程该引脚NC,没用到) */
//enc28j60clkout(2);
/* 初始化以太网 IP 层 */
init_ip_arp_udp_tcp(mymac,myip,mywwwport);
while(1)
{
// get the next new packet:
plen = enc28j60PacketReceive(BUFFER_SIZE, buf);
// plen will ne unequal to zero if there is a valid packet (without crc error)
if(plen==0)
//无任何操作
continue;
// arp is broadcast if unknown but a host may also
// verify the mac address by sending it to
// a unicast address.
if(eth_type_is_arp_and_my_ip(buf,plen))
{
make_arp_answer_from_request(buf);
continue;
}
// check if ip packets are for us:
if(eth_type_is_ip_and_my_ip(buf,plen)==0)
{ //定期检查ip
if(Read_DHT11(&DHT11_Data)==SUCCESS){
sprintf(feedback,"HUM:%d TEM:%d",DHT11_Data.humi_int,DHT11_Data.temp_int);
LCD_write_String(1,4,feedback);
}
continue;
}
if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V)
{
// a ping packet, let's send pong DOS 下的 ping 命令包
LCD_write_String(1,5,"WEB - ping! ");
make_echo_reply_from_request(buf, plen);
continue;
}
/*-----------------tcp port www start, compare only the lower byte-----------------------------------*/
if (buf[IP_PROTO_P]==IP_PROTO_TCP_V&&buf[TCP_DST_PORT_H_P]==0&&buf[TCP_DST_PORT_L_P]==mywwwport)
{
if (buf[TCP_FLAGS_P] & TCP_FLAGS_SYN_V)
{
make_tcp_synack_from_syn(buf);
// make_tcp_synack_from_syn does already send the syn,ack
continue;
}
if (buf[TCP_FLAGS_P] & TCP_FLAGS_ACK_V)//第三次握手
{
init_len_info(buf); // init some data structures
// we can possibly have no data, just ack:
dat_p=get_tcp_data_pointer();
if (dat_p==0)
{
if (buf[TCP_FLAGS_P] & TCP_FLAGS_FIN_V)
{
// finack, answer with ack断开
make_tcp_ack_from_any(buf);
}else{
//分包尝试在这里加上了
if(flag){
flag=0;
plen=fill_tcp_data(buf,0,img);//假设分包就是把img发送两遍
goto SENDTCP;//测试失败
}
}
// just an ack with no data, wait for next packet
continue;
}
if(strncmp("cam",(char *)&(buf[dat_p]),3)==0){
id=(char *)&(buf[dat_p]);
LCD_write_String(1,5,"BUID - str! ");
for(i=0;i<packsize;i++)
img=buff[(packsize*(*(id+3)-'a')+i)/160][(packsize*(*(id+3)-'a')+i)%160];
LCD_write_String(1,5,"BUID - ok! ");
flag=1;
plen=fill_tcp_data(buf,0,img);
goto SENDTCP;
}
SENDTCP:
make_tcp_ack_from_any(buf); // send ack for http get
make_tcp_ack_with_data(buf,plen); // send data
LCD_write_String(1,5,"SEND - ok! ");
continue;
}
}
/*-------------------------------------- tcp port www end ---------------------------------------*/
/*--------------------- udp start, we listen on udp port 1200=0x4B0 -----------------------------*/
if (buf[IP_PROTO_P]==IP_PROTO_UDP_V&&buf[UDP_DST_PORT_H_P]==4&&buf[UDP_DST_PORT_L_P]==0xb0)
{
payloadlen= buf[UDP_LEN_H_P];
payloadlen=payloadlen<<8;
payloadlen=(payloadlen+buf[UDP_LEN_L_P])-UDP_HEADER_LEN;
//payloadlen=buf[UDP_LEN_L_P]-UDP_HEADER_LEN;
// ANSWER:
//while(1){
for(i1=0; i1<payloadlen; i1++) buf1[i1]=buf[UDP_DATA_P+i1];
//make_udp_reply_from_request(buf,str,strlen(str),myudpport);
make_udp_reply_from_request(buf,buf1,payloadlen,myudpport);
//}
}
/*----------------------------------------udp end -----------------------------------------------*/
}
// return (0);
} |
|