Beispiel #1
0
/*---------------------------------------------------------------------------*/
static void
write_chunk(struct rucb_conn *c, int offset, int flag,
	    char *data, int datalen)
{
#if CONTIKI_TARGET_NETSIM
  {
    char buf[100];
    printf("received %d; %d\n", offset, datalen);
    sprintf(buf, "%d%%", (100 * (offset + datalen)) / FILESIZE);
    ether_set_text(buf);
  }
#endif /* CONTIKI_TARGET_NETSIM */

}
/*---------------------------------------------------------------------------*/
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

}
Beispiel #3
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
}