diff --git a/platform/netsim/contiki-main.c b/platform/netsim/contiki-main.c index 09e273d9f..6fc2842b9 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.3 2006/10/06 08:25:30 adamdunkels Exp $ + * $Id: contiki-main.c,v 1.4 2006/10/23 09:01:06 adamdunkels Exp $ */ #include "contiki.h" @@ -147,7 +147,7 @@ idle(void) void contiki_main(int flag) { - random_init(0); + random_init(getpid()); leds_init(); diff --git a/platform/netsim/display.c b/platform/netsim/display.c index 397bda1c3..2f43102a6 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.3 2006/10/06 08:25:30 adamdunkels Exp $ + * $Id: display.c,v 1.4 2006/10/23 09:01:06 adamdunkels Exp $ * * Author: Adam Dunkels * @@ -251,8 +251,8 @@ display_tick(void) } else { e = NULL; } - if(d->size > 40) { - d->size -= 8; + if(d->size > 20) { + d->size /= 2; } else { d->size -= 4; } diff --git a/platform/netsim/ether.c b/platform/netsim/ether.c index 85df30a01..416e61282 100644 --- a/platform/netsim/ether.c +++ b/platform/netsim/ether.c @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: ether.c,v 1.3 2006/10/06 08:25:30 adamdunkels Exp $ + * $Id: ether.c,v 1.4 2006/10/23 09:01:06 adamdunkels Exp $ */ /** * \file @@ -88,6 +88,7 @@ static int s, sc; #define PTYPE_SENSOR 3 #define PTYPE_LEDS 4 #define PTYPE_TEXT 5 +#define PTYPE_DONE 6 struct ether_hdr { int type; @@ -106,7 +107,23 @@ static int strength; static int collisions = 1; static int num_collisions = 0; +static int num_packets = 0; +#include + +static struct timeval t1; +/*-----------------------------------------------------------------------------------*/ +void +ether_print_stats(void) +{ + unsigned long time; + struct timeval t2; + gettimeofday(&t2, NULL); + + time = (t2.tv_sec * 1000 + t2.tv_usec / 1000) - + (t1.tv_sec * 1000 + t1.tv_usec / 1000); + printf("%d, %d, %f\n", num_packets, num_collisions, time/1000.0); +} /*-----------------------------------------------------------------------------------*/ void ether_set_collisions(int c) @@ -130,7 +147,9 @@ void ether_server_init(void) { struct sockaddr_in sa; - + + gettimeofday(&t1, NULL); + memb_init(&packets); list_init(active_packets); @@ -273,6 +292,9 @@ ether_server_poll(void) case PTYPE_TEXT: nodes_set_text(hdr->srcx, hdr->srcy, hdr->text); break; + case PTYPE_DONE: + nodes_done(hdr->srcid); + break; } } /* tv.tv_sec = 0; @@ -342,7 +364,9 @@ ether_tick(void) /* Go through all active packets to see if anyone is sent within range of this node. */ for(p = list_head(active_packets); p != NULL; p = p->next) { - + + num_packets++; + /* Update the node type. */ hdr = (struct ether_hdr *)p->data; /* nodes_node(hdr->srcid)->type = hdr->srcnodetype;*/ @@ -511,3 +535,17 @@ ether_send_sensor_data(struct sensor_data *d, int srcx, int srcy, int strength) } /*-----------------------------------------------------------------------------------*/ +void +ether_send_done(void) +{ + struct ether_hdr hdr; + + hdr.srcx = node.x; + hdr.srcy = node.y; + hdr.type = PTYPE_DONE; + hdr.srcid = node.id; + + node_send_packet((char *)&hdr, sizeof(struct ether_hdr)); + +} +/*-----------------------------------------------------------------------------------*/ diff --git a/platform/netsim/ether.h b/platform/netsim/ether.h index 1a48f6838..354626e0c 100644 --- a/platform/netsim/ether.h +++ b/platform/netsim/ether.h @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: ether.h,v 1.2 2006/09/26 22:10:12 adamdunkels Exp $ + * $Id: ether.h,v 1.3 2006/10/23 09:01:06 adamdunkels Exp $ */ #ifndef __ETHER_H__ #define __ETHER_H__ @@ -46,6 +46,8 @@ struct ether_packet { }; +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); diff --git a/platform/netsim/main.c b/platform/netsim/main.c index a69aa921d..74018bca8 100644 --- a/platform/netsim/main.c +++ b/platform/netsim/main.c @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: main.c,v 1.3 2006/10/06 08:25:30 adamdunkels Exp $ + * $Id: main.c,v 1.4 2006/10/23 09:01:06 adamdunkels Exp $ */ /** @@ -123,7 +123,7 @@ start_node(int x, int y, int b) usleep(1000 * ((random() & 0x0f) << 6) ); - node_init(port - NODES_PORTBASE + 1, x, y, b); + node_init(port - NODES_PORTBASE + 2, x, y, b); ethernode_init(port); @@ -134,11 +134,11 @@ start_node(int x, int y, int b) } /* printf("Adding sensor %d at (%d,%d)\n", pid, x, y);*/ main_process = 1; - nodes_add(pid, x, y, port); + nodes_add(pid, x, y, port, port - NODES_PORTBASE + 2); ++port; - return port - NODES_PORTBASE; + return port - NODES_PORTBASE + 1; } /*---------------------------------------------------------------------------*/ int diff --git a/platform/netsim/net/ethernode.c b/platform/netsim/net/ethernode.c index f20e0a7ae..aa4d3ead5 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.2 2006/10/06 08:25:31 adamdunkels Exp $ + * $Id: ethernode.c,v 1.3 2006/10/23 09:01:06 adamdunkels Exp $ */ /** * \file @@ -181,7 +181,7 @@ ethernode_send(void) dest = ID_BROADCAST; - /* usleep(800 * (random_rand() % 1000));*/ + usleep(100 * (random_rand() % 1000)); do_send(TYPE_DATA, dest, hdr, len); diff --git a/platform/netsim/node.h b/platform/netsim/node.h index fbe8de2d1..4f72437e1 100644 --- a/platform/netsim/node.h +++ b/platform/netsim/node.h @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: node.h,v 1.2 2006/09/26 22:10:12 adamdunkels Exp $ + * $Id: node.h,v 1.3 2006/10/23 09:01:06 adamdunkels Exp $ */ #ifndef __NODE_H__ #define __NODE_H__ @@ -54,4 +54,5 @@ int node_y(void); void node_log(const char *fmt, ...); + #endif /* __NODE_H__ */ diff --git a/platform/netsim/nodes.c b/platform/netsim/nodes.c index a874389d4..4e38d67e6 100644 --- a/platform/netsim/nodes.c +++ b/platform/netsim/nodes.c @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: nodes.c,v 1.2 2006/09/26 22:10:12 adamdunkels Exp $ + * $Id: nodes.c,v 1.3 2006/10/23 09:01:06 adamdunkels Exp $ */ #include #include @@ -51,13 +51,15 @@ nodes_init(void) } /*---------------------------------------------------------------------------*/ void -nodes_add(int pid, int x, int y, int port) +nodes_add(int pid, int x, int y, int port, int id) { nodes[numnodes].pid = pid; nodes[numnodes].x = x; nodes[numnodes].y = y; nodes[numnodes].port = port; nodes[numnodes].leds = 0; + nodes[numnodes].done = 0; + nodes[numnodes].id = id; ++numnodes; } /*---------------------------------------------------------------------------*/ @@ -126,3 +128,24 @@ nodes_find_pid(pid_t pid) return NULL; } /*---------------------------------------------------------------------------*/ +void +nodes_done(int id) +{ + int i; + int num_done = 0; + + for(i = numnodes; i >= 0; --i) { + if(nodes[i].id == id) { + nodes[i].done = 1; + } + if(nodes[i].done != 0) { + num_done++; + } + } + + if(num_done == numnodes) { + ether_print_stats(); + exit(0); + } +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/netsim/nodes.h b/platform/netsim/nodes.h index a0b434023..fab025a85 100644 --- a/platform/netsim/nodes.h +++ b/platform/netsim/nodes.h @@ -30,30 +30,34 @@ * * Author: Adam Dunkels * - * $Id: nodes.h,v 1.2 2006/09/26 22:10:12 adamdunkels Exp $ + * $Id: nodes.h,v 1.3 2006/10/23 09:01:06 adamdunkels Exp $ */ #ifndef __NODES_H__ #define __NODES_H__ #include -#define NODES_TEXTLEN 4 +#define NODES_TEXTLEN 10 void nodes_init(void); -void nodes_add(int pid, int x, int y, int port); +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_done(int id); + int nodes_num(void); struct nodes_node *nodes_node(int num); struct nodes_node *nodes_find_pid(pid_t pid); struct nodes_node { int pid; + int id; int x, y; int port; int leds; + int done; char text[NODES_TEXTLEN]; };