Skip to content

Commit

Permalink
utils: poll: also use stdin if no path set and stdin is not a tty
Browse files Browse the repository at this point in the history
  • Loading branch information
connorimes committed Apr 5, 2024
1 parent c6d1865 commit 9492964
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ See their help output for usage.
* `osp3-dump` - dump the device's serial output.
* `osp3-poll` - poll the device's serial output for complete log entries.

While `osp3-poll` reads from the serial port by default, it can also read from standard input.
For example:

```sh
osp3-dump | osp3-poll
````

Or, more usefully, if you have UDP logging over wifi configured:

```sh
netcat -u -l -p 6000 | osp3-poll
```


## C API

Expand Down
5 changes: 4 additions & 1 deletion utils/osp3-poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <osp3.h>

#ifdef __APPLE__
Expand All @@ -25,6 +26,7 @@
// Much bigger than anything an OSP3 should produce.
#define OSP3_LINE_LEN_MAX 1024

static int path_set = 0;
static const char* path = PATH_DEFAULT;
static unsigned int baud = OSP3_BAUD_DEFAULT;
static unsigned int timeout_ms = TIMEOUT_MS_DEFAULT;
Expand Down Expand Up @@ -72,6 +74,7 @@ static void parse_args(int argc, char** argv) {
print_usage(0);
break;
case 'p':
path_set = 1;
path = optarg;
break;
case 'b':
Expand Down Expand Up @@ -226,7 +229,7 @@ int main(int argc, char** argv) {

parse_args(argc, argv);

if (path != NULL && strlen(path) > 0 && strcmp(path, "-")) {
if (path_set || (isatty(0) && path != NULL && strlen(path) > 0 && strcmp(path, "-"))) {
signal(SIGINT, shandle);
if ((dev = osp3_open_device(path, baud)) == NULL) {
perror("Failed to open ODROID Smart Power 3 connection");
Expand Down

0 comments on commit 9492964

Please sign in to comment.