Giter VIP home page Giter VIP logo

can-utils's Introduction

SocketCAN logo

SocketCAN userspace utilities and tools

This repository contains some userspace utilities for Linux CAN subsystem (aka SocketCAN):

Basic tools to display, record, generate and replay CAN traffic

  • candump : display, filter and log CAN data to files
  • canplayer : replay CAN logfiles
  • cansend : send a single frame
  • cangen : generate (random) CAN traffic
  • cansequence : send and check sequence of CAN frames with incrementing payload
  • cansniffer : display CAN data content differences

CAN access via IP sockets

  • canlogserver : log CAN frames and serves them
  • bcmserver : interactive BCM configuration (remote/local)
  • socketcand : use RAW/BCM/ISO-TP sockets via TCP/IP sockets
  • cannelloni : UDP/SCTP based SocketCAN tunnel

CAN in-kernel gateway configuration

  • cangw : CAN gateway userspace tool for netlink configuration

CAN bus measurement and testing

  • canbusload : calculate and display the CAN busload
  • can-calc-bit-timing : userspace version of in-kernel bitrate calculation
  • canfdtest : Full-duplex test program (DUT and host part)
  • isotpsend : send a single ISO-TP PDU
  • isotprecv : receive ISO-TP PDU(s)
  • isotpsniffer : 'wiretap' ISO-TP PDU(s)
  • isotpdump : 'wiretap' and interpret CAN messages (CAN_RAW)
  • isotpserver : IP server for simple TCP/IP <-> ISO 15765-2 bridging (ASCII HEX)
  • isotpperf : ISO15765-2 protocol performance visualisation
  • isotptun : create a bi-directional IP tunnel on CAN via ISO-TP

J1939/ISOBus tools

  • j1939acd : address claim daemon
  • j1939cat : take a file and send and receive it over CAN
  • j1939spy : spy on J1939 messages using SOC_J1939
  • j1939sr : send/recv from stdin or to stdout
  • testj1939 : send/receive test packet

Follow the link to see examples on how this tools can be used: Kickstart guide to can-j1939 on linux

Log file converters

  • asc2log : convert ASC logfile to compact CAN frame logfile
  • log2asc : convert compact CAN frame logfile to ASC logfile
  • log2long : convert compact CAN frame representation into user readable

Serial Line Discipline configuration (for slcan driver)

  • slcan_attach : userspace tool for serial line CAN interface configuration
  • slcand : daemon for serial line CAN interface configuration
  • slcanpty : creates a pty for applications using the slcan ASCII protocol

CMake Project Generator

  • Place your build folder anywhere, passing CMake the path. Relative or absolute.
  • Some examples using a build folder under the source tree root:
  • Android : cmake -DCMAKE_TOOLCHAIN_FILE=~/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-21 -DANDROID_ABI=armeabi-v7a .. && make
  • Android Studio : Copy repo under your project's app folder, add add_subdirectory(can-utils) to your CMakeLists.txt file after cmake_minimum_required(). Generating project will build Debug/Release for all supported EABI types. ie. arm64-v8a, armeabi-v7a, x86, x86_64.
  • Raspberry Pi : cmake -DCMAKE_TOOLCHAIN_FILE=~/rpi/tools/build/cmake/rpi.toolchain.cmake .. && make
  • Linux : cmake -GNinja .. && ninja
  • Linux Eclipse Photon (Debug) : CC=clang cmake -G"Eclipse CDT4 - Unix Makefiles" ../can-utils/ -DCMAKE_BUILD_TYPE=Debug -DCMAKE_ECLIPSE_VERSION=4.8.0
  • To override the base installation directory use: CMAKE_INSTALL_PREFIX ie. CC=clang cmake -DCMAKE_INSTALL_PREFIX=./out .. && make install

Additional Information:

can-utils's People

Contributors

ajneu avatar bastian-krause avatar darbedar avatar gerasiov avatar gibsson avatar grandwolf avatar hartkopp avatar herbrechtsmeier avatar jbeptx avatar jmahler avatar josemic avatar kohtala avatar kurt-vd avatar lauszus avatar marckleinebudde avatar neheb avatar olerem avatar ricciardi-adrien avatar rschwebel avatar rshanmu avatar rubusch avatar rumpelsepp avatar saschahauer avatar snewz avatar ukleinek avatar vincent-mailhol avatar weichslgartner avatar wentasah avatar yashi avatar yegorich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

can-utils's Issues

listen-only in slcand

slcand isa supposed to be able to replace slcan-attach functionalities. It's true except for the -l option.
Is there any reason why the listen-only functionality has not been implemented in slcand?

can.socketcan.native -ERROR - [Errno 100] network is down

