aboutsummaryrefslogtreecommitdiff
path: root/src/systemcmds/nshterm
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2013-08-18 21:00:47 +0200
committerLorenz Meier <lm@inf.ethz.ch>2013-08-18 21:00:47 +0200
commit80f38e3dea6b707314b407c7c511c19aa4eade39 (patch)
tree81a6e37387b30bc18ef22d772e502e2319b7014e /src/systemcmds/nshterm
parent061be7f7fed430d1c235809f1e1dce61e8b7aa01 (diff)
downloadpx4-firmware-80f38e3dea6b707314b407c7c511c19aa4eade39.tar.gz
px4-firmware-80f38e3dea6b707314b407c7c511c19aa4eade39.tar.bz2
px4-firmware-80f38e3dea6b707314b407c7c511c19aa4eade39.zip
Put console and syslog on UART8, added support to nshterm for proper serial port config
Diffstat (limited to 'src/systemcmds/nshterm')
-rw-r--r--src/systemcmds/nshterm/nshterm.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/systemcmds/nshterm/nshterm.c b/src/systemcmds/nshterm/nshterm.c
index bde0e7841..2341068a2 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);