X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Flib%2Fnet%2Fle%2FLinkEstimatorP.nc;h=5a0f1b62be1a8f338a2f6ea4af873d58d8f8c232;hb=e9bfab607e051bae6afb47b44892ce37541d1b44;hp=2f7c991efb14f5d9256c0935bd14f731a55e4048;hpb=0ec745a939896b4d14901c1a14c5f2a644713e21;p=tinyos-2.x.git diff --git a/tos/lib/net/le/LinkEstimatorP.nc b/tos/lib/net/le/LinkEstimatorP.nc index 2f7c991e..5a0f1b62 100644 --- a/tos/lib/net/le/LinkEstimatorP.nc +++ b/tos/lib/net/le/LinkEstimatorP.nc @@ -100,15 +100,15 @@ implementation { } // get the link estimation footer (neighbor entries) in the packet - linkest_footer_t* getFooter(message_t* m, uint8_t len) { + linkest_footer_t* getFooter(message_t* ONE m, uint8_t len) { // To get a footer at offset "len", the payload must be len + sizeof large. - return (linkest_footer_t*)(len + (uint8_t *)call Packet.getPayload(m,len + sizeof(linkest_footer_t))); + return (linkest_footer_t* ONE)(len + (uint8_t *)call Packet.getPayload(m,len + sizeof(linkest_footer_t))); } // add the link estimation header (seq no) and link estimation // footer (neighbor entries) in the packet. Call just before sending // the packet. - uint8_t addLinkEstHeaderAndFooter(message_t *msg, uint8_t len) { + uint8_t addLinkEstHeaderAndFooter(message_t * ONE msg, uint8_t len) { uint8_t newlen; linkest_header_t *hdr; linkest_footer_t *footer; @@ -131,14 +131,23 @@ implementation { j = 0; newPrevSentIdx = 0; for (i = 0; i < NEIGHBOR_TABLE_SIZE && j < maxEntries; i++) { + uint8_t neighborCount; + neighbor_stat_entry_t * COUNT(neighborCount) neighborLists; + if(maxEntries <= NEIGHBOR_TABLE_SIZE) + neighborCount = maxEntries; + else + neighborCount = NEIGHBOR_TABLE_SIZE; + + neighborLists = TCAST(neighbor_stat_entry_t * COUNT(neighborCount), footer->neighborList); + k = (prevSentIdx + i + 1) % NEIGHBOR_TABLE_SIZE; if ((NeighborTable[k].flags & VALID_ENTRY) && (NeighborTable[k].flags & MATURE_ENTRY)) { - footer->neighborList[j].ll_addr = NeighborTable[k].ll_addr; - footer->neighborList[j].inquality = NeighborTable[k].inquality; + neighborLists[j].ll_addr = NeighborTable[k].ll_addr; + neighborLists[j].inquality = NeighborTable[k].inquality; newPrevSentIdx = k; - dbg("LI", "Loaded on footer: %d %d %d\n", j, footer->neighborList[j].ll_addr, - footer->neighborList[j].inquality); + dbg("LI", "Loaded on footer: %d %d %d\n", j, neighborLists[j].ll_addr, + neighborLists[j].inquality); j++; } } @@ -243,7 +252,7 @@ implementation { // called when new beacon estimate is done // also called when new DEETX estimate is done void updateEETX(neighbor_table_entry_t *ne, uint16_t newEst) { - ne->eetx = (ALPHA * ne->eetx + (10 - ALPHA) * newEst)/10; + ne->eetx = (ALPHA * ne->eetx + (10 - ALPHA) * newEst + 5)/10; } @@ -332,8 +341,8 @@ implementation { ne->inquality = (ALPHA * ne->inquality) / 10; } else { newEst = (255 * ne->rcvcnt) / totalPkt; - dbg("LI,LITest", " %hu: %hhu -> %hhu", ne->ll_addr, ne->inquality, (ALPHA * ne->inquality + (10-ALPHA) * newEst)/10); - ne->inquality = (ALPHA * ne->inquality + (10-ALPHA) * newEst)/10; + dbg("LI,LITest", " %hu: %hhu -> %hhu", ne->ll_addr, ne->inquality, (ALPHA * ne->inquality + (10-ALPHA) * newEst + 5)/10); + ne->inquality = (ALPHA * ne->inquality + (10-ALPHA) * newEst + 5)/10; } ne->rcvcnt = 0; ne->failcnt = 0; @@ -611,7 +620,7 @@ implementation { // called when link estimator generator packet or // packets from upper layer that are wired to pass through // link estimator is received - void processReceivedMessage(message_t* msg, void* payload, uint8_t len) { + void processReceivedMessage(message_t* ONE msg, void* COUNT_NOK(len) payload, uint8_t len) { uint8_t nidx; uint8_t num_entries; @@ -620,7 +629,7 @@ implementation { if (call SubAMPacket.destination(msg) == AM_BROADCAST_ADDR) { linkest_header_t* hdr = getHeader(msg); - linkest_footer_t* footer; + linkest_footer_t* ONE footer; am_addr_t ll_addr; ll_addr = call SubAMPacket.source(msg); @@ -683,20 +692,22 @@ implementation { if ((nidx != INVALID_RVAL) && (num_entries > 0)) { uint8_t payloadLen = call SubPacket.payloadLength(msg); - void* subPayload = call SubPacket.getPayload(msg, payloadLen); + void* COUNT_NOK(payloadLen) subPayload = call SubPacket.getPayload(msg, payloadLen); void* payloadEnd = subPayload + payloadLen; dbg("LI", "Number of footer entries: %d\n", num_entries); - footer = (linkest_footer_t*) (payloadEnd - (num_entries*sizeof(linkest_footer_t))); + footer = TCAST(linkest_footer_t* COUNT(num_entries), (payloadEnd - (num_entries*sizeof(linkest_footer_t)))); { uint8_t i; am_addr_t my_ll_addr; + neighbor_stat_entry_t * COUNT(num_entries) neighborLists; my_ll_addr = call SubAMPacket.address(); + neighborLists = TCAST(neighbor_stat_entry_t * COUNT(num_entries), footer->neighborList); for (i = 0; i < num_entries; i++) { - dbg("LI", "%d %d %d\n", i, footer->neighborList[i].ll_addr, - footer->neighborList[i].inquality); - if (footer->neighborList[i].ll_addr == my_ll_addr) { - updateReverseQuality(ll_addr, footer->neighborList[i].inquality); + dbg("LI", "%d %d %d\n", i, neighborLists[i].ll_addr, + neighborLists[i].inquality); + if (neighborLists[i].ll_addr == my_ll_addr) { + updateReverseQuality(ll_addr, neighborLists[i].inquality); } } }