mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-22 10:30:13 +00:00
Added support for (simulated) serial data input. Data written to netsim's standard input are now sent as serial data to the main node.
This commit is contained in:
parent
7fcb1f3b2a
commit
7a356d0fb5
@ -8,8 +8,8 @@ SENSORS = sensors.c beep.c button-sensor.c pir-sensor.c vib-sensor.c \
|
||||
radio-sensor.c irq.c eeprom.c \
|
||||
dummy-sensors.c leds.c leds-arch.c esb-sensors.c
|
||||
NETSIM = cfs-ram.c ether.c ethernode.c ethernode-uip.c lpm.c rs232.c flash.c \
|
||||
node.c nodes.c sensor.c display.c random.c radio.c \
|
||||
dlloader.c main.c netsim-init.c contiki-main.c symtab.c symbols.c tr1001.c tr1001-drv.c
|
||||
node.c nodes.c sensor.c display.c random.c radio.c serial.c \
|
||||
dlloader.c main.c netsim-init.c contiki-main.c symtab.c symbols.c tr1001.c tr1001-drv.c
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
CONTIKI_TARGET_SOURCEFILES = $(NETSIM) $(SENSORS) wpcap-drv.c wpcap.c
|
||||
|
@ -30,7 +30,7 @@
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: contiki-main.c,v 1.25 2008/01/04 23:09:03 oliverschmidt Exp $
|
||||
* $Id: contiki-main.c,v 1.26 2008/01/14 09:38:16 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
@ -64,6 +64,12 @@
|
||||
#include "dev/radio-sensor.h"
|
||||
#include "dev/leds.h"
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
__attribute__((dllimport)) extern int __argc;
|
||||
__attribute__((dllimport)) extern char **__argv[];
|
||||
#endif /* __CYGWIN__ */
|
||||
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
static struct uip_fw_netif extif =
|
||||
{UIP_FW_NETIF(0,0,0,0, 0,0,0,0, wpcap_output)};
|
||||
@ -111,8 +117,10 @@ contiki_main(int flag)
|
||||
|
||||
procinit_init();
|
||||
|
||||
uip_init();
|
||||
serial_init();
|
||||
|
||||
uip_init();
|
||||
|
||||
ctimer_init();
|
||||
rime_init(nullmac_init(ðernode_driver));
|
||||
|
||||
@ -120,17 +128,19 @@ contiki_main(int flag)
|
||||
|
||||
if(flag == 1) {
|
||||
#ifdef __CYGWIN__
|
||||
process_start(&wpcap_process, NULL);
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
snprintf(buf, sizeof(buf), "route add %d.%d.%d.%d mask %d.%d.%d.%d %d.%d.%d.%d",
|
||||
uip_ipaddr_to_quad(&meshif.ipaddr),
|
||||
uip_ipaddr_to_quad(&meshif.netmask),
|
||||
uip_ipaddr_to_quad(&uip_hostaddr));
|
||||
printf("%s\n", buf);
|
||||
system(buf);
|
||||
signal(SIGTERM, remove_route);
|
||||
if(__argc > 2 && (*__argv)[1][0] != '-') {
|
||||
process_start(&wpcap_process, NULL);
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
snprintf(buf, sizeof(buf), "route add %d.%d.%d.%d mask %d.%d.%d.%d %d.%d.%d.%d",
|
||||
uip_ipaddr_to_quad(&meshif.ipaddr),
|
||||
uip_ipaddr_to_quad(&meshif.netmask),
|
||||
uip_ipaddr_to_quad(&uip_hostaddr));
|
||||
printf("%s\n", buf);
|
||||
system(buf);
|
||||
signal(SIGTERM, remove_route);
|
||||
}
|
||||
}
|
||||
#else /* __CYGWIN__ */
|
||||
process_start(&tapdev_process, NULL);
|
||||
|
@ -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.6 2007/11/17 18:09:18 adamdunkels Exp $
|
||||
* $Id: display.c,v 1.7 2008/01/14 09:38:16 adamdunkels Exp $
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
@ -43,6 +43,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static GdkPixmap *pixmap = NULL;
|
||||
static GtkWidget *drawing_area;
|
||||
@ -486,6 +487,17 @@ get_color(unsigned short r, unsigned short g, unsigned short b)
|
||||
GDK_GC_FOREGROUND);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
stdin_callback(gpointer data, gint source, GdkInputCondition condition)
|
||||
{
|
||||
char buf[1000];
|
||||
int len;
|
||||
|
||||
len = read(STDIN_FILENO, &buf, sizeof(buf));
|
||||
buf[len] = 0;
|
||||
ether_send_serial(buf);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
display_init(void (* idlefunc)(void), int time, int with_gui)
|
||||
{
|
||||
@ -624,6 +636,8 @@ display_init(void (* idlefunc)(void), int time, int with_gui)
|
||||
black = get_color(0, 0, 0);
|
||||
white = get_color(0xffff, 0xffff, 0xffff);
|
||||
}
|
||||
|
||||
gdk_input_add(STDIN_FILENO, GDK_INPUT_READ, stdin_callback, NULL);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
|
@ -30,7 +30,7 @@
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: ether.c,v 1.10 2007/11/17 18:09:18 adamdunkels Exp $
|
||||
* $Id: ether.c,v 1.11 2008/01/14 09:38:16 adamdunkels Exp $
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
@ -61,6 +61,8 @@
|
||||
|
||||
#include "dev/radio-sensor.h"
|
||||
|
||||
#include "dev/serial.h"
|
||||
|
||||
#include "sensor.h"
|
||||
|
||||
#include "node.h"
|
||||
@ -90,6 +92,9 @@ static int s, sc;
|
||||
#define PTYPE_LEDS 4
|
||||
#define PTYPE_TEXT 5
|
||||
#define PTYPE_DONE 6
|
||||
#define PTYPE_SERIAL 7
|
||||
|
||||
#define SERIAL_LEN 80
|
||||
|
||||
struct ether_hdr {
|
||||
int type;
|
||||
@ -101,7 +106,7 @@ struct ether_hdr {
|
||||
int srcid;
|
||||
int srcnodetype;
|
||||
int leds;
|
||||
char text[NODES_TEXTLEN];
|
||||
char text[NODES_TEXTLEN + SERIAL_LEN];
|
||||
};
|
||||
|
||||
static int strength;
|
||||
@ -211,7 +216,7 @@ ether_client_init(int port)
|
||||
|
||||
sa.sin_port = htons(port);
|
||||
|
||||
/* printf("ether_client_init: binding id %d to port %d\n", id, PORTBASE + id);*/
|
||||
/* printf("ether_client_init: binding to port %d\n", port);*/
|
||||
if(bind(sc, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
|
||||
printf("Bind to port %d\n", port);
|
||||
perror("bind");
|
||||
@ -224,6 +229,7 @@ ether_client_poll(void)
|
||||
{
|
||||
fd_set fdset;
|
||||
struct timeval tv;
|
||||
int ret;
|
||||
|
||||
FD_ZERO(&fdset);
|
||||
FD_SET(sc, &fdset);
|
||||
@ -231,7 +237,12 @@ ether_client_poll(void)
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 10000;
|
||||
|
||||
return select(sc + 1, &fdset, NULL, NULL, &tv);
|
||||
ret = select(sc + 1, &fdset, NULL, NULL, &tv);
|
||||
|
||||
if(ret < 0) {
|
||||
perror("ether_client_poll: select");
|
||||
}
|
||||
return ret == 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
u16_t
|
||||
@ -248,15 +259,16 @@ ether_client_read(u8_t *buf, int bufsize)
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 10000;
|
||||
|
||||
|
||||
ret = select(sc + 1, &fdset, NULL, NULL, &tv);
|
||||
|
||||
if(ret == 0) {
|
||||
/* printf("ret 0\n");*/
|
||||
return 0;
|
||||
}
|
||||
if(FD_ISSET(sc, &fdset)) {
|
||||
ret = recv(sc, &rxbuffer[0], sizeof(rxbuffer), 0);
|
||||
if(ret == -1) {
|
||||
perror("ether_client_poll: read");
|
||||
perror("ether_client_poll: recv");
|
||||
return 0;
|
||||
}
|
||||
len = ret;
|
||||
@ -266,6 +278,8 @@ ether_client_read(u8_t *buf, int bufsize)
|
||||
len, bufsize);
|
||||
len = bufsize;
|
||||
}
|
||||
|
||||
/* printf("Incoming len %d\n", len);*/
|
||||
memcpy(buf, &rxbuffer[sizeof(struct ether_hdr)], len);
|
||||
radio_sensor_signal = hdr->signal;
|
||||
|
||||
@ -281,6 +295,12 @@ ether_client_read(u8_t *buf, int bufsize)
|
||||
if(strength > 0) {
|
||||
sensor_input(&hdr->sensor_data, strength);
|
||||
}
|
||||
} else if(hdr->type == PTYPE_SERIAL) {
|
||||
char *ptr = hdr->text;
|
||||
/* printf("serial input %s\n", ptr);*/
|
||||
for(ptr = hdr->text; *ptr != 0; ++ptr) {
|
||||
serial_input_byte(*ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@ -331,6 +351,8 @@ ether_server_poll(void)
|
||||
case PTYPE_DONE:
|
||||
nodes_done(hdr->srcid);
|
||||
break;
|
||||
case PTYPE_SERIAL:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* tv.tv_sec = 0;
|
||||
@ -599,3 +621,26 @@ ether_send_done(void)
|
||||
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
ether_send_serial(char *str)
|
||||
{
|
||||
struct ether_hdr hdr;
|
||||
int len;
|
||||
|
||||
|
||||
hdr.srcx = node.x;
|
||||
hdr.srcy = node.y;
|
||||
hdr.type = PTYPE_SERIAL;
|
||||
hdr.srcid = node.id;
|
||||
len = strlen(str) + 1;
|
||||
if(len > sizeof(hdr.text)) {
|
||||
len = sizeof(hdr.text);
|
||||
}
|
||||
memcpy(&hdr.text, str, len);
|
||||
hdr.text[len] = 0;
|
||||
|
||||
/* printf("ether_send_serial '%s' to %d len %d\n", str, nodes_base_node_port, sizeof(struct ether_hdr));*/
|
||||
|
||||
send_packet((char *)&hdr, sizeof(struct ether_hdr), nodes_base_node_port);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
@ -30,7 +30,7 @@
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: ether.h,v 1.6 2007/11/17 18:09:18 adamdunkels Exp $
|
||||
* $Id: ether.h,v 1.7 2008/01/14 09:38:16 adamdunkels Exp $
|
||||
*/
|
||||
#ifndef __ETHER_H__
|
||||
#define __ETHER_H__
|
||||
@ -51,6 +51,7 @@ 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_send_serial(char *text);
|
||||
|
||||
|
||||
void ether_poll(void);
|
||||
|
@ -30,7 +30,7 @@
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: main.c,v 1.10 2008/01/04 23:28:33 oliverschmidt Exp $
|
||||
* $Id: main.c,v 1.11 2008/01/14 09:38:16 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -123,6 +123,10 @@ start_node(int x, int y, int b)
|
||||
|
||||
/* This is the sensor process. */
|
||||
main_process = 0;
|
||||
|
||||
/* Make standard output unbuffered. */
|
||||
setvbuf(stdout, (char *)NULL, _IONBF, 0);
|
||||
|
||||
|
||||
srand(getpid());
|
||||
|
||||
@ -137,6 +141,11 @@ start_node(int x, int y, int b)
|
||||
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
if(b) {
|
||||
nodes_base_node_port = port;
|
||||
}
|
||||
|
||||
/* printf("Adding sensor %d at (%d,%d)\n", pid, x, y);*/
|
||||
main_process = 1;
|
||||
nodes_add(pid, x, y, port, port - NODES_PORTBASE + 2);
|
||||
@ -162,13 +171,15 @@ int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
#ifdef __CYGWIN__
|
||||
if(argc < 3 || inet_addr(argv[1]) == INADDR_NONE ||
|
||||
inet_addr(argv[2]) == INADDR_NONE) {
|
||||
printf("usage: <program> <ip addr of ethernet card to share> "
|
||||
"<ip addr of netsim gateway>\n");
|
||||
if(argc == 3 &&
|
||||
inet_addr(argv[1]) == INADDR_NONE &&
|
||||
inet_addr(argv[2]) == INADDR_NONE) {
|
||||
printf("usage: %s <ip addr of ethernet card to share> "
|
||||
"<ip addr of netsim gateway>\n", argv[0]);
|
||||
exit(1);
|
||||
} else if(argc == 2) {
|
||||
gwaddr = inet_addr(argv[2]);
|
||||
}
|
||||
gwaddr = inet_addr(argv[2]);
|
||||
#endif /* __CYGWIN__ */
|
||||
|
||||
/* system("ifconfig tap0 inet 192.168.250.1");*/
|
||||
@ -194,7 +205,9 @@ main(int argc, char **argv)
|
||||
#endif /* 0 */
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
if(argc > 3 && strcmp(argv[3], "-q") == 0) {
|
||||
if(argc > 1 && (strcmp(argv[1], "-q") ||
|
||||
strcmp(argv[2], "-q") ||
|
||||
strcmp(argv[3], "-q")) == 0) {
|
||||
#else /* __CYGWIN__ */
|
||||
if(argc > 1 && strcmp(argv[1], "-q") == 0) {
|
||||
#endif /* __CYGWIN__ */
|
||||
|
@ -30,7 +30,7 @@
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: ethernode.c,v 1.13 2007/11/28 12:54:42 adamdunkels Exp $
|
||||
* $Id: ethernode.c,v 1.14 2008/01/14 09:38:16 adamdunkels Exp $
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
@ -247,8 +247,7 @@ PROCESS_THREAD(ethernode_process, ev, data)
|
||||
PROCESS_BEGIN();
|
||||
|
||||
while(1) {
|
||||
process_poll(ðernode_process);
|
||||
PROCESS_WAIT_EVENT();
|
||||
PROCESS_PAUSE();
|
||||
|
||||
if(ethernode_poll()) {
|
||||
if(receiver_callback) {
|
||||
|
@ -30,7 +30,7 @@
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: nodes.c,v 1.5 2007/11/17 18:09:18 adamdunkels Exp $
|
||||
* $Id: nodes.c,v 1.6 2008/01/14 09:38:16 adamdunkels Exp $
|
||||
*/
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
@ -44,6 +44,7 @@ static int numnodes;
|
||||
|
||||
static struct nodes_node nodes[2000];
|
||||
|
||||
int nodes_base_node_port = 0;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
nodes_init(void)
|
||||
|
@ -30,7 +30,7 @@
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: nodes.h,v 1.3 2006/10/23 09:01:06 adamdunkels Exp $
|
||||
* $Id: nodes.h,v 1.4 2008/01/14 09:38:16 adamdunkels Exp $
|
||||
*/
|
||||
#ifndef __NODES_H__
|
||||
#define __NODES_H__
|
||||
@ -63,4 +63,6 @@ struct nodes_node {
|
||||
|
||||
#define NODES_PORTBASE 5000
|
||||
|
||||
extern int nodes_base_node_port;
|
||||
|
||||
#endif /* __NODES_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user