setup serial port mode when opening packet radio interface.

(now reads bytes over serial line)
This commit is contained in:
gardners 2013-02-05 06:06:44 +10:30 committed by Jeremy Lakeman
parent 190a5e693f
commit 0268ccd21a
3 changed files with 43 additions and 14 deletions

@ -403,9 +403,11 @@ overlay_interface_init(const char *name, struct in_addr src_addr, struct in_addr
if (ifconfig->dummy[0]||ifconfig->type==OVERLAY_INTERFACE_PACKETRADIO) {
interface->fileP = 1;
char dummyfile[1024];
if (ifconfig->type==OVERLAY_INTERFACE_PACKETRADIO)
if (ifconfig->type==OVERLAY_INTERFACE_PACKETRADIO) {
if (config.debug.packetradio) DEBUGF("Considering packet radio interface %s",
ifconfig->dummy);
snprintf(dummyfile, 1024, "%s",ifconfig->dummy);
else {
} else {
strbuf d = strbuf_local(dummyfile, sizeof dummyfile);
strbuf_path_join(d, serval_instancepath(), config.server.dummy_interface_dir, ifconfig->dummy, NULL);
if (strbuf_overrun(d))
@ -415,6 +417,11 @@ overlay_interface_init(const char *name, struct in_addr src_addr, struct in_addr
return WHYF("could not open dummy or packet radio interface file %s for append (errno=%d)", dummyfile,errno);
}
if (interface->type==OVERLAY_INTERFACE_PACKETRADIO) {
if (config.debug.packetradio) DEBUGF("Opened packet radio interface");
overlay_packetradio_setup_port(interface);
}
bzero(&interface->address, sizeof(interface->address));
interface->address.sin_family=AF_INET;
interface->address.sin_port = htons(PORT_DNA);
@ -439,6 +446,8 @@ overlay_interface_init(const char *name, struct in_addr src_addr, struct in_addr
// XXX This needs to be parameterised at some point
// Make sure it is not in command mode
write(interface->alarm.poll.fd,"ATO\r",4);
if (config.debug.packetradio)
DEBUGF("Sent ATO to make sure we are in on-line mode");
}
// schedule an alarm for this interface

@ -1,5 +1,6 @@
#include "serval.h"
#include "conf.h"
#include <termios.h>
/* interface decoder states. broadly based on RFC1055 */
#define DC_NORMAL 0
@ -12,6 +13,36 @@
#define SLIP_ESC_END 0334
#define SLIP_ESC_ESC 0335
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);
// 8N1
t.c_cflag &= ~PARENB;
t.c_cflag &= ~CSTOPB;
t.c_cflag &= ~CSIZE;
t.c_cflag |= CS8;
// Disable CTS/RTS flow control (for now)
#ifndef CNEW_RTSCTS
t.c_cflag &= ~CRTSCTS;
#else
t.c_cflag &= ~CNEW_RTSCTS;
#endif
// and software flow control
t.c_iflag &= ~(IXON | IXOFF | IXANY);
// raw data please
t.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
t.c_oflag &= ~OPOST;
tcsetattr(interface->alarm.poll.fd, TCSANOW, &t);
return 0;
}
int overlay_rx_packet_complete(overlay_interface *interface)
{
if (interface->recv_offset) {
@ -130,18 +161,6 @@ void overlay_packetradio_poll(struct sched_ent *alarm)
interface->last_tick_ms=now;
}
unsigned char buffer[8192];
ssize_t nread = read(alarm->poll.fd, buffer,8192);
if (nread == -1){
WHY_perror("read");
return;
}
if (nread>0) {
buffer[8191]=0;
if (nread<8192) buffer[nread]=0;
DEBUGF("Read '%s'",buffer);
}
schedule(alarm);
return ;

@ -752,6 +752,7 @@ int fd_poll();
void overlay_interface_discover(struct sched_ent *alarm);
void overlay_packetradio_poll(struct sched_ent *alarm);
int overlay_packetradio_setup_port(overlay_interface *interface);
void overlay_dummy_poll(struct sched_ent *alarm);
void overlay_route_tick(struct sched_ent *alarm);
void server_config_reload(struct sched_ent *alarm);