Ejemplo n.º 1
0
/*---------------------------------------------------------------------------*/
static void
update_etx(const rimeaddr_t *dest, int packet_etx)
{
/*
  cyg_uint8 *etxp;
  cyg_uint8 recorded_etx, new_etx;

  etxp = (cyg_uint8 *)neighbor_attr_get_data(&etx, dest);
  if(etxp == NULL || *etxp == 0) {
    recorded_etx = ETX2FIX(ETX_FIRST_GUESS);
  } else {
    recorded_etx = *etxp;
  }



  // Update the EWMA of the ETX for the neighbor. 
  packet_etx = ETX2FIX(packet_etx);
  new_etx = ((cyg_uint16)recorded_etx * ETX_ALPHA +
             (cyg_uint16)packet_etx * (ETX_SCALE - ETX_ALPHA)) / ETX_SCALE;
  PRINTF("neighbor-info: ETX changed from %d to %d (packet ETX = %d) %d\n",
         FIX2ETX(recorded_etx), FIX2ETX(new_etx), FIX2ETX(packet_etx),
         dest->u8[7]);
*/



/*
  if(neighbor_attr_has_neighbor(dest)) {
    neighbor_attr_set_data(&etx, dest, &new_etx);
    if(new_etx != recorded_etx && subscriber_callback != NULL) {
           PRINTF("Before subscriber_callback, new_etx = %i\n", new_etx);      
         subscriber_callback(dest, 1, new_etx);
    }
  }

*/

  cyg_uint8 *rssi_ptr;
  cyg_uint8 recorded_rssi ,packet_rssi;

  rssi_ptr = (cyg_uint8 *)neighbor_attr_get_data(&etx, dest);
  if(rssi_ptr == NULL || *rssi_ptr == 0) {
 
  } else {
    recorded_rssi = *rssi_ptr;
  }

 packet_rssi =   packet_etx;
  
  if(neighbor_attr_has_neighbor(dest)) {
    neighbor_attr_set_data(&etx, dest, &packet_rssi);
    if(packet_rssi != recorded_rssi && subscriber_callback != NULL) {
        //   PRINTF("Before subscriber_callback, packet_rssi = %i\n", packet_rssi);      
         subscriber_callback(dest, 1, packet_rssi);
    }
  }


}
Ejemplo n.º 2
0
/*---------------------------------------------------------------------------*/
static void
update_metric(const rimeaddr_t *dest, int packet_metric)
{
  link_metric_t *metricp;
  link_metric_t recorded_metric, new_metric;
  unsigned long time;
  int first_update = 0;

  metricp = (link_metric_t *)neighbor_attr_get_data(&attr_etx, dest);
  packet_metric = NEIGHBOR_INFO_ETX2FIX(packet_metric);
  if(metricp == NULL || *metricp == 0) {
    recorded_metric = packet_metric;
    new_metric = ((uint16_t)recorded_metric * 5 +
         (uint16_t)packet_metric * (ETX_SCALE - 5)) / ETX_SCALE;
    first_update = 1;
  } else {
    recorded_metric = *metricp;
    /* Update the EWMA of the ETX for the neighbor. */
    if(packet_metric != NEIGHBOR_INFO_ETX2FIX(ETX_NOACK_PENALTY)) {
      new_metric = ((uint16_t)recorded_metric * ETX_ALPHA +
          (uint16_t)packet_metric * (ETX_SCALE - ETX_ALPHA)) / ETX_SCALE;
    } else {
      new_metric = ((uint16_t)recorded_metric * 5 +
                (uint16_t)packet_metric * 5) / ETX_SCALE;
    }
  }

  printf("neighbor-info: ETX of %u changed from %d to %d (packet ETX = %d)\n",
   node_id_from_rimeaddr(dest),
	 NEIGHBOR_INFO_FIX2ETX(recorded_metric),
	 NEIGHBOR_INFO_FIX2ETX(new_metric),
	 NEIGHBOR_INFO_FIX2ETX(packet_metric)
  );

  if(neighbor_attr_has_neighbor(dest)) {
    time = clock_seconds();
    neighbor_attr_set_data(&attr_etx, dest, &new_metric);
    neighbor_attr_set_data(&attr_timestamp, dest, &time);
    if(/*(first_update || new_metric != recorded_metric) &&*/ subscriber_callback != NULL) {
      subscriber_callback(dest, 1, new_metric);
    }
  }
}
Ejemplo n.º 3
0
/*---------------------------------------------------------------------------*/
static void
update_metric(const rimeaddr_t *dest, int packet_metric)
{
  static link_metric_t *metricp;
  static link_metric_t recorded_metric;
  static link_metric_t new_metric;
  unsigned long time;
  int first_update = 0;

  metricp = (link_metric_t *)neighbor_attr_get_data(&attr_etx, dest);
  packet_metric = NEIGHBOR_INFO_ETX2FIX(packet_metric);
  if(metricp == NULL || *metricp == 0) {
    recorded_metric = NEIGHBOR_INFO_ETX2FIX(ETX_LIMIT);
    new_metric = packet_metric;
    first_update = 1;
  } else {
    recorded_metric = *metricp;
    /* Update the EWMA of the ETX for the neighbor. */
    new_metric = ((uint16_t)recorded_metric * ETX_ALPHA +
               (uint16_t)packet_metric * (ETX_SCALE - ETX_ALPHA)) / ETX_SCALE;
  }

  PRINTF("neighbor-info: ETX changed from %d to %d (packet ETX = %d) %d\n",
	 NEIGHBOR_INFO_FIX2ETX(recorded_metric),
	 NEIGHBOR_INFO_FIX2ETX(new_metric),
	 NEIGHBOR_INFO_FIX2ETX(packet_metric),
         dest->u8[7]);

  if(neighbor_attr_has_neighbor(dest)) {
    time = clock_seconds();
    neighbor_attr_set_data(&attr_etx, dest, &new_metric);
    neighbor_attr_set_data(&attr_timestamp, dest, &time);
    if((first_update || new_metric != recorded_metric) && subscriber_callback != NULL) {
      subscriber_callback(dest, 1, new_metric);
    }
  }
}