commit
53ea0d0218
2
Makefile
2
Makefile
|
|
@ -148,8 +148,8 @@ isobusfs_srv.o: libj1939.h lib.h
|
||||||
isobusfs_c.o: libj1939.h lib.h
|
isobusfs_c.o: libj1939.h lib.h
|
||||||
canframelen.o: canframelen.h
|
canframelen.o: canframelen.h
|
||||||
|
|
||||||
canbusload: canbusload.o canframelen.o
|
|
||||||
asc2log: asc2log.o lib.o
|
asc2log: asc2log.o lib.o
|
||||||
|
canbusload: canbusload.o canframelen.o
|
||||||
candump: candump.o lib.o
|
candump: candump.o lib.o
|
||||||
cangen: cangen.o lib.o
|
cangen: cangen.o lib.o
|
||||||
canlogserver: canlogserver.o lib.o
|
canlogserver: canlogserver.o lib.o
|
||||||
|
|
|
||||||
65
slcanpty.c
65
slcanpty.c
|
|
@ -50,8 +50,7 @@
|
||||||
#define DEVICE_NAME_PTMX "/dev/ptmx"
|
#define DEVICE_NAME_PTMX "/dev/ptmx"
|
||||||
|
|
||||||
/* read data from pty, send CAN frames to CAN socket and answer commands */
|
/* read data from pty, send CAN frames to CAN socket and answer commands */
|
||||||
int pty2can(int pty, int socket, struct can_filter *fi,
|
int pty2can(int pty, int socket, struct can_filter *fi, int *is_open, int *tstamp)
|
||||||
int *is_open, int *tstamp)
|
|
||||||
{
|
{
|
||||||
unsigned int nbytes;
|
unsigned int nbytes;
|
||||||
char cmd;
|
char cmd;
|
||||||
|
|
@ -137,7 +136,6 @@ rx_restart:
|
||||||
goto rx_out_ack;
|
goto rx_out_ack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* check for timestamp on/off command */
|
/* check for timestamp on/off command */
|
||||||
if (cmd == 'Z') {
|
if (cmd == 'Z') {
|
||||||
*tstamp = buf[1] & 0x01;
|
*tstamp = buf[1] & 0x01;
|
||||||
|
|
@ -147,9 +145,7 @@ rx_restart:
|
||||||
|
|
||||||
/* check for 'O'pen command */
|
/* check for 'O'pen command */
|
||||||
if (cmd == 'O') {
|
if (cmd == 'O') {
|
||||||
setsockopt(socket, SOL_CAN_RAW,
|
setsockopt(socket, SOL_CAN_RAW, CAN_RAW_FILTER, fi, sizeof(struct can_filter));
|
||||||
CAN_RAW_FILTER, fi,
|
|
||||||
sizeof(struct can_filter));
|
|
||||||
ptr = 1;
|
ptr = 1;
|
||||||
*is_open = 1;
|
*is_open = 1;
|
||||||
goto rx_out_ack;
|
goto rx_out_ack;
|
||||||
|
|
@ -157,8 +153,7 @@ rx_restart:
|
||||||
|
|
||||||
/* check for 'C'lose command */
|
/* check for 'C'lose command */
|
||||||
if (cmd == 'C') {
|
if (cmd == 'C') {
|
||||||
setsockopt(socket, SOL_CAN_RAW, CAN_RAW_FILTER,
|
setsockopt(socket, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
|
||||||
NULL, 0);
|
|
||||||
ptr = 1;
|
ptr = 1;
|
||||||
*is_open = 0;
|
*is_open = 0;
|
||||||
goto rx_out_ack;
|
goto rx_out_ack;
|
||||||
|
|
@ -221,8 +216,7 @@ rx_restart:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* catch unknown commands */
|
/* catch unknown commands */
|
||||||
if ((cmd != 't') && (cmd != 'T') &&
|
if ((cmd != 't') && (cmd != 'T') && (cmd != 'r') && (cmd != 'R')) {
|
||||||
(cmd != 'r') && (cmd != 'R')) {
|
|
||||||
ptr = nbytes - 1;
|
ptr = nbytes - 1;
|
||||||
goto rx_out_nack;
|
goto rx_out_nack;
|
||||||
}
|
}
|
||||||
|
|
@ -235,7 +229,6 @@ rx_restart:
|
||||||
memset(&frame.data, 0, 8); /* clear data[] */
|
memset(&frame.data, 0, 8); /* clear data[] */
|
||||||
|
|
||||||
if ((cmd | 0x20) == 'r' && buf[ptr] != '0') {
|
if ((cmd | 0x20) == 'r' && buf[ptr] != '0') {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RTR frame without dlc information!
|
* RTR frame without dlc information!
|
||||||
* This is against the SLCAN spec but sent
|
* This is against the SLCAN spec but sent
|
||||||
|
|
@ -258,7 +251,6 @@ rx_restart:
|
||||||
ptr--; /* we have no dlc component in the violation case */
|
ptr--; /* we have no dlc component in the violation case */
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (!(buf[ptr] >= '0' && buf[ptr] < '9'))
|
if (!(buf[ptr] >= '0' && buf[ptr] < '9'))
|
||||||
goto rx_out_nack;
|
goto rx_out_nack;
|
||||||
|
|
||||||
|
|
@ -275,7 +267,6 @@ rx_restart:
|
||||||
frame.can_id |= CAN_RTR_FLAG;
|
frame.can_id |= CAN_RTR_FLAG;
|
||||||
|
|
||||||
for (i = 0, ptr++; i < frame.can_dlc; i++) {
|
for (i = 0, ptr++; i < frame.can_dlc; i++) {
|
||||||
|
|
||||||
tmp = asc2nibble(buf[ptr++]);
|
tmp = asc2nibble(buf[ptr++]);
|
||||||
if (tmp > 0x0F)
|
if (tmp > 0x0F)
|
||||||
goto rx_out_nack;
|
goto rx_out_nack;
|
||||||
|
|
@ -344,19 +335,14 @@ int can2pty(int pty, int socket, int *tstamp)
|
||||||
cmd = 'T'; /* becomes 't' in SFF format */
|
cmd = 'T'; /* becomes 't' in SFF format */
|
||||||
|
|
||||||
if (frame.can_id & CAN_EFF_FLAG)
|
if (frame.can_id & CAN_EFF_FLAG)
|
||||||
sprintf(buf, "%c%08X%d", cmd,
|
sprintf(buf, "%c%08X%d", cmd, frame.can_id & CAN_EFF_MASK, frame.can_dlc);
|
||||||
frame.can_id & CAN_EFF_MASK,
|
|
||||||
frame.can_dlc);
|
|
||||||
else
|
else
|
||||||
sprintf(buf, "%c%03X%d", cmd | 0x20,
|
sprintf(buf, "%c%03X%d", cmd | 0x20, frame.can_id & CAN_SFF_MASK, frame.can_dlc);
|
||||||
frame.can_id & CAN_SFF_MASK,
|
|
||||||
frame.can_dlc);
|
|
||||||
|
|
||||||
ptr = strlen(buf);
|
ptr = strlen(buf);
|
||||||
|
|
||||||
for (i = 0; i < frame.can_dlc; i++)
|
for (i = 0; i < frame.can_dlc; i++)
|
||||||
sprintf(&buf[ptr + 2*i], "%02X",
|
sprintf(&buf[ptr + 2 * i], "%02X", frame.data[i]);
|
||||||
frame.data[i]);
|
|
||||||
|
|
||||||
if (*tstamp) {
|
if (*tstamp) {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
@ -401,6 +387,24 @@ int check_select_stdin(void)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void print_usage(const char *prg)
|
||||||
|
{
|
||||||
|
fprintf(stderr,
|
||||||
|
"%s: adapter for applications using the slcan ASCII protocol.\n"
|
||||||
|
"\n"
|
||||||
|
"%s creates a pty for applications using the slcan ASCII protocol and\n"
|
||||||
|
"converts the ASCII data to a CAN network interface (and vice versa)\n"
|
||||||
|
"\n"
|
||||||
|
"Usage: %s <pty> <can interface>\n"
|
||||||
|
"\n"
|
||||||
|
"Examples:\n"
|
||||||
|
"%s /dev/ptyc0 can0 - creates /dev/ttyc0 for the slcan application\n"
|
||||||
|
"\n"
|
||||||
|
"e.g. for pseudo-terminal '%s %s can0' creates /dev/pts/N\n"
|
||||||
|
"\n",
|
||||||
|
prg, prg, prg, prg, prg, DEVICE_NAME_PTMX);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
fd_set rdfs;
|
fd_set rdfs;
|
||||||
|
|
@ -416,19 +420,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
/* check command line options */
|
/* check command line options */
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
fprintf(stderr, "%s: adapter for applications using"
|
print_usage(basename(argv[0]));
|
||||||
" the slcan ASCII protocol.\n", basename(argv[0]));
|
|
||||||
fprintf(stderr, "\n%s creates a pty for applications using"
|
|
||||||
" the slcan ASCII protocol and\n", basename(argv[0]));
|
|
||||||
fprintf(stderr, "converts the ASCII data to a CAN network"
|
|
||||||
" interface (and vice versa)\n\n");
|
|
||||||
fprintf(stderr, "Usage: %s <pty> <can interface>\n", basename(argv[0]));
|
|
||||||
fprintf(stderr, "\nExamples:\n");
|
|
||||||
fprintf(stderr, "%s /dev/ptyc0 can0 - creates /dev/ttyc0 for the slcan application\n\n",
|
|
||||||
basename(argv[0]));
|
|
||||||
fprintf(stderr, "e.g. for pseudo-terminal '%s %s can0' creates"
|
|
||||||
" /dev/pts/N\n", basename(argv[0]), DEVICE_NAME_PTMX);
|
|
||||||
fprintf(stderr, "\n");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -447,15 +439,13 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* disable local echo which would cause double frames */
|
/* disable local echo which would cause double frames */
|
||||||
topts.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK |
|
topts.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE);
|
||||||
ECHONL | ECHOPRT | ECHOKE);
|
|
||||||
topts.c_iflag &= ~(ICRNL);
|
topts.c_iflag &= ~(ICRNL);
|
||||||
topts.c_iflag |= INLCR;
|
topts.c_iflag |= INLCR;
|
||||||
tcsetattr(p, TCSANOW, &topts);
|
tcsetattr(p, TCSANOW, &topts);
|
||||||
|
|
||||||
/* Support for the Unix 98 pseudo-terminal interface /dev/ptmx /dev/pts/N */
|
/* Support for the Unix 98 pseudo-terminal interface /dev/ptmx /dev/pts/N */
|
||||||
if (strcmp(argv[1], DEVICE_NAME_PTMX) == 0) {
|
if (strcmp(argv[1], DEVICE_NAME_PTMX) == 0) {
|
||||||
|
|
||||||
char *name_pts = NULL; /* slave pseudo-terminal device name */
|
char *name_pts = NULL; /* slave pseudo-terminal device name */
|
||||||
|
|
||||||
if (grantpt(p) < 0) {
|
if (grantpt(p) < 0) {
|
||||||
|
|
@ -503,7 +493,6 @@ int main(int argc, char **argv)
|
||||||
fi.can_mask = 0;
|
fi.can_mask = 0;
|
||||||
|
|
||||||
while (running) {
|
while (running) {
|
||||||
|
|
||||||
FD_ZERO(&rdfs);
|
FD_ZERO(&rdfs);
|
||||||
|
|
||||||
if (select_stdin)
|
if (select_stdin)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue