From 65f4a7102c1e01d6fd79fd48daa9a69957be67d6 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 19 Oct 2018 18:55:50 -0500 Subject: [PATCH] Check for out of sequence PACKET_FLAG_START_OF_COMMAND. This improves recovery if a start packet is received when we didn't receive a complete packet earlier. This doesn't normally happen, this just matches the error recovery used in game. --- sdk/Windows/SMXDeviceConnection.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sdk/Windows/SMXDeviceConnection.cpp b/sdk/Windows/SMXDeviceConnection.cpp index 1cc7e42..5f9b5dc 100644 --- a/sdk/Windows/SMXDeviceConnection.cpp +++ b/sdk/Windows/SMXDeviceConnection.cpp @@ -203,6 +203,18 @@ void SMX::SMXDeviceConnection::HandleUsbPacket(const string &buf) if(!m_bActive) break; + if(cmd & PACKET_FLAG_START_OF_COMMAND && !m_sCurrentReadBuffer.empty()) + { + // When we get a start packet, the read buffer should already be empty. If + // it isn't, we got a command that didn't end with an END_OF_COMMAND packet, + // and something is wrong. This shouldn't happen, so warn about it and recover + // by clearing the junk in the buffer. + Log(ssprintf("Got PACKET_FLAG_START_OF_COMMAND, but we had %i bytes in the read buffer", + m_sCurrentReadBuffer.size())); + + m_sCurrentReadBuffer.clear(); + } + m_sCurrentReadBuffer.append(sPacket); if(cmd & PACKET_FLAG_END_OF_COMMAND)