Ejemplo n.º 1
0
/*---------------------------------------------------------------------------*/
void
collect_set_sink(struct collect_conn *tc, int should_be_sink)
{
    if(should_be_sink) {
        tc->rtmetric = SINK;
#if !COLLECT_ANNOUNCEMENTS
        neighbor_discovery_start(&tc->neighbor_discovery_conn, tc->rtmetric);
#endif /* !COLLECT_ANNOUNCEMENTS */
    } else {
        tc->rtmetric = RTMETRIC_MAX;
    }
#if COLLECT_ANNOUNCEMENTS
    announcement_set_value(&tc->announcement, tc->rtmetric);
#endif /* COLLECT_ANNOUNCEMENTS */
    update_rtmetric(tc);
}
Ejemplo n.º 2
0
/*---------------------------------------------------------------------------*/
static void
received_announcement(struct announcement *a, const linkaddr_t *from,
		      uint16_t id, uint16_t value)
{
  /* We set our own announced value to one plus that of our neighbor. */
  announcement_set_value(a, value + 1);

  printf("Got announcement from %d.%d, id %d, value %d, our new value is %d\n",
	 from->u8[0], from->u8[1], id, value, value + 1);

#if CONTIKI_TARGET_NETSIM
  {
    char buf[8];
    sprintf(buf, "%d", value + 1);
    ether_set_text(buf);
  }
#endif

}
Ejemplo n.º 3
0
void
httpd_cgi_init(void)
{
  
  httpd_cgi_add(&sensors);
  httpd_cgi_add(&nodeid);
  httpd_cgi_add(&neighbors);

  announcement_register(&announcement, 31,
			received_announcement);
  announcement_set_value(&announcement, 0);
  announcement_listen(2);

  collect_neighbor_list_new(&neighbor_list);
  collect_neighbor_init();
  /*  neighbor_discovery_open(&conn, 31,
			  CLOCK_SECOND * 4,
			  CLOCK_SECOND * 20,
			  CLOCK_SECOND * 60,
			  &neighbor_discovery_callbacks);
			  neighbor_discovery_start(&conn, 0);*/
}
Ejemplo n.º 4
0
/*---------------------------------------------------------------------------*/
static void
update_rtmetric(struct collect_conn *tc)
{
    struct neighbor *n;

    /* We should only update the rtmetric if we are not the sink. */
    if(tc->rtmetric != SINK) {

        /* Find the neighbor with the lowest rtmetric. */
        n = neighbor_best();

        /* If n is NULL, we have no best neighbor. */
        if(n == NULL) {

            /* If we have don't have any neighbors, we set our rtmetric to
            the maximum value to indicate that we do not have a route. */

            if(tc->rtmetric != RTMETRIC_MAX) {
                PRINTF("%d.%d: didn't find a best neighbor, setting rtmetric to max\n",
                       rimeaddr_node_addr.u8[RIMEADDR_SIZE-2], rimeaddr_node_addr.u8[RIMEADDR_SIZE-1]);
            }
            tc->rtmetric = RTMETRIC_MAX;
            announcement_set_value(&tc->announcement, tc->rtmetric);
        } else {

            /* We set our rtmetric to the rtmetric of our best neighbor plus
            the expected transmissions to reach that neighbor. */
            if(n->rtmetric + neighbor_etx(n) != tc->rtmetric) {
                uint16_t old_rtmetric = tc->rtmetric;

                tc->rtmetric = n->rtmetric + neighbor_etx(n);

#if !COLLECT_ANNOUNCEMENTS
                neighbor_discovery_start(&tc->neighbor_discovery_conn, tc->rtmetric);
#else
                announcement_set_value(&tc->announcement, tc->rtmetric);
#endif /* !COLLECT_ANNOUNCEMENTS */

                PRINTF("%d.%d: new rtmetric %d\n",
                       rimeaddr_node_addr.u8[RIMEADDR_SIZE-2], rimeaddr_node_addr.u8[RIMEADDR_SIZE-1],
                       tc->rtmetric);

                /* We got a new, working, route we send any queued packets we may have. */
                if(old_rtmetric == RTMETRIC_MAX) {
                    send_queued_packet();
                }
            }
        }
    }

    /*  DEBUG_PRINTF("%d: new rtmetric %d\n", node_id, rtmetric);*/
#if CONTIKI_TARGET_NETSIM
    {
        char buf[8];
        if(tc->rtmetric == RTMETRIC_MAX) {
            strcpy(buf, " ");
        } else {
            sprintf(buf, "%.1f", (float)tc->rtmetric / NEIGHBOR_ETX_SCALE);
        }
        ether_set_text(buf);
    }
#endif
}