From 3e7de24bdf0c429d23f3b7aa5dc1c16fe0d499e1 Mon Sep 17 00:00:00 2001 From: gardners Date: Fri, 26 Apr 2013 15:16:51 +0930 Subject: [PATCH] added uartpbs and ctsrts config options to packet radio serial interface configuration options. --- conf_schema.c | 19 +++++++++++++++++++ conf_schema.h | 2 ++ overlay_interface.c | 4 +++- overlay_packetradio.c | 13 +++++++------ serval.h | 2 ++ 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/conf_schema.c b/conf_schema.c index e9b38e71..a3b2c59c 100644 --- a/conf_schema.c +++ b/conf_schema.c @@ -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]; diff --git a/conf_schema.h b/conf_schema.h index 565ebf8b..8c968300 100644 --- a/conf_schema.h +++ b/conf_schema.h @@ -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) diff --git a/overlay_interface.c b/overlay_interface.c index 29fae573..f66ff2bd 100644 --- a/overlay_interface.c +++ b/overlay_interface.c @@ -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 */ @@ -360,7 +362,7 @@ overlay_interface_init(const char *name, struct in_addr src_addr, struct in_addr // How often do we announce ourselves on this interface? int tick_ms=-1; int packet_interval=-1; - + // hard coded defaults: switch (ifconfig->type) { case OVERLAY_INTERFACE_PACKETRADIO: diff --git a/overlay_packetradio.c b/overlay_packetradio.c index 046659ed..d20c4fec 100644 --- a/overlay_packetradio.c +++ b/overlay_packetradio.c @@ -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 diff --git a/serval.h b/serval.h index 3e53dc79..c5b55b0c 100644 --- a/serval.h +++ b/serval.h @@ -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;