]> rtime.felk.cvut.cz Git - sojka/can-utils.git/commitdiff
Added timestamp handling with Z0 or Z1 command.
authorOliver Hartkopp <socketcan@hartkopp.net>
Tue, 3 Feb 2009 11:59:53 +0000 (11:59 +0000)
committerOliver Hartkopp <socketcan@hartkopp.net>
Tue, 3 Feb 2009 11:59:53 +0000 (11:59 +0000)
slcanpty.c

index 07a05562a0c087b228c96364f3cdac962d0d3b76..4e4d8fa901ce8ada284df5986cb37b7b4cf74c57 100644 (file)
@@ -69,6 +69,7 @@ int main(int argc, char **argv)
        struct termios topts;
        struct ifreq ifr;
        int running = 1;
+       int tstamp = 0;
        char txcmd, rxcmd;
        char txbuf[SLC_MTU];
        char rxbuf[SLC_MTU];
@@ -179,6 +180,13 @@ int main(int argc, char **argv)
                                        setsockopt(s, SOL_CAN_RAW,
                                                   CAN_RAW_FILTER, &fi,
                                                   sizeof(struct can_filter));
+                               continue;
+                       }
+
+                       /* check for timestamp on/off command */
+                       if (rxcmd == 'Z') {
+                               tstamp = rxbuf[1] & 0x01;
+                               continue;
                        }
 
                        if ((rxcmd != 't') && (rxcmd != 'T') &&
@@ -255,6 +263,16 @@ int main(int argc, char **argv)
                                sprintf(&txbuf[txp + 2*i], "%02X",
                                        txf.data[i]);
 
+                       if (tstamp) {
+                               struct timeval tv;
+
+                               if (ioctl(s, SIOCGSTAMP, &tv) < 0)
+                                       perror("SIOCGSTAMP");
+
+                               sprintf(&txbuf[txp + 2*txf.can_dlc], "%04lX",
+                                       (tv.tv_sec%60)*1000 + tv.tv_usec/1000);
+                       }
+
                        strcat(txbuf, "\r"); /* add terminating character */
                        nbytes = write(p, txbuf, strlen(txbuf));
                        if (nbytes < 0) {