Add more raw options to serial interface

This commit is contained in:
Jeremy Lakeman 2013-02-14 17:17:45 +10:30
parent 6d9bbe2e2c
commit 45efb3f899
4 changed files with 37 additions and 22 deletions

@ -25,22 +25,24 @@ int main(int argc,char **argv)
fds[0].fd=left;
fds[0].events=POLLIN;
fds[1].fd=right;
fds[2].events=POLLIN;
fds[1].events=POLLIN;
while(1) {
poll(fds,2,1000);
for(i=0;i<2;i++) {
if (1||fds[i].revents&POLLIN) {
int bytes=read(fds[i].fd,buffer,8192);
if (fds[i].revents&POLLIN) {
int bytes=read(fds[i].fd,buffer,sizeof(buffer));
if (bytes>0) {
write(fds[i^1].fd,buffer,bytes);
printf("reading from %d, read %d, errno=%d\n",i,bytes,errno);
// every write operation consumes "air time" and adds delay to the next read
usleep(100000);
int written = write(fds[i^1].fd,buffer,bytes);
printf("reading from %d, read %d, written %d, errno=%d\n",i,bytes,written,errno);
}
fds[i].revents=0;
}
if (fds[i].revents&~POLLIN)
printf("revents %x\n", fds[i].revents);
}
usleep(100000);
}
return 0;

@ -556,12 +556,12 @@ static void interface_read_file(struct overlay_interface *interface)
((!interface->drop_broadcasts) &&
memcmp(&packet.dst_addr, &interface->broadcast_address, sizeof(packet.dst_addr))==0)){
if (packetOkOverlay(interface, packet.payload, packet.payload_length, -1,
(struct sockaddr*)&packet.src_addr, sizeof(packet.src_addr))<0) {
WARN("Unsupported packet from dummy interface");
}
}else if (config.debug.packetrx)
DEBUGF("Ignoring packet addressed to %s:%d", inet_ntoa(packet.dst_addr.sin_addr), ntohs(packet.dst_addr.sin_port));
if (packetOkOverlay(interface, packet.payload, packet.payload_length, -1,
(struct sockaddr*)&packet.src_addr, sizeof(packet.src_addr))<0) {
WARN("Unsupported packet from dummy interface");
}
}else if (config.debug.packetrx)
DEBUGF("Ignoring packet addressed to %s:%d", inet_ntoa(packet.dst_addr.sin_addr), ntohs(packet.dst_addr.sin_port));
}
}
@ -587,10 +587,9 @@ static void interface_read_stream(struct overlay_interface *interface){
unsigned char buffer[OVERLAY_INTERFACE_RX_BUFFER_SIZE];
ssize_t nread = read(interface->alarm.poll.fd, buffer, OVERLAY_INTERFACE_RX_BUFFER_SIZE);
if (nread == -1){
// WHY_perror("read");
WHY_perror("read");
return;
}
struct slip_decode_state *state=&interface->slip_decode_state;
state->src=buffer;
@ -645,7 +644,6 @@ static void overlay_interface_poll(struct sched_ent *alarm)
if (interface->state==INTERFACE_STATE_UP && interface->tick_ms>0 && now >= interface->last_tick_ms+interface->tick_ms){
// tick the interface
DEBUG("TICK");
overlay_route_queue_advertisements(interface);
interface->last_tick_ms=now;
alarm->alarm=interface->last_tick_ms+interface->tick_ms;

@ -16,17 +16,24 @@ int overlay_packetradio_setup_port(overlay_interface *interface)
t.c_cflag &= ~CSIZE;
t.c_cflag |= CS8;
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. */
// Enable 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);
// no output processing
t.c_oflag &= ~OPOST;
tcsetattr(interface->alarm.poll.fd, TCSANOW, &t);
@ -35,6 +42,15 @@ int overlay_packetradio_setup_port(overlay_interface *interface)
if (config.debug.packetradio)
DEBUGF("Sent ATO to make sure we are in on-line mode");
if (0){
// dummy write of all possible ascii values
char buff[256];
int i;
for (i=0;i<sizeof buff;i++)
buff[i]=i;
write(interface->alarm.poll.fd,buff,sizeof buff);
}
set_nonblock(interface->alarm.poll.fd);
return 0;

@ -387,8 +387,7 @@ int overlay_rhizome_saw_advertisements(int i, struct overlay_frame *f, long long
while(ob_remaining(f->payload)>0){
unsigned char *bar=ob_get_bytes_ptr(f->payload, RHIZOME_BAR_BYTES);
if (!bar){
WARNF("Expected whole BAR @%d (only %d remains)", ob_position(f->payload), ob_remaining(f->payload));
dump("buffer", ob_ptr(f->payload), ob_limit(f->payload));
WARNF("Expected whole BAR @%x (only %d bytes remain)", ob_position(f->payload), ob_remaining(f->payload));
break;
}
if (rhizome_is_bar_interesting(bar)==1){