问题描述
我想让我的Zedboard使用Xilinx lwIP示例作为基础返回一个数字值,但是无论我做什么,我都无法弄清楚存储接收或传输的数据的原因。
我已经找到了空类型有效载荷,但是我不知道该怎么做。
Snapshot of one instance of payload and a list of lwIP files
以下是最接近我目标的功能:
err_t recv_callback(void *arg,struct tcp_pcb *tpcb,struct pbuf *p,err_t err){
/* do not read the packet if we are not in ESTABLISHED state */
if (!p) {
tcp_close(tpcb);
tcp_recv(tpcb,NULL);
return ERR_OK;
}
/* indicate that the packet has been received */
tcp_recved(tpcb,p->len);
/* echo back the payload */
/* in this case,we assume that the payload is < TCP_SND_BUF */
if (tcp_sndbuf(tpcb) > p->len) {
err = tcp_write(tpcb,p->payload,p->len,1);
//I need to change p->paylod but IDK where it is given a value.
} else
xil_printf("no space in tcp_sndbuf\n\r");
/* free the received pbuf */
pbuf_free(p);
return ERR_OK;
}
任何指导表示赞赏。
谢谢, Turtlemii
解决方法
-我作弊,只是确保该函数可以从echo.c访问Global_tpcb -tcp_write()读入一个地址并显示它看起来每个字符。
void Print_Code()
{
/* Prepare for TRANSMISSION */
char header[] = "\rSwitch: 1 2 3 4 5 6 7 8\n\r"; //header text
char data_t[] = " \n\r\r"; //area for storing the
data
unsigned char mask = 10000000; //mask to decode switches
swc_value = XGpio_DiscreteRead(&SWCInst,1); //Save switch values
/* Write switch values to the LEDs for visual. */
XGpio_DiscreteWrite(&LEDInst,LED_CHANNEL,swc_value);
for (int i =0; i<=7; i++) //load data_t with switch values (0/1)
{
data_t[8+2*i] = '0' + ((swc_value & mask)/mask); //convert one bit to 0/1
mask = mask >> 1;//move to next bit
}
int len_header = *(&header + 1) - header; //find the length of the
header string
int len_data = *(&data_t + 1) - data_t; //find the length of the data string
tcp_write(Global_tpcb,&header,len_header,1); //print the header
tcp_write(Global_tpcb,&data_t,len_data,1); //print the data
}