Rewrote the initial link estimate logic: link estimates are now

computed only over the actual samples, not over the entire
buffer. Also, the initial link estimate is much more conservative now
(16 transmissions) to favor links that have been probed, and which
therefore are likely to have better ETXs.
This commit is contained in:
adamdunkels 2010-10-11 23:34:02 +00:00
parent 98702b2e85
commit 5eb4a0fe8d

View file

@ -32,7 +32,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: collect-link-estimate.c,v 1.4 2010/10/03 20:06:25 adamdunkels Exp $ * $Id: collect-link-estimate.c,v 1.5 2010/10/11 23:34:02 adamdunkels Exp $
*/ */
/** /**
@ -51,7 +51,7 @@
collect-link-estimate.h. */ collect-link-estimate.h. */
#define ETX_HISTORY_WINDOW 8 #define ETX_HISTORY_WINDOW 8
#define INITIAL_LINK_ESTIMATE 4 #define INITIAL_LINK_ESTIMATE 16
#define DEBUG 0 #define DEBUG 0
#if DEBUG #if DEBUG
@ -77,7 +77,7 @@ collect_link_estimate_new(struct collect_link_estimate *le)
{ {
/* Start with a conservative / pessimistic estimate of link quality /* Start with a conservative / pessimistic estimate of link quality
for new links. */ for new links. */
set_all_estimates(le, INITIAL_LINK_ESTIMATE); set_all_estimates(le, 0/*INITIAL_LINK_ESTIMATE*/);
le->historyptr = 0; le->historyptr = 0;
le->num_estimates = 0; le->num_estimates = 0;
} }
@ -86,13 +86,13 @@ void
collect_link_estimate_update_tx(struct collect_link_estimate *le, uint8_t tx) collect_link_estimate_update_tx(struct collect_link_estimate *le, uint8_t tx)
{ {
if(tx == 0) { if(tx == 0) {
printf("ERROR tx == 0\n"); /* printf("ERROR tx == 0\n");*/
return; return;
} }
if(le != NULL) { if(le != NULL) {
if(le->num_estimates == 0) { /* if(le->num_estimates == 0) {
set_all_estimates(le, tx * 2); set_all_estimates(le, tx);
} else { } else*/ {
le->history[le->historyptr] = tx; le->history[le->historyptr] = tx;
le->historyptr = (le->historyptr + 1) % ETX_HISTORY_WINDOW; le->historyptr = (le->historyptr + 1) % ETX_HISTORY_WINDOW;
} }
@ -121,14 +121,19 @@ collect_link_estimate(struct collect_link_estimate *le)
int i; int i;
uint16_t etx; uint16_t etx;
if(le->num_estimates == 0) {
return INITIAL_LINK_ESTIMATE * COLLECT_LINK_ESTIMATE_UNIT;
}
PRINTF("collect_link_estimate: "); PRINTF("collect_link_estimate: ");
etx = 0; etx = 0;
for(i = 0; i < ETX_HISTORY_WINDOW; ++i) { for(i = 0; i < le->num_estimates; ++i) {
PRINTF("%d ", le->history[i]); PRINTF("%d+", le->history[i]);
etx += le->history[i]; etx += le->history[(le->historyptr - i - 1) & (ETX_HISTORY_WINDOW - 1)];
} }
PRINTF(", %d\n", (COLLECT_LINK_ESTIMATE_UNIT * etx) / ETX_HISTORY_WINDOW); PRINTF("/%d = %d\n", i,
return (COLLECT_LINK_ESTIMATE_UNIT * etx) / ETX_HISTORY_WINDOW; (COLLECT_LINK_ESTIMATE_UNIT * etx) / i);
return (COLLECT_LINK_ESTIMATE_UNIT * etx) / i;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int