added uartpbs and ctsrts config options to packet radio serial

interface configuration options.
This commit is contained in:
gardners 2013-04-26 15:16:51 +09:30
parent 91a0b2520f
commit 3e7de24bdf
5 changed files with 33 additions and 7 deletions

View File

@ -262,6 +262,25 @@ int cf_opt_int32_nonneg(int32_t *intp, const char *text)
return CFOK;
}
int cf_opt_int32_rs232baudrate(int32_t *intp, const char *text)
{
const char *end = text;
long value = strtol(text, (char**)&end, 10);
if (end == text || *end || value < 0 || value > 0x7fffffffL)
return CFINVALID;
switch(value) {
case 50: case 75: case 110: case 134: case 150: case 200: case 300:
case 600: case 1200: case 1800: case 2400: case 4800: case 7200:
case 9600: case 14400: case 28800: case 38400: case 57600: case 115200:
case 230400:
*intp = value;
return CFOK;
break;
default:
return CFINVALID;
}
}
static int cf_fmt_int32(const char **textp, const int32_t *intp)
{
char buf[12];

View File

@ -440,6 +440,8 @@ ATOM(int32_t, mdp_tick_ms, -1, int32_nonneg,, "Override MDP ti
ATOM(bool_t, send_broadcasts, 1, boolean,, "If false, don't send any broadcast packets")
ATOM(bool_t, default_route, 0, boolean,, "If true, use this interface as a default route")
ATOM(bool_t, prefer_unicast, 0, boolean,, "If true, send unicast data as unicast IP packets if available")
ATOM(bool_t, ctsrts, 0, boolean,, "If true, enable CTS/RTS hardware handshaking")
ATOM(int32_t, uartbps, -1, int32_rs232baudrate,, "Speed of serial UART link speed (which may be different to serial device link speed)")
END_STRUCT
ARRAY(interface_list, NO_DUPLICATES)

View File

@ -349,6 +349,8 @@ overlay_interface_init(const char *name, struct in_addr src_addr, struct in_addr
interface->default_route = ifconfig->default_route;
interface->socket_type = ifconfig->socket_type;
interface->encapsulation = ifconfig->encapsulation;
interface->uartbps = ifconfig->uartbps;
interface->ctsrts = ifconfig->ctsrts;
/* Pick a reasonable default MTU.
This will ultimately get tuned by the bandwidth and other properties of the interface */

View File

@ -7,9 +7,8 @@ int overlay_packetradio_setup_port(overlay_interface *interface)
struct termios t;
tcgetattr(interface->alarm.poll.fd, &t);
// XXX Speed and options should be configurable
cfsetispeed(&t, B57600);
cfsetospeed(&t, B57600);
cfsetispeed(&t, interface->uartbps);
cfsetospeed(&t, interface->uartbps);
// 8N1
t.c_cflag &= ~PARENB;
t.c_cflag &= ~CSTOPB;
@ -26,11 +25,13 @@ int overlay_packetradio_setup_port(overlay_interface *interface)
No 8th-bit stripping or parity error handling.
Disable START/STOP output flow control. */
// Enable CTS/RTS flow control (for now)
// Enable/disable CTS/RTS flow control
#ifndef CNEW_RTSCTS
t.c_cflag |= CRTSCTS;
if (interface->ctsrts) t.c_cflag |= CRTSCTS;
else t.c_cflag &= ~CRTSCTS;
#else
t.c_cflag |= CNEW_RTSCTS;
if (interface->ctsrts) t.c_cflag |= CNEW_RTSCTS;
else t.c_cflag &= ~CNEW_RTSCTS;
#endif
// no output processing

View File

@ -415,6 +415,8 @@ typedef struct overlay_interface {
These figures will be refined over time, and we will allow people to set them per-interface.
*/
unsigned tick_ms; /* milliseconds per tick */
unsigned int uartbps; // set serial port speed (which might be different from link speed)
int ctsrts; // enabled hardware flow control if non-zero
struct subscriber *next_advert;