private static void OnSendStatus(IMAC macInstance, DateTime time, SendPacketStatus ACKStatus, uint transmitDestination, ushort index) { var pipe = macInstance as MACPipe; switch (ACKStatus) { case SendPacketStatus.SendACKed: #if DBG_DIAGNOSTIC Debug.Print("\t\tApp Message Handler: Retry queue length = " + _retriedPackets.Count); #endif #if !DBG_LOGIC Debug.Print("Detect to " + transmitDestination.ToString() + " ACKed"); #endif // Update link metrics if ((ushort)transmitDestination == RoutingGlobal.Parent) { RoutingGlobal.UpdateNumReceivedInCurrentWindow_Parent(1); #if !DBG_LOGIC Debug.Print("Updated numReceivedInCurrentWindow for parent " + transmitDestination + "; new value = " + RoutingGlobal.GetNumReceivedInCurrentWindow_Parent()); #endif } else { byte cindex = CandidateTable.findIndex((ushort)transmitDestination); if (cindex < byte.MaxValue) { CandidateTable._candidateList[cindex].UpdateNumReceivedInCurrentWindow(1); #if !DBG_LOGIC Debug.Print("Updated numReceivedInCurrentWindow for candidate " + transmitDestination + "; new value = " + CandidateTable._candidateList[cindex].GetNumReceivedInCurrentWindow()); #endif } } if (_retriedPackets.Contains(index)) // If this was a re-try, remove packet from queue { _retriedPackets.Remove(index); } break; case SendPacketStatus.SendNACKed: #if !DBG_LOGIC Debug.Print("Detect to " + transmitDestination.ToString() + " NACKed"); #endif // Update link metrics if ((ushort)transmitDestination == RoutingGlobal.Parent) { RoutingGlobal.UpdateNumTriesInCurrentWindow_Parent(1); #if !DBG_LOGIC Debug.Print("Updated numTriesInCurrentWindow for parent " + transmitDestination + "; new value = " + RoutingGlobal.GetNumTriesInCurrentWindow_Parent()); #endif } else { byte cindex = CandidateTable.findIndex((ushort)transmitDestination); if (cindex < byte.MaxValue) { CandidateTable._candidateList[cindex].UpdateNumTriesInCurrentWindow(1); #if !DBG_LOGIC Debug.Print("Updated numTriesInCurrentWindow for candidate " + transmitDestination + "; new value = " + CandidateTable._candidateList[cindex].GetNumTriesInCurrentWindow()); #endif } } break; case SendPacketStatus.SendFailed: #if DBG_DIAGNOSTIC Debug.Print("\t\tApp Message Handler: Retry queue length = " + _retriedPackets.Count); #endif // Update link metrics if ((ushort)transmitDestination == RoutingGlobal.Parent) { RoutingGlobal.UpdateNumTriesInCurrentWindow_Parent(1); #if !DBG_LOGIC Debug.Print("Updated numTriesInCurrentWindow for parent " + transmitDestination + "; new value = " + RoutingGlobal.GetNumTriesInCurrentWindow_Parent()); #endif } else { byte cindex = CandidateTable.findIndex((ushort)transmitDestination); if (cindex < byte.MaxValue) { CandidateTable._candidateList[cindex].UpdateNumTriesInCurrentWindow(1); #if !DBG_LOGIC Debug.Print("Updated numTriesInCurrentWindow for candidate " + transmitDestination + "; new value = " + CandidateTable._candidateList[cindex].GetNumTriesInCurrentWindow()); #endif } } // Retry if (!_retriedPackets.Contains(index) && RoutingGlobal._color == Color.Green) // If packet not there, enqueue it and retry it once { RoutingGlobal.CleanseCandidateTable(pipe); Candidate tmpBst = CandidateTable.GetBestCandidate(false); AppGlobal.TempParent = tmpBst.GetMacID(); byte[] msg = new byte[AppGlobal.DetectionMessageSize]; if (pipe.GetMsgWithMsgID(ref msg, index) == DeviceStatus.Success) { AppGlobal.SendToTempParent(pipe, msg, msg.Length); tmpBst.UpdateNumTriesInCurrentWindow(1); #if !DBG_LOGIC Debug.Print("Updated numTriesInCurrentWindow for TempParent " + transmitDestination + "; new value = " + tmpBst.GetNumTriesInCurrentWindow()); #endif _retriedPackets.Add(index); } } else // Retried once; drop packet { _retriedPackets.Remove(index); } break; default: break; } }