diff --git a/platform/netsim/Makefile.netsim b/platform/netsim/Makefile.netsim index 5f9594ac7..761ea91d3 100644 --- a/platform/netsim/Makefile.netsim +++ b/platform/netsim/Makefile.netsim @@ -8,8 +8,8 @@ SENSORS = sensors.c beep.c button-sensor.c pir-sensor.c vib-sensor.c \ radio-sensor.c irq.c eeprom.c \ dummy-sensors.c leds.c leds-arch.c esb-sensors.c NETSIM = cfs-ram.c ether.c ethernode.c ethernode-uip.c lpm.c rs232.c flash.c \ - node.c nodes.c sensor.c display.c random.c radio.c \ - dlloader.c main.c netsim-init.c contiki-main.c symtab.c symbols.c tr1001.c tr1001-drv.c + node.c nodes.c sensor.c display.c random.c radio.c serial.c \ + dlloader.c main.c netsim-init.c contiki-main.c symtab.c symbols.c tr1001.c tr1001-drv.c ifeq ($(OS),Windows_NT) CONTIKI_TARGET_SOURCEFILES = $(NETSIM) $(SENSORS) wpcap-drv.c wpcap.c diff --git a/platform/netsim/contiki-main.c b/platform/netsim/contiki-main.c index 12cc06bce..8f6a04e02 100644 --- a/platform/netsim/contiki-main.c +++ b/platform/netsim/contiki-main.c @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: contiki-main.c,v 1.25 2008/01/04 23:09:03 oliverschmidt Exp $ + * $Id: contiki-main.c,v 1.26 2008/01/14 09:38:16 adamdunkels Exp $ */ #include "contiki.h" @@ -64,6 +64,12 @@ #include "dev/radio-sensor.h" #include "dev/leds.h" +#ifdef __CYGWIN__ +__attribute__((dllimport)) extern int __argc; +__attribute__((dllimport)) extern char **__argv[]; +#endif /* __CYGWIN__ */ + + #ifdef __CYGWIN__ static struct uip_fw_netif extif = {UIP_FW_NETIF(0,0,0,0, 0,0,0,0, wpcap_output)}; @@ -111,8 +117,10 @@ contiki_main(int flag) procinit_init(); - uip_init(); + serial_init(); + uip_init(); + ctimer_init(); rime_init(nullmac_init(ðernode_driver)); @@ -120,17 +128,19 @@ contiki_main(int flag) if(flag == 1) { #ifdef __CYGWIN__ - process_start(&wpcap_process, NULL); - { - char buf[1024]; - - snprintf(buf, sizeof(buf), "route add %d.%d.%d.%d mask %d.%d.%d.%d %d.%d.%d.%d", - uip_ipaddr_to_quad(&meshif.ipaddr), - uip_ipaddr_to_quad(&meshif.netmask), - uip_ipaddr_to_quad(&uip_hostaddr)); - printf("%s\n", buf); - system(buf); - signal(SIGTERM, remove_route); + if(__argc > 2 && (*__argv)[1][0] != '-') { + process_start(&wpcap_process, NULL); + { + char buf[1024]; + + snprintf(buf, sizeof(buf), "route add %d.%d.%d.%d mask %d.%d.%d.%d %d.%d.%d.%d", + uip_ipaddr_to_quad(&meshif.ipaddr), + uip_ipaddr_to_quad(&meshif.netmask), + uip_ipaddr_to_quad(&uip_hostaddr)); + printf("%s\n", buf); + system(buf); + signal(SIGTERM, remove_route); + } } #else /* __CYGWIN__ */ process_start(&tapdev_process, NULL); diff --git a/platform/netsim/display.c b/platform/netsim/display.c index 31250bfb6..e3693ec6c 100644 --- a/platform/netsim/display.c +++ b/platform/netsim/display.c @@ -24,7 +24,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * - * $Id: display.c,v 1.6 2007/11/17 18:09:18 adamdunkels Exp $ + * $Id: display.c,v 1.7 2008/01/14 09:38:16 adamdunkels Exp $ * * Author: Adam Dunkels * @@ -43,6 +43,7 @@ #include #include +#include static GdkPixmap *pixmap = NULL; static GtkWidget *drawing_area; @@ -486,6 +487,17 @@ get_color(unsigned short r, unsigned short g, unsigned short b) GDK_GC_FOREGROUND); } /*-----------------------------------------------------------------------------------*/ +static void +stdin_callback(gpointer data, gint source, GdkInputCondition condition) +{ + char buf[1000]; + int len; + + len = read(STDIN_FILENO, &buf, sizeof(buf)); + buf[len] = 0; + ether_send_serial(buf); +} +/*-----------------------------------------------------------------------------------*/ void display_init(void (* idlefunc)(void), int time, int with_gui) { @@ -624,6 +636,8 @@ display_init(void (* idlefunc)(void), int time, int with_gui) black = get_color(0, 0, 0); white = get_color(0xffff, 0xffff, 0xffff); } + + gdk_input_add(STDIN_FILENO, GDK_INPUT_READ, stdin_callback, NULL); } /*-----------------------------------------------------------------------------------*/ void diff --git a/platform/netsim/ether.c b/platform/netsim/ether.c index 8ee493eab..648b8ecbd 100644 --- a/platform/netsim/ether.c +++ b/platform/netsim/ether.c @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: ether.c,v 1.10 2007/11/17 18:09:18 adamdunkels Exp $ + * $Id: ether.c,v 1.11 2008/01/14 09:38:16 adamdunkels Exp $ */ /** * \file @@ -61,6 +61,8 @@ #include "dev/radio-sensor.h" +#include "dev/serial.h" + #include "sensor.h" #include "node.h" @@ -90,6 +92,9 @@ static int s, sc; #define PTYPE_LEDS 4 #define PTYPE_TEXT 5 #define PTYPE_DONE 6 +#define PTYPE_SERIAL 7 + +#define SERIAL_LEN 80 struct ether_hdr { int type; @@ -101,7 +106,7 @@ struct ether_hdr { int srcid; int srcnodetype; int leds; - char text[NODES_TEXTLEN]; + char text[NODES_TEXTLEN + SERIAL_LEN]; }; static int strength; @@ -211,7 +216,7 @@ ether_client_init(int port) sa.sin_port = htons(port); - /* printf("ether_client_init: binding id %d to port %d\n", id, PORTBASE + id);*/ + /* printf("ether_client_init: binding to port %d\n", port);*/ if(bind(sc, (struct sockaddr *)&sa, sizeof(sa)) < 0) { printf("Bind to port %d\n", port); perror("bind"); @@ -224,6 +229,7 @@ ether_client_poll(void) { fd_set fdset; struct timeval tv; + int ret; FD_ZERO(&fdset); FD_SET(sc, &fdset); @@ -231,7 +237,12 @@ ether_client_poll(void) tv.tv_sec = 0; tv.tv_usec = 10000; - return select(sc + 1, &fdset, NULL, NULL, &tv); + ret = select(sc + 1, &fdset, NULL, NULL, &tv); + + if(ret < 0) { + perror("ether_client_poll: select"); + } + return ret == 1; } /*-----------------------------------------------------------------------------------*/ u16_t @@ -248,15 +259,16 @@ ether_client_read(u8_t *buf, int bufsize) tv.tv_sec = 0; tv.tv_usec = 10000; - ret = select(sc + 1, &fdset, NULL, NULL, &tv); + if(ret == 0) { + /* printf("ret 0\n");*/ return 0; } if(FD_ISSET(sc, &fdset)) { ret = recv(sc, &rxbuffer[0], sizeof(rxbuffer), 0); if(ret == -1) { - perror("ether_client_poll: read"); + perror("ether_client_poll: recv"); return 0; } len = ret; @@ -266,6 +278,8 @@ ether_client_read(u8_t *buf, int bufsize) len, bufsize); len = bufsize; } + + /* printf("Incoming len %d\n", len);*/ memcpy(buf, &rxbuffer[sizeof(struct ether_hdr)], len); radio_sensor_signal = hdr->signal; @@ -281,6 +295,12 @@ ether_client_read(u8_t *buf, int bufsize) if(strength > 0) { sensor_input(&hdr->sensor_data, strength); } + } else if(hdr->type == PTYPE_SERIAL) { + char *ptr = hdr->text; + /* printf("serial input %s\n", ptr);*/ + for(ptr = hdr->text; *ptr != 0; ++ptr) { + serial_input_byte(*ptr); + } } } return 0; @@ -331,6 +351,8 @@ ether_server_poll(void) case PTYPE_DONE: nodes_done(hdr->srcid); break; + case PTYPE_SERIAL: + break; } } /* tv.tv_sec = 0; @@ -599,3 +621,26 @@ ether_send_done(void) } /*-----------------------------------------------------------------------------------*/ +void +ether_send_serial(char *str) +{ + struct ether_hdr hdr; + int len; + + + hdr.srcx = node.x; + hdr.srcy = node.y; + hdr.type = PTYPE_SERIAL; + hdr.srcid = node.id; + len = strlen(str) + 1; + if(len > sizeof(hdr.text)) { + len = sizeof(hdr.text); + } + memcpy(&hdr.text, str, len); + hdr.text[len] = 0; + + /* printf("ether_send_serial '%s' to %d len %d\n", str, nodes_base_node_port, sizeof(struct ether_hdr));*/ + + send_packet((char *)&hdr, sizeof(struct ether_hdr), nodes_base_node_port); +} +/*-----------------------------------------------------------------------------------*/ diff --git a/platform/netsim/ether.h b/platform/netsim/ether.h index 86ee237ff..a49ca3ad0 100644 --- a/platform/netsim/ether.h +++ b/platform/netsim/ether.h @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: ether.h,v 1.6 2007/11/17 18:09:18 adamdunkels Exp $ + * $Id: ether.h,v 1.7 2008/01/14 09:38:16 adamdunkels Exp $ */ #ifndef __ETHER_H__ #define __ETHER_H__ @@ -51,6 +51,7 @@ void ether_send_done(void); u8_t ether_send(char *data, int len); void ether_set_leds(int leds); void ether_set_text(char *text); +void ether_send_serial(char *text); void ether_poll(void); diff --git a/platform/netsim/main.c b/platform/netsim/main.c index 7c7654e8e..3bfd35a79 100644 --- a/platform/netsim/main.c +++ b/platform/netsim/main.c @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: main.c,v 1.10 2008/01/04 23:28:33 oliverschmidt Exp $ + * $Id: main.c,v 1.11 2008/01/14 09:38:16 adamdunkels Exp $ */ /** @@ -123,6 +123,10 @@ start_node(int x, int y, int b) /* This is the sensor process. */ main_process = 0; + + /* Make standard output unbuffered. */ + setvbuf(stdout, (char *)NULL, _IONBF, 0); + srand(getpid()); @@ -137,6 +141,11 @@ start_node(int x, int y, int b) /* NOTREACHED */ } + + if(b) { + nodes_base_node_port = port; + } + /* printf("Adding sensor %d at (%d,%d)\n", pid, x, y);*/ main_process = 1; nodes_add(pid, x, y, port, port - NODES_PORTBASE + 2); @@ -162,13 +171,15 @@ int main(int argc, char **argv) { #ifdef __CYGWIN__ - if(argc < 3 || inet_addr(argv[1]) == INADDR_NONE || - inet_addr(argv[2]) == INADDR_NONE) { - printf("usage: " - "\n"); + if(argc == 3 && + inet_addr(argv[1]) == INADDR_NONE && + inet_addr(argv[2]) == INADDR_NONE) { + printf("usage: %s " + "\n", argv[0]); exit(1); + } else if(argc == 2) { + gwaddr = inet_addr(argv[2]); } - gwaddr = inet_addr(argv[2]); #endif /* __CYGWIN__ */ /* system("ifconfig tap0 inet 192.168.250.1");*/ @@ -194,7 +205,9 @@ main(int argc, char **argv) #endif /* 0 */ #ifdef __CYGWIN__ - if(argc > 3 && strcmp(argv[3], "-q") == 0) { + if(argc > 1 && (strcmp(argv[1], "-q") || + strcmp(argv[2], "-q") || + strcmp(argv[3], "-q")) == 0) { #else /* __CYGWIN__ */ if(argc > 1 && strcmp(argv[1], "-q") == 0) { #endif /* __CYGWIN__ */ diff --git a/platform/netsim/net/ethernode.c b/platform/netsim/net/ethernode.c index b512f6d0d..544b8cd01 100644 --- a/platform/netsim/net/ethernode.c +++ b/platform/netsim/net/ethernode.c @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: ethernode.c,v 1.13 2007/11/28 12:54:42 adamdunkels Exp $ + * $Id: ethernode.c,v 1.14 2008/01/14 09:38:16 adamdunkels Exp $ */ /** * \file @@ -247,8 +247,7 @@ PROCESS_THREAD(ethernode_process, ev, data) PROCESS_BEGIN(); while(1) { - process_poll(ðernode_process); - PROCESS_WAIT_EVENT(); + PROCESS_PAUSE(); if(ethernode_poll()) { if(receiver_callback) { diff --git a/platform/netsim/nodes.c b/platform/netsim/nodes.c index 258498897..1eeeb2d89 100644 --- a/platform/netsim/nodes.c +++ b/platform/netsim/nodes.c @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: nodes.c,v 1.5 2007/11/17 18:09:18 adamdunkels Exp $ + * $Id: nodes.c,v 1.6 2008/01/14 09:38:16 adamdunkels Exp $ */ #include #include @@ -44,6 +44,7 @@ static int numnodes; static struct nodes_node nodes[2000]; +int nodes_base_node_port = 0; /*---------------------------------------------------------------------------*/ void nodes_init(void) diff --git a/platform/netsim/nodes.h b/platform/netsim/nodes.h index fab025a85..eb4e6ea63 100644 --- a/platform/netsim/nodes.h +++ b/platform/netsim/nodes.h @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: nodes.h,v 1.3 2006/10/23 09:01:06 adamdunkels Exp $ + * $Id: nodes.h,v 1.4 2008/01/14 09:38:16 adamdunkels Exp $ */ #ifndef __NODES_H__ #define __NODES_H__ @@ -63,4 +63,6 @@ struct nodes_node { #define NODES_PORTBASE 5000 +extern int nodes_base_node_port; + #endif /* __NODES_H__ */