Skip to content

Commit

Permalink
keep stats for serial ports that don't support TIOCGICOUNT
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrake committed Sep 24, 2012
1 parent 91e9270 commit bdcda36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ CMakeFiles
Makefile
cmake_install.cmake
linux-serial-test
build

12 changes: 9 additions & 3 deletions linux-serial-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void process_options(int argc, char * argv[])
{
for (;;) {
int option_index = 0;
static const char *short_options = "b:p:d:RT";
static const char *short_options = "b:p:d:RTs";
static const struct option long_options[] = {
{"help", no_argument, 0, 0},
{"baud", required_argument, 0, 'b'},
Expand Down Expand Up @@ -147,11 +147,16 @@ unsigned char _write_count_value = 0;
unsigned char _read_count_value = 0;
int _fd = -1;

// keep our own counts for cases where the driver stats don't work
int _write_count = 0;
int _read_count = 0;

void process_read_data()
{
unsigned char rb[30];
int c = read(_fd, &rb, sizeof(rb));
if (c > 0) {
_read_count += c;
if (_cl_rx_dump)
dump_data(rb, c);

Expand Down Expand Up @@ -183,6 +188,7 @@ void process_write_data()
int c = write(_fd, &write_data, sizeof(write_data));

if (c > 0) {
_write_count += c;
count += c;
}

Expand All @@ -202,9 +208,9 @@ void dump_serial_port_stats()
struct serial_icounter_struct icount = {};
int ret = ioctl(_fd, TIOCGICOUNT, &icount);
if (ret == -1) {
printf("Error getting serial port stats\n");
printf("%s: rx=%i, tx=%i\n", _cl_port, _read_count, _write_count);
} else {
printf("%s, TIOCGICOUNT: ret=%i, rx=%i, tx=%i, frame = %i, overrun = %i, parity = %i, brk = %i, buf_overrun = %i",
printf("%s: TIOCGICOUNT: ret=%i, rx=%i, tx=%i, frame = %i, overrun = %i, parity = %i, brk = %i, buf_overrun = %i",
_cl_port, ret, icount.rx, icount.tx, icount.frame, icount.overrun, icount.parity, icount.brk,
icount.buf_overrun);
}
Expand Down

0 comments on commit bdcda36

Please sign in to comment.