diff --git a/platform/netsim/contiki-main.c b/platform/netsim/contiki-main.c index 8f6a04e02..44d52ee73 100644 --- a/platform/netsim/contiki-main.c +++ b/platform/netsim/contiki-main.c @@ -30,13 +30,14 @@ * * Author: Adam Dunkels * - * $Id: contiki-main.c,v 1.26 2008/01/14 09:38:16 adamdunkels Exp $ + * $Id: contiki-main.c,v 1.27 2008/02/03 20:49:50 adamdunkels Exp $ */ #include "contiki.h" #include "contiki-net.h" #include "contiki-lib.h" +#include "dev/serial.h" #include "net/rime.h" #ifdef __CYGWIN__ @@ -54,6 +55,10 @@ #include "ether.h" #include +#ifndef HAVE_SNPRINTF +int snprintf(char *str, size_t size, const char *format, ...); +#endif /* HAVE_SNPRINTF */ + #include #include #include diff --git a/platform/netsim/display.c b/platform/netsim/display.c index e3693ec6c..ce88bd593 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.7 2008/01/14 09:38:16 adamdunkels Exp $ + * $Id: display.c,v 1.8 2008/02/03 20:49:50 adamdunkels Exp $ * * Author: Adam Dunkels * @@ -207,6 +207,21 @@ display_redraw(void) y * SCALE + 2, 4, 4); } + if(n->linex != 0 && n->liney != 0) { + gdk_draw_line(pixmap, + green, + x * SCALE, + y * SCALE, + n->linex * SCALE, + n->liney * SCALE); + gdk_draw_rectangle(pixmap, + green, + TRUE, + n->linex * SCALE - 2, + n->liney * SCALE - 2, + 4, 4); + } + } } diff --git a/platform/netsim/ether.c b/platform/netsim/ether.c index 648b8ecbd..ea8ecd83b 100644 --- a/platform/netsim/ether.c +++ b/platform/netsim/ether.c @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: ether.c,v 1.11 2008/01/14 09:38:16 adamdunkels Exp $ + * $Id: ether.c,v 1.12 2008/02/03 20:49:50 adamdunkels Exp $ */ /** * \file @@ -86,6 +86,7 @@ static clock_time_t timer; static int s, sc; +#define PTYPE_NONE 0 #define PTYPE_CLOCK 1 #define PTYPE_DATA 2 #define PTYPE_SENSOR 3 @@ -100,6 +101,7 @@ struct ether_hdr { int type; struct sensor_data sensor_data; clock_time_t clock; + int linex, liney; int signal; int srcx, srcy; int srcpid; @@ -121,6 +123,9 @@ static int num_drops = 0; #include static struct timeval t1; + +static int linex, liney; + /*-----------------------------------------------------------------------------------*/ void ether_print_stats(void) @@ -336,6 +341,7 @@ ether_server_poll(void) perror("ether_poll: read"); return; } + nodes_set_line(hdr->srcx, hdr->srcy, hdr->linex, hdr->liney); switch(hdr->type) { case PTYPE_DATA: PRINTF("ether_poll: read %d bytes from (%d, %d)\n", @@ -538,7 +544,8 @@ ether_send(char *data, int len) /* hdr->srcnodetype = node.type;*/ hdr->srcid = node.id; - + hdr->linex = linex; + hdr->liney = liney; node_send_packet(tmpbuf, len + sizeof(struct ether_hdr)); return UIP_FW_OK; @@ -556,6 +563,8 @@ ether_set_leds(int leds) hdr.leds = leds; /* hdr.srcnodetype = node.type;*/ hdr.srcid = node.id; + hdr.linex = linex; + hdr.liney = liney; node_send_packet((char *)&hdr, sizeof(struct ether_hdr)); @@ -572,6 +581,8 @@ ether_set_text(char *text) strncpy(hdr.text, text, NODES_TEXTLEN); /* hdr.srcnodetype = node.type;*/ hdr.srcid = node.id; + hdr.linex = linex; + hdr.liney = liney; node_send_packet((char *)&hdr, sizeof(struct ether_hdr)); @@ -644,3 +655,22 @@ ether_send_serial(char *str) send_packet((char *)&hdr, sizeof(struct ether_hdr), nodes_base_node_port); } /*-----------------------------------------------------------------------------------*/ +void +ether_set_line(int x, int y) +{ + struct ether_hdr hdr; + + linex = x; + liney = y; + + + hdr.srcx = node.x; + hdr.srcy = node.y; + hdr.type = PTYPE_NONE; + hdr.srcid = node.id; + hdr.linex = linex; + hdr.liney = liney; + + node_send_packet((char *)&hdr, sizeof(struct ether_hdr)); +} +/*-----------------------------------------------------------------------------------*/ diff --git a/platform/netsim/ether.h b/platform/netsim/ether.h index a49ca3ad0..cb42ab73f 100644 --- a/platform/netsim/ether.h +++ b/platform/netsim/ether.h @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: ether.h,v 1.7 2008/01/14 09:38:16 adamdunkels Exp $ + * $Id: ether.h,v 1.8 2008/02/03 20:49:50 adamdunkels Exp $ */ #ifndef __ETHER_H__ #define __ETHER_H__ @@ -83,4 +83,7 @@ void ether_set_drop_probability(double p); void ether_print_stats(void); +void ether_set_line(int x, int y); + + #endif /* __ETHER_H__ */ diff --git a/platform/netsim/nodes.c b/platform/netsim/nodes.c index 1eeeb2d89..d27bf471a 100644 --- a/platform/netsim/nodes.c +++ b/platform/netsim/nodes.c @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: nodes.c,v 1.6 2008/01/14 09:38:16 adamdunkels Exp $ + * $Id: nodes.c,v 1.7 2008/02/03 20:49:50 adamdunkels Exp $ */ #include #include @@ -116,6 +116,20 @@ nodes_set_text(int x, int y, char *text) } } /*---------------------------------------------------------------------------*/ +void +nodes_set_line(int x, int y, int linex, int liney) +{ + int i; + + for(i = numnodes; i >= 0; --i) { + if(nodes[i].x == x && nodes[i].y == y) { + nodes[i].linex = linex; + nodes[i].liney = liney; + return; + } + } +} +/*---------------------------------------------------------------------------*/ struct nodes_node * nodes_find_pid(pid_t pid) { diff --git a/platform/netsim/nodes.h b/platform/netsim/nodes.h index eb4e6ea63..e272d472f 100644 --- a/platform/netsim/nodes.h +++ b/platform/netsim/nodes.h @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: nodes.h,v 1.4 2008/01/14 09:38:16 adamdunkels Exp $ + * $Id: nodes.h,v 1.5 2008/02/03 20:49:50 adamdunkels Exp $ */ #ifndef __NODES_H__ #define __NODES_H__ @@ -44,6 +44,7 @@ void nodes_add(int pid, int x, int y, int port, int id); void nodes_kill(void); void nodes_set_leds(int x, int y, int leds); void nodes_set_text(int x, int y, char *text); +void nodes_set_line(int x, int y, int linex, int liney); void nodes_done(int id); @@ -58,6 +59,7 @@ struct nodes_node { int port; int leds; int done; + int linex, liney; char text[NODES_TEXTLEN]; };