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.
master
Glenn Maynard 6 years ago
parent e57fa5d28e
commit 65f4a7102c
  1. 12
      sdk/Windows/SMXDeviceConnection.cpp

@ -203,6 +203,18 @@ void SMX::SMXDeviceConnection::HandleUsbPacket(const string &buf)
if(!m_bActive) if(!m_bActive)
break; 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); m_sCurrentReadBuffer.append(sPacket);
if(cmd & PACKET_FLAG_END_OF_COMMAND) if(cmd & PACKET_FLAG_END_OF_COMMAND)

Loading…
Cancel
Save