This is a very odd problem that I'm having.

2016-10-27 14:23:29,488 - can.socketcan.native - INFO - Created a socket 2016-10-27 14:23:29,492 - can.socketcan.native - DEBUG - Binding socket to chann el=can1 2016-10-27 14:23:29,495 - can.socketcan.native - DEBUG - Bound socket. 2016-10-27 14:23:29,498 - Receiver - DEBUG - can0 2016-10-27 14:23:29,502 - can.socketcan.native - INFO - Created a socket 2016-10-27 14:23:29,505 - can.socketcan.native - DEBUG - Binding socket to chann el=can0 2016-10-27 14:23:29,508 - can.socketcan.native - DEBUG - Bound socket. 2016-10-27 14:23:29,513 - can.socketcan.native - ERROR - [Errno 100] Network is down Exception in thread Thread-3: Traceback (most recent call last): File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner self.run() File "/usr/lib/python3.4/threading.py", line 868, in run self._target(*self._args, **self._kwargs) File "/home/v7/v7.2/can/notifier.py", line 34, in rx_thread msg = self.bus.recv(self.timeout) File "/home/v7/v7.2/can/interfaces/socketcan_native.py", line 309, in recv packet = capturePacket(self.socket) File "/home/v7/v7.2/can/interfaces/socketcan_native.py", line 242, in captureP acket can_id, can_dlc, data = dissect_can_frame(cf) UnboundLocalError: local variable 'cf' referenced before assignment

I'm running this on a beaglebone - Debian, kernel: 4.1.15 with the TT3201-001-05 CAN cape.
Everything worked perfectly fine earlier, but this is the second time my beaglebone has had this problem (last time to solve the 'network is down' issue, I switched beaglebones)

Using BCM for sending/receiving canfd_frames

Good morning,

I am using SockatCAN on Debian and i'd like to use the BCM to send and receive frames. I successfully set up the BCM for can_frame but I'm having issues on how to setup it for canfd_frame.

The Linux kernel doc on SocketCAN gives the following information:

4.2.7 Broadcast Manager CAN FD support

The programming API of the CAN_BCM depends on struct can_frame which is
given as array directly behind the bcm_msg_head structure. To follow this
schema for the CAN FD frames a new flag 'CAN_FD_FRAME' in the bcm_msg_head
flags indicates that the concatenated CAN frame structures behind the
bcm_msg_head are defined as struct canfd_frame.

struct {
        struct bcm_msg_head msg_head;
        struct canfd_frame frame[5];
} msg;

msg.msg_head.opcode  = RX_SETUP;
msg.msg_head.can_id  = 0x42;
msg.msg_head.flags   = CAN_FD_FRAME;
msg.msg_head.nframes = 5;
(..)

Unfortunately, I can't find any CAN_FD_FRAME flag and I could not find information for TX. Could you help me with that ?

Best regards,

slcand arbitrary serial-can controller

Hi all,

Up until now, I've been working with SocketCAN via CANUSB adapters from Lawycel (http://www.can232.com/?page_id=16). However, now we received a new platform with another serial-can controller from axiomtek (http://www.axiomtek.com/Default.aspx?MenuId=Products&FunctionId=ProductView&ItemId=8270).

I am able to communicate with the CAN controller via serial and receive CAN frames. However, using slcand to create a socketcan interface does not work. As I see here https://github.com/linux-can/can-utils/blob/master/slcand.c , the slcand program sends specific commands to the serial bus and then creates a bridge between the socket and serial. However, the commands are different for my CAN controller.

Can somebody give me some pointers how to get SocketCAN to work with an arbitrary serial-can controller?

I'm am very new to these low level Linux things so I really would appreciate your help / corrections. Thanks in advance,

-Rein

candump exits when device goes down

Hi there,

candump is a useful tool, but the fact that

candump vcan0

will just exit and print read: Network is down, when I pull the device down (via sudo ip link set vcan0 down) is unfortunate.

PS: did you know, that I do not get the message read: Network is down and exit, when using any as device?? ;) Unfortunately using any... does not report on down/up status though.

