rtmetric values should always be computed as 16-bit values
This commit is contained in:
parent
3c733a0c4e
commit
b23a364397
|
@ -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.3 2010/09/22 22:03:21 adamdunkels Exp $
|
* $Id: collect-link-estimate.c,v 1.4 2010/10/03 20:06:25 adamdunkels Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,7 +49,7 @@
|
||||||
the ETX. It cannot be larger than
|
the ETX. It cannot be larger than
|
||||||
COLLECT_LINK_ESTIMATE_HISTORY_SIZE, which is defined in
|
COLLECT_LINK_ESTIMATE_HISTORY_SIZE, which is defined in
|
||||||
collect-link-estimate.h. */
|
collect-link-estimate.h. */
|
||||||
#define ETX_HISTORY_WINDOW 16
|
#define ETX_HISTORY_WINDOW 8
|
||||||
|
|
||||||
#define INITIAL_LINK_ESTIMATE 4
|
#define INITIAL_LINK_ESTIMATE 4
|
||||||
|
|
||||||
|
@ -62,35 +62,51 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
static void
|
||||||
collect_link_estimate_new(struct collect_link_estimate *le)
|
set_all_estimates(struct collect_link_estimate *le, uint16_t value)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
for(i = 0; i < ETX_HISTORY_WINDOW; i++) {
|
||||||
|
le->history[i] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
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. */
|
||||||
for(i = 0; i < ETX_HISTORY_WINDOW; i++) {
|
set_all_estimates(le, INITIAL_LINK_ESTIMATE);
|
||||||
le->history[i] = INITIAL_LINK_ESTIMATE;
|
|
||||||
}
|
|
||||||
le->historyptr = 0;
|
le->historyptr = 0;
|
||||||
|
le->num_estimates = 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
collect_link_estimate_update_tx_fail(struct collect_link_estimate *le, int tx)
|
collect_link_estimate_update_tx(struct collect_link_estimate *le, uint8_t tx)
|
||||||
{
|
{
|
||||||
|
if(tx == 0) {
|
||||||
|
printf("ERROR tx == 0\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(le != NULL) {
|
if(le != NULL) {
|
||||||
le->history[le->historyptr] = tx * 2;
|
if(le->num_estimates == 0) {
|
||||||
le->historyptr = (le->historyptr + 1) % ETX_HISTORY_WINDOW;
|
set_all_estimates(le, tx * 2);
|
||||||
|
} else {
|
||||||
|
le->history[le->historyptr] = tx;
|
||||||
|
le->historyptr = (le->historyptr + 1) % ETX_HISTORY_WINDOW;
|
||||||
|
}
|
||||||
|
if(le->num_estimates < ETX_HISTORY_WINDOW) {
|
||||||
|
le->num_estimates++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
collect_link_estimate_update_tx(struct collect_link_estimate *le, int tx)
|
collect_link_estimate_update_tx_fail(struct collect_link_estimate *le,
|
||||||
|
uint8_t tx)
|
||||||
{
|
{
|
||||||
if(le != NULL) {
|
collect_link_estimate_update_tx(le, tx * 2);
|
||||||
le->history[le->historyptr] = tx;
|
|
||||||
le->historyptr = (le->historyptr + 1) % ETX_HISTORY_WINDOW;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
|
@ -99,10 +115,11 @@ collect_link_estimate_update_rx(struct collect_link_estimate *n)
|
||||||
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
int
|
uint16_t
|
||||||
collect_link_estimate(struct collect_link_estimate *le)
|
collect_link_estimate(struct collect_link_estimate *le)
|
||||||
{
|
{
|
||||||
int i, etx;
|
int i;
|
||||||
|
uint16_t etx;
|
||||||
|
|
||||||
PRINTF("collect_link_estimate: ");
|
PRINTF("collect_link_estimate: ");
|
||||||
etx = 0;
|
etx = 0;
|
||||||
|
@ -114,5 +131,13 @@ collect_link_estimate(struct collect_link_estimate *le)
|
||||||
return (COLLECT_LINK_ESTIMATE_UNIT * etx) / ETX_HISTORY_WINDOW;
|
return (COLLECT_LINK_ESTIMATE_UNIT * etx) / ETX_HISTORY_WINDOW;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
collect_link_estimate_num_estimates(struct collect_link_estimate *le)
|
||||||
|
{
|
||||||
|
if(le != NULL) {
|
||||||
|
return le->num_estimates;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* $Id: collect-link-estimate.h,v 1.2 2010/09/13 13:28:14 adamdunkels Exp $
|
* $Id: collect-link-estimate.h,v 1.3 2010/10/03 20:06:25 adamdunkels Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,8 +63,9 @@
|
||||||
#define COLLECT_LINK_ESTIMATE_HISTORY_SIZE 16
|
#define COLLECT_LINK_ESTIMATE_HISTORY_SIZE 16
|
||||||
|
|
||||||
struct collect_link_estimate {
|
struct collect_link_estimate {
|
||||||
int history[COLLECT_LINK_ESTIMATE_HISTORY_SIZE];
|
uint8_t history[COLLECT_LINK_ESTIMATE_HISTORY_SIZE];
|
||||||
uint8_t historyptr;
|
uint8_t historyptr;
|
||||||
|
uint8_t num_estimates;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,7 +87,7 @@ void collect_link_estimate_new(struct collect_link_estimate *le);
|
||||||
* buffer attributes when computing the link estimate.
|
* buffer attributes when computing the link estimate.
|
||||||
*/
|
*/
|
||||||
void collect_link_estimate_update_tx(struct collect_link_estimate *le,
|
void collect_link_estimate_update_tx(struct collect_link_estimate *le,
|
||||||
int num_tx);
|
uint8_t num_tx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Update a link estimate when a packet has failed to be sent.
|
* \brief Update a link estimate when a packet has failed to be sent.
|
||||||
|
@ -99,7 +100,7 @@ void collect_link_estimate_update_tx(struct collect_link_estimate *le,
|
||||||
* buffer attributes when computing the link estimate.
|
* buffer attributes when computing the link estimate.
|
||||||
*/
|
*/
|
||||||
void collect_link_estimate_update_tx_fail(struct collect_link_estimate *le,
|
void collect_link_estimate_update_tx_fail(struct collect_link_estimate *le,
|
||||||
int num_tx);
|
uint8_t num_tx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Update a link estimate when a packet has been received.
|
* \brief Update a link estimate when a packet has been received.
|
||||||
|
@ -116,9 +117,12 @@ void collect_link_estimate_update_rx(struct collect_link_estimate *le);
|
||||||
/**
|
/**
|
||||||
* \brief Compute the link estimate metric for a link estimate
|
* \brief Compute the link estimate metric for a link estimate
|
||||||
* \param le A pointer to a link estimate structure
|
* \param le A pointer to a link estimate structure
|
||||||
|
* \return The current link estimate metric
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int collect_link_estimate(struct collect_link_estimate *le);
|
uint16_t collect_link_estimate(struct collect_link_estimate *le);
|
||||||
|
|
||||||
|
int collect_link_estimate_num_estimates(struct collect_link_estimate *le);
|
||||||
|
|
||||||
#endif /* COLLECT_LINK_ESTIMATE_H */
|
#endif /* COLLECT_LINK_ESTIMATE_H */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue