]> rtime.felk.cvut.cz Git - socketcan-devel.git/commitdiff
Added information how to obtain timestamps as suggested by
authorhartkopp <hartkopp@030b6a49-0b11-0410-94ab-b0dab22257f2>
Thu, 30 Sep 2010 12:51:54 +0000 (12:51 +0000)
committerhartkopp <hartkopp@030b6a49-0b11-0410-94ab-b0dab22257f2>
Thu, 30 Sep 2010 12:51:54 +0000 (12:51 +0000)
Daniele Venzano <venza@brownhat.org>. Extended the possibility
to get timestamps via recvmsg().

git-svn-id: svn://svn.berlios.de//socketcan/trunk@1198 030b6a49-0b11-0410-94ab-b0dab22257f2

kernel/2.6/Documentation/networking/can.txt

index 6cd6627c3293ded2cf0d97ea1f3be4886182d223..33fa6f9cea0c2652038cbbdc90974a0bb333f85a 100644 (file)
@@ -25,6 +25,7 @@ This file contains
     4.2 Broadcast Manager protocol sockets (SOCK_DGRAM)
     4.3 connected transport protocols (SOCK_SEQPACKET)
     4.4 unconnected transport protocols (SOCK_DGRAM)
+    4.5 Timestamps
 
   5 Socket CAN core module
     5.1 can.ko module params
@@ -334,7 +335,7 @@ solution for a couple of reasons:
             return 1;
     }
 
-    /* paraniod check ... */
+    /* paranoid check ... */
     if (nbytes < sizeof(struct can_frame)) {
             fprintf(stderr, "read: incomplete CAN frame\n");
             return 1;
@@ -475,6 +476,27 @@ solution for a couple of reasons:
   4.3 connected transport protocols (SOCK_SEQPACKET)
   4.4 unconnected transport protocols (SOCK_DGRAM)
 
+  4.5 Timestamps
+  
+  For applications in the CAN environment it is often of interest an
+  accurate timestamp of the instant a message from CAN bus has been received.
+  Such a timestamp can be read with ioctl(2) after reading a message from
+  the socket. Example:
+
+    struct timeval tv;
+    ioctl(s, SIOCGSTAMP, &tv);
+
+  The timestamp on Linux has a resolution of one microsecond and it is set
+  automatically at the reception of a CAN frame.
+
+  Alternatively the timestamp can be obtained as a control message (cmsg) using
+  the recvmsg() system call. After enabling the timestamps in the cmsg's by
+
+    const int timestamp = 1;
+    setsockopt(s, SOL_SOCKET, SO_TIMESTAMP, &timestamp, sizeof(timestamp));  
+
+  the data structures filled by recvmsg() need to be parsed for
+  cmsg->cmsg_type == SO_TIMESTAMP to get the timestamp. See cmsg() manpage.
 
 5. Socket CAN core module
 -------------------------