Added display of radio status: a green ring appears around nodes with their radio turned on. Added a command that prints out a .fig file that shows the current network setup (press the 'd' key).

This commit is contained in:
adamdunkels 2008-05-14 19:22:57 +00:00
parent 1feb4fe3cb
commit 7aa8508e0b
8 changed files with 165 additions and 50 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.8 2008/02/03 20:49:50 adamdunkels Exp $
* $Id: display.c,v 1.9 2008/05/14 19:22:57 adamdunkels Exp $
*
* Author: Adam Dunkels <adam@sics.se>
*
@ -41,6 +41,7 @@
#include <gtk/gtk.h>
#include <sys/time.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
@ -59,12 +60,15 @@ static GdkFont *font;
#define MARK_SIZE 8
#define RADIO_SIZE 20
#define DOT_SIZE ether_strength()
#define DOT_INTENSITY 3
struct dot {
struct dot *next;
int x, y;
int destx, desty;
int size;
int intensity;
};
@ -222,6 +226,17 @@ display_redraw(void)
4, 4);
}
if(n->radio_status) {
gdk_draw_arc(pixmap,
green,
FALSE,
x * SCALE - RADIO_SIZE * SCALE,
y * SCALE - RADIO_SIZE * SCALE,
RADIO_SIZE * 2 * SCALE, RADIO_SIZE * 2 * SCALE,
0, 360 * 64);
}
}
}
@ -351,6 +366,9 @@ key_press_event (GtkWidget * widget, GdkEventKey * event)
gtk_exit(0);
/* exit(0);*/
}
if(event->keyval == 'p') {
display_output_fig();
}
return TRUE;
}
@ -661,3 +679,59 @@ display_run(void)
gtk_main();
}
/*-----------------------------------------------------------------------------------*/
void
display_output_fig(void)
{
int i;
struct nodes_node *n;
int x, y;
int dot_radius = 75;
int scale = 50;
FILE *fp;
char name[40];
struct timeval tv;
gettimeofday(&tv, NULL);
snprintf(name, sizeof(name), "network-%lu.fig", tv.tv_sec);
fp = fopen(name, "w");
fprintf(fp, "#FIG 3.2\n"
"Landscape\n"
"Center\n"
"Inches\n"
"Letter\n"
"100.00\n"
"Single\n"
"-2\n"
"1200 2\n"
);
for(i = 0; i < nodes_num(); ++i) {
n = nodes_node(i);
x = n->x * scale;
y = n->y * scale;
fprintf(fp, "1 3 1 1 0 7 50 -1 0 4.000 1 0.0000 %d %d %d %d %d %d %d %d\n",
x, y,
dot_radius, dot_radius,
x, y,
x + dot_radius, y + dot_radius);
if(strlen(n->text) > 0) {
fprintf(fp, "4 0 0 50 -1 16 18 0.0000 4 135 720 %d %d %s\\001\n",
x + 2 * scale, y, n->text);
}
if(n->linex != 0 && n->liney != 0) {
fprintf(fp, "2 1 1 1 0 7 50 -1 -1 0.000 0 0 -1 0 1 2\n"
"1 1 4.00 60.00 120.00\n"
"%d %d %d %d\n",
x, y,
n->linex * scale, n->liney * scale);
}
}
fclose(fp);
}
/*-----------------------------------------------------------------------------------*/

View File

@ -1,8 +1,8 @@
/*
* Copyright (c) 2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
@ -11,20 +11,20 @@
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* $Id: display.h,v 1.1 2006/06/17 22:41:35 adamdunkels Exp $
* $Id: display.h,v 1.2 2008/05/14 19:22:57 adamdunkels Exp $
*
* Author: Adam Dunkels <adam@sics.se>
*
@ -39,9 +39,6 @@ void display_run(void);
void display_tick(void);
void display_output_fig(void);
#endif /* __DISPLAY_H__ */

View File

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ether.c,v 1.12 2008/02/03 20:49:50 adamdunkels Exp $
* $Id: ether.c,v 1.13 2008/05/14 19:22:58 adamdunkels Exp $
*/
/**
* \file
@ -94,6 +94,7 @@ static int s, sc;
#define PTYPE_TEXT 5
#define PTYPE_DONE 6
#define PTYPE_SERIAL 7
#define PTYPE_RADIO_STATUS 8
#define SERIAL_LEN 80
@ -108,6 +109,7 @@ struct ether_hdr {
int srcid;
int srcnodetype;
int leds;
int radio_status;
char text[NODES_TEXTLEN + SERIAL_LEN];
};
@ -359,6 +361,9 @@ ether_server_poll(void)
break;
case PTYPE_SERIAL:
break;
case PTYPE_RADIO_STATUS:
nodes_set_radio_status(hdr->srcx, hdr->srcy, hdr->radio_status);
break;
}
}
/* tv.tv_sec = 0;
@ -586,6 +591,23 @@ ether_set_text(char *text)
node_send_packet((char *)&hdr, sizeof(struct ether_hdr));
}
/*-----------------------------------------------------------------------------------*/
void
ether_set_radio_status(int onoroff)
{
struct ether_hdr hdr;
hdr.srcx = node.x;
hdr.srcy = node.y;
hdr.type = PTYPE_RADIO_STATUS;
hdr.radio_status = onoroff;
hdr.srcid = node.id;
hdr.linex = linex;
hdr.liney = liney;
node_send_packet((char *)&hdr, sizeof(struct ether_hdr));
}
/*-----------------------------------------------------------------------------------*/
void

