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,12 +5,12 @@ endif
CONTIKI_TARGET_DIRS = . CONTIKI_TARGET_DIRS = .
CONTIKI_TARGET_MAIN = ${addprefix $(OBJECTDIR)/,contiki-main.o} 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) ifeq ($(OS),Windows_NT)
CONTIKI_TARGET_SOURCEFILES += wpcap-drv.c wpcap.c CONTIKI_TARGET_SOURCEFILES += wpcap-drv.c wpcap.c
else else
CONTIKI_TARGET_SOURCEFILES += tapdev-drv.c CONTIKI_TARGET_SOURCEFILES += tapdev-drv.c
#math #math
ifndef UIP_CONF_IPV6 ifndef UIP_CONF_IPV6
CONTIKI_TARGET_SOURCEFILES += tapdev.c CONTIKI_TARGET_SOURCEFILES += tapdev.c

View file

@ -29,7 +29,7 @@
* *
* This file is part of the Contiki OS * 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 <unistd.h>
#include "contiki.h" #include "contiki.h"
#include "contiki-net.h" //math #include "contiki-net.h"
#include "dev/serial.h"
#include "net/uip.h" #include "net/uip.h"
#ifdef __CYGWIN__ #ifdef __CYGWIN__
@ -49,9 +51,9 @@
#endif /* __CYGWIN__ */ #endif /* __CYGWIN__ */
#ifdef __CYGWIN__ #ifdef __CYGWIN__
PROCINIT(&etimer_process, &tcpip_process, &wpcap_process); PROCINIT(&etimer_process, &tcpip_process, &wpcap_process, &serial_process);
#else /* __CYGWIN__ */ #else /* __CYGWIN__ */
PROCINIT(&etimer_process, &tapdev_process, &tcpip_process); PROCINIT(&etimer_process, &tapdev_process, &tcpip_process, &serial_process);
#endif /* __CYGWIN__ */ #endif /* __CYGWIN__ */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -65,7 +67,7 @@ main(void)
autostart_start(autostart_processes); autostart_start(autostart_processes);
#if !UIP_CONF_IPV6 #if !UIP_CONF_IPV6
uip_ipaddr_t addr; uip_ipaddr_t addr;
uip_ipaddr(&addr, 192,168,1,2); uip_ipaddr(&addr, 192,168,1,2);
printf("IP Address: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr)); printf("IP Address: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr));
@ -79,9 +81,12 @@ main(void)
printf("Def. Router: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr)); printf("Def. Router: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr));
uip_setdraddr(&addr); uip_setdraddr(&addr);
#endif #endif
//
/* Make standard output unbuffered. */
setvbuf(stdout, (char *)NULL, _IONBF, 0);
while(1) { while(1) {
fd_set fds;
int n; int n;
struct timeval tv; struct timeval tv;
@ -92,7 +97,16 @@ main(void)
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 1; 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(); etimer_request_poll();
} }