log: finalize unified buffer handling
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>pull/504/head
parent
1da219922d
commit
29290505f7
|
|
@ -72,9 +72,6 @@
|
||||||
#define ANYDEV "any"
|
#define ANYDEV "any"
|
||||||
#define ANL "\r\n" /* newline in ASC mode */
|
#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
|
#define DEFPORT 28700
|
||||||
|
|
||||||
static char devname[MAXDEV][IFNAMSIZ+1];
|
static char devname[MAXDEV][IFNAMSIZ+1];
|
||||||
|
|
@ -199,7 +196,7 @@ int main(int argc, char **argv)
|
||||||
struct sockaddr_in inaddr;
|
struct sockaddr_in inaddr;
|
||||||
struct sockaddr_in clientaddr;
|
struct sockaddr_in clientaddr;
|
||||||
socklen_t sin_size = sizeof(clientaddr);
|
socklen_t sin_size = sizeof(clientaddr);
|
||||||
char temp[BUFSZ];
|
char afrbuf[AFRSZ];
|
||||||
|
|
||||||
sigemptyset(&sigset);
|
sigemptyset(&sigset);
|
||||||
signalaction.sa_handler = &childdied;
|
signalaction.sa_handler = &childdied;
|
||||||
|
|
@ -416,19 +413,19 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
idx = idx2dindex(addr.can_ifindex, s[i]);
|
idx = idx2dindex(addr.can_ifindex, s[i]);
|
||||||
|
|
||||||
sprintf(temp, "(%llu.%06llu) %*s ",
|
sprintf(afrbuf, "(%llu.%06llu) %*s ",
|
||||||
(unsigned long long)tv.tv_sec, (unsigned long long)tv.tv_usec, max_devname_len, devname[idx]);
|
(unsigned long long)tv.tv_sec, (unsigned long long)tv.tv_usec, max_devname_len, devname[idx]);
|
||||||
sprint_canframe(temp+strlen(temp), (cu_t *)&frame, 0);
|
sprint_canframe(afrbuf+strlen(afrbuf), (cu_t *)&frame, 0);
|
||||||
strcat(temp, "\n");
|
strcat(afrbuf, "\n");
|
||||||
|
|
||||||
if (write(accsocket, temp, strlen(temp)) < 0) {
|
if (write(accsocket, afrbuf, strlen(afrbuf)) < 0) {
|
||||||
perror("writeaccsock");
|
perror("writeaccsock");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* print CAN frame in log file style to stdout */
|
/* print CAN frame in log file style to stdout */
|
||||||
printf("%s", temp);
|
printf("%s", afrbuf);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
22
canplayer.c
22
canplayer.c
|
|
@ -61,10 +61,24 @@
|
||||||
#define DEFAULT_GAP 1 /* ms */
|
#define DEFAULT_GAP 1 /* ms */
|
||||||
#define DEFAULT_LOOPS 1 /* only one replay */
|
#define DEFAULT_LOOPS 1 /* only one replay */
|
||||||
#define CHANNELS 20 /* anyone using more than 20 CAN interfaces at a time? */
|
#define CHANNELS 20 /* anyone using more than 20 CAN interfaces at a time? */
|
||||||
#define COMMENTSZ 200
|
|
||||||
#define BUFSZ (sizeof("(1345212884.318850)") + IFNAMSIZ + 4 + CL_CFSZ + COMMENTSZ) /* for one line in the logfile */
|
|
||||||
#define STDOUTIDX 65536 /* interface index for printing on stdout - bigger than max uint16 */
|
#define STDOUTIDX 65536 /* interface index for printing on stdout - bigger than max uint16 */
|
||||||
|
|
||||||
|
#if (IFNAMSIZ != 16)
|
||||||
|
#error "IFNAMSIZ value does not to DEVSZ calculation!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define DEVSZ 22 /* IFNAMSZ + 6 */
|
||||||
|
#define TIMESZ sizeof("(1345212884.318850) ")
|
||||||
|
#define BUFSZ (TIMESZ + DEVSZ + AFRSZ)
|
||||||
|
|
||||||
|
/* adapt sscanf() functions below on error */
|
||||||
|
#if (AFRSZ != 6300)
|
||||||
|
#error "AFRSZ value does not fit sscanf restrictions!"
|
||||||
|
#endif
|
||||||
|
#if (DEVSZ != 22)
|
||||||
|
#error "DEVSZ value does not fit sscanf restrictions!"
|
||||||
|
#endif
|
||||||
|
|
||||||
struct assignment {
|
struct assignment {
|
||||||
char txif[IFNAMSIZ];
|
char txif[IFNAMSIZ];
|
||||||
int txifidx;
|
int txifidx;
|
||||||
|
|
@ -239,7 +253,7 @@ int add_assignment(char *mode, int socket, char *txname, char *rxname, int verbo
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
static char buf[BUFSZ], device[BUFSZ], afrbuf[AFRSZ];
|
static char buf[BUFSZ], device[DEVSZ], afrbuf[AFRSZ];
|
||||||
struct sockaddr_can addr;
|
struct sockaddr_can addr;
|
||||||
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,
|
||||||
|
|
@ -426,7 +440,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
eof = 0;
|
eof = 0;
|
||||||
|
|
||||||
if (sscanf(buf, "(%llu.%llu) %s %s", &sec, &usec, device, afrbuf) != 4) {
|
if (sscanf(buf, "(%llu.%llu) %21s %6299s", &sec, &usec, device, afrbuf) != 4) {
|
||||||
fprintf(stderr, "incorrect line format in logfile\n");
|
fprintf(stderr, "incorrect line format in logfile\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
lib.h
2
lib.h
|
|
@ -63,8 +63,6 @@ typedef union {
|
||||||
struct canxl_frame xl;
|
struct canxl_frame xl;
|
||||||
} cu_t;
|
} cu_t;
|
||||||
|
|
||||||
#define CL_CFSZ 400 /* to be removed */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The buffer size for ASCII CAN frame string representations
|
* The buffer size for ASCII CAN frame string representations
|
||||||
* covers also the 'long' CAN frame output from sprint_long_canframe()
|
* covers also the 'long' CAN frame output from sprint_long_canframe()
|
||||||
|
|
|
||||||
24
log2asc.c
24
log2asc.c
|
|
@ -54,8 +54,6 @@
|
||||||
|
|
||||||
#include "lib.h"
|
#include "lib.h"
|
||||||
|
|
||||||
#define BUFSZ 400 /* for one line in the logfile */
|
|
||||||
|
|
||||||
extern int optind, opterr, optopt;
|
extern int optind, opterr, optopt;
|
||||||
|
|
||||||
void print_usage(char *prg)
|
void print_usage(char *prg)
|
||||||
|
|
@ -181,9 +179,25 @@ void canfd_asc(struct canfd_frame *cf, int devno, int mtu, char *extra_info, FIL
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define DEVSZ 22
|
||||||
|
#define EXTRASZ 20
|
||||||
|
#define TIMESZ sizeof("(1345212884.318850) ")
|
||||||
|
#define BUFSZ (DEVSZ + AFRSZ + EXTRASZ + TIMESZ)
|
||||||
|
|
||||||
|
/* adapt sscanf() functions below on error */
|
||||||
|
#if (AFRSZ != 6300)
|
||||||
|
#error "AFRSZ value does not fit sscanf restrictions!"
|
||||||
|
#endif
|
||||||
|
#if (DEVSZ != 22)
|
||||||
|
#error "DEVSZ value does not fit sscanf restrictions!"
|
||||||
|
#endif
|
||||||
|
#if (EXTRASZ != 20)
|
||||||
|
#error "EXTRASZ value does not fit sscanf restrictions!"
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
static char buf[BUFSZ], device[BUFSZ], afrbuf[AFRSZ], extra_info[BUFSZ];
|
static char buf[BUFSZ], device[DEVSZ], afrbuf[AFRSZ], extra_info[EXTRASZ];
|
||||||
|
|
||||||
static cu_t cu;
|
static cu_t cu;
|
||||||
static struct timeval tv, start_tv;
|
static struct timeval tv, start_tv;
|
||||||
|
|
@ -261,13 +275,13 @@ int main(int argc, char **argv)
|
||||||
if (buf[0] != '(')
|
if (buf[0] != '(')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (sscanf(buf, "(%llu.%llu) %s %s %s", &sec, &usec,
|
if (sscanf(buf, "(%llu.%llu) %21s %6299s %19s", &sec, &usec,
|
||||||
device, afrbuf, extra_info) != 5) {
|
device, afrbuf, extra_info) != 5) {
|
||||||
|
|
||||||
/* do not evaluate the extra info */
|
/* do not evaluate the extra info */
|
||||||
extra_info[0] = 0;
|
extra_info[0] = 0;
|
||||||
|
|
||||||
if (sscanf(buf, "(%llu.%llu) %s %s", &sec, &usec,
|
if (sscanf(buf, "(%llu.%llu) %21s %6299s", &sec, &usec,
|
||||||
device, afrbuf) != 4) {
|
device, afrbuf) != 4) {
|
||||||
fprintf(stderr, "incorrect line format in logfile\n");
|
fprintf(stderr, "incorrect line format in logfile\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
||||||
33
log2long.c
33
log2long.c
|
|
@ -43,26 +43,45 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <linux/can.h>
|
#include <linux/can.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
|
|
||||||
#include "lib.h"
|
#include "lib.h"
|
||||||
|
|
||||||
#define COMMENTSZ 200
|
#define DEVSZ 22
|
||||||
#define BUFSZ (sizeof("(1345212884.318850)") + IFNAMSIZ + 4 + CL_CFSZ + COMMENTSZ) /* for one line in the logfile */
|
#define TIMESZ 22 /* sizeof("(1345212884.318850) ") */
|
||||||
|
#define BUFSZ (DEVSZ + AFRSZ + TIMESZ)
|
||||||
|
|
||||||
|
/* adapt sscanf() functions below on error */
|
||||||
|
#if (AFRSZ != 6300)
|
||||||
|
#error "AFRSZ value does not fit sscanf restrictions!"
|
||||||
|
#endif
|
||||||
|
#if (DEVSZ != 22)
|
||||||
|
#error "DEVSZ value does not fit sscanf restrictions!"
|
||||||
|
#endif
|
||||||
|
#if (TIMESZ != 22)
|
||||||
|
#error "TIMESZ value does not fit sscanf restrictions!"
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
char buf[BUFSZ], timestamp[BUFSZ], device[BUFSZ], ascframe[BUFSZ];
|
char buf[BUFSZ], timestamp[TIMESZ], device[DEVSZ], afrbuf[AFRSZ];
|
||||||
static cu_t cu;
|
static cu_t cu;
|
||||||
int mtu;
|
int mtu;
|
||||||
|
|
||||||
while (fgets(buf, BUFSZ-1, stdin)) {
|
while (fgets(buf, BUFSZ-1, stdin)) {
|
||||||
if (sscanf(buf, "%s %s %s", timestamp, device, ascframe) != 3)
|
|
||||||
|
if (strlen(buf) >= BUFSZ-2) {
|
||||||
|
fprintf(stderr, "line too long for input buffer\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sscanf(buf, "%21s %21s %6299s", timestamp, device, afrbuf) != 3)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
mtu = parse_canframe(ascframe, &cu);
|
mtu = parse_canframe(afrbuf, &cu);
|
||||||
|
|
||||||
/* mark dual-use struct canfd_frame - no CAN_XL support */
|
/* mark dual-use struct canfd_frame - no CAN_XL support */
|
||||||
if (mtu == CAN_MTU)
|
if (mtu == CAN_MTU)
|
||||||
|
|
@ -75,10 +94,10 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* with ASCII output */
|
/* with ASCII output */
|
||||||
sprint_long_canframe(ascframe, &cu,
|
sprint_long_canframe(afrbuf, &cu,
|
||||||
(CANLIB_VIEW_INDENT_SFF | CANLIB_VIEW_ASCII));
|
(CANLIB_VIEW_INDENT_SFF | CANLIB_VIEW_ASCII));
|
||||||
|
|
||||||
printf("%s %s %s\n", timestamp, device, ascframe);
|
printf("%s %s %s\n", timestamp, device, afrbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue