Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rx threashold to avoid infinite loop condition #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Usage: linux-serial-test [OPTION]
-a, --tx-delay Delay between writing data (ms)
-w, --tx-bytes Number of bytes for each write (default is to repeatedly write 1024 bytes
until no more are accepted)
-M, --rx-bytes-threash Read threashold, continue to next operation after reading this many bytes
-q, --rs485 Enable RS485 direction control on port, and set delay from when TX is
finished and RS485 driver enable is de-asserted. Delay is specified in
bit times. To optionally specify a delay from when the driver is enabled
Expand Down
12 changes: 11 additions & 1 deletion linux-serial-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ int _cl_no_tx = 0;
int _cl_rx_delay = 0;
int _cl_tx_delay = 0;
int _cl_tx_bytes = 0;
int _cl_rx_bytes_threash = 0;
int _cl_rs485_after_delay = -1;
int _cl_rs485_before_delay = 0;
int _cl_rs485_rts_after_send = 0;
Expand All @@ -79,6 +80,7 @@ unsigned char _read_count_value = 0;
int _fd = -1;
unsigned char * _write_data;
ssize_t _write_size;
ssize_t _read_size_threash;

// keep our own counts for cases where the driver stats don't work
long long int _write_count = 0;
Expand Down Expand Up @@ -310,6 +312,7 @@ static void display_help(void)
" -a, --tx-delay Delay between writing data (ms)\n"
" -w, --tx-bytes Number of bytes for each write (default is to repeatedly write 1024 bytes\n"
" until no more are accepted)\n"
" -M, --rx-bytes-threash Read threashold, continue to next operation after reading this many bytes\n"
" -q, --rs485 Enable RS485 direction control on port, and set delay from when TX is\n"
" finished and RS485 driver enable is de-asserted. Delay is specified in\n"
" bit times. To optionally specify a delay from when the driver is enabled\n"
Expand Down Expand Up @@ -357,6 +360,7 @@ static void process_options(int argc, char * argv[])
{"rx-delay", required_argument, 0, 'l'},
{"tx-delay", required_argument, 0, 'a'},
{"tx-bytes", required_argument, 0, 'w'},
{"rx-bytes-threash", required_argument, 0, 'M'},
{"rs485", required_argument, 0, 'q'},
{"rs485_rts", no_argument, 0, 'Q'},
{"no-modem", no_argument, 0, 'm'},
Expand Down Expand Up @@ -461,6 +465,11 @@ static void process_options(int argc, char * argv[])
_cl_tx_bytes = strtol(optarg, &endptr, 0);
break;
}
case 'M': {
char *endptr;
_cl_rx_bytes_threash = strtol(optarg, &endptr, 0);
break;
}
case 'q': {
char *endptr;
_cl_rs485_after_delay = strtol(optarg, &endptr, 0);
Expand Down Expand Up @@ -540,7 +549,7 @@ static void process_read_data(void)
{
unsigned char rb[1024];
int actual_read_count = 0;
while (actual_read_count < 1024) {
while (actual_read_count < _read_size_threash) {
int c = read(_fd, &rb, sizeof(rb));
if (c > 0) {
if (_cl_rx_dump) {
Expand Down Expand Up @@ -814,6 +823,7 @@ int main(int argc, char * argv[])
}

_write_size = (_cl_tx_bytes == 0) ? 1024 : _cl_tx_bytes;
_read_size_threash = (_cl_rx_bytes_threash == 0) ? 1024 : _cl_rx_bytes_threash;

_write_data = malloc(_write_size);
if (_write_data == NULL) {
Expand Down