Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAN arrival timestamps not conveyed #39

Open
olowo726 opened this issue Apr 27, 2022 · 3 comments
Open

CAN arrival timestamps not conveyed #39

olowo726 opened this issue Apr 27, 2022 · 3 comments
Labels
cannelloni_v2 Feature for a new protocol version

Comments

@olowo726
Copy link

Our application uses the timestamps from when frames arrive (setsocketopt with SO_TIMESTAMPING). This seems to not be implemented. For us it would be great if it was.

@mguentner
Copy link
Owner

Can you please go into detail how this could work? Please also see #34

@olowo726
Copy link
Author

I don't know enough about the Linux kernel to understand how It could be implemented.

Our code for reading CAN frames via SocketCAN looks roughly like

    const int nbytes = recvmsg(s, &rxMsg, 0);

    if (nbytes > 0)
    {
        // frame received
        *frameId = frame.can_id;
        *numRecievedBytes = frame.can_dlc;
        memcpy(data, frame.data, std::min(static_cast<size_t>(datalen), sizeof(frame.data)));
        bool timestampValid = false;
        for (rxCmsg = CMSG_FIRSTHDR(&rxMsg); rxCmsg && (rxCmsg->cmsg_level == SOL_SOCKET); rxCmsg = CMSG_NXTHDR(&rxMsg,rxCmsg))
        {
            if (rxCmsg->cmsg_type == SO_TIMESTAMPING)
            {
                struct timespec *stamp = (struct timespec *)CMSG_DATA(rxCmsg);
                *timestamp = stamp[2].tv_sec * 1000000U + stamp[2].tv_nsec/1000;
                timestampValid = true;
                break;
            }
        }

It would be great if the actual timestamp recorded on the actual physical CAN device was delivered to the listener so that it can be read the same way as you would do with a normal SocketCAN.

@mguentner
Copy link
Owner

Probably there is no easy way to do this in userspace as you would need to overwrite the time the kernel at which the kernel received the packet. If you find a way to do that, the timestamp could be added to the protocol with some effort.

@mguentner mguentner added the cannelloni_v2 Feature for a new protocol version label Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cannelloni_v2 Feature for a new protocol version
Projects
None yet
Development

No branches or pull requests

2 participants