Added a hack for setting a text label on each simulated node

This commit is contained in:
adamdunkels 2006-09-26 22:10:12 +00:00
parent 15aba3d619
commit 58b7f8de5b
7 changed files with 168 additions and 123 deletions

View file

@ -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.1 2006/06/17 22:41:35 adamdunkels Exp $
* $Id: display.c,v 1.2 2006/09/26 22:10:12 adamdunkels Exp $
*
* Author: Adam Dunkels <adam@sics.se>
*
@ -45,7 +45,7 @@
static GdkPixmap *pixmap = NULL;
static GtkWidget *drawing_area;
static GdkFont *font;
#define DISPLAY_WIDTH 400
#define DISPLAY_HEIGHT 300
@ -111,7 +111,7 @@ display_redraw(void)
x = n->x;
y = n->y;
if(n->type == NODE_TYPE_CLUSTERHEAD) {
/* if(n->type == NODE_TYPE_CLUSTERHEAD) {
gdk_draw_arc(pixmap,
intensity_clusterhead_lightgray,
TRUE,
@ -119,7 +119,7 @@ display_redraw(void)
y * SCALE - DOT_SIZE * SCALE,
DOT_SIZE * 2 * SCALE, DOT_SIZE * 2 * SCALE,
0, 360 * 64);
}
}*/
if(n == marked_node) {
gdk_draw_arc(pixmap,
@ -138,7 +138,7 @@ display_redraw(void)
x = n->x;
y = n->y;
if(n->type == NODE_TYPE_CLUSTERHEAD) {
/* if(n->type == NODE_TYPE_CLUSTERHEAD) {
gdk_draw_rectangle(pixmap,
intensity_clusterhead_red,
TRUE,
@ -159,9 +159,18 @@ display_redraw(void)
}
}
} else {
}
} else */ {
if(strlen(n->text) > 0) {
gdk_draw_string(pixmap,
font,
black,
x * SCALE + 2,
y * SCALE - 1,
n->text);
}
gdk_draw_rectangle(pixmap,
black,
TRUE,
@ -498,6 +507,8 @@ display_init(void (* idlefunc)(void), int time, int with_gui)
gtk_signal_connect(GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (quit), NULL);
font = gdk_font_load("-*-courier-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
/* Create the drawing area */
drawing_area = gtk_drawing_area_new();

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ether.c,v 1.1 2006/06/17 22:41:35 adamdunkels Exp $
* $Id: ether.c,v 1.2 2006/09/26 22:10:12 adamdunkels Exp $
*/
/**
* \file
@ -85,6 +85,7 @@ static int s, sc;
#define PTYPE_DATA 2
#define PTYPE_SENSOR 3
#define PTYPE_LEDS 4
#define PTYPE_TEXT 5
struct ether_hdr {
int type;
@ -95,7 +96,9 @@ struct ether_hdr {
int srcid;
int srcnodetype;
int leds;
char text[NODES_TEXTLEN];
};
static int strength;
static int collisions = 1;
@ -207,7 +210,7 @@ ether_client_poll(void)
memcpy(uip_buf, &rxbuffer[sizeof(struct ether_hdr)], len);
if(hdr->type == PTYPE_DATA) {
if(hdr->type == PTYPE_DATA && hdr->srcid != node.id) {
return len - sizeof(struct ether_hdr);
} else if(hdr->type == PTYPE_CLOCK) {
node_set_time(hdr->clock);
@ -262,6 +265,9 @@ ether_server_poll(void)
case PTYPE_LEDS:
nodes_set_leds(hdr->srcx, hdr->srcy, hdr->leds);
break;
case PTYPE_TEXT:
nodes_set_text(hdr->srcx, hdr->srcy, hdr->text);
break;
}
}
/* tv.tv_sec = 0;
@ -334,7 +340,7 @@ ether_tick(void)
/* Update the node type. */
hdr = (struct ether_hdr *)p->data;
nodes_node(hdr->srcid)->type = hdr->srcnodetype;
/* nodes_node(hdr->srcid)->type = hdr->srcnodetype;*/
if(!(p->x == x && p->y == y) && /* Don't send packets back to
the sender. */
@ -363,6 +369,8 @@ ether_tick(void)
}
if(!interference) {
/* printf("ether: delivering packet from %d to %d\n",
hdr->srcid, port);*/
send_packet(p->data, p->len, port);
}
}
@ -419,7 +427,7 @@ ether_send(char *data, int len)
hdr->srcx = node.x;
hdr->srcy = node.y;
hdr->type = PTYPE_DATA;
hdr->srcnodetype = node.type;
/* hdr->srcnodetype = node.type;*/
hdr->srcid = node.id;
@ -437,7 +445,23 @@ ether_set_leds(int leds)
hdr.srcy = node.y;
hdr.type = PTYPE_LEDS;
hdr.leds = leds;
hdr.srcnodetype = node.type;
/* hdr.srcnodetype = node.type;*/
hdr.srcid = node.id;
node_send_packet((char *)&hdr, sizeof(struct ether_hdr));
}
/*-----------------------------------------------------------------------------------*/
void
ether_set_text(char *text)
{
struct ether_hdr hdr;
hdr.srcx = node.x;
hdr.srcy = node.y;
hdr.type = PTYPE_TEXT;
strncpy(hdr.text, text, NODES_TEXTLEN);
/* hdr.srcnodetype = node.type;*/
hdr.srcid = node.id;
node_send_packet((char *)&hdr, sizeof(struct ether_hdr));

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ether.h,v 1.1 2006/06/17 22:41:35 adamdunkels Exp $
* $Id: ether.h,v 1.2 2006/09/26 22:10:12 adamdunkels Exp $
*/
#ifndef __ETHER_H__
#define __ETHER_H__
@ -48,6 +48,7 @@ struct ether_packet {
u8_t ether_send(char *data, int len);
void ether_set_leds(int leds);
void ether_set_text(char *text);
void ether_poll(void);

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: node.c,v 1.2 2006/08/14 14:01:02 bg- Exp $
* $Id: node.c,v 1.3 2006/09/26 22:10:12 adamdunkels Exp $
*/
#include "node.h"
#include "contiki.h"
@ -55,7 +55,7 @@ node_init(int id, int posx, int posy, int b)
node.id = id;
node.x = posx;
node.y = posy;
node.type = NODE_TYPE_NORMAL;
/* node.type = NODE_TYPE_NORMAL;*/
if(b) {
uip_ipaddr(&addr, 192,168,250,2);

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: node.h,v 1.1 2006/06/17 22:41:35 adamdunkels Exp $
* $Id: node.h,v 1.2 2006/09/26 22:10:12 adamdunkels Exp $
*/
#ifndef __NODE_H__
#define __NODE_H__
@ -39,12 +39,6 @@
struct node {
int x, y;
#define NODE_TYPE_NORMAL 1
#define NODE_TYPE_CLUSTERHEAD 2
int type;
/* The node ID is used only during simulation. */
int id;
};

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: nodes.c,v 1.1 2006/06/17 22:41:35 adamdunkels Exp $
* $Id: nodes.c,v 1.2 2006/09/26 22:10:12 adamdunkels Exp $
*/
#include <signal.h>
#include <stdio.h>
@ -99,6 +99,19 @@ nodes_set_leds(int x, int y, int leds)
}
}
/*---------------------------------------------------------------------------*/
void
nodes_set_text(int x, int y, char *text)
{
int i;
for(i = numnodes; i >= 0; --i) {
if(nodes[i].x == x && nodes[i].y == y) {
strncpy(nodes[i].text, text, NODES_TEXTLEN);
return;
}
}
}
/*---------------------------------------------------------------------------*/
struct nodes_node *
nodes_find_pid(pid_t pid)
{

View file

@ -30,18 +30,20 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: nodes.h,v 1.1 2006/06/17 22:41:35 adamdunkels Exp $
* $Id: nodes.h,v 1.2 2006/09/26 22:10:12 adamdunkels Exp $
*/
#ifndef __NODES_H__
#define __NODES_H__
#include <sys/types.h>
#define NODES_TEXTLEN 4
void nodes_init(void);
void nodes_add(int pid, int x, int y, int port);
void nodes_kill(void);
void nodes_set_leds(int x, int y, int leds);
void nodes_set_text(int x, int y, char *text);
int nodes_num(void);
struct nodes_node *nodes_node(int num);
@ -51,8 +53,8 @@ struct nodes_node {
int pid;
int x, y;
int port;
int type;
int leds;
char text[NODES_TEXTLEN];
};
#define NODES_PORTBASE 5000