From 69a5b6752333eca3c20c638c562eaa256da0ccf7 Mon Sep 17 00:00:00 2001 From: adamdunkels Date: Tue, 23 Feb 2010 18:44:08 +0000 Subject: [PATCH] Updated netsim to new netstack API --- platform/netsim/contiki-main.c | 5 +- platform/netsim/display.c | 5 +- platform/netsim/ether.c | 4 +- platform/netsim/net/ethernode.c | 104 +++++++++++++++++++++++--------- 4 files changed, 83 insertions(+), 35 deletions(-) diff --git a/platform/netsim/contiki-main.c b/platform/netsim/contiki-main.c index 9bb25b853..a12591a55 100644 --- a/platform/netsim/contiki-main.c +++ b/platform/netsim/contiki-main.c @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $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); diff --git a/platform/netsim/display.c b/platform/netsim/display.c index bc86f7cdc..b8d9a7dcc 100644 --- a/platform/netsim/display.c +++ b/platform/netsim/display.c @@ -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 * @@ -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); } diff --git a/platform/netsim/ether.c b/platform/netsim/ether.c index 885845c5b..f1ccb45b4 100644 --- a/platform/netsim/ether.c +++ b/platform/netsim/ether.c @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $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); diff --git a/platform/netsim/net/ethernode.c b/platform/netsim/net/ethernode.c index b52e71711..f3d2a009e 100644 --- a/platform/netsim/net/ethernode.c +++ b/platform/netsim/net/ethernode.c @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $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 #include +#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(ðernode_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(ðernode_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(ðernode_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, + }; + +