public static void WaitResponse(SerialPort inPort, bool verbose = true) { // Dump the response into a buffer.. // (byte by byte so we can compare the challenge/response) // e.g. it may start spewing data immediately after and we // have to catch that. // note: the attribute extensions use 40ish bytes of memory per pop string responseBuffer = ""; if (verbose) { Console.WriteLine("Waiting for response: " + argCommand.response()); } while (true) { if (inPort.BytesToRead != 0) { // Why the f**k does readchar return an int? responseBuffer += (char)inPort.ReadByte(); } if (verbose) { Console.Write("\r Response: " + responseBuffer); } if ( // regular mode responseBuffer == argCommand.response() // legacy modes || (argCommand == CommandMode.SEND_OLD_EXE && responseBuffer.Length > 0 && responseBuffer[responseBuffer.Length - 1] == 0x99) || (argCommand == CommandMode.SEND_OLD_ROM && responseBuffer.Length > 0 && responseBuffer[responseBuffer.Length - 1] == 0x99) ) { if (verbose) { Console.WriteLine("\nGot response: " + responseBuffer + "!"); } break; } // filter any noise at the start of the response // seems to happen once in a while if (responseBuffer.Length > 4) { responseBuffer = responseBuffer.Remove(0, 1); } } }
// If we're in solo monitor mode, there will be no // challenge/response, let's future-proof it though public static bool ChallengeResponse(CommandMode inMode) { return(ChallengeResponse(inMode.challenge(), inMode.response())); }