View File

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ether.h,v 1.8 2008/02/03 20:49:50 adamdunkels Exp $
* $Id: ether.h,v 1.9 2008/05/14 19:22:58 adamdunkels Exp $
*/
#ifndef __ETHER_H__
#define __ETHER_H__
@ -43,6 +43,7 @@ struct ether_packet {
char data[1500];
int len;
int x, y;
int destx, desty;
};
@ -51,6 +52,8 @@ 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_set_radio_status(int onoroff);
void ether_send_serial(char *text);

View File

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: main.c,v 1.11 2008/01/14 09:38:16 adamdunkels Exp $
* $Id: main.c,v 1.12 2008/05/14 19:22:58 adamdunkels Exp $
*/
/**
@ -177,7 +177,7 @@ main(int argc, char **argv)
printf("usage: %s <ip addr of ethernet card to share> "
"<ip addr of netsim gateway>\n", argv[0]);
exit(1);
} else if(argc == 2) {
} else if(argc >= 2) {
gwaddr = inet_addr(argv[2]);
}
#endif /* __CYGWIN__ */

View File

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ethernode.c,v 1.14 2008/01/14 09:38:16 adamdunkels Exp $
* $Id: ethernode.c,v 1.15 2008/05/14 19:22:58 adamdunkels Exp $
*/
/**
* \file
@ -75,8 +75,20 @@ struct hdr {
u8_t seqno;
};
static int ethernode_on(void) {return 0;}
static int ethernode_safe_off(void) {return 0;}
static int radio_is_on = 1;
static int
ethernode_on(void)
{
radio_is_on = 1;
ether_set_radio_status(radio_is_on);
}
static int
ethernode_safe_off(void)
{
radio_is_on = 0;
ether_set_radio_status(radio_is_on);
}
#include "net/ethernode.h"
@ -157,7 +169,11 @@ ethernode_read(void *buf, unsigned short bufsize)
if(len == 0) {
return 0;
}
if(radio_is_on == 0) {
/* Drop the incoming packet if the simulated radio is switched off. */
return 0;
}
/* printf("ethernode_poll: received data packet with len %d type %d\n", len, hdr->type);*/
switch(hdr->type) {

View File

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: nodes.c,v 1.7 2008/02/03 20:49:50 adamdunkels Exp $
* $Id: nodes.c,v 1.8 2008/05/14 19:22:58 adamdunkels Exp $
*/
#include <signal.h>
#include <stdio.h>
@ -90,44 +90,45 @@ nodes_node(int num)
return &nodes[num];
}
/*---------------------------------------------------------------------------*/
void
nodes_set_leds(int x, int y, int leds)
static struct nodes_node *
find_node(int x, int y)
{
int i;
for(i = numnodes; i >= 0; --i) {
if(nodes[i].x == x && nodes[i].y == y) {
nodes[i].leds = leds;
return;
return &nodes[i];
}
}
return &nodes[0];
}
/*---------------------------------------------------------------------------*/
void
nodes_set_leds(int x, int y, int leds)
{
find_node(x, y)->leds = 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;
}
}
strncpy(find_node(x, y)->text, text, NODES_TEXTLEN);
}
/*---------------------------------------------------------------------------*/
void
nodes_set_radio_status(int x, int y, int radio_status)
{
find_node(x, y)->radio_status = radio_status;
}
/*---------------------------------------------------------------------------*/
void
nodes_set_line(int x, int y, int linex, int liney)
{
int i;
struct nodes_node *n;
for(i = numnodes; i >= 0; --i) {
if(nodes[i].x == x && nodes[i].y == y) {
nodes[i].linex = linex;
nodes[i].liney = liney;
return;
}
}
n = find_node(x, y);
n->linex = linex;
n->liney = liney;
}
/*---------------------------------------------------------------------------*/
struct nodes_node *

View File

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: nodes.h,v 1.5 2008/02/03 20:49:50 adamdunkels Exp $
* $Id: nodes.h,v 1.6 2008/05/14 19:22:58 adamdunkels Exp $
*/
#ifndef __NODES_H__
#define __NODES_H__
@ -45,6 +45,7 @@ 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_set_radio_status(int x, int y, int radio_status);
void nodes_done(int id);
@ -60,6 +61,7 @@ struct nodes_node {
int leds;
int done;
int linex, liney;
int radio_status;
char text[NODES_TEXTLEN];
};