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> * 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" #include "contiki.h"
@ -127,7 +127,8 @@ contiki_main(int flag)
ctimer_init(); ctimer_init();
netstack_init(); NETSTACK_MAC.init();
NETSTACK_RDC.init();
uip_over_mesh_init(2); uip_over_mesh_init(2);
uip_over_mesh_set_net(&meshif.ipaddr, &meshif.netmask); 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 * 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.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> * Author: Adam Dunkels <adam@sics.se>
* *
@ -525,8 +525,9 @@ stdin_callback(gpointer data, gint source, GdkInputCondition condition)
{ {
char buf[1000]; char buf[1000];
int len; int len;
len = read(STDIN_FILENO, &buf, sizeof(buf)); len = read(STDIN_FILENO, &buf, sizeof(buf));
printf("read len %d\n", len);
buf[len] = 0; buf[len] = 0;
ether_send_serial(buf); ether_send_serial(buf);
} }

View file

@ -30,7 +30,7 @@
* *
* Author: Adam Dunkels <adam@sics.se> * 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 * \file
@ -242,7 +242,7 @@ ether_client_poll(void)
FD_SET(sc, &fdset); FD_SET(sc, &fdset);
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 10000; tv.tv_usec = 1000;
ret = select(sc + 1, &fdset, NULL, NULL, &tv); ret = select(sc + 1, &fdset, NULL, NULL, &tv);

View file

@ -30,7 +30,7 @@
* *
* Author: Adam Dunkels <adam@sics.se> * 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 * \file
@ -45,6 +45,8 @@
#include "ether.h" #include "ether.h"
#include "dev/radio.h" #include "dev/radio.h"
#include "net/netstack.h"
#include "net/rime/packetbuf.h"
#include "node.h" #include "node.h"
@ -54,6 +56,8 @@
#include <sys/select.h> #include <sys/select.h>
#include <unistd.h> #include <unistd.h>
#include "net/ethernode.h"
#define BUF ((uip_tcpip_hdr *)&uip_buf[HDR_LEN]) #define BUF ((uip_tcpip_hdr *)&uip_buf[HDR_LEN])
#define PRINTF(...) #define PRINTF(...)
@ -77,29 +81,42 @@ struct hdr {
static int radio_is_on = 1; static int radio_is_on = 1;
/*---------------------------------------------------------------------------*/
static int static int
ethernode_on(void) ethernode_on(void)
{ {
radio_is_on = 1; radio_is_on = 1;
ether_set_radio_status(radio_is_on); ether_set_radio_status(radio_is_on);
return 1;
} }
/*---------------------------------------------------------------------------*/
static int static int
ethernode_safe_off(void) ethernode_safe_off(void)
{ {
radio_is_on = 0; radio_is_on = 0;
ether_set_radio_status(radio_is_on); ether_set_radio_status(radio_is_on);
return 1;
} }
/*---------------------------------------------------------------------------*/
#include "net/ethernode.h" static int
channel_clear(void)
const struct radio_driver ethernode_driver = {
{ return 1;
ethernode_send_buf, }
ethernode_read, /*---------------------------------------------------------------------------*/
ethernode_set_receiver, static int
ethernode_on, receiving(void)
ethernode_safe_off, {
}; return 0;
}
/*---------------------------------------------------------------------------*/
static int
pending(void)
{
return 0;
}
/*---------------------------------------------------------------------------*/
#define HDR_LEN UIP_LLH_LEN #define HDR_LEN UIP_LLH_LEN
@ -234,44 +251,73 @@ ethernode_send(void)
return UIP_FW_OK; return UIP_FW_OK;
} }
/*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/
int static char tmpbuf[2048];
ethernode_send_buf(const void *buf, unsigned short len) static struct hdr *hdr = (struct hdr *)tmpbuf;
{ static u8_t dest;
char tmpbuf[2048];
struct hdr *hdr = (struct hdr *)tmpbuf;
u8_t dest;
static int
prepare(const void *buf, unsigned short len)
{
memcpy(&tmpbuf[HDR_LEN], buf, len); memcpy(&tmpbuf[HDR_LEN], buf, len);
len = len + HDR_LEN; len = len + HDR_LEN;
dest = ID_BROADCAST; dest = ID_BROADCAST;
do_send(TYPE_DATA, dest, hdr, len);
return len; return len;
} }
/*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/
static void (* receiver_callback)(const struct radio_driver *); static int
/*-------------------------------------------------------------------------------*/ transmit(unsigned short len)
void
ethernode_set_receiver(void (* recv)(const struct radio_driver *))
{ {
process_start(&ethernode_process, NULL); do_send(TYPE_DATA, dest, hdr, len + HDR_LEN);
receiver_callback = recv; 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) PROCESS_THREAD(ethernode_process, ev, data)
{ {
int len;
PROCESS_BEGIN(); PROCESS_BEGIN();
while(1) { while(1) {
process_post(PROCESS_CURRENT(), PROCESS_EVENT_CONTINUE, NULL); process_post(PROCESS_CURRENT(), PROCESS_EVENT_CONTINUE, NULL);
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_CONTINUE); PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_CONTINUE);
if(ethernode_poll()) { len = ethernode_poll();
if(receiver_callback) { if(len > 0) {
receiver_callback(&ethernode_driver);
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(); 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,
};