Data transfer on ethernet

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Data transfer on ethernet

1,282 Views
kapil_p
Contributor III

Hi

I am trying to build a communication from serial to ethernet and ethernet to serial.

By using the tcp_echo example i am trying to build the above communication . The ethernet to serial is working (transferred a data using packet sender and data is received in tcpecho.c file and same data is given to uart ).

Now to build the serial to ethernet communication , not understanding where to put  data which is received from the serial.

I given the data received from the serial  to tcp_write( ) in tcpecho_raw.c file but it is not working.

Not understanding how tcpecho_raw.c is working.

Thank you.

Kapil Patil.

Tags (1)
0 Kudos
5 Replies

1,121 Views
FelipeGarcia
NXP Employee
NXP Employee

Hello Kapil,

 

Could you please specify which MCU are you working on? Thanks.

 

Best regards,

Felipe

0 Kudos

1,121 Views
kapil_p
Contributor III

Hello Felipe Garcia

I am using a FRDM K64-F development board.

Once again I am explaining my problem. I know it is difficult to understand to you but still I am trying to explain.

I want to develop a communication like Ethernet to serial and serial to Ethernet. I am using a lwip tcpecho example. I am successful in Ethernet to serial communication (transferring from TCP and receiving at serial ).

In tcpecho example the data transfer tcpecho_raw_send(tcp,es) function is called in the tcpecho_recv function , here I commented all the tcpecho_raw_send() functions whhich is called inside tcp_raw_recv() function. Now I want to send my own data by using tcpecho_raw_send() but I am confused where to call this function in tcpecho_raw.c file , if I called tcpecho_raw_send function outside the tcpecho_raw_file , I am confuse how to pass the parameters   tcp and es , if I declare this parameters separately in main function then invalid PCB error is generating. On error invalid PCB I understood that , while making a new connection one pcb is generated and the PCB which I am using is not that PCB which is previously created , so again I created a connection like following but again it showing a error the connection is already done for this IP.

void echo_tx_tcp()

struct tcp_pcb *l_tcp_pcb;
l_tcp_pcb = tcp_new();

 wr_err = tcp_bind(l_tcp_pcb, IP_ANY_TYPE, 7);
tcpecho_raw_pcb = tcp_listen(l_tcp_pcb);
wr_err = tcp_connect(l_tcp_pcb, IP_ANY_TYPE, 7, tcp_accept);

struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, 1024, PBUF_RAM);
unsigned char buffer_send[1024] = "My Name Is TCP";
p->payload = buffer_send;
p->len = 1024;
p->tot_len = 1024;

wr_err = tcp_write(tcpecho_raw_pcb , p->payload, p->len, 1);

}

 The main thing is I want to a separate transfer function where I can put my data received from the serial.

I am using 

IDE = MCUXpresso

board = FRDM K64-F

Thank you.

Kapil Patil

0 Kudos

1,121 Views
FelipeGarcia
NXP Employee
NXP Employee

Hello Kapil,

 

If you check tcp_write() function, the second argument is a pointer to the data to be enqueued for sending. How about you change this argument and put your own data instead?

 

From tcpecho_raw_send()

 

  struct pbuf *ptr;

  err_t wr_err = ERR_OK;

 

  while ((wr_err == ERR_OK) &&

         (es->p != NULL) &&

         (es->p->len <= tcp_sndbuf(tpcb))) {

    ptr = es->p;

 

    /* enqueue data for transmission */

    wr_err = tcp_write(tpcb, ptr->payload, ptr->len, 1);

 

Please let me know of this helps.

 

Best regards,

Felipe

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

1,121 Views
kapil_p
Contributor III

Hello Felipe García

Thank you for the reply.

The problem is not changing the argument . In tcpecho_raw_send function I given my own data and it is working fine only when I call the function tcpecho_raw_send()  in tcpecho_raw_recv(). 

         I want to call tcpecho_raw_send() in main file ,  but I am not understanding how to pass a arguments. 

       My transmit function should not depend on the receive function , I want to call this when my serial data is arrive.

I have a problem with the parameters like struct tcp_pcb *tpcb 

tcpecho_raw_send(struct tcp_pcb *tpcb, struct tcpecho_raw_state *es)

static void
tcpecho_raw_send(struct tcp_pcb *tpcb, struct tcpecho_raw_state *es)
{
struct pbuf *ptr;
err_t wr_err = ERR_OK;
char mydata[1024] = "Hello everyone\n";

// tcpecho_raw_init();
while ((wr_err == ERR_OK) &&
(es->p != NULL) &&
(es->p->len <= tcp_sndbuf(tpcb))) {
ptr = es->p;

wr_err = tcp_write(tpcb, "FRDM K64-F",10, 1);  // This is working fine 


if (wr_err == ERR_OK) {
u16_t plen;

plen = ptr->len;
/* continue with next pbuf in chain (if any) */
es->p = ptr->next;
if(es->p != NULL) {
/* new reference! */
pbuf_ref(es->p);
}
/* chop first pbuf from chain */
pbuf_free(ptr);
/* we can read more data now */
tcp_recved(tpcb, plen);
} else if(wr_err == ERR_MEM) {
/* we are low on memory, try later / harder, defer to poll */
es->p = ptr;
} else {
/* other problem ?? */
}
}

}

I tried above function like this but invalid pcb error is generated.

static void
tcpecho_raw_send()
{

struct tcp_pcb *new_tpcb;
struct pbuf *ptr;
err_t wr_err = ERR_OK;
char mydata[1024] = "Hello everyone\n";

// tcpecho_raw_init();
while ((wr_err == ERR_OK) &&
(es->p != NULL) &&
(es->p->len <= tcp_sndbuf(tpcb))) {
ptr = es->p;

wr_err = tcp_write(new_tpcb, "FRDM K64-F",10, 1);  // This is working fine 


if (wr_err == ERR_OK) {
u16_t plen;

plen = ptr->len;
/* continue with next pbuf in chain (if any) */
es->p = ptr->next;
if(es->p != NULL) {
/* new reference! */
pbuf_ref(es->p);
}
/* chop first pbuf from chain */
pbuf_free(ptr);
/* we can read more data now */
tcp_recved(tpcb, plen);
} else if(wr_err == ERR_MEM) {
/* we are low on memory, try later / harder, defer to poll */
es->p = ptr;
} else {
/* other problem ?? */
}
}

}

Thank you

Kapil Patil

0 Kudos

1,121 Views
FelipeGarcia
NXP Employee
NXP Employee

Hello Kapil,

 

Could you please show me errors you mentioned? Even better if you can share your code with the modifications stated in your previous reply so I can replicate this on my side.

 

Best regards,

Felipe

0 Kudos