public void RcvData(string InputString) { // Compare the frame number and checksum to see whether the frame is good or bad. bool isFrameGood; // Compare frame numbers. if (InputString.TrimStart('\x02').StartsWith(ExpectedFrame.ToString())) { isFrameGood = true; } else { AppendToLog("Frame number is incorrect!"); isFrameGood = false; } // Check checksum. if (isFrameGood) { isFrameGood = CheckChecksum(InputString); } // If it's a header message, check the password. if (isFrameGood) { isFrameGood = CheckPassword(InputString); } // If the frame is still good after all those checks, // take appropriate action. if (isFrameGood) { // Send ACK comm.Send(Constants.ACK); // Reset rcvTimer to 30 seconds. comm.rcvTimer.Reset(30); // Increment frame number. ExpectedFrame = ++ExpectedFrame % 8; // Actually handle the frame. comm.ParseMessageLine(InputString); } else { // Send NAK comm.Send(Constants.NAK); // Reset rcvTimer to 30 seconds. comm.rcvTimer.Reset(30); } }
public void RcvACK() { // Send next frame. comm.CurrentMessage = comm.OutboundMessageQueue.Dequeue(); comm.CurrentMessage.PrepareToSend(); comm.Send(comm.CurrentMessage.FrameList[comm.CurrentFrameCounter]); comm.CurrentFrameCounter++; // Reset the NAK count to 0. comm.numNAK = 0; // Reset the transaction timer to 15 seconds. comm.transTimer.Reset(15); }
public void RcvACK() { #if DEBUG AppendToLog("CurrentMessage.FrameList.Count: " + comm.CurrentMessage.FrameList.Count); AppendToLog("CurrentFrameCounter: " + comm.CurrentFrameCounter); #endif // If all frames have been sent, end the transmission. if (comm.CurrentMessage.FrameList.Count == comm.CurrentFrameCounter) { comm.Send(Constants.EOT); comm.CurrentMessage = new Message(comm); } else { // Otherwise, send next frame. comm.Send(comm.CurrentMessage.FrameList[comm.CurrentFrameCounter]); comm.CurrentFrameCounter++; // Reset the NAK count to 0. comm.numNAK = 0; // Reset the transaction timer to 15 seconds. comm.transTimer.Reset(15); } }