/*
- * $Id$
- */
-
-/*
* canlogserver.c
*
* Copyright (c) 2002-2007 Volkswagen Group Electronic Research
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
- * Send feedback to <socketcan-users@lists.berlios.de>
+ * Send feedback to <linux-can@vger.kernel.org>
*
*/
#include <time.h>
#include <sys/time.h>
+#include <sys/wait.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <linux/can.h>
#include <linux/can/raw.h>
#include <signal.h>
-#include <wait.h>
#include <errno.h>
#include "lib.h"
#define ANYDEV "any"
#define ANL "\r\n" /* newline in ASC mode */
+#define COMMENTSZ 200
+#define BUFSZ (sizeof("(1345212884.318850)") + IFNAMSIZ + 4 + CL_CFSZ + COMMENTSZ) /* for one line in the logfile */
+
#define DEFPORT 28700
static char devname[MAXDEV][IFNAMSIZ+1];
fprintf(stderr, " <received_can_id> & mask == value & mask\n");
fprintf(stderr, "\n");
fprintf(stderr, "When using more than one CAN interface the options\n");
- fprintf(stderr, "m/v/i/e have comma seperated values e.g. '-m 0,7FF,0'\n");
+ fprintf(stderr, "m/v/i/e have comma separated values e.g. '-m 0,7FF,0'\n");
fprintf(stderr, "\nUse interface name '%s' to receive from all CAN interfaces.\n\n", ANYDEV);
}
int currmax = 1; /* we assume at least one can bus ;-) */
struct sockaddr_can addr;
struct can_filter rfilter;
- struct can_frame frame;
- int nbytes, i, j;
+ struct canfd_frame frame;
+ const int canfd_on = 1;
+ int nbytes, i, j, maxdlen;
struct ifreq ifr;
- struct timeval tv, last_tv;
+ struct timeval tv;
int port = DEFPORT;
struct sockaddr_in inaddr;
struct sockaddr_in clientaddr;
socklen_t sin_size = sizeof(clientaddr);
- char temp[128];
+ char temp[BUFSZ];
sigemptyset(&sigset);
signalaction.sa_handler = &childdied;
sigaction(SIGTERM, &signalaction, NULL); /* install Signal for termination */
sigaction(SIGINT, &signalaction, NULL); /* install Signal for termination */
-
- last_tv.tv_sec = 0;
- last_tv.tv_usec = 0;
-
while ((opt = getopt(argc, argv, "m:v:i:e:p:?")) != -1) {
switch (opt) {
setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_ERR_FILTER,
&err_mask[i], sizeof(err_mask[i]));
+ /* try to switch the socket into CAN FD mode */
+ setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &canfd_on, sizeof(canfd_on));
+
j = strlen(argv[optind+i]);
if (!(j < IFNAMSIZ)) {
socklen_t len = sizeof(addr);
int idx;
- if ((nbytes = recvfrom(s[i], &frame,
- sizeof(struct can_frame), 0,
+ if ((nbytes = recvfrom(s[i], &frame, CANFD_MTU, 0,
(struct sockaddr*)&addr, &len)) < 0) {
perror("read");
return 1;
}
- if (nbytes < sizeof(struct can_frame)) {
+ if ((size_t)nbytes == CAN_MTU)
+ maxdlen = CAN_MAX_DLEN;
+ else if ((size_t)nbytes == CANFD_MTU)
+ maxdlen = CANFD_MAX_DLEN;
+ else {
fprintf(stderr, "read: incomplete CAN frame\n");
return 1;
}
sprintf(temp, "(%ld.%06ld) %*s ",
tv.tv_sec, tv.tv_usec, max_devname_len, devname[idx]);
- sprint_canframe(temp+strlen(temp), &frame, 0);
+ sprint_canframe(temp+strlen(temp), &frame, 0, maxdlen);
strcat(temp, "\n");
if (write(accsocket, temp, strlen(temp)) < 0) {
return 1;
}
- /* printf("%s\n",temp2); */
-
#if 0
/* print CAN frame in log file style to stdout */
printf("(%ld.%06ld) ", tv.tv_sec, tv.tv_usec);
printf("%*s ", max_devname_len, devname[idx]);
- fprint_canframe(stdout, &frame, "\n", 0);
+ fprint_canframe(stdout, &frame, "\n", 0, maxdlen);
#endif
}