aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/systemcmds/nshterm/nshterm.c31
-rw-r--r--src/systemcmds/top/top.c18
2 files changed, 38 insertions, 11 deletions
diff --git a/src/systemcmds/nshterm/nshterm.c b/src/systemcmds/nshterm/nshterm.c
index bde0e7841..41d108ffc 100644
--- a/src/systemcmds/nshterm/nshterm.c
+++ b/src/systemcmds/nshterm/nshterm.c
@@ -40,6 +40,7 @@
*/
#include <nuttx/config.h>
+#include <termios.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdarg.h>
@@ -48,6 +49,7 @@
#include <errno.h>
#include <apps/nsh.h>
#include <fcntl.h>
+#include <systemlib/err.h>
__EXPORT int nshterm_main(int argc, char *argv[]);
@@ -61,8 +63,8 @@ nshterm_main(int argc, char *argv[])
uint8_t retries = 0;
int fd = -1;
while (retries < 5) {
- // the retries are to cope with the behaviour of /dev/ttyACM0
- // which may not be ready immediately.
+ /* the retries are to cope with the behaviour of /dev/ttyACM0 */
+ /* which may not be ready immediately. */
fd = open(argv[1], O_RDWR);
if (fd != -1) {
break;
@@ -74,7 +76,30 @@ nshterm_main(int argc, char *argv[])
perror(argv[1]);
exit(1);
}
- // setup standard file descriptors
+
+ /* set up the serial port with output processing */
+
+ /* Try to set baud rate */
+ struct termios uart_config;
+ int termios_state;
+
+ /* Back up the original uart configuration to restore it after exit */
+ if ((termios_state = tcgetattr(fd, &uart_config)) < 0) {
+ warnx("ERROR get termios config %s: %d\n", argv[1], termios_state);
+ close(fd);
+ return -1;
+ }
+
+ /* Set ONLCR flag (which appends a CR for every LF) */
+ uart_config.c_oflag |= (ONLCR | OPOST/* | OCRNL*/);
+
+ if ((termios_state = tcsetattr(fd, TCSANOW, &uart_config)) < 0) {
+ warnx("ERROR setting baudrate / termios config for %s (tcsetattr)\n", argv[1]);
+ close(fd);
+ return -1;
+ }
+
+ /* setup standard file descriptors */
close(0);
close(1);
close(2);
diff --git a/src/systemcmds/top/top.c b/src/systemcmds/top/top.c
index 0d064a05e..1ca3fc928 100644
--- a/src/systemcmds/top/top.c
+++ b/src/systemcmds/top/top.c
@@ -107,9 +107,6 @@ top_main(void)
float interval_time_ms_inv = 0.f;
- /* Open console directly to grab CTRL-C signal */
- int console = open("/dev/console", O_NONBLOCK | O_RDONLY | O_NOCTTY);
-
/* clear screen */
printf("\033[2J");
@@ -256,17 +253,24 @@ top_main(void)
interval_start_time = new_time;
/* Sleep 200 ms waiting for user input five times ~ 1s */
- /* XXX use poll ... */
for (int k = 0; k < 5; k++) {
char c;
- if (read(console, &c, 1) == 1) {
+ struct pollfd fds;
+ int ret;
+ fds.fd = 0; /* stdin */
+ fds.events = POLLIN;
+ ret = poll(&fds, 1, 0);
+
+ if (ret > 0) {
+
+ read(0, &c, 1);
+
switch (c) {
case 0x03: // ctrl-c
case 0x1b: // esc
case 'c':
case 'q':
- close(console);
return OK;
/* not reached */
}
@@ -278,7 +282,5 @@ top_main(void)
new_time = hrt_absolute_time();
}
- close(console);
-
return OK;
}