diff --git a/sw/in_progress/wind_tunnel/Makefile b/sw/in_progress/wind_tunnel/Makefile new file mode 100644 index 0000000000..00d292d5b9 --- /dev/null +++ b/sw/in_progress/wind_tunnel/Makefile @@ -0,0 +1,11 @@ + +CC = gcc +GLIB_CFLAGS = -Wall `pkg-config glib-2.0 --cflags` +GLIB_LDFLAGS = `pkg-config glib-2.0 --libs` -lglibivy -lpcre + +main: main.c serial_port.c + $(CC) $(GLIB_CFLAGS) -o $@ main.c serial_port.c $(GLIB_LDFLAGS) + + +clean: + rm -f main \ No newline at end of file diff --git a/sw/in_progress/wind_tunnel/main.c b/sw/in_progress/wind_tunnel/main.c new file mode 100644 index 0000000000..734998e61d --- /dev/null +++ b/sw/in_progress/wind_tunnel/main.c @@ -0,0 +1,88 @@ +#include +#include +#include + +#include +#include + +#include "serial_port.h" + +static struct SerialPort* sp; +static GIOChannel* ioc; + +static void configure_term(struct termios *termios, speed_t *speed) { + /* input modes */ + termios->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|INPCK|ISTRIP|INLCR|IGNCR + |ICRNL |IUCLC|IXON|IXANY|IXOFF|IMAXBEL); + termios->c_iflag |= IGNPAR; + /* control modes*/ + termios->c_cflag &= ~(CSIZE|PARENB|CRTSCTS|PARODD|HUPCL); + termios->c_cflag |= CREAD|CS8|CSTOPB|CLOCAL; + /* local modes */ + termios->c_lflag &= ~(ISIG|ICANON|IEXTEN|ECHO|FLUSHO|PENDIN); + termios->c_lflag |= NOFLSH; + /* speed */ + *speed = B9600; +} + +static void dump_buf ( int len, char* buf) { + int i; + for (i=0; ifd); + g_io_channel_set_encoding(ioc, NULL, NULL); + g_io_channel_set_flags (ioc,G_IO_FLAG_NONBLOCK, NULL ); + g_io_add_watch (ioc, G_IO_IN, on_serial_data_received, NULL); + + + GMainLoop *ml = g_main_loop_new(NULL, FALSE); + + IvyInit ("Example2", "Example2 READY", NULL, NULL, NULL, NULL); + IvyStart("127.255.255.255"); + + g_timeout_add(500, timeout_callback, NULL); + + g_main_loop_run(ml); + + return 0; +} + diff --git a/sw/in_progress/wind_tunnel/serial_port.c b/sw/in_progress/wind_tunnel/serial_port.c new file mode 100644 index 0000000000..d5dd1b3ac8 --- /dev/null +++ b/sw/in_progress/wind_tunnel/serial_port.c @@ -0,0 +1,89 @@ +/* + pc2rc serial port functions + Copyright (C) 2001 Antoine Drouin + + This file is part of paparazzi. + + paparazzi is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + paparazzi is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with paparazzi; see the file COPYING. If not, write to + the Free Software Foundation, 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "serial_port.h" + +#define TRACE(type,fmt,args...) +#define TRACE_ERROR 1 + +struct SerialPort* serial_port_new() { + struct SerialPort* this = malloc(sizeof(struct SerialPort)); + return this; +} + +/* + * opens serial port and setup the terminal + */ +guint +serial_port_open(struct SerialPort* this, const char* device, + void(*term_conf_callback)(struct termios*, speed_t*)) { + speed_t speed; + if ((this->fd = open(device, O_RDWR)) < 0) { + TRACE(TRACE_ERROR,"opening %s (%s)\n", device, strerror(errno)); + return -1; + } + if (tcgetattr(this->fd, &this->orig_termios) < 0) { + TRACE(TRACE_ERROR,"getting term settings (%s)\n", strerror(errno)); + return -1; + } + this->cur_termios = this->orig_termios; + term_conf_callback(&this->cur_termios, &speed); + if (cfsetispeed(&this->cur_termios, speed)) { + TRACE(TRACE_ERROR,"setting term speed (%s)\n", strerror(errno)); + return -1; + } + if (tcsetattr(this->fd, TCSADRAIN, &this->cur_termios)) { + TRACE(TRACE_ERROR,"setting term attributes (%s)\n", strerror(errno)); + return -1; + } + return 0; +} + +/* + * closes serial port and restore term settings + */ +guint +serial_port_close(struct SerialPort* this) { + if (tcflush(this->fd, TCIOFLUSH)) { + TRACE(TRACE_ERROR,"flushing (%s)\n", strerror(errno)); + return -1; + } + if (tcsetattr(this->fd, TCSADRAIN, &this->orig_termios)) { // Restore modes. + TRACE(TRACE_ERROR,"restoring term attributes (%s)\n", strerror(errno)); + return -1; + } + if (close(this->fd)) { + TRACE(TRACE_ERROR,"closing (%s)\n", strerror(errno)); + return -1; + } + return 0; +} diff --git a/sw/in_progress/wind_tunnel/serial_port.h b/sw/in_progress/wind_tunnel/serial_port.h new file mode 100644 index 0000000000..18b37713e2 --- /dev/null +++ b/sw/in_progress/wind_tunnel/serial_port.h @@ -0,0 +1,20 @@ +#ifndef SERIAL_PORT_H +#define SERIAL_PORT_H + +#include +#include + +struct SerialPort { + int fd; /* serial device fd */ + struct termios orig_termios; /* saved tty state structure */ + struct termios cur_termios; /* tty state structure */ +}; + + +struct SerialPort* serial_port_new(); +guint serial_port_open(struct SerialPort* this, const char* device, + void(*term_conf_callback)(struct termios*, speed_t*)); +guint serial_port_close(struct SerialPort* this); + + +#endif