receiving can bus messages and send over UDP/TCP continuously

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

receiving can bus messages and send over UDP/TCP continuously

Postby snahmad75 » Wed Aug 08, 2018 4:44 pm

Hi,

I have Task/thread which continuous check for any can message and then I put into my queue. other thread check queue and send it over TCP/UDP continuous.

Does any one have experience with it?

Any performance issues.

UDP is not 100% reliable I do lost some can packets using boradcast or unicast destination address.

For TCP. it buffers my multiple messages togther. send them some time 30, 60 or 90 bytes.
As my can packets are small size max =30 bytes.

Can I avoid TCP buffering?

I also notice TCP do retry as well. so I receive duplicate message.


Using mongoose Web Server Networking API. I cannot continuously send packets because mongoose thread polling every 1ms.

I am using lwip BSD socket. It is better.

Deouss
Posts: 425
Joined: Tue Mar 20, 2018 11:36 am

Re: receiving can bus messages and send over UDP/TCP continuously

Postby Deouss » Wed Aug 08, 2018 6:33 pm

I used idf sokets and they are blasting fast. We are talking transfers of 10+mbyte/s (TCP)
There is however buffer limit for single socket and number of non blocking calls on the system.
It is all in menuconfig - I must check that.

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: receiving can bus messages and send over UDP/TCP continuously

Postby snahmad75 » Wed Aug 08, 2018 7:31 pm

What you mean by idf sokets?

Do you mean LWIP socket BSD API?

Kindly give me your menuconfig file and example code.

Deouss
Posts: 425
Joined: Tue Mar 20, 2018 11:36 am

Re: receiving can bus messages and send over UDP/TCP continuously

Postby Deouss » Wed Aug 08, 2018 11:01 pm

I mean sockets that come with esp-idf rtos. I guess lightweight library don't know if bsd compatible.
Those sockets work fine with windows sockets so what's the difference.
The speed is insane: example here

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: receiving can bus messages and send over UDP/TCP continuously

Postby fly135 » Wed Aug 08, 2018 11:17 pm

snahmad75 wrote:I also notice TCP do retry as well. so I receive duplicate message.
I really doubt you are receiving duplicates. I've never seen that.

I'm guessing that you don't want messages combined because you aren't parsing the stream and depend on getting a whole message per read. That's a fundamentally flawed way of using TCP. With TCP you should packetize your data and parse it.

However, you can try disabling the accumulation of data with the following....

Code: Select all

static void set_tcp_nodelay(int fd) {
  int val = 1;
  int rv;
  rv = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val, (socklen_t)sizeof(val));
  if (rv == -1) {
    dief("setsockopt", strerror(errno));
  }
}

John A

Who is online

Users browsing this forum: No registered users and 137 guests