Compare commits
7 Commits
887b93c31b
...
272646affc
| Author | SHA1 | Date |
|---|---|---|
|
|
272646affc | |
|
|
cbbe4b41ea | |
|
|
2da0c7e95e | |
|
|
1f038b3cd8 | |
|
|
392ccc970b | |
|
|
0cfff2e5da | |
|
|
1e2c8fea4c |
|
|
@ -1,4 +1,4 @@
|
||||||
cmake_minimum_required(VERSION 3.5)
|
cmake_minimum_required(VERSION 3.5...3.10)
|
||||||
|
|
||||||
project(can-utils LANGUAGES C)
|
project(can-utils LANGUAGES C)
|
||||||
|
|
||||||
|
|
|
||||||
14
asc2log.c
14
asc2log.c
|
|
@ -84,7 +84,7 @@ static void print_usage(char *prg)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prframe(FILE *file, struct timeval *tv, int dev,
|
static void prframe(FILE *file, struct timeval *tv, int dev,
|
||||||
cu_t *cf, char dir)
|
union cfu *cf, char dir)
|
||||||
{
|
{
|
||||||
static char abuf[BUFLEN];
|
static char abuf[BUFLEN];
|
||||||
|
|
||||||
|
|
@ -177,7 +177,7 @@ static void eval_can(char* buf, struct timeval *date_tvp, char timestamps,
|
||||||
cf.len = CAN_ERR_DLC;
|
cf.len = CAN_ERR_DLC;
|
||||||
|
|
||||||
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
|
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
|
||||||
prframe(outfile, &tv, interface, (cu_t *)&cf, NO_DIR);
|
prframe(outfile, &tv, interface, (union cfu *)&cf, NO_DIR);
|
||||||
fflush(outfile);
|
fflush(outfile);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -249,7 +249,7 @@ static void eval_can(char* buf, struct timeval *date_tvp, char timestamps,
|
||||||
cf.data[i] = data[i] & 0xFFU;
|
cf.data[i] = data[i] & 0xFFU;
|
||||||
|
|
||||||
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
|
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
|
||||||
prframe(outfile, &tv, interface, (cu_t *)&cf, dir[0]);
|
prframe(outfile, &tv, interface, (union cfu *)&cf, dir[0]);
|
||||||
fflush(outfile);
|
fflush(outfile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -374,7 +374,7 @@ static void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps,
|
||||||
}
|
}
|
||||||
|
|
||||||
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
|
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
|
||||||
prframe(outfile, &tv, interface, (cu_t *)&cf, dir[0]);
|
prframe(outfile, &tv, interface, (union cfu *)&cf, dir[0]);
|
||||||
fflush(outfile);
|
fflush(outfile);
|
||||||
|
|
||||||
/* No support for really strange CANFD ErrorFrames format m( */
|
/* No support for really strange CANFD ErrorFrames format m( */
|
||||||
|
|
@ -487,7 +487,7 @@ static void eval_canxl_cc(char* buf, struct timeval *date_tvp, char timestamps,
|
||||||
cf.len8_dlc = dlc;
|
cf.len8_dlc = dlc;
|
||||||
|
|
||||||
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
|
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
|
||||||
prframe(outfile, &tv, interface, (cu_t *)&cf, dir[0]);
|
prframe(outfile, &tv, interface, (union cfu *)&cf, dir[0]);
|
||||||
fflush(outfile);
|
fflush(outfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -594,7 +594,7 @@ static void eval_canxl_fd(char* buf, struct timeval *date_tvp, char timestamps,
|
||||||
cf.flags |= CANFD_ESI;
|
cf.flags |= CANFD_ESI;
|
||||||
|
|
||||||
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
|
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
|
||||||
prframe(outfile, &tv, interface, (cu_t *)&cf, dir[0]);
|
prframe(outfile, &tv, interface, (union cfu *)&cf, dir[0]);
|
||||||
fflush(outfile);
|
fflush(outfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -723,7 +723,7 @@ static void eval_canxl_xl(char* buf, struct timeval *date_tvp, char timestamps,
|
||||||
cf.flags |= CANXL_RRS;
|
cf.flags |= CANXL_RRS;
|
||||||
|
|
||||||
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
|
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
|
||||||
prframe(outfile, &tv, interface, (cu_t *)&cf, dir[0]);
|
prframe(outfile, &tv, interface, (union cfu *)&cf, dir[0]);
|
||||||
fflush(outfile);
|
fflush(outfile);
|
||||||
|
|
||||||
/* No support for CAN XL ErrorFrames */
|
/* No support for CAN XL ErrorFrames */
|
||||||
|
|
|
||||||
|
|
@ -342,7 +342,7 @@ int main(int argc, char **argv)
|
||||||
struct cmsghdr *cmsg;
|
struct cmsghdr *cmsg;
|
||||||
struct can_filter *rfilter;
|
struct can_filter *rfilter;
|
||||||
can_err_mask_t err_mask;
|
can_err_mask_t err_mask;
|
||||||
static cu_t cu; /* union for CAN CC/FD/XL frames */
|
static union cfu cu; /* union for CAN CC/FD/XL frames */
|
||||||
int nbytes, i;
|
int nbytes, i;
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
struct timespec ts, last_ts;
|
struct timespec ts, last_ts;
|
||||||
|
|
|
||||||
4
cangen.c
4
cangen.c
|
|
@ -299,7 +299,7 @@ static int setsockopt_txtime(int fd)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_send_one(int fd, cu_t *cu, size_t len, int timeout)
|
static int do_send_one(int fd, union cfu *cu, size_t len, int timeout)
|
||||||
{
|
{
|
||||||
uint8_t control[CMSG_SPACE(sizeof(uint64_t))] = { 0 };
|
uint8_t control[CMSG_SPACE(sizeof(uint64_t))] = { 0 };
|
||||||
struct iovec iov = {
|
struct iovec iov = {
|
||||||
|
|
@ -494,7 +494,7 @@ int main(int argc, char **argv)
|
||||||
struct can_raw_vcid_options vcid_opts = {
|
struct can_raw_vcid_options vcid_opts = {
|
||||||
.flags = CAN_RAW_XL_VCID_TX_PASS,
|
.flags = CAN_RAW_XL_VCID_TX_PASS,
|
||||||
};
|
};
|
||||||
static cu_t cu;
|
static union cfu cu;
|
||||||
int i;
|
int i;
|
||||||
struct ifreq ifr = { 0 };
|
struct ifreq ifr = { 0 };
|
||||||
const int enable_canfx = 1;
|
const int enable_canfx = 1;
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,7 @@ int main(int argc, char **argv)
|
||||||
.rx_vcid_mask = 0,
|
.rx_vcid_mask = 0,
|
||||||
};
|
};
|
||||||
struct can_filter rfilter;
|
struct can_filter rfilter;
|
||||||
static cu_t cu; /* union for CAN CC/FD/XL frames */
|
static union cfu cu; /* union for CAN CC/FD/XL frames */
|
||||||
const int canfx_on = 1;
|
const int canfx_on = 1;
|
||||||
int nbytes, i, j;
|
int nbytes, i, j;
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
|
|
|
||||||
|
|
@ -261,7 +261,7 @@ int main(int argc, char **argv)
|
||||||
struct can_raw_vcid_options vcid_opts = {
|
struct can_raw_vcid_options vcid_opts = {
|
||||||
.flags = CAN_RAW_XL_VCID_TX_PASS,
|
.flags = CAN_RAW_XL_VCID_TX_PASS,
|
||||||
};
|
};
|
||||||
static cu_t cu;
|
static union cfu cu;
|
||||||
static struct timeval today_tv, log_tv, last_log_tv, diff_tv;
|
static struct timeval today_tv, log_tv, last_log_tv, diff_tv;
|
||||||
struct timespec sleep_ts;
|
struct timespec sleep_ts;
|
||||||
int s; /* CAN_RAW socket */
|
int s; /* CAN_RAW socket */
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ int main(int argc, char **argv)
|
||||||
struct can_raw_vcid_options vcid_opts = {
|
struct can_raw_vcid_options vcid_opts = {
|
||||||
.flags = CAN_RAW_XL_VCID_TX_PASS,
|
.flags = CAN_RAW_XL_VCID_TX_PASS,
|
||||||
};
|
};
|
||||||
static cu_t cu;
|
static union cfu cu;
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
|
|
||||||
/* check command line options */
|
/* check command line options */
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@
|
||||||
#include <linux/can.h>
|
#include <linux/can.h>
|
||||||
#include <linux/can/isotp.h>
|
#include <linux/can/isotp.h>
|
||||||
#include <linux/sockios.h>
|
#include <linux/sockios.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#define NO_CAN_ID 0xFFFFFFFFU
|
#define NO_CAN_ID 0xFFFFFFFFU
|
||||||
|
|
||||||
|
|
@ -66,6 +67,8 @@
|
||||||
#define FORMAT_ASCII 2
|
#define FORMAT_ASCII 2
|
||||||
#define FORMAT_DEFAULT (FORMAT_ASCII | FORMAT_HEX)
|
#define FORMAT_DEFAULT (FORMAT_ASCII | FORMAT_HEX)
|
||||||
|
|
||||||
|
#define PDU_BUF_SIZE 4096
|
||||||
|
|
||||||
void print_usage(char *prg)
|
void print_usage(char *prg)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "\nUsage: %s [options] <CAN interface>\n", prg);
|
fprintf(stderr, "\nUsage: %s [options] <CAN interface>\n", prg);
|
||||||
|
|
@ -79,6 +82,7 @@ void print_usage(char *prg)
|
||||||
fprintf(stderr, " -f <format> (1 = HEX, 2 = ASCII, 3 = HEX & ASCII - default: %d)\n", FORMAT_DEFAULT);
|
fprintf(stderr, " -f <format> (1 = HEX, 2 = ASCII, 3 = HEX & ASCII - default: %d)\n", FORMAT_DEFAULT);
|
||||||
fprintf(stderr, " -L (set link layer options for CAN FD)\n");
|
fprintf(stderr, " -L (set link layer options for CAN FD)\n");
|
||||||
fprintf(stderr, " -h <len> (head: print only first <len> bytes)\n");
|
fprintf(stderr, " -h <len> (head: print only first <len> bytes)\n");
|
||||||
|
fprintf(stderr, " -i (ignore syscall errors to receive malformed PDUs)\n");
|
||||||
fprintf(stderr, "\nCAN IDs and addresses are given and expected in hexadecimal values.\n");
|
fprintf(stderr, "\nCAN IDs and addresses are given and expected in hexadecimal values.\n");
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
}
|
}
|
||||||
|
|
@ -189,15 +193,16 @@ int main(int argc, char **argv)
|
||||||
int head = 0;
|
int head = 0;
|
||||||
int timestamp = 0;
|
int timestamp = 0;
|
||||||
int format = FORMAT_DEFAULT;
|
int format = FORMAT_DEFAULT;
|
||||||
|
int ignore_errors = 0;
|
||||||
canid_t src = NO_CAN_ID;
|
canid_t src = NO_CAN_ID;
|
||||||
canid_t dst = NO_CAN_ID;
|
canid_t dst = NO_CAN_ID;
|
||||||
extern int optind, opterr, optopt;
|
extern int optind, opterr, optopt;
|
||||||
static struct timeval tv, last_tv;
|
static struct timeval tv, last_tv;
|
||||||
|
|
||||||
unsigned char buffer[4096];
|
unsigned char buffer[PDU_BUF_SIZE];
|
||||||
int nbytes;
|
int nbytes;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "s:d:x:X:h:ct:f:L?")) != -1) {
|
while ((opt = getopt(argc, argv, "s:d:x:X:h:ct:f:L?i")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 's':
|
case 's':
|
||||||
src = strtoul(optarg, NULL, 16);
|
src = strtoul(optarg, NULL, 16);
|
||||||
|
|
@ -249,6 +254,10 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'i':
|
||||||
|
ignore_errors = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
print_usage(basename(argv[0]));
|
print_usage(basename(argv[0]));
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -367,31 +376,37 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(s, &rdfs)) {
|
if (FD_ISSET(s, &rdfs)) {
|
||||||
nbytes = read(s, buffer, 4096);
|
nbytes = read(s, buffer, PDU_BUF_SIZE);
|
||||||
if (nbytes < 0) {
|
if (nbytes < 0) {
|
||||||
perror("read socket s");
|
perror("read socket s");
|
||||||
r = 1;
|
r = 1;
|
||||||
|
if(!ignore_errors)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (nbytes > 4095) {
|
if (nbytes > (PDU_BUF_SIZE - 1)) {
|
||||||
r = 1;
|
r = 1;
|
||||||
|
fprintf(stderr, "PDU length %d longer than PDU buffer: %s\n", nbytes, strerror(errno));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
if(nbytes > 0)
|
||||||
printbuf(buffer, nbytes, color?2:0, timestamp, format,
|
printbuf(buffer, nbytes, color?2:0, timestamp, format,
|
||||||
&tv, &last_tv, dst, s, if_name, head);
|
&tv, &last_tv, dst, s, if_name, head);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(t, &rdfs)) {
|
if (FD_ISSET(t, &rdfs)) {
|
||||||
nbytes = read(t, buffer, 4096);
|
nbytes = read(t, buffer, PDU_BUF_SIZE);
|
||||||
if (nbytes < 0) {
|
if (nbytes < 0) {
|
||||||
perror("read socket t");
|
perror("read socket t");
|
||||||
r = 1;
|
r = 1;
|
||||||
|
if(!ignore_errors)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (nbytes > 4095) {
|
if (nbytes > (PDU_BUF_SIZE - 1)) {
|
||||||
r = 1;
|
r = 1;
|
||||||
|
fprintf(stderr, "PDU length %d longer than PDU buffer: %s\n", nbytes, strerror(errno));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
if(nbytes > 0)
|
||||||
printbuf(buffer, nbytes, color?1:0, timestamp, format,
|
printbuf(buffer, nbytes, color?1:0, timestamp, format,
|
||||||
&tv, &last_tv, src, t, if_name, head);
|
&tv, &last_tv, src, t, if_name, head);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
6
lib.c
6
lib.c
|
|
@ -155,7 +155,7 @@ int hexstring2data(char *arg, unsigned char *data, int maxdlen)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_canframe(char *cs, cu_t *cu)
|
int parse_canframe(char *cs, union cfu *cu)
|
||||||
{
|
{
|
||||||
/* documentation see lib.h */
|
/* documentation see lib.h */
|
||||||
|
|
||||||
|
|
@ -309,7 +309,7 @@ int parse_canframe(char *cs, cu_t *cu)
|
||||||
return mtu;
|
return mtu;
|
||||||
}
|
}
|
||||||
|
|
||||||
int snprintf_canframe(char *buf, size_t size, cu_t *cu, int sep)
|
int snprintf_canframe(char *buf, size_t size, union cfu *cu, int sep)
|
||||||
{
|
{
|
||||||
/* documentation see lib.h */
|
/* documentation see lib.h */
|
||||||
|
|
||||||
|
|
@ -433,7 +433,7 @@ int snprintf_canframe(char *buf, size_t size, cu_t *cu, int sep)
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int snprintf_long_canframe(char *buf, size_t size, cu_t *cu, int view)
|
int snprintf_long_canframe(char *buf, size_t size, union cfu *cu, int view)
|
||||||
{
|
{
|
||||||
/* documentation see lib.h */
|
/* documentation see lib.h */
|
||||||
|
|
||||||
|
|
|
||||||
10
lib.h
10
lib.h
|
|
@ -59,11 +59,11 @@ static inline int pr_debug(const char* fmt, ...) {return 0;}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* CAN CC/FD/XL frame union */
|
/* CAN CC/FD/XL frame union */
|
||||||
typedef union {
|
union cfu {
|
||||||
struct can_frame cc;
|
struct can_frame cc;
|
||||||
struct canfd_frame fd;
|
struct canfd_frame fd;
|
||||||
struct canxl_frame xl;
|
struct canxl_frame xl;
|
||||||
} cu_t;
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The buffer size for ASCII CAN frame string representations
|
* The buffer size for ASCII CAN frame string representations
|
||||||
|
|
@ -110,7 +110,7 @@ int hexstring2data(char *arg, unsigned char *data, int maxdlen);
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int parse_canframe(char *cs, cu_t *cu);
|
int parse_canframe(char *cs, union cfu *cu);
|
||||||
/*
|
/*
|
||||||
* Transfers a valid ASCII string describing a CAN frame into the CAN union
|
* Transfers a valid ASCII string describing a CAN frame into the CAN union
|
||||||
* containing CAN CC/FD/XL structs.
|
* containing CAN CC/FD/XL structs.
|
||||||
|
|
@ -180,7 +180,7 @@ int parse_canframe(char *cs, cu_t *cu);
|
||||||
* - CAN FD frames do not have a RTR bit
|
* - CAN FD frames do not have a RTR bit
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int snprintf_canframe(char *buf, size_t size, cu_t *cu, int sep);
|
int snprintf_canframe(char *buf, size_t size, union cfu *cu, int sep);
|
||||||
/*
|
/*
|
||||||
* Creates a CAN frame hexadecimal output in compact format.
|
* Creates a CAN frame hexadecimal output in compact format.
|
||||||
* The CAN data[] is separated by '.' when sep != 0.
|
* The CAN data[] is separated by '.' when sep != 0.
|
||||||
|
|
@ -213,7 +213,7 @@ int snprintf_canframe(char *buf, size_t size, cu_t *cu, int sep);
|
||||||
|
|
||||||
#define SWAP_DELIMITER '`'
|
#define SWAP_DELIMITER '`'
|
||||||
|
|
||||||
int snprintf_long_canframe(char *buf, size_t size, cu_t *cu, int view);
|
int snprintf_long_canframe(char *buf, size_t size, union cfu *cu, int view);
|
||||||
/*
|
/*
|
||||||
* Creates a CAN frame hexadecimal output in user readable format.
|
* Creates a CAN frame hexadecimal output in user readable format.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,7 @@ static void canfd_asc(struct canfd_frame *cf, int devno, int mtu,
|
||||||
fprintf(outfile, " %8d %4d %8X 0 0 0 0 0", 130000, 130, flags);
|
fprintf(outfile, " %8d %4d %8X 0 0 0 0 0", 130000, 130, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void canxl_asc(cu_t *cu, int devno, int mtu,
|
static void canxl_asc(union cfu *cu, int devno, int mtu,
|
||||||
char *extra_info, FILE *outfile)
|
char *extra_info, FILE *outfile)
|
||||||
{
|
{
|
||||||
char id[10];
|
char id[10];
|
||||||
|
|
@ -314,7 +314,7 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
static char buf[BUFSZ], device[DEVSZ], afrbuf[AFRSZ], extra_info[EXTRASZ];
|
static char buf[BUFSZ], device[DEVSZ], afrbuf[AFRSZ], extra_info[EXTRASZ];
|
||||||
|
|
||||||
static cu_t cu;
|
static union cfu cu;
|
||||||
static struct timeval tv, start_tv;
|
static struct timeval tv, start_tv;
|
||||||
FILE *infile = stdin;
|
FILE *infile = stdin;
|
||||||
FILE *outfile = stdout;
|
FILE *outfile = stdout;
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
static char buf[BUFSZ], timestamp[TIMESZ], device[DEVSZ], afrbuf[AFRSZ];
|
static char buf[BUFSZ], timestamp[TIMESZ], device[DEVSZ], afrbuf[AFRSZ];
|
||||||
static cu_t cu;
|
static union cfu cu;
|
||||||
int mtu;
|
int mtu;
|
||||||
|
|
||||||
while (fgets(buf, BUFSZ-1, stdin)) {
|
while (fgets(buf, BUFSZ-1, stdin)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue