- /*Logic operation on the vector */
- command error_t VectorLogic.setItem(dhv_key_t key){
- call DhvVectorCache.addItem(key);
- call DhvTrickleTimer.reset();
- return SUCCESS;
- }
-
- command error_t VectorLogic.setReqItem(dhv_key_t key){
- call DhvVectorCache.addReqItem(key);
- call DhvTrickleTimer.reset();
- return SUCCESS;
- }
-
- command error_t VectorLogic.unsetItem(dhv_key_t key){
- call DhvVectorCache.removeItem(key);
- call DhvStateLogic.setVBitState(0);
- return SUCCESS;
- }
-
- command uint8_t * VectorLogic.allItem(){
- return call DhvVectorCache.allItem();
- }
-
- command uint8_t VectorLogic.nextItem(){
- return call DhvVectorCache.nextItem();
- }
-
- /*logic operations on the data*/
- command error_t DataLogic.setItem(dhv_key_t key){
- call DhvDataCache.addItem( key);
- call DhvTrickleTimer.reset();
- return SUCCESS;
- }
-
- command error_t DataLogic.setReqItem(dhv_key_t key){
- call DhvDataCache.addReqItem( key);
- call DhvTrickleTimer.reset();
- return SUCCESS;
- }
-
- command error_t DataLogic.unsetItem(dhv_key_t key){
- call DhvDataCache.removeItem(key);
- call DhvStateLogic.setVBitState(0);
- return SUCCESS;
- }
-
- command uint8_t* DataLogic.allItem(){
- return call DhvDataCache.allItem();
- }
-
- command uint8_t DataLogic.nextItem(){
- return call DhvDataCache.nextItem();
- }
+ /*Logic operation on the vector */
+ command error_t VectorLogic.setItem(dhv_key_t key){
+ call DhvVectorCache.addItem(key);
+ call DhvTrickleTimer.reset();
+ return SUCCESS;
+ }
+
+ command error_t VectorLogic.setReqItem(dhv_key_t key){
+ call DhvVectorCache.addReqItem(key);
+ call DhvTrickleTimer.reset();
+ return SUCCESS;
+ }
+
+ command error_t VectorLogic.unsetItem(dhv_key_t key){
+ call DhvVectorCache.removeItem(key);
+ call DhvStateLogic.setVBitState(0);
+ return SUCCESS;
+ }
+
+ command uint8_t * VectorLogic.allItem(){
+ return call DhvVectorCache.allItem();
+ }
+
+ command uint8_t VectorLogic.nextItem(){
+ return call DhvVectorCache.nextItem();
+ }
+
+ /*logic operations on the data*/
+ command error_t DataLogic.setItem(dhv_key_t key){
+ call DhvDataCache.addItem( key);
+ call DhvTrickleTimer.reset();
+ return SUCCESS;
+ }
+
+ command error_t DataLogic.setReqItem(dhv_key_t key){
+ call DhvDataCache.addReqItem( key);
+ call DhvTrickleTimer.reset();
+ return SUCCESS;
+ }
+
+ command error_t DataLogic.unsetItem(dhv_key_t key){
+ call DhvDataCache.removeItem(key);
+ call DhvStateLogic.setVBitState(0);
+ return SUCCESS;
+ }
+
+ command uint8_t* DataLogic.allItem(){
+ return call DhvDataCache.allItem();
+ }
+
+ command uint8_t DataLogic.nextItem(){
+ return call DhvDataCache.nextItem();
+ }
- return hsum_status;
- }
-
- command void DhvStateLogic.setDiffSummary(){
- if(bitIndex == 0){
- bitIndex=1;
- }
-
- call DhvTrickleTimer.reset();
- }
-
- command void DhvStateLogic.setSameSummary(){
- bitIndex = 0;
- hsum_status = 0;
- //reset all the vector and data status to avoid flooding
- call DhvDataCache.removeAll();
- call DhvVectorCache.removeAll();
-
- }
-
- command void DhvStateLogic.setVBitState(uint32_t state){
- bitIndex = state;
+ return hsum_status;
+ }
+
+ command void DhvStateLogic.setDiffSummary(){
+ if(bitIndex == 0){
+ bitIndex=1;
+ }
+
+ call DhvTrickleTimer.reset();
+ }
+
+ command void DhvStateLogic.setSameSummary(){
+ bitIndex = 0;
+ hsum_status = 0;
+ //reset all the vector and data status to avoid flooding
+ call DhvDataCache.removeAll();
+ call DhvVectorCache.removeAll();
+
+ }
+
+ command void DhvStateLogic.setVBitState(uint32_t state){
+ bitIndex = state;
- dbg("TempDebug", "TempDebug: Before mask dindex bitIndex %d %d %d\n", mask, dindex, bitIndex);
- if((bitIndex & mask) != 0){
- bitIndex = bitIndex^mask;
- }
- dbg("TempDebug", "TempDebug: After bitIndex %d\n", bitIndex);
- }
-
- command void DhvStateLogic.setVBitIndex(uint8_t dindex){
+ dbg("TempDebug", "TempDebug: Before mask dindex bitIndex %d %d %d\n", mask, dindex, bitIndex);
+ if((bitIndex & mask) != 0){
+ bitIndex = bitIndex^mask;
+ }
+ dbg("TempDebug", "TempDebug: After bitIndex %d\n", bitIndex);
+ }
+
+ command void DhvStateLogic.setVBitIndex(uint8_t dindex){
-//get the non-zero bit index to extract the vertical bits.
-command uint8_t DhvStateLogic.getVBitIndex(){
-
- uint32_t mask;
- uint8_t i;
- uint32_t xor;
-
- if(bitIndex == 0){
- return 0;
- }else
- {
- mask = 1;
- for(i = 1; i <= 32; i++){
- xor = bitIndex & mask;
-
- dbg("TempDebug", "TempDebug: %d %d %d %d \n", i, bitIndex, mask, xor);
- if(xor != 0){
- return i;
- }
- mask = mask << 1;
- }
- return 0;
- }
-}
+ bitIndex = bitIndex | mask;
+
+ call DhvTrickleTimer.reset();
+ }
+
+ //get the non-zero bit index to extract the vertical bits.
+ command uint8_t DhvStateLogic.getVBitIndex(){
+
+ uint32_t mask;
+ uint8_t i;
+ uint32_t xor;
+
+ if(bitIndex == 0){
+ return 0;
+ }else
+ {
+ mask = 1;
+ for(i = 1; i <= 32; i++){
+ xor = bitIndex & mask;
+
+ dbg("TempDebug", "TempDebug: %d %d %d %d \n", i, bitIndex, mask, xor);
+ if(xor != 0){
+ return i;
+ }
+ mask = mask << 1;
+ }
+ return 0;
+ }
+ }
- uint8_t decision;
-
- decision = sendDecision();
-
- if(decision == ID_DHV_SUMMARY){
- windowSize = windowSize << 1;
- if(windowSize > DHV_TAU_HIGH){
- windowSize = DHV_TAU_HIGH;
- }
- }else{
- if(decision != ID_DHV_INVALID){
- windowSize = DHV_TAU_LOW;
- }
- }
-
- /*if(decision == ID_DHV_DATA){
- windowSize = DHV_TAU_LOW;
- }else{
- if(decision == ID_DHV_VBIT){
- windowSize = DHV_TAU_LOW;
- }else{
- windowSize = windowSize << 1;
- if(windowSize > DHV_TAU_HIGH){
- windowSize = DHV_TAU_HIGH;
- }
- }
- }
- */
+ uint8_t decision;
+
+ decision = sendDecision();
+
+ if(decision == ID_DHV_SUMMARY){
+ windowSize = windowSize << 1;
+ if(windowSize > DHV_TAU_HIGH){
+ windowSize = DHV_TAU_HIGH;
+ }
+ }else{
+ if(decision != ID_DHV_INVALID){
+ windowSize = DHV_TAU_LOW;
+ }
+ }
+
- case ID_DHV_INVALID:
- dbg("DhvLogicP", "Decision to SUPPRESS\n");
- break;
- case ID_DHV_SUMMARY:
- dbg("DhvLogicP", "Decision to SUMMARY\n");
- call DhvSummaryDecision.send();
- break;
- case ID_DHV_VECTOR:
- dbg("DhvLogicP", "Decision to VECTOR\n");
- call DhvVectorDecision.send();
- break;
- case ID_DHV_DATA:
- dbg("DhvLogicP", "Decision to DATA\n");
- call DhvDataDecision.send();
- break;
- case ID_DHV_VBIT:
- dbg("DhvLogicP", "Decision to VSUM\n");
- call DhvVBitDecision.send();
- break;
- case ID_DHV_HSUM:
- dbg("DhvLogicP", "Decision to HSUM\n");
- call DhvHSumDecision.send();
- break;
+ case ID_DHV_INVALID:
+ dbg("DhvLogicP", "Decision to SUPPRESS\n");
+ break;
+ case ID_DHV_SUMMARY:
+ dbg("DhvLogicP", "Decision to SUMMARY\n");
+ call DhvSummaryDecision.send();
+ break;
+ case ID_DHV_VECTOR:
+ dbg("DhvLogicP", "Decision to VECTOR\n");
+ call DhvVectorDecision.send();
+ break;
+ case ID_DHV_DATA:
+ dbg("DhvLogicP", "Decision to DATA\n");
+ call DhvDataDecision.send();
+ break;
+ case ID_DHV_VBIT:
+ dbg("DhvLogicP", "Decision to VSUM\n");
+ call DhvVBitDecision.send();
+ break;
+ case ID_DHV_HSUM:
+ dbg("DhvLogicP", "Decision to HSUM\n");
+ call DhvHSumDecision.send();
+ break;
-
- uint8_t getState() {
- bool hasItemToSend;
- uint32_t bindex;
-
- hasItemToSend = FALSE;
-
- hasItemToSend = call DhvDataCache.hasItemToSend();
- if(hasItemToSend){
- dbg("DhvLogicP", "has data to send? %u \n", hasItemToSend);
- return ID_DHV_DATA;
- }else{
- hasItemToSend = call DhvVectorCache.hasItemToSend();
- dbg("DhvLogicP", "has vector to send? %u \n", hasItemToSend);
- if(hasItemToSend){
- return ID_DHV_VECTOR;
- }else{
- bindex = call DhvStateLogic.getVBitState();
- dbg("DhvLogicP", "send decision bindex %d \n", bindex);
-
- if(bindex != 0){
- return ID_DHV_VBIT;
- }else{
- if(hsum_status != 0){
- return ID_DHV_HSUM;
- }else {
- return ID_DHV_SUMMARY;
- }
- }
- }
- }
- }
-
-
- if(hasItemToSend){
- dbg("DhvLogicP", "has data to send? %u \n", hasItemToSend);
- return ID_DHV_DATA;
- }
-
- bindex = call DhvStateLogic.getVBitState();
- dbg("DhvLogicP", "send decision bindex %d \n", bindex);
-
- if(bindex != 0){
- return ID_DHV_VBIT;
- }
-
- if(hsum_status != 0){
- return ID_DHV_HSUM;
- }
-
- if(dataCommRate > 1) {
- dbg("DhvLogicP", "Heard data\n");
- return ID_DHV_INVALID;
- }
-
-
- hasItemToSend = call DhvVectorCache.hasItemToSend();
- dbg("DhvLogicP", "has vector to send? %u \n", hasItemToSend);
-
- if(hasItemToSend){
- return ID_DHV_VECTOR;
- }
-
- // didn't send or hear data at this point
- if(vectorCommRate + summaryCommRate + vbitCommRate > 1) {
- dbg("DhvLogicP", "Heard an advertisement\n");
- return ID_DHV_INVALID;
- }
-
- return ID_DHV_SUMMARY;
- }
+ if(hasItemToSend){
+ dbg("DhvLogicP", "has data to send? %u \n", hasItemToSend);
+ return ID_DHV_DATA;
+ }
+
+ // didn't send or hear data at this point
+ if(dataCommRate + vectorCommRate + summaryCommRate + vbitCommRate + hsumCommRate >= INFO_THRESHOLD) {
+ dbg("DhvLogicP", "Heard an advertisement\n");
+ return ID_DHV_INVALID;
+ }
+
+ hasItemToSend = call DhvVectorCache.hasItemToSend();
+ dbg("DhvLogicP", "has vector to send? %u \n", hasItemToSend);
+
+ if(hasItemToSend){
+ return ID_DHV_VECTOR;
+ }
+
+ bindex = call DhvStateLogic.getVBitState();
+ dbg("DhvLogicP", "send decision bindex %d \n", bindex);
+
+ if(bindex != 0){
+ return ID_DHV_VBIT;
+ }
+
+ if(hsum_status != 0){
+ return ID_DHV_HSUM;
+ }
+
+ return ID_DHV_SUMMARY;
+ }