LWIP Echo:无法以正确格式读取Hercules中的数据

时间:2018-10-09 04:27:49

标签: c sdk xilinx lwip

对于硬件实现,我正在尝试使用itoa函数读取Hercules中的连续DestinationBuffer数据。我在Hercules中读取了一些垃圾字符的数据。如何清除垃圾? enter link description here

实际数据流应为Data:1050842703,Data:1050842704,Data:1050842705,Data:1050842706,Data:1050842707,Data:1050842708,Data:1050842709,Data:1050842710,Data:1050842711,Data:1050842712,

但是我能够读取Hercules中的数据,但是没有任何逗号。 105084270310508427041050842705105084270610508427071050842708 如何使用逗号中断数据。

 char *itoa(int val, int base)       
 {
  int i = 30;
  for(; val && i ; --i, val /= base)
  buf[i] = "0123456789abcdef"[val % base];
 return &buf[i+1];
 }

 err_t recv_callback(void *arg, struct tcp_pcb *tpcb,
                           struct pbuf *p, err_t err)
{
int i,j,Status;
Status=aurora_rx_main();         ///FUNCTION CALL
for(i=0;i<50;i++)
 {
    xil_printf(" Data:%d,",DestinationBuffer[i]);
 }

 int base=10; // here 10 means decimal
 char *result={0};
 if (!p) 
   {
    tcp_close(tpcb);
    tcp_recv(tpcb, NULL);
    return ERR_OK;
 }

/* indicate that the packet has been received */
tcp_recved(tpcb, p->len);
if (tcp_sndbuf(tpcb) > 50) 
     {
     for (j=0;j<=50;j++)
        {
        result= itoa(DestinationBuffer[j],base);
        err = tcp_write(tpcb,",",10,1);    // for itoa 
        err = tcp_write(tpcb,result,10,1);
        }
    } else
    xil_printf("no space in tcp_sndbuf\n\r");

/* free the received pbuf */
 pbuf_free(p);

 return ERR_OK;
} 

[Hercules Console][1]

0 个答案:

没有答案