/** \brief Indicate some (non-ACK) packet was received from a neighbor. This function should be called for each received (non-ACK) packet so neighbor statistics in the neighbor table can be updated. The fields which are updated are: - numRx - rssi - asn - stableNeighbor - switchStabilityCounter \param[in] l2_src MAC source address of the packet, i.e. the neighbor who sent the packet just received. \param[in] rssi RSSI with which this packet was received. \param[in] asnTs ASN at which this packet was received. \param[in] joinPrioPresent Whether a join priority was present in the received packet. \param[in] joinPrio The join priority present in the packet, if any. */ void neighbors_indicateRx(open_addr_t* l2_src, int8_t rssi, asn_t* asnTs, bool joinPrioPresent, uint8_t joinPrio) { uint8_t i; bool newNeighbor; // update existing neighbor newNeighbor = TRUE; for (i=0;i<MAXNUMNEIGHBORS;i++) { if (isThisRowMatching(l2_src,i)) { // this is not a new neighbor newNeighbor = FALSE; // update numRx, rssi, asn neighbors_vars.neighbors[i].numRx++; neighbors_vars.neighbors[i].rssi=rssi; memcpy(&neighbors_vars.neighbors[i].asn,asnTs,sizeof(asn_t)); //update jp if (joinPrioPresent==TRUE){ neighbors_vars.neighbors[i].joinPrio=joinPrio; } // update stableNeighbor, switchStabilityCounter if (neighbors_vars.neighbors[i].stableNeighbor==FALSE) { if (neighbors_vars.neighbors[i].rssi>BADNEIGHBORMAXRSSI) { neighbors_vars.neighbors[i].switchStabilityCounter++; if (neighbors_vars.neighbors[i].switchStabilityCounter>=SWITCHSTABILITYTHRESHOLD) { neighbors_vars.neighbors[i].switchStabilityCounter=0; neighbors_vars.neighbors[i].stableNeighbor=TRUE; } } else { neighbors_vars.neighbors[i].switchStabilityCounter=0; } } else if (neighbors_vars.neighbors[i].stableNeighbor==TRUE) { if (neighbors_vars.neighbors[i].rssi<GOODNEIGHBORMINRSSI) { neighbors_vars.neighbors[i].switchStabilityCounter++; if (neighbors_vars.neighbors[i].switchStabilityCounter>=SWITCHSTABILITYTHRESHOLD) { neighbors_vars.neighbors[i].switchStabilityCounter=0; neighbors_vars.neighbors[i].stableNeighbor=FALSE; } } else { neighbors_vars.neighbors[i].switchStabilityCounter=0; } } // stop looping break; } } // register new neighbor if (newNeighbor==TRUE) { registerNewNeighbor(l2_src, rssi, asnTs, joinPrioPresent,joinPrio); } }
void neighbors_indicateRx(open_addr_t* l2_src, int8_t rssi, asn_t* asnTimestamp) { uint8_t i=0; while (i<MAXNUMNEIGHBORS) { if (isThisRowMatching(l2_src,i)) { neighbors_vars.neighbors[i].numRx++; neighbors_vars.neighbors[i].rssi=rssi; memcpy(&neighbors_vars.neighbors[i].asn,asnTimestamp,sizeof(asn_t)); if (neighbors_vars.neighbors[i].stableNeighbor==FALSE) { if (neighbors_vars.neighbors[i].rssi>BADNEIGHBORMAXRSSI) { neighbors_vars.neighbors[i].switchStabilityCounter++; if (neighbors_vars.neighbors[i].switchStabilityCounter>=SWITCHSTABILITYTHRESHOLD) { neighbors_vars.neighbors[i].switchStabilityCounter=0; neighbors_vars.neighbors[i].stableNeighbor=TRUE; } } else { neighbors_vars.neighbors[i].switchStabilityCounter=0; } } else if (neighbors_vars.neighbors[i].stableNeighbor==TRUE) { if (neighbors_vars.neighbors[i].rssi<GOODNEIGHBORMINRSSI) { neighbors_vars.neighbors[i].switchStabilityCounter++; if (neighbors_vars.neighbors[i].switchStabilityCounter>=SWITCHSTABILITYTHRESHOLD) { neighbors_vars.neighbors[i].switchStabilityCounter=0; neighbors_vars.neighbors[i].stableNeighbor=FALSE; } } else { neighbors_vars.neighbors[i].switchStabilityCounter=0; } } return; } i++; } // this is a new neighbor: register registerNewNeighbor(l2_src, rssi, asnTimestamp); }