Added support for serial data input

This commit is contained in:
adamdunkels 2009-03-06 00:13:56 +00:00
parent 6d545730ba
commit 3848bba210
2 changed files with 23 additions and 9 deletions

View file

@ -5,7 +5,7 @@ endif
CONTIKI_TARGET_DIRS = .
CONTIKI_TARGET_MAIN = ${addprefix $(OBJECTDIR)/,contiki-main.o}
CONTIKI_TARGET_SOURCEFILES = contiki-main.c clock.c leds.c leds-arch.c cfs-posix.c cfs-posix-dir.c dlloader.c
CONTIKI_TARGET_SOURCEFILES = contiki-main.c clock.c leds.c leds-arch.c cfs-posix.c cfs-posix-dir.c dlloader.c serial.c
ifeq ($(OS),Windows_NT)
CONTIKI_TARGET_SOURCEFILES += wpcap-drv.c wpcap.c

View file

@ -29,7 +29,7 @@
*
* This file is part of the Contiki OS
*
* $Id: contiki-main.c,v 1.17 2008/10/31 18:11:44 adamdunkels Exp $
* $Id: contiki-main.c,v 1.18 2009/03/06 00:13:56 adamdunkels Exp $
*
*/
@ -39,7 +39,9 @@
#include <unistd.h>
#include "contiki.h"
#include "contiki-net.h" //math
#include "contiki-net.h"
#include "dev/serial.h"
#include "net/uip.h"
#ifdef __CYGWIN__
@ -49,9 +51,9 @@
#endif /* __CYGWIN__ */
#ifdef __CYGWIN__
PROCINIT(&etimer_process, &tcpip_process, &wpcap_process);
PROCINIT(&etimer_process, &tcpip_process, &wpcap_process, &serial_process);
#else /* __CYGWIN__ */
PROCINIT(&etimer_process, &tapdev_process, &tcpip_process);
PROCINIT(&etimer_process, &tapdev_process, &tcpip_process, &serial_process);
#endif /* __CYGWIN__ */
/*---------------------------------------------------------------------------*/
@ -79,9 +81,12 @@ main(void)
printf("Def. Router: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr));
uip_setdraddr(&addr);
#endif
//
/* Make standard output unbuffered. */
setvbuf(stdout, (char *)NULL, _IONBF, 0);
while(1) {
fd_set fds;
int n;
struct timeval tv;
@ -92,7 +97,16 @@ main(void)
tv.tv_sec = 0;
tv.tv_usec = 1;
select(0, NULL, NULL, NULL, &tv);
FD_ZERO(&fds);
FD_SET(STDIN_FILENO, &fds);
select(1, &fds, NULL, NULL, &tv);
if(FD_ISSET(STDIN_FILENO, &fds)) {
char c;
if(read(STDIN_FILENO, &c, 1) > 0) {
serial_input_byte(c);
}
}
etimer_request_poll();
}