Minor aside:
There's a common use-case for binaries using libsocketcan, to pull the device down (can_do_stop) and back up again (can_do_start). It's the only way I know of, to clear the socketcan transmit buffer. (And I really want to clear pending messages from it, because if a CAN-bus reconnect only occurs in say 5 minutes, then I don't want to transmit 5-minute old frames on reconnection.)

To try to work around the binary just exiting, I scripted up something, where I use ip monitor to detect when a device goes down and back up, and then invoke candump again. Try:

ip monitor link | while IFS=':' read num name status; do
    num=$(echo    $num    | xargs) # strip whitespace
    name=$(echo   $name   | xargs) # strip whitespace
    status=$(echo $status | xargs) # strip whitespace
    echo "   num   ==$num"
    echo "   name  ==$name"
    echo "   status==$status"
    read extraline
    ## ...
    ## ... code to handle change of status from DOWN to UNKOWN
    ## ...
done

But it's an ugly solution, because that script is so slow that the immediate frames sent when the device is back up are just missed. That's not ok.

So I decided to modify the candump.c code.
I've got 2 versions:

I believe it would be nice for something like the bottom one to go into upstream here.
I'm using some code (function send_dump_request) from libsocketcan.c. I think it's compatible with the very permissive Volkswagen license of candump.c.

Please clone the bottom one (down_up_reporting) and give it a try: candump -R -D vcan0. Bring down devices from a second shell and bring them up again. What do you think?

PCAN USB hardware timestamps

Hi,

Is it possible to get the hardware timestamp transformed in to system time?, I have a simple test case
where the timestamp given are wrong: One device sends the following messages

1F0#XXXX030405060708
1F1#XXXX030405060708
00ABCDEF#XXXX030405060708

The device waits 400 us between messages and then 10 ms to repeat the sequence.

What I get on the PC with candump is

(1502763522.866989) can1 1F0#8E61030405060708
(1502763522.867989) can1 1F1#8F61030405060708
(1502763522.867989) can1 00ABCDEF#9061030405060708
(1502763522.877774) can1 1F0#9161030405060708
(1502763522.878752) can1 1F1#9261030405060708
(1502763522.878752) can1 00ABCDEF#9361030405060708

So the time deltas are wrong because the device sends multiple CAN messages in one USB packet.

I found a commit [1] by @hartkopp that changed something related to timestamps in the pcan driver,
undoing that commit fixes the deltas but the timestamps no longer include system time.

I tried the netdev driver supplied by PEAK system and it gives the correct timestamps and deltas but it may not always be correct because it uses a non monotonic clock.

Is there a way to get both system time and deltas valid using the driver provided by linux?

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/net/can/usb/peak_usb?id=c9faaa09e2a1335678f09c70a0d0eda095564bab

cansend send only one frame

I am sorry but cansend send only one time just after I turn up can0 interface, in fact, I test it with oscilloscope and cansend send only one frame I am using raspbian and mcp2515 stand-alone module

question about candump

Hello,

I have a vehicle network adapter connected to a beagle bone blue which has an on board CAN transceiver. The VNA sends out 50k CAN frames each time it's powered up with a speed of roughly 4 frames per millisecond. Using candump I was able to capture all 50k frames. But If I use a blocking read() to get the frames from the can0 interface:

    int counter = 0;
    while (1) {
        nbytes = read(s, &frame, sizeof(frame));
        counter++;
        printf("total %d\n", counter);
    }

the counter didn't go all the way to 50k. And after reading the source code of candump, I changed my code to:

    while (1) {
        FD_ZERO(&rdfs);
        FD_SET(s, &rdfs);
        select(s + 1, &rdfs, NULL, NULL, timeout_current);
        if (FD_ISSET(s, &rdfs)) {
            nbytes = read(s, &frame, sizeof(frame));
            counter++;
            printf("total %d\n", counter);
        }
        fflush(stdout);
    }

the counter did show 50k at the end of every testing. I wonder why making read() unblocking will have the effect of receiving all the frames from the socket.

Thanks,
Alvin

Replace the unportable signal with sigaction

According to the Linux manpage signal(2) the function signal should not be used as its behaviour can vary across platforms. Currently glibc mimics the BSD behaviour which implicitly uses the flag SA_RESTART. This behaviour can be different when other libc are used. Instead of signal sigaction should be used.

Should candump show the frames sent while the device is not connected to the bus?

Hello. I'm using MPC2515 and it is not connected to a CAN bus.
I set up the network like so:
sudo ip link set can0 up type can bitrate 500000
When I send a frame with the following command,
cansend can0 000#DEADBEEF
candump can0 does not show it as an output.
But if I use the loopback on option when setting up can0, candump produces two outputs, which, I assume, correspond to the frame send and the frame received.

  can0  000   [4]  DE AD BE EF
  can0  000   [4]  DE AD BE EF

Is this behaviour normal?

Candump showing 29 bit ID's instead of 11 bit - can't replay codes

Trying to replay CAN codes for 2018 Dodge Promaster. From what I've read they use an 11 bit CAN ID. However when I use:

candump -L can0 > can.log

The log shows 29 bit ID's

(1519238827.107818) can0 04394100#00000000F0006000
(1519238827.122395) can0 063D4000#4652000080FE0000
(1519238827.126761) can0 04394000#000000AB
(1519238827.147822) can0 03029000#0000000000000000
(1519238827.152676) can0 06254000#00FFFF00FFFFFF00
(1519238827.157823) can0 03029100#0000000000000000
(1519238827.207842) can0 04394100#00000000F0006000
(1519238827.222727) can0 06314000#0000000000000000
(1519238827.226953) can0 04394000#000000AB
(1519238827.244633) can0 0E094000#001A00000409
(1519238827.247843) can0 03029000#0000000000000000
(1519238827.249614) can0 0E094003#001A
(1519238827.251375) can0 0E094020#000A
(1519238827.253121) can0 0E09400A#001A
(1519238827.254935) can0 0621400A#0000
(1519238827.257940) can0 03029100#0000000000000000
(1519238827.262128) can0 06314020#100000BC

I'm thinking this is why replaying with canplayer is not working. Does anyone know how I can force candump to use 11 bit ID's?

Detect Error frames with SocketCAN BCM

Hello,

I am trying to set up a C++ CAN system using SocketCAN BCM. While I can successfully detect data frames, I can't detect error frames.

My method to read an incoming frame has the following code:

// ...
typedef struct {
        struct bcm_msg_head head;
        struct can_frame frame;
 } rx_bcm_msg;

while(true) {
        rx_bcm_msg bcm_frame;
        int bytesReceived = ::read(rxSocket_, &bcm_frame, sizeof(bcm_frame));

        if(bytesReceived <= 0)
                break;   

        cout << frame.head.can_id & CAN_ERR_FLAG << endl;
        cout << frame.frame.can_id & CAN_ERR_FLAG << endl;

        // ...
}

// ...

For my tests, there are no incoming or written can frames apart from the eventual error frames.
Using a VCAN interface named vcan0, I try to activate a bus error by doing:

> sudo ip link set vcan0 down

When doing so, I detect an incoming frame from the BCM but the output of the program is:

0
0

How can I detect error frames with BCM ?
Best regards.

lib.h -- please utilize pointer to const

Hi,

thanks for your nice library!

Please could the following function prototypes be changed, to have the bold const shown below:

  • void snprintf_can_error_frame(char *buf, size_t len,conststruct canfd_frame *cf,constchar* sep) (ref)
  • static int snprintf_error_lostarb(char *buf, size_t len,conststruct canfd_frame *cf) (ref)
  • static int snprintf_error_ctrl(char *buf, size_t len,conststruct canfd_frame *cf) (ref)
  • static int snprintf_error_prot(char *buf, size_t len,conststruct canfd_frame *cf) (ref)

Reason: I'm using compiler warnings, and my compile is tripping up.

Here's a patch (should work if you do: git apply patchfile)

patchfile

diff --git a/lib.c b/lib.c
index 973be52..fe18e0f 100644
--- a/lib.c
+++ b/lib.c
@@ -519,14 +519,14 @@ static int snprintf_error_data(char *buf, size_t len, uint8_t err,
    return n;
 }

-static int snprintf_error_lostarb(char *buf, size_t len, struct canfd_frame *cf)
+static int snprintf_error_lostarb(char *buf, size_t len, const struct canfd_frame *cf)
 {
    if (len <= 0)
        return 0;
    return snprintf(buf, len, "{at bit %d}", cf->data[0]);
 }

-static int snprintf_error_ctrl(char *buf, size_t len, struct canfd_frame *cf)
+static int snprintf_error_ctrl(char *buf, size_t len, const struct canfd_frame *cf)
 {
    int n = 0;

@@ -542,7 +542,7 @@ static int snprintf_error_ctrl(char *buf, size_t len, struct canfd_frame *cf)
    return n;
 }

-static int snprintf_error_prot(char *buf, size_t len, struct canfd_frame *cf)
+static int snprintf_error_prot(char *buf, size_t len, const struct canfd_frame *cf)
 {
    int n = 0;

@@ -563,8 +563,8 @@ static int snprintf_error_prot(char *buf, size_t len, struct canfd_frame *cf)
    return n;
 }

-void snprintf_can_error_frame(char *buf, size_t len, struct canfd_frame *cf,
-                 char* sep)
+void snprintf_can_error_frame(char *buf, size_t len, const struct canfd_frame *cf,
+                  const char* sep)
 {
    canid_t class, mask;
    int i, n = 0, classes = 0;
diff --git a/lib.h b/lib.h
index 4f73743..36c3a09 100644
--- a/lib.h
+++ b/lib.h
@@ -203,8 +203,8 @@ void sprint_long_canframe(char *buf , struct canfd_frame *cf, int view, int maxd
  *
  */

-void snprintf_can_error_frame(char *buf, size_t len, struct canfd_frame *cf,
-                 char *sep);
+void snprintf_can_error_frame(char *buf, size_t len, const struct canfd_frame *cf,
+                  const char *sep);
 /*
  * Creates a CAN error frame output in user readable format.
  */

Thanks.

[Question] Unsupported can bus speeds

Hi,

I currently try to communicate to a lowspeed can bus with a speed of 33kbps. Is there any way to start slcandwith that speed? Is there any workaround?

Thanks
Benjamin

AutoGen.sh not found

Hi,

When I try to generate the auto config I am getting this message:

autoreconf

./autogen.sh: line 20: autoreconf: command not found

viki@c3po:~/Downloads/can-utils$ ./autogen.sh

autoreconf

./autogen.sh: line 20: autoreconf: command not found

canfdtest utility bug

canfdtest utility is using gettimeofday call to inject a 3msec delay in a tight loop. This is buggy for many reasons

  • gettimeofday usage on systems running ntpd can cause jumps

  • the tight loop logic also needs fixing. Why not use millisleep?

                            gettimeofday(&tvn, NULL);
                            while ((tv_stop.tv_sec > tvn.tv_sec) ||
                                   ((tv_stop.tv_sec = tvn.tv_sec) &&
                                    (tv_stop.tv_usec >= tvn.tv_usec)))
                                    gettimeofday(&tvn, NULL);
    

For e.g. if tv_stop.tv_usec is 999999 and tv_usec is also 999999, the code enters the loop again and calls gettimeofday. The only way we can come of the loop is when tv_usec is 0 or more, which means the tv_sec is incremented => infinite loop. This is what happening in my system

bcmserver: long interface name

I've tring to use bcmserver with long interface name over 10 character, but it didn't work well.
I found a code looks like a bug in bcmserver.c.

285 items = sscanf(buf, "< %6s %c %lu %lu %x %hhu "
286 "%hhx %hhx %hhx %hhx %hhx %hhx "
287 "%hhx %hhx >",
288 ifr.ifr_name,
289 &cmd,
290 &msg.msg_head.ival2.tv_sec,

In the <if.h>, IFNAMSIZ is defined as 16. so I think if_name size would be 15.
Is the ifr_name size(6) is intended?

candump bridge issue, stops after 300 frames

I am running 3 Cantacts at a fully working car electronic from a VW Golf 7.
slcand, cansend and so on are fully working.
Now I want to create a bridge between two of the Cantacts them.
But if I ran candump can0 -b can1, it stops printing out the frames after exactly 300 Frames and freezes. I can not stop it than with Ctrl+C or Ctrl+D.

Do you have any Ideas why? In the code I cannot find a 300Frames limit.

FATAL: Module vcan not found

On my normal Ubuntu system. modprobe vcan works as expected. On my Chromebook the command gives me the following error:

modprobe: FATAL: Module vcan not found in directory /lib/modules/4.9.4-galliumos-braswell

Using can-utils with OBDLink SX cable

Hi folks!

I have realised that I can actually sniff raw CAN messages using OBDLink SX diagnostic cable and serial terminal. Could it be also done "can-utils"? I have tried so far, nothing worked. But I am not a Linux guy, maybe I did something wrong.

I like the way how "can-utils" works and just would like to be able filter the messages.

Thanks!

J1939

Im trying to use this at a tractor.
Why dont I get an output here?
Candump brings me an output.

cansend. Valgrind reports points to uninitialised byte(s) in bind call.

==7553== Syscall param socketcall.bind(my_addr.sa_data) points to uninitialised byte(s)
==7553==    at 0x4F420F7: bind (syscall-template.S:84)
==7553==    by 0x400CBA: ??? (in /usr/bin/cansend)
==7553==    by 0x4E5A82F: (below main) (libc-start.c:291)
==7553==  Address 0xffefffd12 is on thread 1's stack

The program still works fine but in my own project it was an issue and I fixed it by adding bzero(&addr,sizeof(struct sockaddr_can)); to zero out the struct. I tried to fork and add it myself but after doing that then running make and the command ./cansend vcan0 123#DEADBEEF I get the error message write: No such device or address. Still learning C so not to sure why it's the case but your repo has been a big help to me with my project.

Module vcan not found in directory /lib/modules

Hi,

Trying to set up a vcan using modprobe vcan but get the following error message:
modprobe: FATAL: Module vcan not found in directory /lib/modules/4.4.0-1020-aws

both "can" and "can_raw" both work but vcan keeps giving me this error.

Is there something I'm doing wrong, as I've followed the instructions but keep getting this issue.
Please let me know if you need any further info.

Thanks

canplayer error: No buffer space available

I've been working quite a bit with cansniffer, cangen and candump. I noticed that canplayer seems to have an issue when I try to replay a file. I almost always get:
sendto: No buffer space available

If I type a command like
canplayer -v <name_of_file> stdout=can0
It correctly plays the candump file on the screen but obviously is not sending it.

My initial reaction was that the microcontroller connected to the CAN bus (a STM32F205RGY6 120Mhz ARM Cortex M3) could not take that much data in its buffer size. To dispel this, I tried sending messages at a high rate with cangen and was able to send messages every 3 ms which is much faster rate than recorded messages from candump.

Any thoughts on how I can avoid this error?

slcand keeps running when underlying USB dongle is detached

When using slcand on a USB can dongle (providing a serial-over-USB device as /dev/ttyUSBx) and detaching that dongle slcand doesn't detect that event and keeps running.

As a way of detecting this I've replaced the sleep(1) call with select(readfds=[fd], timeout=1) and terminate when a read() call returns 0 (EOF). Considering that the underlying device is gone, resetting the line discipline and terminal properties isn't necessary anymore either.

Example solution:

/* The Big Loop */
while (slcand_running)
{
   /* Wait for one second or until the CAN dongle gets detached */
   struct pollfd fds = {
       .fd = fd,
       .events = 0 /* POLLHUP doesn't need to be selected as to-be-waited-for */,
   };
   const int retval = poll(&fds, 1, 1000);

    /* EOF on serial line: assume it's a USB serial device that got pulled out and terminate. */
   if (retval > 0
     && (fds.revents & POLLHUP))
   {
       syslog(LOG_NOTICE, "terminated on %s due to EOF", ttypath);
       exit(EXIT_SUCCESS);
   }
}

This works because the file descriptor's function-table gets replaced with hung_up_tty_fops as seen in https://github.com/torvalds/linux/blob/d1d3a0f7448fe038ce7e94e2c281dcd2f91b23c6/drivers/tty/tty_io.c#L722 . That always returns POLLHUP | POLLERR and the selected event bits (we don't care about any other), that's why we don't select them.

PS Shouldn't the global slcand_running be volatile?

canplayer issue with wlan

Hello

I'm having an issue with canplayer on my android.
I have a script that launch a canplayer on a log file with can frames on system boot.

When wlan0 is created from wpa_supplicant. The canplayer accelerates the file reading.

I don't know why wlan and canplayer enters on conflict.

Even when I start after a delay I have this problem.

AOSP impossible to get binary

Hello,

I'm trying to add canUtils into AOSP.
I have integrated the entire folder in the device tree and added the package to the device.mk
But I have no binary (cansend or canplayer) in the out directory.

Do you know why ?

Setting up an interface: bit rate is half of what I specify-MPC2515

I'm using a CAN module which uses MCP2515 controller with an 8 MHz external oscillator and TJA1050 transceiver. If I set up the interface with
sudo ip link set can0 up type can bitrate 1000000
the actual bit rate is 500 Kbps.
I have verified this in two ways.
1- When connecting the module to a 1 Mbps CAN bus, I couldn't sniff the messages with candump, and couldn't communicate with the node (which was a motor drive). Lowering the bitrate of drive to 500 Kbps solved the problem.
2- Connecting an oscilloscope to high (or low) pin coming out of the transceiver, length of each bit of a CAN frame was 2 microseconds, which corresponds to a baud rate of 500 Kbps.
I also repeated the second test with
sudo ip link set can0 up type can bitrate 500000
and transferring each bit would take 4 microseconds, i.e. baud rate of 250 Kbps

Question about timeout

Hi,
Not sure to ask the question in the good place, but I'm wondering if it's possible to define a timeout value for a CAN socket (as for a TCP/IP socket with SO_RCVTIMEO) for read operation.

Thank you.

warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

I am trying to install can-utils on Raspberry Pi. How to solve it?

pi@raspberrypi:~/can-utils $ make
CC lib.lo
CC canframelen.lo
CCLD libcan.la
CC asc2log.o
CCLD asc2log
CC bcmserver.o
CCLD bcmserver
CC can-calc-bit-timing.o
CCLD can-calc-bit-timing
CC canbusload.o
CCLD canbusload
CC candump.o
candump.c: In function ‘main’:
candump.c:692:21: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
tv = *(struct timeval *)CMSG_DATA(cmsg);
^
candump.c:694:7: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
dropcnt[i] = *(__u32 *)CMSG_DATA(cmsg);
^
CCLD candump
CC canfdtest.o
CCLD canfdtest
CC cangen.o
cangen.c: In function ‘main’:
cangen.c:404:4: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
(unsigned long)(&frame.data[0]) = random();
^
cangen.c:405:4: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
(unsigned long)(&frame.data[4]) = random();
^
CCLD cangen
CC cangw.o
CCLD cangw
CC canlogserver.o
CCLD canlogserver
CC canplayer.o
CCLD canplayer
CC cansend.o
CCLD cansend
CC cansniffer.o
cansniffer.c: In function ‘rx_setup’:
cansniffer.c:373:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
U64_DATA(&txmsg.frame) = (__u64) 0xFFFFFFFFFFFFFFFFULL;
^
cansniffer.c: In function ‘handle_keyb’:
cansniffer.c:481:4: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
U64_DATA(&sniftab[i].notch) = (__u64) 0;
^
cansniffer.c: In function ‘handle_bcm’:
cansniffer.c:521:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
U64_DATA(&sniftab[id].marker) |=
^
cansniffer.c:522:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
U64_DATA(&sniftab[id].current) ^ U64_DATA(&sniftab[id].last);
^
cansniffer.c:522:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
cansniffer.c: In function ‘handle_timeo’:
cansniffer.c:551:4: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
U64_DATA(&sniftab[i].notch) |= U64_DATA(&sniftab[i].marker);
^
cansniffer.c:551:4: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
cansniffer.c:572:9: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
U64_DATA(&sniftab[i].marker) = (__u64) 0;
^
cansniffer.c: In function ‘print_snifline’:
cansniffer.c:673:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
U64_DATA(&sniftab[id].marker) = (__u64) 0;
^
CCLD cansniffer
CC isotpdump.o
CCLD isotpdump
CC isotpperf.o
CCLD isotpperf
CC isotprecv.o
CCLD isotprecv
CC isotpsend.o
CCLD isotpsend
CC isotpserver.o
CCLD isotpserver
CC isotpsniffer.o
CCLD isotpsniffer
CC isotptun.o
CCLD isotptun
CC log2asc.o
CCLD log2asc
CC log2long.o
CCLD log2long
CC slcan_attach.o
CCLD slcan_attach
CC slcand.o
CCLD slcand
CC slcanpty.o
slcanpty.c: In function ‘pty2can’:
slcanpty.c:249:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
*(unsigned long long ) (&frame.data) = 0ULL; / clear data[] */
^
CCLD slcanpty

cannot install

Dear all
i am not install driver
i try run ./autogen.sh but found error

root@raspberrypi:~/can-utils# ./autogen.sh


autoreconf

./autogen.sh: line 20: autoreconf: command not found
root@raspberrypi:~/can-utils# ./autogen.sh

thank for help

CAN communication terminates replaying file using canplayer

I am trying to send CAN data recorded using candump on the vehicle's CAN bus using canplayer. This sometimes works while sometimes terminates the CAN communication.
Example: I recorded the data for turning the indicator on and then off. After replaying it the first time using canplayer, the entire communication stopped with no error displayed. Nothing was received using candump. After restarting the system, I could send the data using canplayer. This did turn on /off the indicators. I could do it 2 times. The third time I replayed the file using canplayer, the communication stopped again (nothing received using candump) and I had to again restart the system.
Am I missing something here? I have not terminated the CAN cable used to connect to my system as it is short (~50cm). Could this be the issue?

Android.mk Errors

I had to make the following patch in order to get can-utils to build inside the AOSP source tree.

diff --git a/Android.mk b/Android.mk
index 86557ae..fee085e 100644
--- a/Android.mk
+++ b/Android.mk
@@ -3,7 +3,11 @@ LOCAL_PATH := $(call my-dir)
 PRIVATE_LOCAL_CFLAGS := -O2 -g -W -Wall                \
                        -DSO_RXQ_OVFL=40        \
                        -DPF_CAN=29             \
-                       -DAF_CAN=PF_CAN
+                       -DAF_CAN=PF_CAN \
+            -Wno-error=unused-parameter \
+            -Wno-error=sign-compare \
+            -Wno-error=pointer-arith \
+            -Wno-error=address-of-packed-member
 
 #
 # canlib

I'm not sure if suppressing these is the right thing to do.
Wanted to check here submitting a PR.
I'd rather see this upstreamed (or the warnings fixed) than maintain a branch just for this.

Question: How can I automatically bring up CAN interface using netplan?

I apologize first as this is most likely the wrong place to ask my question but I can not find how to get in touch with socket CAN community.

I am wondering how I could use netplan to bring up and configure a CAN interface. Previously I was able to automate this using the '/etc/network/interfaces' file. As of ubuntu 17.10 this file is no longer used and I think I am supposed to use netplan now. However, I do not know how to detect CAN interface becoming available. Have you by any chance ran into this issue? I think soon a lot of people will hit this problem, especially after 18.04 LTS is released.

I appreciate any help!
https://askubuntu.com/questions/991623/how-to-automatically-bring-up-can-interface-in-ubuntu-17-10

This was my script that used to work:

$ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

allow-hotplug can0
iface can0 can static
    bitrate 250000
    up /sbin/ip link set $IFACE down
    up /sbin/ifconfig $IFACE txqueuelen 20000
    up /sbin/ip link set $IFACE type can bitrate 250000 restart-ms 10
    up /sbin/ip link set $IFACE up

installation fails

hi,
I am trying to install can-utils on Ubuntu 15.
when I insert the make install command it fails.
can anyone help me with this issue?

Can candump log from zero?

Hello,

I'm using can-utils and it works well.
The problem is I want to log the can data from zero timestamp
candump -tz can0 can show the can data from zero timestamp
But candump cannot log data from zero
I tried to type candump -tz -l can0, the timestamp still start from absolute
I saw the code and find that -tz will create a local variable: timeval diff, and log using tv.tv_sec, tv.tv_usec to fprintf the log file.
So the -tz will not work for logging.
Is there other way to achieve logging data from zero timestamp?

cansniffer filtering

Probably a dumb question but when running cansniffer on gmlan 33kbps its not displaying IDs that are larger than 3.

Example when running candump i get the below results, but when i run cansniffer it only displays the ones with three in this case 624# is there anyway for it to work with larger Id's ?

(1472971756.787337) can0 10210040#0000155900001582
(1472971756.797509) can0 10220040#0000000000000000
(1472971756.807138) can0 1022E040#A14665F561F050E6
(1472971756.817105) can0 10230040#232D4AC772C265D8
(1472971756.834293) can0 624#0020000000000000
(1472971756.837776) can0 1020C040#0600002A01
(1472971756.842273) can0 10B06060#00041E0700000223
(1472971756.846630) can0 10240040#83F67701003A0FE8
(1472971756.851280) can0 10400060#820801AAD4
(1472971756.854677) can0 102C0040#629E8C2A03
(1472971756.858994) can0 10ACE060#1EC0000000000000
(1472971756.863225) can0 102CA040#000008970800F101

canplayer does not parse timestamp as seconds from log file

After a lot of pain I discovered that canplayer does not parse a time in seconds from the log file. Instead it parses seconds and microseconds as integers with '.' as the seperator.

Using '.' as the separator in the timestamp is very misleading. I assumed that the timestamp was a single value in seconds. It lead to a lot of subtle errors when the timestamps I was feeding it were a floating point seconds with varying digits of precision.

Can we either change the separator so that it does not look like a single timestamp of seconds or parse the field as seconds.fractions_of_a_second?

Typo: "ist" instead of "is"

grep -rI " ist " can-utils
can-utils/cansend.c:			printf("CAN interface ist not CAN FD capable - sorry.\n");
can-utils/cangen.c:			printf("CAN interface ist not CAN FD capable - sorry.\n");

Reconsider final actions for program termination

I have taken another look at the end of the implementation for the function “main()”. I got the impression that only functions are called which should be usually performed by a regular program termination.
Thus I suggest to omit a bit of extra source code.

diff --git a/log2asc.c b/log2asc.c
index 8fb88a9..509897b 100644
--- a/log2asc.c
+++ b/log2asc.c
@@ -198,9 +198,6 @@ int main(int argc, char **argv)
                        fprintf(outfile, "\n");
                }
        }
-       fflush(outfile);
-       fclose(outfile);
-       fclose(infile);
 
        return 0;
 }

🔮 How do you think about to delete any unnecessary stuff also in other source files?

Compiling can-utils on Mac OSX El Capitan.

I've gotten quite far trying to compile can-utils on Mac OSX. I had to redefine typedefs and the location of socket.h for Mac OSX. I finally got stuck with the following error:

bcmserver.c:234:8: error: no member named 'ifr_ifindex' in 'struct ifreq'
                    ifr.ifr_ifindex = caddr.can_ifindex;
                    ~~~ ^
bcmserver.c:235:14: error: use of undeclared identifier 'SIOCGIFNAME'
                    ioctl(sc, SIOCGIFNAME, &ifr);
                              ^
bcmserver.c:344:19: error: use of undeclared identifier 'SIOCGIFINDEX'
                    if (!ioctl(sc, SIOCGIFINDEX, &ifr)) {
                                   ^
bcmserver.c:345:29: error: no member named 'ifr_ifindex' in 'struct ifreq'
                            caddr.can_ifindex = ifr.ifr_ifindex;

Any help would be greatly appreciated! I'll post my changes on my repo and would be really interested in your feedback.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.