mirror of
https://github.com/linux-can/can-utils.git
synced 2026-08-05 06:20:00 +02:00
cangen.c: added -c option for bursty output. (#201)
added -c option for bursty output. specify -c 100 to have 100 packets sent in burst before a gap. use for example -p 1000 to avoid TX buffer full errors
This commit is contained in:
@@ -66,6 +66,7 @@
|
|||||||
#include "lib.h"
|
#include "lib.h"
|
||||||
|
|
||||||
#define DEFAULT_GAP 200 /* ms */
|
#define DEFAULT_GAP 200 /* ms */
|
||||||
|
#define DEFAULT_BURST_COUNT 1
|
||||||
|
|
||||||
#define MODE_RANDOM 0
|
#define MODE_RANDOM 0
|
||||||
#define MODE_INCREMENT 1
|
#define MODE_INCREMENT 1
|
||||||
@@ -104,6 +105,8 @@ void print_usage(char *prg)
|
|||||||
" write() syscalls)\n");
|
" write() syscalls)\n");
|
||||||
fprintf(stderr, " -x (disable local loopback of "
|
fprintf(stderr, " -x (disable local loopback of "
|
||||||
"generated CAN frames)\n");
|
"generated CAN frames)\n");
|
||||||
|
fprintf(stderr, " -c (number of messages to send in burst, "
|
||||||
|
"default 1)\n");
|
||||||
fprintf(stderr, " -v (increment verbose level for "
|
fprintf(stderr, " -v (increment verbose level for "
|
||||||
"printing sent CAN frames)\n\n");
|
"printing sent CAN frames)\n\n");
|
||||||
fprintf(stderr, "Generation modes:\n");
|
fprintf(stderr, "Generation modes:\n");
|
||||||
@@ -136,6 +139,7 @@ void sigterm(int signo)
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
double gap = DEFAULT_GAP;
|
double gap = DEFAULT_GAP;
|
||||||
|
unsigned long burst_count = DEFAULT_BURST_COUNT;
|
||||||
unsigned long polltimeout = 0;
|
unsigned long polltimeout = 0;
|
||||||
unsigned char ignore_enobufs = 0;
|
unsigned char ignore_enobufs = 0;
|
||||||
unsigned char extended = 0;
|
unsigned char extended = 0;
|
||||||
@@ -149,6 +153,7 @@ int main(int argc, char **argv)
|
|||||||
unsigned char verbose = 0;
|
unsigned char verbose = 0;
|
||||||
unsigned char rtr_frame = 0;
|
unsigned char rtr_frame = 0;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
unsigned long burst_sent_count = 0;
|
||||||
int mtu, maxdlen;
|
int mtu, maxdlen;
|
||||||
uint64_t incdata = 0;
|
uint64_t incdata = 0;
|
||||||
int incdlc = 0;
|
int incdlc = 0;
|
||||||
@@ -176,7 +181,7 @@ int main(int argc, char **argv)
|
|||||||
signal(SIGHUP, sigterm);
|
signal(SIGHUP, sigterm);
|
||||||
signal(SIGINT, sigterm);
|
signal(SIGINT, sigterm);
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "ig:ebfmI:L:D:xp:n:vRh?")) != -1) {
|
while ((opt = getopt(argc, argv, "ig:ebfmI:L:D:xp:n:c:vRh?")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
@@ -241,6 +246,10 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'c':
|
||||||
|
burst_count = strtoul(optarg, NULL, 10);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
verbose++;
|
verbose++;
|
||||||
break;
|
break;
|
||||||
@@ -459,10 +468,14 @@ resend:
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gap) /* gap == 0 => performance test :-] */
|
burst_sent_count++;
|
||||||
|
if (gap && burst_sent_count >= burst_count) /* gap == 0 => performance test :-] */
|
||||||
if (nanosleep(&ts, NULL))
|
if (nanosleep(&ts, NULL))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
if (burst_sent_count >= burst_count)
|
||||||
|
burst_sent_count = 0;
|
||||||
|
|
||||||
if (id_mode == MODE_INCREMENT)
|
if (id_mode == MODE_INCREMENT)
|
||||||
frame.can_id++;
|
frame.can_id++;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user