Compare commits
1 Commits
887b93c31b
...
dacd9da569
| Author | SHA1 | Date |
|---|---|---|
|
|
dacd9da569 |
|
|
@ -72,9 +72,6 @@
|
|||
#ifndef SO_TIMESTAMPING
|
||||
#define SO_TIMESTAMPING 37
|
||||
#endif
|
||||
#ifndef SCM_TIMESTAMPING
|
||||
#define SCM_TIMESTAMPING SO_TIMESTAMPING
|
||||
#endif
|
||||
|
||||
#define TIMESTAMPSZ 50 /* string 'absolute with date' requires max 49 bytes */
|
||||
|
||||
|
|
@ -810,13 +807,13 @@ int main(int argc, char **argv)
|
|||
for (cmsg = CMSG_FIRSTHDR(&msg);
|
||||
cmsg && (cmsg->cmsg_level == SOL_SOCKET);
|
||||
cmsg = CMSG_NXTHDR(&msg,cmsg)) {
|
||||
if (cmsg->cmsg_type == SCM_TIMESTAMP) {
|
||||
if (cmsg->cmsg_type == SO_TIMESTAMP) {
|
||||
struct timeval tv;
|
||||
memcpy(&tv, CMSG_DATA(cmsg), sizeof(tv));
|
||||
ts.tv_sec = tv.tv_sec;
|
||||
ts.tv_nsec = tv.tv_usec;
|
||||
ts.tv_nsec *= 1000;
|
||||
} else if (cmsg->cmsg_type == SCM_TIMESTAMPING) {
|
||||
} else if (cmsg->cmsg_type == SO_TIMESTAMPING) {
|
||||
struct timespec *stamp = (struct timespec *)CMSG_DATA(cmsg);
|
||||
|
||||
/*
|
||||
|
|
|
|||
110
cangen.c
110
cangen.c
|
|
@ -180,7 +180,7 @@ static void print_usage(char *prg)
|
|||
fprintf(stderr, " -X (generate CAN XL CAN frames)\n");
|
||||
fprintf(stderr, " -R (generate RTR frames)\n");
|
||||
fprintf(stderr, " -8 (allow DLC values greater then 8 for Classic CAN frames)\n");
|
||||
fprintf(stderr, " -m (mix CC [-e -R] FD [-f -b -E] XL [-X] on capable devices)\n");
|
||||
fprintf(stderr, " -m (mix -e -f -b -E -R -X frames)\n");
|
||||
fprintf(stderr, " -I <mode> (CAN ID generation mode - see below)\n");
|
||||
fprintf(stderr, " -L <mode> (CAN data length code (dlc) generation mode - see below)\n");
|
||||
fprintf(stderr, " -D <mode> (CAN data (payload) generation mode - see below)\n");
|
||||
|
|
@ -339,9 +339,10 @@ resend:
|
|||
nbytes = sendmsg(fd, &msg, 0);
|
||||
if (nbytes < 0) {
|
||||
ret = -errno;
|
||||
if (ret != -ENOBUFS)
|
||||
if (ret != -ENOBUFS) {
|
||||
perror("write");
|
||||
return ret;
|
||||
|
||||
}
|
||||
if (!ignore_enobufs && !timeout) {
|
||||
perror("write");
|
||||
return ret;
|
||||
|
|
@ -454,9 +455,6 @@ int main(int argc, char **argv)
|
|||
unsigned char extended = 0;
|
||||
unsigned char canfd = 0;
|
||||
unsigned char canxl = 0;
|
||||
unsigned char mixcc = 1; /* mix default */
|
||||
unsigned char mixfd = 1; /* mix default */
|
||||
unsigned char mixxl = 1; /* mix default */
|
||||
unsigned char brs = 0;
|
||||
unsigned char esi = 0;
|
||||
unsigned char mix = 0;
|
||||
|
|
@ -576,6 +574,7 @@ int main(int argc, char **argv)
|
|||
|
||||
case 'm':
|
||||
mix = 1;
|
||||
canfd = 1; /* to switch the socket into CAN FD mode */
|
||||
view |= CANLIB_VIEW_INDENT_SFF;
|
||||
break;
|
||||
|
||||
|
|
@ -778,32 +777,34 @@ int main(int argc, char **argv)
|
|||
&loopback, sizeof(loopback));
|
||||
}
|
||||
|
||||
/* get CAN netdevice MTU for frame type capabilities */
|
||||
if (canfd || canxl) {
|
||||
|
||||
/* check if the frame fits into the CAN netdevice */
|
||||
if (ioctl(s, SIOCGIFMTU, &ifr) < 0) {
|
||||
perror("SIOCGIFMTU");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* check CAN XL support */
|
||||
if (ifr.ifr_mtu < (int)CANXL_MIN_MTU) {
|
||||
mixxl = 0;
|
||||
if (canxl) {
|
||||
if (canfd) {
|
||||
/* ensure discrete CAN FD length values 0..8, 12, 16, 20, 24, 32, 64 */
|
||||
cu.fd.len = can_fd_dlc2len(can_fd_len2dlc(cu.fd.len));
|
||||
} else {
|
||||
/* limit fixed CAN XL data length to 64 */
|
||||
if (cu.fd.len > CANFD_MAX_DLEN)
|
||||
cu.fd.len = CANFD_MAX_DLEN;
|
||||
}
|
||||
|
||||
if (canxl && (ifr.ifr_mtu < (int)CANXL_MIN_MTU)) {
|
||||
printf("CAN interface not CAN XL capable - sorry.\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* check CAN FD support */
|
||||
if (ifr.ifr_mtu < (int)CANFD_MTU) {
|
||||
mixfd = 0;
|
||||
if (canfd) {
|
||||
if (canfd && (ifr.ifr_mtu < (int)CANFD_MTU)) {
|
||||
printf("CAN interface not CAN FD capable - sorry.\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* enable CAN FD on the socket */
|
||||
if (mixfd) {
|
||||
if (ifr.ifr_mtu == (int)CANFD_MTU) {
|
||||
/* interface is ok - try to switch the socket into CAN FD mode */
|
||||
if (setsockopt(s, SOL_CAN_RAW, CAN_RAW_FD_FRAMES,
|
||||
&enable_canfx, sizeof(enable_canfx))){
|
||||
|
|
@ -812,8 +813,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
/* enable CAN XL on the socket */
|
||||
if (mixxl) {
|
||||
if (ifr.ifr_mtu >= (int)CANXL_MIN_MTU) {
|
||||
/* interface is ok - try to switch the socket into CAN XL mode */
|
||||
if (setsockopt(s, SOL_CAN_RAW, CAN_RAW_XL_FRAMES,
|
||||
&enable_canfx, sizeof(enable_canfx))){
|
||||
|
|
@ -828,16 +828,6 @@ int main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
/* sanitize given values */
|
||||
if (canfd || canxl) {
|
||||
if (canfd) {
|
||||
/* ensure discrete CAN FD length values 0..8, 12, 16, 20, 24, 32, 64 */
|
||||
cu.fd.len = can_fd_dlc2len(can_fd_len2dlc(cu.fd.len));
|
||||
} else {
|
||||
/* limit fixed CAN XL data length to 64 */
|
||||
if (cu.fd.len > CANFD_MAX_DLEN)
|
||||
cu.fd.len = CANFD_MAX_DLEN;
|
||||
}
|
||||
} else {
|
||||
/* sanitize Classical CAN 2.0 frame length */
|
||||
if (len8_dlc) {
|
||||
|
|
@ -1050,31 +1040,8 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
ret = do_send_one(s, &cu, mtu, polltimeout);
|
||||
if ((ret == -EINVAL) && mix) {
|
||||
/* mix mode: disable unsupported CAN frame type */
|
||||
switch (mtu) {
|
||||
case CAN_MTU:
|
||||
mixcc = 0;
|
||||
break;
|
||||
case CANFD_MTU:
|
||||
mixfd = 0;
|
||||
break;
|
||||
case CANXL_MTU:
|
||||
mixxl = 0;
|
||||
break;
|
||||
default:
|
||||
printf ("mix mode: unknown MTU");
|
||||
if (ret)
|
||||
return 1;
|
||||
}
|
||||
if (!mixcc && !mixfd && !mixxl) {
|
||||
printf ("mix mode: no valid CAN frame types\n");
|
||||
return 1;
|
||||
}
|
||||
} else if (ret) {
|
||||
/* other error than -ENOBUFS and -EINVAL */
|
||||
perror("write");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (burst_sent_count >= burst_count)
|
||||
burst_sent_count = 0;
|
||||
|
|
@ -1115,41 +1082,18 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
if (mix) {
|
||||
canfd = 0;
|
||||
canxl = 0;
|
||||
i = random();
|
||||
extended = i & 1;
|
||||
if (mixfd) {
|
||||
canfd = i & 2;
|
||||
if (canfd) {
|
||||
brs = i & 4;
|
||||
esi = i & 8;
|
||||
}
|
||||
}
|
||||
if (mixxl) {
|
||||
if (mixfd)
|
||||
canxl = ((i & 96) == 96); /* 1/4 */
|
||||
else
|
||||
canxl = ((i & 32) == 32); /* 1/2 */
|
||||
}
|
||||
if (mixcc) {
|
||||
rtr_frame = ((i & 24) == 24); /* reduce RTR to 1/4 */
|
||||
} else {
|
||||
/* no CC frames allowed - CAN XL-only mode? */
|
||||
if (!canxl && !canfd) {
|
||||
/* force XL or FD frames */
|
||||
if (mixxl)
|
||||
canxl = 1;
|
||||
else if (mixfd) {
|
||||
canfd = 1;
|
||||
brs = i & 4;
|
||||
esi = i & 8;
|
||||
} else {
|
||||
printf ("mix mode: no valid CAN frame types\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* generate CAN XL traffic if the interface is capable */
|
||||
if (ifr.ifr_mtu >= (int)CANXL_MIN_MTU)
|
||||
canxl = ((i & 96) == 96);
|
||||
|
||||
rtr_frame = ((i & 24) == 24); /* reduce RTR frames to 1/4 */
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
12
j1939acd.c
12
j1939acd.c
|
|
@ -112,10 +112,10 @@ static struct {
|
|||
int sig_alrm;
|
||||
int sig_usr1;
|
||||
int state;
|
||||
#define STATE_INITIAL 0
|
||||
#define STATE_REQ_SENT 1
|
||||
#define STATE_REQ_PENDING 2 /* wait 1250 msec for first claim */
|
||||
#define STATE_OPERATIONAL 3
|
||||
#define STATE_INITIAL 0
|
||||
#define STATE_REQ_SENT 1
|
||||
#define STATE_REQ_PENDING 2 /* wait 1250 msec for first claim */
|
||||
#define STATE_OPERATIONAL 3
|
||||
} s = {
|
||||
.intf = default_intf,
|
||||
.ranges = default_range,
|
||||
|
|
@ -126,8 +126,8 @@ static struct {
|
|||
struct {
|
||||
uint64_t name;
|
||||
int flags;
|
||||
#define F_USE 0x01
|
||||
#define F_SEEN 0x02
|
||||
#define F_USE 0x01
|
||||
#define F_SEEN 0x02
|
||||
} addr[J1939_IDLE_ADDR /* =254 */];
|
||||
|
||||
/* lookup by name */
|
||||
|
|
|
|||
|
|
@ -68,9 +68,9 @@ static struct {
|
|||
int pkt_len;
|
||||
int priority;
|
||||
int defined;
|
||||
#define DEF_SRC 1
|
||||
#define DEF_DST 2
|
||||
#define DEF_PRIO 4
|
||||
#define DEF_SRC 1
|
||||
#define DEF_DST 2
|
||||
#define DEF_PRIO 4
|
||||
struct sockaddr_can src, dst;
|
||||
} s = {
|
||||
.priority = 6,
|
||||
|
|
|
|||
7
lib.c
7
lib.c
|
|
@ -83,8 +83,8 @@ static inline void _put_id(char *buf, int end_offset, canid_t id)
|
|||
|
||||
/* CAN DLC to real data length conversion helpers */
|
||||
|
||||
static const unsigned char dlc2len[] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64};
|
||||
static const unsigned char dlc2len[] = {0, 1, 2, 3, 4, 5, 6, 7,
|
||||
8, 12, 16, 20, 24, 32, 48, 64};
|
||||
|
||||
/* get data length from raw data length code (DLC) */
|
||||
unsigned char can_fd_dlc2len(unsigned char dlc)
|
||||
|
|
@ -92,8 +92,7 @@ unsigned char can_fd_dlc2len(unsigned char dlc)
|
|||
return dlc2len[dlc & 0x0F];
|
||||
}
|
||||
|
||||
static const unsigned char len2dlc[] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, /* 0 - 8 */
|
||||
static const unsigned char len2dlc[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, /* 0 - 8 */
|
||||
9, 9, 9, 9, /* 9 - 12 */
|
||||
10, 10, 10, 10, /* 13 - 16 */
|
||||
11, 11, 11, 11, /* 17 - 20 */
|
||||
|
|
|
|||
Loading…
Reference in New Issue