У меня проблемы с чтением и хранением полученных данных на TCP-сервере. Я использую библиотеку LWIP и плату NUCLEO-F746ZG. Я полагаю, что я должен получить данные, когда я es-> p . Я читал, что вы должны использовать полезную нагрузку , но я не знаю, как это реализовать в обратном вызове mi receive:
static err_t tcp_echoserver_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{
struct tcp_echoserver_struct *es;
err_t ret_err;
u32_t *tempPtr;
LWIP_ASSERT("arg != NULL",arg != NULL);
es = (struct tcp_echoserver_struct *)arg;
/* if we receive an empty tcp frame from client => close connection */
if (p == NULL)
{
/* remote host closed connection */
es->state = ES_CLOSING;
if(es->p == NULL)
{
/* we're done sending, close connection */
tcp_echoserver_connection_close(tpcb, es);
}
else
{
/* we're not done yet */
/* acknowledge received packet */
tcp_sent(tpcb, tcp_echoserver_sent);
/* send remaining data*/
tcp_echoserver_send(tpcb, es);
}
ret_err = ERR_OK;
}
/* else : a non empty frame was received from client but for some reason err != ERR_OK */
else if(err != ERR_OK)
{
/* free received pbuf*/
if (p != NULL)
{
es->p = NULL;
pbuf_free(p);
}
ret_err = err;
}
else if(es->state == ES_ACCEPTED)
{
/* first data chunk in p->payload */
es->state = ES_RECEIVED;
/* store reference to incoming pbuf (chain) */
es ->p = p; //I can´t convert this into a String
/* initialize LwIP tcp_sent callback function */
tcp_sent(tpcb, tcp_echoserver_sent);
/* send back the received data (echo) */
tcp_echoserver_send(tpcb, es);
ret_err = ERR_OK;
}
else if (es->state == ES_RECEIVED)
{
/* more data received from client and previous data has been already sent*/
if(es->p == NULL)
{
//es->p = p;
/* send back received data */
tcp_echoserver_send(tpcb, es);
}
else
{
struct pbuf *ptr;
/* chain pbufs to the end of what we recv'ed previously */
//ptr = es->p;
//pbuf_chain(ptr,p);
}
ret_err = ERR_OK;
}
else if(es->state == ES_CLOSING)
{
/* odd case, remote side closing twice, trash data */
//tcp_recved(tpcb, p->tot_len);
//es->p = NULL;
//pbuf_free(p);
ret_err = ERR_OK;
}
else
{
/* unkown es->state, trash data */
//tcp_recved(tpcb, p->tot_len);
//es->p = NULL;
//pbuf_free(p);
ret_err = ERR_OK;
}
return ret_err;
}
Если кто-нибудь знает, как извлечь данные в виде строки, это мне очень поможет.
заранее спасибо !!