Added timestamp handling with Z0 or Z1 command.

pull/7/head
Oliver Hartkopp 2009-02-03 11:59:53 +00:00
parent baa90a135a
commit af858087e6
1 changed files with 18 additions and 0 deletions

View File

@ -69,6 +69,7 @@ int main(int argc, char **argv)
struct termios topts; struct termios topts;
struct ifreq ifr; struct ifreq ifr;
int running = 1; int running = 1;
int tstamp = 0;
char txcmd, rxcmd; char txcmd, rxcmd;
char txbuf[SLC_MTU]; char txbuf[SLC_MTU];
char rxbuf[SLC_MTU]; char rxbuf[SLC_MTU];
@ -179,6 +180,13 @@ int main(int argc, char **argv)
setsockopt(s, SOL_CAN_RAW, setsockopt(s, SOL_CAN_RAW,
CAN_RAW_FILTER, &fi, CAN_RAW_FILTER, &fi,
sizeof(struct can_filter)); sizeof(struct can_filter));
continue;
}
/* check for timestamp on/off command */
if (rxcmd == 'Z') {
tstamp = rxbuf[1] & 0x01;
continue;
} }
if ((rxcmd != 't') && (rxcmd != 'T') && if ((rxcmd != 't') && (rxcmd != 'T') &&
@ -255,6 +263,16 @@ int main(int argc, char **argv)
sprintf(&txbuf[txp + 2*i], "%02X", sprintf(&txbuf[txp + 2*i], "%02X",
txf.data[i]); 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 */ strcat(txbuf, "\r"); /* add terminating character */
nbytes = write(p, txbuf, strlen(txbuf)); nbytes = write(p, txbuf, strlen(txbuf));
if (nbytes < 0) { if (nbytes < 0) {