mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-08-28 07:28:58 +00:00
Added a hack for setting a text label on each simulated node
This commit is contained in:
parent
15aba3d619
commit
58b7f8de5b
@ -24,7 +24,7 @@
|
|||||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||||
* OF SUCH DAMAGE.
|
* 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>
|
* Author: Adam Dunkels <adam@sics.se>
|
||||||
*
|
*
|
||||||
@ -45,7 +45,7 @@
|
|||||||
|
|
||||||
static GdkPixmap *pixmap = NULL;
|
static GdkPixmap *pixmap = NULL;
|
||||||
static GtkWidget *drawing_area;
|
static GtkWidget *drawing_area;
|
||||||
|
static GdkFont *font;
|
||||||
|
|
||||||
#define DISPLAY_WIDTH 400
|
#define DISPLAY_WIDTH 400
|
||||||
#define DISPLAY_HEIGHT 300
|
#define DISPLAY_HEIGHT 300
|
||||||
@ -111,7 +111,7 @@ display_redraw(void)
|
|||||||
x = n->x;
|
x = n->x;
|
||||||
y = n->y;
|
y = n->y;
|
||||||
|
|
||||||
if(n->type == NODE_TYPE_CLUSTERHEAD) {
|
/* if(n->type == NODE_TYPE_CLUSTERHEAD) {
|
||||||
gdk_draw_arc(pixmap,
|
gdk_draw_arc(pixmap,
|
||||||
intensity_clusterhead_lightgray,
|
intensity_clusterhead_lightgray,
|
||||||
TRUE,
|
TRUE,
|
||||||
@ -119,7 +119,7 @@ display_redraw(void)
|
|||||||
y * SCALE - DOT_SIZE * SCALE,
|
y * SCALE - DOT_SIZE * SCALE,
|
||||||
DOT_SIZE * 2 * SCALE, DOT_SIZE * 2 * SCALE,
|
DOT_SIZE * 2 * SCALE, DOT_SIZE * 2 * SCALE,
|
||||||
0, 360 * 64);
|
0, 360 * 64);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
if(n == marked_node) {
|
if(n == marked_node) {
|
||||||
gdk_draw_arc(pixmap,
|
gdk_draw_arc(pixmap,
|
||||||
@ -138,7 +138,7 @@ display_redraw(void)
|
|||||||
x = n->x;
|
x = n->x;
|
||||||
y = n->y;
|
y = n->y;
|
||||||
|
|
||||||
if(n->type == NODE_TYPE_CLUSTERHEAD) {
|
/* if(n->type == NODE_TYPE_CLUSTERHEAD) {
|
||||||
gdk_draw_rectangle(pixmap,
|
gdk_draw_rectangle(pixmap,
|
||||||
intensity_clusterhead_red,
|
intensity_clusterhead_red,
|
||||||
TRUE,
|
TRUE,
|
||||||
@ -160,8 +160,17 @@ 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,
|
gdk_draw_rectangle(pixmap,
|
||||||
black,
|
black,
|
||||||
TRUE,
|
TRUE,
|
||||||
@ -498,6 +507,8 @@ display_init(void (* idlefunc)(void), int time, int with_gui)
|
|||||||
gtk_signal_connect(GTK_OBJECT (window), "destroy",
|
gtk_signal_connect(GTK_OBJECT (window), "destroy",
|
||||||
GTK_SIGNAL_FUNC (quit), NULL);
|
GTK_SIGNAL_FUNC (quit), NULL);
|
||||||
|
|
||||||
|
font = gdk_font_load("-*-courier-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
|
||||||
|
|
||||||
/* Create the drawing area */
|
/* Create the drawing area */
|
||||||
|
|
||||||
drawing_area = gtk_drawing_area_new();
|
drawing_area = gtk_drawing_area_new();
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
* Author: Adam Dunkels <adam@sics.se>
|
* 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
|
* \file
|
||||||
@ -85,6 +85,7 @@ static int s, sc;
|
|||||||
#define PTYPE_DATA 2
|
#define PTYPE_DATA 2
|
||||||
#define PTYPE_SENSOR 3
|
#define PTYPE_SENSOR 3
|
||||||
#define PTYPE_LEDS 4
|
#define PTYPE_LEDS 4
|
||||||
|
#define PTYPE_TEXT 5
|
||||||
|
|
||||||
struct ether_hdr {
|
struct ether_hdr {
|
||||||
int type;
|
int type;
|
||||||
@ -95,7 +96,9 @@ struct ether_hdr {
|
|||||||
int srcid;
|
int srcid;
|
||||||
int srcnodetype;
|
int srcnodetype;
|
||||||
int leds;
|
int leds;
|
||||||
|
char text[NODES_TEXTLEN];
|
||||||
};
|
};
|
||||||
|
|
||||||
static int strength;
|
static int strength;
|
||||||
|
|
||||||
static int collisions = 1;
|
static int collisions = 1;
|
||||||
@ -207,7 +210,7 @@ ether_client_poll(void)
|
|||||||
|
|
||||||
memcpy(uip_buf, &rxbuffer[sizeof(struct ether_hdr)], len);
|
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);
|
return len - sizeof(struct ether_hdr);
|
||||||
} else if(hdr->type == PTYPE_CLOCK) {
|
} else if(hdr->type == PTYPE_CLOCK) {
|
||||||
node_set_time(hdr->clock);
|
node_set_time(hdr->clock);
|
||||||
@ -262,6 +265,9 @@ ether_server_poll(void)
|
|||||||
case PTYPE_LEDS:
|
case PTYPE_LEDS:
|
||||||
nodes_set_leds(hdr->srcx, hdr->srcy, hdr->leds);
|
nodes_set_leds(hdr->srcx, hdr->srcy, hdr->leds);
|
||||||
break;
|
break;
|
||||||
|
case PTYPE_TEXT:
|
||||||
|
nodes_set_text(hdr->srcx, hdr->srcy, hdr->text);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* tv.tv_sec = 0;
|
/* tv.tv_sec = 0;
|
||||||
@ -334,7 +340,7 @@ ether_tick(void)
|
|||||||
|
|
||||||
/* Update the node type. */
|
/* Update the node type. */
|
||||||
hdr = (struct ether_hdr *)p->data;
|
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
|
if(!(p->x == x && p->y == y) && /* Don't send packets back to
|
||||||
the sender. */
|
the sender. */
|
||||||
@ -363,6 +369,8 @@ ether_tick(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!interference) {
|
if(!interference) {
|
||||||
|
/* printf("ether: delivering packet from %d to %d\n",
|
||||||
|
hdr->srcid, port);*/
|
||||||
send_packet(p->data, p->len, port);
|
send_packet(p->data, p->len, port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -419,7 +427,7 @@ ether_send(char *data, int len)
|
|||||||
hdr->srcx = node.x;
|
hdr->srcx = node.x;
|
||||||
hdr->srcy = node.y;
|
hdr->srcy = node.y;
|
||||||
hdr->type = PTYPE_DATA;
|
hdr->type = PTYPE_DATA;
|
||||||
hdr->srcnodetype = node.type;
|
/* hdr->srcnodetype = node.type;*/
|
||||||
hdr->srcid = node.id;
|
hdr->srcid = node.id;
|
||||||
|
|
||||||
|
|
||||||
@ -437,7 +445,23 @@ ether_set_leds(int leds)
|
|||||||
hdr.srcy = node.y;
|
hdr.srcy = node.y;
|
||||||
hdr.type = PTYPE_LEDS;
|
hdr.type = PTYPE_LEDS;
|
||||||
hdr.leds = 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;
|
hdr.srcid = node.id;
|
||||||
|
|
||||||
node_send_packet((char *)&hdr, sizeof(struct ether_hdr));
|
node_send_packet((char *)&hdr, sizeof(struct ether_hdr));
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
* Author: Adam Dunkels <adam@sics.se>
|
* 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__
|
#ifndef __ETHER_H__
|
||||||
#define __ETHER_H__
|
#define __ETHER_H__
|
||||||
@ -48,6 +48,7 @@ struct ether_packet {
|
|||||||
|
|
||||||
u8_t ether_send(char *data, int len);
|
u8_t ether_send(char *data, int len);
|
||||||
void ether_set_leds(int leds);
|
void ether_set_leds(int leds);
|
||||||
|
void ether_set_text(char *text);
|
||||||
|
|
||||||
|
|
||||||
void ether_poll(void);
|
void ether_poll(void);
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
* Author: Adam Dunkels <adam@sics.se>
|
* 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 "node.h"
|
||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
@ -55,7 +55,7 @@ node_init(int id, int posx, int posy, int b)
|
|||||||
node.id = id;
|
node.id = id;
|
||||||
node.x = posx;
|
node.x = posx;
|
||||||
node.y = posy;
|
node.y = posy;
|
||||||
node.type = NODE_TYPE_NORMAL;
|
/* node.type = NODE_TYPE_NORMAL;*/
|
||||||
|
|
||||||
if(b) {
|
if(b) {
|
||||||
uip_ipaddr(&addr, 192,168,250,2);
|
uip_ipaddr(&addr, 192,168,250,2);
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
* Author: Adam Dunkels <adam@sics.se>
|
* 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__
|
#ifndef __NODE_H__
|
||||||
#define __NODE_H__
|
#define __NODE_H__
|
||||||
@ -39,12 +39,6 @@
|
|||||||
|
|
||||||
struct node {
|
struct node {
|
||||||
int x, y;
|
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;
|
int id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
* Author: Adam Dunkels <adam@sics.se>
|
* 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 <signal.h>
|
||||||
#include <stdio.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 *
|
struct nodes_node *
|
||||||
nodes_find_pid(pid_t pid)
|
nodes_find_pid(pid_t pid)
|
||||||
{
|
{
|
||||||
|
@ -30,18 +30,20 @@
|
|||||||
*
|
*
|
||||||
* Author: Adam Dunkels <adam@sics.se>
|
* 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__
|
#ifndef __NODES_H__
|
||||||
#define __NODES_H__
|
#define __NODES_H__
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#define NODES_TEXTLEN 4
|
||||||
|
|
||||||
void nodes_init(void);
|
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);
|
||||||
void nodes_kill(void);
|
void nodes_kill(void);
|
||||||
void nodes_set_leds(int x, int y, int leds);
|
void nodes_set_leds(int x, int y, int leds);
|
||||||
|
void nodes_set_text(int x, int y, char *text);
|
||||||
|
|
||||||
int nodes_num(void);
|
int nodes_num(void);
|
||||||
struct nodes_node *nodes_node(int num);
|
struct nodes_node *nodes_node(int num);
|
||||||
@ -51,8 +53,8 @@ struct nodes_node {
|
|||||||
int pid;
|
int pid;
|
||||||
int x, y;
|
int x, y;
|
||||||
int port;
|
int port;
|
||||||
int type;
|
|
||||||
int leds;
|
int leds;
|
||||||
|
char text[NODES_TEXTLEN];
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NODES_PORTBASE 5000
|
#define NODES_PORTBASE 5000
|
||||||
|
Loading…
Reference in New Issue
Block a user