Change order of initialization so that Rime is initialized before uIP-over-Rime. Send out a new gateway command if a spurious (erroneous) gateway command is received. (Note for the future: this will cause a ping-pong problem with two correct gateways in the network; need to come up with a better solution for this.)

This commit is contained in:
adamdunkels 2008-03-03 20:23:53 +00:00
parent 136443a387
commit c38d43c387

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* @(#)$Id: contiki-sky-main.c,v 1.28 2008/02/24 21:13:03 adamdunkels Exp $ * @(#)$Id: contiki-sky-main.c,v 1.29 2008/03/03 20:23:53 adamdunkels Exp $
*/ */
#include <signal.h> #include <signal.h>
@ -161,6 +161,11 @@ trickle_recv(struct trickle_conn *c)
if(!is_gateway) { if(!is_gateway) {
uip_over_mesh_set_gateway(&msg->gateway); uip_over_mesh_set_gateway(&msg->gateway);
} else {
/* We've received an erroneous message so we send out our own. */
rimeaddr_copy(&msg->gateway, &rimeaddr_node_addr);
rimebuf_copyfrom(msg, sizeof(struct gateway_msg));
trickle_send(c);
} }
} }
@ -219,6 +224,23 @@ main(int argc, char **argv)
node_id_restore(); node_id_restore();
leds_off(LEDS_BLUE); leds_off(LEDS_BLUE);
/*
* Initialize Contiki and our processes.
*/
process_init();
process_start(&etimer_process, NULL);
process_start(&sensors_process, NULL);
simple_cc2420_init();
simple_cc2420_set_pan_addr(panId, 0 /*XXX*/, ds2411_id);
simple_cc2420_set_channel(RF_CHANNEL);
#if WITH_NULLMAC
rime_init(nullmac_init(&simple_cc2420_driver));
#else
rime_init(xmac_init(&simple_cc2420_driver));
#endif
printf(CONTIKI_VERSION_STRING " started. "); printf(CONTIKI_VERSION_STRING " started. ");
if(node_id > 0) { if(node_id > 0) {
printf("Node id is set to %u.\n", node_id); printf("Node id is set to %u.\n", node_id);
@ -229,7 +251,7 @@ main(int argc, char **argv)
printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
ds2411_id[0], ds2411_id[1], ds2411_id[2], ds2411_id[3], ds2411_id[0], ds2411_id[1], ds2411_id[2], ds2411_id[3],
ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7]); ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7]);
#if WITH_UIP #if WITH_UIP
{ {
uip_ipaddr_t hostaddr, netmask; uip_ipaddr_t hostaddr, netmask;
@ -253,13 +275,6 @@ main(int argc, char **argv)
} }
#endif /* WITH_UIP */ #endif /* WITH_UIP */
/*
* Initialize Contiki and our processes.
*/
process_init();
process_start(&etimer_process, NULL);
process_start(&sensors_process, NULL);
#if !WITH_UIP #if !WITH_UIP
uart1_set_input(serial_input_byte); uart1_set_input(serial_input_byte);
serial_init(); serial_init();
@ -273,15 +288,6 @@ main(int argc, char **argv)
leds_off(LEDS_GREEN); leds_off(LEDS_GREEN);
simple_cc2420_init();
simple_cc2420_set_pan_addr(panId, 0 /*XXX*/, ds2411_id);
simple_cc2420_set_channel(RF_CHANNEL);
#if WITH_NULLMAC
rime_init(nullmac_init(&simple_cc2420_driver));
#else
rime_init(xmac_init(&simple_cc2420_driver));
#endif
timesynch_init(); timesynch_init();
@ -310,6 +316,7 @@ main(int argc, char **argv)
* This is the scheduler loop. * This is the scheduler loop.
*/ */
watchdog_start(); watchdog_start();
/* watchdog_stop();*/
while (1) { while (1) {
int r; int r;
#if PROFILE_CONF_ON #if PROFILE_CONF_ON