2013-02-04 19:12:50 +00:00
|
|
|
#include "serval.h"
|
|
|
|
#include "conf.h"
|
2013-02-04 19:36:44 +00:00
|
|
|
#include <termios.h>
|
2013-02-04 19:12:50 +00:00
|
|
|
|
2013-02-04 19:36:44 +00:00
|
|
|
int overlay_packetradio_setup_port(overlay_interface *interface)
|
|
|
|
{
|
|
|
|
struct termios t;
|
2013-02-04 19:49:48 +00:00
|
|
|
|
2013-06-24 06:41:20 +00:00
|
|
|
if (tcgetattr(interface->alarm.poll.fd, &t))
|
|
|
|
WHY_perror("Failed to get terminal parameters");
|
|
|
|
speed_t baud_rate;
|
|
|
|
switch(interface->uartbps){
|
|
|
|
case 0: baud_rate = B0; break;
|
|
|
|
case 50: baud_rate = B50; break;
|
|
|
|
case 75: baud_rate = B75; break;
|
|
|
|
case 110: baud_rate = B110; break;
|
|
|
|
case 134: baud_rate = B134; break;
|
|
|
|
case 150: baud_rate = B150; break;
|
|
|
|
case 200: baud_rate = B200; break;
|
|
|
|
case 300: baud_rate = B300; break;
|
|
|
|
case 600: baud_rate = B600; break;
|
|
|
|
case 1200: baud_rate = B1200; break;
|
|
|
|
case 1800: baud_rate = B1800; break;
|
|
|
|
case 2400: baud_rate = B2400; break;
|
|
|
|
case 4800: baud_rate = B4800; break;
|
|
|
|
case 9600: baud_rate = B9600; break;
|
|
|
|
case 19200: baud_rate = B19200; break;
|
|
|
|
case 38400: baud_rate = B38400; break;
|
|
|
|
default:
|
|
|
|
case 57600: baud_rate = B57600; break;
|
2013-07-12 06:13:25 +00:00
|
|
|
case 115200: baud_rate = B115200; break;
|
2013-06-24 06:41:20 +00:00
|
|
|
case 230400: baud_rate = B230400; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cfsetospeed(&t, baud_rate))
|
|
|
|
WHY_perror("Failed to set output baud rate");
|
|
|
|
if (cfsetispeed(&t, baud_rate))
|
|
|
|
WHY_perror("Failed to set input baud rate");
|
2013-05-08 04:02:01 +00:00
|
|
|
|
2013-02-04 19:36:44 +00:00
|
|
|
// 8N1
|
|
|
|
t.c_cflag &= ~PARENB;
|
|
|
|
t.c_cflag &= ~CSTOPB;
|
|
|
|
t.c_cflag &= ~CSIZE;
|
|
|
|
t.c_cflag |= CS8;
|
|
|
|
|
2013-02-14 06:47:45 +00:00
|
|
|
t.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO | ECHOE);
|
|
|
|
/* Noncanonical mode, disable signals, extended
|
|
|
|
input processing, and software flow control and echoing */
|
|
|
|
|
|
|
|
t.c_iflag &= ~(BRKINT | ICRNL | IGNBRK | IGNCR | INLCR |
|
|
|
|
INPCK | ISTRIP | IXON | IXOFF | IXANY | PARMRK);
|
|
|
|
/* Disable special handling of CR, NL, and BREAK.
|
|
|
|
No 8th-bit stripping or parity error handling.
|
|
|
|
Disable START/STOP output flow control. */
|
|
|
|
|
2013-04-26 05:46:51 +00:00
|
|
|
// Enable/disable CTS/RTS flow control
|
2013-02-04 19:36:44 +00:00
|
|
|
#ifndef CNEW_RTSCTS
|
2013-04-26 05:46:51 +00:00
|
|
|
if (interface->ctsrts) t.c_cflag |= CRTSCTS;
|
|
|
|
else t.c_cflag &= ~CRTSCTS;
|
2013-02-04 19:36:44 +00:00
|
|
|
#else
|
2013-04-26 05:46:51 +00:00
|
|
|
if (interface->ctsrts) t.c_cflag |= CNEW_RTSCTS;
|
|
|
|
else t.c_cflag &= ~CNEW_RTSCTS;
|
2013-02-04 19:36:44 +00:00
|
|
|
#endif
|
|
|
|
|
2013-02-14 06:47:45 +00:00
|
|
|
// no output processing
|
2013-02-04 19:36:44 +00:00
|
|
|
t.c_oflag &= ~OPOST;
|
|
|
|
|
2013-06-24 06:41:20 +00:00
|
|
|
if (tcsetattr(interface->alarm.poll.fd, TCSANOW, &t))
|
|
|
|
WHY_perror("Failed to set terminal parameters");
|
2013-05-08 04:02:01 +00:00
|
|
|
|
2013-08-29 06:20:13 +00:00
|
|
|
// Enable MAVLink mode to get regular RSSI reports
|
|
|
|
uint8_t buf[256];
|
|
|
|
int buflen=0;
|
|
|
|
buflen=0;
|
|
|
|
mavlink_heartbeat(buf,&buflen);
|
|
|
|
(void)write_all(interface->alarm.poll.fd,buf,buflen);
|
|
|
|
|
|
|
|
|
2013-02-14 19:37:51 +00:00
|
|
|
if (config.debug.packetradio) {
|
2013-05-08 04:02:24 +00:00
|
|
|
tcgetattr(interface->alarm.poll.fd, &t);
|
2013-05-08 04:02:01 +00:00
|
|
|
int in_speed=cfgetispeed(&t);
|
|
|
|
int out_speed=cfgetospeed(&t);
|
|
|
|
|
2013-08-29 06:20:13 +00:00
|
|
|
DEBUGF("Enabled MAVLink based RSSI reporting for RFD900 radios");
|
2013-05-08 04:02:01 +00:00
|
|
|
DEBUGF("uart speed reported as %d/%d",in_speed,out_speed);
|
2013-02-14 19:37:51 +00:00
|
|
|
}
|
2013-02-04 19:12:50 +00:00
|
|
|
|
2013-02-14 06:47:45 +00:00
|
|
|
if (0){
|
|
|
|
// dummy write of all possible ascii values
|
|
|
|
char buff[256];
|
|
|
|
int i;
|
|
|
|
for (i=0;i<sizeof buff;i++)
|
|
|
|
buff[i]=i;
|
2013-03-18 06:09:08 +00:00
|
|
|
(void)write_all(interface->alarm.poll.fd,buff,sizeof buff);
|
2013-02-14 06:47:45 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 03:48:56 +00:00
|
|
|
set_nonblock(interface->alarm.poll.fd);
|
2013-02-04 21:08:50 +00:00
|
|
|
|
2013-02-04 19:49:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|