Closed serkonda7 closed 1 year ago
Hello,
thank you for your feedback!
When canny initializes, it attempts to open a listening socket on each available CAN interface. The error that you're seeing (EINVAL
from bind()
) is what happens when you attempt to open more than one socket on the same CAN interface.
In other words, I think the problem is that cangen and canny can't be used at the same time.
Just to be sure, can you start canny when cangen isn't running?
The same error also happens without cangen or anything else running.
Hi, I had the same problem with my Raspberry PI 4 B
The function for initializing and opening a socket on available CAN doesn't seem to work as expected on a raspberry PI.
After many hours of debugging ( I am far from good on Linux and C), I found that the bind opening the canbus fail by lack of a canbus name to open. So I forced the value of CAN0 in the source and it worked... The program can now connect to my CAN0. After that, I also found another problem... even if the documentation state it works on IPV4, I notice that the port listen to always end up on a TCPV6 address at port 3840 even if we state -p1234....
In the source code it always refer to INET6. Is that the reason why it always end up in IPV6???
Thanks for any feedback :o)
static int cansock(void) { struct sockaddr_can addr; struct ifreq ifr; int fd; int res; int e; const char *ifname = "can0"; ** Added by me
if(!(ifaces = array_alloc())) {
return(-1);
}
if((fd = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
e = errno;
perror("socket");
errno = e;
return(-1);
}
memset(&addr, 0, sizeof(addr));
strcpy(ifr.ifr_name, ifname); *********** Added by me
ioctl(fd, SIOCGIFINDEX, &ifr); *********** Added by me
addr.can_family = AF_CAN;
addr.can_ifindex = ifr.ifr_ifindex;
if(bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
e = errno;
perror("bind");
close(fd);
free(ifaces);
ifaces = NULL;
errno = e;
return(-1);
}
Hello,
I am terribly sorry I didn't follow up on this issue for such a long time.. I decided to spend some money on a Raspberry Pi and CAN interfaces so that I can figure out what is happening here and finally solve this issue. Would you mind telling me what exact hardware you were using when you ran into this issue?
Best regards
Hello, First, dont be sorry. Your canny has allowed me to complete a proof of concept. So it was very useful. My patch wasn't ideal but did the job. The unit used was a Raspberry Pi 4 Model B/8GB. If you are to open the code I have one question/request... Is canny able to self dectect the canbus speed and self ajust in its current implementation? And if not can that be added easily?
As for the Raspberry Pi, Since the pandemic, it is very difficult to get the hold of one. If you encounter such problem, contact me.
Best Regards
Oups,
in addition, my config included a PiCAN-3 for running the CAN bus
https://www.skpang.co.uk/products/pican3-can-bus-board-for-raspberry-pi-4-with-3a-smps-rtc
Regards
Hey @ghubmlafontaine,
thank you for your response and understanding! I'm really happy to hear that canny has been useful to you, especially since I hacked it together during my student days and I never really expected anyone to use it. :-)
If you are to open the code I have one question/request... Is canny able to self dectect the canbus speed and self ajust in its current implementation? And if not can that be added easily?
Canny can't currently do that, but I suppose it would not be terribly complicated to add support for sensing/adjusting the bus speed. Could you please open a new issue and write a brief explanation how exactly you imagine the feature to work? That'll make it easier to discuss the feature.
As for the Raspberry Pi, Since the pandemic, it is very difficult to get the hold of one. If you encounter such problem, contact me.
Thank you very much! I ordered a Raspberry Pi 4B with 8GB and a couple of MCP2515-based CAN controllers (not the PiCAN, but a similar design) just the other day and they should arrive tommorrow. I should be able to provide a small update next week.
Best regards
Hey there,
the Raspberry Pi and the CAN interfaces arrived yesterday and I've been able to figure out why the initialization fails. At first, I thought the problem had something to do with the number of interfaces in the system, since I never had any problems on my single-interface Raspberry Pi back when I first wrote canny. However, this problem is actually caused by a bug in the CAN socket initialization. The address structure that canny passes to the kernel does not have the address family set, and I suppose older kernel versions (like the one I used back then) didn't check the values as strictly as more recent kernels.
This is actually a very stupid bug and it has been in canny since day 1.. sorry I didn't notice it until now. :sweat_smile:
Anyway, I have pushed a fix to the master branch (https://github.com/m10k/canny/commit/4c0d22a651a0eea5c158f5368fdfa3d23254db67). Please let me know if this fixes the problem for you.
Best regards
Great, I will try to go and run a test next weekend with the new code.... Thanks
Hey hey,
I can confirm (I am sure there is no surprise for you!) It solve the problem for me too.
Thanks a lot 🥇 👍
I have not the equipment to verify at the moment but consider this as closed. Thanks you :100:
Hey @ghubmlafontaine and @serkonda7, thank you for your feedback and for trying out the fix. I really appreciate it! :)
Running canny fails on an raspberry pi:
I have
can0
andcan1
ports open and simulated traffic (cangen) on can0.