Updated netsim to new netstack API

This commit is contained in:
adamdunkels 2010-02-23 18:44:08 +00:00
parent 08f06d8039
commit 69a5b67523
4 changed files with 83 additions and 35 deletions

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: contiki-main.c,v 1.35 2010/02/18 23:19:03 adamdunkels Exp $
* $Id: contiki-main.c,v 1.36 2010/02/23 18:44:08 adamdunkels Exp $
*/
#include "contiki.h"
@ -127,7 +127,8 @@ contiki_main(int flag)
ctimer_init();
netstack_init();
NETSTACK_MAC.init();
NETSTACK_RDC.init();
uip_over_mesh_init(2);
uip_over_mesh_set_net(&meshif.ipaddr, &meshif.netmask);

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.9 2008/05/14 19:22:57 adamdunkels Exp $
* $Id: display.c,v 1.10 2010/02/23 18:44:08 adamdunkels Exp $
*
* Author: Adam Dunkels <adam@sics.se>
*
@ -525,8 +525,9 @@ stdin_callback(gpointer data, gint source, GdkInputCondition condition)
{
char buf[1000];
int len;
len = read(STDIN_FILENO, &buf, sizeof(buf));
printf("read len %d\n", len);
buf[len] = 0;
ether_send_serial(buf);
}

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ether.c,v 1.15 2009/03/17 15:56:32 adamdunkels Exp $
* $Id: ether.c,v 1.16 2010/02/23 18:44:08 adamdunkels Exp $
*/
/**
* \file
@ -242,7 +242,7 @@ ether_client_poll(void)
FD_SET(sc, &fdset);
tv.tv_sec = 0;
tv.tv_usec = 10000;
tv.tv_usec = 1000;
ret = select(sc + 1, &fdset, NULL, NULL, &tv);

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ethernode.c,v 1.16 2008/08/15 19:54:58 adamdunkels Exp $
* $Id: ethernode.c,v 1.17 2010/02/23 18:44:08 adamdunkels Exp $
*/
/**
* \file
@ -45,6 +45,8 @@
#include "ether.h"
#include "dev/radio.h"
#include "net/netstack.h"
#include "net/rime/packetbuf.h"
#include "node.h"
@ -54,6 +56,8 @@
#include <sys/select.h>
#include <unistd.h>
#include "net/ethernode.h"
#define BUF ((uip_tcpip_hdr *)&uip_buf[HDR_LEN])
#define PRINTF(...)
@ -77,29 +81,42 @@ struct hdr {
static int radio_is_on = 1;
/*---------------------------------------------------------------------------*/
static int
ethernode_on(void)
{
radio_is_on = 1;
ether_set_radio_status(radio_is_on);
return 1;
}
/*---------------------------------------------------------------------------*/
static int
ethernode_safe_off(void)
{
radio_is_on = 0;
ether_set_radio_status(radio_is_on);
return 1;
}
#include "net/ethernode.h"
const struct radio_driver ethernode_driver =
{
ethernode_send_buf,
ethernode_read,
ethernode_set_receiver,
ethernode_on,
ethernode_safe_off,
};
/*---------------------------------------------------------------------------*/
static int
channel_clear(void)
{
return 1;
}
/*---------------------------------------------------------------------------*/
static int
receiving(void)
{
return 0;
}
/*---------------------------------------------------------------------------*/
static int
pending(void)
{
return 0;
}
/*---------------------------------------------------------------------------*/
#define HDR_LEN UIP_LLH_LEN
@ -234,44 +251,73 @@ ethernode_send(void)
return UIP_FW_OK;
}
/*-------------------------------------------------------------------------------*/
int
ethernode_send_buf(const void *buf, unsigned short len)
{
char tmpbuf[2048];
struct hdr *hdr = (struct hdr *)tmpbuf;
u8_t dest;
static char tmpbuf[2048];
static struct hdr *hdr = (struct hdr *)tmpbuf;
static u8_t dest;
static int
prepare(const void *buf, unsigned short len)
{
memcpy(&tmpbuf[HDR_LEN], buf, len);
len = len + HDR_LEN;
dest = ID_BROADCAST;
do_send(TYPE_DATA, dest, hdr, len);
return len;
}
/*-------------------------------------------------------------------------------*/
static void (* receiver_callback)(const struct radio_driver *);
/*-------------------------------------------------------------------------------*/
void
ethernode_set_receiver(void (* recv)(const struct radio_driver *))
static int
transmit(unsigned short len)
{
process_start(&ethernode_process, NULL);
receiver_callback = recv;
do_send(TYPE_DATA, dest, hdr, len + HDR_LEN);
return RADIO_TX_OK;
}
/*-------------------------------------------------------------------------------*/
static int
send(const void *payload, unsigned short payload_len)
{
prepare(payload, payload_len);
return transmit(payload_len);
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(ethernode_process, ev, data)
{
int len;
PROCESS_BEGIN();
while(1) {
process_post(PROCESS_CURRENT(), PROCESS_EVENT_CONTINUE, NULL);
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_CONTINUE);
if(ethernode_poll()) {
if(receiver_callback) {
receiver_callback(&ethernode_driver);
len = ethernode_poll();
if(len > 0) {
packetbuf_clear();
len = ethernode_read(packetbuf_dataptr(), PACKETBUF_SIZE);
if(len > 0) {
packetbuf_set_datalen(len);
NETSTACK_RDC.input();
}
/* if(receiver_callback) {
receiver_callback(&ethernode_driver);
}*/
}
}
PROCESS_END();
}
/*-------------------------------------------------------------------------------*/
const struct radio_driver ethernode_driver =
{
(int (*)(void))ethernode_init,
prepare,
transmit,
send,
ethernode_read,
channel_clear,
receiving,
pending,
ethernode_on,
ethernode_safe_off,
};